blob: 2d34f55efdf68399654a02cf83b9248a7477045d [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,
Neale Rannsf068c3e2018-01-03 04:18:48 -0800113 is_dvr=0,
Neale Ranns810086d2017-11-05 16:26:46 -0800114 next_hop_id=0xffffffff,
Neale Rannsda78f952017-05-24 09:15:43 -0700115 proto=DpoProto.DPO_PROTO_IP4):
Neale Ranns177bbdc2016-11-15 09:46:51 +0000116 self.nh_itf = nh_sw_if_index
117 self.nh_table_id = nh_table_id
Neale Rannsad422ed2016-11-02 14:20:04 +0000118 self.nh_via_label = nh_via_label
119 self.nh_labels = labels
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800120 self.weight = 1
121 self.rpf_id = rpf_id
Neale Rannsda78f952017-05-24 09:15:43 -0700122 self.proto = proto
123 if self.proto is DpoProto.DPO_PROTO_IP6:
124 self.nh_addr = inet_pton(AF_INET6, nh_addr)
125 elif self.proto is DpoProto.DPO_PROTO_IP4:
Neale Rannsb3b2de72017-03-08 05:17:22 -0800126 self.nh_addr = inet_pton(AF_INET, nh_addr)
Neale Ranns31426c62017-05-24 10:32:58 -0700127 else:
Neale Rannsda78f952017-05-24 09:15:43 -0700128 self.nh_addr = inet_pton(AF_INET6, "::")
Neale Rannsf12a83f2017-04-18 09:09:40 -0700129 self.is_resolve_host = is_resolve_host
130 self.is_resolve_attached = is_resolve_attached
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800131 self.is_interface_rx = is_interface_rx
Neale Ranns054c03a2017-10-13 05:15:07 -0700132 self.is_source_lookup = is_source_lookup
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800133 self.is_rpf_id = 0
134 if rpf_id != 0:
135 self.is_rpf_id = 1
136 self.nh_itf = rpf_id
Neale Ranns810086d2017-11-05 16:26:46 -0800137 self.is_udp_encap = is_udp_encap
138 self.next_hop_id = next_hop_id
Neale Rannsf068c3e2018-01-03 04:18:48 -0800139 self.is_dvr = is_dvr
Neale Ranns177bbdc2016-11-15 09:46:51 +0000140
141
Neale Ranns5a8123b2017-01-26 01:18:23 -0800142class VppMRoutePath(VppRoutePath):
Neale Ranns32e1c012016-11-22 17:07:28 +0000143
Neale Rannsd792d9c2017-10-21 10:53:20 -0700144 def __init__(self, nh_sw_if_index, flags,
145 proto=DpoProto.DPO_PROTO_IP4,
146 bier_imp=0):
147 super(VppMRoutePath, self).__init__(
148 "::" if proto is DpoProto.DPO_PROTO_IP6 else "0.0.0.0",
149 nh_sw_if_index,
150 proto=proto)
Neale Ranns32e1c012016-11-22 17:07:28 +0000151 self.nh_i_flags = flags
Neale Rannsd792d9c2017-10-21 10:53:20 -0700152 self.bier_imp = bier_imp
Neale Ranns32e1c012016-11-22 17:07:28 +0000153
154
Neale Ranns5a8123b2017-01-26 01:18:23 -0800155class VppIpRoute(VppObject):
Neale Ranns177bbdc2016-11-15 09:46:51 +0000156 """
157 IP Route
158 """
159
160 def __init__(self, test, dest_addr,
Neale Ranns37be7362017-02-21 17:30:26 -0800161 dest_addr_len, paths, table_id=0, is_ip6=0, is_local=0,
162 is_unreach=0, is_prohibit=0):
Neale Ranns177bbdc2016-11-15 09:46:51 +0000163 self._test = test
164 self.paths = paths
Neale Ranns177bbdc2016-11-15 09:46:51 +0000165 self.dest_addr_len = dest_addr_len
166 self.table_id = table_id
Neale Rannsfca0c242017-01-13 07:57:46 -0800167 self.is_ip6 = is_ip6
168 self.is_local = is_local
Neale Ranns37be7362017-02-21 17:30:26 -0800169 self.is_unreach = is_unreach
170 self.is_prohibit = is_prohibit
Neale Rannsb3b2de72017-03-08 05:17:22 -0800171 self.dest_addr_p = dest_addr
Neale Rannsfca0c242017-01-13 07:57:46 -0800172 if is_ip6:
Neale Rannsb3b2de72017-03-08 05:17:22 -0800173 self.dest_addr = inet_pton(AF_INET6, dest_addr)
Neale Rannsfca0c242017-01-13 07:57:46 -0800174 else:
Neale Rannsb3b2de72017-03-08 05:17:22 -0800175 self.dest_addr = inet_pton(AF_INET, dest_addr)
Neale Ranns177bbdc2016-11-15 09:46:51 +0000176
Neale Ranns69b7aa42017-03-10 03:04:12 -0800177 def modify(self, paths, is_local=0,
178 is_unreach=0, is_prohibit=0):
179 self.paths = paths
180 self.is_local = is_local
181 self.is_unreach = is_unreach
182 self.is_prohibit = is_prohibit
183
Neale Ranns177bbdc2016-11-15 09:46:51 +0000184 def add_vpp_config(self):
Neale Ranns37be7362017-02-21 17:30:26 -0800185 if self.is_local or self.is_unreach or self.is_prohibit:
Klement Sekerada505f62017-01-04 12:58:53 +0100186 self._test.vapi.ip_add_del_route(
187 self.dest_addr,
188 self.dest_addr_len,
Neale Rannsb3b2de72017-03-08 05:17:22 -0800189 inet_pton(AF_INET6, "::"),
Neale Rannsfca0c242017-01-13 07:57:46 -0800190 0xffffffff,
Neale Ranns37be7362017-02-21 17:30:26 -0800191 is_local=self.is_local,
192 is_unreach=self.is_unreach,
193 is_prohibit=self.is_prohibit,
Klement Sekerada505f62017-01-04 12:58:53 +0100194 table_id=self.table_id,
Neale Rannsfca0c242017-01-13 07:57:46 -0800195 is_ipv6=self.is_ip6)
196 else:
197 for path in self.paths:
198 self._test.vapi.ip_add_del_route(
199 self.dest_addr,
200 self.dest_addr_len,
201 path.nh_addr,
202 path.nh_itf,
203 table_id=self.table_id,
204 next_hop_out_label_stack=path.nh_labels,
205 next_hop_n_out_labels=len(
206 path.nh_labels),
207 next_hop_via_label=path.nh_via_label,
Neale Rannsf12a83f2017-04-18 09:09:40 -0700208 next_hop_table_id=path.nh_table_id,
Neale Ranns810086d2017-11-05 16:26:46 -0800209 next_hop_id=path.next_hop_id,
Neale Rannsf12a83f2017-04-18 09:09:40 -0700210 is_ipv6=self.is_ip6,
Neale Rannsf068c3e2018-01-03 04:18:48 -0800211 is_dvr=path.is_dvr,
Neale Rannsf12a83f2017-04-18 09:09:40 -0700212 is_resolve_host=path.is_resolve_host,
213 is_resolve_attached=path.is_resolve_attached,
Neale Ranns054c03a2017-10-13 05:15:07 -0700214 is_source_lookup=path.is_source_lookup,
Neale Ranns810086d2017-11-05 16:26:46 -0800215 is_udp_encap=path.is_udp_encap,
Neale Rannsf12a83f2017-04-18 09:09:40 -0700216 is_multipath=1 if len(self.paths) > 1 else 0)
Neale Ranns5a8123b2017-01-26 01:18:23 -0800217 self._test.registry.register(self, self._test.logger)
Neale Ranns177bbdc2016-11-15 09:46:51 +0000218
219 def remove_vpp_config(self):
Neale Ranns37be7362017-02-21 17:30:26 -0800220 if self.is_local or self.is_unreach or self.is_prohibit:
Neale Rannsfca0c242017-01-13 07:57:46 -0800221 self._test.vapi.ip_add_del_route(
222 self.dest_addr,
223 self.dest_addr_len,
Neale Rannsb3b2de72017-03-08 05:17:22 -0800224 inet_pton(AF_INET6, "::"),
Neale Rannsfca0c242017-01-13 07:57:46 -0800225 0xffffffff,
Neale Ranns37be7362017-02-21 17:30:26 -0800226 is_local=self.is_local,
227 is_unreach=self.is_unreach,
228 is_prohibit=self.is_prohibit,
Neale Rannsfca0c242017-01-13 07:57:46 -0800229 is_add=0,
230 table_id=self.table_id,
231 is_ipv6=self.is_ip6)
232 else:
233 for path in self.paths:
Neale Rannsf12a83f2017-04-18 09:09:40 -0700234 self._test.vapi.ip_add_del_route(
235 self.dest_addr,
236 self.dest_addr_len,
237 path.nh_addr,
238 path.nh_itf,
239 table_id=self.table_id,
240 next_hop_table_id=path.nh_table_id,
241 next_hop_via_label=path.nh_via_label,
Neale Ranns810086d2017-11-05 16:26:46 -0800242 next_hop_id=path.next_hop_id,
Neale Rannsf12a83f2017-04-18 09:09:40 -0700243 is_add=0,
Neale Ranns810086d2017-11-05 16:26:46 -0800244 is_udp_encap=path.is_udp_encap,
Neale Rannsf068c3e2018-01-03 04:18:48 -0800245 is_ipv6=self.is_ip6,
246 is_dvr=path.is_dvr)
Neale Rannsad422ed2016-11-02 14:20:04 +0000247
Neale Ranns5a8123b2017-01-26 01:18:23 -0800248 def query_vpp_config(self):
Neale Rannsb3b2de72017-03-08 05:17:22 -0800249 return find_route(self._test,
250 self.dest_addr_p,
251 self.dest_addr_len,
252 self.table_id,
253 inet=AF_INET6 if self.is_ip6 == 1 else AF_INET)
Neale Rannsad422ed2016-11-02 14:20:04 +0000254
Neale Ranns5a8123b2017-01-26 01:18:23 -0800255 def __str__(self):
256 return self.object_id()
257
258 def object_id(self):
Neale Rannsb3b2de72017-03-08 05:17:22 -0800259 return ("%d:%s/%d"
260 % (self.table_id,
261 self.dest_addr_p,
262 self.dest_addr_len))
Neale Ranns5a8123b2017-01-26 01:18:23 -0800263
264
265class VppIpMRoute(VppObject):
Neale Ranns32e1c012016-11-22 17:07:28 +0000266 """
267 IP Multicast Route
268 """
269
270 def __init__(self, test, src_addr, grp_addr,
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800271 grp_addr_len, e_flags, paths, table_id=0,
272 rpf_id=0, is_ip6=0):
Neale Ranns32e1c012016-11-22 17:07:28 +0000273 self._test = test
274 self.paths = paths
275 self.grp_addr_len = grp_addr_len
276 self.table_id = table_id
277 self.e_flags = e_flags
278 self.is_ip6 = is_ip6
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800279 self.rpf_id = rpf_id
Neale Ranns32e1c012016-11-22 17:07:28 +0000280
281 if is_ip6:
Neale Rannsb3b2de72017-03-08 05:17:22 -0800282 self.grp_addr = inet_pton(AF_INET6, grp_addr)
283 self.src_addr = inet_pton(AF_INET6, src_addr)
Neale Ranns32e1c012016-11-22 17:07:28 +0000284 else:
Neale Rannsb3b2de72017-03-08 05:17:22 -0800285 self.grp_addr = inet_pton(AF_INET, grp_addr)
286 self.src_addr = inet_pton(AF_INET, src_addr)
Neale Ranns32e1c012016-11-22 17:07:28 +0000287
288 def add_vpp_config(self):
289 for path in self.paths:
290 self._test.vapi.ip_mroute_add_del(self.src_addr,
291 self.grp_addr,
292 self.grp_addr_len,
293 self.e_flags,
Neale Rannsd792d9c2017-10-21 10:53:20 -0700294 path.proto,
Neale Ranns32e1c012016-11-22 17:07:28 +0000295 path.nh_itf,
296 path.nh_i_flags,
Neale Rannsd792d9c2017-10-21 10:53:20 -0700297 bier_imp=path.bier_imp,
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800298 rpf_id=self.rpf_id,
Neale Ranns32e1c012016-11-22 17:07:28 +0000299 table_id=self.table_id,
300 is_ipv6=self.is_ip6)
Neale Ranns5a8123b2017-01-26 01:18:23 -0800301 self._test.registry.register(self, self._test.logger)
Neale Ranns32e1c012016-11-22 17:07:28 +0000302
303 def remove_vpp_config(self):
304 for path in self.paths:
305 self._test.vapi.ip_mroute_add_del(self.src_addr,
306 self.grp_addr,
307 self.grp_addr_len,
308 self.e_flags,
Neale Rannsd792d9c2017-10-21 10:53:20 -0700309 path.proto,
Neale Ranns32e1c012016-11-22 17:07:28 +0000310 path.nh_itf,
311 path.nh_i_flags,
312 table_id=self.table_id,
Neale Rannseea537a2018-01-09 04:11:28 -0800313 bier_imp=path.bier_imp,
Neale Ranns32e1c012016-11-22 17:07:28 +0000314 is_add=0,
315 is_ipv6=self.is_ip6)
316
317 def update_entry_flags(self, flags):
318 self.e_flags = flags
319 self._test.vapi.ip_mroute_add_del(self.src_addr,
320 self.grp_addr,
321 self.grp_addr_len,
322 self.e_flags,
Neale Rannsd792d9c2017-10-21 10:53:20 -0700323 0,
Neale Ranns32e1c012016-11-22 17:07:28 +0000324 0xffffffff,
325 0,
326 table_id=self.table_id,
327 is_ipv6=self.is_ip6)
328
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800329 def update_rpf_id(self, rpf_id):
330 self.rpf_id = rpf_id
331 self._test.vapi.ip_mroute_add_del(self.src_addr,
332 self.grp_addr,
333 self.grp_addr_len,
334 self.e_flags,
Neale Rannsd792d9c2017-10-21 10:53:20 -0700335 0,
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800336 0xffffffff,
337 0,
338 rpf_id=self.rpf_id,
339 table_id=self.table_id,
340 is_ipv6=self.is_ip6)
341
Neale Ranns32e1c012016-11-22 17:07:28 +0000342 def update_path_flags(self, itf, flags):
343 for path in self.paths:
344 if path.nh_itf == itf:
345 path.nh_i_flags = flags
346 break
347 self._test.vapi.ip_mroute_add_del(self.src_addr,
348 self.grp_addr,
349 self.grp_addr_len,
350 self.e_flags,
Neale Rannsd792d9c2017-10-21 10:53:20 -0700351 path.proto,
Neale Ranns32e1c012016-11-22 17:07:28 +0000352 path.nh_itf,
353 path.nh_i_flags,
354 table_id=self.table_id,
355 is_ipv6=self.is_ip6)
356
Neale Ranns5a8123b2017-01-26 01:18:23 -0800357 def query_vpp_config(self):
Neale Rannsd792d9c2017-10-21 10:53:20 -0700358 if self.is_ip6:
359 dump = self._test.vapi.ip6_mfib_dump()
360 else:
361 dump = self._test.vapi.ip_mfib_dump()
Neale Ranns5a8123b2017-01-26 01:18:23 -0800362 for e in dump:
Neale Rannsd792d9c2017-10-21 10:53:20 -0700363 if self.grp_addr == e.grp_address \
Neale Ranns5a8123b2017-01-26 01:18:23 -0800364 and self.grp_addr_len == e.address_length \
Neale Rannsd792d9c2017-10-21 10:53:20 -0700365 and self.src_addr == e.src_address \
Neale Ranns5a8123b2017-01-26 01:18:23 -0800366 and self.table_id == e.table_id:
367 return True
368 return False
Neale Ranns32e1c012016-11-22 17:07:28 +0000369
Neale Ranns5a8123b2017-01-26 01:18:23 -0800370 def __str__(self):
371 return self.object_id()
372
373 def object_id(self):
374 if self.is_ip6:
375 return ("%d:(%s,%s/%d)"
376 % (self.table_id,
Neale Rannsb3b2de72017-03-08 05:17:22 -0800377 inet_ntop(AF_INET6, self.src_addr),
378 inet_ntop(AF_INET6, self.grp_addr),
Neale Ranns5a8123b2017-01-26 01:18:23 -0800379 self.grp_addr_len))
380 else:
381 return ("%d:(%s,%s/%d)"
382 % (self.table_id,
Neale Rannsb3b2de72017-03-08 05:17:22 -0800383 inet_ntop(AF_INET, self.src_addr),
384 inet_ntop(AF_INET, self.grp_addr),
Neale Ranns5a8123b2017-01-26 01:18:23 -0800385 self.grp_addr_len))
386
387
388class VppMFibSignal(object):
Neale Ranns32e1c012016-11-22 17:07:28 +0000389 def __init__(self, test, route, interface, packet):
390 self.route = route
391 self.interface = interface
392 self.packet = packet
393 self.test = test
394
395 def compare(self, signal):
396 self.test.assertEqual(self.interface, signal.sw_if_index)
397 self.test.assertEqual(self.route.table_id, signal.table_id)
398 self.test.assertEqual(self.route.grp_addr_len,
399 signal.grp_address_len)
400 for i in range(self.route.grp_addr_len / 8):
401 self.test.assertEqual(self.route.grp_addr[i],
402 signal.grp_address[i])
403 if (self.route.grp_addr_len > 32):
404 for i in range(4):
405 self.test.assertEqual(self.route.src_addr[i],
406 signal.src_address[i])
407
408
Neale Ranns5a8123b2017-01-26 01:18:23 -0800409class VppMplsIpBind(VppObject):
Neale Rannsad422ed2016-11-02 14:20:04 +0000410 """
411 MPLS to IP Binding
412 """
413
Neale Ranns5a8123b2017-01-26 01:18:23 -0800414 def __init__(self, test, local_label, dest_addr, dest_addr_len,
Neale Rannsf12a83f2017-04-18 09:09:40 -0700415 table_id=0, ip_table_id=0, is_ip6=0):
Neale Rannsad422ed2016-11-02 14:20:04 +0000416 self._test = test
Neale Rannsad422ed2016-11-02 14:20:04 +0000417 self.dest_addr_len = dest_addr_len
Neale Rannsf12a83f2017-04-18 09:09:40 -0700418 self.dest_addr = dest_addr
Neale Rannsad422ed2016-11-02 14:20:04 +0000419 self.local_label = local_label
Neale Ranns5a8123b2017-01-26 01:18:23 -0800420 self.table_id = table_id
421 self.ip_table_id = ip_table_id
Neale Rannsf12a83f2017-04-18 09:09:40 -0700422 self.is_ip6 = is_ip6
423 if is_ip6:
424 self.dest_addrn = inet_pton(AF_INET6, dest_addr)
425 else:
426 self.dest_addrn = inet_pton(AF_INET, dest_addr)
Neale Rannsad422ed2016-11-02 14:20:04 +0000427
428 def add_vpp_config(self):
429 self._test.vapi.mpls_ip_bind_unbind(self.local_label,
Neale Rannsf12a83f2017-04-18 09:09:40 -0700430 self.dest_addrn,
Neale Ranns5a8123b2017-01-26 01:18:23 -0800431 self.dest_addr_len,
432 table_id=self.table_id,
Neale Rannsf12a83f2017-04-18 09:09:40 -0700433 ip_table_id=self.ip_table_id,
434 is_ip4=(self.is_ip6 == 0))
Neale Ranns5a8123b2017-01-26 01:18:23 -0800435 self._test.registry.register(self, self._test.logger)
Neale Rannsad422ed2016-11-02 14:20:04 +0000436
437 def remove_vpp_config(self):
438 self._test.vapi.mpls_ip_bind_unbind(self.local_label,
Neale Rannsf12a83f2017-04-18 09:09:40 -0700439 self.dest_addrn,
Neale Rannsad422ed2016-11-02 14:20:04 +0000440 self.dest_addr_len,
Neale Rannsf12a83f2017-04-18 09:09:40 -0700441 table_id=self.table_id,
442 ip_table_id=self.ip_table_id,
443 is_bind=0,
444 is_ip4=(self.is_ip6 == 0))
Neale Rannsad422ed2016-11-02 14:20:04 +0000445
Neale Ranns5a8123b2017-01-26 01:18:23 -0800446 def query_vpp_config(self):
447 dump = self._test.vapi.mpls_fib_dump()
448 for e in dump:
449 if self.local_label == e.label \
Neale Ranns5a8123b2017-01-26 01:18:23 -0800450 and self.table_id == e.table_id:
451 return True
452 return False
Neale Rannsad422ed2016-11-02 14:20:04 +0000453
Neale Ranns5a8123b2017-01-26 01:18:23 -0800454 def __str__(self):
455 return self.object_id()
456
457 def object_id(self):
458 return ("%d:%s binds %d:%s/%d"
459 % (self.table_id,
460 self.local_label,
461 self.ip_table_id,
Neale Rannsf12a83f2017-04-18 09:09:40 -0700462 self.dest_addr,
Neale Ranns5a8123b2017-01-26 01:18:23 -0800463 self.dest_addr_len))
464
465
Neale Ranns15002542017-09-10 04:39:11 -0700466class VppMplsTable(VppObject):
467
468 def __init__(self,
469 test,
470 table_id):
471 self._test = test
472 self.table_id = table_id
473
474 def add_vpp_config(self):
475 self._test.vapi.mpls_table_add_del(
476 self.table_id,
477 is_add=1)
478 self._test.registry.register(self, self._test.logger)
479
480 def remove_vpp_config(self):
481 self._test.vapi.mpls_table_add_del(
482 self.table_id,
483 is_add=0)
484
485 def query_vpp_config(self):
486 # find the default route
487 dump = self._test.vapi.mpls_fib_dump()
488 if len(dump):
489 return True
490 return False
491
492 def __str__(self):
493 return self.object_id()
494
495 def object_id(self):
496 return ("table-mpls-%d" % (self.table_id))
497
498
Neale Ranns5a8123b2017-01-26 01:18:23 -0800499class VppMplsRoute(VppObject):
Neale Rannsad422ed2016-11-02 14:20:04 +0000500 """
Neale Ranns5a8123b2017-01-26 01:18:23 -0800501 MPLS Route/LSP
Neale Rannsad422ed2016-11-02 14:20:04 +0000502 """
503
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800504 def __init__(self, test, local_label, eos_bit, paths, table_id=0,
505 is_multicast=0):
Neale Rannsad422ed2016-11-02 14:20:04 +0000506 self._test = test
507 self.paths = paths
508 self.local_label = local_label
509 self.eos_bit = eos_bit
510 self.table_id = table_id
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800511 self.is_multicast = is_multicast
Neale Rannsad422ed2016-11-02 14:20:04 +0000512
513 def add_vpp_config(self):
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800514 is_multipath = len(self.paths) > 1
Neale Rannsad422ed2016-11-02 14:20:04 +0000515 for path in self.paths:
Klement Sekerada505f62017-01-04 12:58:53 +0100516 self._test.vapi.mpls_route_add_del(
517 self.local_label,
518 self.eos_bit,
Neale Rannsda78f952017-05-24 09:15:43 -0700519 path.proto,
Klement Sekerada505f62017-01-04 12:58:53 +0100520 path.nh_addr,
521 path.nh_itf,
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800522 is_multicast=self.is_multicast,
523 is_multipath=is_multipath,
Klement Sekerada505f62017-01-04 12:58:53 +0100524 table_id=self.table_id,
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800525 is_interface_rx=path.is_interface_rx,
526 is_rpf_id=path.is_rpf_id,
Klement Sekerada505f62017-01-04 12:58:53 +0100527 next_hop_out_label_stack=path.nh_labels,
528 next_hop_n_out_labels=len(
529 path.nh_labels),
530 next_hop_via_label=path.nh_via_label,
531 next_hop_table_id=path.nh_table_id)
Neale Ranns5a8123b2017-01-26 01:18:23 -0800532 self._test.registry.register(self, self._test.logger)
Neale Rannsad422ed2016-11-02 14:20:04 +0000533
534 def remove_vpp_config(self):
535 for path in self.paths:
536 self._test.vapi.mpls_route_add_del(self.local_label,
537 self.eos_bit,
Neale Rannsda78f952017-05-24 09:15:43 -0700538 path.proto,
Neale Rannsad422ed2016-11-02 14:20:04 +0000539 path.nh_addr,
540 path.nh_itf,
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800541 is_rpf_id=path.is_rpf_id,
Neale Rannsad422ed2016-11-02 14:20:04 +0000542 table_id=self.table_id,
543 is_add=0)
Neale Ranns5a8123b2017-01-26 01:18:23 -0800544
545 def query_vpp_config(self):
546 dump = self._test.vapi.mpls_fib_dump()
547 for e in dump:
548 if self.local_label == e.label \
549 and self.eos_bit == e.eos_bit \
550 and self.table_id == e.table_id:
551 return True
552 return False
553
554 def __str__(self):
555 return self.object_id()
556
557 def object_id(self):
558 return ("%d:%s/%d"
559 % (self.table_id,
560 self.local_label,
561 20+self.eos_bit))