blob: 3bc3b65111cbb0cf199c1f9d19278ffd5f53f17f [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
Neale Rannsd792d9c2017-10-21 10:53:20 -070037 DPO_PROTO_BIER = 4
38 DPO_PROTO_NSH = 5
Neale Rannsda78f952017-05-24 09:15:43 -070039
40
Neale Rannsb3b2de72017-03-08 05:17:22 -080041def find_route(test, ip_addr, len, table_id=0, inet=AF_INET):
42 if inet == AF_INET:
43 s = 4
44 routes = test.vapi.ip_fib_dump()
45 else:
46 s = 16
47 routes = test.vapi.ip6_fib_dump()
48
49 route_addr = inet_pton(inet, ip_addr)
50 for e in routes:
51 if route_addr == e.address[:s] \
52 and len == e.address_length \
53 and table_id == e.table_id:
54 return True
55 return False
56
57
Neale Ranns15002542017-09-10 04:39:11 -070058class VppIpTable(VppObject):
59
60 def __init__(self,
61 test,
62 table_id,
63 is_ip6=0):
64 self._test = test
65 self.table_id = table_id
66 self.is_ip6 = is_ip6
67
68 def add_vpp_config(self):
69 self._test.vapi.ip_table_add_del(
70 self.table_id,
71 is_ipv6=self.is_ip6,
72 is_add=1)
73 self._test.registry.register(self, self._test.logger)
74
75 def remove_vpp_config(self):
76 self._test.vapi.ip_table_add_del(
77 self.table_id,
78 is_ipv6=self.is_ip6,
79 is_add=0)
80
81 def query_vpp_config(self):
82 # find the default route
83 return find_route(self._test,
84 "::" if self.is_ip6 else "0.0.0.0",
85 0,
86 self.table_id,
87 inet=AF_INET6 if self.is_ip6 == 1 else AF_INET)
88
89 def __str__(self):
90 return self.object_id()
91
92 def object_id(self):
93 return ("table-%s-%d" %
94 ("v6" if self.is_ip6 == 1 else "v4",
95 self.table_id))
96
97
Neale Ranns5a8123b2017-01-26 01:18:23 -080098class VppRoutePath(object):
Neale Rannsad422ed2016-11-02 14:20:04 +000099
Klement Sekerada505f62017-01-04 12:58:53 +0100100 def __init__(
101 self,
102 nh_addr,
103 nh_sw_if_index,
104 nh_table_id=0,
105 labels=[],
Neale Rannsfca0c242017-01-13 07:57:46 -0800106 nh_via_label=MPLS_LABEL_INVALID,
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800107 rpf_id=0,
Neale Rannsf12a83f2017-04-18 09:09:40 -0700108 is_interface_rx=0,
109 is_resolve_host=0,
Neale Rannsda78f952017-05-24 09:15:43 -0700110 is_resolve_attached=0,
Neale Ranns054c03a2017-10-13 05:15:07 -0700111 is_source_lookup=0,
Neale Ranns810086d2017-11-05 16:26:46 -0800112 is_udp_encap=0,
113 next_hop_id=0xffffffff,
Neale Rannsda78f952017-05-24 09:15:43 -0700114 proto=DpoProto.DPO_PROTO_IP4):
Neale Ranns177bbdc2016-11-15 09:46:51 +0000115 self.nh_itf = nh_sw_if_index
116 self.nh_table_id = nh_table_id
Neale Rannsad422ed2016-11-02 14:20:04 +0000117 self.nh_via_label = nh_via_label
118 self.nh_labels = labels
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800119 self.weight = 1
120 self.rpf_id = rpf_id
Neale Rannsda78f952017-05-24 09:15:43 -0700121 self.proto = proto
122 if self.proto is DpoProto.DPO_PROTO_IP6:
123 self.nh_addr = inet_pton(AF_INET6, nh_addr)
124 elif self.proto is DpoProto.DPO_PROTO_IP4:
Neale Rannsb3b2de72017-03-08 05:17:22 -0800125 self.nh_addr = inet_pton(AF_INET, nh_addr)
Neale Ranns31426c62017-05-24 10:32:58 -0700126 else:
Neale Rannsda78f952017-05-24 09:15:43 -0700127 self.nh_addr = inet_pton(AF_INET6, "::")
Neale Rannsf12a83f2017-04-18 09:09:40 -0700128 self.is_resolve_host = is_resolve_host
129 self.is_resolve_attached = is_resolve_attached
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800130 self.is_interface_rx = is_interface_rx
Neale Ranns054c03a2017-10-13 05:15:07 -0700131 self.is_source_lookup = is_source_lookup
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800132 self.is_rpf_id = 0
133 if rpf_id != 0:
134 self.is_rpf_id = 1
135 self.nh_itf = rpf_id
Neale Ranns810086d2017-11-05 16:26:46 -0800136 self.is_udp_encap = is_udp_encap
137 self.next_hop_id = next_hop_id
Neale Ranns177bbdc2016-11-15 09:46:51 +0000138
139
Neale Ranns5a8123b2017-01-26 01:18:23 -0800140class VppMRoutePath(VppRoutePath):
Neale Ranns32e1c012016-11-22 17:07:28 +0000141
Neale Rannsd792d9c2017-10-21 10:53:20 -0700142 def __init__(self, nh_sw_if_index, flags,
143 proto=DpoProto.DPO_PROTO_IP4,
144 bier_imp=0):
145 super(VppMRoutePath, self).__init__(
146 "::" if proto is DpoProto.DPO_PROTO_IP6 else "0.0.0.0",
147 nh_sw_if_index,
148 proto=proto)
Neale Ranns32e1c012016-11-22 17:07:28 +0000149 self.nh_i_flags = flags
Neale Rannsd792d9c2017-10-21 10:53:20 -0700150 self.bier_imp = bier_imp
Neale Ranns32e1c012016-11-22 17:07:28 +0000151
152
Neale Ranns5a8123b2017-01-26 01:18:23 -0800153class VppIpRoute(VppObject):
Neale Ranns177bbdc2016-11-15 09:46:51 +0000154 """
155 IP Route
156 """
157
158 def __init__(self, test, dest_addr,
Neale Ranns37be7362017-02-21 17:30:26 -0800159 dest_addr_len, paths, table_id=0, is_ip6=0, is_local=0,
160 is_unreach=0, is_prohibit=0):
Neale Ranns177bbdc2016-11-15 09:46:51 +0000161 self._test = test
162 self.paths = paths
Neale Ranns177bbdc2016-11-15 09:46:51 +0000163 self.dest_addr_len = dest_addr_len
164 self.table_id = table_id
Neale Rannsfca0c242017-01-13 07:57:46 -0800165 self.is_ip6 = is_ip6
166 self.is_local = is_local
Neale Ranns37be7362017-02-21 17:30:26 -0800167 self.is_unreach = is_unreach
168 self.is_prohibit = is_prohibit
Neale Rannsb3b2de72017-03-08 05:17:22 -0800169 self.dest_addr_p = dest_addr
Neale Rannsfca0c242017-01-13 07:57:46 -0800170 if is_ip6:
Neale Rannsb3b2de72017-03-08 05:17:22 -0800171 self.dest_addr = inet_pton(AF_INET6, dest_addr)
Neale Rannsfca0c242017-01-13 07:57:46 -0800172 else:
Neale Rannsb3b2de72017-03-08 05:17:22 -0800173 self.dest_addr = inet_pton(AF_INET, dest_addr)
Neale Ranns177bbdc2016-11-15 09:46:51 +0000174
Neale Ranns69b7aa42017-03-10 03:04:12 -0800175 def modify(self, paths, is_local=0,
176 is_unreach=0, is_prohibit=0):
177 self.paths = paths
178 self.is_local = is_local
179 self.is_unreach = is_unreach
180 self.is_prohibit = is_prohibit
181
Neale Ranns177bbdc2016-11-15 09:46:51 +0000182 def add_vpp_config(self):
Neale Ranns37be7362017-02-21 17:30:26 -0800183 if self.is_local or self.is_unreach or self.is_prohibit:
Klement Sekerada505f62017-01-04 12:58:53 +0100184 self._test.vapi.ip_add_del_route(
185 self.dest_addr,
186 self.dest_addr_len,
Neale Rannsb3b2de72017-03-08 05:17:22 -0800187 inet_pton(AF_INET6, "::"),
Neale Rannsfca0c242017-01-13 07:57:46 -0800188 0xffffffff,
Neale Ranns37be7362017-02-21 17:30:26 -0800189 is_local=self.is_local,
190 is_unreach=self.is_unreach,
191 is_prohibit=self.is_prohibit,
Klement Sekerada505f62017-01-04 12:58:53 +0100192 table_id=self.table_id,
Neale Rannsfca0c242017-01-13 07:57:46 -0800193 is_ipv6=self.is_ip6)
194 else:
195 for path in self.paths:
196 self._test.vapi.ip_add_del_route(
197 self.dest_addr,
198 self.dest_addr_len,
199 path.nh_addr,
200 path.nh_itf,
201 table_id=self.table_id,
202 next_hop_out_label_stack=path.nh_labels,
203 next_hop_n_out_labels=len(
204 path.nh_labels),
205 next_hop_via_label=path.nh_via_label,
Neale Rannsf12a83f2017-04-18 09:09:40 -0700206 next_hop_table_id=path.nh_table_id,
Neale Ranns810086d2017-11-05 16:26:46 -0800207 next_hop_id=path.next_hop_id,
Neale Rannsf12a83f2017-04-18 09:09:40 -0700208 is_ipv6=self.is_ip6,
Neale Ranns6f631152017-10-03 08:20:21 -0700209 is_l2_bridged=1
210 if path.proto == DpoProto.DPO_PROTO_ETHERNET else 0,
Neale Rannsf12a83f2017-04-18 09:09:40 -0700211 is_resolve_host=path.is_resolve_host,
212 is_resolve_attached=path.is_resolve_attached,
Neale Ranns054c03a2017-10-13 05:15:07 -0700213 is_source_lookup=path.is_source_lookup,
Neale Ranns810086d2017-11-05 16:26:46 -0800214 is_udp_encap=path.is_udp_encap,
Neale Rannsf12a83f2017-04-18 09:09:40 -0700215 is_multipath=1 if len(self.paths) > 1 else 0)
Neale Ranns5a8123b2017-01-26 01:18:23 -0800216 self._test.registry.register(self, self._test.logger)
Neale Ranns177bbdc2016-11-15 09:46:51 +0000217
218 def remove_vpp_config(self):
Neale Ranns37be7362017-02-21 17:30:26 -0800219 if self.is_local or self.is_unreach or self.is_prohibit:
Neale Rannsfca0c242017-01-13 07:57:46 -0800220 self._test.vapi.ip_add_del_route(
221 self.dest_addr,
222 self.dest_addr_len,
Neale Rannsb3b2de72017-03-08 05:17:22 -0800223 inet_pton(AF_INET6, "::"),
Neale Rannsfca0c242017-01-13 07:57:46 -0800224 0xffffffff,
Neale Ranns37be7362017-02-21 17:30:26 -0800225 is_local=self.is_local,
226 is_unreach=self.is_unreach,
227 is_prohibit=self.is_prohibit,
Neale Rannsfca0c242017-01-13 07:57:46 -0800228 is_add=0,
229 table_id=self.table_id,
230 is_ipv6=self.is_ip6)
231 else:
232 for path in self.paths:
Neale Rannsf12a83f2017-04-18 09:09:40 -0700233 self._test.vapi.ip_add_del_route(
234 self.dest_addr,
235 self.dest_addr_len,
236 path.nh_addr,
237 path.nh_itf,
238 table_id=self.table_id,
239 next_hop_table_id=path.nh_table_id,
240 next_hop_via_label=path.nh_via_label,
Neale Ranns810086d2017-11-05 16:26:46 -0800241 next_hop_id=path.next_hop_id,
Neale Rannsf12a83f2017-04-18 09:09:40 -0700242 is_add=0,
Neale Ranns810086d2017-11-05 16:26:46 -0800243 is_udp_encap=path.is_udp_encap,
Neale Rannsf12a83f2017-04-18 09:09:40 -0700244 is_ipv6=self.is_ip6)
Neale Rannsad422ed2016-11-02 14:20:04 +0000245
Neale Ranns5a8123b2017-01-26 01:18:23 -0800246 def query_vpp_config(self):
Neale Rannsb3b2de72017-03-08 05:17:22 -0800247 return find_route(self._test,
248 self.dest_addr_p,
249 self.dest_addr_len,
250 self.table_id,
251 inet=AF_INET6 if self.is_ip6 == 1 else AF_INET)
Neale Rannsad422ed2016-11-02 14:20:04 +0000252
Neale Ranns5a8123b2017-01-26 01:18:23 -0800253 def __str__(self):
254 return self.object_id()
255
256 def object_id(self):
Neale Rannsb3b2de72017-03-08 05:17:22 -0800257 return ("%d:%s/%d"
258 % (self.table_id,
259 self.dest_addr_p,
260 self.dest_addr_len))
Neale Ranns5a8123b2017-01-26 01:18:23 -0800261
262
263class VppIpMRoute(VppObject):
Neale Ranns32e1c012016-11-22 17:07:28 +0000264 """
265 IP Multicast Route
266 """
267
268 def __init__(self, test, src_addr, grp_addr,
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800269 grp_addr_len, e_flags, paths, table_id=0,
270 rpf_id=0, is_ip6=0):
Neale Ranns32e1c012016-11-22 17:07:28 +0000271 self._test = test
272 self.paths = paths
273 self.grp_addr_len = grp_addr_len
274 self.table_id = table_id
275 self.e_flags = e_flags
276 self.is_ip6 = is_ip6
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800277 self.rpf_id = rpf_id
Neale Ranns32e1c012016-11-22 17:07:28 +0000278
279 if is_ip6:
Neale Rannsb3b2de72017-03-08 05:17:22 -0800280 self.grp_addr = inet_pton(AF_INET6, grp_addr)
281 self.src_addr = inet_pton(AF_INET6, src_addr)
Neale Ranns32e1c012016-11-22 17:07:28 +0000282 else:
Neale Rannsb3b2de72017-03-08 05:17:22 -0800283 self.grp_addr = inet_pton(AF_INET, grp_addr)
284 self.src_addr = inet_pton(AF_INET, src_addr)
Neale Ranns32e1c012016-11-22 17:07:28 +0000285
286 def add_vpp_config(self):
287 for path in self.paths:
288 self._test.vapi.ip_mroute_add_del(self.src_addr,
289 self.grp_addr,
290 self.grp_addr_len,
291 self.e_flags,
Neale Rannsd792d9c2017-10-21 10:53:20 -0700292 path.proto,
Neale Ranns32e1c012016-11-22 17:07:28 +0000293 path.nh_itf,
294 path.nh_i_flags,
Neale Rannsd792d9c2017-10-21 10:53:20 -0700295 bier_imp=path.bier_imp,
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800296 rpf_id=self.rpf_id,
Neale Ranns32e1c012016-11-22 17:07:28 +0000297 table_id=self.table_id,
298 is_ipv6=self.is_ip6)
Neale Ranns5a8123b2017-01-26 01:18:23 -0800299 self._test.registry.register(self, self._test.logger)
Neale Ranns32e1c012016-11-22 17:07:28 +0000300
301 def remove_vpp_config(self):
302 for path in self.paths:
303 self._test.vapi.ip_mroute_add_del(self.src_addr,
304 self.grp_addr,
305 self.grp_addr_len,
306 self.e_flags,
Neale Rannsd792d9c2017-10-21 10:53:20 -0700307 path.proto,
Neale Ranns32e1c012016-11-22 17:07:28 +0000308 path.nh_itf,
309 path.nh_i_flags,
310 table_id=self.table_id,
311 is_add=0,
312 is_ipv6=self.is_ip6)
313
314 def update_entry_flags(self, flags):
315 self.e_flags = flags
316 self._test.vapi.ip_mroute_add_del(self.src_addr,
317 self.grp_addr,
318 self.grp_addr_len,
319 self.e_flags,
Neale Rannsd792d9c2017-10-21 10:53:20 -0700320 0,
Neale Ranns32e1c012016-11-22 17:07:28 +0000321 0xffffffff,
322 0,
323 table_id=self.table_id,
324 is_ipv6=self.is_ip6)
325
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800326 def update_rpf_id(self, rpf_id):
327 self.rpf_id = rpf_id
328 self._test.vapi.ip_mroute_add_del(self.src_addr,
329 self.grp_addr,
330 self.grp_addr_len,
331 self.e_flags,
Neale Rannsd792d9c2017-10-21 10:53:20 -0700332 0,
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800333 0xffffffff,
334 0,
335 rpf_id=self.rpf_id,
336 table_id=self.table_id,
337 is_ipv6=self.is_ip6)
338
Neale Ranns32e1c012016-11-22 17:07:28 +0000339 def update_path_flags(self, itf, flags):
340 for path in self.paths:
341 if path.nh_itf == itf:
342 path.nh_i_flags = flags
343 break
344 self._test.vapi.ip_mroute_add_del(self.src_addr,
345 self.grp_addr,
346 self.grp_addr_len,
347 self.e_flags,
Neale Rannsd792d9c2017-10-21 10:53:20 -0700348 path.proto,
Neale Ranns32e1c012016-11-22 17:07:28 +0000349 path.nh_itf,
350 path.nh_i_flags,
351 table_id=self.table_id,
352 is_ipv6=self.is_ip6)
353
Neale Ranns5a8123b2017-01-26 01:18:23 -0800354 def query_vpp_config(self):
Neale Rannsd792d9c2017-10-21 10:53:20 -0700355 if self.is_ip6:
356 dump = self._test.vapi.ip6_mfib_dump()
357 else:
358 dump = self._test.vapi.ip_mfib_dump()
Neale Ranns5a8123b2017-01-26 01:18:23 -0800359 for e in dump:
Neale Rannsd792d9c2017-10-21 10:53:20 -0700360 if self.grp_addr == e.grp_address \
Neale Ranns5a8123b2017-01-26 01:18:23 -0800361 and self.grp_addr_len == e.address_length \
Neale Rannsd792d9c2017-10-21 10:53:20 -0700362 and self.src_addr == e.src_address \
Neale Ranns5a8123b2017-01-26 01:18:23 -0800363 and self.table_id == e.table_id:
364 return True
365 return False
Neale Ranns32e1c012016-11-22 17:07:28 +0000366
Neale Ranns5a8123b2017-01-26 01:18:23 -0800367 def __str__(self):
368 return self.object_id()
369
370 def object_id(self):
371 if self.is_ip6:
372 return ("%d:(%s,%s/%d)"
373 % (self.table_id,
Neale Rannsb3b2de72017-03-08 05:17:22 -0800374 inet_ntop(AF_INET6, self.src_addr),
375 inet_ntop(AF_INET6, self.grp_addr),
Neale Ranns5a8123b2017-01-26 01:18:23 -0800376 self.grp_addr_len))
377 else:
378 return ("%d:(%s,%s/%d)"
379 % (self.table_id,
Neale Rannsb3b2de72017-03-08 05:17:22 -0800380 inet_ntop(AF_INET, self.src_addr),
381 inet_ntop(AF_INET, self.grp_addr),
Neale Ranns5a8123b2017-01-26 01:18:23 -0800382 self.grp_addr_len))
383
384
385class VppMFibSignal(object):
Neale Ranns32e1c012016-11-22 17:07:28 +0000386 def __init__(self, test, route, interface, packet):
387 self.route = route
388 self.interface = interface
389 self.packet = packet
390 self.test = test
391
392 def compare(self, signal):
393 self.test.assertEqual(self.interface, signal.sw_if_index)
394 self.test.assertEqual(self.route.table_id, signal.table_id)
395 self.test.assertEqual(self.route.grp_addr_len,
396 signal.grp_address_len)
397 for i in range(self.route.grp_addr_len / 8):
398 self.test.assertEqual(self.route.grp_addr[i],
399 signal.grp_address[i])
400 if (self.route.grp_addr_len > 32):
401 for i in range(4):
402 self.test.assertEqual(self.route.src_addr[i],
403 signal.src_address[i])
404
405
Neale Ranns5a8123b2017-01-26 01:18:23 -0800406class VppMplsIpBind(VppObject):
Neale Rannsad422ed2016-11-02 14:20:04 +0000407 """
408 MPLS to IP Binding
409 """
410
Neale Ranns5a8123b2017-01-26 01:18:23 -0800411 def __init__(self, test, local_label, dest_addr, dest_addr_len,
Neale Rannsf12a83f2017-04-18 09:09:40 -0700412 table_id=0, ip_table_id=0, is_ip6=0):
Neale Rannsad422ed2016-11-02 14:20:04 +0000413 self._test = test
Neale Rannsad422ed2016-11-02 14:20:04 +0000414 self.dest_addr_len = dest_addr_len
Neale Rannsf12a83f2017-04-18 09:09:40 -0700415 self.dest_addr = dest_addr
Neale Rannsad422ed2016-11-02 14:20:04 +0000416 self.local_label = local_label
Neale Ranns5a8123b2017-01-26 01:18:23 -0800417 self.table_id = table_id
418 self.ip_table_id = ip_table_id
Neale Rannsf12a83f2017-04-18 09:09:40 -0700419 self.is_ip6 = is_ip6
420 if is_ip6:
421 self.dest_addrn = inet_pton(AF_INET6, dest_addr)
422 else:
423 self.dest_addrn = inet_pton(AF_INET, dest_addr)
Neale Rannsad422ed2016-11-02 14:20:04 +0000424
425 def add_vpp_config(self):
426 self._test.vapi.mpls_ip_bind_unbind(self.local_label,
Neale Rannsf12a83f2017-04-18 09:09:40 -0700427 self.dest_addrn,
Neale Ranns5a8123b2017-01-26 01:18:23 -0800428 self.dest_addr_len,
429 table_id=self.table_id,
Neale Rannsf12a83f2017-04-18 09:09:40 -0700430 ip_table_id=self.ip_table_id,
431 is_ip4=(self.is_ip6 == 0))
Neale Ranns5a8123b2017-01-26 01:18:23 -0800432 self._test.registry.register(self, self._test.logger)
Neale Rannsad422ed2016-11-02 14:20:04 +0000433
434 def remove_vpp_config(self):
435 self._test.vapi.mpls_ip_bind_unbind(self.local_label,
Neale Rannsf12a83f2017-04-18 09:09:40 -0700436 self.dest_addrn,
Neale Rannsad422ed2016-11-02 14:20:04 +0000437 self.dest_addr_len,
Neale Rannsf12a83f2017-04-18 09:09:40 -0700438 table_id=self.table_id,
439 ip_table_id=self.ip_table_id,
440 is_bind=0,
441 is_ip4=(self.is_ip6 == 0))
Neale Rannsad422ed2016-11-02 14:20:04 +0000442
Neale Ranns5a8123b2017-01-26 01:18:23 -0800443 def query_vpp_config(self):
444 dump = self._test.vapi.mpls_fib_dump()
445 for e in dump:
446 if self.local_label == e.label \
Neale Ranns5a8123b2017-01-26 01:18:23 -0800447 and self.table_id == e.table_id:
448 return True
449 return False
Neale Rannsad422ed2016-11-02 14:20:04 +0000450
Neale Ranns5a8123b2017-01-26 01:18:23 -0800451 def __str__(self):
452 return self.object_id()
453
454 def object_id(self):
455 return ("%d:%s binds %d:%s/%d"
456 % (self.table_id,
457 self.local_label,
458 self.ip_table_id,
Neale Rannsf12a83f2017-04-18 09:09:40 -0700459 self.dest_addr,
Neale Ranns5a8123b2017-01-26 01:18:23 -0800460 self.dest_addr_len))
461
462
Neale Ranns15002542017-09-10 04:39:11 -0700463class VppMplsTable(VppObject):
464
465 def __init__(self,
466 test,
467 table_id):
468 self._test = test
469 self.table_id = table_id
470
471 def add_vpp_config(self):
472 self._test.vapi.mpls_table_add_del(
473 self.table_id,
474 is_add=1)
475 self._test.registry.register(self, self._test.logger)
476
477 def remove_vpp_config(self):
478 self._test.vapi.mpls_table_add_del(
479 self.table_id,
480 is_add=0)
481
482 def query_vpp_config(self):
483 # find the default route
484 dump = self._test.vapi.mpls_fib_dump()
485 if len(dump):
486 return True
487 return False
488
489 def __str__(self):
490 return self.object_id()
491
492 def object_id(self):
493 return ("table-mpls-%d" % (self.table_id))
494
495
Neale Ranns5a8123b2017-01-26 01:18:23 -0800496class VppMplsRoute(VppObject):
Neale Rannsad422ed2016-11-02 14:20:04 +0000497 """
Neale Ranns5a8123b2017-01-26 01:18:23 -0800498 MPLS Route/LSP
Neale Rannsad422ed2016-11-02 14:20:04 +0000499 """
500
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800501 def __init__(self, test, local_label, eos_bit, paths, table_id=0,
502 is_multicast=0):
Neale Rannsad422ed2016-11-02 14:20:04 +0000503 self._test = test
504 self.paths = paths
505 self.local_label = local_label
506 self.eos_bit = eos_bit
507 self.table_id = table_id
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800508 self.is_multicast = is_multicast
Neale Rannsad422ed2016-11-02 14:20:04 +0000509
510 def add_vpp_config(self):
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800511 is_multipath = len(self.paths) > 1
Neale Rannsad422ed2016-11-02 14:20:04 +0000512 for path in self.paths:
Klement Sekerada505f62017-01-04 12:58:53 +0100513 self._test.vapi.mpls_route_add_del(
514 self.local_label,
515 self.eos_bit,
Neale Rannsda78f952017-05-24 09:15:43 -0700516 path.proto,
Klement Sekerada505f62017-01-04 12:58:53 +0100517 path.nh_addr,
518 path.nh_itf,
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800519 is_multicast=self.is_multicast,
520 is_multipath=is_multipath,
Klement Sekerada505f62017-01-04 12:58:53 +0100521 table_id=self.table_id,
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800522 is_interface_rx=path.is_interface_rx,
523 is_rpf_id=path.is_rpf_id,
Klement Sekerada505f62017-01-04 12:58:53 +0100524 next_hop_out_label_stack=path.nh_labels,
525 next_hop_n_out_labels=len(
526 path.nh_labels),
527 next_hop_via_label=path.nh_via_label,
528 next_hop_table_id=path.nh_table_id)
Neale Ranns5a8123b2017-01-26 01:18:23 -0800529 self._test.registry.register(self, self._test.logger)
Neale Rannsad422ed2016-11-02 14:20:04 +0000530
531 def remove_vpp_config(self):
532 for path in self.paths:
533 self._test.vapi.mpls_route_add_del(self.local_label,
534 self.eos_bit,
Neale Rannsda78f952017-05-24 09:15:43 -0700535 path.proto,
Neale Rannsad422ed2016-11-02 14:20:04 +0000536 path.nh_addr,
537 path.nh_itf,
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800538 is_rpf_id=path.is_rpf_id,
Neale Rannsad422ed2016-11-02 14:20:04 +0000539 table_id=self.table_id,
540 is_add=0)
Neale Ranns5a8123b2017-01-26 01:18:23 -0800541
542 def query_vpp_config(self):
543 dump = self._test.vapi.mpls_fib_dump()
544 for e in dump:
545 if self.local_label == e.label \
546 and self.eos_bit == e.eos_bit \
547 and self.table_id == e.table_id:
548 return True
549 return False
550
551 def __str__(self):
552 return self.object_id()
553
554 def object_id(self):
555 return ("%d:%s/%d"
556 % (self.table_id,
557 self.local_label,
558 20+self.eos_bit))