All Classes Namespaces Files Functions Pages
Tutorial: 4. Create a Frame

Previous: Tutorial: 3. Create our src-port and dst-port

To easily create a Frame, we use a procedure which is available in our excentis_basic package. This procedure will generate the bytes of our frame that we can set on our Frame. First we need to resolve our destination Mac address. Following snippet will send an ARP request from our source port to resolve the Mac address.

1 #
2 # --- Get the destination MAC addresses for our UDP frame to reach the other port ---
3 #
4 #- Sending an Arp for the destination IP of our UDP frame.
5 set dmacBackToBackDestination [ $srcL3 Protocol.Arp [ $dstL3 Ip.Get ] ]

Protocol.Arp will have as effect the transmission of an ARP packet to resolve the destination. It will return the resolved Mac address.

Note
Depending on the setup: the Mac address of our destination port or the Mac address of our gateway.

If it fails, it will throw an exception. Now that we have our destination Mac address, we can generate the bytes of our Frame. We will create an UDP frame of length 64Bytes ( incl Ethernet FCS ) between UDP port 2001 and 2002.

First, we define our Frame content settings:

1 set dstUdpPort 2002
2 set srcUdpPort 2001
3 # length exclude FCS
4 set udpLength 60

Now, we can generate the actual Frame content:

1 set srcFrameContent [ ::excentis::basic::Frame.Udp.Set $dmacBackToBackDestination [ $srcL2 Mac.Get ] [ $dstL3 Ip.Get ] [ $srcL3 Ip.Get ] $dstUdpPort $srcUdpPort [ list -Length $udpLength ] ]

As you can see, Layer2 and Layer3 settings are obtained from the current settings of the source and destination port. The destination Mac address is the one we just resolved.

This line of code will return the string representation of the bytes of our frame. If you want to provide UDP content you could create your frame this way

1 set udpPayload [ list 0xAA 0xBB 0xCC 0xDD ]
2 set srcFrameContent [ ::excentis::basic::Frame.Udp.Set $dmacBackToBackSource [ $srcL2 Mac.Get ] [ $dmacBackToBackSource Ip.Get ] [ $srcL3 Ip.Get ] $dstUdpPort $srcUdpPort $udpPayload

where 0xAA 0xBB 0xCC 0xDD represents the UDP payload

Further reading: Tutorial: 5. Define a Flow