X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=test%2Ftest_gso.py;h=78c5c7346606b521709d3f1e021e371114d457f0;hb=2f4586d9b3507243918c11ce99b9d151d5bde7a0;hp=ee676a41c4a6a4974ed1210c6777d854f351b614;hpb=5c6dd17a373a2c56e57f02426d66a79af7faa19c;p=vpp.git diff --git a/test/test_gso.py b/test/test_gso.py index ee676a41c4a..78c5c734660 100644 --- a/test/test_gso.py +++ b/test/test_gso.py @@ -11,27 +11,27 @@ import unittest from scapy.packet import Raw -from scapy.layers.inet6 import IPv6, Ether, IP, UDP, ICMPv6PacketTooBig +from scapy.layers.l2 import GRE +from scapy.layers.inet6 import IPv6, Ether, IP, ICMPv6PacketTooBig from scapy.layers.inet6 import ipv6nh, IPerror6 from scapy.layers.inet import TCP, ICMP from scapy.layers.vxlan import VXLAN -from scapy.data import ETH_P_IP, ETH_P_IPV6, ETH_P_ARP -from scapy.layers.ipsec import SecurityAssociation, ESP +from scapy.layers.ipsec import ESP from vpp_papi import VppEnum -from framework import VppTestCase, VppTestRunner -from vpp_object import VppObject -from vpp_interface import VppInterface -from vpp_ip import DpoProto +from framework import VppTestCase +from asfframework import VppTestRunner from vpp_ip_route import VppIpRoute, VppRoutePath, FibPathProto from vpp_ipip_tun_interface import VppIpIpTunInterface from vpp_vxlan_tunnel import VppVxlanTunnel -from socket import AF_INET, AF_INET6, inet_pton -from util import reassemble4 +from vpp_gre_interface import VppGreInterface from vpp_ipsec import VppIpsecSA, VppIpsecTunProtect -from template_ipsec import IPsecIPv4Params, IPsecIPv6Params, \ - mk_scapy_crypt_key, config_tun_params +from template_ipsec import ( + IPsecIPv4Params, + IPsecIPv6Params, + config_tun_params, +) """ Test_gso is a subclass of VPPTestCase classes. GSO tests. @@ -39,7 +39,7 @@ from template_ipsec import IPsecIPv4Params, IPsecIPv6Params, \ class TestGSO(VppTestCase): - """ GSO Test Case """ + """GSO Test Case""" def __init__(self, *args): VppTestCase.__init__(self, *args) @@ -70,18 +70,29 @@ class TestGSO(VppTestCase): i.resolve_ndp() self.single_tunnel_bd = 10 - self.vxlan = VppVxlanTunnel(self, src=self.pg0.local_ip4, - dst=self.pg0.remote_ip4, - vni=self.single_tunnel_bd) - - self.vxlan2 = VppVxlanTunnel(self, src=self.pg0.local_ip6, - dst=self.pg0.remote_ip6, - vni=self.single_tunnel_bd) - - self.ipip4 = VppIpIpTunInterface(self, self.pg0, self.pg0.local_ip4, - self.pg0.remote_ip4) - self.ipip6 = VppIpIpTunInterface(self, self.pg0, self.pg0.local_ip6, - self.pg0.remote_ip6) + self.vxlan = VppVxlanTunnel( + self, + src=self.pg0.local_ip4, + dst=self.pg0.remote_ip4, + vni=self.single_tunnel_bd, + ) + + self.vxlan2 = VppVxlanTunnel( + self, + src=self.pg0.local_ip6, + dst=self.pg0.remote_ip6, + vni=self.single_tunnel_bd, + ) + + self.ipip4 = VppIpIpTunInterface( + self, self.pg0, self.pg0.local_ip4, self.pg0.remote_ip4 + ) + self.ipip6 = VppIpIpTunInterface( + self, self.pg0, self.pg0.local_ip6, self.pg0.remote_ip6 + ) + + self.gre4 = VppGreInterface(self, self.pg0.local_ip4, self.pg0.remote_ip4) + self.gre6 = VppGreInterface(self, self.pg0.local_ip6, self.pg0.remote_ip6) def tearDown(self): super(TestGSO, self).tearDown() @@ -92,15 +103,16 @@ class TestGSO(VppTestCase): i.admin_down() def test_gso(self): - """ GSO test """ + """GSO test""" # # Send jumbo frame with gso disabled and DF bit is set # - p4 = (Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac) / - IP(src=self.pg0.remote_ip4, dst=self.pg1.remote_ip4, - flags='DF') / - TCP(sport=1234, dport=1234) / - Raw(b'\xa5' * 65200)) + p4 = ( + Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac) + / IP(src=self.pg0.remote_ip4, dst=self.pg1.remote_ip4, flags="DF") + / TCP(sport=1234, dport=1234) + / Raw(b"\xa5" * 65200) + ) rxs = self.send_and_expect(self.pg0, [p4], self.pg0) @@ -115,13 +127,14 @@ class TestGSO(VppTestCase): # # Send checksum offload frames # - p40 = (Ether(src=self.pg2.remote_mac, dst=self.pg2.local_mac) / - IP(src=self.pg2.remote_ip4, dst=self.pg0.remote_ip4, - flags='DF') / - TCP(sport=1234, dport=1234) / - Raw(b'\xa5' * 1460)) + p40 = ( + Ether(src=self.pg2.remote_mac, dst=self.pg2.local_mac) + / IP(src=self.pg2.remote_ip4, dst=self.pg0.remote_ip4, flags="DF") + / TCP(sport=1234, dport=1234) + / Raw(b"\xa5" * 1460) + ) - rxs = self.send_and_expect(self.pg2, 100*[p40], self.pg0) + rxs = self.send_and_expect(self.pg2, 100 * [p40], self.pg0) for rx in rxs: self.assertEqual(rx[Ether].src, self.pg0.local_mac) @@ -133,12 +146,14 @@ class TestGSO(VppTestCase): self.assert_tcp_checksum_valid(rx) self.assertEqual(payload_len, len(rx[Raw])) - p60 = (Ether(src=self.pg2.remote_mac, dst=self.pg2.local_mac) / - IPv6(src=self.pg2.remote_ip6, dst=self.pg0.remote_ip6) / - TCP(sport=1234, dport=1234) / - Raw(b'\xa5' * 1440)) + p60 = ( + Ether(src=self.pg2.remote_mac, dst=self.pg2.local_mac) + / IPv6(src=self.pg2.remote_ip6, dst=self.pg0.remote_ip6) + / TCP(sport=1234, dport=1234) + / Raw(b"\xa5" * 1440) + ) - rxs = self.send_and_expect(self.pg2, 100*[p60], self.pg0) + rxs = self.send_and_expect(self.pg2, 100 * [p60], self.pg0) for rx in rxs: self.assertEqual(rx[Ether].src, self.pg0.local_mac) @@ -153,15 +168,17 @@ class TestGSO(VppTestCase): # Send jumbo frame with gso enabled and DF bit is set # input and output interfaces support GSO # - self.vapi.feature_gso_enable_disable(sw_if_index=self.pg3.sw_if_index, - enable_disable=1) - p41 = (Ether(src=self.pg2.remote_mac, dst=self.pg2.local_mac) / - IP(src=self.pg2.remote_ip4, dst=self.pg3.remote_ip4, - flags='DF') / - TCP(sport=1234, dport=1234) / - Raw(b'\xa5' * 65200)) + self.vapi.feature_gso_enable_disable( + sw_if_index=self.pg3.sw_if_index, enable_disable=1 + ) + p41 = ( + Ether(src=self.pg2.remote_mac, dst=self.pg2.local_mac) + / IP(src=self.pg2.remote_ip4, dst=self.pg3.remote_ip4, flags="DF") + / TCP(sport=1234, dport=1234) + / Raw(b"\xa5" * 65200) + ) - rxs = self.send_and_expect(self.pg2, 100*[p41], self.pg3, 100) + rxs = self.send_and_expect(self.pg2, 100 * [p41], self.pg3, 100) for rx in rxs: self.assertEqual(rx[Ether].src, self.pg3.local_mac) @@ -175,12 +192,14 @@ class TestGSO(VppTestCase): # # ipv6 # - p61 = (Ether(src=self.pg2.remote_mac, dst=self.pg2.local_mac) / - IPv6(src=self.pg2.remote_ip6, dst=self.pg3.remote_ip6) / - TCP(sport=1234, dport=1234) / - Raw(b'\xa5' * 65200)) + p61 = ( + Ether(src=self.pg2.remote_mac, dst=self.pg2.local_mac) + / IPv6(src=self.pg2.remote_ip6, dst=self.pg3.remote_ip6) + / TCP(sport=1234, dport=1234) + / Raw(b"\xa5" * 65200) + ) - rxs = self.send_and_expect(self.pg2, 100*[p61], self.pg3, 100) + rxs = self.send_and_expect(self.pg2, 100 * [p61], self.pg3, 100) for rx in rxs: self.assertEqual(rx[Ether].src, self.pg3.local_mac) @@ -196,15 +215,17 @@ class TestGSO(VppTestCase): # and DF bit is set. GSO packet will be chunked into gso_size # data payload # - self.vapi.feature_gso_enable_disable(sw_if_index=self.pg0.sw_if_index, - enable_disable=1) - p42 = (Ether(src=self.pg2.remote_mac, dst=self.pg2.local_mac) / - IP(src=self.pg2.remote_ip4, dst=self.pg0.remote_ip4, - flags='DF') / - TCP(sport=1234, dport=1234) / - Raw(b'\xa5' * 65200)) - - rxs = self.send_and_expect(self.pg2, 5*[p42], self.pg0, 225) + self.vapi.feature_gso_enable_disable( + sw_if_index=self.pg0.sw_if_index, enable_disable=1 + ) + p42 = ( + Ether(src=self.pg2.remote_mac, dst=self.pg2.local_mac) + / IP(src=self.pg2.remote_ip4, dst=self.pg0.remote_ip4, flags="DF") + / TCP(sport=1234, dport=1234) + / Raw(b"\xa5" * 65200) + ) + + rxs = self.send_and_expect(self.pg2, 5 * [p42], self.pg0, 225) size = 0 for rx in rxs: self.assertEqual(rx[Ether].src, self.pg0.local_mac) @@ -218,17 +239,19 @@ class TestGSO(VppTestCase): self.assertEqual(rx[TCP].dport, 1234) self.assertEqual(payload_len, len(rx[Raw])) size += payload_len - self.assertEqual(size, 65200*5) + self.assertEqual(size, 65200 * 5) # # ipv6 # - p62 = (Ether(src=self.pg2.remote_mac, dst=self.pg2.local_mac) / - IPv6(src=self.pg2.remote_ip6, dst=self.pg0.remote_ip6) / - TCP(sport=1234, dport=1234) / - Raw(b'\xa5' * 65200)) + p62 = ( + Ether(src=self.pg2.remote_mac, dst=self.pg2.local_mac) + / IPv6(src=self.pg2.remote_ip6, dst=self.pg0.remote_ip6) + / TCP(sport=1234, dport=1234) + / Raw(b"\xa5" * 65200) + ) - rxs = self.send_and_expect(self.pg2, 5*[p62], self.pg0, 225) + rxs = self.send_and_expect(self.pg2, 5 * [p62], self.pg0, 225) size = 0 for rx in rxs: self.assertEqual(rx[Ether].src, self.pg0.local_mac) @@ -241,22 +264,25 @@ class TestGSO(VppTestCase): self.assertEqual(rx[TCP].dport, 1234) self.assertEqual(payload_len, len(rx[Raw])) size += payload_len - self.assertEqual(size, 65200*5) + self.assertEqual(size, 65200 * 5) # # Send jumbo frame with gso enabled only on input interface # and DF bit is unset. GSO packet will be fragmented. # self.vapi.sw_interface_set_mtu(self.pg1.sw_if_index, [576, 0, 0, 0]) - self.vapi.feature_gso_enable_disable(sw_if_index=self.pg1.sw_if_index, - enable_disable=1) + self.vapi.feature_gso_enable_disable( + sw_if_index=self.pg1.sw_if_index, enable_disable=1 + ) - p43 = (Ether(src=self.pg2.remote_mac, dst=self.pg2.local_mac) / - IP(src=self.pg2.remote_ip4, dst=self.pg1.remote_ip4) / - TCP(sport=1234, dport=1234) / - Raw(b'\xa5' * 65200)) + p43 = ( + Ether(src=self.pg2.remote_mac, dst=self.pg2.local_mac) + / IP(src=self.pg2.remote_ip4, dst=self.pg1.remote_ip4) + / TCP(sport=1234, dport=1234) + / Raw(b"\xa5" * 65200) + ) - rxs = self.send_and_expect(self.pg2, 5*[p43], self.pg1, 5*119) + rxs = self.send_and_expect(self.pg2, 5 * [p43], self.pg1, 5 * 119) size = 0 for rx in rxs: self.assertEqual(rx[Ether].src, self.pg1.local_mac) @@ -265,8 +291,8 @@ class TestGSO(VppTestCase): self.assertEqual(rx[IP].dst, self.pg1.remote_ip4) self.assert_ip_checksum_valid(rx) size += rx[IP].len - 20 - size -= 20*5 # TCP header - self.assertEqual(size, 65200*5) + size -= 20 * 5 # TCP header + self.assertEqual(size, 65200 * 5) # # IPv6 @@ -274,12 +300,14 @@ class TestGSO(VppTestCase): # ICMPv6 Packet Too Big will be sent back to sender. # self.vapi.sw_interface_set_mtu(self.pg1.sw_if_index, [1280, 0, 0, 0]) - p63 = (Ether(src=self.pg2.remote_mac, dst=self.pg2.local_mac) / - IPv6(src=self.pg2.remote_ip6, dst=self.pg1.remote_ip6) / - TCP(sport=1234, dport=1234) / - Raw(b'\xa5' * 65200)) - - rxs = self.send_and_expect_some(self.pg2, 5*[p63], self.pg2, 5) + p63 = ( + Ether(src=self.pg2.remote_mac, dst=self.pg2.local_mac) + / IPv6(src=self.pg2.remote_ip6, dst=self.pg1.remote_ip6) + / TCP(sport=1234, dport=1234) + / Raw(b"\xa5" * 65200) + ) + + rxs = self.send_and_expect_some(self.pg2, 5 * [p63], self.pg2, 5) for rx in rxs: self.assertEqual(rx[Ether].src, self.pg2.local_mac) self.assertEqual(rx[Ether].dst, self.pg2.remote_mac) @@ -299,12 +327,14 @@ class TestGSO(VppTestCase): # self.vapi.sw_interface_set_mtu(self.pg1.sw_if_index, [9000, 0, 0, 0]) self.vapi.sw_interface_set_mtu(self.pg4.sw_if_index, [9000, 0, 0, 0]) - p44 = (Ether(src=self.pg4.remote_mac, dst=self.pg4.local_mac) / - IP(src=self.pg4.remote_ip4, dst=self.pg1.remote_ip4) / - TCP(sport=1234, dport=1234) / - Raw(b'\xa5' * 65200)) - - rxs = self.send_and_expect(self.pg4, 5*[p44], self.pg1, 165) + p44 = ( + Ether(src=self.pg4.remote_mac, dst=self.pg4.local_mac) + / IP(src=self.pg4.remote_ip4, dst=self.pg1.remote_ip4) + / TCP(sport=1234, dport=1234) + / Raw(b"\xa5" * 65200) + ) + + rxs = self.send_and_expect(self.pg4, 5 * [p44], self.pg1, 165) size = 0 for rx in rxs: self.assertEqual(rx[Ether].src, self.pg1.local_mac) @@ -316,17 +346,19 @@ class TestGSO(VppTestCase): self.assert_tcp_checksum_valid(rx) self.assertEqual(payload_len, len(rx[Raw])) size += payload_len - self.assertEqual(size, 65200*5) + self.assertEqual(size, 65200 * 5) # # IPv6 # - p64 = (Ether(src=self.pg4.remote_mac, dst=self.pg4.local_mac) / - IPv6(src=self.pg4.remote_ip6, dst=self.pg1.remote_ip6) / - TCP(sport=1234, dport=1234) / - Raw(b'\xa5' * 65200)) + p64 = ( + Ether(src=self.pg4.remote_mac, dst=self.pg4.local_mac) + / IPv6(src=self.pg4.remote_ip6, dst=self.pg1.remote_ip6) + / TCP(sport=1234, dport=1234) + / Raw(b"\xa5" * 65200) + ) - rxs = self.send_and_expect(self.pg4, 5*[p64], self.pg1, 170) + rxs = self.send_and_expect(self.pg4, 5 * [p64], self.pg1, 170) size = 0 for rx in rxs: self.assertEqual(rx[Ether].src, self.pg1.local_mac) @@ -337,15 +369,17 @@ class TestGSO(VppTestCase): self.assert_tcp_checksum_valid(rx) self.assertEqual(payload_len, len(rx[Raw])) size += payload_len - self.assertEqual(size, 65200*5) + self.assertEqual(size, 65200 * 5) - self.vapi.feature_gso_enable_disable(sw_if_index=self.pg0.sw_if_index, - enable_disable=0) - self.vapi.feature_gso_enable_disable(sw_if_index=self.pg1.sw_if_index, - enable_disable=0) + self.vapi.feature_gso_enable_disable( + sw_if_index=self.pg0.sw_if_index, enable_disable=0 + ) + self.vapi.feature_gso_enable_disable( + sw_if_index=self.pg1.sw_if_index, enable_disable=0 + ) def test_gso_vxlan(self): - """ GSO VXLAN test """ + """GSO VXLAN test""" self.logger.info(self.vapi.cli("sh int addr")) # # Send jumbo frame with gso enabled only on input interface and @@ -358,21 +392,26 @@ class TestGSO(VppTestCase): # self.vxlan.add_vpp_config() self.vapi.sw_interface_set_l2_bridge( - rx_sw_if_index=self.vxlan.sw_if_index, bd_id=self.single_tunnel_bd) + rx_sw_if_index=self.vxlan.sw_if_index, bd_id=self.single_tunnel_bd + ) self.vapi.sw_interface_set_l2_bridge( - rx_sw_if_index=self.pg2.sw_if_index, bd_id=self.single_tunnel_bd) - self.vapi.feature_gso_enable_disable(sw_if_index=self.pg0.sw_if_index, - enable_disable=1) + rx_sw_if_index=self.pg2.sw_if_index, bd_id=self.single_tunnel_bd + ) + self.vapi.feature_gso_enable_disable( + sw_if_index=self.pg0.sw_if_index, enable_disable=1 + ) # # IPv4/IPv4 - VXLAN # - p45 = (Ether(src=self.pg2.remote_mac, dst="02:fe:60:1e:a2:79") / - IP(src=self.pg2.remote_ip4, dst="172.16.3.3", flags='DF') / - TCP(sport=1234, dport=1234) / - Raw(b'\xa5' * 65200)) + p45 = ( + Ether(src=self.pg2.remote_mac, dst="02:fe:60:1e:a2:79") + / IP(src=self.pg2.remote_ip4, dst="172.16.3.3", flags="DF") + / TCP(sport=1234, dport=1234) + / Raw(b"\xa5" * 65200) + ) - rxs = self.send_and_expect(self.pg2, 5*[p45], self.pg0, 225) + rxs = self.send_and_expect(self.pg2, 5 * [p45], self.pg0, 225) size = 0 for rx in rxs: self.assertEqual(rx[Ether].src, self.pg0.local_mac) @@ -393,17 +432,19 @@ class TestGSO(VppTestCase): payload_len = inner[IP].len - 20 - 20 self.assertEqual(payload_len, len(inner[Raw])) size += payload_len - self.assertEqual(size, 65200*5) + self.assertEqual(size, 65200 * 5) # # IPv4/IPv6 - VXLAN # - p65 = (Ether(src=self.pg2.remote_mac, dst="02:fe:60:1e:a2:79") / - IPv6(src=self.pg2.remote_ip6, dst="fd01:3::3") / - TCP(sport=1234, dport=1234) / - Raw(b'\xa5' * 65200)) + p65 = ( + Ether(src=self.pg2.remote_mac, dst="02:fe:60:1e:a2:79") + / IPv6(src=self.pg2.remote_ip6, dst="fd01:3::3") + / TCP(sport=1234, dport=1234) + / Raw(b"\xa5" * 65200) + ) - rxs = self.send_and_expect(self.pg2, 5*[p65], self.pg0, 225) + rxs = self.send_and_expect(self.pg2, 5 * [p65], self.pg0, 225) size = 0 for rx in rxs: self.assertEqual(rx[Ether].src, self.pg0.local_mac) @@ -423,7 +464,7 @@ class TestGSO(VppTestCase): payload_len = inner[IPv6].plen - 20 self.assertEqual(payload_len, len(inner[Raw])) size += payload_len - self.assertEqual(size, 65200*5) + self.assertEqual(size, 65200 * 5) # # disable ipv4/vxlan @@ -435,18 +476,20 @@ class TestGSO(VppTestCase): # self.vxlan2.add_vpp_config() self.vapi.sw_interface_set_l2_bridge( - rx_sw_if_index=self.vxlan2.sw_if_index, - bd_id=self.single_tunnel_bd) + rx_sw_if_index=self.vxlan2.sw_if_index, bd_id=self.single_tunnel_bd + ) # # IPv6/IPv4 - VXLAN # - p46 = (Ether(src=self.pg2.remote_mac, dst="02:fe:60:1e:a2:79") / - IP(src=self.pg2.remote_ip4, dst="172.16.3.3", flags='DF') / - TCP(sport=1234, dport=1234) / - Raw(b'\xa5' * 65200)) + p46 = ( + Ether(src=self.pg2.remote_mac, dst="02:fe:60:1e:a2:79") + / IP(src=self.pg2.remote_ip4, dst="172.16.3.3", flags="DF") + / TCP(sport=1234, dport=1234) + / Raw(b"\xa5" * 65200) + ) - rxs = self.send_and_expect(self.pg2, 5*[p46], self.pg0, 225) + rxs = self.send_and_expect(self.pg2, 5 * [p46], self.pg0, 225) size = 0 for rx in rxs: self.assertEqual(rx[Ether].src, self.pg0.local_mac) @@ -466,17 +509,19 @@ class TestGSO(VppTestCase): payload_len = inner[IP].len - 20 - 20 self.assertEqual(payload_len, len(inner[Raw])) size += payload_len - self.assertEqual(size, 65200*5) + self.assertEqual(size, 65200 * 5) # # IPv6/IPv6 - VXLAN # - p66 = (Ether(src=self.pg2.remote_mac, dst="02:fe:60:1e:a2:79") / - IPv6(src=self.pg2.remote_ip6, dst="fd01:3::3") / - TCP(sport=1234, dport=1234) / - Raw(b'\xa5' * 65200)) + p66 = ( + Ether(src=self.pg2.remote_mac, dst="02:fe:60:1e:a2:79") + / IPv6(src=self.pg2.remote_ip6, dst="fd01:3::3") + / TCP(sport=1234, dport=1234) + / Raw(b"\xa5" * 65200) + ) - rxs = self.send_and_expect(self.pg2, 5*[p66], self.pg0, 225) + rxs = self.send_and_expect(self.pg2, 5 * [p66], self.pg0, 225) size = 0 for rx in rxs: self.assertEqual(rx[Ether].src, self.pg0.local_mac) @@ -495,25 +540,27 @@ class TestGSO(VppTestCase): payload_len = inner[IPv6].plen - 20 self.assertEqual(payload_len, len(inner[Raw])) size += payload_len - self.assertEqual(size, 65200*5) + self.assertEqual(size, 65200 * 5) # # disable ipv4/vxlan # self.vxlan2.remove_vpp_config() - self.vapi.feature_gso_enable_disable(sw_if_index=self.pg0.sw_if_index, - enable_disable=0) + self.vapi.feature_gso_enable_disable( + sw_if_index=self.pg0.sw_if_index, enable_disable=0 + ) def test_gso_ipip(self): - """ GSO IPIP test """ + """GSO IPIP test""" self.logger.info(self.vapi.cli("sh int addr")) # # Send jumbo frame with gso enabled only on input interface and # create IPIP tunnel on VPP pg0. # - self.vapi.feature_gso_enable_disable(sw_if_index=self.pg0.sw_if_index, - enable_disable=1) + self.vapi.feature_gso_enable_disable( + sw_if_index=self.pg0.sw_if_index, enable_disable=1 + ) # # enable ipip4 @@ -526,21 +573,30 @@ class TestGSO(VppTestCase): # Add IPv4 routes via tunnel interface self.ip4_via_ip4_tunnel = VppIpRoute( - self, "172.16.10.0", 24, - [VppRoutePath("0.0.0.0", - self.ipip4.sw_if_index, - proto=FibPathProto.FIB_PATH_NH_PROTO_IP4)]) + self, + "172.16.10.0", + 24, + [ + VppRoutePath( + "0.0.0.0", + self.ipip4.sw_if_index, + proto=FibPathProto.FIB_PATH_NH_PROTO_IP4, + ) + ], + ) self.ip4_via_ip4_tunnel.add_vpp_config() # # IPv4/IPv4 - IPIP # - p47 = (Ether(src=self.pg2.remote_mac, dst="02:fe:60:1e:a2:79") / - IP(src=self.pg2.remote_ip4, dst="172.16.10.3", flags='DF') / - TCP(sport=1234, dport=1234) / - Raw(b'\xa5' * 65200)) + p47 = ( + Ether(src=self.pg2.remote_mac, dst="02:fe:60:1e:a2:79") + / IP(src=self.pg2.remote_ip4, dst="172.16.10.3", flags="DF") + / TCP(sport=1234, dport=1234) + / Raw(b"\xa5" * 65200) + ) - rxs = self.send_and_expect(self.pg2, 5*[p47], self.pg0, 225) + rxs = self.send_and_expect(self.pg2, 5 * [p47], self.pg0, 225) size = 0 for rx in rxs: self.assertEqual(rx[Ether].src, self.pg0.local_mac) @@ -558,23 +614,32 @@ class TestGSO(VppTestCase): payload_len = inner[IP].len - 20 - 20 self.assertEqual(payload_len, len(inner[Raw])) size += payload_len - self.assertEqual(size, 65200*5) + self.assertEqual(size, 65200 * 5) self.ip6_via_ip4_tunnel = VppIpRoute( - self, "fd01:10::", 64, - [VppRoutePath("::", - self.ipip4.sw_if_index, - proto=FibPathProto.FIB_PATH_NH_PROTO_IP6)]) + self, + "fd01:10::", + 64, + [ + VppRoutePath( + "::", + self.ipip4.sw_if_index, + proto=FibPathProto.FIB_PATH_NH_PROTO_IP6, + ) + ], + ) self.ip6_via_ip4_tunnel.add_vpp_config() # # IPv4/IPv6 - IPIP # - p67 = (Ether(src=self.pg2.remote_mac, dst="02:fe:60:1e:a2:79") / - IPv6(src=self.pg2.remote_ip6, dst="fd01:10::3") / - TCP(sport=1234, dport=1234) / - Raw(b'\xa5' * 65200)) + p67 = ( + Ether(src=self.pg2.remote_mac, dst="02:fe:60:1e:a2:79") + / IPv6(src=self.pg2.remote_ip6, dst="fd01:10::3") + / TCP(sport=1234, dport=1234) + / Raw(b"\xa5" * 65200) + ) - rxs = self.send_and_expect(self.pg2, 5*[p67], self.pg0, 225) + rxs = self.send_and_expect(self.pg2, 5 * [p67], self.pg0, 225) size = 0 for rx in rxs: self.assertEqual(rx[Ether].src, self.pg0.local_mac) @@ -591,20 +656,21 @@ class TestGSO(VppTestCase): payload_len = inner[IPv6].plen - 20 self.assertEqual(payload_len, len(inner[Raw])) size += payload_len - self.assertEqual(size, 65200*5) + self.assertEqual(size, 65200 * 5) # # Send jumbo frame with gso enabled only on input interface and # create IPIP tunnel on VPP pg0. Enable gso feature node on ipip # tunnel - IPSec use case # - self.vapi.feature_gso_enable_disable(sw_if_index=self.pg0.sw_if_index, - enable_disable=0) self.vapi.feature_gso_enable_disable( - sw_if_index=self.ipip4.sw_if_index, - enable_disable=1) + sw_if_index=self.pg0.sw_if_index, enable_disable=0 + ) + self.vapi.feature_gso_enable_disable( + sw_if_index=self.ipip4.sw_if_index, enable_disable=1 + ) - rxs = self.send_and_expect(self.pg2, 5*[p47], self.pg0, 225) + rxs = self.send_and_expect(self.pg2, 5 * [p47], self.pg0, 225) size = 0 for rx in rxs: self.assertEqual(rx[Ether].src, self.pg0.local_mac) @@ -622,14 +688,14 @@ class TestGSO(VppTestCase): payload_len = inner[IP].len - 20 - 20 self.assertEqual(payload_len, len(inner[Raw])) size += payload_len - self.assertEqual(size, 65200*5) + self.assertEqual(size, 65200 * 5) # # disable ipip4 # self.vapi.feature_gso_enable_disable( - sw_if_index=self.ipip4.sw_if_index, - enable_disable=0) + sw_if_index=self.ipip4.sw_if_index, enable_disable=0 + ) self.ip4_via_ip4_tunnel.remove_vpp_config() self.ip6_via_ip4_tunnel.remove_vpp_config() self.ipip4.remove_vpp_config() @@ -637,8 +703,9 @@ class TestGSO(VppTestCase): # # enable ipip6 # - self.vapi.feature_gso_enable_disable(sw_if_index=self.pg0.sw_if_index, - enable_disable=1) + self.vapi.feature_gso_enable_disable( + sw_if_index=self.pg0.sw_if_index, enable_disable=1 + ) self.ipip6.add_vpp_config() # Set interface up and enable IP on it @@ -647,21 +714,30 @@ class TestGSO(VppTestCase): # Add IPv4 routes via tunnel interface self.ip4_via_ip6_tunnel = VppIpRoute( - self, "172.16.10.0", 24, - [VppRoutePath("0.0.0.0", - self.ipip6.sw_if_index, - proto=FibPathProto.FIB_PATH_NH_PROTO_IP4)]) + self, + "172.16.10.0", + 24, + [ + VppRoutePath( + "0.0.0.0", + self.ipip6.sw_if_index, + proto=FibPathProto.FIB_PATH_NH_PROTO_IP4, + ) + ], + ) self.ip4_via_ip6_tunnel.add_vpp_config() # # IPv6/IPv4 - IPIP # - p48 = (Ether(src=self.pg2.remote_mac, dst="02:fe:60:1e:a2:79") / - IP(src=self.pg2.remote_ip4, dst="172.16.10.3", flags='DF') / - TCP(sport=1234, dport=1234) / - Raw(b'\xa5' * 65200)) + p48 = ( + Ether(src=self.pg2.remote_mac, dst="02:fe:60:1e:a2:79") + / IP(src=self.pg2.remote_ip4, dst="172.16.10.3", flags="DF") + / TCP(sport=1234, dport=1234) + / Raw(b"\xa5" * 65200) + ) - rxs = self.send_and_expect(self.pg2, 5*[p48], self.pg0, 225) + rxs = self.send_and_expect(self.pg2, 5 * [p48], self.pg0, 225) size = 0 for rx in rxs: self.assertEqual(rx[Ether].src, self.pg0.local_mac) @@ -678,24 +754,33 @@ class TestGSO(VppTestCase): payload_len = inner[IP].len - 20 - 20 self.assertEqual(payload_len, len(inner[Raw])) size += payload_len - self.assertEqual(size, 65200*5) + self.assertEqual(size, 65200 * 5) self.ip6_via_ip6_tunnel = VppIpRoute( - self, "fd01:10::", 64, - [VppRoutePath("::", - self.ipip6.sw_if_index, - proto=FibPathProto.FIB_PATH_NH_PROTO_IP6)]) + self, + "fd01:10::", + 64, + [ + VppRoutePath( + "::", + self.ipip6.sw_if_index, + proto=FibPathProto.FIB_PATH_NH_PROTO_IP6, + ) + ], + ) self.ip6_via_ip6_tunnel.add_vpp_config() # # IPv6/IPv6 - IPIP # - p68 = (Ether(src=self.pg2.remote_mac, dst="02:fe:60:1e:a2:79") / - IPv6(src=self.pg2.remote_ip6, dst="fd01:10::3") / - TCP(sport=1234, dport=1234) / - Raw(b'\xa5' * 65200)) + p68 = ( + Ether(src=self.pg2.remote_mac, dst="02:fe:60:1e:a2:79") + / IPv6(src=self.pg2.remote_ip6, dst="fd01:10::3") + / TCP(sport=1234, dport=1234) + / Raw(b"\xa5" * 65200) + ) - rxs = self.send_and_expect(self.pg2, 5*[p68], self.pg0, 225) + rxs = self.send_and_expect(self.pg2, 5 * [p68], self.pg0, 225) size = 0 for rx in rxs: self.assertEqual(rx[Ether].src, self.pg0.local_mac) @@ -711,7 +796,7 @@ class TestGSO(VppTestCase): payload_len = inner[IPv6].plen - 20 self.assertEqual(payload_len, len(inner[Raw])) size += payload_len - self.assertEqual(size, 65200*5) + self.assertEqual(size, 65200 * 5) # # disable ipip6 @@ -720,11 +805,208 @@ class TestGSO(VppTestCase): self.ip6_via_ip6_tunnel.remove_vpp_config() self.ipip6.remove_vpp_config() - self.vapi.feature_gso_enable_disable(sw_if_index=self.pg0.sw_if_index, - enable_disable=0) + self.vapi.feature_gso_enable_disable( + sw_if_index=self.pg0.sw_if_index, enable_disable=0 + ) + + def test_gso_gre(self): + """GSO GRE test""" + # + # Send jumbo frame with gso enabled only on gre tunnel interface. + # create GRE tunnel on VPP pg0. + # + + # + # create gre 4 tunnel + # + self.gre4.add_vpp_config() + self.gre4.admin_up() + self.gre4.config_ip4() + + # + # Add a route that resolves the tunnel's destination + # + # Add IPv4 routes via tunnel interface + self.ip4_via_gre4_tunnel = VppIpRoute( + self, + "172.16.10.0", + 24, + [ + VppRoutePath( + "0.0.0.0", + self.gre4.sw_if_index, + proto=FibPathProto.FIB_PATH_NH_PROTO_IP4, + ) + ], + ) + self.ip4_via_gre4_tunnel.add_vpp_config() + + pgre4 = ( + Ether(src=self.pg2.remote_mac, dst="02:fe:60:1e:a2:79") + / IP(src=self.pg2.remote_ip4, dst="172.16.10.3", flags="DF") + / TCP(sport=1234, dport=1234) + / Raw(b"\xa5" * 65200) + ) + + # test when GSO segmentation is disabled, Packets are truncated + rxs = self.send_and_expect(self.pg2, 5 * [pgre4], self.pg0, 5) + for rx in rxs: + self.assertEqual(rx[Ether].src, self.pg0.local_mac) + self.assertEqual(rx[Ether].dst, self.pg0.remote_mac) + self.assertEqual(rx[IP].src, self.pg0.local_ip4) + self.assertEqual(rx[IP].dst, self.pg0.remote_ip4) + self.assert_ip_checksum_valid(rx) + self.assertEqual(rx[IP].proto, 0x2F) # GRE encap + self.assertEqual(rx[GRE].proto, 0x0800) # IPv4 + inner = rx[GRE].payload + self.assertNotEqual(rx[IP].len - 20 - 4, len(inner)) + self.assertEqual(inner[IP].src, self.pg2.remote_ip4) + self.assertEqual(inner[IP].dst, "172.16.10.3") + self.assert_ip_checksum_valid(inner) + payload_len = inner[IP].len - 20 - 20 + self.assertEqual(payload_len, 65200) + # truncated packet to MTU size + self.assertNotEqual(payload_len, len(inner[Raw])) + + # enable the GSO segmentation on GRE tunnel + self.vapi.feature_gso_enable_disable( + sw_if_index=self.gre4.sw_if_index, enable_disable=1 + ) + + # test again, this time payload will be chuncked to GSO size (i.e. 1448) + rxs = self.send_and_expect(self.pg2, 5 * [pgre4], self.pg0, 225) + size = 0 + for rx in rxs: + self.assertEqual(rx[Ether].src, self.pg0.local_mac) + self.assertEqual(rx[Ether].dst, self.pg0.remote_mac) + self.assertEqual(rx[IP].src, self.pg0.local_ip4) + self.assertEqual(rx[IP].dst, self.pg0.remote_ip4) + self.assert_ip_checksum_valid(rx) + self.assertEqual(rx[IP].proto, 0x2F) # GRE encap + self.assertEqual(rx[GRE].proto, 0x0800) # IPv4 + inner = rx[GRE].payload + self.assertEqual(rx[IP].len - 20 - 4, len(inner)) + self.assertEqual(inner[IP].src, self.pg2.remote_ip4) + self.assertEqual(inner[IP].dst, "172.16.10.3") + self.assert_ip_checksum_valid(inner) + self.assert_tcp_checksum_valid(inner) + payload_len = inner[IP].len - 20 - 20 + self.assertEqual(payload_len, len(inner[Raw])) + size += payload_len + self.assertEqual(size, 65200 * 5) + + # Disable the GSO segmentation on GRE tunnel + self.vapi.feature_gso_enable_disable( + sw_if_index=self.gre4.sw_if_index, enable_disable=0 + ) + + # test again when GSO segmentation is disabled, Packets are truncated + rxs = self.send_and_expect(self.pg2, 5 * [pgre4], self.pg0, 5) + for rx in rxs: + self.assertEqual(rx[Ether].src, self.pg0.local_mac) + self.assertEqual(rx[Ether].dst, self.pg0.remote_mac) + self.assertEqual(rx[IP].src, self.pg0.local_ip4) + self.assertEqual(rx[IP].dst, self.pg0.remote_ip4) + self.assert_ip_checksum_valid(rx) + self.assertEqual(rx[IP].proto, 0x2F) # GRE encap + self.assertEqual(rx[GRE].proto, 0x0800) # IPv4 + inner = rx[GRE].payload + self.assertNotEqual(rx[IP].len - 20 - 4, len(inner)) + self.assertEqual(inner[IP].src, self.pg2.remote_ip4) + self.assertEqual(inner[IP].dst, "172.16.10.3") + self.assert_ip_checksum_valid(inner) + payload_len = inner[IP].len - 20 - 20 + self.assertEqual(payload_len, 65200) + # truncated packet to MTU size + self.assertNotEqual(payload_len, len(inner[Raw])) + + self.ip4_via_gre4_tunnel.remove_vpp_config() + self.gre4.remove_vpp_config() + + self.gre6.add_vpp_config() + self.gre6.admin_up() + self.gre6.config_ip4() + + # + # Add a route that resolves the tunnel's destination + # Add IPv6 routes via tunnel interface + # + self.vapi.feature_gso_enable_disable( + sw_if_index=self.gre6.sw_if_index, enable_disable=1 + ) + self.ip6_via_gre6_tunnel = VppIpRoute( + self, + "fd01:10::", + 64, + [ + VppRoutePath( + "::", + self.gre6.sw_if_index, + proto=FibPathProto.FIB_PATH_NH_PROTO_IP6, + ) + ], + ) + self.ip6_via_gre6_tunnel.add_vpp_config() + + # + # Create IPv6 packet + # + pgre6 = ( + Ether(src=self.pg2.remote_mac, dst="02:fe:60:1e:a2:79") + / IPv6(src=self.pg2.remote_ip6, dst="fd01:10::3") + / TCP(sport=1234, dport=1234) + / Raw(b"\xa5" * 65200) + ) + + # test when GSO segmentation is enabled, payload will be segmented + # into GSO size (i.e. 1448) + rxs = self.send_and_expect(self.pg2, 5 * [pgre6], self.pg0, 225) + size = 0 + for rx in rxs: + self.assertEqual(rx[Ether].src, self.pg0.local_mac) + self.assertEqual(rx[Ether].dst, self.pg0.remote_mac) + self.assertEqual(rx[IPv6].src, self.pg0.local_ip6) + self.assertEqual(rx[IPv6].dst, self.pg0.remote_ip6) + self.assertEqual(ipv6nh[rx[IPv6].nh], "GRE") + self.assertEqual(rx[GRE].proto, 0x86DD) # IPv6 + inner = rx[GRE].payload + self.assertEqual(rx[IPv6].plen - 4, len(inner)) + self.assertEqual(inner[IPv6].src, self.pg2.remote_ip6) + self.assertEqual(inner[IPv6].dst, "fd01:10::3") + self.assert_tcp_checksum_valid(inner) + payload_len = inner[IPv6].plen - 20 + self.assertEqual(payload_len, len(inner[Raw])) + size += payload_len + self.assertEqual(size, 65200 * 5) + + # disable GSO segmentation + self.vapi.feature_gso_enable_disable( + sw_if_index=self.gre6.sw_if_index, enable_disable=0 + ) + + # test again, this time packets will be truncated + rxs = self.send_and_expect(self.pg2, 5 * [pgre6], self.pg0, 5) + for rx in rxs: + self.assertEqual(rx[Ether].src, self.pg0.local_mac) + self.assertEqual(rx[Ether].dst, self.pg0.remote_mac) + self.assertEqual(rx[IPv6].src, self.pg0.local_ip6) + self.assertEqual(rx[IPv6].dst, self.pg0.remote_ip6) + self.assertEqual(ipv6nh[rx[IPv6].nh], "GRE") + self.assertEqual(rx[GRE].proto, 0x86DD) # IPv6 + inner = rx[GRE].payload + self.assertNotEqual(rx[IPv6].plen - 4, len(inner)) + self.assertEqual(inner[IPv6].src, self.pg2.remote_ip6) + self.assertEqual(inner[IPv6].dst, "fd01:10::3") + payload_len = inner[IPv6].plen - 20 + self.assertEqual(payload_len, 65200) + # packets are truncated to MTU size + self.assertNotEqual(payload_len, len(inner[Raw])) + + self.ip6_via_gre6_tunnel.remove_vpp_config() + self.gre6.remove_vpp_config() def test_gso_ipsec(self): - """ GSO IPSEC test """ + """GSO IPSEC test""" # # Send jumbo frame with gso enabled only on input interface and # create IPIP tunnel on VPP pg0. @@ -735,14 +1017,22 @@ class TestGSO(VppTestCase): # self.ipip4.add_vpp_config() self.vapi.feature_gso_enable_disable( - sw_if_index=self.ipip4.sw_if_index, enable_disable=1) + sw_if_index=self.ipip4.sw_if_index, enable_disable=1 + ) # Add IPv4 routes via tunnel interface self.ip4_via_ip4_tunnel = VppIpRoute( - self, "172.16.10.0", 24, - [VppRoutePath("0.0.0.0", - self.ipip4.sw_if_index, - proto=FibPathProto.FIB_PATH_NH_PROTO_IP4)]) + self, + "172.16.10.0", + 24, + [ + VppRoutePath( + "0.0.0.0", + self.ipip4.sw_if_index, + proto=FibPathProto.FIB_PATH_NH_PROTO_IP4, + ) + ], + ) self.ip4_via_ip4_tunnel.add_vpp_config() # IPSec config @@ -750,30 +1040,33 @@ class TestGSO(VppTestCase): self.encryption_type = ESP config_tun_params(self.ipv4_params, self.encryption_type, self.ipip4) - self.tun_sa_in_v4 = VppIpsecSA(self, self.ipv4_params.vpp_tun_sa_id, - self.ipv4_params.vpp_tun_spi, - self.ipv4_params.auth_algo_vpp_id, - self.ipv4_params.auth_key, - self.ipv4_params.crypt_algo_vpp_id, - self.ipv4_params.crypt_key, - VppEnum.vl_api_ipsec_proto_t. - IPSEC_API_PROTO_ESP) + self.tun_sa_in_v4 = VppIpsecSA( + self, + self.ipv4_params.scapy_tun_sa_id, + self.ipv4_params.scapy_tun_spi, + self.ipv4_params.auth_algo_vpp_id, + self.ipv4_params.auth_key, + self.ipv4_params.crypt_algo_vpp_id, + self.ipv4_params.crypt_key, + VppEnum.vl_api_ipsec_proto_t.IPSEC_API_PROTO_ESP, + ) self.tun_sa_in_v4.add_vpp_config() - self.tun_sa_out_v4 = VppIpsecSA(self, self.ipv4_params.scapy_tun_sa_id, - self.ipv4_params.scapy_tun_spi, - self.ipv4_params.auth_algo_vpp_id, - self.ipv4_params.auth_key, - self.ipv4_params.crypt_algo_vpp_id, - self.ipv4_params.crypt_key, - VppEnum.vl_api_ipsec_proto_t. - IPSEC_API_PROTO_ESP) + self.tun_sa_out_v4 = VppIpsecSA( + self, + self.ipv4_params.vpp_tun_sa_id, + self.ipv4_params.vpp_tun_spi, + self.ipv4_params.auth_algo_vpp_id, + self.ipv4_params.auth_key, + self.ipv4_params.crypt_algo_vpp_id, + self.ipv4_params.crypt_key, + VppEnum.vl_api_ipsec_proto_t.IPSEC_API_PROTO_ESP, + ) self.tun_sa_out_v4.add_vpp_config() - self.tun_protect_v4 = VppIpsecTunProtect(self, - self.ipip4, - self.tun_sa_out_v4, - [self.tun_sa_in_v4]) + self.tun_protect_v4 = VppIpsecTunProtect( + self, self.ipip4, self.tun_sa_out_v4, [self.tun_sa_in_v4] + ) self.tun_protect_v4.add_vpp_config() @@ -784,10 +1077,12 @@ class TestGSO(VppTestCase): # # IPv4/IPv4 - IPSEC # - ipsec44 = (Ether(src=self.pg2.remote_mac, dst="02:fe:60:1e:a2:79") / - IP(src=self.pg2.remote_ip4, dst="172.16.10.3", flags='DF') / - TCP(sport=1234, dport=1234) / - Raw(b'\xa5' * 65200)) + ipsec44 = ( + Ether(src=self.pg2.remote_mac, dst="02:fe:60:1e:a2:79") + / IP(src=self.pg2.remote_ip4, dst="172.16.10.3", flags="DF") + / TCP(sport=1234, dport=1234) + / Raw(b"\xa5" * 65200) + ) rxs = self.send_and_expect(self.pg2, [ipsec44], self.pg0, 45) size = 0 @@ -797,7 +1092,7 @@ class TestGSO(VppTestCase): self.assertEqual(rx[IP].src, self.pg0.local_ip4) self.assertEqual(rx[IP].dst, self.pg0.remote_ip4) self.assertEqual(rx[IP].proto, 50) # ESP - self.assertEqual(rx[ESP].spi, self.ipv4_params.scapy_tun_spi) + self.assertEqual(rx[ESP].spi, self.ipv4_params.vpp_tun_spi) inner = self.ipv4_params.vpp_tun_sa.decrypt(rx[IP]) self.assertEqual(inner[IP].src, self.pg2.remote_ip4) self.assertEqual(inner[IP].dst, "172.16.10.3") @@ -805,18 +1100,27 @@ class TestGSO(VppTestCase): self.assertEqual(size, 65200) self.ip6_via_ip4_tunnel = VppIpRoute( - self, "fd01:10::", 64, - [VppRoutePath("::", - self.ipip4.sw_if_index, - proto=FibPathProto.FIB_PATH_NH_PROTO_IP6)]) + self, + "fd01:10::", + 64, + [ + VppRoutePath( + "::", + self.ipip4.sw_if_index, + proto=FibPathProto.FIB_PATH_NH_PROTO_IP6, + ) + ], + ) self.ip6_via_ip4_tunnel.add_vpp_config() # # IPv4/IPv6 - IPSEC # - ipsec46 = (Ether(src=self.pg2.remote_mac, dst="02:fe:60:1e:a2:79") / - IPv6(src=self.pg2.remote_ip6, dst="fd01:10::3") / - TCP(sport=1234, dport=1234) / - Raw(b'\xa5' * 65200)) + ipsec46 = ( + Ether(src=self.pg2.remote_mac, dst="02:fe:60:1e:a2:79") + / IPv6(src=self.pg2.remote_ip6, dst="fd01:10::3") + / TCP(sport=1234, dport=1234) + / Raw(b"\xa5" * 65200) + ) rxs = self.send_and_expect(self.pg2, [ipsec46], self.pg0, 45) size = 0 @@ -826,7 +1130,7 @@ class TestGSO(VppTestCase): self.assertEqual(rx[IP].src, self.pg0.local_ip4) self.assertEqual(rx[IP].dst, self.pg0.remote_ip4) self.assertEqual(rx[IP].proto, 50) # ESP - self.assertEqual(rx[ESP].spi, self.ipv4_params.scapy_tun_spi) + self.assertEqual(rx[ESP].spi, self.ipv4_params.vpp_tun_spi) inner = self.ipv4_params.vpp_tun_sa.decrypt(rx[IP]) self.assertEqual(inner[IPv6].src, self.pg2.remote_ip6) self.assertEqual(inner[IPv6].dst, "fd01:10::3") @@ -841,8 +1145,7 @@ class TestGSO(VppTestCase): # # disable ipip4 # - self.vapi.feature_gso_enable_disable(self.ipip4.sw_if_index, - enable_disable=0) + self.vapi.feature_gso_enable_disable(self.ipip4.sw_if_index, enable_disable=0) self.ip4_via_ip4_tunnel.remove_vpp_config() self.ip6_via_ip4_tunnel.remove_vpp_config() self.ipip4.remove_vpp_config() @@ -851,8 +1154,7 @@ class TestGSO(VppTestCase): # enable ipip6 # self.ipip6.add_vpp_config() - self.vapi.feature_gso_enable_disable(self.ipip6.sw_if_index, - enable_disable=1) + self.vapi.feature_gso_enable_disable(self.ipip6.sw_if_index, enable_disable=1) # Set interface up and enable IP on it self.ipip6.admin_up() @@ -860,50 +1162,62 @@ class TestGSO(VppTestCase): # Add IPv4 routes via tunnel interface self.ip4_via_ip6_tunnel = VppIpRoute( - self, "172.16.10.0", 24, - [VppRoutePath("0.0.0.0", - self.ipip6.sw_if_index, - proto=FibPathProto.FIB_PATH_NH_PROTO_IP4)]) + self, + "172.16.10.0", + 24, + [ + VppRoutePath( + "0.0.0.0", + self.ipip6.sw_if_index, + proto=FibPathProto.FIB_PATH_NH_PROTO_IP4, + ) + ], + ) self.ip4_via_ip6_tunnel.add_vpp_config() # IPSec config self.ipv6_params = IPsecIPv6Params() self.encryption_type = ESP config_tun_params(self.ipv6_params, self.encryption_type, self.ipip6) - self.tun_sa_in_v6 = VppIpsecSA(self, self.ipv6_params.vpp_tun_sa_id, - self.ipv6_params.vpp_tun_spi, - self.ipv6_params.auth_algo_vpp_id, - self.ipv6_params.auth_key, - self.ipv6_params.crypt_algo_vpp_id, - self.ipv6_params.crypt_key, - VppEnum.vl_api_ipsec_proto_t. - IPSEC_API_PROTO_ESP) + self.tun_sa_in_v6 = VppIpsecSA( + self, + self.ipv6_params.scapy_tun_sa_id, + self.ipv6_params.scapy_tun_spi, + self.ipv6_params.auth_algo_vpp_id, + self.ipv6_params.auth_key, + self.ipv6_params.crypt_algo_vpp_id, + self.ipv6_params.crypt_key, + VppEnum.vl_api_ipsec_proto_t.IPSEC_API_PROTO_ESP, + ) self.tun_sa_in_v6.add_vpp_config() - self.tun_sa_out_v6 = VppIpsecSA(self, self.ipv6_params.scapy_tun_sa_id, - self.ipv6_params.scapy_tun_spi, - self.ipv6_params.auth_algo_vpp_id, - self.ipv6_params.auth_key, - self.ipv6_params.crypt_algo_vpp_id, - self.ipv6_params.crypt_key, - VppEnum.vl_api_ipsec_proto_t. - IPSEC_API_PROTO_ESP) + self.tun_sa_out_v6 = VppIpsecSA( + self, + self.ipv6_params.vpp_tun_sa_id, + self.ipv6_params.vpp_tun_spi, + self.ipv6_params.auth_algo_vpp_id, + self.ipv6_params.auth_key, + self.ipv6_params.crypt_algo_vpp_id, + self.ipv6_params.crypt_key, + VppEnum.vl_api_ipsec_proto_t.IPSEC_API_PROTO_ESP, + ) self.tun_sa_out_v6.add_vpp_config() - self.tun_protect_v6 = VppIpsecTunProtect(self, - self.ipip6, - self.tun_sa_out_v6, - [self.tun_sa_in_v6]) + self.tun_protect_v6 = VppIpsecTunProtect( + self, self.ipip6, self.tun_sa_out_v6, [self.tun_sa_in_v6] + ) self.tun_protect_v6.add_vpp_config() # # IPv6/IPv4 - IPSEC # - ipsec64 = (Ether(src=self.pg2.remote_mac, dst="02:fe:60:1e:a2:79") / - IP(src=self.pg2.remote_ip4, dst="172.16.10.3", flags='DF') / - TCP(sport=1234, dport=1234) / - Raw(b'\xa5' * 65200)) + ipsec64 = ( + Ether(src=self.pg2.remote_mac, dst="02:fe:60:1e:a2:79") + / IP(src=self.pg2.remote_ip4, dst="172.16.10.3", flags="DF") + / TCP(sport=1234, dport=1234) + / Raw(b"\xa5" * 65200) + ) rxs = self.send_and_expect(self.pg2, [ipsec64], self.pg0, 45) size = 0 @@ -913,7 +1227,7 @@ class TestGSO(VppTestCase): self.assertEqual(rx[IPv6].src, self.pg0.local_ip6) self.assertEqual(rx[IPv6].dst, self.pg0.remote_ip6) self.assertEqual(ipv6nh[rx[IPv6].nh], "ESP Header") - self.assertEqual(rx[ESP].spi, self.ipv6_params.scapy_tun_spi) + self.assertEqual(rx[ESP].spi, self.ipv6_params.vpp_tun_spi) inner = self.ipv6_params.vpp_tun_sa.decrypt(rx[IPv6]) self.assertEqual(inner[IP].src, self.pg2.remote_ip4) self.assertEqual(inner[IP].dst, "172.16.10.3") @@ -921,19 +1235,28 @@ class TestGSO(VppTestCase): self.assertEqual(size, 65200) self.ip6_via_ip6_tunnel = VppIpRoute( - self, "fd01:10::", 64, - [VppRoutePath("::", - self.ipip6.sw_if_index, - proto=FibPathProto.FIB_PATH_NH_PROTO_IP6)]) + self, + "fd01:10::", + 64, + [ + VppRoutePath( + "::", + self.ipip6.sw_if_index, + proto=FibPathProto.FIB_PATH_NH_PROTO_IP6, + ) + ], + ) self.ip6_via_ip6_tunnel.add_vpp_config() # # IPv6/IPv6 - IPSEC # - ipsec66 = (Ether(src=self.pg2.remote_mac, dst="02:fe:60:1e:a2:79") / - IPv6(src=self.pg2.remote_ip6, dst="fd01:10::3") / - TCP(sport=1234, dport=1234) / - Raw(b'\xa5' * 65200)) + ipsec66 = ( + Ether(src=self.pg2.remote_mac, dst="02:fe:60:1e:a2:79") + / IPv6(src=self.pg2.remote_ip6, dst="fd01:10::3") + / TCP(sport=1234, dport=1234) + / Raw(b"\xa5" * 65200) + ) rxs = self.send_and_expect(self.pg2, [ipsec66], self.pg0, 45) size = 0 @@ -943,7 +1266,7 @@ class TestGSO(VppTestCase): self.assertEqual(rx[IPv6].src, self.pg0.local_ip6) self.assertEqual(rx[IPv6].dst, self.pg0.remote_ip6) self.assertEqual(ipv6nh[rx[IPv6].nh], "ESP Header") - self.assertEqual(rx[ESP].spi, self.ipv6_params.scapy_tun_spi) + self.assertEqual(rx[ESP].spi, self.ipv6_params.vpp_tun_spi) inner = self.ipv6_params.vpp_tun_sa.decrypt(rx[IPv6]) self.assertEqual(inner[IPv6].src, self.pg2.remote_ip6) self.assertEqual(inner[IPv6].dst, "fd01:10::3") @@ -962,8 +1285,8 @@ class TestGSO(VppTestCase): self.ip6_via_ip6_tunnel.remove_vpp_config() self.ipip6.remove_vpp_config() - self.vapi.feature_gso_enable_disable(self.pg0.sw_if_index, - enable_disable=0) + self.vapi.feature_gso_enable_disable(self.pg0.sw_if_index, enable_disable=0) + -if __name__ == '__main__': +if __name__ == "__main__": unittest.main(testRunner=VppTestRunner)