Agenda: exercises-network-metrics-and-analysis.txt

File exercises-network-metrics-and-analysis.txt, 13.7 KB (added by hervey, 8 years ago)
Line 
1Network Performance Definitions and Measurement Exercises
2=========================================================
3
4Notes:
5------
6* Commands preceded with "$" imply that you should execute the command as
7  a general user - not as root.
8* Commands preceded with "#" imply that you should be working as root.
9* Commands with more specific command lines (e.g. "GW-RTR>" or "mysql>")
10  imply that you are executing commands on remote equipment, or within
11  another program.
12* If a command line ends with "\" this indicates that the command continues
13  on the next line and you should treat this as a single line.
14
15Exercises Part I
16================
17
180. Log in to your PC/VM or open a terminal window as the sysadm user.
19
20NOTE: During these exercises if you find that the apt-get command complains
21      that some archives cannot be found, then you may need to update your
22      apt package database. To do this type:
23
24      $ sudo apt-get update
25
26
27Network Performance Metrics
28---------------------------
29
301. ping
31-------
32
33ping is a program that sends ICMP echo request packets to target hosts and
34waits for an ICMP response from the host. Depending on the operating system
35on which you are using ping you may see the minimum, maximum, and the mean
36round-trip times, and sometimes the standard deviation of the mean for the
37ICMP responses from the target host. For more details see:
38
39http://en.wikipedia.org/wiki/Ping
40
41Blocking ping is generally a bad idea.
42
43With all this in mind, try using ping in a few different ways:
44
45    $ ping localhost
46
47Press ctrl-c to stop the process. Here is typical output from the above
48command:
49
50    PING localhost (127.0.0.1) 56(84) bytes of data.
51    64 bytes from localhost (127.0.0.1): icmp_seq=1 ttl=64 time=0.020 ms
52    64 bytes from localhost (127.0.0.1): icmp_seq=2 ttl=64 time=0.006 ms
53    64 bytes from localhost (127.0.0.1): icmp_seq=3 ttl=64 time=0.006 ms
54    64 bytes from localhost (127.0.0.1): icmp_seq=4 ttl=64 time=0.006 ms
55    64 bytes from localhost (127.0.0.1): icmp_seq=5 ttl=64 time=0.006 ms
56    64 bytes from localhost (127.0.0.1): icmp_seq=6 ttl=64 time=0.009 ms
57    64 bytes from localhost (127.0.0.1): icmp_seq=7 ttl=64 time=0.007 ms
58    ^C
59    --- localhost ping statistics ---
60    7 packets transmitted, 7 received, 0% packet loss, time 5994ms
61    rtt min/avg/max/mdev = 0.006/0.008/0.020/0.005 ms
62
63Question: why did the first ICMP response take 20ms while the remaining
64responses were much quicker? This is a type of delay. What kind is it?
65
66
672. traceroute
68-------------
69
70You may have used traceroute before, but have you really looked at what it is
71doing? If not, read this:
72
73http://en.wikipedia.org/wiki/Traceroute
74
75You may need to install the traceroute command first. To do this do:
76
77        $ sudo apt-get install traceroute
78
79Once installed try:
80
81        $ traceroute nsrc.org
82
83Here's sample output from traceroute to nsrc.org (lines wrapped due to length):
84
85        traceroute to nsrc.org (128.223.157.19), 64 hops max, 52 byte packets
86         1  gw.ws.nsrc.org (10.10.0.254)  1.490 ms  1.069 ms  1.055 ms
87         2  192.248.5.2 (192.248.5.2)  2.741 ms  2.450 ms  3.182 ms
88         3  192.248.1.126 (192.248.1.126)  2.473 ms  2.497 ms  2.618 ms
89         4  mb-t3-01-v4.bb.tein3.net (202.179.249.93)  26.324 ms  28.049 ms  27.403 ms
90         5  sg-so-06-v4.bb.tein3.net (202.179.249.81)  103.321 ms  91.072 ms  91.674 ms
91         6  jp-pop-sg-v4.bb.tein3.net (202.179.249.50)  168.948 ms  168.712 ms  168.903 ms
92         7  tpr5-ge0-0-0-4.jp.apan.net (203.181.248.250)  172.789 ms  170.367 ms  188.689 ms
93         8  losa-tokyo-tp2.transpac2.net (192.203.116.145)  579.586 ms  284.736 ms  284.202 ms
94         9  abilene-1-lo-jmb-702.lsanca.pacificwave.net (207.231.240.131)  303.736 ms 
95            284.884 ms  530.854 ms
96        10  vl-101.xe-0-0-0.core0-gw.pdx.oregon-gigapop.net (198.32.165.65)  328.082 ms 
97            305.800 ms  533.644 ms
98        11  vl-105.uonet9-gw.eug.oregon-gigapop.net (198.32.165.92)  336.680 ms  617.267 ms 
99            495.685 ms
100        12  vl-3.uonet2-gw.uoregon.edu (128.223.3.2)  310.552 ms  421.638 ms  612.399 ms
101        13  nsrc.org (128.223.157.19)  309.548 ms  612.151 ms  611.505 ms
102
103Do you understand what each item means? If not, see the Wikipedia page and type:
104
105    $ man traceroute
106
107for more information. What does it mean if you see lines like this?
108
109    15  * * *
110    16  * * *
111    17  * * *
112
113When you see this it means that the remote device does not reply to icmp echo requests, or
114it uses a private network address (RFC 1918).
115
116As you can see traceroute can be used to determine where problems are taking place
117between two endpoints on a network.
118
119Try running traceroute again to the same host (nsrc.org). It will likely take considerably
120less time.
121
122
1233. mtr
124------
125
126The mtr tool combines ping and traceroute in to a single, dynamically updating display.
127Before using mtr you may need to first install it:
128
129        $ sudo apt-get install mtr-tiny
130
131Now give it a try:
132
133        $ mtr nsrc.org
134
135The output of the command looks different on different Linux and UNIX flavors, but in
136general you'll see a summary of packet loss to each node on the path to the remote
137target host, number of ICMP echo request packets sent, last rtt (round-trip-time) to
138the host, average, best and worst rtt as well as the standard deviation of rtt's.
139
140By showing the percent loss of packets in this format it makes it much easier to see
141where you may be having network issues.
142
143
1444. ping with variable packet size
145---------------------------------
146
147By default, ping sends out IP datagrams of size 84 bytes:
148
149* 20 bytes IP header
150*  8 bytes ICMP header
151* 56 bytes data padding
152
153However, you can send out larger packets using the -s option. Using
154`-s 1472` will give you a 1500-byte IP datagram, which is the maximum for
155most networks before fragmentation takes place (MTU = Maximum Transmission
156Unit)
157
158This simple mechanism can be used to debug all sorts of problems, and even
159distinguish between transmission delay and propagation delay.
160
161Let's find a host that is a few hops away from us. First do:
162
163        $ traceroute nsrc.org
164
165Now look for a machine that is more than two hops away and make a note of
166the IP address. Why? Because one hop is your virtual router and this exercise
167will not work reliably using virtual hardware. The second hop is the gateway
168router on our private network. It is too close and the difference in ping
169times are likely to be too small to be useful. We'll refer to the machine
170you choose to ping to as PING_MACHINE.
171
172Send 20 standard pings to that address:
173
174        $ ping -c20 PING_MACHINE
175
176Make a note of the *average* round-trip time seen (t1).
177
178Now send 20 maximum-sized pings:
179
180        $ ping -c20 -s1472 PING_MACHINE
181
182Again, make a note of the *average* round-trip time seen (t2).
183
184The propagation delay is the same in both cases, so the larger round-trip
185time must be due to transmission delay.
186
187You can now estimate the transmission delay and hence the bandwidth of
188the link between two points
189
190    increase in transmission time   =  t2 - t1
191    increase in bits sent           =  (1500-84) * 8 * 2  = 22656
192
193(multiply by 2 because the round-trip time involves sending the packet twice)
194
195Divide the bits by time to get an estimate of bits per second. Remember to
196convert milliseconds to seconds first.
197
198Example:
199       
200t2 = 1.71
201t1 = 1.14
202
203t2-t1 = 0.57
204
2050.57 ms = 0.00057 sec
206
20722656 bits / 0.00057 sec = 39747368.42 bps
208
209You could then convert this to Kbps, Mbps, etc.
210
211By doing this for subsequent hops, it's possible to estimate the bandwidth
212on each hop, even those remote from you. There is a tool available which
213does this automatically - it's called "pathchar" but you have to build it
214from source. A few OS-specific binaries are available at:
215
216ftp://ftp.ee.lbl.gov/pathchar/
217
218The web page, including documentation is available here:
219
220http://www.caida.org/tools/utilities/others/pathchar/
221
222
223---------------------------------------------------------------------------
224
225
226Exercises Part II
227=================
228
229Network Analysis
230----------------
231
2321. lsof and netstat
233-------------------
234
235See what services are running on your machine. You can use the
236presentation as a reference.
237
238Or, utilize "man lsof", "man netstat", "lsof -h" and "netstat -h" to see
239the available options (there are a lot!). Remember to use
240sudo when using lsof and netstat to give yourself necessary permissions
241to view everything.
242
243You may need to install lsof. To do this type:
244
245        $ sudo apt-get install lsof
246
247* Using lsof, what IPv4 services are listening on your machine?
248* Using netstat, what IPv4 and IPv6 services are listening on your machine?
249
250When you run lsof and netstat you should run them as root:
251
252        $ sudo lsof
253        $ sudo netstat
254
255Remember - you will need to specify options to answer what IPv4 and IPv6 services
256are running on your machine.
257
258
2592. tcpdump and tshark
260---------------------
261
262First we need to install both these programs:
263
264        $ sudo apt-get install tcpdump tshark
265
266Use tcpdump like this:
267
268        $ sudo tcpdump -i lo -A -s1500 -w /tmp/tcpdump.log
269
270Now, generate some traffic on your lo interface in another terminal. That is
271open another ssh session to your pc/vm.
272
273For example:
274
275        $ ping localhost
276        $ ssh localhost
277 
278etc. Afterwords press CTRL-C to terminate the tcpdump session.
279
280Note: ssh generates much more "interesting" output. Now let's read the
281output from tcpdump using tshark:
282
283        $ sudo tshark -r /tmp/tcpdump.log | less
284
285What do you see? Can you follow the SSH session you initiated earlier?
286
287Next we'll use ftp. First we need to install an ftp client:
288
289        $ sudo apt-get install ftp
290
291Now try something like this:
292
293        $ sudo rm /tmp/tcpdump.log
294        $ sudo tcpdump -i eth0 -A -s1500 -w /tmp/tcpdump.log
295
296In another terminal do:
297
298        $ ftp limestone.uoregon.edu
299 
300        Connected to limestone.uoregon.edu.
301        220 FTP Server ready.
302        Name (limestone.uoregon.edu:sysadmin): anonymous
303        Password: <anything you want>
304        ftp> exit
305
306End the tcpdump session in the other terminal (CTRL-C). Now view the
307contents of the log file:
308
309        $ sudo tshark -r /tmp/tcpdump.log | less
310
311Can you see your password? If you have a lot of traffic on  your network, then
312the tcpdump.log file may be fairly large. You can search for your FTP session
313by typing:
314
315        "/FTP"
316
317in the output screen. Since you piped your shark command output to the "less"
318command using the "/" to search for strings works. Now press the "n" key for
319"n"ext to follow the FTP session. You should see a line with the string:
320
321        "FTP Request: PASS PasswordYouTypedIn"
322
323Sniffing unencrypted passwords on wireless lans is very easy with a tool like
324this.
325
326Rememer to clean up after yourself:
327
328        $ rm /tmp/tcpdump.log
329
330
3313. tcpdump part II
332-------------------
333
334You can use tcpdump as a forensic tool in real-time as well. To completely cover tcpdump would
335take several hours of class time, but let's get started with another practical example.
336
337Let's watch a dhcp request from your PC and the responses that it receives.
338
339First connect to your PC image and become root:
340
341    $ sudo bash
342   
343Next we are going to use a utility called screen:
344
345    # apt-get install screen
346   
347Now run screen:
348
349    # screen
350   
351At this point you can have multiple terminal sessions open in a single ssh window. Let's start
352the tcpdump process listening for dhcp requests:
353
354    # tcpdump -s0 -ni eth0 port 67 or port 68
355
356Now use screen to open another "screen" in your ssh terminal window.
357
358        Press ctrl-a c
359   
360To figure out what "-s0", "-n" and "-i" are doing you can read the tcpdump man page:
361
362        # man tcpdump
363       
364Search for "-s" by typing a "/" and then "-s" and then press ENTER. Press "n" to see the next
365occurrence of the string "-s".
366
367Now make a dhcp request for a new address for eth0 on your machine:
368
369        # dhcpclient
370       
371Return to the previous screen to see what tcpdump displays:
372
373        Press "ctrl-a p"                ("p" for previous, "n" for next" to cycle through screens)
374
375You should see some output like this:
376
377tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
378listening on eth0, link-type EN10MB (Ethernet), capture size 65535 bytes
37918:03:05.003190 IP 0.0.0.0.68 > 255.255.255.255.67: BOOTP/DHCP, Request from 52:54:4a:5e:68:77, length 300
38018:03:05.004349 IP 10.10.0.254.67 > 10.10.0.250.68: BOOTP/DHCP, Reply, length 300
381
382        To stop the tcpdump session type "ctrl-c"
383
384Do you know what this means? Why did we specify to listen on ports 67 and 68? If you look in the
385file /etc/services you will find the following defintions for ports 67 and 68
386
387bootps           67/udp     # Bootstrap Protocol Server
388bootps           67/tcp     # Bootstrap Protocol Server
389bootpc           68/udp     # Bootstrap Protocol Client
390bootpc           68/tcp     # Bootstrap Protocol Client
391
392You can return the screen where you ran dhcpclient and exit from the screen if you wish:
393
394        ctrl-a-n
395       
396Then type:
397
398        # exit
399       
400If you are interested in the screen utility and how it works see:
401
402        http://www.howtoforge.com/linux_screen
403
404for more information or ask your instructor.
405
406
4074. Using iperf
408--------------
409
410First we need to install iperf:
411
412        $ sudo apt-get install iperf
413
414Use "man iperf" or "iperf -h" for help.
415
416Ask your neighbor to run:
417
418        $ iperf -s
419
420Connect to your neighbor's machine using:
421
422        $ iperf -c ipNeighbor
423
424If you don't know the IP address of your neighbor's machine ask them to
425do:
426
427        $ ifconfig eth0
428
429and tell you what IP address their machine is using.
430
431How much throughput is there between your machines? You can repeat this
432exercise with any remote machine where iperf is installed and you have
433an account. This is a quick way to see what bandwidth looks like between
434two points.
435
436To stop the iperf server where you ran "iperf -s" press CTRL-c.
437
438If you have time continue playing with iperf options. If you have a
439remote PC running UNIX or Linux you might want to try installing iperf
440and testing your connection from the workshop lab to your remote
441machine.
442
443Some more things to try...
444
445* Test TCP using various window sizes (-2).
446
447* Verify TCP MSS (-m). How does this affect throughput? What is
448  Path MTU discovery?
449
450* Test with two parallel threads (-P) and compare the totals. Is
451  there any difference? Why?
452
453* Test with different packet sizes and the TCP_NODELAY (-N) option.