dnscrypto-proxy: Support files updated.
[tomato.git] / release / src / router / vlan / vlan_test.pl
blob1e290c4ecb2a9204647e61dc9d781d75af99eced
1 #!/usr/bin/perl
3 # For now, this just tests the addition and removal of 1000 VLAN interfaces on eth0
5 # Arguments:
6 # graph Generate a graph.
7 # clean Remove interfaces.
9 use strict;
11 $| = 1;
13 if ($ARGV[0] eq "graph") {
14 my $dev_cnt = 0;
15 my $user = 0;
16 my $system = 0;
17 my $real = 0;
18 my $prog = "";
20 open(IPNH, ">/tmp/ip_rpt_no_hash.txt") || die("Can't open /tmp/ip_rpt_no_hash.txt\n");
21 open(IFCFGNH, ">/tmp/ifconfig_rpt_no_hash.txt") || die("Can't open /tmp/ifconfig_rpt_no_hash.txt\n");
22 open(IP, ">/tmp/ip_rpt.txt") || die("Can't open /tmp/ip_rpt.txt\n");
23 open(IFCFG, ">/tmp/ifconfig_rpt.txt") || die("Can't open /tmp/ifconfig_rpt.txt\n");
25 my $hash = $ARGV[1];
26 my $no_hash = $ARGV[2];
28 open(IF, "$no_hash");
29 while (<IF>) {
30 my $ln = $_;
31 chomp($ln);
33 #print "LINE: -:$ln:-\n";
35 if ($ln =~ /Doing ip addr show for (\S+)/) {
36 $dev_cnt = $1;
37 $prog = "ip";
39 elsif ($ln =~ /Doing ifconfig -a for (\S+)/) {
40 $dev_cnt = $1;
41 $prog = "ifconfig";
43 elsif ($ln =~ /^real (\S+)/) {
44 $real = $1;
46 elsif ($ln =~ /^user (\S+)/) {
47 $user = $1;
49 elsif ($ln =~ /^sys (\S+)/) {
50 $system = $1;
51 #print "prog: $prog $dev_cnt\t$user\t$system\t$real\n";
52 if ($prog eq "ip") {
53 print IPNH "$dev_cnt\t$user\t$system\t$real\n";
55 else {
56 print IFCFGNH "$dev_cnt\t$user\t$system\t$real\n";
59 else {
60 #print "INFO: Didn't match anything -:$ln:-\n";
64 close(IPNH);
65 close(IFCFGNH);
66 close(IF);
68 open(IF, "$hash");
69 while (<IF>) {
70 my $ln = $_;
71 chomp($ln);
73 #print "LINE: -:$ln:-\n";
75 if ($ln =~ /Doing ip addr show for (\S+)/) {
76 $dev_cnt = $1;
77 $prog = "ip";
79 elsif ($ln =~ /Doing ifconfig -a for (\S+)/) {
80 $dev_cnt = $1;
81 $prog = "ifconfig";
83 elsif ($ln =~ /^real (\S+)/) {
84 $real = $1;
86 elsif ($ln =~ /^user (\S+)/) {
87 $user = $1;
89 elsif ($ln =~ /^sys (\S+)/) {
90 $system = $1;
91 #print "prog: $prog $dev_cnt\t$user\t$system\t$real\n";
92 if ($prog eq "ip") {
93 print IP "$dev_cnt\t$user\t$system\t$real\n";
95 else {
96 print IFCFG "$dev_cnt\t$user\t$system\t$real\n";
99 else {
100 #print "INFO: Didn't match anything -:$ln:-\n";
104 close(IP);
105 close(IFCFG);
107 my $plot_cmd = "set title \"ip addr show V/S ifconfig -a\"
108 set terminal png color
109 set output \"ip_addr_show.png\"
110 set size 1,2
111 set xlabel \"Interface Count\"
112 set ylabel \"Seconds\"
113 set grid
114 plot \'/tmp/ip_rpt.txt\' using 1:3 title \"ip_system\" with lines, \\
115 \'/tmp/ip_rpt.txt\' using 1:2 title \"ip_user\" with lines, \\
116 \'/tmp/ifconfig_rpt.txt\' using 1:3 title \"ifconfig_system\" with lines, \\
117 \'/tmp/ifconfig_rpt.txt\' using 1:2 title \"ifconfig_user\" with lines, \\
118 \'/tmp/ip_rpt_no_hash.txt\' using 1:3 title \"ip_system_no_hash\" with lines, \\
119 \'/tmp/ip_rpt_no_hash.txt\' using 1:2 title \"ip_user_no_hash\" with lines, \\
120 \'/tmp/ifconfig_rpt_no_hash.txt\' using 1:3 title \"ifconfig_system_no_hash\" with lines, \\
121 \'/tmp/ifconfig_rpt_no_hash.txt\' using 1:2 title \"ifconfig_user_no_hash\" with lines";
122 print "Plotting with cmd -:$plot_cmd:-\n";
124 open(GP, "| gnuplot") or die ("Can't open gnuplot pipe(2).\n");
125 print GP "$plot_cmd";
126 close(GP);
128 exit(0);
131 my $num_if = 4000;
133 `/usr/local/bin/vconfig set_name_type VLAN_PLUS_VID_NO_PAD`;
135 my $d = 5;
136 my $c = 5;
138 if ($ARGV[0] ne "clean") {
140 my $i;
141 print "Adding VLAN interfaces 1 through $num_if\n";
143 print "Turnning off /sbin/hotplug";
144 `echo > /proc/sys/kernel/hotplug`;
146 my $p = time();
147 for ($i = 1; $i<=$num_if; $i++) {
148 `/usr/local/bin/vconfig add eth0 $i`;
149 #`ip address flush dev vlan$i`;
150 `ip address add 192.168.$c.$c/24 dev vlan$i`;
151 `ip link set dev vlan$i up`;
153 if (($i <= 4000) && (($i % 50) == 0)) {
154 #print "Doing ifconfig -a for $i devices.\n";
155 #`time -p ifconfig -a > /tmp/vlan_test_ifconfig_a_$i.txt`;
156 print "Doing ip addr show for $i devices.\n";
157 `time -p ip addr show > /tmp/vlan_test_ip_addr_$i.txt`;
160 $d++;
161 if ($d > 250) {
162 $d = 5;
163 $c++;
166 my $n = time();
167 my $diff = $n - $p;
169 print "Done adding $num_if VLAN interfaces in $diff seconds.\n";
171 sleep 2;
174 print "Removing VLAN interfaces 1 through $num_if\n";
175 $d = 5;
176 $c = 5;
177 my $p = time();
178 my $i;
179 for ($i = 1; $i<=$num_if; $i++) {
180 `/usr/local/bin/vconfig rem vlan$i`;
182 $d++;
183 if ($d > 250) {
184 $d = 5;
185 $c++;
188 my $n = time();
189 my $diff = $n - $p;
190 print "Done deleting $num_if VLAN interfaces in $diff seconds.\n";
192 sleep 2;
195 if ($ARGV[0] ne "clean") {
197 my $tmp = $num_if / 4;
198 print "\nGoing to add and remove 2 interfaces $tmp times.\n";
199 $p = time();
202 for ($i = 1; $i<=$tmp; $i++) {
203 `/usr/local/bin/vconfig add eth0 1`;
204 `ifconfig vlan1 192.168.200.200`;
205 `ifconfig vlan1 up`;
206 `ifconfig vlan1 down`;
208 `/usr/local/bin/vconfig add eth0 2`;
209 `ifconfig vlan2 192.168.202.202`;
210 `ifconfig vlan2 up`;
211 `ifconfig vlan2 down`;
213 `/usr/local/bin/vconfig rem vlan2`;
214 `/usr/local/bin/vconfig rem vlan1`;
216 $n = time();
217 $diff = $n - $p;
218 print "Done adding/removing 2 VLAN interfaces $tmp times in $diff seconds.\n";
221 print "Re-installing /sbin/hotplug";
222 `echo /sbin/hotplug > /proc/sys/kernel/hotplug`;