4 object abstractions for representing IP routes in VPP
8 from vpp_object import *
10 # from vnet/vnet/mpls/mpls_types.h
11 MPLS_IETF_MAX_LABEL = 0xfffff
12 MPLS_LABEL_INVALID = MPLS_IETF_MAX_LABEL + 1
15 class VppRoutePath(object):
23 nh_via_label=MPLS_LABEL_INVALID,
25 self.nh_itf = nh_sw_if_index
26 self.nh_table_id = nh_table_id
27 self.nh_via_label = nh_via_label
28 self.nh_labels = labels
30 self.nh_addr = socket.inet_pton(socket.AF_INET6, nh_addr)
32 self.nh_addr = socket.inet_pton(socket.AF_INET, nh_addr)
35 class VppMRoutePath(VppRoutePath):
37 def __init__(self, nh_sw_if_index, flags):
38 super(VppMRoutePath, self).__init__("0.0.0.0",
40 self.nh_i_flags = flags
43 class VppIpRoute(VppObject):
48 def __init__(self, test, dest_addr,
49 dest_addr_len, paths, table_id=0, is_ip6=0, is_local=0):
52 self.dest_addr_len = dest_addr_len
53 self.table_id = table_id
55 self.is_local = is_local
57 self.dest_addr = socket.inet_pton(socket.AF_INET6, dest_addr)
59 self.dest_addr = socket.inet_pton(socket.AF_INET, dest_addr)
61 def add_vpp_config(self):
63 self._test.vapi.ip_add_del_route(
66 socket.inet_pton(socket.AF_INET6, "::"),
69 table_id=self.table_id,
72 for path in self.paths:
73 self._test.vapi.ip_add_del_route(
78 table_id=self.table_id,
79 next_hop_out_label_stack=path.nh_labels,
80 next_hop_n_out_labels=len(
82 next_hop_via_label=path.nh_via_label,
84 self._test.registry.register(self, self._test.logger)
86 def remove_vpp_config(self):
88 self._test.vapi.ip_add_del_route(
91 socket.inet_pton(socket.AF_INET6, "::"),
95 table_id=self.table_id,
98 for path in self.paths:
99 self._test.vapi.ip_add_del_route(self.dest_addr,
103 table_id=self.table_id,
106 def query_vpp_config(self):
107 dump = self._test.vapi.ip_fib_dump()
109 if self.dest_addr == e.address \
110 and self.dest_addr_len == e.address_length \
111 and self.table_id == e.table_id:
116 return self.object_id()
121 socket.inet_ntop(socket.AF_INET, self.dest_addr),
125 class VppIpMRoute(VppObject):
130 def __init__(self, test, src_addr, grp_addr,
131 grp_addr_len, e_flags, paths, table_id=0, is_ip6=0):
134 self.grp_addr_len = grp_addr_len
135 self.table_id = table_id
136 self.e_flags = e_flags
140 self.grp_addr = socket.inet_pton(socket.AF_INET6, grp_addr)
141 self.src_addr = socket.inet_pton(socket.AF_INET6, src_addr)
143 self.grp_addr = socket.inet_pton(socket.AF_INET, grp_addr)
144 self.src_addr = socket.inet_pton(socket.AF_INET, src_addr)
146 def add_vpp_config(self):
147 for path in self.paths:
148 self._test.vapi.ip_mroute_add_del(self.src_addr,
154 table_id=self.table_id,
156 self._test.registry.register(self, self._test.logger)
158 def remove_vpp_config(self):
159 for path in self.paths:
160 self._test.vapi.ip_mroute_add_del(self.src_addr,
166 table_id=self.table_id,
170 def update_entry_flags(self, flags):
172 self._test.vapi.ip_mroute_add_del(self.src_addr,
178 table_id=self.table_id,
181 def update_path_flags(self, itf, flags):
182 for path in self.paths:
183 if path.nh_itf == itf:
184 path.nh_i_flags = flags
186 self._test.vapi.ip_mroute_add_del(self.src_addr,
192 table_id=self.table_id,
195 def query_vpp_config(self):
196 dump = self._test.vapi.ip_fib_dump()
198 if self.grp_addr == e.address \
199 and self.grp_addr_len == e.address_length \
200 and self.table_id == e.table_id:
205 return self.object_id()
209 return ("%d:(%s,%s/%d)"
211 socket.inet_ntop(socket.AF_INET6, self.src_addr),
212 socket.inet_ntop(socket.AF_INET6, self.grp_addr),
215 return ("%d:(%s,%s/%d)"
217 socket.inet_ntop(socket.AF_INET, self.src_addr),
218 socket.inet_ntop(socket.AF_INET, self.grp_addr),
222 class VppMFibSignal(object):
223 def __init__(self, test, route, interface, packet):
225 self.interface = interface
229 def compare(self, signal):
230 self.test.assertEqual(self.interface, signal.sw_if_index)
231 self.test.assertEqual(self.route.table_id, signal.table_id)
232 self.test.assertEqual(self.route.grp_addr_len,
233 signal.grp_address_len)
234 for i in range(self.route.grp_addr_len / 8):
235 self.test.assertEqual(self.route.grp_addr[i],
236 signal.grp_address[i])
237 if (self.route.grp_addr_len > 32):
239 self.test.assertEqual(self.route.src_addr[i],
240 signal.src_address[i])
243 class VppMplsIpBind(VppObject):
248 def __init__(self, test, local_label, dest_addr, dest_addr_len,
249 table_id=0, ip_table_id=0):
251 self.dest_addr = socket.inet_pton(socket.AF_INET, dest_addr)
252 self.dest_addr_len = dest_addr_len
253 self.local_label = local_label
254 self.table_id = table_id
255 self.ip_table_id = ip_table_id
257 def add_vpp_config(self):
258 self._test.vapi.mpls_ip_bind_unbind(self.local_label,
261 table_id=self.table_id,
262 ip_table_id=self.ip_table_id)
263 self._test.registry.register(self, self._test.logger)
265 def remove_vpp_config(self):
266 self._test.vapi.mpls_ip_bind_unbind(self.local_label,
271 def query_vpp_config(self):
272 dump = self._test.vapi.mpls_fib_dump()
274 if self.local_label == e.label \
275 and self.eos_bit == e.eos_bit \
276 and self.table_id == e.table_id:
281 return self.object_id()
284 return ("%d:%s binds %d:%s/%d"
288 socket.inet_ntop(socket.AF_INET, self.dest_addr),
292 class VppMplsRoute(VppObject):
297 def __init__(self, test, local_label, eos_bit, paths, table_id=0):
300 self.local_label = local_label
301 self.eos_bit = eos_bit
302 self.table_id = table_id
304 def add_vpp_config(self):
305 for path in self.paths:
306 self._test.vapi.mpls_route_add_del(
312 table_id=self.table_id,
313 next_hop_out_label_stack=path.nh_labels,
314 next_hop_n_out_labels=len(
316 next_hop_via_label=path.nh_via_label,
317 next_hop_table_id=path.nh_table_id)
318 self._test.registry.register(self, self._test.logger)
320 def remove_vpp_config(self):
321 for path in self.paths:
322 self._test.vapi.mpls_route_add_del(self.local_label,
327 table_id=self.table_id,
330 def query_vpp_config(self):
331 dump = self._test.vapi.mpls_fib_dump()
333 if self.local_label == e.label \
334 and self.eos_bit == e.eos_bit \
335 and self.table_id == e.table_id:
340 return self.object_id()