blob: b79937939c072f792551a61de7339e44e131972b [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,
196 is_resolve_host=path.is_resolve_host,
197 is_resolve_attached=path.is_resolve_attached,
198 is_multipath=1 if len(self.paths) > 1 else 0)
Neale Ranns5a8123b2017-01-26 01:18:23 -0800199 self._test.registry.register(self, self._test.logger)
Neale Ranns177bbdc2016-11-15 09:46:51 +0000200
201 def remove_vpp_config(self):
Neale Ranns37be7362017-02-21 17:30:26 -0800202 if self.is_local or self.is_unreach or self.is_prohibit:
Neale Rannsfca0c242017-01-13 07:57:46 -0800203 self._test.vapi.ip_add_del_route(
204 self.dest_addr,
205 self.dest_addr_len,
Neale Rannsb3b2de72017-03-08 05:17:22 -0800206 inet_pton(AF_INET6, "::"),
Neale Rannsfca0c242017-01-13 07:57:46 -0800207 0xffffffff,
Neale Ranns37be7362017-02-21 17:30:26 -0800208 is_local=self.is_local,
209 is_unreach=self.is_unreach,
210 is_prohibit=self.is_prohibit,
Neale Rannsfca0c242017-01-13 07:57:46 -0800211 is_add=0,
212 table_id=self.table_id,
213 is_ipv6=self.is_ip6)
214 else:
215 for path in self.paths:
Neale Rannsf12a83f2017-04-18 09:09:40 -0700216 self._test.vapi.ip_add_del_route(
217 self.dest_addr,
218 self.dest_addr_len,
219 path.nh_addr,
220 path.nh_itf,
221 table_id=self.table_id,
222 next_hop_table_id=path.nh_table_id,
223 next_hop_via_label=path.nh_via_label,
224 is_add=0,
225 is_ipv6=self.is_ip6)
Neale Rannsad422ed2016-11-02 14:20:04 +0000226
Neale Ranns5a8123b2017-01-26 01:18:23 -0800227 def query_vpp_config(self):
Neale Rannsb3b2de72017-03-08 05:17:22 -0800228 return find_route(self._test,
229 self.dest_addr_p,
230 self.dest_addr_len,
231 self.table_id,
232 inet=AF_INET6 if self.is_ip6 == 1 else AF_INET)
Neale Rannsad422ed2016-11-02 14:20:04 +0000233
Neale Ranns5a8123b2017-01-26 01:18:23 -0800234 def __str__(self):
235 return self.object_id()
236
237 def object_id(self):
Neale Rannsb3b2de72017-03-08 05:17:22 -0800238 return ("%d:%s/%d"
239 % (self.table_id,
240 self.dest_addr_p,
241 self.dest_addr_len))
Neale Ranns5a8123b2017-01-26 01:18:23 -0800242
243
244class VppIpMRoute(VppObject):
Neale Ranns32e1c012016-11-22 17:07:28 +0000245 """
246 IP Multicast Route
247 """
248
249 def __init__(self, test, src_addr, grp_addr,
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800250 grp_addr_len, e_flags, paths, table_id=0,
251 rpf_id=0, is_ip6=0):
Neale Ranns32e1c012016-11-22 17:07:28 +0000252 self._test = test
253 self.paths = paths
254 self.grp_addr_len = grp_addr_len
255 self.table_id = table_id
256 self.e_flags = e_flags
257 self.is_ip6 = is_ip6
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800258 self.rpf_id = rpf_id
Neale Ranns32e1c012016-11-22 17:07:28 +0000259
260 if is_ip6:
Neale Rannsb3b2de72017-03-08 05:17:22 -0800261 self.grp_addr = inet_pton(AF_INET6, grp_addr)
262 self.src_addr = inet_pton(AF_INET6, src_addr)
Neale Ranns32e1c012016-11-22 17:07:28 +0000263 else:
Neale Rannsb3b2de72017-03-08 05:17:22 -0800264 self.grp_addr = inet_pton(AF_INET, grp_addr)
265 self.src_addr = inet_pton(AF_INET, src_addr)
Neale Ranns32e1c012016-11-22 17:07:28 +0000266
267 def add_vpp_config(self):
268 for path in self.paths:
269 self._test.vapi.ip_mroute_add_del(self.src_addr,
270 self.grp_addr,
271 self.grp_addr_len,
272 self.e_flags,
273 path.nh_itf,
274 path.nh_i_flags,
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800275 rpf_id=self.rpf_id,
Neale Ranns32e1c012016-11-22 17:07:28 +0000276 table_id=self.table_id,
277 is_ipv6=self.is_ip6)
Neale Ranns5a8123b2017-01-26 01:18:23 -0800278 self._test.registry.register(self, self._test.logger)
Neale Ranns32e1c012016-11-22 17:07:28 +0000279
280 def remove_vpp_config(self):
281 for path in self.paths:
282 self._test.vapi.ip_mroute_add_del(self.src_addr,
283 self.grp_addr,
284 self.grp_addr_len,
285 self.e_flags,
286 path.nh_itf,
287 path.nh_i_flags,
288 table_id=self.table_id,
289 is_add=0,
290 is_ipv6=self.is_ip6)
291
292 def update_entry_flags(self, flags):
293 self.e_flags = flags
294 self._test.vapi.ip_mroute_add_del(self.src_addr,
295 self.grp_addr,
296 self.grp_addr_len,
297 self.e_flags,
298 0xffffffff,
299 0,
300 table_id=self.table_id,
301 is_ipv6=self.is_ip6)
302
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800303 def update_rpf_id(self, rpf_id):
304 self.rpf_id = rpf_id
305 self._test.vapi.ip_mroute_add_del(self.src_addr,
306 self.grp_addr,
307 self.grp_addr_len,
308 self.e_flags,
309 0xffffffff,
310 0,
311 rpf_id=self.rpf_id,
312 table_id=self.table_id,
313 is_ipv6=self.is_ip6)
314
Neale Ranns32e1c012016-11-22 17:07:28 +0000315 def update_path_flags(self, itf, flags):
316 for path in self.paths:
317 if path.nh_itf == itf:
318 path.nh_i_flags = flags
319 break
320 self._test.vapi.ip_mroute_add_del(self.src_addr,
321 self.grp_addr,
322 self.grp_addr_len,
323 self.e_flags,
324 path.nh_itf,
325 path.nh_i_flags,
326 table_id=self.table_id,
327 is_ipv6=self.is_ip6)
328
Neale Ranns5a8123b2017-01-26 01:18:23 -0800329 def query_vpp_config(self):
330 dump = self._test.vapi.ip_fib_dump()
331 for e in dump:
332 if self.grp_addr == e.address \
333 and self.grp_addr_len == e.address_length \
334 and self.table_id == e.table_id:
335 return True
336 return False
Neale Ranns32e1c012016-11-22 17:07:28 +0000337
Neale Ranns5a8123b2017-01-26 01:18:23 -0800338 def __str__(self):
339 return self.object_id()
340
341 def object_id(self):
342 if self.is_ip6:
343 return ("%d:(%s,%s/%d)"
344 % (self.table_id,
Neale Rannsb3b2de72017-03-08 05:17:22 -0800345 inet_ntop(AF_INET6, self.src_addr),
346 inet_ntop(AF_INET6, self.grp_addr),
Neale Ranns5a8123b2017-01-26 01:18:23 -0800347 self.grp_addr_len))
348 else:
349 return ("%d:(%s,%s/%d)"
350 % (self.table_id,
Neale Rannsb3b2de72017-03-08 05:17:22 -0800351 inet_ntop(AF_INET, self.src_addr),
352 inet_ntop(AF_INET, self.grp_addr),
Neale Ranns5a8123b2017-01-26 01:18:23 -0800353 self.grp_addr_len))
354
355
356class VppMFibSignal(object):
Neale Ranns32e1c012016-11-22 17:07:28 +0000357 def __init__(self, test, route, interface, packet):
358 self.route = route
359 self.interface = interface
360 self.packet = packet
361 self.test = test
362
363 def compare(self, signal):
364 self.test.assertEqual(self.interface, signal.sw_if_index)
365 self.test.assertEqual(self.route.table_id, signal.table_id)
366 self.test.assertEqual(self.route.grp_addr_len,
367 signal.grp_address_len)
368 for i in range(self.route.grp_addr_len / 8):
369 self.test.assertEqual(self.route.grp_addr[i],
370 signal.grp_address[i])
371 if (self.route.grp_addr_len > 32):
372 for i in range(4):
373 self.test.assertEqual(self.route.src_addr[i],
374 signal.src_address[i])
375
376
Neale Ranns5a8123b2017-01-26 01:18:23 -0800377class VppMplsIpBind(VppObject):
Neale Rannsad422ed2016-11-02 14:20:04 +0000378 """
379 MPLS to IP Binding
380 """
381
Neale Ranns5a8123b2017-01-26 01:18:23 -0800382 def __init__(self, test, local_label, dest_addr, dest_addr_len,
Neale Rannsf12a83f2017-04-18 09:09:40 -0700383 table_id=0, ip_table_id=0, is_ip6=0):
Neale Rannsad422ed2016-11-02 14:20:04 +0000384 self._test = test
Neale Rannsad422ed2016-11-02 14:20:04 +0000385 self.dest_addr_len = dest_addr_len
Neale Rannsf12a83f2017-04-18 09:09:40 -0700386 self.dest_addr = dest_addr
Neale Rannsad422ed2016-11-02 14:20:04 +0000387 self.local_label = local_label
Neale Ranns5a8123b2017-01-26 01:18:23 -0800388 self.table_id = table_id
389 self.ip_table_id = ip_table_id
Neale Rannsf12a83f2017-04-18 09:09:40 -0700390 self.is_ip6 = is_ip6
391 if is_ip6:
392 self.dest_addrn = inet_pton(AF_INET6, dest_addr)
393 else:
394 self.dest_addrn = inet_pton(AF_INET, dest_addr)
Neale Rannsad422ed2016-11-02 14:20:04 +0000395
396 def add_vpp_config(self):
397 self._test.vapi.mpls_ip_bind_unbind(self.local_label,
Neale Rannsf12a83f2017-04-18 09:09:40 -0700398 self.dest_addrn,
Neale Ranns5a8123b2017-01-26 01:18:23 -0800399 self.dest_addr_len,
400 table_id=self.table_id,
Neale Rannsf12a83f2017-04-18 09:09:40 -0700401 ip_table_id=self.ip_table_id,
402 is_ip4=(self.is_ip6 == 0))
Neale Ranns5a8123b2017-01-26 01:18:23 -0800403 self._test.registry.register(self, self._test.logger)
Neale Rannsad422ed2016-11-02 14:20:04 +0000404
405 def remove_vpp_config(self):
406 self._test.vapi.mpls_ip_bind_unbind(self.local_label,
Neale Rannsf12a83f2017-04-18 09:09:40 -0700407 self.dest_addrn,
Neale Rannsad422ed2016-11-02 14:20:04 +0000408 self.dest_addr_len,
Neale Rannsf12a83f2017-04-18 09:09:40 -0700409 table_id=self.table_id,
410 ip_table_id=self.ip_table_id,
411 is_bind=0,
412 is_ip4=(self.is_ip6 == 0))
Neale Rannsad422ed2016-11-02 14:20:04 +0000413
Neale Ranns5a8123b2017-01-26 01:18:23 -0800414 def query_vpp_config(self):
415 dump = self._test.vapi.mpls_fib_dump()
416 for e in dump:
417 if self.local_label == e.label \
Neale Ranns5a8123b2017-01-26 01:18:23 -0800418 and self.table_id == e.table_id:
419 return True
420 return False
Neale Rannsad422ed2016-11-02 14:20:04 +0000421
Neale Ranns5a8123b2017-01-26 01:18:23 -0800422 def __str__(self):
423 return self.object_id()
424
425 def object_id(self):
426 return ("%d:%s binds %d:%s/%d"
427 % (self.table_id,
428 self.local_label,
429 self.ip_table_id,
Neale Rannsf12a83f2017-04-18 09:09:40 -0700430 self.dest_addr,
Neale Ranns5a8123b2017-01-26 01:18:23 -0800431 self.dest_addr_len))
432
433
Neale Ranns15002542017-09-10 04:39:11 -0700434class VppMplsTable(VppObject):
435
436 def __init__(self,
437 test,
438 table_id):
439 self._test = test
440 self.table_id = table_id
441
442 def add_vpp_config(self):
443 self._test.vapi.mpls_table_add_del(
444 self.table_id,
445 is_add=1)
446 self._test.registry.register(self, self._test.logger)
447
448 def remove_vpp_config(self):
449 self._test.vapi.mpls_table_add_del(
450 self.table_id,
451 is_add=0)
452
453 def query_vpp_config(self):
454 # find the default route
455 dump = self._test.vapi.mpls_fib_dump()
456 if len(dump):
457 return True
458 return False
459
460 def __str__(self):
461 return self.object_id()
462
463 def object_id(self):
464 return ("table-mpls-%d" % (self.table_id))
465
466
Neale Ranns5a8123b2017-01-26 01:18:23 -0800467class VppMplsRoute(VppObject):
Neale Rannsad422ed2016-11-02 14:20:04 +0000468 """
Neale Ranns5a8123b2017-01-26 01:18:23 -0800469 MPLS Route/LSP
Neale Rannsad422ed2016-11-02 14:20:04 +0000470 """
471
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800472 def __init__(self, test, local_label, eos_bit, paths, table_id=0,
473 is_multicast=0):
Neale Rannsad422ed2016-11-02 14:20:04 +0000474 self._test = test
475 self.paths = paths
476 self.local_label = local_label
477 self.eos_bit = eos_bit
478 self.table_id = table_id
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800479 self.is_multicast = is_multicast
Neale Rannsad422ed2016-11-02 14:20:04 +0000480
481 def add_vpp_config(self):
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800482 is_multipath = len(self.paths) > 1
Neale Rannsad422ed2016-11-02 14:20:04 +0000483 for path in self.paths:
Klement Sekerada505f62017-01-04 12:58:53 +0100484 self._test.vapi.mpls_route_add_del(
485 self.local_label,
486 self.eos_bit,
Neale Rannsda78f952017-05-24 09:15:43 -0700487 path.proto,
Klement Sekerada505f62017-01-04 12:58:53 +0100488 path.nh_addr,
489 path.nh_itf,
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800490 is_multicast=self.is_multicast,
491 is_multipath=is_multipath,
Klement Sekerada505f62017-01-04 12:58:53 +0100492 table_id=self.table_id,
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800493 is_interface_rx=path.is_interface_rx,
494 is_rpf_id=path.is_rpf_id,
Klement Sekerada505f62017-01-04 12:58:53 +0100495 next_hop_out_label_stack=path.nh_labels,
496 next_hop_n_out_labels=len(
497 path.nh_labels),
498 next_hop_via_label=path.nh_via_label,
499 next_hop_table_id=path.nh_table_id)
Neale Ranns5a8123b2017-01-26 01:18:23 -0800500 self._test.registry.register(self, self._test.logger)
Neale Rannsad422ed2016-11-02 14:20:04 +0000501
502 def remove_vpp_config(self):
503 for path in self.paths:
504 self._test.vapi.mpls_route_add_del(self.local_label,
505 self.eos_bit,
Neale Rannsda78f952017-05-24 09:15:43 -0700506 path.proto,
Neale Rannsad422ed2016-11-02 14:20:04 +0000507 path.nh_addr,
508 path.nh_itf,
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800509 is_rpf_id=path.is_rpf_id,
Neale Rannsad422ed2016-11-02 14:20:04 +0000510 table_id=self.table_id,
511 is_add=0)
Neale Ranns5a8123b2017-01-26 01:18:23 -0800512
513 def query_vpp_config(self):
514 dump = self._test.vapi.mpls_fib_dump()
515 for e in dump:
516 if self.local_label == e.label \
517 and self.eos_bit == e.eos_bit \
518 and self.table_id == e.table_id:
519 return True
520 return False
521
522 def __str__(self):
523 return self.object_id()
524
525 def object_id(self):
526 return ("%d:%s/%d"
527 % (self.table_id,
528 self.local_label,
529 20+self.eos_bit))