1 # Copyright (c) 2016 Cisco and/or its affiliates.
2 # Licensed under the Apache License, Version 2.0 (the "License");
3 # you may not use this file except in compliance with the License.
4 # You may obtain a copy of the License at:
6 # http://www.apache.org/licenses/LICENSE-2.0
8 # Unless required by applicable law or agreed to in writing, software
9 # distributed under the License is distributed on an "AS IS" BASIS,
10 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 # See the License for the specific language governing permissions and
12 # limitations under the License.
14 """Library to set up Lisp in topology."""
16 from resources.libraries.python.topology import NodeType
17 from resources.libraries.python.VatExecutor import VatExecutor
20 class LispStatus(object):
21 """Class for lisp API."""
27 def vpp_lisp_enable_disable(node, state):
28 """Enable/Disable lisp in the VPP node in topology.
30 :param node: Node of the test topology.
31 :param state: State of the lisp, enable or disable.
36 VatExecutor.cmd_from_template(node,
37 'lisp/lisp_status.vat',
41 class LispRemoteMapping(object):
42 """Class for lisp remote mapping API."""
48 def vpp_add_lisp_remote_mapping(node, vni, deid, deid_prefix, seid,
49 seid_prefix, rloc, is_mac=False):
50 """Add lisp remote mapping on the VPP node in topology.
52 :param node: VPP node.
54 :param deid: Destination eid address.
55 :param deid_prefix: Destination eid address prefix_len.
56 :param seid: Source eid address.
57 :param seid_prefix: Source eid address prefix_len.
58 :param rloc: Receiver locator.
59 :param is_mac: Set to True if the deid/seid is MAC address.
63 :type deid_prefix: int
65 :type seid_prefix: int
73 deid_prefix = '/{}'.format(deid_prefix)
74 seid_prefix = '/{}'.format(seid_prefix)
75 VatExecutor.cmd_from_template(node,
76 'lisp/add_lisp_remote_mapping.vat',
79 deid_prefix=deid_prefix,
81 seid_prefix=seid_prefix,
85 def vpp_del_lisp_remote_mapping(node, vni, deid, deid_prefix, seid,
87 """Delete lisp remote mapping on the VPP node in topology.
89 :param node: VPP node.
91 :param deid: Destination eid address.
92 :param deid_prefix: Destination eid address prefix_len.
93 :param seid: Source eid address.
94 :param seid_prefix: Source eid address prefix_len.
95 :param rloc: Receiver locator.
99 :type deid_prefix: int
101 :type seid_prefix: int
105 VatExecutor.cmd_from_template(node,
106 'lisp/del_lisp_remote_mapping.vat',
109 deid_prefix=deid_prefix,
111 seid_prefix=seid_prefix,
115 class LispAdjacency(object):
116 """Class for lisp adjacency API."""
122 def vpp_add_lisp_adjacency(node, vni, deid, deid_prefix, seid,
123 seid_prefix, is_mac=False):
124 """Add lisp adjacency on the VPP node in topology.
126 :param node: VPP node.
128 :param deid: Destination eid address.
129 :param deid_prefix: Destination eid address prefix_len.
130 :param seid: Source eid address.
131 :param seid_prefix: Source eid address prefix_len.
132 :param is_mac: Set to True if the deid/seid is MAC address.
136 :type deid_prefix: int
138 :type seid_prefix: int
145 deid_prefix = '/{}'.format(deid_prefix)
146 seid_prefix = '/{}'.format(seid_prefix)
147 VatExecutor.cmd_from_template(node,
148 'lisp/add_lisp_adjacency.vat',
151 deid_prefix=deid_prefix,
153 seid_prefix=seid_prefix)
156 def vpp_del_lisp_adjacency(node, vni, deid, deid_prefix, seid,
158 """Delete lisp adjacency on the VPP node in topology.
160 :param node: VPP node.
162 :param deid: Destination eid address.
163 :param deid_prefix: Destination eid address prefix_len.
164 :param seid: Source eid address.
165 :param seid_prefix: Source eid address prefix_len.
169 :type deid_prefix: int
171 :type seid_prefix: int
174 VatExecutor.cmd_from_template(node,
175 'lisp/del_lisp_adjacency.vat',
178 deid_prefix=deid_prefix,
180 seid_prefix=seid_prefix)
183 class LispGpeStatus(object):
184 """Clas for LISP GPE status manipulation."""
190 def vpp_lisp_gpe_enable_disable(node, state):
191 """Change the state of LISP GPE - enable or disable.
193 :param node: VPP node.
194 :param state: Requested state - enable or disable.
199 VatExecutor.cmd_from_template(node, 'lisp/lisp_gpe_status.vat',
203 class LispGpeIface(object):
204 """Class for Lisp gpe interface API."""
210 def vpp_lisp_gpe_iface(node, state):
211 """Set lisp gpe interface up or down on the VPP node in topology.
213 :param node: VPP node.
214 :param state: State of the gpe iface, up or down.
219 VatExecutor.cmd_from_template(node, 'lisp/lisp_gpe_iface.vat',
223 class LispGpeForwardEntry(object):
224 """The functionality needed for these methods is not implemented in VPP
225 (VAT). Bug https://jira.fd.io/browse/VPP-334 was open to cover this issue.
227 TODO: Implement when VPP-334 is fixed.
234 def add_lisp_gpe_forward_entry(node, *args):
235 """Not implemented"""
236 # TODO: Implement when VPP-334 is fixed.
240 def del_lisp_gpe_forward_entry(node, *args):
241 """Not implemented"""
242 # TODO: Implement when VPP-334 is fixed.
246 class LispMapResolver(object):
247 """Class for Lisp map resolver API."""
253 def vpp_add_map_resolver(node, map_resolver_ip):
254 """Set lisp map resolver on the VPP node in topology.
256 :param node: VPP node.
257 :param map_resolver_ip: IP address of the map resolver.
259 :type map_resolver_ip: str
262 VatExecutor.cmd_from_template(node,
263 'lisp/add_lisp_map_resolver.vat',
264 address=map_resolver_ip)
267 def vpp_del_map_resolver(node, map_resolver_ip):
268 """Unset lisp map resolver on the VPP node in topology.
270 :param node: VPP node.
271 :param map_resolver_ip: IP address of the map resolver.
273 :type map_resolver_ip: str
276 VatExecutor.cmd_from_template(node,
277 'lisp/del_lisp_map_resolver.vat',
278 address=map_resolver_ip)
281 class LispLocalEid(object):
282 """Class for Lisp local eid API."""
288 def vpp_add_lisp_local_eid(node, locator_set_name, vni, eid,
290 """Set lisp eid address on the VPP node in topology.
292 :param node: VPP node.
293 :param locator_set_name: Name of the locator_set.
294 :param vni: vni value.
295 :param eid: Eid value.
296 :param prefix_len: prefix len if the eid is IP address.
298 :type locator_set_name: str
301 :type prefix_len: int
304 if prefix_len is not None:
305 VatExecutor.cmd_from_template(node,
306 'lisp/add_lisp_local_eid.vat',
309 eid_prefix=prefix_len,
310 locator_name=locator_set_name)
312 VatExecutor.cmd_from_template(node,
313 'lisp/add_lisp_local_eid_mac.vat',
316 locator_name=locator_set_name)
319 def vpp_del_lisp_local_eid(node, locator_set_name, vni, eid,
321 """Set lisp eid addres on the VPP node in topology.
323 :param node: VPP node.
324 :param locator_set_name: Name of the locator_set.
325 :param vni: vni value.
326 :param eid: Eid value.
327 :param prefix_len: prefix len if the eid is IP address.
329 :type locator_set_name: str
332 :type prefix_len: int
335 if prefix_len is not None:
336 VatExecutor.cmd_from_template(node,
337 'lisp/del_lisp_local_eid.vat',
340 eid_prefix=prefix_len,
341 locator_name=locator_set_name)
343 VatExecutor.cmd_from_template(node,
344 'lisp/del_lisp_local_eid_mac.vat',
347 locator_name=locator_set_name)
350 class LispLocator(object):
351 """Class for the Lisp Locator API."""
357 def vpp_add_lisp_locator(node, locator_name, sw_if_index, priority, weight):
358 """Set lisp locator on the VPP node in topology.
360 :param node: VPP node.
361 :param locator_name: Name of the locator_set.
362 :param sw_if_index: sw_if_index if the interface.
363 :param priority: priority of the locator.
364 :param weight: weight of the locator.
366 :type locator_name: str
367 :type sw_if_index: int
372 VatExecutor.cmd_from_template(node,
373 'lisp/add_lisp_locator.vat',
374 lisp_name=locator_name,
375 sw_if_index=sw_if_index,
380 def vpp_del_lisp_locator(node, locator_name, sw_if_index, priority, weight):
381 """Unset lisp locator on the VPP node in topology.
383 :param node: VPP node.
384 :param locator_name: Name of the locator_set.
385 :param sw_if_index: sw_if_index if the interface.
386 :param priority: priority of the locator.
387 :param weight: weight of the locator.
389 :type locator_name: str
390 :type sw_if_index: int
395 VatExecutor.cmd_from_template(node,
396 'lisp/del_lisp_locator.vat',
397 lisp_name=locator_name,
398 sw_if_index=sw_if_index,
403 class LispLocatorSet(object):
404 """Class for Lisp Locator Set API."""
410 def vpp_add_lisp_locator_set(node, name):
411 """Add lisp locator_set on VPP.
413 :param node: VPP node.
414 :param name: VPP locator name.
419 VatExecutor.cmd_from_template(node,
420 'lisp/add_lisp_locator_set.vat',
424 def vpp_del_lisp_locator_set(node, name):
425 """Del lisp locator_set on VPP.
427 :param node: VPP node.
428 :param name: VPP locator name.
433 VatExecutor.cmd_from_template(node,
434 'lisp/del_lisp_locator_set.vat',
438 class LispSetup(object):
439 """Lisp setup in topology."""
445 def vpp_set_lisp_locator_set(node, locator_set_list):
446 """Set lisp locator_sets on VPP node in topology.
448 :param node: VPP node.
449 :param locator_set_list: List of locator_set.
451 :type locator_set_list: list
454 if node['type'] != NodeType.DUT:
455 raise ValueError('Node is not DUT')
457 lisp_locator = LispLocator()
458 lisp_locator_set = LispLocatorSet()
459 for locator_set in locator_set_list:
460 locator_set_name = locator_set.get('locator-set')
461 locator_list = locator_set.get('locator')
462 lisp_locator_set.vpp_add_lisp_locator_set(node,
464 for locator in locator_list:
465 sw_if_index = locator.get('locator-index')
466 priority = locator.get('priority')
467 weight = locator.get('weight')
468 lisp_locator.vpp_add_lisp_locator(node,
475 def vpp_unset_lisp_locator_set(node, locator_set_list):
476 """Unset lisp locator_sets on VPP node in topology.
478 :param node: VPP node.
479 :param locator_set_list: List of locator_set.
481 :type locator_set_list: list
484 if node['type'] != NodeType.DUT:
485 raise ValueError('Lisp locator set, node is not DUT')
487 lisp_locator = LispLocator()
488 lisp_locator_set = LispLocatorSet()
489 for locator_set in locator_set_list:
490 locator_set_name = locator_set.get('locator-set')
491 locator_list = locator_set.get('locator')
492 for locator in locator_list:
493 sw_if_index = locator.get('locator-index')
494 priority = locator.get('priority')
495 weight = locator.get('weight')
496 lisp_locator.vpp_del_lisp_locator(node,
502 lisp_locator_set.vpp_del_lisp_locator_set(node,
506 def vpp_set_lisp_eid_table(node, eid_table):
507 """Set lisp eid tables on VPP node in topology.
509 :param node: VPP node.
510 :param eid_table: Dictionary containing information of eid_table.
512 :type eid_table: dict
515 if node['type'] != NodeType.DUT:
516 raise ValueError('Node is not DUT')
518 lisp_locator_set = LispLocatorSet()
519 lisp_eid = LispLocalEid()
520 for eid in eid_table:
522 eid_address = eid.get('eid')
523 eid_prefix_len = eid.get('eid-prefix-len')
524 locator_set_name = eid.get('locator-set')
525 lisp_locator_set.vpp_add_lisp_locator_set(node, locator_set_name)
526 lisp_eid.vpp_add_lisp_local_eid(node,
533 def vpp_unset_lisp_eid_table(node, eid_table):
534 """Unset lisp eid tables on VPP node in topology.
536 :param node: VPP node.
537 :param eid_table: Dictionary containing information of eid_table.
539 :type eid_table: dict
542 if node['type'] != NodeType.DUT:
543 raise ValueError('Node is not DUT')
545 locator_set_list = []
546 lisp_locator_set = LispLocatorSet()
547 lisp_eid = LispLocalEid()
548 for eid in eid_table:
550 eid_address = eid.get('eid')
551 eid_prefix_len = eid.get('eid-prefix-len')
552 locator_set_name = eid.get('locator-set')
553 if locator_set_name not in locator_set_list:
554 locator_set_list.append(locator_set_name)
556 lisp_eid.vpp_del_lisp_local_eid(node,
562 for locator_set_name in locator_set_list:
563 lisp_locator_set.vpp_del_lisp_locator_set(node, locator_set_name)
566 def vpp_set_lisp_map_resolver(node, map_resolver):
567 """Set lisp map resolvers on VPP node in topology.
569 :param node: VPP node.
570 :param map_resolver: Dictionary containing information of map resolver.
572 :type map_resolver: dict
575 lisp_map_res = LispMapResolver()
576 for map_ip in map_resolver:
577 lisp_map_res.vpp_add_map_resolver(node, map_ip.get('map resolver'))
580 def vpp_unset_lisp_map_resolver(node, map_resolver):
581 """Unset lisp map resolvers on VPP node in topology.
583 :param node: VPP node.
584 :param map_resolver: Dictionary containing information of map resolver.
586 :type map_resolver: dict
589 lisp_map_res = LispMapResolver()
590 for map_ip in map_resolver:
591 lisp_map_res.vpp_del_map_resolver(node, map_ip.get('map resolver'))
594 def vpp_lisp_gpe_interface_status(node, state):
595 """Set lisp gpe interface status on VPP node in topology.
597 :param node: VPP node.
598 :param state: State of the gpe iface, up or down
604 lgi.vpp_lisp_gpe_iface(node, state)
607 class LispEidTableMap(object):
609 Class for EID table map.
613 def vpp_lisp_eid_table_mapping(node, vni, bd_id=None, vrf=None):
615 Map LISP VNI to either bridge domain ID, or VRF ID.
617 :param node: VPP node.
618 :param vni: Lisp VNI.
619 :param bd_id: Bridge domain ID.
627 bd_or_vrf = 'bd_index {}'.format(bd_id)
629 bd_or_vrf = 'vrf {}'.format(vrf)
630 VatExecutor.cmd_from_template(node,
631 'lisp/lisp_eid_table_add_del_map.vat',