2 * Mausezahn - A fast versatile traffic generator
3 * Copyright (C) 2008-2010 Herbert Haas
5 * This program is free software; you can redistribute it and/or modify it under
6 * the terms of the GNU General Public License version 2 as published by the
7 * Free Software Foundation.
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, see http://www.gnu.org/licenses/gpl-2.0.html
24 // Calculates the number of TCP transmissions based on SQNR range
25 u_int32_t
mops_tcp_complexity_sqnr (struct mops
* mp
)
27 u_int32_t a
,b
,t
,result
;
29 a
= mp
->tcp_seq_start
;
31 t
= mp
->tcp_seq_delta
;
33 if (!t
) return 1; // delta set to zero means no range
35 if (a
<b
) // regular case
36 result
= ceill ((b
-a
)/t
);
37 else // range wraps around
38 result
= ceill (((0xffffffff-a
) + b
)/t
);
44 // Calculates the number of TCP transmissions based on SQNR range
45 u_int32_t
mops_tcp_complexity_acknr (struct mops
* mp
)
47 u_int32_t a
,b
,t
,result
;
49 a
= mp
->tcp_ack_start
;
51 t
= mp
->tcp_ack_delta
;
53 if (!t
) return 1; // delta set to zero means no range
55 if (a
<b
) // regular case
56 result
= ceill ((b
-a
)/t
);
57 else // range wraps around
58 result
= ceill (((0xffffffff-a
) + b
)/t
);
66 // *****TODO: TCP Options ******
69 int mops_tcp_option_remove_all (struct mops
* mp
)
76 // Prints current flag settings in the provided string 'str'.
77 // NOTE that str must be at least 32 bytes!
78 // *** BETTER USE 64 bytes (for future compatibility) ***
80 int mops_tcp_flags2str (struct mops
* mp
, char *str
)
83 sprintf(str
, "(no valid mops)\n");
87 sprintf(str
, "%s-%s-%s-%s-%s-%s-%s-%s",
88 (mp
->tcp_ctrl_CWR
) ? "CRW" : "---",
89 (mp
->tcp_ctrl_ECE
) ? "ECE" : "---",
90 (mp
->tcp_ctrl_URG
) ? "URG" : "---",
91 (mp
->tcp_ctrl_ACK
) ? "ACK" : "---",
92 (mp
->tcp_ctrl_PSH
) ? "PSH" : "---",
93 (mp
->tcp_ctrl_RST
) ? "RST" : "---",
94 (mp
->tcp_ctrl_SYN
) ? "SYN" : "---",
95 (mp
->tcp_ctrl_FIN
) ? "FIN" : "---");
102 // TODO: currently all params are ignored and a default option combination is added.
104 int mops_tcp_add_option (struct mops
* mp
,
112 u_int8_t tcp_default_options
[] = {
113 0x02, 0x04, 0x05, 0xac, // MSS
114 0x04, 0x02, // SACK permitted
115 0x08, 0x0a, 0x19, 0x35, 0x90, 0xc3, 0x00, 0x00, 0x00, 0x00, // Timestamps
117 0x03, 0x03, 0x05 // Window Scale 5
124 +-------+-------+---------------------+---------------------+
125 |Kind=8 | 10 | TS Value (TSval) |TS Echo Reply (TSecr)|
126 +-------+-------+---------------------+---------------------+
129 * The Timestamps option carries two four-byte timestamp fields. The
130 * Timestamp Value field (TSval) contains the current value of the
131 * timestamp clock of the TCP sending the option.
133 * The Timestamp Echo Reply field (TSecr) is only valid if the ACK bit
134 * is set in the TCP header; if it is valid, it echos a times- tamp
135 * value that was sent by the remote TCP in the TSval field of a
136 * Timestamps option. When TSecr is not valid, its value must be zero.
137 * The TSecr value will generally be from the most recent Timestamp
138 * option that was received; however, there are exceptions that are
141 * A TCP may send the Timestamps option (TSopt) in an initial <SYN>
142 * segment (i.e., segment containing a SYN bit and no ACK bit), and
143 * may send a TSopt in other segments only if it re- ceived a TSopt in
144 * the initial <SYN> segment for the connection.
148 memcpy((void*) mp
->tcp_option
, (void*) tcp_default_options
, 20);
149 mp
->tcp_option_s
= 20;
150 mp
->tcp_option_used
= 1;