2 from ipaddress import ip_network
4 from vpp_object import VppObject
7 class VppLispLocatorSet(VppObject):
8 """Represents LISP locator set in VPP"""
10 def __init__(self, test, ls_name):
12 self._ls_name = ls_name
22 def add_vpp_config(self):
23 self.test.vapi.lisp_add_del_locator_set(locator_set_name=self._ls_name)
24 self._test.registry.register(self, self.test.logger)
26 def get_lisp_locator_sets_dump_entry(self):
27 result = self.test.vapi.lisp_locator_set_dump()
29 if ls.ls_name.strip("\x00") == self._ls_name:
33 def query_vpp_config(self):
34 return self.get_lisp_locator_sets_dump_entry() is not None
36 def remove_vpp_config(self):
37 self.test.vapi.lisp_add_del_locator_set(
38 locator_set_name=self._ls_name, is_add=0
42 return "lisp-locator-set-%s" % self._ls_name
45 class VppLispLocator(VppObject):
46 """Represents LISP locator in VPP"""
48 def __init__(self, test, sw_if_index, ls_name, priority=1, weight=1):
50 self._sw_if_index = sw_if_index
51 self._ls_name = ls_name
52 self._priority = priority
57 """Test which created this locator"""
62 """Locator set name"""
66 def sw_if_index(self):
67 return self._sw_if_index
77 def add_vpp_config(self):
78 self.test.vapi.lisp_add_del_locator(
79 locator_set_name=self._ls_name,
80 sw_if_index=self._sw_if_index,
81 priority=self._priority,
84 self._test.registry.register(self, self.test.logger)
86 def get_lisp_locator_dump_entry(self):
87 locators = self.test.vapi.lisp_locator_dump(
88 is_index_set=0, ls_name=self._ls_name
90 for locator in locators:
91 if locator.sw_if_index == self._sw_if_index:
95 def query_vpp_config(self):
96 locator = self.get_lisp_locator_dump_entry()
97 return locator is not None
99 def remove_vpp_config(self):
100 self.test.vapi.lisp_add_del_locator(
101 locator_set_name=self._ls_name,
102 sw_if_index=self._sw_if_index,
103 priority=self._priority,
107 self._test.registry.register(self, self.test.logger)
110 return "lisp-locator-%s-%d" % (self._ls_name, self._sw_if_index)
126 """Lisp endpoint identifier"""
128 def __init__(self, eid):
132 # find out whether EID is ip prefix, or MAC
134 self.prefix = ip_network(self.eid)
135 self._type = LispEIDType.PREFIX
138 if self.eid.count(":") == 5: # MAC address
140 self._type = LispEIDType.MAC
142 raise Exception("Unsupported EID format {!s}!".format(eid))
150 if self.eid_type == LispEIDType.PREFIX:
152 elif self.eid_type == LispEIDType.MAC:
154 elif self.eid_type == LispEIDType.NSH:
155 return Exception("Unimplemented")
159 if self.eid_type == LispEIDType.PREFIX:
160 return {"type": self._type, "address": {"prefix": self.prefix}}
161 elif self.eid_type == LispEIDType.MAC:
162 return {"type": self._type, "address": {"mac": self.mac}}
163 elif self.eid_type == LispEIDType.NSH:
164 return Exception("Unimplemented")
170 def __init__(self, key_type, key):
171 self._key_type = key_type
176 return {"id": self._key_type, "key": self._key}
179 class VppLispMapping(VppObject):
180 """Represents common features for remote and local LISP mapping in VPP"""
182 def __init__(self, test, eid, vni=0, priority=1, weight=1):
183 self._eid = LispEID(eid)
185 self._priority = priority
186 self._weight = weight
203 return self._priority
209 def get_lisp_mapping_dump_entry(self):
210 return self.test.vapi.lisp_eid_table_dump(
211 eid_set=1, vni=self._vni, eid=self._eid.packed
214 def query_vpp_config(self):
215 mapping = self.get_lisp_mapping_dump_entry()
219 return "lisp-mapping-[%s]-%s-%s-%s" % (
227 class VppLocalMapping(VppLispMapping):
228 """LISP Local mapping"""
238 key_id=LispKeyIdType.NONE,
241 super(VppLocalMapping, self).__init__(test, eid, vni, priority, weight)
242 self._ls_name = ls_name
243 self._key = LispKey(key_id, key)
257 def add_vpp_config(self):
258 self.test.vapi.lisp_add_del_local_eid(
259 locator_set_name=self._ls_name,
260 eid=self._eid.packed,
262 key=self._key.packed,
264 self._test.registry.register(self, self.test.logger)
266 def remove_vpp_config(self):
267 self.test.vapi.lisp_add_del_local_eid(
268 locator_set_name=self._ls_name,
269 eid=self._eid.packed,
275 return "lisp-eid-local-mapping-%s[%d]" % (self._eid.address, self._vni)
278 class LispRemoteLocator:
279 def __init__(self, addr, priority=1, weight=1):
281 self.priority = priority
287 "priority": self.priority,
288 "weight": self.weight,
289 "ip_address": self.addr,
293 class VppRemoteMapping(VppLispMapping):
294 def __init__(self, test, eid, rlocs=None, vni=0, priority=1, weight=1):
295 super(VppRemoteMapping, self).__init__(test, eid, vni, priority, weight)
301 for rloc in self._rlocs:
302 rlocs.append(rloc.packed)
305 def add_vpp_config(self):
306 self.test.vapi.lisp_add_del_remote_mapping(
308 deid=self._eid.packed,
310 rloc_num=len(self._rlocs),
312 self._test.registry.register(self, self.test.logger)
314 def remove_vpp_config(self):
315 self.test.vapi.lisp_add_del_remote_mapping(
316 deid=self._eid.packed, vni=self._vni, is_add=0, rloc_num=0
320 return "lisp-eid-remote-mapping-%s[%d]" % (self._eid.address, self._vni)
323 class VppLispAdjacency(VppObject):
324 """Represents LISP adjacency in VPP"""
326 def __init__(self, test, leid, reid, vni=0):
327 self._leid = LispEID(leid)
328 self._reid = LispEID(reid)
329 if self._leid.eid_type != self._reid.eid_type:
330 raise Exception("remote and local EID are different types!")
350 def add_vpp_config(self):
351 self.test.vapi.lisp_add_del_adjacency(
352 leid=self._leid.packed, reid=self._reid.packed, vni=self._vni
354 self._test.registry.register(self, self.test.logger)
357 def eid_equal(eid, eid_api):
358 if eid.eid_type != eid_api.type:
361 if eid_api.type == LispEIDType.PREFIX:
362 if eid.address.prefixlen != eid_api.address.prefix.prefixlen:
365 if eid.address != eid_api.address:
370 def query_vpp_config(self):
371 res = self.test.vapi.lisp_adjacencies_get(vni=self._vni)
372 for adj in res.adjacencies:
373 if self.eid_equal(self._leid, adj.leid) and self.eid_equal(
379 def remove_vpp_config(self):
380 self.test.vapi.lisp_add_del_adjacency(
381 leid=self._leid.packed, reid=self._reid.packed, vni=self._vni, is_add=0
385 return "lisp-adjacency-%s-%s[%d]" % (self._leid, self._reid, self._vni)