Showing posts with label tcpdump. Show all posts
Showing posts with label tcpdump. Show all posts

Saturday, July 2, 2011

Cold Interweb Tubes in Action

‹prev | My Chain | next›

Last night I started play with tcptrace and xplot.org as tools to graphically analyze network traffic (mostly as it relates to SPDY and competing protocols). One thing that struck me as odd was the Firefox graph of a small image loaded on a "warm" interweb tube:



This particular tube had been warmed by first downloading a very large image over it. A "warm" interweb tube is a TCP/IP stream that has gone through the "slow start" period of it connection. At first, the congestion window (CWND), the amount of data that is sent before waiting for an acknowledgement, is quite small (on the order a network MTU). After a few round trips, the CWND has expanded significantly, allowing for larger chunks of data to be transferred.

The Firefox tube was definitely warm, but there are still those steps that look very much like additional warming. So what gives?

To answer that, I try downloading the same small image (http://www.ducksong.com/sortbycwnd/b.png, taken from the blog post on Firefox CWND) using curl. That should definitely be a cold tube.

But first, I open a tcpdump session to capture the packets going back and forth between the ducksong.com server:
sudo tcpdump -i usb0 host www.ducksong.com -w 02-ducksong_curl.pcap
Then I curl the PNG:
curl http://www.ducksong.com/sortbycwnd/b.png > /dev/null
And then I xplot.org the data in that tcpdump file:
➜  02  tcptrace -S -n 02-ducksong_curl.pcap
1 arg remaining, starting with '/home/cstrom/repos/spdybook/notes/2011/07/02/02-ducksong_curl.pcap'
Ostermann's tcptrace -- version 6.6.7 -- Thu Nov 4, 2004

58 packets seen, 58 TCP packets traced
elapsed wallclock time: 0:00:00.002043, 28375 pkts/sec analyzed
trace file elapsed time: 0:00:00.808258
TCP connection info:
1: 192.168.42.48:32807 - 64.22.125.164:80 (a2b) 29> 29< (complete)
I am not resolving any network resources (-n). I see 58 total packets, 29 going and 29 coming back. All packets are over a single tube, which tcptrace labels as a2b. tcptrace dumps to Time-Sequence plot, one for the request (a2b) and one for the response.

I xplot.org the response (b2a) to find:



That is pretty much what I expect on a cold tube. A couple of packets sent back, then a pause as a TCP/IP acknowledgement is sent, then a few more packets (more than the first clump), followed by another pause for an acknowledgement. Lastly comes the remaining data. The entire PNG image is transferred in around 2 tenths of a second (from the 12.55 second mark to the 12.75 second mark).

Next up, I try the same thing with Chrome. I follow the same experiment that I did yesterday warming a bunch of tubes (by downloading the main page from the blog post mentioned earlier). Then I click on that PNG. Examining the PNG network traffic in a Time-Sequence plot, I find:



That is really what I expected from a warmed tube. No waits for the CWND to increase, just pure download. And, without the warming overhead, nearly 50% less time is needed to transfer the image (no wonder SPDY aims to just use a single warm tube).

So what gives with the Firefox plot. Maybe I simple drew it at a bad scale? Aligning it to a window of ~3 tenths of a second like the other, I find:



Hrm... That's not it. Maybe I just need to retry the experiment again:



Hrm... Well. Firefox seems to be generating a small step for me regardless. I think I can chalk this up to small sample size for now, but I will definitely look into this more later. I would hate to have to explain those steps in SPDY Book if I don't have to (and it doesn't help with the narrative).

Regardless, both the latest Chrome (14) and Firefox (5) both seem to re-use high CWND tubes on secondary requests, significantly cutting down on network travel time for such requests.

Day #63

Friday, July 1, 2011

SPDY Graphs

‹prev | My Chain | next›

Playing with Firefox and CWND has given me a hankering to make cool graphs.

No really.

The mozilla bug that spurred Firefox's new connection sorting by CWND had an associated blog post with some nice graphs in it.

Those graphs got me to thinking that I have no way of making nice graphs for SPDY Book (now in beta!). Hence the hankering for graphs.

Wireshark has some graphing tools under its Statistics menu. It even has Time-Sequence graphs (under TCP Stream Graph) that seem very close to what is in the Firefox post. But no matter what I try, I cannot get the graph to zoom into particular sections of traffic (at least that is how it was for me under Ubuntu).

That led me to investigate tcptrace which boast all manner of graphs, including the Time-Sequence graphs that I desire (via a -S command-line option). Best of all, it runs against the tcpdump data that I dumped into a file yesterday.

Running the command yields:
➜  30 git:(master) tcptrace -S -n 03-ducksong_ff.pcap
1 arg remaining, starting with '03-ducksong_ff.pcap'
Ostermann's tcptrace -- version 6.6.7 -- Thu Nov 4, 2004

6911 packets seen, 6911 TCP packets traced
elapsed wallclock time: 0:00:00.209689, 32958 pkts/sec analyzed
trace file elapsed time: 0:00:43.906356
TCP connection info:
1: 192.168.0.4:55906 - 64.22.125.164:80 (a2b) 8> 5< (complete)
2: 192.168.0.4:55907 - 64.22.125.164:80 (c2d) 7> 5< (complete)
3: 192.168.0.4:55908 - 64.22.125.164:80 (e2f) 6> 4< (complete)
4: 192.168.0.4:55909 - 64.22.125.164:80 (g2h) 1794> 2550<
5: 192.168.0.4:55910 - 64.22.125.164:80 (i2j) 1034> 1498< (complete)
It takes me a while, but eventually, I realize that these are the 5 tubes opened by Firefox when it accessed the test page.

The numbers in the last two columns (ignoring the complete column) are the number of packets that are sent in each direction. I am most interested in the largest connection that, by virtue of Firefox CWND sorting, should have been the tube that handled subsequent requests.

That ought to be the connection labelled g2h. I think the graph in which I am interested is the server response, not the client request side, so I want the h2g xplot output file:
➜  30 git:(master) ✗ ls -l
total 21108
-rw-r--r-- 1 cstrom cstrom 6415796 2011-06-30 23:18 01-ducksong_chrome.pcap
-rw-r--r-- 1 cstrom cstrom 6409982 2011-06-30 23:18 02-ducksong_ff.pcap
-rw-r--r-- 1 cstrom cstrom 6420473 2011-06-30 23:18 03-ducksong_ff.pcap
-rw-r--r-- 1 cstrom cstrom 2124 2011-07-01 23:45 a2b_tsg.xpl
-rw-r--r-- 1 cstrom cstrom 2405 2011-07-01 23:45 b2a_tsg.xpl
-rw-r--r-- 1 cstrom cstrom 1888 2011-07-01 23:45 c2d_tsg.xpl
-rw-r--r-- 1 cstrom cstrom 2185 2011-07-01 23:45 d2c_tsg.xpl
-rw-r--r-- 1 cstrom cstrom 1609 2011-07-01 23:45 e2f_tsg.xpl
-rw-r--r-- 1 cstrom cstrom 1744 2011-07-01 23:45 f2e_tsg.xpl
-rw-r--r-- 1 cstrom cstrom 654658 2011-07-01 23:45 g2h_tsg.xpl
-rw-r--r-- 1 cstrom cstrom 809240 2011-07-01 23:45 h2g_tsg.xpl
-rw-r--r-- 1 cstrom cstrom 383019 2011-07-01 23:45 i2j_tsg.xpl
-rw-r--r-- 1 cstrom cstrom 473634 2011-07-01 23:45 j2i_tsg.xpl
Running xplot against that file, I see:



Ooh! That looks about right. The bulk of the graph is the request for the large file that warms the tube (increasing the CWND). The last little bit on the right is the request for the small image.

Zooming, I see the request for the small image itself:



Nice! I expected a straighter line than that, but the time between the first segment and the last is about right. That will do for today. I think these graphs will server quite nicely for my purposes in SPDY Book.

Day #62

Friday, April 29, 2011

Low Level SPDY Debugging

‹prev | My Chain | next›

In response to my pull request on the SPDY gem, Ilya mentioned that the SPDY version that he saw in the packets was 2—despite Draft #2 of the SPDY protocol stating that it ought to be 1. That got me wondering, how does one see real SPDY packets?

I half hoped to see this in the Network section of the Developer tools. No such luck.

My next stop is the Events tab on the chrome://net-internals page in Chrome. There, I see:
www.google.com:443 (DIRECT)

Start Time: Fri Apr 29 2011 16:56:10 GMT-0400 (EDT)

(P) t=1304110570969 [st= 0] +SPDY_SESSION [dt=?]
--> host = "www.google.com:443"
--> proxy = "DIRECT"
(P) t=1304110570969 [st= 0] SPDY_SESSION_SEND_SETTINGS
--> settings = ["[4:100]"]
(P) t=1304110570971 [st= 2] SPDY_SESSION_RECV_SETTINGS
--> settings = ["[4:100]"]
(P) t=1304113104957 [st= 2533988] SPDY_SESSION_SEND_RST_STREAM
--> status = 5
--> stream_id = 175
(P) t=1304113461199 [st= 2890230] SPDY_SESSION_SYN_STREAM
--> flags = 1
--> accept: */*
accept-charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3
accept-encoding: gzip,deflate,sdch
accept-language: en-US,en;q=0.8
cookie: [value was stripped]
host: www.google.com
method: GET
scheme: https
url: /voice/b/0/request/unread/?b=0
user-agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/534.30 (KHTML, like Gecko) Chrome/12.0.742.9 Safari/534.30
version: HTTP/1.1
--> id = 201
(P) t=1304113461266 [st= 2890297] SPDY_SESSION_SYN_REPLY
--> flags = 0
--> cache-control: no-cache, no-store, must-revalidate
content-disposition: attachment
content-encoding: gzip
content-length: 148
content-type: text/javascript; charset=UTF-8
date: Fri, 29 Apr 2011 21:44:21 GMT
expires: Fri, 01 Jan 1990 00:00:00 GMT
pragma: no-cache, no-store
server: GSE
status: 200 OK
version: HTTP/1.1
x-content-type-options: nosniff
x-frame-options: SAMEORIGIN
x-xss-protection: 1; mode=block
--> id = 201
(P) t=1304113461271 [st= 2890302] SPDY_SESSION_RECV_DATA
--> flags = 0
--> size = 148
--> stream_id = 201
Nice. That looks to be a SPDY session between the Google Voice extension and the Google servers. In there, I see all the fields that I have come to know and love over the past couple of days. This looks to be an invaluable tool in debugging SPDY sessions. Except...

I do not see the SPDY version in any of those packets. So what do I do if I need to do even lower level debugging than this?

I quickly scan through the tool and debugging page from the SPDY project. That does not seem to be of much help because it suggests that the Network tab in the Developer Tools ought to support SPDY debugging, which it does not. I give the Speed Tracer extension a whirl, but it also does not include SPDY information.

It seems that I am stuck with good old tcpdump, which is a fairly nice place to be stuck. To use it, though, I need to turn off SSL in examples/spdy_server.rb of the SPDY gem:
...
def post_init
@parser = SPDY::Parser.new
@parser.on_headers_complete do |stream_id, associated_stream, priority, headers|
#...
end

# start_tls
end
I also need to start Chrome without SSL in SPDY:
google-chrome --use-spdy=no-ssl
Lastly, I start a tcpdump session:
➜  spdy git:(master) ✗ sudo tcpdump -i lo -X -s0 port 10000
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on lo, link-type EN10MB (Ethernet), capture size 65535 bytes
And load the page. In the tcpdump output, I see:
...
23:23:11.696498 IP localhost.localdomain.webmin > localhost.localdomain.33000: Flags [P.], seq 1:91, ack 305, win 265, options [nop,nop,TS val 33869373 ecr 33869372], length 90
0x0000: 4500 008e 1038 4000 4006 2c30 7f00 0001 E....8@.@.,0....
0x0010: 7f00 0001 2710 80e8 7f76 de0b 7f7f d955 ....'....v.....U
0x0020: 8018 0109 fe82 0000 0101 080a 0204 ce3d ...............=
0x0030: 0204 ce3c 8002 0002 0000 0035 0000 0009 ...<.......5....
0x0040: 0000 78bb dfa2 51b2 6260 66e0 7186 0652 ..x...Q.b`f.q..R
0x0050: 0830 9018 b810 7630 b041 9433 b001 93b1 .0....v0.A.3....
0x0060: 82bf 3703 3b54 2303 07cc 3c00 0000 00ff ..7.;T#...<.....
0x0070: ff00 0000 0900 0000 0d54 6869 7320 6973 .........This.is
0x0080: 2053 5044 592e 0000 0009 0100 0000 .SPDY.........
...
I am most interested in the first four bytes of the bold section, 8002. The control bit at the very beginning of the SYN_REPLY generates the 8. The remaining 002 is the version of the protocol being used, which is, indeed, version 2, not 1 as the Draft Specification says.

Just to be sure I am looking at the right bit of information, the next 4 bytes, 0002 should contain the message type. In the case of a SYN_REPLY, it should be 2—which it is—so I am definitely looking at the right response here.

Similarly, the SYN_STREAM from the browser sends 8002 0001 so even the browser is sending version 2.

In the grand scheme of things, whether it is version 1 or 2 does not make much difference. I am content knowing that I have a mechanism to troubleshoot this stuff at a very low level. I just hope I do not have to make a habit of it.

Before moving on with my exploration, I think I will give ssldump a whirl. It would be nice to be able to see the same information without the special Chrome flags. I will pick back up there tomorrow.

Day #5