How to generate MPLS packets using Ostinato HexDump
Ostinato includes and supports a lot of the commonly used protocols to generate packets. However, from time to time, one may come across a protocol that is not available in Ostinato.
Fear not, Ostinato provides a way to generate packets for protocols that are not available out of the box. Actually it provides two ways, not one.
In this post we will see how to create a MPLS packet by using the first of the two ways - hexdump.
Although this post talks about MPLS, the same method is applicable for any protocol, MPLS is used just as an example here
Let’s look at the MPLS frame format. Let’s assume we need to generate a IP/UDP packet encapsulated inside a MPLS tunnel. So the frame format would consist of the following protocol headers in this order -
+----------+------+----+-----+ | Ethernet | MPLS | IP | UDP | +----------+------+----+-----+
All the protocols in the above frame except MPLS are already supported in Ostinato.
To create this packet in Ostinato, we create a stream and select the protocols - Ethernet II, IPv4, UDP, Hex Dump and then switch to the advanced protocol selection mode -
HexDump protocol in the Selected Protocols list and use the up/down arrows to move it between
Eth II and
Now that we have the HexDump header at the correct place in the packet, let’s switch to the
Protocol Data tab and click on
We need to enter the MPLS header bytes here in hex format. To calculate these, we need to know the MPLS header format.
The MPLS header consists of one or more MPLS tags comprising a tag stack -
+-------+-------+-------+-----+ | Tag 1 | Tag 2 | Tag 3 | ... | +-------+-------+-------+-----+
Each tag is 32-bit wide and is composed of the following fields -
+------------+-----+-----+-----+ | MPLS Label | Exp | S | TTL | | (20) | (3) | (1) | (8) | +------------+-----+-----+-----+
The numbers in () represents the bit-width of each field. The S bit is set to 1 for the last (innermost) tag and is 0 for all the other tags
Let’s create a single tag MPLS header with the following values -
Label = 12701 EXP = 5 S = 1 TTL = 64
First, let’s convert each of those values to hexadecimal -
Label = 12701 (0x319D) EXP = 5 (0x5) S = 1 (0x1) TTL = 64 (0x40)
Looking at the tag encoding above and some bit arithmetic, we can now calculate the 32-bit hex encoded tag for these values -
So, we enter these bytes in the hexdump editor, and uncheck the padding -
We need to do one last thing - go to the
Ethernet II tab, tick the checkbox and enter the MPLS ethertype
To verify if the MPLS header is correct, we apply our changes, transmit the stream, capture the transmitted packet and view it in Wireshark -
Voila, Wireshark decodes that perfectly!
What if you need more than one tag? Just calculate the 4-byte (32-bit) hex value for each tag (make sure S=0 in all tags except the last one) and enter the same in the hexdump.
Here’s an example -
Tag 1: Label = 12701 (0x319D) EXP = 5 (0x5) S = 0 (0x0) TTL = 64 (0x40) Tag 2: Label = 972 (0x3CC) EXP = 1 (0x1) S = 0 (0x0) TTL = 128 (0x80) Tag 3: Label = 19 (0x13) EXP = 3 (0x3) S = 1 (0x1) TTL = 255 (0xff)
Hex Encoded value -
0319DA40 003CC280 000137FF
Here’s the 3-tag stack mpls frame in Wireshark -
In the next post, we’ll see how to use a Ostinato userscript to do the same thing so that we don’t need to do all this manual hex calculation which is prone to errors.
Interested in more Ostinato tips and tricks? Subscribe to receive email updates!
Leave a Comment