From adb63cbe11726e8fa43f04251431ddbdaa0aa8e7 Mon Sep 17 00:00:00 2001 From: Neal Cardwell <ncardwell@google.com> Date: Fri, 22 Nov 2013 20:39:42 -0500 Subject: [PATCH] net-test: packetdrill MPLS support: print MPLS label stacks Code to print MPLS label stacks in a human-readable format matching the script syntax: mpls (label 123, tc 1, [S], ttl 255) (label 456, tc 1, [S], ttl 255) Change-Id: I706be8aab089fbad79eabde67125345330728517 --- gtests/net/packetdrill/packet_to_string.c | 24 +++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/gtests/net/packetdrill/packet_to_string.c b/gtests/net/packetdrill/packet_to_string.c index 64ab8f3c..fdc10dec 100644 --- a/gtests/net/packetdrill/packet_to_string.c +++ b/gtests/net/packetdrill/packet_to_string.c @@ -95,6 +95,29 @@ static int gre_header_to_string(FILE *s, struct packet *packet, int layer, return STATUS_OK; } +static int mpls_header_to_string(FILE *s, struct packet *packet, int layer, + enum dump_format_t format, char **error) +{ + struct header *header = &packet->headers[layer]; + int num_entries = header->header_bytes / sizeof(struct mpls); + int i = 0; + + fprintf(s, "mpls"); + + for (i = 0; i < num_entries; ++i) { + const struct mpls *mpls = header->h.mpls + i; + + fprintf(s, " (label %u, tc %u,%s ttl %u)", + mpls_entry_label(mpls), + mpls_entry_tc(mpls), + mpls_entry_stack(mpls) ? " [S]," : "", + mpls_entry_ttl(mpls)); + } + + fprintf(s, ": "); + return STATUS_OK; +} + /* Print a string representation of the TCP packet: * direction opt_ip_info flags seq ack window tcp_options */ @@ -197,6 +220,7 @@ static int encap_header_to_string(FILE *s, struct packet *packet, int layer, [HEADER_IPV4] = ipv4_header_to_string, [HEADER_IPV6] = ipv6_header_to_string, [HEADER_GRE] = gre_header_to_string, + [HEADER_MPLS] = mpls_header_to_string, }; header_to_string_func printer = NULL; enum header_t type = packet->headers[layer].type; -- GitLab