Skip to content

Commit

Permalink
incorporated patches for ns FullTcp extra headers from Angelos Stavrou
Browse files Browse the repository at this point in the history
(angelos@ee.columbia.edu)
  • Loading branch information
weddy committed Jul 22, 2002
1 parent 9ed8722 commit 1890907
Show file tree
Hide file tree
Showing 5 changed files with 195 additions and 20 deletions.
3 changes: 3 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -419,3 +419,6 @@ are interested in running tcptrace on OpenVMS.
Changes made to code in order to be able to compile tcptrace under cygwin on
Windows. Now works on windows too. Does not support reading compressed dump
files directly though.

The ns code was modified by Angelos Stavrou to read in the more detailed
output from the extra headers in the ns FullTcp.
2 changes: 2 additions & 0 deletions THANKS
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,5 @@ or ported the program to other architectures:
Matt Muggeridge (Matt.Muggeridge@compaq.com) for porting tcptrace to
OpenVMS and providing us with detailed documentation for the
same.
Angelos Stavrou (angelos@ee.columbia.edu) for adding support for the
reading of headers from ns FullTcp agents.
199 changes: 182 additions & 17 deletions ns.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,15 +134,19 @@ pread_ns(
&ipb->ip_dst.s_addr,
&tcpb->th_dport,
&seq,
&ipb->ip_id);
&ipb->ip_id,
&junk, /*don't care since it is not FullTCP */
&junk,
&junk,
&junk);

/* if we can't match all 14 fields, we give up on the file */
if (rlen != 14) {
fprintf(stderr,"Bad ns packet header in line %u\n", linenum);
/* if we reach the End Of File we stop */
if (rlen == EOF) {
return(0);
}

if (rlen == EOF) {
/* if we can't match all 14 fields, we give up on the file */
if (rlen != 14 && rlen != 18) {
fprintf(stderr,"Bad NS packet header in line %u only [%d] arguments can be matched expected 14 or 18 \n", linenum, rlen);
return(0);
}

Expand All @@ -154,10 +158,19 @@ pread_ns(
/* if it's not a TCP data segment or ACK, discard and try again */
if (!is_tcp && !is_ack)
continue;


if ((!ns_hdrs && is_tcp) || (ns_hdrs && packlen ==0))
*plen = *plen + sizeof(struct ip) + sizeof(struct tcphdr);

if (packlen == 0 && is_tcp)
packlen = *plen - sizeof(struct ip) - sizeof(struct tcphdr);
packlen = *plen - sizeof(struct ip) - sizeof(struct tcphdr);

if (ns_hdrs && is_tcp)
packlen = *plen- sizeof(struct ip) - sizeof(struct tcphdr);

if (is_ack) /* this is explicitly for SACK that creates packets > 40 Bytes*/
*plen = 40;

ipb->ip_len = htons(*plen);

if (is_tcp) {
Expand Down Expand Up @@ -225,7 +238,7 @@ pread_ns(
e = d * 1000000.0;
ptime->tv_usec = e;

*ptlen = *plen;
*ptlen = *plen;

*ppip = (struct ip *) pip_buf;
*pplast = (char *)pip_buf + *plen;
Expand All @@ -241,6 +254,147 @@ pread_ns(
}
}

pread_ns_fulltcp(
struct timeval *ptime,
int *plen,
int *ptlen,
void **pphys,
int *pphystype,
struct ip **ppip,
void **pplast)
{
double c, d, e;
while (1) {
/* read the packet info */

char tt;
double timestamp;
int junk;
char type[100];
char flags[100];
int iteration;
int seqno;
int ackno;
int hdrlen;
int is_ack;
int is_tcp;
int pflags;
int rlen;

++linenum;

/* correct NS output line would have 14 fields if show_tcphdr_ is 0: */
/* For Full TCP this changes to 18 fields when show_tcp is 1*/
rlen = fscanf(stdin, "%c %lg %d %d %s %d %s %d %d.%hu %d.%hu %d %d %d 0x%x %u %hu\n",
&tt,
&timestamp,
&junk,
&junk,
type,
plen,
flags,
&iteration,
&ipb->ip_src.s_addr,
&tcpb->th_sport,
&ipb->ip_dst.s_addr,
&tcpb->th_dport,
&seqno,
&ipb->ip_id,
&ackno,
&pflags,
&hdrlen,
&junk);

/* if we reach the End of File we stop */
if (rlen == EOF) {
return(0);
}
/* if we can't match all 18 fields, we give up on the file */
if (rlen != 18) {
fprintf(stderr,"Bad NS packet header in line %u only [%d] arguments can be matched expected 14 or 18 \n", linenum, rlen);
fprintf(stderr,"Is this a Full Tcp Header?\n");
return(0);
}

tcpb->th_sport = tcpb->th_dport = iteration;
is_tcp = strcmp(type, "tcp") == 0;
is_ack = strcmp(type, "ack") == 0;

/* if it's not a TCP data segment or ACK, discard and try again */
if (!is_tcp && !is_ack)
continue;

/* we have biger header than 40 Bytes (SACK?) */
if (hdrlen > sizeof(struct ip) + sizeof(struct tcphdr)){
*plen = *plen - (hdrlen - (sizeof(struct ip) - sizeof(struct tcphdr)));
}

ipb->ip_len = htons(*plen);

if (is_tcp && (*plen > hdrlen)) { /*for empty tcp packets acting as acks*/
tcpb->th_seq = htonl(seqno);
tcpb->th_ack = 0;
} else {
tcpb->th_seq = 0;
tcpb->th_ack = htonl(ackno);
}

/* make up a reasonable IPv4 packet header */
ipb->ip_hl = 5; /* no options, normal length of 20 */
ipb->ip_v = 4; /* IPv4 */
ipb->ip_tos = 0;
ipb->ip_off = 0;
ipb->ip_ttl = 64; /* nice round number */
ipb->ip_p = 6; /* TCP */
ipb->ip_sum = 0; /* IP checksum, hope it doesn't get checked! */
ipb->ip_id = ipb->ip_id;

/* is the transport "ECN-Capable"? */
if (strchr(flags, 'N') != NULL)
ipb->ip_tos |= IPTOS_ECT;

/* was the "Experienced Congestion" bit set? */
if (strchr(flags, 'E') != NULL)
ipb->ip_tos |= IPTOS_CE;

/* make up a reasonable TCP segment header */
tcpb->th_off = 5; /* no options, normal length of 20 */
tcpb->th_flags = pflags; /* sdo: what about first SYN?? */
tcpb->th_x2 = 0;
tcpb->th_sum = 0;
tcpb->th_urp = 0;
tcpb->th_win = htons(65535);

/* x2 *was* reserved, now used for ECN bits */

if (strchr(flags, 'C') != NULL)
tcpb->th_x2 |= TH_ECN_ECHO;
if (strchr(flags, 'A') != NULL)
tcpb->th_x2 |= TH_CWR;

/* convert floating point timestamp to (tv_sec,tv_usec) */
c = floor(timestamp);
ptime->tv_sec = c;
d = timestamp - (double) ptime->tv_sec;
e = d * 1000000.0;
ptime->tv_usec = e;

*ptlen = *plen;

*ppip = (struct ip *) pip_buf;
*pplast = (char *)pip_buf + *plen;
*pphys = pep;
*pphystype = PHYS_ETHER;


/* printf("timestamp %g, type %s, plen %d, seq %d, id %d, ack %d, 0x%x %d \n",
timestamp, type, *plen, seqno, ipb->ip_id,ackno,pflags,hdrlen);*/


return(1);
}
return(0);
}


/*
Expand All @@ -249,22 +403,27 @@ pread_ns(
pread_f *is_ns(char *filename)
{
int rlen;
char tt;
int junk;
double junkd;
char junks[20];
int hdrlen = 0;
int pflags = 0;

#ifdef __WIN32
if((fp = fopen(filename, "r")) == NULL) {
perror(filename);
exit(-1);
}
#endif /* __WIN32 */

if ((rlen = getc(SYS_STDIN)) == EOF) {
rewind(SYS_STDIN);

rlen = fscanf(stdin, "%c %lg %d %d %s %d %s %d %d.%hu %d.%hu %d %d %d 0x%x %u %hu\n", &tt, &junkd, &junk, &junks, &junk, &junks, &junk, &junk, &junk, &junk, &junk, &junk, &junk, &junk, &junk, &pflags, &hdrlen, &junk);

if ((rlen = getc(stdin)) == EOF) {
return(NULL);
}

rewind(SYS_STDIN);

switch (rlen) {
switch (tt) {
case '+':
case '-':
case 'h':
Expand All @@ -287,7 +446,13 @@ pread_f *is_ns(char *filename)

/* init line count (we might be called several times, must be done here) */
linenum = 0;

return(pread_ns);
/* Lets check if it is FullTCP or not*/
if (hdrlen || pflags){ /*it is FullTCP */
/* printf("Full TCP \n"); */
return(pread_ns_fulltcp);
}
else{ /*Regular TCP (with or without tcpheaders activated */
return(pread_ns);
}
}
#endif /* GROK_NS */
10 changes: 7 additions & 3 deletions tcptrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ Bool triple_dupack_allows_data = FALSE;
Bool run_continuously = FALSE;
Bool xplot_all_files = FALSE;
Bool conn_num_threshold = FALSE;
Bool ns_hdrs = TRUE;
u_long remove_live_conn_interval = REMOVE_LIVE_CONN_INTERVAL;
u_long remove_closed_conn_interval = REMOVE_CLOSED_CONN_INTERVAL;
u_long update_interval = UPDATE_INTERVAL;
Expand Down Expand Up @@ -244,7 +245,9 @@ static struct ext_bool_op {
"limit the maximum number of connections kept at a time in real-time mode"},
{"xplot_all_files", &xplot_all_files, TRUE,
"display all generated xplot files at the end"},

{"ns_hdrs", &ns_hdrs, TRUE,
"assume that ns has the useHeaders_ flag true (uses IP+TCP headers)"},

};
#define NUM_EXTENDED_BOOLS (sizeof(extended_bools) / sizeof(struct ext_bool_op))

Expand Down Expand Up @@ -2006,9 +2009,10 @@ DumpFlags(void)
fprintf(stderr,"beginning pnum: %lu\n", beginpnum);
fprintf(stderr,"ending pnum: %lu\n", endpnum);
fprintf(stderr,"throughput intvl: %d\n", thru_interval);
fprintf(stderr,"number modules: %u\n", (unsigned)NUM_MODULES);
fprintf(stderr,"NS simulator hdrs:%u\n", BOOL2STR(ns_hdrs));
fprintf(stderr,"number modules: %u\n", (unsigned)NUM_MODULES);
fprintf(stderr,"debug: %s\n", BOOL2STR(debug));

/* print out the stuff controlled by the extended boolean args */
for (i=0; i < NUM_EXTENDED_BOOLS; ++i) {
struct ext_bool_op *pbop = &extended_bools[i];
Expand Down
1 change: 1 addition & 0 deletions tcptrace.h
Original file line number Diff line number Diff line change
Expand Up @@ -670,6 +670,7 @@ extern Bool docheck_hw_dups;
extern Bool run_continuously;
extern Bool conn_num_threshold;
extern Bool xplot_all_files;
extern Bool ns_hdrs;
extern u_long remove_live_conn_interval;
extern u_long remove_closed_conn_interval;
extern u_long update_interval;
Expand Down

0 comments on commit 1890907

Please sign in to comment.