blob: 7501146e96a4a8545250622585d89ddbb8ad8f42 [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,
Neale Ranns054c03a2017-10-13 05:15:07 -0700110 is_source_lookup=0,
Neale Rannsda78f952017-05-24 09:15:43 -0700111 proto=DpoProto.DPO_PROTO_IP4):
Neale Ranns177bbdc2016-11-15 09:46:51 +0000112 self.nh_itf = nh_sw_if_index
113 self.nh_table_id = nh_table_id
Neale Rannsad422ed2016-11-02 14:20:04 +0000114 self.nh_via_label = nh_via_label
115 self.nh_labels = labels
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800116 self.weight = 1
117 self.rpf_id = rpf_id
Neale Rannsda78f952017-05-24 09:15:43 -0700118 self.proto = proto
119 if self.proto is DpoProto.DPO_PROTO_IP6:
120 self.nh_addr = inet_pton(AF_INET6, nh_addr)
121 elif self.proto is DpoProto.DPO_PROTO_IP4:
Neale Rannsb3b2de72017-03-08 05:17:22 -0800122 self.nh_addr = inet_pton(AF_INET, nh_addr)
Neale Ranns31426c62017-05-24 10:32:58 -0700123 else:
Neale Rannsda78f952017-05-24 09:15:43 -0700124 self.nh_addr = inet_pton(AF_INET6, "::")
Neale Rannsf12a83f2017-04-18 09:09:40 -0700125 self.is_resolve_host = is_resolve_host
126 self.is_resolve_attached = is_resolve_attached
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800127 self.is_interface_rx = is_interface_rx
Neale Ranns054c03a2017-10-13 05:15:07 -0700128 self.is_source_lookup = is_source_lookup
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800129 self.is_rpf_id = 0
130 if rpf_id != 0:
131 self.is_rpf_id = 1
132 self.nh_itf = rpf_id
Neale Ranns177bbdc2016-11-15 09:46:51 +0000133
134
Neale Ranns5a8123b2017-01-26 01:18:23 -0800135class VppMRoutePath(VppRoutePath):
Neale Ranns32e1c012016-11-22 17:07:28 +0000136
137 def __init__(self, nh_sw_if_index, flags):
Neale Ranns5a8123b2017-01-26 01:18:23 -0800138 super(VppMRoutePath, self).__init__("0.0.0.0",
139 nh_sw_if_index)
Neale Ranns32e1c012016-11-22 17:07:28 +0000140 self.nh_i_flags = flags
141
142
Neale Ranns5a8123b2017-01-26 01:18:23 -0800143class VppIpRoute(VppObject):
Neale Ranns177bbdc2016-11-15 09:46:51 +0000144 """
145 IP Route
146 """
147
148 def __init__(self, test, dest_addr,
Neale Ranns37be7362017-02-21 17:30:26 -0800149 dest_addr_len, paths, table_id=0, is_ip6=0, is_local=0,
150 is_unreach=0, is_prohibit=0):
Neale Ranns177bbdc2016-11-15 09:46:51 +0000151 self._test = test
152 self.paths = paths
Neale Ranns177bbdc2016-11-15 09:46:51 +0000153 self.dest_addr_len = dest_addr_len
154 self.table_id = table_id
Neale Rannsfca0c242017-01-13 07:57:46 -0800155 self.is_ip6 = is_ip6
156 self.is_local = is_local
Neale Ranns37be7362017-02-21 17:30:26 -0800157 self.is_unreach = is_unreach
158 self.is_prohibit = is_prohibit
Neale Rannsb3b2de72017-03-08 05:17:22 -0800159 self.dest_addr_p = dest_addr
Neale Rannsfca0c242017-01-13 07:57:46 -0800160 if is_ip6:
Neale Rannsb3b2de72017-03-08 05:17:22 -0800161 self.dest_addr = inet_pton(AF_INET6, dest_addr)
Neale Rannsfca0c242017-01-13 07:57:46 -0800162 else:
Neale Rannsb3b2de72017-03-08 05:17:22 -0800163 self.dest_addr = inet_pton(AF_INET, dest_addr)
Neale Ranns177bbdc2016-11-15 09:46:51 +0000164
Neale Ranns69b7aa42017-03-10 03:04:12 -0800165 def modify(self, paths, is_local=0,
166 is_unreach=0, is_prohibit=0):
167 self.paths = paths
168 self.is_local = is_local
169 self.is_unreach = is_unreach
170 self.is_prohibit = is_prohibit
171
Neale Ranns177bbdc2016-11-15 09:46:51 +0000172 def add_vpp_config(self):
Neale Ranns37be7362017-02-21 17:30:26 -0800173 if self.is_local or self.is_unreach or self.is_prohibit:
Klement Sekerada505f62017-01-04 12:58:53 +0100174 self._test.vapi.ip_add_del_route(
175 self.dest_addr,
176 self.dest_addr_len,
Neale Rannsb3b2de72017-03-08 05:17:22 -0800177 inet_pton(AF_INET6, "::"),
Neale Rannsfca0c242017-01-13 07:57:46 -0800178 0xffffffff,
Neale Ranns37be7362017-02-21 17:30:26 -0800179 is_local=self.is_local,
180 is_unreach=self.is_unreach,
181 is_prohibit=self.is_prohibit,
Klement Sekerada505f62017-01-04 12:58:53 +0100182 table_id=self.table_id,
Neale Rannsfca0c242017-01-13 07:57:46 -0800183 is_ipv6=self.is_ip6)
184 else:
185 for path in self.paths:
186 self._test.vapi.ip_add_del_route(
187 self.dest_addr,
188 self.dest_addr_len,
189 path.nh_addr,
190 path.nh_itf,
191 table_id=self.table_id,
192 next_hop_out_label_stack=path.nh_labels,
193 next_hop_n_out_labels=len(
194 path.nh_labels),
195 next_hop_via_label=path.nh_via_label,
Neale Rannsf12a83f2017-04-18 09:09:40 -0700196 next_hop_table_id=path.nh_table_id,
197 is_ipv6=self.is_ip6,
Neale Ranns6f631152017-10-03 08:20:21 -0700198 is_l2_bridged=1
199 if path.proto == DpoProto.DPO_PROTO_ETHERNET else 0,
Neale Rannsf12a83f2017-04-18 09:09:40 -0700200 is_resolve_host=path.is_resolve_host,
201 is_resolve_attached=path.is_resolve_attached,
Neale Ranns054c03a2017-10-13 05:15:07 -0700202 is_source_lookup=path.is_source_lookup,
Neale Rannsf12a83f2017-04-18 09:09:40 -0700203 is_multipath=1 if len(self.paths) > 1 else 0)
Neale Ranns5a8123b2017-01-26 01:18:23 -0800204 self._test.registry.register(self, self._test.logger)
Neale Ranns177bbdc2016-11-15 09:46:51 +0000205
206 def remove_vpp_config(self):
Neale Ranns37be7362017-02-21 17:30:26 -0800207 if self.is_local or self.is_unreach or self.is_prohibit:
Neale Rannsfca0c242017-01-13 07:57:46 -0800208 self._test.vapi.ip_add_del_route(
209 self.dest_addr,
210 self.dest_addr_len,
Neale Rannsb3b2de72017-03-08 05:17:22 -0800211 inet_pton(AF_INET6, "::"),
Neale Rannsfca0c242017-01-13 07:57:46 -0800212 0xffffffff,
Neale Ranns37be7362017-02-21 17:30:26 -0800213 is_local=self.is_local,
214 is_unreach=self.is_unreach,
215 is_prohibit=self.is_prohibit,
Neale Rannsfca0c242017-01-13 07:57:46 -0800216 is_add=0,
217 table_id=self.table_id,
218 is_ipv6=self.is_ip6)
219 else:
220 for path in self.paths:
Neale Rannsf12a83f2017-04-18 09:09:40 -0700221 self._test.vapi.ip_add_del_route(
222 self.dest_addr,
223 self.dest_addr_len,
224 path.nh_addr,
225 path.nh_itf,
226 table_id=self.table_id,
227 next_hop_table_id=path.nh_table_id,
228 next_hop_via_label=path.nh_via_label,
229 is_add=0,
230 is_ipv6=self.is_ip6)
Neale Rannsad422ed2016-11-02 14:20:04 +0000231
Neale Ranns5a8123b2017-01-26 01:18:23 -0800232 def query_vpp_config(self):
Neale Rannsb3b2de72017-03-08 05:17:22 -0800233 return find_route(self._test,
234 self.dest_addr_p,
235 self.dest_addr_len,
236 self.table_id,
237 inet=AF_INET6 if self.is_ip6 == 1 else AF_INET)
Neale Rannsad422ed2016-11-02 14:20:04 +0000238
Neale Ranns5a8123b2017-01-26 01:18:23 -0800239 def __str__(self):
240 return self.object_id()
241
242 def object_id(self):
Neale Rannsb3b2de72017-03-08 05:17:22 -0800243 return ("%d:%s/%d"
244 % (self.table_id,
245 self.dest_addr_p,
246 self.dest_addr_len))
Neale Ranns5a8123b2017-01-26 01:18:23 -0800247
248
249class VppIpMRoute(VppObject):
Neale Ranns32e1c012016-11-22 17:07:28 +0000250 """
251 IP Multicast Route
252 """
253
254 def __init__(self, test, src_addr, grp_addr,
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800255 grp_addr_len, e_flags, paths, table_id=0,
256 rpf_id=0, is_ip6=0):
Neale Ranns32e1c012016-11-22 17:07:28 +0000257 self._test = test
258 self.paths = paths
259 self.grp_addr_len = grp_addr_len
260 self.table_id = table_id
261 self.e_flags = e_flags
262 self.is_ip6 = is_ip6
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800263 self.rpf_id = rpf_id
Neale Ranns32e1c012016-11-22 17:07:28 +0000264
265 if is_ip6:
Neale Rannsb3b2de72017-03-08 05:17:22 -0800266 self.grp_addr = inet_pton(AF_INET6, grp_addr)
267 self.src_addr = inet_pton(AF_INET6, src_addr)
Neale Ranns32e1c012016-11-22 17:07:28 +0000268 else:
Neale Rannsb3b2de72017-03-08 05:17:22 -0800269 self.grp_addr = inet_pton(AF_INET, grp_addr)
270 self.src_addr = inet_pton(AF_INET, src_addr)
Neale Ranns32e1c012016-11-22 17:07:28 +0000271
272 def add_vpp_config(self):
273 for path in self.paths:
274 self._test.vapi.ip_mroute_add_del(self.src_addr,
275 self.grp_addr,
276 self.grp_addr_len,
277 self.e_flags,
278 path.nh_itf,
279 path.nh_i_flags,
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800280 rpf_id=self.rpf_id,
Neale Ranns32e1c012016-11-22 17:07:28 +0000281 table_id=self.table_id,
282 is_ipv6=self.is_ip6)
Neale Ranns5a8123b2017-01-26 01:18:23 -0800283 self._test.registry.register(self, self._test.logger)
Neale Ranns32e1c012016-11-22 17:07:28 +0000284
285 def remove_vpp_config(self):
286 for path in self.paths:
287 self._test.vapi.ip_mroute_add_del(self.src_addr,
288 self.grp_addr,
289 self.grp_addr_len,
290 self.e_flags,
291 path.nh_itf,
292 path.nh_i_flags,
293 table_id=self.table_id,
294 is_add=0,
295 is_ipv6=self.is_ip6)
296
297 def update_entry_flags(self, flags):
298 self.e_flags = flags
299 self._test.vapi.ip_mroute_add_del(self.src_addr,
300 self.grp_addr,
301 self.grp_addr_len,
302 self.e_flags,
303 0xffffffff,
304 0,
305 table_id=self.table_id,
306 is_ipv6=self.is_ip6)
307
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800308 def update_rpf_id(self, rpf_id):
309 self.rpf_id = rpf_id
310 self._test.vapi.ip_mroute_add_del(self.src_addr,
311 self.grp_addr,
312 self.grp_addr_len,
313 self.e_flags,
314 0xffffffff,
315 0,
316 rpf_id=self.rpf_id,
317 table_id=self.table_id,
318 is_ipv6=self.is_ip6)
319
Neale Ranns32e1c012016-11-22 17:07:28 +0000320 def update_path_flags(self, itf, flags):
321 for path in self.paths:
322 if path.nh_itf == itf:
323 path.nh_i_flags = flags
324 break
325 self._test.vapi.ip_mroute_add_del(self.src_addr,
326 self.grp_addr,
327 self.grp_addr_len,
328 self.e_flags,
329 path.nh_itf,
330 path.nh_i_flags,
331 table_id=self.table_id,
332 is_ipv6=self.is_ip6)
333
Neale Ranns5a8123b2017-01-26 01:18:23 -0800334 def query_vpp_config(self):
335 dump = self._test.vapi.ip_fib_dump()
336 for e in dump:
337 if self.grp_addr == e.address \
338 and self.grp_addr_len == e.address_length \
339 and self.table_id == e.table_id:
340 return True
341 return False
Neale Ranns32e1c012016-11-22 17:07:28 +0000342
Neale Ranns5a8123b2017-01-26 01:18:23 -0800343 def __str__(self):
344 return self.object_id()
345
346 def object_id(self):
347 if self.is_ip6:
348 return ("%d:(%s,%s/%d)"
349 % (self.table_id,
Neale Rannsb3b2de72017-03-08 05:17:22 -0800350 inet_ntop(AF_INET6, self.src_addr),
351 inet_ntop(AF_INET6, self.grp_addr),
Neale Ranns5a8123b2017-01-26 01:18:23 -0800352 self.grp_addr_len))
353 else:
354 return ("%d:(%s,%s/%d)"
355 % (self.table_id,
Neale Rannsb3b2de72017-03-08 05:17:22 -0800356 inet_ntop(AF_INET, self.src_addr),
357 inet_ntop(AF_INET, self.grp_addr),
Neale Ranns5a8123b2017-01-26 01:18:23 -0800358 self.grp_addr_len))
359
360
361class VppMFibSignal(object):
Neale Ranns32e1c012016-11-22 17:07:28 +0000362 def __init__(self, test, route, interface, packet):
363 self.route = route
364 self.interface = interface
365 self.packet = packet
366 self.test = test
367
368 def compare(self, signal):
369 self.test.assertEqual(self.interface, signal.sw_if_index)
370 self.test.assertEqual(self.route.table_id, signal.table_id)
371 self.test.assertEqual(self.route.grp_addr_len,
372 signal.grp_address_len)
373 for i in range(self.route.grp_addr_len / 8):
374 self.test.assertEqual(self.route.grp_addr[i],
375 signal.grp_address[i])
376 if (self.route.grp_addr_len > 32):
377 for i in range(4):
378 self.test.assertEqual(self.route.src_addr[i],
379 signal.src_address[i])
380
381
Neale Ranns5a8123b2017-01-26 01:18:23 -0800382class VppMplsIpBind(VppObject):
Neale Rannsad422ed2016-11-02 14:20:04 +0000383 """
384 MPLS to IP Binding
385 """
386
Neale Ranns5a8123b2017-01-26 01:18:23 -0800387 def __init__(self, test, local_label, dest_addr, dest_addr_len,
Neale Rannsf12a83f2017-04-18 09:09:40 -0700388 table_id=0, ip_table_id=0, is_ip6=0):
Neale Rannsad422ed2016-11-02 14:20:04 +0000389 self._test = test
Neale Rannsad422ed2016-11-02 14:20:04 +0000390 self.dest_addr_len = dest_addr_len
Neale Rannsf12a83f2017-04-18 09:09:40 -0700391 self.dest_addr = dest_addr
Neale Rannsad422ed2016-11-02 14:20:04 +0000392 self.local_label = local_label
Neale Ranns5a8123b2017-01-26 01:18:23 -0800393 self.table_id = table_id
394 self.ip_table_id = ip_table_id
Neale Rannsf12a83f2017-04-18 09:09:40 -0700395 self.is_ip6 = is_ip6
396 if is_ip6:
397 self.dest_addrn = inet_pton(AF_INET6, dest_addr)
398 else:
399 self.dest_addrn = inet_pton(AF_INET, dest_addr)
Neale Rannsad422ed2016-11-02 14:20:04 +0000400
401 def add_vpp_config(self):
402 self._test.vapi.mpls_ip_bind_unbind(self.local_label,
Neale Rannsf12a83f2017-04-18 09:09:40 -0700403 self.dest_addrn,
Neale Ranns5a8123b2017-01-26 01:18:23 -0800404 self.dest_addr_len,
405 table_id=self.table_id,
Neale Rannsf12a83f2017-04-18 09:09:40 -0700406 ip_table_id=self.ip_table_id,
407 is_ip4=(self.is_ip6 == 0))
Neale Ranns5a8123b2017-01-26 01:18:23 -0800408 self._test.registry.register(self, self._test.logger)
Neale Rannsad422ed2016-11-02 14:20:04 +0000409
410 def remove_vpp_config(self):
411 self._test.vapi.mpls_ip_bind_unbind(self.local_label,
Neale Rannsf12a83f2017-04-18 09:09:40 -0700412 self.dest_addrn,
Neale Rannsad422ed2016-11-02 14:20:04 +0000413 self.dest_addr_len,
Neale Rannsf12a83f2017-04-18 09:09:40 -0700414 table_id=self.table_id,
415 ip_table_id=self.ip_table_id,
416 is_bind=0,
417 is_ip4=(self.is_ip6 == 0))
Neale Rannsad422ed2016-11-02 14:20:04 +0000418
Neale Ranns5a8123b2017-01-26 01:18:23 -0800419 def query_vpp_config(self):
420 dump = self._test.vapi.mpls_fib_dump()
421 for e in dump:
422 if self.local_label == e.label \
Neale Ranns5a8123b2017-01-26 01:18:23 -0800423 and self.table_id == e.table_id:
424 return True
425 return False
Neale Rannsad422ed2016-11-02 14:20:04 +0000426
Neale Ranns5a8123b2017-01-26 01:18:23 -0800427 def __str__(self):
428 return self.object_id()
429
430 def object_id(self):
431 return ("%d:%s binds %d:%s/%d"
432 % (self.table_id,
433 self.local_label,
434 self.ip_table_id,
Neale Rannsf12a83f2017-04-18 09:09:40 -0700435 self.dest_addr,
Neale Ranns5a8123b2017-01-26 01:18:23 -0800436 self.dest_addr_len))
437
438
Neale Ranns15002542017-09-10 04:39:11 -0700439class VppMplsTable(VppObject):
440
441 def __init__(self,
442 test,
443 table_id):
444 self._test = test
445 self.table_id = table_id
446
447 def add_vpp_config(self):
448 self._test.vapi.mpls_table_add_del(
449 self.table_id,
450 is_add=1)
451 self._test.registry.register(self, self._test.logger)
452
453 def remove_vpp_config(self):
454 self._test.vapi.mpls_table_add_del(
455 self.table_id,
456 is_add=0)
457
458 def query_vpp_config(self):
459 # find the default route
460 dump = self._test.vapi.mpls_fib_dump()
461 if len(dump):
462 return True
463 return False
464
465 def __str__(self):
466 return self.object_id()
467
468 def object_id(self):
469 return ("table-mpls-%d" % (self.table_id))
470
471
Neale Ranns5a8123b2017-01-26 01:18:23 -0800472class VppMplsRoute(VppObject):
Neale Rannsad422ed2016-11-02 14:20:04 +0000473 """
Neale Ranns5a8123b2017-01-26 01:18:23 -0800474 MPLS Route/LSP
Neale Rannsad422ed2016-11-02 14:20:04 +0000475 """
476
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800477 def __init__(self, test, local_label, eos_bit, paths, table_id=0,
478 is_multicast=0):
Neale Rannsad422ed2016-11-02 14:20:04 +0000479 self._test = test
480 self.paths = paths
481 self.local_label = local_label
482 self.eos_bit = eos_bit
483 self.table_id = table_id
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800484 self.is_multicast = is_multicast
Neale Rannsad422ed2016-11-02 14:20:04 +0000485
486 def add_vpp_config(self):
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800487 is_multipath = len(self.paths) > 1
Neale Rannsad422ed2016-11-02 14:20:04 +0000488 for path in self.paths:
Klement Sekerada505f62017-01-04 12:58:53 +0100489 self._test.vapi.mpls_route_add_del(
490 self.local_label,
491 self.eos_bit,
Neale Rannsda78f952017-05-24 09:15:43 -0700492 path.proto,
Klement Sekerada505f62017-01-04 12:58:53 +0100493 path.nh_addr,
494 path.nh_itf,
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800495 is_multicast=self.is_multicast,
496 is_multipath=is_multipath,
Klement Sekerada505f62017-01-04 12:58:53 +0100497 table_id=self.table_id,
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800498 is_interface_rx=path.is_interface_rx,
499 is_rpf_id=path.is_rpf_id,
Klement Sekerada505f62017-01-04 12:58:53 +0100500 next_hop_out_label_stack=path.nh_labels,
501 next_hop_n_out_labels=len(
502 path.nh_labels),
503 next_hop_via_label=path.nh_via_label,
504 next_hop_table_id=path.nh_table_id)
Neale Ranns5a8123b2017-01-26 01:18:23 -0800505 self._test.registry.register(self, self._test.logger)
Neale Rannsad422ed2016-11-02 14:20:04 +0000506
507 def remove_vpp_config(self):
508 for path in self.paths:
509 self._test.vapi.mpls_route_add_del(self.local_label,
510 self.eos_bit,
Neale Rannsda78f952017-05-24 09:15:43 -0700511 path.proto,
Neale Rannsad422ed2016-11-02 14:20:04 +0000512 path.nh_addr,
513 path.nh_itf,
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800514 is_rpf_id=path.is_rpf_id,
Neale Rannsad422ed2016-11-02 14:20:04 +0000515 table_id=self.table_id,
516 is_add=0)
Neale Ranns5a8123b2017-01-26 01:18:23 -0800517
518 def query_vpp_config(self):
519 dump = self._test.vapi.mpls_fib_dump()
520 for e in dump:
521 if self.local_label == e.label \
522 and self.eos_bit == e.eos_bit \
523 and self.table_id == e.table_id:
524 return True
525 return False
526
527 def __str__(self):
528 return self.object_id()
529
530 def object_id(self):
531 return ("%d:%s/%d"
532 % (self.table_id,
533 self.local_label,
534 20+self.eos_bit))