blob: 94062b89ae2345331848fedcce6292f913d4ba05 [file] [log] [blame]
Neale Ranns039cbfe2018-02-27 03:45:38 -08001#!/usr/bin/env python
2
3import unittest
Neale Ranns039cbfe2018-02-27 03:45:38 -08004
5from framework import VppTestCase, VppTestRunner
Neale Ranns0809f6c2018-07-16 04:14:21 -07006from vpp_sub_interface import VppDot1QSubint
Neale Rannsc0a93142018-09-05 15:42:26 -07007from vpp_ip import DpoProto
Neale Ranns0809f6c2018-07-16 04:14:21 -07008from vpp_ip_route import VppIpRoute, VppRoutePath, VppMplsRoute, \
Neale Ranns097fa662018-05-01 05:17:55 -07009 VppMplsLabel, VppMplsTable, FibPathProto
Neale Ranns039cbfe2018-02-27 03:45:38 -080010
Paul Vinciguerraa7427ec2019-03-10 10:04:23 -070011import scapy.compat
Neale Ranns039cbfe2018-02-27 03:45:38 -080012from scapy.packet import Raw
Neale Ranns0809f6c2018-07-16 04:14:21 -070013from scapy.layers.l2 import Ether, Dot1Q
Neale Ranns039cbfe2018-02-27 03:45:38 -080014from scapy.layers.inet import IP, UDP
15from scapy.layers.inet6 import IPv6
16from scapy.contrib.mpls import MPLS
Paul Vinciguerrab7658202019-05-17 09:48:15 -040017from vpp_papi import VppEnum
Neale Ranns039cbfe2018-02-27 03:45:38 -080018
Paul Vinciguerra4271c972019-05-14 13:25:49 -040019NUM_PKTS = 67
20
Neale Ranns039cbfe2018-02-27 03:45:38 -080021
22class TestQOS(VppTestCase):
23 """ QOS Test Case """
24
Paul Vinciguerrab7658202019-05-17 09:48:15 -040025 # Note: Since the enums aren't created dynamically until after
26 # the papi client attaches to VPP, we put it in a property to
27 # ensure it is the value at runtime, not at module load time.
28 @property
29 def QOS_SOURCE(self):
30 return VppEnum.vl_api_qos_source_t
31
Paul Vinciguerra7f9b7f92019-03-12 19:23:27 -070032 @classmethod
33 def setUpClass(cls):
34 super(TestQOS, cls).setUpClass()
35
36 @classmethod
37 def tearDownClass(cls):
38 super(TestQOS, cls).tearDownClass()
39
Neale Ranns039cbfe2018-02-27 03:45:38 -080040 def setUp(self):
41 super(TestQOS, self).setUp()
42
43 self.create_pg_interfaces(range(5))
44
Neale Ranns0809f6c2018-07-16 04:14:21 -070045 tbl = VppMplsTable(self, 0)
46 tbl.add_vpp_config()
47
Neale Ranns039cbfe2018-02-27 03:45:38 -080048 for i in self.pg_interfaces:
49 i.admin_up()
50 i.config_ip4()
51 i.resolve_arp()
52 i.config_ip6()
53 i.resolve_ndp()
Neale Ranns0809f6c2018-07-16 04:14:21 -070054 i.enable_mpls()
Neale Ranns039cbfe2018-02-27 03:45:38 -080055
56 def tearDown(self):
57 for i in self.pg_interfaces:
58 i.unconfig_ip4()
59 i.unconfig_ip6()
Neale Ranns0809f6c2018-07-16 04:14:21 -070060 i.disable_mpls()
Neale Ranns039cbfe2018-02-27 03:45:38 -080061
62 super(TestQOS, self).tearDown()
63
64 def test_qos_ip(self):
Neale Ranns0809f6c2018-07-16 04:14:21 -070065 """ QoS Mark/Record IP """
Neale Ranns039cbfe2018-02-27 03:45:38 -080066
67 #
68 # for table 1 map the n=0xff possible values of input QoS mark,
69 # n to 1-n
70 #
Paul Vinciguerraa7427ec2019-03-10 10:04:23 -070071 output = [scapy.compat.chb(0)] * 256
Neale Ranns039cbfe2018-02-27 03:45:38 -080072 for i in range(0, 255):
Paul Vinciguerraa7427ec2019-03-10 10:04:23 -070073 output[i] = scapy.compat.chb(255 - i)
74 os = b''.join(output)
Neale Ranns039cbfe2018-02-27 03:45:38 -080075 rows = [{'outputs': os},
76 {'outputs': os},
77 {'outputs': os},
78 {'outputs': os}]
79
80 self.vapi.qos_egress_map_update(1, rows)
81
82 #
83 # For table 2 (and up) use the value n for everything
84 #
Paul Vinciguerraa7427ec2019-03-10 10:04:23 -070085 output = [scapy.compat.chb(2)] * 256
86 os = b''.join(output)
Neale Ranns039cbfe2018-02-27 03:45:38 -080087 rows = [{'outputs': os},
88 {'outputs': os},
89 {'outputs': os},
90 {'outputs': os}]
91
92 self.vapi.qos_egress_map_update(2, rows)
93
Paul Vinciguerraa7427ec2019-03-10 10:04:23 -070094 output = [scapy.compat.chb(3)] * 256
95 os = b''.join(output)
Neale Ranns039cbfe2018-02-27 03:45:38 -080096 rows = [{'outputs': os},
97 {'outputs': os},
98 {'outputs': os},
99 {'outputs': os}]
100
101 self.vapi.qos_egress_map_update(3, rows)
102
Paul Vinciguerraa7427ec2019-03-10 10:04:23 -0700103 output = [scapy.compat.chb(4)] * 256
104 os = b''.join(output)
Neale Ranns039cbfe2018-02-27 03:45:38 -0800105 rows = [{'outputs': os},
106 {'outputs': os},
107 {'outputs': os},
108 {'outputs': os}]
109 self.vapi.qos_egress_map_update(4, rows)
110 self.vapi.qos_egress_map_update(5, rows)
111 self.vapi.qos_egress_map_update(6, rows)
112 self.vapi.qos_egress_map_update(7, rows)
113
114 self.logger.info(self.vapi.cli("sh qos eg map"))
115
116 #
117 # Bind interface pgN to table n
118 #
119 self.vapi.qos_mark_enable_disable(self.pg1.sw_if_index,
Paul Vinciguerrab7658202019-05-17 09:48:15 -0400120 self.QOS_SOURCE.QOS_API_SOURCE_IP,
Neale Ranns039cbfe2018-02-27 03:45:38 -0800121 1,
122 1)
123 self.vapi.qos_mark_enable_disable(self.pg2.sw_if_index,
Paul Vinciguerrab7658202019-05-17 09:48:15 -0400124 self.QOS_SOURCE.QOS_API_SOURCE_IP,
Neale Ranns039cbfe2018-02-27 03:45:38 -0800125 2,
126 1)
127 self.vapi.qos_mark_enable_disable(self.pg3.sw_if_index,
Paul Vinciguerrab7658202019-05-17 09:48:15 -0400128 self.QOS_SOURCE.QOS_API_SOURCE_IP,
Neale Ranns039cbfe2018-02-27 03:45:38 -0800129 3,
130 1)
131 self.vapi.qos_mark_enable_disable(self.pg4.sw_if_index,
Paul Vinciguerrab7658202019-05-17 09:48:15 -0400132 self.QOS_SOURCE.QOS_API_SOURCE_IP,
Neale Ranns039cbfe2018-02-27 03:45:38 -0800133 4,
134 1)
135
136 #
137 # packets ingress on Pg0
138 #
139 p_v4 = (Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac) /
140 IP(src=self.pg0.remote_ip4, dst=self.pg1.remote_ip4, tos=1) /
141 UDP(sport=1234, dport=1234) /
Paul Vinciguerra4271c972019-05-14 13:25:49 -0400142 Raw(scapy.compat.chb(100) * NUM_PKTS))
Neale Ranns039cbfe2018-02-27 03:45:38 -0800143 p_v6 = (Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac) /
144 IPv6(src=self.pg0.remote_ip6, dst=self.pg1.remote_ip6,
145 tc=1) /
146 UDP(sport=1234, dport=1234) /
Paul Vinciguerra4271c972019-05-14 13:25:49 -0400147 Raw(scapy.compat.chb(100) * NUM_PKTS))
Neale Ranns039cbfe2018-02-27 03:45:38 -0800148
149 #
150 # Since we have not yet enabled the recording of the input QoS
151 # from the input iP header, the egress packet's ToS will be unchanged
152 #
Paul Vinciguerra4271c972019-05-14 13:25:49 -0400153 rx = self.send_and_expect(self.pg0, p_v4 * NUM_PKTS, self.pg1)
Neale Ranns039cbfe2018-02-27 03:45:38 -0800154 for p in rx:
155 self.assertEqual(p[IP].tos, 1)
Paul Vinciguerra4271c972019-05-14 13:25:49 -0400156 rx = self.send_and_expect(self.pg0, p_v6 * NUM_PKTS, self.pg1)
Neale Ranns039cbfe2018-02-27 03:45:38 -0800157 for p in rx:
158 self.assertEqual(p[IPv6].tc, 1)
159
160 #
Paul Vinciguerra8feeaff2019-03-27 11:25:48 -0700161 # Enable QoS recording on IP input for pg0
Neale Ranns039cbfe2018-02-27 03:45:38 -0800162 #
163 self.vapi.qos_record_enable_disable(self.pg0.sw_if_index,
Paul Vinciguerrab7658202019-05-17 09:48:15 -0400164 self.QOS_SOURCE.QOS_API_SOURCE_IP,
Neale Ranns039cbfe2018-02-27 03:45:38 -0800165 1)
166
167 #
168 # send the same packets, this time expect the input TOS of 1
169 # to be mapped to pg1's egress value of 254
170 #
Paul Vinciguerra4271c972019-05-14 13:25:49 -0400171 rx = self.send_and_expect(self.pg0, p_v4 * NUM_PKTS, self.pg1)
Neale Ranns039cbfe2018-02-27 03:45:38 -0800172 for p in rx:
173 self.assertEqual(p[IP].tos, 254)
Paul Vinciguerra4271c972019-05-14 13:25:49 -0400174 rx = self.send_and_expect(self.pg0, p_v6 * NUM_PKTS, self.pg1)
Neale Ranns039cbfe2018-02-27 03:45:38 -0800175 for p in rx:
176 self.assertEqual(p[IPv6].tc, 254)
177
178 #
179 # different input ToS to test the mapping
180 #
181 p_v4[IP].tos = 127
Paul Vinciguerra4271c972019-05-14 13:25:49 -0400182 rx = self.send_and_expect(self.pg0, p_v4 * NUM_PKTS, self.pg1)
Neale Ranns039cbfe2018-02-27 03:45:38 -0800183 for p in rx:
184 self.assertEqual(p[IP].tos, 128)
185 p_v6[IPv6].tc = 127
Paul Vinciguerra4271c972019-05-14 13:25:49 -0400186 rx = self.send_and_expect(self.pg0, p_v6 * NUM_PKTS, self.pg1)
Neale Ranns039cbfe2018-02-27 03:45:38 -0800187 for p in rx:
188 self.assertEqual(p[IPv6].tc, 128)
189
190 p_v4[IP].tos = 254
Paul Vinciguerra4271c972019-05-14 13:25:49 -0400191 rx = self.send_and_expect(self.pg0, p_v4 * NUM_PKTS, self.pg1)
Neale Ranns039cbfe2018-02-27 03:45:38 -0800192 for p in rx:
193 self.assertEqual(p[IP].tos, 1)
194 p_v6[IPv6].tc = 254
Paul Vinciguerra4271c972019-05-14 13:25:49 -0400195 rx = self.send_and_expect(self.pg0, p_v6 * NUM_PKTS, self.pg1)
Neale Ranns039cbfe2018-02-27 03:45:38 -0800196 for p in rx:
197 self.assertEqual(p[IPv6].tc, 1)
198
199 #
200 # send packets out the other interfaces to test the maps are
201 # correctly applied
202 #
203 p_v4[IP].dst = self.pg2.remote_ip4
Paul Vinciguerra4271c972019-05-14 13:25:49 -0400204 rx = self.send_and_expect(self.pg0, p_v4 * NUM_PKTS, self.pg2)
Neale Ranns039cbfe2018-02-27 03:45:38 -0800205 for p in rx:
206 self.assertEqual(p[IP].tos, 2)
207
208 p_v4[IP].dst = self.pg3.remote_ip4
Paul Vinciguerra4271c972019-05-14 13:25:49 -0400209 rx = self.send_and_expect(self.pg0, p_v4 * NUM_PKTS, self.pg3)
Neale Ranns039cbfe2018-02-27 03:45:38 -0800210 for p in rx:
211 self.assertEqual(p[IP].tos, 3)
212
213 p_v6[IPv6].dst = self.pg3.remote_ip6
Paul Vinciguerra4271c972019-05-14 13:25:49 -0400214 rx = self.send_and_expect(self.pg0, p_v6 * NUM_PKTS, self.pg3)
Neale Ranns039cbfe2018-02-27 03:45:38 -0800215 for p in rx:
216 self.assertEqual(p[IPv6].tc, 3)
217
218 #
219 # remove the map on pg2 and pg3, now expect an unchanged IP tos
220 #
221 self.vapi.qos_mark_enable_disable(self.pg2.sw_if_index,
Paul Vinciguerrab7658202019-05-17 09:48:15 -0400222 self.QOS_SOURCE.QOS_API_SOURCE_IP,
Neale Ranns039cbfe2018-02-27 03:45:38 -0800223 2,
224 0)
225 self.vapi.qos_mark_enable_disable(self.pg3.sw_if_index,
Paul Vinciguerrab7658202019-05-17 09:48:15 -0400226 self.QOS_SOURCE.QOS_API_SOURCE_IP,
Neale Ranns039cbfe2018-02-27 03:45:38 -0800227 3,
228 0)
229 self.logger.info(self.vapi.cli("sh int feat pg2"))
230
231 p_v4[IP].dst = self.pg2.remote_ip4
Paul Vinciguerra4271c972019-05-14 13:25:49 -0400232 rx = self.send_and_expect(self.pg0, p_v4 * NUM_PKTS, self.pg2)
Neale Ranns039cbfe2018-02-27 03:45:38 -0800233 for p in rx:
234 self.assertEqual(p[IP].tos, 254)
235
236 p_v4[IP].dst = self.pg3.remote_ip4
Paul Vinciguerra4271c972019-05-14 13:25:49 -0400237 rx = self.send_and_expect(self.pg0, p_v4 * NUM_PKTS, self.pg3)
Neale Ranns039cbfe2018-02-27 03:45:38 -0800238 for p in rx:
239 self.assertEqual(p[IP].tos, 254)
240
241 #
242 # still mapping out of pg1
243 #
244 p_v4[IP].dst = self.pg1.remote_ip4
Paul Vinciguerra4271c972019-05-14 13:25:49 -0400245 rx = self.send_and_expect(self.pg0, p_v4 * NUM_PKTS, self.pg1)
Neale Ranns039cbfe2018-02-27 03:45:38 -0800246 for p in rx:
247 self.assertEqual(p[IP].tos, 1)
248
249 #
250 # disable the input recording on pg0
251 #
252 self.vapi.qos_record_enable_disable(self.pg0.sw_if_index,
Paul Vinciguerrab7658202019-05-17 09:48:15 -0400253 self.QOS_SOURCE.QOS_API_SOURCE_IP,
Neale Ranns039cbfe2018-02-27 03:45:38 -0800254 0)
255
256 #
257 # back to an unchanged TOS value
258 #
Paul Vinciguerra4271c972019-05-14 13:25:49 -0400259 rx = self.send_and_expect(self.pg0, p_v4 * NUM_PKTS, self.pg1)
Neale Ranns039cbfe2018-02-27 03:45:38 -0800260 for p in rx:
261 self.assertEqual(p[IP].tos, 254)
262
263 #
264 # disable the egress map on pg1 and pg4
265 #
266 self.vapi.qos_mark_enable_disable(self.pg1.sw_if_index,
Paul Vinciguerrab7658202019-05-17 09:48:15 -0400267 self.QOS_SOURCE.QOS_API_SOURCE_IP,
Neale Ranns039cbfe2018-02-27 03:45:38 -0800268 1,
269 0)
270 self.vapi.qos_mark_enable_disable(self.pg4.sw_if_index,
Paul Vinciguerrab7658202019-05-17 09:48:15 -0400271 self.QOS_SOURCE.QOS_API_SOURCE_IP,
Neale Ranns039cbfe2018-02-27 03:45:38 -0800272 4,
273 0)
274
275 #
276 # unchanged Tos on pg1
277 #
Paul Vinciguerra4271c972019-05-14 13:25:49 -0400278 rx = self.send_and_expect(self.pg0, p_v4 * NUM_PKTS, self.pg1)
Neale Ranns039cbfe2018-02-27 03:45:38 -0800279 for p in rx:
280 self.assertEqual(p[IP].tos, 254)
281
282 #
Paul Vinciguerra8feeaff2019-03-27 11:25:48 -0700283 # clean-up the map
Neale Ranns039cbfe2018-02-27 03:45:38 -0800284 #
285 self.vapi.qos_egress_map_delete(1)
286 self.vapi.qos_egress_map_delete(4)
287 self.vapi.qos_egress_map_delete(2)
288 self.vapi.qos_egress_map_delete(3)
289 self.vapi.qos_egress_map_delete(5)
290 self.vapi.qos_egress_map_delete(6)
291 self.vapi.qos_egress_map_delete(7)
292
293 def test_qos_mpls(self):
Neale Ranns0809f6c2018-07-16 04:14:21 -0700294 """ QoS Mark/Record MPLS """
Neale Ranns039cbfe2018-02-27 03:45:38 -0800295
296 #
297 # 255 QoS for all input values
298 #
Neale Ranns18668842018-11-15 07:46:12 +0000299 from_ext = 7
300 from_ip = 6
301 from_mpls = 5
302 from_vlan = 4
Paul Vinciguerraa7427ec2019-03-10 10:04:23 -0700303 output = [scapy.compat.chb(from_ext)] * 256
304 os1 = b''.join(output)
305 output = [scapy.compat.chb(from_vlan)] * 256
306 os2 = b''.join(output)
307 output = [scapy.compat.chb(from_mpls)] * 256
308 os3 = b''.join(output)
309 output = [scapy.compat.chb(from_ip)] * 256
310 os4 = b''.join(output)
Neale Ranns18668842018-11-15 07:46:12 +0000311 rows = [{'outputs': os1},
312 {'outputs': os2},
313 {'outputs': os3},
314 {'outputs': os4}]
Neale Ranns039cbfe2018-02-27 03:45:38 -0800315
316 self.vapi.qos_egress_map_update(1, rows)
317
318 #
319 # a route with 1 MPLS label
320 #
321 route_10_0_0_1 = VppIpRoute(self, "10.0.0.1", 32,
322 [VppRoutePath(self.pg1.remote_ip4,
323 self.pg1.sw_if_index,
324 labels=[32])])
325 route_10_0_0_1.add_vpp_config()
326
327 #
328 # a route with 3 MPLS labels
329 #
330 route_10_0_0_3 = VppIpRoute(self, "10.0.0.3", 32,
331 [VppRoutePath(self.pg1.remote_ip4,
332 self.pg1.sw_if_index,
333 labels=[63, 33, 34])])
334 route_10_0_0_3.add_vpp_config()
335
336 #
337 # enable IP QoS recording on the input Pg0 and MPLS egress marking
338 # on Pg1
339 #
340 self.vapi.qos_record_enable_disable(self.pg0.sw_if_index,
Paul Vinciguerrab7658202019-05-17 09:48:15 -0400341 self.QOS_SOURCE.QOS_API_SOURCE_IP,
Neale Ranns039cbfe2018-02-27 03:45:38 -0800342 1)
343 self.vapi.qos_mark_enable_disable(self.pg1.sw_if_index,
Paul Vinciguerrab7658202019-05-17 09:48:15 -0400344 self.QOS_SOURCE.QOS_API_SOURCE_MPLS,
Neale Ranns039cbfe2018-02-27 03:45:38 -0800345 1,
346 1)
347
348 #
349 # packet that will get one label added and 3 labels added resp.
350 #
351 p_1 = (Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac) /
352 IP(src=self.pg0.remote_ip4, dst="10.0.0.1", tos=1) /
353 UDP(sport=1234, dport=1234) /
Paul Vinciguerra4271c972019-05-14 13:25:49 -0400354 Raw(scapy.compat.chb(100) * NUM_PKTS))
Neale Ranns039cbfe2018-02-27 03:45:38 -0800355 p_3 = (Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac) /
356 IP(src=self.pg0.remote_ip4, dst="10.0.0.3", tos=1) /
357 UDP(sport=1234, dport=1234) /
Paul Vinciguerra4271c972019-05-14 13:25:49 -0400358 Raw(scapy.compat.chb(100) * NUM_PKTS))
Neale Ranns039cbfe2018-02-27 03:45:38 -0800359
Paul Vinciguerra4271c972019-05-14 13:25:49 -0400360 rx = self.send_and_expect(self.pg0, p_1 * NUM_PKTS, self.pg1)
Neale Ranns039cbfe2018-02-27 03:45:38 -0800361
362 #
363 # only 3 bits of ToS value in MPLS make sure tos is correct
364 # and the label and EOS bit have not been corrupted
365 #
366 for p in rx:
Neale Ranns18668842018-11-15 07:46:12 +0000367 self.assertEqual(p[MPLS].cos, from_ip)
Neale Ranns039cbfe2018-02-27 03:45:38 -0800368 self.assertEqual(p[MPLS].label, 32)
369 self.assertEqual(p[MPLS].s, 1)
Paul Vinciguerra4271c972019-05-14 13:25:49 -0400370 rx = self.send_and_expect(self.pg0, p_3 * NUM_PKTS, self.pg1)
Neale Ranns039cbfe2018-02-27 03:45:38 -0800371 for p in rx:
Neale Ranns18668842018-11-15 07:46:12 +0000372 self.assertEqual(p[MPLS].cos, from_ip)
Neale Ranns039cbfe2018-02-27 03:45:38 -0800373 self.assertEqual(p[MPLS].label, 63)
374 self.assertEqual(p[MPLS].s, 0)
375 h = p[MPLS].payload
Neale Ranns18668842018-11-15 07:46:12 +0000376 self.assertEqual(h[MPLS].cos, from_ip)
Neale Ranns039cbfe2018-02-27 03:45:38 -0800377 self.assertEqual(h[MPLS].label, 33)
378 self.assertEqual(h[MPLS].s, 0)
379 h = h[MPLS].payload
Neale Ranns18668842018-11-15 07:46:12 +0000380 self.assertEqual(h[MPLS].cos, from_ip)
Neale Ranns039cbfe2018-02-27 03:45:38 -0800381 self.assertEqual(h[MPLS].label, 34)
382 self.assertEqual(h[MPLS].s, 1)
383
384 #
Neale Ranns0809f6c2018-07-16 04:14:21 -0700385 # enable MPLS QoS recording on the input Pg0 and IP egress marking
386 # on Pg1
387 #
Paul Vinciguerrab7658202019-05-17 09:48:15 -0400388 self.vapi.qos_record_enable_disable(
389 self.pg0.sw_if_index,
390 self.QOS_SOURCE.QOS_API_SOURCE_MPLS,
391 1)
Neale Ranns0809f6c2018-07-16 04:14:21 -0700392 self.vapi.qos_mark_enable_disable(self.pg1.sw_if_index,
Paul Vinciguerrab7658202019-05-17 09:48:15 -0400393 self.QOS_SOURCE.QOS_API_SOURCE_IP,
Neale Ranns0809f6c2018-07-16 04:14:21 -0700394 1,
395 1)
396
397 #
Neale Ranns18668842018-11-15 07:46:12 +0000398 # MPLS x-connect - COS according to pg1 map
Neale Ranns0809f6c2018-07-16 04:14:21 -0700399 #
400 route_32_eos = VppMplsRoute(self, 32, 1,
401 [VppRoutePath(self.pg1.remote_ip4,
402 self.pg1.sw_if_index,
403 labels=[VppMplsLabel(33)])])
404 route_32_eos.add_vpp_config()
405
406 p_m1 = (Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac) /
407 MPLS(label=32, cos=3, ttl=2) /
408 IP(src=self.pg0.remote_ip4, dst="10.0.0.1", tos=1) /
409 UDP(sport=1234, dport=1234) /
Paul Vinciguerra4271c972019-05-14 13:25:49 -0400410 Raw(scapy.compat.chb(100) * NUM_PKTS))
Neale Ranns0809f6c2018-07-16 04:14:21 -0700411
Paul Vinciguerra4271c972019-05-14 13:25:49 -0400412 rx = self.send_and_expect(self.pg0, p_m1 * NUM_PKTS, self.pg1)
Neale Ranns0809f6c2018-07-16 04:14:21 -0700413 for p in rx:
Neale Ranns18668842018-11-15 07:46:12 +0000414 self.assertEqual(p[MPLS].cos, from_mpls)
Neale Ranns0809f6c2018-07-16 04:14:21 -0700415 self.assertEqual(p[MPLS].label, 33)
416 self.assertEqual(p[MPLS].s, 1)
417
418 #
419 # MPLS deag - COS is copied from MPLS to IP
420 #
421 route_33_eos = VppMplsRoute(self, 33, 1,
422 [VppRoutePath("0.0.0.0",
423 0xffffffff,
424 nh_table_id=0)])
425 route_33_eos.add_vpp_config()
426
427 route_10_0_0_4 = VppIpRoute(self, "10.0.0.4", 32,
428 [VppRoutePath(self.pg1.remote_ip4,
429 self.pg1.sw_if_index)])
430 route_10_0_0_4.add_vpp_config()
431
432 p_m2 = (Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac) /
433 MPLS(label=33, ttl=2, cos=3) /
434 IP(src=self.pg0.remote_ip4, dst="10.0.0.4", tos=1) /
435 UDP(sport=1234, dport=1234) /
Paul Vinciguerra4271c972019-05-14 13:25:49 -0400436 Raw(scapy.compat.chb(100) * NUM_PKTS))
Neale Ranns0809f6c2018-07-16 04:14:21 -0700437
Paul Vinciguerra4271c972019-05-14 13:25:49 -0400438 rx = self.send_and_expect(self.pg0, p_m2 * NUM_PKTS, self.pg1)
Neale Ranns0809f6c2018-07-16 04:14:21 -0700439
440 for p in rx:
Neale Ranns18668842018-11-15 07:46:12 +0000441 self.assertEqual(p[IP].tos, from_mpls)
Neale Ranns0809f6c2018-07-16 04:14:21 -0700442
443 #
Neale Ranns039cbfe2018-02-27 03:45:38 -0800444 # cleanup
445 #
446 self.vapi.qos_record_enable_disable(self.pg0.sw_if_index,
Paul Vinciguerrab7658202019-05-17 09:48:15 -0400447 self.QOS_SOURCE.QOS_API_SOURCE_IP,
Neale Ranns039cbfe2018-02-27 03:45:38 -0800448 0)
449 self.vapi.qos_mark_enable_disable(self.pg1.sw_if_index,
Paul Vinciguerrab7658202019-05-17 09:48:15 -0400450 self.QOS_SOURCE.QOS_API_SOURCE_MPLS,
Neale Ranns039cbfe2018-02-27 03:45:38 -0800451 1,
452 0)
Paul Vinciguerrab7658202019-05-17 09:48:15 -0400453 self.vapi.qos_record_enable_disable(
454 self.pg0.sw_if_index,
455 self.QOS_SOURCE.QOS_API_SOURCE_MPLS,
456 0)
Neale Ranns0809f6c2018-07-16 04:14:21 -0700457 self.vapi.qos_mark_enable_disable(self.pg1.sw_if_index,
Paul Vinciguerrab7658202019-05-17 09:48:15 -0400458 self.QOS_SOURCE.QOS_API_SOURCE_IP,
Neale Ranns0809f6c2018-07-16 04:14:21 -0700459 1,
460 0)
Neale Ranns039cbfe2018-02-27 03:45:38 -0800461 self.vapi.qos_egress_map_delete(1)
462
Neale Ranns0809f6c2018-07-16 04:14:21 -0700463 def test_qos_vlan(self):
464 """QoS mark/record VLAN """
465
466 #
467 # QoS for all input values
468 #
Paul Vinciguerraa7427ec2019-03-10 10:04:23 -0700469 output = [scapy.compat.chb(0)] * 256
Neale Ranns0809f6c2018-07-16 04:14:21 -0700470 for i in range(0, 255):
Paul Vinciguerraa7427ec2019-03-10 10:04:23 -0700471 output[i] = scapy.compat.chb(255 - i)
472 os = b''.join(output)
Neale Ranns0809f6c2018-07-16 04:14:21 -0700473 rows = [{'outputs': os},
474 {'outputs': os},
475 {'outputs': os},
476 {'outputs': os}]
477
478 self.vapi.qos_egress_map_update(1, rows)
479
480 sub_if = VppDot1QSubint(self, self.pg0, 11)
481
482 sub_if.admin_up()
483 sub_if.config_ip4()
484 sub_if.resolve_arp()
485 sub_if.config_ip6()
486 sub_if.resolve_ndp()
487
488 #
489 # enable VLAN QoS recording/marking on the input Pg0 subinterface and
490 #
Paul Vinciguerrab7658202019-05-17 09:48:15 -0400491 self.vapi.qos_record_enable_disable(
492 sub_if.sw_if_index,
493 self.QOS_SOURCE.QOS_API_SOURCE_VLAN,
494 1)
Neale Ranns0809f6c2018-07-16 04:14:21 -0700495 self.vapi.qos_mark_enable_disable(sub_if.sw_if_index,
Paul Vinciguerrab7658202019-05-17 09:48:15 -0400496 self.QOS_SOURCE.QOS_API_SOURCE_VLAN,
Neale Ranns0809f6c2018-07-16 04:14:21 -0700497 1,
498 1)
499
500 #
501 # IP marking/recording on pg1
502 #
503 self.vapi.qos_record_enable_disable(self.pg1.sw_if_index,
Paul Vinciguerrab7658202019-05-17 09:48:15 -0400504 self.QOS_SOURCE.QOS_API_SOURCE_IP,
Neale Ranns0809f6c2018-07-16 04:14:21 -0700505 1)
506 self.vapi.qos_mark_enable_disable(self.pg1.sw_if_index,
Paul Vinciguerrab7658202019-05-17 09:48:15 -0400507 self.QOS_SOURCE.QOS_API_SOURCE_IP,
Neale Ranns0809f6c2018-07-16 04:14:21 -0700508 1,
509 1)
510
511 #
512 # a routes to/from sub-interface
513 #
514 route_10_0_0_1 = VppIpRoute(self, "10.0.0.1", 32,
515 [VppRoutePath(sub_if.remote_ip4,
516 sub_if.sw_if_index)])
517 route_10_0_0_1.add_vpp_config()
518 route_10_0_0_2 = VppIpRoute(self, "10.0.0.2", 32,
519 [VppRoutePath(self.pg1.remote_ip4,
520 self.pg1.sw_if_index)])
521 route_10_0_0_2.add_vpp_config()
522 route_2001_1 = VppIpRoute(self, "2001::1", 128,
523 [VppRoutePath(sub_if.remote_ip6,
Neale Ranns097fa662018-05-01 05:17:55 -0700524 sub_if.sw_if_index)])
Neale Ranns0809f6c2018-07-16 04:14:21 -0700525 route_2001_1.add_vpp_config()
526 route_2001_2 = VppIpRoute(self, "2001::2", 128,
527 [VppRoutePath(self.pg1.remote_ip6,
Neale Ranns097fa662018-05-01 05:17:55 -0700528 self.pg1.sw_if_index)])
Neale Ranns0809f6c2018-07-16 04:14:21 -0700529 route_2001_2.add_vpp_config()
530
531 p_v1 = (Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac) /
532 Dot1Q(vlan=11, prio=1) /
533 IP(src="1.1.1.1", dst="10.0.0.2", tos=1) /
534 UDP(sport=1234, dport=1234) /
Paul Vinciguerra4271c972019-05-14 13:25:49 -0400535 Raw(scapy.compat.chb(100) * NUM_PKTS))
Neale Ranns0809f6c2018-07-16 04:14:21 -0700536
537 p_v2 = (Ether(src=self.pg1.remote_mac, dst=self.pg1.local_mac) /
538 IP(src="1.1.1.1", dst="10.0.0.1", tos=1) /
539 UDP(sport=1234, dport=1234) /
Paul Vinciguerra4271c972019-05-14 13:25:49 -0400540 Raw(scapy.compat.chb(100) * NUM_PKTS))
Neale Ranns0809f6c2018-07-16 04:14:21 -0700541
Paul Vinciguerra4271c972019-05-14 13:25:49 -0400542 rx = self.send_and_expect(self.pg1, p_v2 * NUM_PKTS, self.pg0)
Neale Ranns0809f6c2018-07-16 04:14:21 -0700543
544 for p in rx:
545 self.assertEqual(p[Dot1Q].prio, 6)
546
Paul Vinciguerra4271c972019-05-14 13:25:49 -0400547 rx = self.send_and_expect(self.pg0, p_v1 * NUM_PKTS, self.pg1)
Neale Ranns0809f6c2018-07-16 04:14:21 -0700548
549 for p in rx:
550 self.assertEqual(p[IP].tos, 254)
551
552 p_v1 = (Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac) /
553 Dot1Q(vlan=11, prio=2) /
554 IPv6(src="2001::1", dst="2001::2", tc=1) /
555 UDP(sport=1234, dport=1234) /
Paul Vinciguerra4271c972019-05-14 13:25:49 -0400556 Raw(scapy.compat.chb(100) * NUM_PKTS))
Neale Ranns0809f6c2018-07-16 04:14:21 -0700557
558 p_v2 = (Ether(src=self.pg1.remote_mac, dst=self.pg1.local_mac) /
559 IPv6(src="3001::1", dst="2001::1", tc=1) /
560 UDP(sport=1234, dport=1234) /
Paul Vinciguerra4271c972019-05-14 13:25:49 -0400561 Raw(scapy.compat.chb(100) * NUM_PKTS))
Neale Ranns0809f6c2018-07-16 04:14:21 -0700562
Paul Vinciguerra4271c972019-05-14 13:25:49 -0400563 rx = self.send_and_expect(self.pg1, p_v2 * NUM_PKTS, self.pg0)
Neale Ranns0809f6c2018-07-16 04:14:21 -0700564
565 for p in rx:
566 self.assertEqual(p[Dot1Q].prio, 6)
567
Paul Vinciguerra4271c972019-05-14 13:25:49 -0400568 rx = self.send_and_expect(self.pg0, p_v1 * NUM_PKTS, self.pg1)
Neale Ranns0809f6c2018-07-16 04:14:21 -0700569
570 for p in rx:
571 self.assertEqual(p[IPv6].tc, 253)
572
573 #
574 # cleanup
575 #
576 sub_if.unconfig_ip4()
577 sub_if.unconfig_ip6()
578
Paul Vinciguerrab7658202019-05-17 09:48:15 -0400579 self.vapi.qos_record_enable_disable(
580 sub_if.sw_if_index,
581 self.QOS_SOURCE.QOS_API_SOURCE_VLAN,
582 0)
Neale Ranns0809f6c2018-07-16 04:14:21 -0700583 self.vapi.qos_mark_enable_disable(sub_if.sw_if_index,
Paul Vinciguerrab7658202019-05-17 09:48:15 -0400584 self.QOS_SOURCE.QOS_API_SOURCE_VLAN,
Neale Ranns0809f6c2018-07-16 04:14:21 -0700585 1,
586 0)
587 self.vapi.qos_record_enable_disable(self.pg1.sw_if_index,
Paul Vinciguerrab7658202019-05-17 09:48:15 -0400588 self.QOS_SOURCE.QOS_API_SOURCE_IP,
Neale Ranns0809f6c2018-07-16 04:14:21 -0700589 0)
590 self.vapi.qos_mark_enable_disable(self.pg1.sw_if_index,
Paul Vinciguerrab7658202019-05-17 09:48:15 -0400591 self.QOS_SOURCE.QOS_API_SOURCE_IP,
Neale Ranns0809f6c2018-07-16 04:14:21 -0700592 1,
593 0)
594
Neale Ranns039cbfe2018-02-27 03:45:38 -0800595
596if __name__ == '__main__':
597 unittest.main(testRunner=VppTestRunner)