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,
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_predix: 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.
62 :type deid_prefix: int
64 :type seid_prefix: int
68 VatExecutor.cmd_from_template(node,
69 'lisp/add_lisp_remote_mapping.vat',
72 deid_prefix=deid_prefix,
74 seid_prefix=seid_prefix,
78 def vpp_del_lisp_remote_mapping(node, vni, deid, deid_prefix, seid,
80 """Delete lisp remote mapping on the VPP node in topology.
82 :param node: VPP node.
84 :param deid: Destination eid address.
85 :param deid_predix: Destination eid address prefix_len.
86 :param seid: Source eid address.
87 :param seid_prefix: Source eid address prefix_len.
88 :param rloc: Receiver locator.
92 :type deid_prefix: int
94 :type seid_prefix: int
98 VatExecutor.cmd_from_template(node,
99 'lisp/del_lisp_remote_mapping.vat',
102 deid_prefix=deid_prefix,
104 seid_prefix=seid_prefix,
108 class LispAdjacency(object):
109 """Class for lisp adjacency API."""
115 def vpp_add_lisp_adjacency(node, vni, deid, deid_prefix, seid,
117 """Add lisp adjacency on the VPP node in topology.
119 :param node: VPP node.
121 :param deid: Destination eid address.
122 :param deid_prefix: Destination eid address prefix_len.
123 :param seid: Source eid address.
124 :param seid_prefix: Source eid address prefix_len.
128 :type deid_prefix: int
130 :type seid_prefix: int
133 VatExecutor.cmd_from_template(node,
134 'lisp/add_lisp_adjacency.vat',
137 deid_prefix=deid_prefix,
139 seid_prefix=seid_prefix)
142 def vpp_del_lisp_adjacency(node, vni, deid, deid_prefix, seid,
144 """Delete lisp adjacency on the VPP node in topology.
146 :param node: VPP node.
148 :param deid: Destination eid address.
149 :param deid_prefix: Destination eid address prefix_len.
150 :param seid: Source eid address.
151 :param seid_prefix: Source eid address prefix_len.
155 :type deid_prefix: int
157 :type seid_prefix: int
160 VatExecutor.cmd_from_template(node,
161 'lisp/del_lisp_adjacency.vat',
164 deid_prefix=deid_prefix,
166 seid_prefix=seid_prefix)
169 class LispGpeStatus(object):
170 """Clas for LISP GPE status manipulation."""
176 def vpp_lisp_gpe_enable_disable(node, state):
177 """Change the state of LISP GPE - enable or disable.
179 :param node: VPP node.
180 :param state: Requested state - enable or disable.
185 VatExecutor.cmd_from_template(node, 'lisp/lisp_gpe_status.vat',
189 class LispGpeIface(object):
190 """Class for Lisp gpe interface API."""
196 def vpp_lisp_gpe_iface(node, state):
197 """Set lisp gpe interface up or down on the VPP node in topology.
199 :param node: VPP node.
200 :param state: State of the gpe iface, up or down.
205 VatExecutor.cmd_from_template(node, 'lisp/lisp_gpe_iface.vat',
209 class LispGpeForwardEntry(object):
210 """The functionality needed for these methods is not implemented in VPP
211 (VAT). Bug https://jira.fd.io/browse/VPP-334 was open to cover this issue.
213 TODO: Implement when VPP-334 is fixed.
220 def add_lisp_gpe_forward_entry(node, *args):
221 """Not implemented"""
222 # TODO: Implement when VPP-334 is fixed.
226 def del_lisp_gpe_forward_entry(node, *args):
227 """Not implemented"""
228 # TODO: Implement when VPP-334 is fixed.
232 class LispMapResolver(object):
233 """Class for Lisp map resolver API."""
239 def vpp_add_map_resolver(node, map_resolver_ip):
240 """Set lisp map resolver on the VPP node in topology.
242 :param node: VPP node.
243 :param map_resolver_ip: IP address of the map resolver.
245 :type map_resolver_ip: str
248 VatExecutor.cmd_from_template(node,
249 'lisp/add_lisp_map_resolver.vat',
250 address=map_resolver_ip)
253 def vpp_del_map_resolver(node, map_resolver_ip):
254 """Unset 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/del_lisp_map_resolver.vat',
264 address=map_resolver_ip)
267 class LispLocalEid(object):
268 """Class for Lisp local eid API."""
274 def vpp_add_lisp_local_eid(node, locator_set_name, vni, eid,
276 """Set lisp eid address on the VPP node in topology.
278 :param node: VPP node.
279 :param locator_set_name: Name of the locator_set.
280 :param vni: vni value.
281 :param eid: Eid value.
282 :param prefix_len: prefix len if the eid is IP address.
284 :type locator_set_name: str
287 :type prefix_len: int
290 if prefix_len is not None:
291 VatExecutor.cmd_from_template(node,
292 'lisp/add_lisp_local_eid.vat',
295 eid_prefix=prefix_len,
296 locator_name=locator_set_name)
298 VatExecutor.cmd_from_template(node,
299 'lisp/add_lisp_local_eid_mac.vat',
302 locator_name=locator_set_name)
305 def vpp_del_lisp_local_eid(node, locator_set_name, vni, eid,
307 """Set lisp eid addres on the VPP node in topology.
309 :param node: VPP node.
310 :param locator_set_name: Name of the locator_set.
311 :param vni: vni value.
312 :param eid: Eid value.
313 :param prefix_len: prefix len if the eid is IP address.
315 :type locator_set_name: str
318 :type prefix_len: int
321 if prefix_len is not None:
322 VatExecutor.cmd_from_template(node,
323 'lisp/del_lisp_local_eid.vat',
326 eid_prefix=prefix_len,
327 locator_name=locator_set_name)
329 VatExecutor.cmd_from_template(node,
330 'lisp/del_lisp_local_eid_mac.vat',
333 locator_name=locator_set_name)
336 class LispLocator(object):
337 """Class for the Lisp Locator API."""
343 def vpp_add_lisp_locator(node, locator_name, sw_if_index, priority, weight):
344 """Set lisp locator on the VPP node in topology.
346 :param node: VPP node.
347 :param locator_name: Name of the locator_set.
348 :param sw_if_index: sw_if_index if the interface.
349 :param priority: priority of the locator.
350 :param weight: weight of the locator.
352 :type locator_name: str
353 :type sw_if_index: int
358 VatExecutor.cmd_from_template(node,
359 'lisp/add_lisp_locator.vat',
360 lisp_name=locator_name,
361 sw_if_index=sw_if_index,
366 def vpp_del_lisp_locator(node, locator_name, sw_if_index, priority, weight):
367 """Unset lisp locator on the VPP node in topology.
369 :param node: VPP node.
370 :param locator_name: Name of the locator_set.
371 :param sw_if_index: sw_if_index if the interface.
372 :param priority: priority of the locator.
373 :param weight: weight of the locator.
375 :type locator_name: str
376 :type sw_if_index: int
381 VatExecutor.cmd_from_template(node,
382 'lisp/del_lisp_locator.vat',
383 lisp_name=locator_name,
384 sw_if_index=sw_if_index,
389 class LispLocatorSet(object):
390 """Class for Lisp Locator Set API."""
396 def vpp_add_lisp_locator_set(node, name):
397 """Add lisp locator_set on VPP.
399 :param node: VPP node.
400 :param name: VPP locator name.
405 VatExecutor.cmd_from_template(node,
406 'lisp/add_lisp_locator_set.vat',
410 def vpp_del_lisp_locator_set(node, name):
411 """Del lisp locator_set on VPP.
413 :param node: VPP node.
414 :param name: VPP locator name.
419 VatExecutor.cmd_from_template(node,
420 'lisp/del_lisp_locator_set.vat',
424 class LispSetup(object):
425 """Lisp setup in topology."""
431 def vpp_set_lisp_locator_set(node, locator_set_list):
432 """Set lisp locator_sets on VPP node in topology.
434 :param node: VPP node.
435 :param locator_set_list: List of locator_set.
437 :type locator_set_list: list
440 if node['type'] != NodeType.DUT:
441 raise ValueError('Node is not DUT')
443 lisp_locator = LispLocator()
444 lisp_locator_set = LispLocatorSet()
445 for locator_set in locator_set_list:
446 locator_set_name = locator_set.get('locator-set')
447 locator_list = locator_set.get('locator')
448 lisp_locator_set.vpp_add_lisp_locator_set(node,
450 for locator in locator_list:
451 sw_if_index = locator.get('locator-index')
452 priority = locator.get('priority')
453 weight = locator.get('weight')
454 lisp_locator.vpp_add_lisp_locator(node,
461 def vpp_unset_lisp_locator_set(node, locator_set_list):
462 """Unset lisp locator_sets on VPP node in topology.
464 :param node: VPP node.
465 :param locator_set_list: List of locator_set.
467 :type locator_set_list: list
470 if node['type'] != NodeType.DUT:
471 raise ValueError('Lisp locator set, node is not DUT')
473 lisp_locator = LispLocator()
474 lisp_locator_set = LispLocatorSet()
475 for locator_set in locator_set_list:
476 locator_set_name = locator_set.get('locator-set')
477 locator_list = locator_set.get('locator')
478 for locator in locator_list:
479 sw_if_index = locator.get('locator-index')
480 priority = locator.get('priority')
481 weight = locator.get('weight')
482 lisp_locator.vpp_del_lisp_locator(node,
488 lisp_locator_set.vpp_del_lisp_locator_set(node,
492 def vpp_set_lisp_eid_table(node, eid_table):
493 """Set lisp eid tables on VPP node in topology.
495 :param node: VPP node.
496 :param eid_table: Dictionary containing information of eid_table.
498 :type eid_table: dict
501 if node['type'] != NodeType.DUT:
502 raise ValueError('Node is not DUT')
504 lisp_locator_set = LispLocatorSet()
505 lisp_eid = LispLocalEid()
506 for eid in eid_table:
508 eid_address = eid.get('eid')
509 eid_prefix_len = eid.get('eid-prefix-len')
510 locator_set_name = eid.get('locator-set')
511 lisp_locator_set.vpp_add_lisp_locator_set(node, locator_set_name)
512 lisp_eid.vpp_add_lisp_local_eid(node,
519 def vpp_unset_lisp_eid_table(node, eid_table):
520 """Unset lisp eid tables on VPP node in topology.
522 :param node: VPP node.
523 :param eid_table: Dictionary containing information of eid_table.
525 :type eid_table: dict
528 if node['type'] != NodeType.DUT:
529 raise ValueError('Node is not DUT')
531 locator_set_list = []
532 lisp_locator_set = LispLocatorSet()
533 lisp_eid = LispLocalEid()
534 for eid in eid_table:
536 eid_address = eid.get('eid')
537 eid_prefix_len = eid.get('eid-prefix-len')
538 locator_set_name = eid.get('locator-set')
539 if locator_set_name not in locator_set_list:
540 locator_set_list.append(locator_set_name)
542 lisp_eid.vpp_del_lisp_local_eid(node,
548 for locator_set_name in locator_set_list:
549 lisp_locator_set.vpp_del_lisp_locator_set(node, locator_set_name)
552 def vpp_set_lisp_map_resolver(node, map_resolver):
553 """Set lisp map resolvers on VPP node in topology.
555 :param node: VPP node.
556 :param map_resolver: Dictionary containing information of map resolver.
558 :type map_resolver: dict
561 lisp_map_res = LispMapResolver()
562 for map_ip in map_resolver:
563 lisp_map_res.vpp_add_map_resolver(node, map_ip.get('map resolver'))
566 def vpp_unset_lisp_map_resolver(node, map_resolver):
567 """Unset 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_del_map_resolver(node, map_ip.get('map resolver'))
580 def vpp_lisp_gpe_interface_status(node, state):
581 """Set lisp gpe interface status on VPP node in topology.
583 :param node: VPP node.
584 :param state: State of the gpe iface, up or down
590 lgi.vpp_lisp_gpe_iface(node, state)