1The following C-like psuedocode should help you make tcp plots like
2those in the MIT/LCS/TR-494.  The code below is simultaneously making
3two different plots, one plot for each direction that data can be
4carried on a tcp connection.  In addition to emulating the pseudo code
5below, you'll have to add some boilerplate to the plotter files.  See
6demo.1 for an example tcp plot.
7
8static  struct last {
9  unsigned long ack;
10  unsigned long windowend;
11  struct timeval time;
12} a, b;
13
14typedef struct {
15  unsigned long  a_address;
16  unsigned long  b_address;
17  unsigned short a_port;
18  unsigned short b_port;
19} tcp_pair;
20
21tcp_pair tp;
22
23PLOTTER topl;
24PLOTTER frompl;
25PLOTTER abpl;
26PLOTTER bapl;
27
28for each tcp packet in order {
29  struct ip_header *iph;
30  struct tcp_header *tcph;
31  tcp_pair ttp;
32  unsigned int tcp_length;
33  unsigned int tcp_data_length;
34  unsigned int start;
35  unsigned int end;
36  struct timeval time;
37
38  iph = get_pointer_to_ip_header;
39  ttp = iph2ttp(iph);
40
41  /* figure out which direction this packet is going */
42  if (tp.a_address == ttp.a_address && tp.a_port == ttp.a_port) {
43    topl = bapl;
44    frompl = abpl;
45    r = &a;
46  } else {
47    topl = abpl;
48    frompl = bapl;
49    r = &b;
50  }
51
52  tcph = iph2tcph(iph);
53
54  time = nh->nh_timestamp;
55
56  tcp_length = ntohs(iph->total_length) - (4 * iph->ihl);
57  tcp_data_length =
58    tcp_length - (4 * tcph->data_offset) + tcph->syn + tcph->fin;
59
60  start = ntohl(tcph->sequence_number);
61  end = start + tcp_data_length;
62
63  /* draw the packet */
64
65  plotter_darrow(frompl, time, start);
66  plotter_uarrow(frompl, time, end);
67  plotter_line(frompl, time, start, time, end);
68
69  /* draw the ack and win in the other plotter */
70  if (tcph->ack) {
71    unsigned int ack;
72    unsigned int win;
73    unsigned int winend;
74    ack = ntohl(tcph->acknowledgment_number);
75    win = ntohs(tcph->window);
76    winend = ack + win;
77
78    if (r->time.tv_sec != -1) {
79      plotter_line(topl, r->time, r->ack, time, r->ack);
80      if (r->ack != ack) {
81	plotter_line(topl, time, r->ack, time, ack);
82      } else {
83	plotter_dtick(topl, time, ack);
84      }
85      if (plotwindow) {
86	plotter_line(topl, r->time, r->windowend, time, r->windowend);
87	if (r->windowend != winend) {
88	  plotter_line(topl, time, r->windowend, time, winend);
89	} else {
90	  plotter_utick(topl, time, winend);
91	}
92      }
93    }
94    r->time = time;
95    r->ack = ack;
96    r->windowend = winend;
97  }
98}
99