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_predix=deid_prefix,
104 seid_prefix=seid_prefix,
106 class LispAdjacency(object):
107 """Class for lisp adjacency API."""
113 def vpp_add_lisp_adjacency(node, vni, deid, deid_prefix, seid,
115 """Add lisp adjacency on the VPP node in topology.
117 :param node: VPP node.
119 :param deid: Destination eid address.
120 :param deid_predix: Destination eid address prefix_len.
121 :param seid: Source eid address.
122 :param seid_prefix: Source eid address prefix_len.
126 :type deid_prefix: int
128 :type seid_prefix: int
131 VatExecutor.cmd_from_template(node,
132 'lisp/add_lisp_adjacency.vat',
135 deid_prefix=deid_prefix,
137 seid_prefix=seid_prefix)
140 def vpp_del_lisp_adjacency(node, vni, deid, deid_prefix, seid,
142 """Delete lisp adjacency on the VPP node in topology.
144 :param node: VPP node.
146 :param deid: Destination eid address.
147 :param deid_predix: Destination eid address prefix_len.
148 :param seid: Source eid address.
149 :param seid_prefix: Source eid address prefix_len.
153 :type deid_prefix: int
155 :type seid_prefix: int
158 VatExecutor.cmd_from_template(node,
159 'lisp/del_lisp_adjacency.vat',
162 deid_predix=deid_prefix,
164 seid_prefix=seid_prefix)
167 class LispGpeIface(object):
168 """Class for Lisp gpe interface API."""
174 def vpp_lisp_gpe_iface(node, state):
175 """Set lisp gpe interface up or down on the VPP node in topology.
177 :param node: VPP node.
178 :param state: State of the gpe iface, up or down.
183 VatExecutor.cmd_from_template(node,
184 'lisp/lisp_gpe_iface.vat',
188 class LispMapResolver(object):
189 """Class for Lisp map resolver API."""
195 def vpp_add_map_resolver(node, map_resolver_ip):
196 """Set lisp map resolver on the VPP node in topology.
198 :param node: VPP node.
199 :param map_resolver_ip: IP address of the map resolver.
201 :type map_resolver_ip: str
204 VatExecutor.cmd_from_template(node,
205 'lisp/add_lisp_map_resolver.vat',
206 address=map_resolver_ip)
209 def vpp_del_map_resolver(node, map_resolver_ip):
210 """Unset lisp map resolver on the VPP node in topology.
212 :param node: VPP node.
213 :param map_resolver_ip: IP address of the map resolver.
215 :type map_resolver_ip: str
218 VatExecutor.cmd_from_template(node,
219 'lisp/del_lisp_map_resolver.vat',
220 address=map_resolver_ip)
223 class LispLocalEid(object):
224 """Class for Lisp local eid API."""
230 def vpp_add_lisp_local_eid(node, locator_set_name, vni, eid,
232 """Set lisp eid address on the VPP node in topology.
234 :param node: VPP node.
235 :param locator_set_name: Name of the locator_set.
236 :param vni: vni value.
237 :param eid: Eid value.
238 :param prefix_len: prefix len if the eid is IP address.
240 :type locator_set_name: str
243 :type prefix_len: int
246 if prefix_len is not None:
247 VatExecutor.cmd_from_template(node,
248 'lisp/add_lisp_local_eid.vat',
251 eid_prefix=prefix_len,
252 locator_name=locator_set_name)
254 VatExecutor.cmd_from_template(node,
255 'lisp/add_lisp_local_eid_mac.vat',
258 locator_name=locator_set_name)
261 def vpp_del_lisp_local_eid(node, locator_set_name, vni, eid,
263 """Set lisp eid addres on the VPP node in topology.
265 :param node: VPP node.
266 :param locator_set_name: Name of the locator_set.
267 :param vni: vni value.
268 :param eid: Eid value.
269 :param prefix_len: prefix len if the eid is IP address.
271 :type locator_set_name: str
274 :type prefix_len: int
277 if prefix_len is not None:
278 VatExecutor.cmd_from_template(node,
279 'lisp/del_lisp_local_eid.vat',
282 eid_prefix=prefix_len,
283 locator_name=locator_set_name)
285 VatExecutor.cmd_from_template(node,
286 'lisp/del_lisp_local_eid_mac.vat',
289 locator_name=locator_set_name)
292 class LispLocator(object):
293 """Class for the Lisp Locator API."""
299 def vpp_add_lisp_locator(node, locator_name, sw_if_index, priority, weight):
300 """Set lisp locator on the VPP node in topology.
302 :param node: VPP node.
303 :param locator_name: Name of the locator_set.
304 :param sw_if_index: sw_if_index if the interface.
305 :param priority: priority of the locator.
306 :param weight: weight of the locator.
308 :type locator_name: str
309 :type sw_if_index: int
314 VatExecutor.cmd_from_template(node,
315 'lisp/add_lisp_locator.vat',
316 lisp_name=locator_name,
317 sw_if_index=sw_if_index,
322 def vpp_del_lisp_locator(node, locator_name, sw_if_index, priority, weight):
323 """Unset lisp locator on the VPP node in topology.
325 :param node: VPP node.
326 :param locator_name: Name of the locator_set.
327 :param sw_if_index: sw_if_index if the interface.
328 :param priority: priority of the locator.
329 :param weight: weight of the locator.
331 :type locator_name: str
332 :type sw_if_index: int
337 VatExecutor.cmd_from_template(node,
338 'lisp/del_lisp_locator.vat',
339 lisp_name=locator_name,
340 sw_if_index=sw_if_index,
345 class LispLocatorSet(object):
346 """Class for Lisp Locator Set API."""
352 def vpp_add_lisp_locator_set(node, name):
353 """Add lisp locator_set on VPP.
355 :param node: VPP node.
356 :param name: VPP locator name.
361 VatExecutor.cmd_from_template(node,
362 'lisp/add_lisp_locator_set.vat',
366 def vpp_del_lisp_locator_set(node, name):
367 """Del lisp locator_set on VPP.
369 :param node: VPP node.
370 :param name: VPP locator name.
375 VatExecutor.cmd_from_template(node,
376 'lisp/del_lisp_locator_set.vat',
380 class LispSetup(object):
381 """Lisp setup in topology."""
387 def vpp_set_lisp_locator_set(node, locator_set_list):
388 """Set lisp locator_sets on VPP node in topology.
390 :param node: VPP node.
391 :param locator_set_list: List of locator_set.
393 :type locator_set_list: list
396 if node['type'] != NodeType.DUT:
397 raise ValueError('Node is not DUT')
399 lisp_locator = LispLocator()
400 lisp_locator_set = LispLocatorSet()
401 for locator_set in locator_set_list:
402 locator_set_name = locator_set.get('locator-set')
403 locator_list = locator_set.get('locator')
404 lisp_locator_set.vpp_add_lisp_locator_set(node,
406 for locator in locator_list:
407 sw_if_index = locator.get('locator-index')
408 priority = locator.get('priority')
409 weight = locator.get('weight')
410 lisp_locator.vpp_add_lisp_locator(node,
417 def vpp_unset_lisp_locator_set(node, locator_set_list):
418 """Unset lisp locator_sets on VPP node in topology.
420 :param node: VPP node.
421 :param locator_set_list: List of locator_set.
423 :type locator_set_list: list
426 if node['type'] != NodeType.DUT:
427 raise ValueError('Lisp locator set, node is not DUT')
429 lisp_locator = LispLocator()
430 lisp_locator_set = LispLocatorSet()
431 for locator_set in locator_set_list:
432 locator_set_name = locator_set.get('locator-set')
433 locator_list = locator_set.get('locator')
434 for locator in locator_list:
435 sw_if_index = locator.get('locator-index')
436 priority = locator.get('priority')
437 weight = locator.get('weight')
438 lisp_locator.vpp_del_lisp_locator(node,
444 lisp_locator_set.vpp_del_lisp_locator_set(node,
448 def vpp_set_lisp_eid_table(node, eid_table):
449 """Set lisp eid tables on VPP node in topology.
451 :param node: VPP node.
452 :param eid_table: Dictionary containing information of eid_table.
454 :type eid_table: dict
457 if node['type'] != NodeType.DUT:
458 raise ValueError('Node is not DUT')
460 lisp_locator_set = LispLocatorSet()
461 lisp_eid = LispLocalEid()
462 for eid in eid_table:
464 eid_address = eid.get('eid')
465 eid_prefix_len = eid.get('eid-prefix-len')
466 locator_set_name = eid.get('locator-set')
467 lisp_locator_set.vpp_add_lisp_locator_set(node, locator_set_name)
468 lisp_eid.vpp_add_lisp_local_eid(node,
475 def vpp_unset_lisp_eid_table(node, eid_table):
476 """Unset lisp eid tables on VPP node in topology.
478 :param node: VPP node.
479 :param eid_table: Dictionary containing information of eid_table.
481 :type eid_table: dict
484 if node['type'] != NodeType.DUT:
485 raise ValueError('Node is not DUT')
487 locator_set_list = []
488 lisp_locator_set = LispLocatorSet()
489 lisp_eid = LispLocalEid()
490 for eid in eid_table:
492 eid_address = eid.get('eid')
493 eid_prefix_len = eid.get('eid-prefix-len')
494 locator_set_name = eid.get('locator-set')
495 if locator_set_name not in locator_set_list:
496 locator_set_list.append(locator_set_name)
498 lisp_eid.vpp_del_lisp_local_eid(node,
504 for locator_set_name in locator_set_list:
505 lisp_locator_set.vpp_del_lisp_locator_set(node, locator_set_name)
508 def vpp_set_lisp_map_resolver(node, map_resolver):
509 """Set lisp map resolvers on VPP node in topology.
511 :param node: VPP node.
512 :param map_resolver: Dictionary containing information of map resolver.
514 :type map_resolver: dict
517 lisp_map_res = LispMapResolver()
518 for map_ip in map_resolver:
519 lisp_map_res.vpp_add_map_resolver(node, map_ip.get('map resolver'))
522 def vpp_unset_lisp_map_resolver(node, map_resolver):
523 """Unset lisp map resolvers on VPP node in topology.
525 :param node: VPP node.
526 :param map_resolver: Dictionary containing information of map resolver.
528 :type map_resolver: dict
531 lisp_map_res = LispMapResolver()
532 for map_ip in map_resolver:
533 lisp_map_res.vpp_del_map_resolver(node, map_ip.get('map resolver'))
536 def vpp_lisp_gpe_interface_status(node, state):
537 """Set lisp gpe interface status on VPP node in topology.
539 :param node: VPP node.
540 :param state: State of the gpe iface, up or down
546 lgi.vpp_lisp_gpe_iface(node, state)