Testing - adwinying/FreeLwIP-Nios-II GitHub Wiki

Testing TCP/IP Stack

To test the TCP/IP stacks, one would need to send various network packets to the target device and ensure the correct network packets are sent back to the user.

Pre-requisites

Generating packets

There are various ways of generating packets for testing. The method listed here captures existing packets from Wireshark, edits the packet in WireEdit then finally sends the packet in Ostinato.

Wireshark

  1. Launch Wireshark. Under Capture, select the network interface where your network is connected to (Eg: Local Area Connection).
  2. Automatically Wireshark will start capturing packets. Since the packets are moving at a very fast rate, enter the protocol of the packet that you would want to capture (Eg: arp)
  3. Once you have captured sufficient packets (1 or 2 is sufficient), Stop capturing packets by pressing the 2nd button from the left.
  4. Select packets that you want to save by holding down Ctrl and click on the packets.
  5. To save the packets, go to File > Export Specified Packets.
  6. At the save dialog, under Packet Range select Select packet and ensure the number shows the number of packets selected previously.
  7. As for file type, select Wireshack/tcpdump/. Ensure packets are saved with extension *.pcap.
  8. Choose save directory and file name then click Save.
  9. Done. Proceed to editing packets.

Editing Packets

  1. Launch WireEdit.
  2. Open the *.pcap file that you saved previously. Alternatively, you can drag and drop the file into WireEdit.
  3. Expand the packet by pressing the + sign.
  4. Depending on the type of packet, proceed to the next step below:

ARP (Address Resolution Protocol)

An ARP packet is used to know the MAC address of a target device. Read more about ARP

ARP has two types of packets: request and reply. In WireEdit, you can identify the type of ARP under the Type column. For testing purposes, we only use the request packet. For ARP packets, modifications are only necessary for destination & source MAC address and IP address. Generally, the destination MAC address is unknown before sending an ARP packet, hence, the destination MAC address used is FF:FF:FF:FF:FF:FF, which is also known as broadcast. This means that this packet is meant for all devices. The stack is said to be working properly if it returns the ARP packet with it's own MAC address inside the packet, again which can be checked using WireEdit.

Editing MAC address

  1. Expand Ethernet II.
  2. Under Ethernet II, change the Dst and Src with your own destination and source MAC address respectively.
  3. Then click OK.
  4. Repeat the same thing for Sender Hardware Address and Target Hardware Address under ARP:request.
  5. If there is anything highlighted in red, it is a checksum error. Just double click it and it will go away.

Editing IP address

  1. Expand ARP:request.
  2. Under ARP:request, edit Sender Protocol Address and Target Protocol Address with your own source and destination respectively.
  3. Then click OK.
  4. If there is anything highlighted in red, it is a checksum error. Just double click it and it will go away.
  5. Finally, save the packet.
  6. Done. Proceed to sending packets.

ARP

ICMP (PING)

Internet Control Message Protocol (ICMP) is the type of packet used when running ping commands. Read more about ICMP

When a ping command is sent out, it firsts send an ARP packet to find out the MAC address. Then an ICMP packet is sent to see whether the device is responding. The easiest way to get an ICMP packet is to run a ping command in the command prompt, and capture the packet with Wireshark. For ICMP packets, the MAC address and IP address have to be changed as well.

Editing MAC address

  1. Expand Ethernet II.
  2. Under Ethernet II, change the Dst and Src with your own destination and source MAC address respectively.
  3. Then click OK.
  4. If there is anything highlighted in red, it is a checksum error. Just double click it and it will go away.

Editing IP address

  1. Expand IPv4.
  2. Under IPv4, edit Source Address and Destination Address with your own source and destination respectively.
  3. Then click OK.
  4. If there is anything highlighted in red, it is a checksum error. Just double click it and it will go away.
  5. Finally, save the packet.
  6. Done. Proceed to sending packets.

PING

Sending & Monitoring Packets

  1. Prepare Wireshark by launching it and start monitoring. Enter protocol name of the packet you wish to test in the display filter.
  2. Launch Ostinato. On the top left pane, expand the Port Group and select the port your network is running on (Eg: Port 0)
  3. On the top right pane, under the Streams tab, right click the empty area and select Open Streams.
  4. Change the file type to PCAP (*.pcap) and select the edited packets.
  5. If there are existing packets in Ostinato, you can choose to append or overwrite.
  6. Uncheck Intelligent Import (via PDML) and click OK.
  7. Back at the right pane, check the packet(s) you want to send and click Apply at the top right corner.
  8. At the bottom pane, select the port name (Eg: **Port 0-0 *) and press the play button to send the packets.
  9. The packets are sent when the number increases on the Frames Sent row.
  10. Check whether the packet is sent in Wireshark. Additionally, check for a response either via the UART logs or Wireshark.
  11. If the packet sent is difficult to locate in Wireshark, you can press the play button multiple times in a row to identify the packet you sent.
  12. Done.

Ostinato