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 int tx_switch(struct cli_def
*cli
)
27 // These handles are only used when creating L3 and above packets.
28 libnet_t
*l
; // the context
29 libnet_ptag_t t2
=0, t3
=0, t4
=0; // handles to layers
40 if (send_arp()==-1) return 0;
44 if (send_bpdu()==-1) return 0;
48 if (send_cdp()==-1) return 0;
51 case IP
: // From now on a new much more modular method is used:
52 l
= get_link_context();
53 t3
= create_ip_packet(l
); // t3 can be used for later header changes
54 if (!quiet
) complexity();
55 if (tx
.packet_mode
==0) // Ethernet manipulation features does NOT use ARP to determine eth_dst
56 t2
= create_eth_frame(l
, t3
, t4
); // t2 can be used for later header changes
58 send_frame (l
, t3
, t4
); // NOTE: send_frame also destroys context finaly
63 l
= get_link_context();
64 t4
= create_icmp_packet(l
); // t4 can be used for later header changes
66 t3
= create_ip_packet(l
); // t3 can be used for later header changes
67 if (!quiet
) complexity();
68 if (tx
.packet_mode
==0) // Ethernet manipulation features does NOT use ARP to determine eth_dst
69 t2
= create_eth_frame(l
, t3
, t4
); // t2 can be used for later header changes
71 send_frame (l
, t3
, t4
); // NOTE: send_frame also destroys context finaly
76 l
= get_link_context();
77 t4
= create_udp_packet(l
); // t4 can be used for later header changes
79 t3
= create_ip_packet(l
); // t3 can be used for later header changes
80 if (!quiet
) complexity();
81 if (tx
.packet_mode
==0) // Ethernet manipulation features does NOT use ARP to determine eth_dst
82 t2
= create_eth_frame(l
, t3
, t4
); // t2 can be used for later header changes
84 send_frame (l
, t3
, t4
); // NOTE: send_frame also destroys context finaly
89 l
= get_link_context();
90 t4
= create_tcp_packet(l
); // t4 can be used for later header changes
92 t3
= create_ip_packet(l
); // t3 can be used for later header changes
93 if (!quiet
) complexity();
94 if (tx
.packet_mode
==0) // Ethernet manipulation features does NOT use ARP to determine eth_dst
95 t2
= create_eth_frame(l
, t3
, t4
); // t2 can be used for later header changes
97 send_frame (l
, t3
, t4
); // NOTE: send_frame also destroys context finaly
102 l
= get_link_context();
103 if (create_dns_packet()==-1) return 0;
104 t4
= create_udp_packet(l
); // t4 can be used for later header changes
105 t3
= create_ip_packet(l
); // t3 can be used for later header changes
106 if (!quiet
) complexity();
107 if (tx
.packet_mode
==0) // Ethernet manipulation features does NOT use ARP to determine eth_dst
108 t2
= create_eth_frame(l
, t3
, t4
); // t2 can be used for later header changes
110 send_frame (l
, t3
, t4
); // NOTE: send_frame also destroys context finaly
115 l
= get_link_context();
116 if (create_rtp_packet()==-1) return 0;
117 cli_print(cli
, "RTP mode! (count=%u, delay=%u usec)\n", tx
.count
, tx
.delay
);
118 t4
= create_udp_packet(l
); // t4 can be used for later header changes
119 t3
= create_ip_packet(l
); // t3 can be used for later header changes
120 if (!quiet
) complexity();
121 if (tx
.packet_mode
==0) // Ethernet manipulation features does NOT use ARP to determine eth_dst
122 t2
= create_eth_frame(l
, t3
, t4
); // t2 can be used for later header changes
124 send_frame (l
, t3
, t4
); // NOTE: send_frame also destroys context finaly
127 case RX_RTP
: // Receive RTP packets
134 l
= get_link_context();
135 if (create_syslog_packet()==-1) return 0;
136 t4
= create_udp_packet(l
); // t4 can be used for later header changes
137 t3
= create_ip_packet(l
); // t3 can be used for later header changes
138 if (!quiet
) complexity();
140 if (tx
.packet_mode
==0) // Ethernet manipulation features does NOT use ARP to determine eth_dst
141 t2
= create_eth_frame(l
, t3
, t4
); // t2 can be used for later header changes
143 send_frame (l
, t3
, t4
); // NOTE: send_frame also destroys context finaly
146 case LLDP
: // start with a new concept here
147 //l = get_link_context();
148 //(void) create_lldp_packet();
149 // // // printf("SIZE=%lu\n",sizeof(struct tx_struct));
154 cli_print(cli
,"Unknown mode!\n");
159 // ***** Re-init packet functions: *****
162 tx
.tcp_payload_s
= 0;
163 tx
.icmp_payload_s
= 0;
166 // **************************************
170 cpu_time_used
= ((double) (mz_stop
- mz_start
)) / CLOCKS_PER_SEC
;
171 if (cpu_time_used
> 0)
173 total_d
/= cpu_time_used
;
174 cli_print(cli
, "%.2f seconds (%.Lf packets per second)\n",cpu_time_used
,total_d
);