2 """GRO functional tests"""
7 # - Verify that sending 1500 Bytes frame without GRO enabled correctly
8 # - Verify that sending 1500 Bytes frame with GRO enabled correctly
12 from scapy.packet import Raw
13 from scapy.layers.inet6 import IPv6, Ether, IP
14 from scapy.layers.inet import TCP
16 from framework import VppTestCase
17 from asfframework import VppTestRunner
20 """ Test_gro is a subclass of VPPTestCase classes.
25 class TestGRO(VppTestCase):
30 super(TestGRO, self).setUpClass()
31 res = self.create_pg_interfaces(range(2))
32 res_gro = self.create_pg_interfaces(range(2, 3), 1, 1460)
33 self.create_pg_interfaces(range(3, 4), 1, 8940)
34 self.pg_interfaces.append(res[0])
35 self.pg_interfaces.append(res[1])
36 self.pg_interfaces.append(res_gro[0])
37 self.pg2.coalesce_enable()
38 self.pg3.coalesce_enable()
41 def tearDownClass(self):
42 super(TestGRO, self).tearDownClass()
45 super(TestGRO, self).setUp()
46 for i in self.pg_interfaces:
55 super(TestGRO, self).tearDown()
57 for i in self.pg_interfaces:
67 # Send 1500 bytes frame with gro disabled
70 Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac)
71 / IP(src=self.pg0.remote_ip4, dst=self.pg1.remote_ip4, flags="DF")
72 / TCP(sport=1234, dport=4321)
76 rxs = self.send_and_expect(self.pg0, n_packets * p4, self.pg1)
78 self.assertEqual(rx[Ether].src, self.pg1.local_mac)
79 self.assertEqual(rx[Ether].dst, self.pg1.remote_mac)
80 self.assertEqual(rx[IP].src, self.pg0.remote_ip4)
81 self.assertEqual(rx[IP].dst, self.pg1.remote_ip4)
82 self.assertEqual(rx[TCP].sport, 1234)
83 self.assertEqual(rx[TCP].dport, 4321)
86 # Send 1500 bytes frame with gro enabled on
87 # output interfaces support GRO
91 for n in range(0, n_packets):
94 Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac)
95 / IP(src=self.pg0.remote_ip4, dst=self.pg2.remote_ip4, flags="DF")
96 / TCP(sport=1234, dport=4321, seq=s, ack=n, flags="A")
102 rxs = self.send_and_expect(self.pg0, p, self.pg2, n_rx=2)
107 self.assertEqual(rx[Ether].src, self.pg2.local_mac)
108 self.assertEqual(rx[Ether].dst, self.pg2.remote_mac)
109 self.assertEqual(rx[IP].src, self.pg0.remote_ip4)
110 self.assertEqual(rx[IP].dst, self.pg2.remote_ip4)
111 self.assertEqual(rx[IP].len, 64280) # 1460 * 44 + 40 < 65536
112 self.assertEqual(rx[TCP].sport, 1234)
113 self.assertEqual(rx[TCP].dport, 4321)
114 self.assertEqual(rx[TCP].ack, (44 * i - 1))
117 Ether(src=self.pg2.remote_mac, dst=self.pg2.local_mac)
118 / IP(src=self.pg2.remote_ip4, dst=self.pg0.remote_ip4, flags="DF")
119 / TCP(sport=1234, dport=4321, flags="F")
122 rxs = self.send_and_expect(self.pg2, 100 * [p4_temp], self.pg0, n_rx=100)
123 rx_coalesce = self.pg2.get_capture(1, timeout=1)
126 self.assertEqual(rx0[Ether].src, self.pg2.local_mac)
127 self.assertEqual(rx0[Ether].dst, self.pg2.remote_mac)
128 self.assertEqual(rx0[IP].src, self.pg0.remote_ip4)
129 self.assertEqual(rx0[IP].dst, self.pg2.remote_ip4)
130 self.assertEqual(rx0[IP].len, 52600) # 1460 * 36 + 40
131 self.assertEqual(rx0[TCP].sport, 1234)
132 self.assertEqual(rx0[TCP].dport, 4321)
135 self.assertEqual(rx[Ether].src, self.pg0.local_mac)
136 self.assertEqual(rx[Ether].dst, self.pg0.remote_mac)
137 self.assertEqual(rx[IP].src, self.pg2.remote_ip4)
138 self.assertEqual(rx[IP].dst, self.pg0.remote_ip4)
139 self.assertEqual(rx[IP].len, 40)
140 self.assertEqual(rx[TCP].sport, 1234)
141 self.assertEqual(rx[TCP].dport, 4321)
144 # Same test with IPv6
148 for n in range(0, 88):
151 Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac)
152 / IPv6(src=self.pg0.remote_ip6, dst=self.pg2.remote_ip6)
153 / TCP(sport=1234, dport=4321, seq=s, ack=n, flags="A")
154 / Raw(b"\xa5" * 1460)
158 p[-1][TCP].flags = "AP" # push to flush second packet
160 rxs = self.send_and_expect(self.pg0, p, self.pg2, n_rx=2)
165 self.assertEqual(rx[Ether].src, self.pg2.local_mac)
166 self.assertEqual(rx[Ether].dst, self.pg2.remote_mac)
167 self.assertEqual(rx[IPv6].src, self.pg0.remote_ip6)
168 self.assertEqual(rx[IPv6].dst, self.pg2.remote_ip6)
169 self.assertEqual(rx[IPv6].plen, 64260) # 1460 * 44 + 20 < 65536
170 self.assertEqual(rx[TCP].sport, 1234)
171 self.assertEqual(rx[TCP].dport, 4321)
172 self.assertEqual(rx[TCP].ack, (44 * i - 1))
175 # Send a series of 1500 bytes packets each followed by a packet with a
176 # PSH flag. Verify that GRO stops everytime a PSH flag is encountered
180 for n in range(0, n_packets):
183 Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac)
184 / IP(src=self.pg0.remote_ip4, dst=self.pg2.remote_ip4, flags="DF")
185 / TCP(sport=1234, dport=4321, seq=s, ack=2 * n, flags="A")
186 / Raw(b"\xa5" * 1460)
192 Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac)
193 / IP(src=self.pg0.remote_ip4, dst=self.pg2.remote_ip4, flags="DF")
194 / TCP(sport=1234, dport=4321, seq=s, ack=2 * n + 1, flags="AP")
195 / Raw(b"\xa5" * 1340)
200 rxs = self.send_and_expect(self.pg0, p, self.pg2, n_rx=n_packets)
204 self.assertEqual(rx[Ether].src, self.pg2.local_mac)
205 self.assertEqual(rx[Ether].dst, self.pg2.remote_mac)
206 self.assertEqual(rx[IP].src, self.pg0.remote_ip4)
207 self.assertEqual(rx[IP].dst, self.pg2.remote_ip4)
208 self.assertEqual(rx[IP].len, 40 + 1460 + 1340)
209 self.assertEqual(rx[TCP].sport, 1234)
210 self.assertEqual(rx[TCP].dport, 4321)
211 self.assertEqual(rx[TCP].ack, (2 * i + 1))
215 # Send a series of 1500 bytes packets each followed by a short packet
216 # with padding. Verify that GRO removes the padding and stops on short
221 for n in range(0, n_packets):
225 Ether(src=i.remote_mac, dst=i.local_mac)
226 / IP(src=i.remote_ip4, dst=self.pg2.remote_ip4, flags="DF")
227 / TCP(sport=1234, dport=4321, seq=s, ack=2 * n, flags="A")
228 / Raw(b"\xa5" * 1459)
233 Ether(src=i.remote_mac, dst=i.local_mac)
234 / IP(src=i.remote_ip4, dst=self.pg2.remote_ip4, flags="DF", len=41)
235 / TCP(sport=1234, dport=4321, seq=s, ack=2 * n + 1, flags="A")
238 # first compute csum of pkt w/o padding to work around scapy bug
239 p2 = Ether(bytes(p2))
240 p.append(p2 / Raw(b"\xa5" * 5)) # 1 byte data + 5 bytes padding
243 rxs = self.send_and_expect(self.pg0, p, self.pg2, n_rx=n_packets)
247 self.assertEqual(rx[Ether].src, self.pg2.local_mac)
248 self.assertEqual(rx[Ether].dst, self.pg2.remote_mac)
249 self.assertEqual(rx[IP].src, self.pg0.remote_ip4)
250 self.assertEqual(rx[IP].dst, self.pg2.remote_ip4)
251 self.assertEqual(rx[IP].len, 40 + 1459 + 1)
252 self.assertEqual(rx[TCP].sport, 1234)
253 self.assertEqual(rx[TCP].dport, 4321)
254 self.assertEqual(rx[TCP].ack, (2 * i + 1))
258 if __name__ == "__main__":
259 unittest.main(testRunner=VppTestRunner)