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
- Knowledge on packets
- Wireshark for packet monitoring/sniffing
- WireEdit for packet modifying
- Ostinato for sending packets
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
- Launch Wireshark. Under Capture, select the network interface where your network is connected to (Eg:
Local Area Connection
). - 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
) - Once you have captured sufficient packets (1 or 2 is sufficient), Stop capturing packets by pressing the 2nd button from the left.
- Select packets that you want to save by holding down
Ctrl
and click on the packets. - To save the packets, go to File > Export Specified Packets.
- At the save dialog, under Packet Range select Select packet and ensure the number shows the number of packets selected previously.
- As for file type, select
Wireshack/tcpdump/
. Ensure packets are saved with extension*.pcap
. - Choose save directory and file name then click Save.
- Done. Proceed to editing packets.
Editing Packets
- Launch WireEdit.
- Open the
*.pcap
file that you saved previously. Alternatively, you can drag and drop the file into WireEdit. - Expand the packet by pressing the + sign.
- 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
- Expand
Ethernet II
. - Under
Ethernet II
, change theDst
andSrc
with your own destination and source MAC address respectively. - Then click OK.
- Repeat the same thing for
Sender Hardware Address
andTarget Hardware Address
underARP:request
. - If there is anything highlighted in red, it is a checksum error. Just double click it and it will go away.
Editing IP address
- Expand
ARP:request
. - Under
ARP:request
, editSender Protocol Address
andTarget Protocol Address
with your own source and destination respectively. - Then click OK.
- If there is anything highlighted in red, it is a checksum error. Just double click it and it will go away.
- Finally, save the packet.
- Done. Proceed to sending packets.
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
- Expand
Ethernet II
. - Under
Ethernet II
, change theDst
andSrc
with your own destination and source MAC address respectively. - Then click OK.
- If there is anything highlighted in red, it is a checksum error. Just double click it and it will go away.
Editing IP address
- Expand
IPv4
. - Under
IPv4
, editSource Address
andDestination Address
with your own source and destination respectively. - Then click OK.
- If there is anything highlighted in red, it is a checksum error. Just double click it and it will go away.
- Finally, save the packet.
- Done. Proceed to sending packets.
Sending & Monitoring Packets
- Prepare Wireshark by launching it and start monitoring. Enter protocol name of the packet you wish to test in the display filter.
- Launch Ostinato. On the top left pane, expand the Port Group and select the port your network is running on (Eg: Port 0)
- On the top right pane, under the Streams tab, right click the empty area and select Open Streams.
- Change the file type to
PCAP (*.pcap)
and select the edited packets. - If there are existing packets in Ostinato, you can choose to append or overwrite.
- Uncheck Intelligent Import (via PDML) and click OK.
- Back at the right pane, check the packet(s) you want to send and click Apply at the top right corner.
- At the bottom pane, select the port name (Eg: **Port 0-0 *) and press the play button to send the packets.
- The packets are sent when the number increases on the Frames Sent row.
- Check whether the packet is sent in Wireshark. Additionally, check for a response either via the UART logs or Wireshark.
- 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.
- Done.