summaryrefslogtreecommitdiff
path: root/vlan_test.pl
blob: f723089fb97840bd54bafa223fc36057e811aff7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
#!/usr/bin/perl

# For now, this just tests the addition and removal of 1000 VLAN interfaces on eth0

# Arguments:
#  graph  Generate a graph.
#  clean  Remove interfaces.

use strict;

$| = 1;

if ($ARGV[0] eq "graph") {
  my $dev_cnt = 0;
  my $user = 0;
  my $system = 0;
  my $real = 0;
  my $prog = "";

  open(IPNH, ">/tmp/ip_rpt_no_hash.txt") || die("Can't open /tmp/ip_rpt_no_hash.txt\n");
  open(IFCFGNH, ">/tmp/ifconfig_rpt_no_hash.txt") || die("Can't open /tmp/ifconfig_rpt_no_hash.txt\n");
  open(IP, ">/tmp/ip_rpt.txt") || die("Can't open /tmp/ip_rpt.txt\n");
  open(IFCFG, ">/tmp/ifconfig_rpt.txt") || die("Can't open /tmp/ifconfig_rpt.txt\n");

  my $hash = $ARGV[1];
  my $no_hash = $ARGV[2];

  open(IF, "$no_hash");
  while (<IF>) {
    my $ln = $_;
    chomp($ln);

    #print "LINE: -:$ln:-\n";

    if ($ln =~ /Doing ip addr show for (\S+)/) {
      $dev_cnt = $1;
      $prog = "ip";
    }
    elsif ($ln =~ /Doing ifconfig -a for (\S+)/) {
      $dev_cnt = $1;
      $prog = "ifconfig";
    }
    elsif ($ln =~ /^real (\S+)/) {
      $real = $1;
    }
    elsif ($ln =~ /^user (\S+)/) {
      $user = $1;
    }
    elsif ($ln =~ /^sys (\S+)/) {
      $system = $1;
      #print "prog: $prog  $dev_cnt\t$user\t$system\t$real\n";
      if ($prog eq "ip") {
	print IPNH "$dev_cnt\t$user\t$system\t$real\n";
      }
      else {
	print IFCFGNH "$dev_cnt\t$user\t$system\t$real\n";
      }
    }
    else {
      #print "INFO:  Didn't match anything -:$ln:-\n";
    }
  }

  close(IPNH);
  close(IFCFGNH);
  close(IF);

  open(IF, "$hash");
  while (<IF>) {
    my $ln = $_;
    chomp($ln);

    #print "LINE: -:$ln:-\n";

    if ($ln =~ /Doing ip addr show for (\S+)/) {
      $dev_cnt = $1;
      $prog = "ip";
    }
    elsif ($ln =~ /Doing ifconfig -a for (\S+)/) {
      $dev_cnt = $1;
      $prog = "ifconfig";
    }
    elsif ($ln =~ /^real (\S+)/) {
      $real = $1;
    }
    elsif ($ln =~ /^user (\S+)/) {
      $user = $1;
    }
    elsif ($ln =~ /^sys (\S+)/) {
      $system = $1;
      #print "prog: $prog  $dev_cnt\t$user\t$system\t$real\n";
      if ($prog eq "ip") {
	print IP "$dev_cnt\t$user\t$system\t$real\n";
      }
      else {
	print IFCFG "$dev_cnt\t$user\t$system\t$real\n";
      }
    }
    else {
      #print "INFO:  Didn't match anything -:$ln:-\n";
    }
  }

  close(IP);
  close(IFCFG);

  my $plot_cmd = "set title \"ip addr show V/S ifconfig -a\"
set terminal png color
set output \"ip_addr_show.png\"
set size 1,2
set xlabel \"Interface Count\"
set ylabel \"Seconds\"
set grid
plot \'/tmp/ip_rpt.txt\' using 1:3 title \"ip_system\" with lines, \\
     \'/tmp/ip_rpt.txt\' using 1:2 title \"ip_user\" with lines, \\
     \'/tmp/ifconfig_rpt.txt\' using 1:3 title \"ifconfig_system\" with lines, \\
     \'/tmp/ifconfig_rpt.txt\' using 1:2 title \"ifconfig_user\" with lines, \\
     \'/tmp/ip_rpt_no_hash.txt\' using 1:3 title \"ip_system_no_hash\" with lines, \\
     \'/tmp/ip_rpt_no_hash.txt\' using 1:2 title \"ip_user_no_hash\" with lines, \\
     \'/tmp/ifconfig_rpt_no_hash.txt\' using 1:3 title \"ifconfig_system_no_hash\" with lines, \\
     \'/tmp/ifconfig_rpt_no_hash.txt\' using 1:2 title \"ifconfig_user_no_hash\" with lines";
  print "Plotting with cmd -:$plot_cmd:-\n";

  open(GP, "| gnuplot") or die ("Can't open gnuplot pipe(2).\n");
  print GP "$plot_cmd";
  close(GP);

  exit(0);
}

my $num_if = 4000;

`/usr/local/bin/vconfig set_name_type VLAN_PLUS_VID_NO_PAD`;

my $d = 5;
my $c = 5;

if ($ARGV[0] ne "clean") {

  my $i;
  print "Adding VLAN interfaces 1 through $num_if\n";

  print "Turnning off /sbin/hotplug";
  `echo  > /proc/sys/kernel/hotplug`;

  my $p = time();
  for ($i = 1; $i<=$num_if; $i++) {
    `/usr/local/bin/vconfig add eth0 $i`;
    #`ip address flush dev vlan$i`;
    `ip address add 192.168.$c.$c/24 dev vlan$i`;
    `ip link set dev vlan$i up`;

    if (($i <= 4000) && (($i % 250) == 0)) {
      print "Doing ifconfig -a for $i devices.\n";
      `time -p ifconfig -a > /tmp/vlan_test_ifconfig_a_$i.txt`;
      print "Doing ip addr show for $i devices.\n";
      `time -p ip addr show > /tmp/vlan_test_ip_addr_$i.txt`;
    }

    $d++;
    if ($d > 250) {
      $d = 5;
      $c++;
    }
  }
  my $n = time();
  my $diff = $n - $p;

  print "Done adding $num_if VLAN interfaces in $diff seconds.\n";

  sleep 2;
}

print "Removing VLAN interfaces 1 through $num_if\n";
$d = 5;
$c = 5;
my $p = time();
my $i;
for ($i = 1; $i<=$num_if; $i++) {
  `/usr/local/bin/vconfig rem vlan$i`;

  $d++;
  if ($d > 250) {
    $d = 5;
    $c++;
  }
}
my $n = time();
my $diff = $n - $p;
print "Done deleting $num_if VLAN interfaces in $diff seconds.\n";

sleep 2;


if ($ARGV[0] ne "clean") {

  my $tmp = $num_if / 4;
  print "\nGoing to add and remove 2 interfaces $tmp times.\n";
  $p = time();
  
  
  for ($i = 1; $i<=$tmp; $i++) {
    `/usr/local/bin/vconfig add eth0 1`;
    `ifconfig vlan1 192.168.200.200`;
    `ifconfig vlan1 up`;
    `ifconfig vlan1 down`;
    
    `/usr/local/bin/vconfig add eth0 2`;
    `ifconfig vlan2 192.168.202.202`;
    `ifconfig vlan2 up`;
    `ifconfig vlan2 down`;
    
    `/usr/local/bin/vconfig rem vlan2`;
    `/usr/local/bin/vconfig rem vlan1`;
  }
  $n = time();
  $diff = $n - $p;
  print "Done adding/removing 2 VLAN interfaces $tmp times in $diff seconds.\n";
}

print "Re-installing /sbin/hotplug";
`echo /sbin/hotplug > /proc/sys/kernel/hotplug`;