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,
108 class LispGpeIface(object):
109 """Class for Lisp gpe interface API."""
115 def vpp_lisp_gpe_iface(node, state):
116 """Set lisp gpe interface up or down on the VPP node in topology.
118 :param node: VPP node.
119 :param state: State of the gpe iface, up or down.
124 VatExecutor.cmd_from_template(node,
125 'lisp/lisp_gpe_iface.vat',
129 class LispMapResolver(object):
130 """Class for Lisp map resolver API."""
136 def vpp_add_map_resolver(node, map_resolver_ip):
137 """Set lisp map resolver on the VPP node in topology.
139 :param node: VPP node.
140 :param map_resolver_ip: IP address of the map resolver.
142 :type map_resolver_ip: str
145 VatExecutor.cmd_from_template(node,
146 'lisp/add_lisp_map_resolver.vat',
147 address=map_resolver_ip)
150 def vpp_del_map_resolver(node, map_resolver_ip):
151 """Unset lisp map resolver on the VPP node in topology.
153 :param node: VPP node.
154 :param map_resolver_ip: IP address of the map resolver.
156 :type map_resolver_ip: str
159 VatExecutor.cmd_from_template(node,
160 'lisp/del_lisp_map_resolver.vat',
161 address=map_resolver_ip)
164 class LispLocalEid(object):
165 """Class for Lisp local eid API."""
171 def vpp_add_lisp_local_eid(node, locator_set_name, address, prefix_len):
172 """Set lisp eid addres on the VPP node in topology.
174 :param node: VPP node.
175 :param locator_set_name: Name of the locator_set.
176 :param address: Eid IP address.
177 :param prefix_len: prefix len of the eid IP address.
179 :type locator_set_name: str
181 :type prefix_len: int
184 VatExecutor.cmd_from_template(node,
185 'lisp/add_lisp_local_eid.vat',
187 eid_prefix=prefix_len,
188 locator_name=locator_set_name)
191 def vpp_del_lisp_local_eid(node, locator_set_name, address, prefix_len):
192 """Set lisp eid addres on the VPP node in topology.
194 :param node: VPP node.
195 :param locator_set_name: Name of the locator_set.
196 :param address: Eid IP address.
197 :param prefix_len: prefix len of the eid IP address.
199 :type locator_set_name: str
201 :type prefix_len: int
204 VatExecutor.cmd_from_template(node,
205 'lisp/del_lisp_local_eid.vat',
207 eid_prefix=prefix_len,
208 locator_name=locator_set_name)
211 class LispLocator(object):
212 """Class for the Lisp Locator API."""
218 def vpp_add_lisp_locator(node, locator_name, sw_if_index, priority, weight):
219 """Set lisp locator on the VPP node in topology.
221 :param node: VPP node.
222 :param locator_name: Name of the locator_set.
223 :param sw_if_index: sw_if_index if the interface.
224 :param priority: priority of the locator.
225 :param weight: weight of the locator.
227 :type locator_name: str
228 :type sw_if_index: int
233 VatExecutor.cmd_from_template(node,
234 'lisp/add_lisp_locator.vat',
235 lisp_name=locator_name,
236 sw_if_index=sw_if_index,
241 def vpp_del_lisp_locator(node, locator_name, sw_if_index, priority, weight):
242 """Unset lisp locator on the VPP node in topology.
244 :param node: VPP node.
245 :param locator_name: Name of the locator_set.
246 :param sw_if_index: sw_if_index if the interface.
247 :param priority: priority of the locator.
248 :param weight: weight of the locator.
250 :type locator_name: str
251 :type sw_if_index: int
256 VatExecutor.cmd_from_template(node,
257 'lisp/del_lisp_locator.vat',
258 lisp_name=locator_name,
259 sw_if_index=sw_if_index,
264 class LispLocatorSet(object):
265 """Class for Lisp Locator Set API."""
271 def vpp_add_lisp_locator_set(node, name):
272 """Add lisp locator_set on VPP.
274 :param node: VPP node.
275 :param name: VPP locator name.
280 VatExecutor.cmd_from_template(node,
281 'lisp/add_lisp_locator_set.vat',
285 def vpp_del_lisp_locator_set(node, name):
286 """Del lisp locator_set on VPP.
288 :param node: VPP node.
289 :param name: VPP locator name.
294 VatExecutor.cmd_from_template(node,
295 'lisp/del_lisp_locator_set.vat',
299 class LispSetup(object):
300 """Lisp setup in topology."""
306 def vpp_set_lisp_locator_set(node, locator_sets):
307 """Set lisp locator_sets on VPP node in topology.
309 There are two ways how set lisp locator_set.
310 One locator_set can contain multiple locators.
311 Add new locator_set with same name as it already save in vpp
312 will reset locator_set and his locator.
313 To not reset locator_set, use "normal" type of generate data,
314 where the locator_set is set just once.
315 To test reset locator_set use "reset" type of generate data,
316 where the locator_set will be set multiple times.
318 :param node: VPP node.
319 :param locator_sets: Dictionary containing information of locator_set.
321 :type locator_sets: dict
324 if node['type'] != NodeType.DUT:
325 raise ValueError('Lisp locator set, node is not DUT')
327 lisp_locator_set = LispLocatorSet()
328 lisp_locator = LispLocator()
329 for locator_set_type, item in locator_sets.iteritems():
330 if locator_set_type == 'normal':
332 elif locator_set_type == 'reset':
335 raise ValueError('Unknown locator_set_type value: '
336 '{}'.format(locator_set_type))
338 locator_set_list = []
339 for locator_set in item:
340 locator_name = locator_set.get('locator-set')
341 sw_if_index = locator_set.get('locator')
342 priority = locator_set.get('priority')
343 weight = locator_set.get('weight')
345 if locator_name not in locator_set_list:
346 locator_set_list.append(locator_name)
347 lisp_locator_set.vpp_add_lisp_locator_set(node,
350 lisp_locator_set.vpp_add_lisp_locator_set(node,
352 lisp_locator.vpp_add_lisp_locator(node,
359 def vpp_unset_lisp_locator_set(node, locator_sets):
360 """Unset lisp locator_sets on VPP node in topology.
362 :param node: VPP node.
363 :param locator_sets: Dictionary containing information of locator_set.
365 :type locator_sets: dict
368 if node['type'] != NodeType.DUT:
369 raise ValueError('Lisp locator set, node is not DUT')
371 lisp_locator = LispLocator()
372 lisp_locator_set = LispLocatorSet()
373 for locator_set_type, item in locator_sets.iteritems():
374 if locator_set_type == 'normal':
376 elif locator_set_type == 'reset':
379 raise ValueError('Unknown locator_set_type value: '
380 '{}'.format(locator_set_type))
382 locator_set_list = []
383 for locator_set in item:
384 locator_set_name = locator_set.get('locator-set')
385 sw_if_index = locator_set.get('locator')
386 priority = locator_set.get('priority')
387 weight = locator_set.get('weight')
389 if locator_set_name not in locator_set_list:
390 locator_set_list.append(locator_set_name)
392 lisp_locator.vpp_del_lisp_locator(node,
398 for locator_set_name in locator_set_list:
399 lisp_locator_set.vpp_del_lisp_locator_set(node, locator_set_name)
402 def vpp_set_lisp_eid_table(node, eid_table):
403 """Set lisp eid tables on VPP node in topology.
405 :param node: VPP node.
406 :param eid_table: Dictionary containing information of eid_table.
408 :type eid_table: dict
411 if node['type'] != NodeType.DUT:
412 raise ValueError('Lisp locator set, node is not DUT')
414 lisp_locator_set = LispLocatorSet()
415 lisp_eid = LispLocalEid()
416 for eid in eid_table:
417 eid_address = eid.get('eid address')
418 eid_prefix_len = eid.get('eid prefix len')
419 locator_set_name = eid.get('locator-set')
420 lisp_locator_set.vpp_add_lisp_locator_set(node, locator_set_name)
421 lisp_eid.vpp_add_lisp_local_eid(node,
427 def vpp_unset_lisp_eid_table(node, eid_table):
428 """Unset lisp eid tables on VPP node in topology.
430 :param node: VPP node.
431 :param eid_table: Dictionary containing information of eid_table.
433 :type eid_table: dict
436 if node['type'] != NodeType.DUT:
437 raise ValueError('Lisp locator set, node is not DUT')
439 locator_set_list = []
440 lisp_locator_set = LispLocatorSet()
441 lisp_eid = LispLocalEid()
442 for eid in eid_table:
443 eid_address = eid.get('eid address')
444 eid_prefix_len = eid.get('eid prefix len')
445 locator_set_name = eid.get('locator-set')
446 if locator_set_name not in locator_set_list:
447 locator_set_list.append(locator_set_name)
449 lisp_eid.vpp_del_lisp_local_eid(node,
454 for locator_set_name in locator_set_list:
455 lisp_locator_set.vpp_del_lisp_locator_set(node, locator_set_name)
458 def vpp_set_lisp_map_resolver(node, map_resolver):
459 """Set lisp map resolvers on VPP node in topology.
461 :param node: VPP node.
462 :param map_resolver: Dictionary containing information of map resolver.
464 :type map_resolver: dict
467 lisp_map_res = LispMapResolver()
468 for map_ip in map_resolver:
469 lisp_map_res.vpp_add_map_resolver(node, map_ip.get('map resolver'))
472 def vpp_unset_lisp_map_resolver(node, map_resolver):
473 """Unset lisp map resolvers on VPP node in topology.
475 :param node: VPP node.
476 :param map_resolver: Dictionary containing information of map resolver.
478 :type map_resolver: dict
481 lisp_map_res = LispMapResolver()
482 for map_ip in map_resolver:
483 lisp_map_res.vpp_del_map_resolver(node, map_ip.get('map resolver'))
486 def vpp_lisp_gpe_interface_status(node, state):
487 """Set lisp gpe interface status on VPP node in topology.
489 :param node: VPP node.
490 :param state: State of the gpe iface, up or down
496 lgi.vpp_lisp_gpe_iface(node, state)