2 """GSO functional tests"""
7 # - Verify that sending Jumbo frame without GSO enabled correctly
8 # - Verify that sending Jumbo frame with GSO enabled correctly
9 # - Verify that sending Jumbo frame with GSO enabled only on ingress interface
13 from scapy.packet import Raw
14 from scapy.layers.inet6 import IPv6, Ether, IP, UDP, ICMPv6PacketTooBig
15 from scapy.layers.inet import TCP, ICMP
16 from scapy.layers.vxlan import VXLAN
17 from scapy.data import ETH_P_IP, ETH_P_IPV6, ETH_P_ARP
19 from framework import VppTestCase, VppTestRunner
20 from vpp_object import VppObject
21 from vpp_interface import VppInterface
22 from vpp_ip import DpoProto
23 from vpp_ip_route import VppIpRoute, VppRoutePath, FibPathProto
24 from socket import AF_INET, AF_INET6, inet_pton
25 from util import reassemble4
28 """ Test_gso is a subclass of VPPTestCase classes.
33 class TestGSO(VppTestCase):
36 def __init__(self, *args):
37 VppTestCase.__init__(self, *args)
41 super(TestGSO, self).setUpClass()
44 def tearDownClass(self):
45 super(TestGSO, self).tearDownClass()
48 super(TestGSO, self).setUp()
51 super(TestGSO, self).tearDown()
53 for i in self.pg_interfaces:
61 # Send jumbo frame with gso disabled and DF bit is set
63 self.create_pg_interfaces(range(2))
64 for i in self.pg_interfaces:
72 p4 = (Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac) /
73 IP(src=self.pg0.remote_ip4, dst=self.pg1.remote_ip4,
75 TCP(sport=1234, dport=1234) /
78 rxs = self.send_and_expect(self.pg0, [p4], self.pg0)
81 self.assertEqual(rx[Ether].src, self.pg0.local_mac)
82 self.assertEqual(rx[Ether].dst, self.pg0.remote_mac)
83 self.assertEqual(rx[IP].src, self.pg0.local_ip4)
84 self.assertEqual(rx[IP].dst, self.pg0.remote_ip4)
85 self.assertEqual(rx[ICMP].type, 3) # "dest-unreach"
86 self.assertEqual(rx[ICMP].code, 4) # "fragmentation-needed"
89 # Send jumbo frame with gso enabled and DF bit is set
90 # input and output interfaces support GSO
92 self.create_pg_interfaces(range(2, 4), 1, 1460)
93 for i in self.pg_interfaces:
101 p41 = (Ether(src=self.pg2.remote_mac, dst=self.pg2.local_mac) /
102 IP(src=self.pg2.remote_ip4, dst=self.pg3.remote_ip4,
104 TCP(sport=1234, dport=1234) /
107 rxs = self.send_and_expect(self.pg2, [p41], self.pg3)
110 self.assertEqual(rx[Ether].src, self.pg3.local_mac)
111 self.assertEqual(rx[Ether].dst, self.pg3.remote_mac)
112 self.assertEqual(rx[IP].src, self.pg2.remote_ip4)
113 self.assertEqual(rx[IP].dst, self.pg3.remote_ip4)
114 self.assertEqual(rx[IP].len, 65240) # 65200 + 20 (IP) + 20 (TCP)
115 self.assertEqual(rx[TCP].sport, 1234)
116 self.assertEqual(rx[TCP].dport, 1234)
119 # Send jumbo frame with gso enabled only on input interface
120 # and DF bit is set. GSO packet will be chunked into gso_size
123 self.create_pg_interfaces(range(4, 5))
124 for i in self.pg_interfaces:
132 p42 = (Ether(src=self.pg2.remote_mac, dst=self.pg2.local_mac) /
133 IP(src=self.pg2.remote_ip4, dst=self.pg4.remote_ip4,
135 TCP(sport=1234, dport=1234) /
138 rxs = self.send_and_expect(self.pg2, [p42], self.pg4, 45)
141 self.assertEqual(rx[Ether].src, self.pg4.local_mac)
142 self.assertEqual(rx[Ether].dst, self.pg4.remote_mac)
143 self.assertEqual(rx[IP].src, self.pg2.remote_ip4)
144 self.assertEqual(rx[IP].dst, self.pg4.remote_ip4)
145 self.assertEqual(rx[TCP].sport, 1234)
146 self.assertEqual(rx[TCP].dport, 1234)
148 size = rxs[44][TCP].seq + rxs[44][IP].len - 20 - 20
149 self.assertEqual(size, 65200)
152 # Send jumbo frame with gso enabled only on input interface
153 # and DF bit is unset. GSO packet will be fragmented.
155 self.vapi.sw_interface_set_mtu(self.pg1.sw_if_index, [576, 0, 0, 0])
157 p43 = (Ether(src=self.pg2.remote_mac, dst=self.pg2.local_mac) /
158 IP(src=self.pg2.remote_ip4, dst=self.pg1.remote_ip4) /
159 TCP(sport=1234, dport=1234) /
162 rxs = self.send_and_expect(self.pg2, [p43], self.pg1, 119)
165 self.assertEqual(rx[Ether].src, self.pg1.local_mac)
166 self.assertEqual(rx[Ether].dst, self.pg1.remote_mac)
167 self.assertEqual(rx[IP].src, self.pg2.remote_ip4)
168 self.assertEqual(rx[IP].dst, self.pg1.remote_ip4)
169 size += rx[IP].len - 20
170 size -= 20 # TCP header
171 self.assertEqual(size, 65200)
174 # Send jumbo frame with gso enabled only on input interface with 9K MTU
175 # and DF bit is unset. GSO packet will be fragmented. GSO size will be
178 self.vapi.sw_interface_set_mtu(self.pg1.sw_if_index, [9000, 0, 0, 0])
179 self.create_pg_interfaces(range(5, 6), 1, 8960)
180 for i in self.pg_interfaces:
188 self.vapi.sw_interface_set_mtu(self.pg5.sw_if_index, [9000, 0, 0, 0])
189 p44 = (Ether(src=self.pg5.remote_mac, dst=self.pg5.local_mac) /
190 IP(src=self.pg5.remote_ip4, dst=self.pg1.remote_ip4) /
191 TCP(sport=1234, dport=1234) /
194 self.pg1.enable_capture()
195 rxs = self.send_and_expect(self.pg5, [p44], self.pg1, 33)
198 self.assertEqual(rx[Ether].src, self.pg1.local_mac)
199 self.assertEqual(rx[Ether].dst, self.pg1.remote_mac)
200 self.assertEqual(rx[IP].src, self.pg5.remote_ip4)
201 self.assertEqual(rx[IP].dst, self.pg1.remote_ip4)
202 size = rxs[32][TCP].seq + rxs[32][IP].len - 20 - 20
203 self.assertEqual(size, 65200)
205 if __name__ == '__main__':
206 unittest.main(testRunner=VppTestRunner)