5

I remember that in Linux (when doing make menuconfig) somewhere there was an option that said something like this:

Use this only if you want to generate network traffic, or if you want to create faulty network traffic

Unfortunately I can't remember where this was or even remember any tool that allows me to actually create such traffic.

What I'm after is

  • creating erroneous ICMP packets
  • injecting high latency or packet loss

on a network which is otherwise perfectly fine.

The purpose is to test the behavior of some applications that have to work with links that are between EU and US. I'd like to "stress test" the application how much latency it will swallow or how much packet loss it can deal with.

6 Answers 6

4

The option you are thinking of is CONFIG_NET_PKTGEN.

2
  • I whish I could upvote twice, it seems like the option I was looking for, plus the link is great. I didn't know there was some "make menuconfig" explanation on the web. Seem like the linuxfoundation site is worth investigating, I filed it under "yeah another enterprise linux site thingie" originally Jun 17, 2009 at 16:30
  • Server Horror, I'll upvote for you :-)
    – rkthkr
    Jun 17, 2009 at 17:09
5

Linux is not so well equipped than FreeBSD here. But you can try Netem with tc (package iproute).

Load Netem

modprobe sch_netem

Drop half of the packets on device tap0:

tc qdisc add dev  tap0 root netem delay 50ms loss 50% 
1
  • tc seems like the userspace tool I was looking for. Thanks. Jun 18, 2009 at 8:39
1

hping lets you generate TCP, UDP, ICMP and RAW-IP protocol packets.

1
  • True, but not to simulate high latency or packet drop.
    – bortzmeyer
    Jun 18, 2009 at 6:16
1

There is also tool called scapy. It can generate almost any type of packet. As author says:

Scapy is a powerful interactive packet manipulation program. It is able to forge or decode packets of a wide number of protocols, send them on the wire, capture them, match requests and replies, and much more. It can easily handle most classical tasks like scanning, tracerouting, probing, unit tests, attacks or network discovery (it can replace hping, 85% of nmap, arpspoof, arp-sk, arping, tcpdump, tethereal, p0f, etc.)

And about packet loss and delay:

  • iptables have --probability option
  • IIRC it can QUEUE packets to insert delay
0

You might also consider using a combination of:

Mixing this with the expected levels of traffic generated by your app.

0

You might also consider using PcapPlusPlus. It has a packet creation engine that supports ICMP and a way to send packets to the network. Here is an example code for what you want (sending high-latency erroneous ICMP packets):

// open a pcap live device for interface with IP 10.0.0.1 (put your IP address instead)
IPv4Address ipToSearch("10.0.0.1");
PcapLiveDevice* liveDev = PcapLiveDeviceList::getInstance().getPcapLiveDeviceByIp(ipToSearch);;
liveDev->open();

int NUM_OF_ERRONEOUS_PACKETS_TO_GENERATE = 1000;

// send NUM_OF_ERRONEOUS_PACKETS_TO_GENERATE echo request packets
for (int i = 0; i < NUM_OF_ERRONEOUS_PACKETS_TO_GENERATE; i++)
{
    // create an Eth layer with whatever MAC addresses you want
    MacAddress srcMac(std::string("11:22:33:44:55:66")); // put the MAC address you want here
    MacAddress destMac(std::string("66:55:44:33:22:11")); // put the MAC address you want here
    EthLayer ethLayer(srcMac, destMac, ETHERTYPE_IP);

    // create IPv4 layer with whatever IPs you want (put the IPs you want instead)
    IPv4Layer ipLayer(IPv4Address(std::string("1.1.1.1")), IPv4Address(std::string("2.2.2.2")));

    // Create ICMP echo (ping) request layer
    IcmpLayer echoReqLayer;
    icmp_echo_request* echoReq = echoReqLayer.setEchoRequestData(100, 0, 0xe45104007dd6a751ULL, NULL, 0);

    // make the echo request erroneous. You can do whatever manipulation you want here
    echoReq->header->checksum = 0x1111;
    echoReq->header->code = 100;

    // create a packet with Eth, IPv4, ICMP echo layers;
    Packet echoRequestPacket(100);
    echoRequestPacket.addLayer(&ethLayer);
    echoRequestPacket.addLayer(&ipLayer);
    echoRequestPacket.addLayer(&echoReqLayer);

    // send the packet
    liveDev->sendPacket(&echoRequestPacket);
}

liveDev->close();

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .