From 281d8ab8c41d8c6f72ba40f23aa15142001091d7 Mon Sep 17 00:00:00 2001 From: Neal Cardwell <ncardwell@google.com> Date: Mon, 4 Nov 2013 13:55:46 -0500 Subject: [PATCH] net-test: packetdrill encap support: tests for basic header printing Tests for basic support of printing encapsulation headers. Change-Id: I2a3e743db44493cb8b338943ab40fc96d9abf63c --- .../net/packetdrill/packet_to_string_test.c | 49 ++++++++++++++----- 1 file changed, 38 insertions(+), 11 deletions(-) diff --git a/gtests/net/packetdrill/packet_to_string_test.c b/gtests/net/packetdrill/packet_to_string_test.c index f552aedc..7bd2bd16 100644 --- a/gtests/net/packetdrill/packet_to_string_test.c +++ b/gtests/net/packetdrill/packet_to_string_test.c @@ -31,8 +31,15 @@ static void test_tcp_ipv4_packet_to_string(void) { - /* A TCP/IPv4 packet. */ + /* An IPv4/GRE/IPv4/TCP packet. */ u8 data[] = { + /* IPv4: */ + 0x45, 0x00, 0x00, 0x54, 0x00, 0x00, 0x00, 0x00, + 0xff, 0x2f, 0xb5, 0x75, 0x02, 0x02, 0x02, 0x02, + 0x01, 0x01, 0x01, 0x01, + /* GRE: */ + 0x00, 0x00, 0x08, 0x00, + /* IPv4, TCP: */ 0x45, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x00, 0x00, 0xff, 0x06, 0x39, 0x11, 0xc0, 0x00, 0x02, 0x01, 0xc0, 0xa8, 0x00, 0x01, 0xcf, 0x3f, 0x1f, 0x90, @@ -63,6 +70,7 @@ static void test_tcp_ipv4_packet_to_string(void) assert(error == NULL); printf("dump = '%s'\n", dump); expected = + "ipv4 2.2.2.2 > 1.1.1.1: gre: " ". 1:1(0) ack 2202903899 win 257 " "<sack 2202905347:2202906795,TS val 300 ecr 1623332896>"; assert(strcmp(dump, expected) == 0); @@ -74,6 +82,7 @@ static void test_tcp_ipv4_packet_to_string(void) assert(error == NULL); printf("dump = '%s'\n", dump); expected = + "ipv4 2.2.2.2 > 1.1.1.1: gre: " "192.0.2.1:53055 > 192.168.0.1:8080 " ". 1:1(0) ack 2202903899 win 257 " "<sack 2202905347:2202906795,TS val 300 ecr 1623332896>"; @@ -86,14 +95,17 @@ static void test_tcp_ipv4_packet_to_string(void) assert(error == NULL); printf("dump = '%s'\n", dump); expected = + "ipv4 2.2.2.2 > 1.1.1.1: gre: " "192.0.2.1:53055 > 192.168.0.1:8080 " ". 1:1(0) ack 2202903899 win 257 " "<sack 2202905347:2202906795,TS val 300 ecr 1623332896>" "\n" - "0x0000: 45 00 00 3c 00 00 00 00 ff 06 39 11 c0 00 02 01 " "\n" - "0x0010: c0 a8 00 01 cf 3f 1f 90 00 00 00 01 83 4d a5 5b " "\n" - "0x0020: a0 10 01 01 db 2d 00 00 05 0a 83 4d ab 03 83 4d " "\n" - "0x0030: b0 ab 08 0a 00 00 01 2c 60 c2 18 20 " "\n"; + "0x0000: 45 00 00 54 00 00 00 00 ff 2f b5 75 02 02 02 02 " "\n" + "0x0010: 01 01 01 01 00 00 08 00 45 00 00 3c 00 00 00 00 " "\n" + "0x0020: ff 06 39 11 c0 00 02 01 c0 a8 00 01 cf 3f 1f 90 " "\n" + "0x0030: 00 00 00 01 83 4d a5 5b a0 10 01 01 db 2d 00 00 " "\n" + "0x0040: 05 0a 83 4d ab 03 83 4d b0 ab 08 0a 00 00 01 2c " "\n" + "0x0050: 60 c2 18 20 " "\n"; assert(strcmp(dump, expected) == 0); free(dump); @@ -102,8 +114,17 @@ static void test_tcp_ipv4_packet_to_string(void) static void test_tcp_ipv6_packet_to_string(void) { - /* A TCP/IPv6 packet. */ + /* An IPv6/GRE/TCP/IPv6 packet. */ u8 data[] = { + /* IPv6: */ + 0x60, 0x00, 0x00, 0x00, 0x00, 0x4c, 0x2f, 0xff, + 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x22, 0x22, + 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x11, + /* GRE: */ + 0x00, 0x00, 0x86, 0xdd, + /* IPv6, TCP: */ 0x60, 0x00, 0x00, 0x00, 0x00, 0x20, 0x06, 0xff, 0x20, 0x01, 0x0d, 0xb8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, @@ -135,6 +156,7 @@ static void test_tcp_ipv6_packet_to_string(void) assert(error == NULL); printf("dump = '%s'\n", dump); expected = + "ipv6 2::2222 > 1::1111: gre: " "S 0:0(0) win 32792 <mss 1000,sackOK,nop,nop,nop,wscale 7>"; assert(strcmp(dump, expected) == 0); free(dump); @@ -145,6 +167,7 @@ static void test_tcp_ipv6_packet_to_string(void) assert(error == NULL); printf("dump = '%s'\n", dump); expected = + "ipv6 2::2222 > 1::1111: gre: " "2001:db8::1:54242 > fd3d:fa7b:d17d::1:8080 " "S 0:0(0) win 32792 <mss 1000,sackOK,nop,nop,nop,wscale 7>"; assert(strcmp(dump, expected) == 0); @@ -156,13 +179,17 @@ static void test_tcp_ipv6_packet_to_string(void) assert(error == NULL); printf("dump = '%s'\n", dump); expected = + "ipv6 2::2222 > 1::1111: gre: " "2001:db8::1:54242 > fd3d:fa7b:d17d::1:8080 " "S 0:0(0) win 32792 <mss 1000,sackOK,nop,nop,nop,wscale 7>\n" - "0x0000: 60 00 00 00 00 20 06 ff 20 01 0d b8 00 00 00 00 " "\n" - "0x0010: 00 00 00 00 00 00 00 01 fd 3d fa 7b d1 7d 00 00 " "\n" - "0x0020: 00 00 00 00 00 00 00 01 d3 e2 1f 90 00 00 00 00 " "\n" - "0x0030: 00 00 00 00 80 02 80 18 06 60 00 00 02 04 03 e8 " "\n" - "0x0040: 04 02 01 01 01 03 03 07 " "\n"; + "0x0000: 60 00 00 00 00 4c 2f ff 00 02 00 00 00 00 00 00 " "\n" + "0x0010: 00 00 00 00 00 00 22 22 00 01 00 00 00 00 00 00 " "\n" + "0x0020: 00 00 00 00 00 00 11 11 00 00 86 dd 60 00 00 00 " "\n" + "0x0030: 00 20 06 ff 20 01 0d b8 00 00 00 00 00 00 00 00 " "\n" + "0x0040: 00 00 00 01 fd 3d fa 7b d1 7d 00 00 00 00 00 00 " "\n" + "0x0050: 00 00 00 01 d3 e2 1f 90 00 00 00 00 00 00 00 00 " "\n" + "0x0060: 80 02 80 18 06 60 00 00 02 04 03 e8 04 02 01 01 " "\n" + "0x0070: 01 03 03 07 " "\n"; assert(strcmp(dump, expected) == 0); free(dump); -- GitLab