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,
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_prefix=deid_prefix,
164 seid_prefix=seid_prefix)
167 class LispGpeStatus(object):
168 """Clas for LISP GPE status manipulation."""
174 def vpp_lisp_gpe_enable_disable(node, state):
175 """Change the state of LISP GPE - enable or disable.
177 :param node: VPP node.
178 :param state: Requested state - enable or disable.
183 VatExecutor.cmd_from_template(node, 'lisp/lisp_gpe_status.vat',
187 class LispGpeIface(object):
188 """Class for Lisp gpe interface API."""
194 def vpp_lisp_gpe_iface(node, state):
195 """Set lisp gpe interface up or down on the VPP node in topology.
197 :param node: VPP node.
198 :param state: State of the gpe iface, up or down.
203 VatExecutor.cmd_from_template(node, 'lisp/lisp_gpe_iface.vat',
207 class LispGpeForwardEntry(object):
208 """The functionality needed for these methods is not implemented in VPP
209 (VAT). Bug https://jira.fd.io/browse/VPP-334 was open to cover this issue.
211 TODO: Implement when VPP-334 is fixed.
218 def add_lisp_gpe_forward_entry(node, *args):
219 # TODO: Implement when VPP-334 is fixed.
223 def del_lisp_gpe_forward_entry(node, *args):
224 # TODO: Implement when VPP-334 is fixed.
228 class LispMapResolver(object):
229 """Class for Lisp map resolver API."""
235 def vpp_add_map_resolver(node, map_resolver_ip):
236 """Set lisp map resolver on the VPP node in topology.
238 :param node: VPP node.
239 :param map_resolver_ip: IP address of the map resolver.
241 :type map_resolver_ip: str
244 VatExecutor.cmd_from_template(node,
245 'lisp/add_lisp_map_resolver.vat',
246 address=map_resolver_ip)
249 def vpp_del_map_resolver(node, map_resolver_ip):
250 """Unset lisp map resolver on the VPP node in topology.
252 :param node: VPP node.
253 :param map_resolver_ip: IP address of the map resolver.
255 :type map_resolver_ip: str
258 VatExecutor.cmd_from_template(node,
259 'lisp/del_lisp_map_resolver.vat',
260 address=map_resolver_ip)
263 class LispLocalEid(object):
264 """Class for Lisp local eid API."""
270 def vpp_add_lisp_local_eid(node, locator_set_name, vni, eid,
272 """Set lisp eid address on the VPP node in topology.
274 :param node: VPP node.
275 :param locator_set_name: Name of the locator_set.
276 :param vni: vni value.
277 :param eid: Eid value.
278 :param prefix_len: prefix len if the eid is IP address.
280 :type locator_set_name: str
283 :type prefix_len: int
286 if prefix_len is not None:
287 VatExecutor.cmd_from_template(node,
288 'lisp/add_lisp_local_eid.vat',
291 eid_prefix=prefix_len,
292 locator_name=locator_set_name)
294 VatExecutor.cmd_from_template(node,
295 'lisp/add_lisp_local_eid_mac.vat',
298 locator_name=locator_set_name)
301 def vpp_del_lisp_local_eid(node, locator_set_name, vni, eid,
303 """Set lisp eid addres on the VPP node in topology.
305 :param node: VPP node.
306 :param locator_set_name: Name of the locator_set.
307 :param vni: vni value.
308 :param eid: Eid value.
309 :param prefix_len: prefix len if the eid is IP address.
311 :type locator_set_name: str
314 :type prefix_len: int
317 if prefix_len is not None:
318 VatExecutor.cmd_from_template(node,
319 'lisp/del_lisp_local_eid.vat',
322 eid_prefix=prefix_len,
323 locator_name=locator_set_name)
325 VatExecutor.cmd_from_template(node,
326 'lisp/del_lisp_local_eid_mac.vat',
329 locator_name=locator_set_name)
332 class LispLocator(object):
333 """Class for the Lisp Locator API."""
339 def vpp_add_lisp_locator(node, locator_name, sw_if_index, priority, weight):
340 """Set lisp locator on the VPP node in topology.
342 :param node: VPP node.
343 :param locator_name: Name of the locator_set.
344 :param sw_if_index: sw_if_index if the interface.
345 :param priority: priority of the locator.
346 :param weight: weight of the locator.
348 :type locator_name: str
349 :type sw_if_index: int
354 VatExecutor.cmd_from_template(node,
355 'lisp/add_lisp_locator.vat',
356 lisp_name=locator_name,
357 sw_if_index=sw_if_index,
362 def vpp_del_lisp_locator(node, locator_name, sw_if_index, priority, weight):
363 """Unset lisp locator on the VPP node in topology.
365 :param node: VPP node.
366 :param locator_name: Name of the locator_set.
367 :param sw_if_index: sw_if_index if the interface.
368 :param priority: priority of the locator.
369 :param weight: weight of the locator.
371 :type locator_name: str
372 :type sw_if_index: int
377 VatExecutor.cmd_from_template(node,
378 'lisp/del_lisp_locator.vat',
379 lisp_name=locator_name,
380 sw_if_index=sw_if_index,
385 class LispLocatorSet(object):
386 """Class for Lisp Locator Set API."""
392 def vpp_add_lisp_locator_set(node, name):
393 """Add lisp locator_set on VPP.
395 :param node: VPP node.
396 :param name: VPP locator name.
401 VatExecutor.cmd_from_template(node,
402 'lisp/add_lisp_locator_set.vat',
406 def vpp_del_lisp_locator_set(node, name):
407 """Del lisp locator_set on VPP.
409 :param node: VPP node.
410 :param name: VPP locator name.
415 VatExecutor.cmd_from_template(node,
416 'lisp/del_lisp_locator_set.vat',
420 class LispSetup(object):
421 """Lisp setup in topology."""
427 def vpp_set_lisp_locator_set(node, locator_set_list):
428 """Set lisp locator_sets on VPP node in topology.
430 :param node: VPP node.
431 :param locator_set_list: List of locator_set.
433 :type locator_set_list: list
436 if node['type'] != NodeType.DUT:
437 raise ValueError('Node is not DUT')
439 lisp_locator = LispLocator()
440 lisp_locator_set = LispLocatorSet()
441 for locator_set in locator_set_list:
442 locator_set_name = locator_set.get('locator-set')
443 locator_list = locator_set.get('locator')
444 lisp_locator_set.vpp_add_lisp_locator_set(node,
446 for locator in locator_list:
447 sw_if_index = locator.get('locator-index')
448 priority = locator.get('priority')
449 weight = locator.get('weight')
450 lisp_locator.vpp_add_lisp_locator(node,
457 def vpp_unset_lisp_locator_set(node, locator_set_list):
458 """Unset lisp locator_sets on VPP node in topology.
460 :param node: VPP node.
461 :param locator_set_list: List of locator_set.
463 :type locator_set_list: list
466 if node['type'] != NodeType.DUT:
467 raise ValueError('Lisp locator set, node is not DUT')
469 lisp_locator = LispLocator()
470 lisp_locator_set = LispLocatorSet()
471 for locator_set in locator_set_list:
472 locator_set_name = locator_set.get('locator-set')
473 locator_list = locator_set.get('locator')
474 for locator in locator_list:
475 sw_if_index = locator.get('locator-index')
476 priority = locator.get('priority')
477 weight = locator.get('weight')
478 lisp_locator.vpp_del_lisp_locator(node,
484 lisp_locator_set.vpp_del_lisp_locator_set(node,
488 def vpp_set_lisp_eid_table(node, eid_table):
489 """Set lisp eid tables on VPP node in topology.
491 :param node: VPP node.
492 :param eid_table: Dictionary containing information of eid_table.
494 :type eid_table: dict
497 if node['type'] != NodeType.DUT:
498 raise ValueError('Node is not DUT')
500 lisp_locator_set = LispLocatorSet()
501 lisp_eid = LispLocalEid()
502 for eid in eid_table:
504 eid_address = eid.get('eid')
505 eid_prefix_len = eid.get('eid-prefix-len')
506 locator_set_name = eid.get('locator-set')
507 lisp_locator_set.vpp_add_lisp_locator_set(node, locator_set_name)
508 lisp_eid.vpp_add_lisp_local_eid(node,
515 def vpp_unset_lisp_eid_table(node, eid_table):
516 """Unset lisp eid tables on VPP node in topology.
518 :param node: VPP node.
519 :param eid_table: Dictionary containing information of eid_table.
521 :type eid_table: dict
524 if node['type'] != NodeType.DUT:
525 raise ValueError('Node is not DUT')
527 locator_set_list = []
528 lisp_locator_set = LispLocatorSet()
529 lisp_eid = LispLocalEid()
530 for eid in eid_table:
532 eid_address = eid.get('eid')
533 eid_prefix_len = eid.get('eid-prefix-len')
534 locator_set_name = eid.get('locator-set')
535 if locator_set_name not in locator_set_list:
536 locator_set_list.append(locator_set_name)
538 lisp_eid.vpp_del_lisp_local_eid(node,
544 for locator_set_name in locator_set_list:
545 lisp_locator_set.vpp_del_lisp_locator_set(node, locator_set_name)
548 def vpp_set_lisp_map_resolver(node, map_resolver):
549 """Set lisp map resolvers on VPP node in topology.
551 :param node: VPP node.
552 :param map_resolver: Dictionary containing information of map resolver.
554 :type map_resolver: dict
557 lisp_map_res = LispMapResolver()
558 for map_ip in map_resolver:
559 lisp_map_res.vpp_add_map_resolver(node, map_ip.get('map resolver'))
562 def vpp_unset_lisp_map_resolver(node, map_resolver):
563 """Unset lisp map resolvers on VPP node in topology.
565 :param node: VPP node.
566 :param map_resolver: Dictionary containing information of map resolver.
568 :type map_resolver: dict
571 lisp_map_res = LispMapResolver()
572 for map_ip in map_resolver:
573 lisp_map_res.vpp_del_map_resolver(node, map_ip.get('map resolver'))
576 def vpp_lisp_gpe_interface_status(node, state):
577 """Set lisp gpe interface status on VPP node in topology.
579 :param node: VPP node.
580 :param state: State of the gpe iface, up or down
586 lgi.vpp_lisp_gpe_iface(node, state)