blob: e670230487a3b1e7dbb351cb2b61329aac61b32f [file] [log] [blame]
Neale Ranns177bbdc2016-11-15 09:46:51 +00001"""
2 IP Routes
3
4 object abstractions for representing IP routes in VPP
5"""
6
Neale Ranns5a8123b2017-01-26 01:18:23 -08007from vpp_object import *
Neale Rannsb3b2de72017-03-08 05:17:22 -08008from socket import inet_pton, inet_ntop, AF_INET, AF_INET6
Neale Ranns177bbdc2016-11-15 09:46:51 +00009
Neale Rannsad422ed2016-11-02 14:20:04 +000010# from vnet/vnet/mpls/mpls_types.h
11MPLS_IETF_MAX_LABEL = 0xfffff
12MPLS_LABEL_INVALID = MPLS_IETF_MAX_LABEL + 1
Neale Ranns177bbdc2016-11-15 09:46:51 +000013
Neale Ranns177bbdc2016-11-15 09:46:51 +000014
Neale Ranns180279b2017-03-16 15:49:09 -040015class MRouteItfFlags:
16 MFIB_ITF_FLAG_NONE = 0
17 MFIB_ITF_FLAG_NEGATE_SIGNAL = 1
18 MFIB_ITF_FLAG_ACCEPT = 2
19 MFIB_ITF_FLAG_FORWARD = 4
20 MFIB_ITF_FLAG_SIGNAL_PRESENT = 8
21 MFIB_ITF_FLAG_INTERNAL_COPY = 16
22
23
24class MRouteEntryFlags:
25 MFIB_ENTRY_FLAG_NONE = 0
26 MFIB_ENTRY_FLAG_SIGNAL = 1
27 MFIB_ENTRY_FLAG_DROP = 2
28 MFIB_ENTRY_FLAG_CONNECTED = 4
29 MFIB_ENTRY_FLAG_INHERIT_ACCEPT = 8
30
31
Neale Rannsda78f952017-05-24 09:15:43 -070032class DpoProto:
33 DPO_PROTO_IP4 = 0
34 DPO_PROTO_IP6 = 1
35 DPO_PROTO_MPLS = 2
36 DPO_PROTO_ETHERNET = 3
37 DPO_PROTO_NSH = 4
38
39
Neale Rannsb3b2de72017-03-08 05:17:22 -080040def find_route(test, ip_addr, len, table_id=0, inet=AF_INET):
41 if inet == AF_INET:
42 s = 4
43 routes = test.vapi.ip_fib_dump()
44 else:
45 s = 16
46 routes = test.vapi.ip6_fib_dump()
47
48 route_addr = inet_pton(inet, ip_addr)
49 for e in routes:
50 if route_addr == e.address[:s] \
51 and len == e.address_length \
52 and table_id == e.table_id:
53 return True
54 return False
55
56
Neale Ranns15002542017-09-10 04:39:11 -070057class VppIpTable(VppObject):
58
59 def __init__(self,
60 test,
61 table_id,
62 is_ip6=0):
63 self._test = test
64 self.table_id = table_id
65 self.is_ip6 = is_ip6
66
67 def add_vpp_config(self):
68 self._test.vapi.ip_table_add_del(
69 self.table_id,
70 is_ipv6=self.is_ip6,
71 is_add=1)
72 self._test.registry.register(self, self._test.logger)
73
74 def remove_vpp_config(self):
75 self._test.vapi.ip_table_add_del(
76 self.table_id,
77 is_ipv6=self.is_ip6,
78 is_add=0)
79
80 def query_vpp_config(self):
81 # find the default route
82 return find_route(self._test,
83 "::" if self.is_ip6 else "0.0.0.0",
84 0,
85 self.table_id,
86 inet=AF_INET6 if self.is_ip6 == 1 else AF_INET)
87
88 def __str__(self):
89 return self.object_id()
90
91 def object_id(self):
92 return ("table-%s-%d" %
93 ("v6" if self.is_ip6 == 1 else "v4",
94 self.table_id))
95
96
Neale Ranns5a8123b2017-01-26 01:18:23 -080097class VppRoutePath(object):
Neale Rannsad422ed2016-11-02 14:20:04 +000098
Klement Sekerada505f62017-01-04 12:58:53 +010099 def __init__(
100 self,
101 nh_addr,
102 nh_sw_if_index,
103 nh_table_id=0,
104 labels=[],
Neale Rannsfca0c242017-01-13 07:57:46 -0800105 nh_via_label=MPLS_LABEL_INVALID,
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800106 rpf_id=0,
Neale Rannsf12a83f2017-04-18 09:09:40 -0700107 is_interface_rx=0,
108 is_resolve_host=0,
Neale Rannsda78f952017-05-24 09:15:43 -0700109 is_resolve_attached=0,
110 proto=DpoProto.DPO_PROTO_IP4):
Neale Ranns177bbdc2016-11-15 09:46:51 +0000111 self.nh_itf = nh_sw_if_index
112 self.nh_table_id = nh_table_id
Neale Rannsad422ed2016-11-02 14:20:04 +0000113 self.nh_via_label = nh_via_label
114 self.nh_labels = labels
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800115 self.weight = 1
116 self.rpf_id = rpf_id
Neale Rannsda78f952017-05-24 09:15:43 -0700117 self.proto = proto
118 if self.proto is DpoProto.DPO_PROTO_IP6:
119 self.nh_addr = inet_pton(AF_INET6, nh_addr)
120 elif self.proto is DpoProto.DPO_PROTO_IP4:
Neale Rannsb3b2de72017-03-08 05:17:22 -0800121 self.nh_addr = inet_pton(AF_INET, nh_addr)
Neale Ranns31426c62017-05-24 10:32:58 -0700122 else:
Neale Rannsda78f952017-05-24 09:15:43 -0700123 self.nh_addr = inet_pton(AF_INET6, "::")
Neale Rannsf12a83f2017-04-18 09:09:40 -0700124 self.is_resolve_host = is_resolve_host
125 self.is_resolve_attached = is_resolve_attached
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800126 self.is_interface_rx = is_interface_rx
127 self.is_rpf_id = 0
128 if rpf_id != 0:
129 self.is_rpf_id = 1
130 self.nh_itf = rpf_id
Neale Ranns177bbdc2016-11-15 09:46:51 +0000131
132
Neale Ranns5a8123b2017-01-26 01:18:23 -0800133class VppMRoutePath(VppRoutePath):
Neale Ranns32e1c012016-11-22 17:07:28 +0000134
135 def __init__(self, nh_sw_if_index, flags):
Neale Ranns5a8123b2017-01-26 01:18:23 -0800136 super(VppMRoutePath, self).__init__("0.0.0.0",
137 nh_sw_if_index)
Neale Ranns32e1c012016-11-22 17:07:28 +0000138 self.nh_i_flags = flags
139
140
Neale Ranns5a8123b2017-01-26 01:18:23 -0800141class VppIpRoute(VppObject):
Neale Ranns177bbdc2016-11-15 09:46:51 +0000142 """
143 IP Route
144 """
145
146 def __init__(self, test, dest_addr,
Neale Ranns37be7362017-02-21 17:30:26 -0800147 dest_addr_len, paths, table_id=0, is_ip6=0, is_local=0,
148 is_unreach=0, is_prohibit=0):
Neale Ranns177bbdc2016-11-15 09:46:51 +0000149 self._test = test
150 self.paths = paths
Neale Ranns177bbdc2016-11-15 09:46:51 +0000151 self.dest_addr_len = dest_addr_len
152 self.table_id = table_id
Neale Rannsfca0c242017-01-13 07:57:46 -0800153 self.is_ip6 = is_ip6
154 self.is_local = is_local
Neale Ranns37be7362017-02-21 17:30:26 -0800155 self.is_unreach = is_unreach
156 self.is_prohibit = is_prohibit
Neale Rannsb3b2de72017-03-08 05:17:22 -0800157 self.dest_addr_p = dest_addr
Neale Rannsfca0c242017-01-13 07:57:46 -0800158 if is_ip6:
Neale Rannsb3b2de72017-03-08 05:17:22 -0800159 self.dest_addr = inet_pton(AF_INET6, dest_addr)
Neale Rannsfca0c242017-01-13 07:57:46 -0800160 else:
Neale Rannsb3b2de72017-03-08 05:17:22 -0800161 self.dest_addr = inet_pton(AF_INET, dest_addr)
Neale Ranns177bbdc2016-11-15 09:46:51 +0000162
Neale Ranns69b7aa42017-03-10 03:04:12 -0800163 def modify(self, paths, is_local=0,
164 is_unreach=0, is_prohibit=0):
165 self.paths = paths
166 self.is_local = is_local
167 self.is_unreach = is_unreach
168 self.is_prohibit = is_prohibit
169
Neale Ranns177bbdc2016-11-15 09:46:51 +0000170 def add_vpp_config(self):
Neale Ranns37be7362017-02-21 17:30:26 -0800171 if self.is_local or self.is_unreach or self.is_prohibit:
Klement Sekerada505f62017-01-04 12:58:53 +0100172 self._test.vapi.ip_add_del_route(
173 self.dest_addr,
174 self.dest_addr_len,
Neale Rannsb3b2de72017-03-08 05:17:22 -0800175 inet_pton(AF_INET6, "::"),
Neale Rannsfca0c242017-01-13 07:57:46 -0800176 0xffffffff,
Neale Ranns37be7362017-02-21 17:30:26 -0800177 is_local=self.is_local,
178 is_unreach=self.is_unreach,
179 is_prohibit=self.is_prohibit,
Klement Sekerada505f62017-01-04 12:58:53 +0100180 table_id=self.table_id,
Neale Rannsfca0c242017-01-13 07:57:46 -0800181 is_ipv6=self.is_ip6)
182 else:
183 for path in self.paths:
184 self._test.vapi.ip_add_del_route(
185 self.dest_addr,
186 self.dest_addr_len,
187 path.nh_addr,
188 path.nh_itf,
189 table_id=self.table_id,
190 next_hop_out_label_stack=path.nh_labels,
191 next_hop_n_out_labels=len(
192 path.nh_labels),
193 next_hop_via_label=path.nh_via_label,
Neale Rannsf12a83f2017-04-18 09:09:40 -0700194 next_hop_table_id=path.nh_table_id,
195 is_ipv6=self.is_ip6,
Neale Ranns6f631152017-10-03 08:20:21 -0700196 is_l2_bridged=1
197 if path.proto == DpoProto.DPO_PROTO_ETHERNET else 0,
Neale Rannsf12a83f2017-04-18 09:09:40 -0700198 is_resolve_host=path.is_resolve_host,
199 is_resolve_attached=path.is_resolve_attached,
200 is_multipath=1 if len(self.paths) > 1 else 0)
Neale Ranns5a8123b2017-01-26 01:18:23 -0800201 self._test.registry.register(self, self._test.logger)
Neale Ranns177bbdc2016-11-15 09:46:51 +0000202
203 def remove_vpp_config(self):
Neale Ranns37be7362017-02-21 17:30:26 -0800204 if self.is_local or self.is_unreach or self.is_prohibit:
Neale Rannsfca0c242017-01-13 07:57:46 -0800205 self._test.vapi.ip_add_del_route(
206 self.dest_addr,
207 self.dest_addr_len,
Neale Rannsb3b2de72017-03-08 05:17:22 -0800208 inet_pton(AF_INET6, "::"),
Neale Rannsfca0c242017-01-13 07:57:46 -0800209 0xffffffff,
Neale Ranns37be7362017-02-21 17:30:26 -0800210 is_local=self.is_local,
211 is_unreach=self.is_unreach,
212 is_prohibit=self.is_prohibit,
Neale Rannsfca0c242017-01-13 07:57:46 -0800213 is_add=0,
214 table_id=self.table_id,
215 is_ipv6=self.is_ip6)
216 else:
217 for path in self.paths:
Neale Rannsf12a83f2017-04-18 09:09:40 -0700218 self._test.vapi.ip_add_del_route(
219 self.dest_addr,
220 self.dest_addr_len,
221 path.nh_addr,
222 path.nh_itf,
223 table_id=self.table_id,
224 next_hop_table_id=path.nh_table_id,
225 next_hop_via_label=path.nh_via_label,
226 is_add=0,
227 is_ipv6=self.is_ip6)
Neale Rannsad422ed2016-11-02 14:20:04 +0000228
Neale Ranns5a8123b2017-01-26 01:18:23 -0800229 def query_vpp_config(self):
Neale Rannsb3b2de72017-03-08 05:17:22 -0800230 return find_route(self._test,
231 self.dest_addr_p,
232 self.dest_addr_len,
233 self.table_id,
234 inet=AF_INET6 if self.is_ip6 == 1 else AF_INET)
Neale Rannsad422ed2016-11-02 14:20:04 +0000235
Neale Ranns5a8123b2017-01-26 01:18:23 -0800236 def __str__(self):
237 return self.object_id()
238
239 def object_id(self):
Neale Rannsb3b2de72017-03-08 05:17:22 -0800240 return ("%d:%s/%d"
241 % (self.table_id,
242 self.dest_addr_p,
243 self.dest_addr_len))
Neale Ranns5a8123b2017-01-26 01:18:23 -0800244
245
246class VppIpMRoute(VppObject):
Neale Ranns32e1c012016-11-22 17:07:28 +0000247 """
248 IP Multicast Route
249 """
250
251 def __init__(self, test, src_addr, grp_addr,
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800252 grp_addr_len, e_flags, paths, table_id=0,
253 rpf_id=0, is_ip6=0):
Neale Ranns32e1c012016-11-22 17:07:28 +0000254 self._test = test
255 self.paths = paths
256 self.grp_addr_len = grp_addr_len
257 self.table_id = table_id
258 self.e_flags = e_flags
259 self.is_ip6 = is_ip6
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800260 self.rpf_id = rpf_id
Neale Ranns32e1c012016-11-22 17:07:28 +0000261
262 if is_ip6:
Neale Rannsb3b2de72017-03-08 05:17:22 -0800263 self.grp_addr = inet_pton(AF_INET6, grp_addr)
264 self.src_addr = inet_pton(AF_INET6, src_addr)
Neale Ranns32e1c012016-11-22 17:07:28 +0000265 else:
Neale Rannsb3b2de72017-03-08 05:17:22 -0800266 self.grp_addr = inet_pton(AF_INET, grp_addr)
267 self.src_addr = inet_pton(AF_INET, src_addr)
Neale Ranns32e1c012016-11-22 17:07:28 +0000268
269 def add_vpp_config(self):
270 for path in self.paths:
271 self._test.vapi.ip_mroute_add_del(self.src_addr,
272 self.grp_addr,
273 self.grp_addr_len,
274 self.e_flags,
275 path.nh_itf,
276 path.nh_i_flags,
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800277 rpf_id=self.rpf_id,
Neale Ranns32e1c012016-11-22 17:07:28 +0000278 table_id=self.table_id,
279 is_ipv6=self.is_ip6)
Neale Ranns5a8123b2017-01-26 01:18:23 -0800280 self._test.registry.register(self, self._test.logger)
Neale Ranns32e1c012016-11-22 17:07:28 +0000281
282 def remove_vpp_config(self):
283 for path in self.paths:
284 self._test.vapi.ip_mroute_add_del(self.src_addr,
285 self.grp_addr,
286 self.grp_addr_len,
287 self.e_flags,
288 path.nh_itf,
289 path.nh_i_flags,
290 table_id=self.table_id,
291 is_add=0,
292 is_ipv6=self.is_ip6)
293
294 def update_entry_flags(self, flags):
295 self.e_flags = flags
296 self._test.vapi.ip_mroute_add_del(self.src_addr,
297 self.grp_addr,
298 self.grp_addr_len,
299 self.e_flags,
300 0xffffffff,
301 0,
302 table_id=self.table_id,
303 is_ipv6=self.is_ip6)
304
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800305 def update_rpf_id(self, rpf_id):
306 self.rpf_id = rpf_id
307 self._test.vapi.ip_mroute_add_del(self.src_addr,
308 self.grp_addr,
309 self.grp_addr_len,
310 self.e_flags,
311 0xffffffff,
312 0,
313 rpf_id=self.rpf_id,
314 table_id=self.table_id,
315 is_ipv6=self.is_ip6)
316
Neale Ranns32e1c012016-11-22 17:07:28 +0000317 def update_path_flags(self, itf, flags):
318 for path in self.paths:
319 if path.nh_itf == itf:
320 path.nh_i_flags = flags
321 break
322 self._test.vapi.ip_mroute_add_del(self.src_addr,
323 self.grp_addr,
324 self.grp_addr_len,
325 self.e_flags,
326 path.nh_itf,
327 path.nh_i_flags,
328 table_id=self.table_id,
329 is_ipv6=self.is_ip6)
330
Neale Ranns5a8123b2017-01-26 01:18:23 -0800331 def query_vpp_config(self):
332 dump = self._test.vapi.ip_fib_dump()
333 for e in dump:
334 if self.grp_addr == e.address \
335 and self.grp_addr_len == e.address_length \
336 and self.table_id == e.table_id:
337 return True
338 return False
Neale Ranns32e1c012016-11-22 17:07:28 +0000339
Neale Ranns5a8123b2017-01-26 01:18:23 -0800340 def __str__(self):
341 return self.object_id()
342
343 def object_id(self):
344 if self.is_ip6:
345 return ("%d:(%s,%s/%d)"
346 % (self.table_id,
Neale Rannsb3b2de72017-03-08 05:17:22 -0800347 inet_ntop(AF_INET6, self.src_addr),
348 inet_ntop(AF_INET6, self.grp_addr),
Neale Ranns5a8123b2017-01-26 01:18:23 -0800349 self.grp_addr_len))
350 else:
351 return ("%d:(%s,%s/%d)"
352 % (self.table_id,
Neale Rannsb3b2de72017-03-08 05:17:22 -0800353 inet_ntop(AF_INET, self.src_addr),
354 inet_ntop(AF_INET, self.grp_addr),
Neale Ranns5a8123b2017-01-26 01:18:23 -0800355 self.grp_addr_len))
356
357
358class VppMFibSignal(object):
Neale Ranns32e1c012016-11-22 17:07:28 +0000359 def __init__(self, test, route, interface, packet):
360 self.route = route
361 self.interface = interface
362 self.packet = packet
363 self.test = test
364
365 def compare(self, signal):
366 self.test.assertEqual(self.interface, signal.sw_if_index)
367 self.test.assertEqual(self.route.table_id, signal.table_id)
368 self.test.assertEqual(self.route.grp_addr_len,
369 signal.grp_address_len)
370 for i in range(self.route.grp_addr_len / 8):
371 self.test.assertEqual(self.route.grp_addr[i],
372 signal.grp_address[i])
373 if (self.route.grp_addr_len > 32):
374 for i in range(4):
375 self.test.assertEqual(self.route.src_addr[i],
376 signal.src_address[i])
377
378
Neale Ranns5a8123b2017-01-26 01:18:23 -0800379class VppMplsIpBind(VppObject):
Neale Rannsad422ed2016-11-02 14:20:04 +0000380 """
381 MPLS to IP Binding
382 """
383
Neale Ranns5a8123b2017-01-26 01:18:23 -0800384 def __init__(self, test, local_label, dest_addr, dest_addr_len,
Neale Rannsf12a83f2017-04-18 09:09:40 -0700385 table_id=0, ip_table_id=0, is_ip6=0):
Neale Rannsad422ed2016-11-02 14:20:04 +0000386 self._test = test
Neale Rannsad422ed2016-11-02 14:20:04 +0000387 self.dest_addr_len = dest_addr_len
Neale Rannsf12a83f2017-04-18 09:09:40 -0700388 self.dest_addr = dest_addr
Neale Rannsad422ed2016-11-02 14:20:04 +0000389 self.local_label = local_label
Neale Ranns5a8123b2017-01-26 01:18:23 -0800390 self.table_id = table_id
391 self.ip_table_id = ip_table_id
Neale Rannsf12a83f2017-04-18 09:09:40 -0700392 self.is_ip6 = is_ip6
393 if is_ip6:
394 self.dest_addrn = inet_pton(AF_INET6, dest_addr)
395 else:
396 self.dest_addrn = inet_pton(AF_INET, dest_addr)
Neale Rannsad422ed2016-11-02 14:20:04 +0000397
398 def add_vpp_config(self):
399 self._test.vapi.mpls_ip_bind_unbind(self.local_label,
Neale Rannsf12a83f2017-04-18 09:09:40 -0700400 self.dest_addrn,
Neale Ranns5a8123b2017-01-26 01:18:23 -0800401 self.dest_addr_len,
402 table_id=self.table_id,
Neale Rannsf12a83f2017-04-18 09:09:40 -0700403 ip_table_id=self.ip_table_id,
404 is_ip4=(self.is_ip6 == 0))
Neale Ranns5a8123b2017-01-26 01:18:23 -0800405 self._test.registry.register(self, self._test.logger)
Neale Rannsad422ed2016-11-02 14:20:04 +0000406
407 def remove_vpp_config(self):
408 self._test.vapi.mpls_ip_bind_unbind(self.local_label,
Neale Rannsf12a83f2017-04-18 09:09:40 -0700409 self.dest_addrn,
Neale Rannsad422ed2016-11-02 14:20:04 +0000410 self.dest_addr_len,
Neale Rannsf12a83f2017-04-18 09:09:40 -0700411 table_id=self.table_id,
412 ip_table_id=self.ip_table_id,
413 is_bind=0,
414 is_ip4=(self.is_ip6 == 0))
Neale Rannsad422ed2016-11-02 14:20:04 +0000415
Neale Ranns5a8123b2017-01-26 01:18:23 -0800416 def query_vpp_config(self):
417 dump = self._test.vapi.mpls_fib_dump()
418 for e in dump:
419 if self.local_label == e.label \
Neale Ranns5a8123b2017-01-26 01:18:23 -0800420 and self.table_id == e.table_id:
421 return True
422 return False
Neale Rannsad422ed2016-11-02 14:20:04 +0000423
Neale Ranns5a8123b2017-01-26 01:18:23 -0800424 def __str__(self):
425 return self.object_id()
426
427 def object_id(self):
428 return ("%d:%s binds %d:%s/%d"
429 % (self.table_id,
430 self.local_label,
431 self.ip_table_id,
Neale Rannsf12a83f2017-04-18 09:09:40 -0700432 self.dest_addr,
Neale Ranns5a8123b2017-01-26 01:18:23 -0800433 self.dest_addr_len))
434
435
Neale Ranns15002542017-09-10 04:39:11 -0700436class VppMplsTable(VppObject):
437
438 def __init__(self,
439 test,
440 table_id):
441 self._test = test
442 self.table_id = table_id
443
444 def add_vpp_config(self):
445 self._test.vapi.mpls_table_add_del(
446 self.table_id,
447 is_add=1)
448 self._test.registry.register(self, self._test.logger)
449
450 def remove_vpp_config(self):
451 self._test.vapi.mpls_table_add_del(
452 self.table_id,
453 is_add=0)
454
455 def query_vpp_config(self):
456 # find the default route
457 dump = self._test.vapi.mpls_fib_dump()
458 if len(dump):
459 return True
460 return False
461
462 def __str__(self):
463 return self.object_id()
464
465 def object_id(self):
466 return ("table-mpls-%d" % (self.table_id))
467
468
Neale Ranns5a8123b2017-01-26 01:18:23 -0800469class VppMplsRoute(VppObject):
Neale Rannsad422ed2016-11-02 14:20:04 +0000470 """
Neale Ranns5a8123b2017-01-26 01:18:23 -0800471 MPLS Route/LSP
Neale Rannsad422ed2016-11-02 14:20:04 +0000472 """
473
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800474 def __init__(self, test, local_label, eos_bit, paths, table_id=0,
475 is_multicast=0):
Neale Rannsad422ed2016-11-02 14:20:04 +0000476 self._test = test
477 self.paths = paths
478 self.local_label = local_label
479 self.eos_bit = eos_bit
480 self.table_id = table_id
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800481 self.is_multicast = is_multicast
Neale Rannsad422ed2016-11-02 14:20:04 +0000482
483 def add_vpp_config(self):
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800484 is_multipath = len(self.paths) > 1
Neale Rannsad422ed2016-11-02 14:20:04 +0000485 for path in self.paths:
Klement Sekerada505f62017-01-04 12:58:53 +0100486 self._test.vapi.mpls_route_add_del(
487 self.local_label,
488 self.eos_bit,
Neale Rannsda78f952017-05-24 09:15:43 -0700489 path.proto,
Klement Sekerada505f62017-01-04 12:58:53 +0100490 path.nh_addr,
491 path.nh_itf,
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800492 is_multicast=self.is_multicast,
493 is_multipath=is_multipath,
Klement Sekerada505f62017-01-04 12:58:53 +0100494 table_id=self.table_id,
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800495 is_interface_rx=path.is_interface_rx,
496 is_rpf_id=path.is_rpf_id,
Klement Sekerada505f62017-01-04 12:58:53 +0100497 next_hop_out_label_stack=path.nh_labels,
498 next_hop_n_out_labels=len(
499 path.nh_labels),
500 next_hop_via_label=path.nh_via_label,
501 next_hop_table_id=path.nh_table_id)
Neale Ranns5a8123b2017-01-26 01:18:23 -0800502 self._test.registry.register(self, self._test.logger)
Neale Rannsad422ed2016-11-02 14:20:04 +0000503
504 def remove_vpp_config(self):
505 for path in self.paths:
506 self._test.vapi.mpls_route_add_del(self.local_label,
507 self.eos_bit,
Neale Rannsda78f952017-05-24 09:15:43 -0700508 path.proto,
Neale Rannsad422ed2016-11-02 14:20:04 +0000509 path.nh_addr,
510 path.nh_itf,
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800511 is_rpf_id=path.is_rpf_id,
Neale Rannsad422ed2016-11-02 14:20:04 +0000512 table_id=self.table_id,
513 is_add=0)
Neale Ranns5a8123b2017-01-26 01:18:23 -0800514
515 def query_vpp_config(self):
516 dump = self._test.vapi.mpls_fib_dump()
517 for e in dump:
518 if self.local_label == e.label \
519 and self.eos_bit == e.eos_bit \
520 and self.table_id == e.table_id:
521 return True
522 return False
523
524 def __str__(self):
525 return self.object_id()
526
527 def object_id(self):
528 return ("%d:%s/%d"
529 % (self.table_id,
530 self.local_label,
531 20+self.eos_bit))