-
Notifications
You must be signed in to change notification settings - Fork 25
/
lf_port_walk.pl
executable file
·279 lines (210 loc) · 8 KB
/
lf_port_walk.pl
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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
#!/usr/bin/perl
# This program is used to stress test the LANforge system, and may be used as
# an example for others who wish to automate LANforge tests.
# The purpose of this script is to create 10 (or more) TCP and/or UDP connections on
# specified ports. The connections will run for a short period of time, and
# then 10 more will be created on a new set of ports (the next 10). It
# writes it's cmds to a log file so you can get an idea of what it's doing.
#
# This script should be useful for people who are testing firewalls and other
# types of systems that care about what ports the data is transmitted on...
#
# Written by Candela Technologies Inc.
# Udated by:
#
#
# Un-buffer output
$| = 1;
use Net::Telnet ();
use Getopt::Long;
my $lfmgr_host = "localhost";
my $lfmgr_port = 4001;
my $shelf_num = 1;
# Specify 'card' numbers for this configuration.
my $lanf1 = 1;
my $lanf2 = 2;
# Script assumes that we are using one port on each machine for data transmission...specifically
# port 1.
my $test_mgr = "port-walker";
my $run_for_time = 20; # Run for XX seconds before tearing down and bringing up the next set..
my $report_timer = 8000; # XX/1000 seconds
# Default values for ye ole cmd-line args.
my $proto = "both"; # tcp, udp, or both
my $start_port = 1; # Port to start with...
my $end_port = 65535; # port to end with
my $to_do_at_a_time = 20; # Do XX cross-connects at a time. Don't make this too big,
# especially now...there is a buglet w/the GUI, especially...
my $do_bulk_removes = 1;
my $do_cx_too = 1; # Should probably be 1 most of the time...
my $do_run_cxs = 1; #Should usually be 1
my $cmd_log_name = "lf_port_walk_cmds.txt";
open(CMD_LOG, ">$cmd_log_name") or die("Can't open $cmd_log_name for writing...\n");
print "History of all commands can be found in $cmd_log_name\n";
########################################################################
# Nothing to configure below here, most likely.
########################################################################
my $usage = "$0 [--protocol={tcp | udp | both}] [--start_port={port}] [--end_port={port}]\n";
my $i = 0;
GetOptions
(
'protocol|p=s' => \$proto,
'start_port|s=i' => \$start_port,
'end_port|e=i' => \$end_port,
) || die("$usage");
my @endpoint_names = (); #will be added to as they are created
my @cx_names = ();
# Open connection to the LANforge server.
my $t = new Net::Telnet(Prompt => '/default\@btbits\>\>/');
$t->open(Host => $lfmgr_host,
Port => $lfmgr_port,
Timeout => 10);
$t->waitfor("/btbits\>\>/");
my $dt = "";
# Lets create udp and tcp connections on all ports. Some of these
# won't work, so we'll ignore them.
# get these numbers by doing something like:
# netstat -an | grep LISTEN
# There may be more or less on your machine...it would be best to check with the
# above cmd.
#
my @tcp_ignore_array = (
6010, # X
3999, 4002, 4001, # LANforge
1024, # varies, rpc.statd often
111, # portmapper for NFS
22, #ssh
25, #smtp (email)
);
# Set up a hash for fast existence checking...
my %ignore_ports = ();
for ($i = 0; $i<@tcp_ignore_array; $i++) {
my $prt = $tcp_ignore_array[$i];
$ignore_ports->{$prt} = "$prt";
}
$dt = `date`;
chomp($dt);
print "\n\n***** Starting loop at: $dt *****\n\n";
# Remove any existing configuration information
initToDefaults();
print " ***Sleeping 3 seconds for ports to initialize to defaults...\n";
sleep(3);
#exit(0);
# Now, add back the test manager we will be using
doCmd("add_tm $test_mgr");
doCmd("tm_register $test_mgr default"); #Add default user
doCmd("tm_register $test_mgr default_gui"); #Add default GUI user
# Add some IP addresses to the ports
initIpAddresses();
print " ***Sleeping 3 seconds for ports to initialize to current values...\n";
sleep(3);
# Now, go build lots of endpoints, one for every tcp/udp port known to man and beast!
for ($i = $start_port; $i<$end_port; $i++) {
# Do XX at once.
my $j = 0;
for ($j = 0; $j<$to_do_at_a_time; $j++) {
my $ht = $ignore_ports->{$i};
if ((defined($ht)) && (length($ht) > 0)) {
# continue...it's in our ignore list
# TODO: We could probably still do UDP, so we should really have separate
# ingore lists for the different protocols...
print " *** Skipping port: $i\n";
$i++;
next;
}
# Syntax for adding an endpoint is:
# add_endp [alias] [shelf] [card] [port] [type] [IP-port] [bursty] [min_rate] [max_rate]
# [pkt_sz_random] [min_pkt] [max_pkt] [pattern] [use_checksum]
if (($proto eq "both") || ($proto eq "udp")) {
# Set up 128Kbps full duplex UDP link, 1200 byte UDP payloads, on port $i
print " *** Creating UDP endpoint on port $i\n";
doCmd("add_endp udp-$i-TX $shelf_num $lanf1 1 lf_udp $i NO 512000 512000 NO 1200 1200 increasing NO");
doCmd("add_endp udp-$i-RX $shelf_num $lanf2 1 lf_udp $i NO 512000 512000 NO 1200 1200 increasing NO");
if ($do_cx_too) {
doCmd("add_cx udp-$i $test_mgr udp-${i}-TX udp-${i}-RX");
@cx_names = (@cx_names, "udp-$i");
}
@endpoint_names = (@endpoint_names, "udp-${i}-TX", "udp-${i}-RX");
}
if (($proto eq "both") || ($proto eq "tcp")) {
# Set up 128Kbps full duplex TCP link, 1200 byte TCP payloads, on port $i
print " *** Creating TCP endpoint on port $i\n";
doCmd("add_endp tcp-$i-TX $shelf_num $lanf1 1 lf_tcp $i NO 512000 512000 NO 1200 1200 increasing NO");
doCmd("add_endp tcp-$i-RX $shelf_num $lanf2 1 lf_tcp $i NO 512000 512000 NO 1200 1200 increasing NO");
if ($do_cx_too) {
doCmd("add_cx tcp-$i $test_mgr tcp-${i}-TX tcp-${i}-RX");
@cx_names = (@cx_names, "tcp-$i");
}
@endpoint_names = (@endpoint_names, "tcp-${i}-TX", "tcp-${i}-RX");
}
$i++;
if ($i >= $end_port) {
last;
}
}
# So, our CXs and endpoints are created...lets start them running.
if ($do_run_cxs) {
doCmd("set_cx_state $test_mgr all RUNNING");
}
# SLeep for a bit, because it takes connections, especially TCP a bit to get started
# properly...and we want to give the user time to see if the expected behaviour is
# really happening....
print " ***Done starting endpoints...sleeping $run_for_time seconds.\n";
sleep($run_for_time);
if ($do_run_cxs) {
doCmd("set_cx_state $test_mgr all STOPPED");
}
my $q = 0;
if (! $do_bulk_removes) {
for ($q = 0; $q<@cx_names; $q++) {
# Delete the endpoints and cross-connects related to this test manager.
doCmd("rm_cx $test_mgr $cx_names[$q]");
}
for ($q = 0; $q<@endpoint_names; $q++) {
# Delete the endpoints and cross-connects related to this test manager.
doCmd("rm_endp $endpoint_names[$q]");
}
}
else {
doCmd("rm_cx $test_mgr ALL");
doCmd("rm_endp YES_ALL"); # Won't delete those attached to cross-connects still...
}
@endpoint_names = ();
@cx_names = ();
}# for all ports
$dt = `date`;
chomp($dt);
print "Done at: $dt\n\n";
exit(0);
sub initToDefaults {
# Clean up database if stuff exists
doCmd("rm_cx $test_mgr all");
doCmd("rm_endp YES_ALL");
doCmd("rm_test_mgr $test_mgr");
initPortsToDefault();
}#initToDefaults
sub initPortsToDefault {
# Set all ports we are messing with to known state.
my $i = 0;
my $num_ports = 1;
for ($i = 1; $i<=$num_ports; $i++) {
doCmd("set_port $shelf_num $lanf1 $i 0.0.0.0 0.0.0.0 0.0.0.0 NA NA NA");
doCmd("set_port $shelf_num $lanf2 $i 0.0.0.0 0.0.0.0 0.0.0.0 NA NA NA");
}
}
sub initIpAddresses {
# Set all ports we are messing with to known state.
# Syntax for setting port info is:
# set_port [shelf] [card] [port] [ip] [mask] [gateway] [cmd-flags] [cur-flags] [MAC]
# NOTE: Just use NA for the flags for now...not tested otherwise.
doCmd("set_port $shelf_num $lanf1 1 172.25.7.2 255.255.255.0 172.25.7.1 NA NA NA");
doCmd("set_port $shelf_num $lanf2 1 172.25.7.3 255.255.255.0 172.25.7.1 NA NA NA");
}
sub doCmd {
my $cmd = shift;
print CMD_LOG "$cmd\n";
print ">>> $cmd\n";
$t->print($cmd);
my @rslt = $t->waitfor('/ \>\>RSLT:(.*)/');
print "**************\n @rslt ................\n\n";
#sleep(1);
}