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, vni, eid,
173 """Set lisp eid address on the VPP node in topology.
175 :param node: VPP node.
176 :param locator_set_name: Name of the locator_set.
177 :param vni: vni value.
178 :param eid: Eid value.
179 :param prefix_len: prefix len if the eid is IP address.
181 :type locator_set_name: str
184 :type prefix_len: int
187 if prefix_len is not None:
188 VatExecutor.cmd_from_template(node,
189 'lisp/add_lisp_local_eid.vat',
192 eid_prefix=prefix_len,
193 locator_name=locator_set_name)
195 VatExecutor.cmd_from_template(node,
196 'lisp/add_lisp_local_eid_mac.vat',
199 locator_name=locator_set_name)
202 def vpp_del_lisp_local_eid(node, locator_set_name, vni, eid,
204 """Set lisp eid addres on the VPP node in topology.
206 :param node: VPP node.
207 :param locator_set_name: Name of the locator_set.
208 :param vni: vni value.
209 :param eid: Eid value.
210 :param prefix_len: prefix len if the eid is IP address.
212 :type locator_set_name: str
215 :type prefix_len: int
218 if prefix_len is not None:
219 VatExecutor.cmd_from_template(node,
220 'lisp/del_lisp_local_eid.vat',
223 eid_prefix=prefix_len,
224 locator_name=locator_set_name)
226 VatExecutor.cmd_from_template(node,
227 'lisp/del_lisp_local_eid_mac.vat',
230 locator_name=locator_set_name)
233 class LispLocator(object):
234 """Class for the Lisp Locator API."""
240 def vpp_add_lisp_locator(node, locator_name, sw_if_index, priority, weight):
241 """Set lisp locator on the VPP node in topology.
243 :param node: VPP node.
244 :param locator_name: Name of the locator_set.
245 :param sw_if_index: sw_if_index if the interface.
246 :param priority: priority of the locator.
247 :param weight: weight of the locator.
249 :type locator_name: str
250 :type sw_if_index: int
255 VatExecutor.cmd_from_template(node,
256 'lisp/add_lisp_locator.vat',
257 lisp_name=locator_name,
258 sw_if_index=sw_if_index,
263 def vpp_del_lisp_locator(node, locator_name, sw_if_index, priority, weight):
264 """Unset lisp locator on the VPP node in topology.
266 :param node: VPP node.
267 :param locator_name: Name of the locator_set.
268 :param sw_if_index: sw_if_index if the interface.
269 :param priority: priority of the locator.
270 :param weight: weight of the locator.
272 :type locator_name: str
273 :type sw_if_index: int
278 VatExecutor.cmd_from_template(node,
279 'lisp/del_lisp_locator.vat',
280 lisp_name=locator_name,
281 sw_if_index=sw_if_index,
286 class LispLocatorSet(object):
287 """Class for Lisp Locator Set API."""
293 def vpp_add_lisp_locator_set(node, name):
294 """Add lisp locator_set on VPP.
296 :param node: VPP node.
297 :param name: VPP locator name.
302 VatExecutor.cmd_from_template(node,
303 'lisp/add_lisp_locator_set.vat',
307 def vpp_del_lisp_locator_set(node, name):
308 """Del lisp locator_set on VPP.
310 :param node: VPP node.
311 :param name: VPP locator name.
316 VatExecutor.cmd_from_template(node,
317 'lisp/del_lisp_locator_set.vat',
321 class LispSetup(object):
322 """Lisp setup in topology."""
328 def vpp_set_lisp_locator_set(node, locator_set_list):
329 """Set lisp locator_sets on VPP node in topology.
331 :param node: VPP node.
332 :param locator_set_list: List of locator_set.
334 :type locator_set_list: list
337 if node['type'] != NodeType.DUT:
338 raise ValueError('Node is not DUT')
340 lisp_locator = LispLocator()
341 lisp_locator_set = LispLocatorSet()
342 for locator_set in locator_set_list:
343 locator_set_name = locator_set.get('locator-set')
344 locator_list = locator_set.get('locator')
345 lisp_locator_set.vpp_add_lisp_locator_set(node,
347 for locator in locator_list:
348 sw_if_index = locator.get('locator-index')
349 priority = locator.get('priority')
350 weight = locator.get('weight')
351 lisp_locator.vpp_add_lisp_locator(node,
358 def vpp_unset_lisp_locator_set(node, locator_set_list):
359 """Unset lisp locator_sets on VPP node in topology.
361 :param node: VPP node.
362 :param locator_set_list: List of locator_set.
364 :type locator_set_list: list
367 if node['type'] != NodeType.DUT:
368 raise ValueError('Lisp locator set, node is not DUT')
370 lisp_locator = LispLocator()
371 lisp_locator_set = LispLocatorSet()
372 for locator_set in locator_set_list:
373 locator_set_name = locator_set.get('locator-set')
374 locator_list = locator_set.get('locator')
375 for locator in locator_list:
376 sw_if_index = locator.get('locator-index')
377 priority = locator.get('priority')
378 weight = locator.get('weight')
379 lisp_locator.vpp_del_lisp_locator(node,
385 lisp_locator_set.vpp_del_lisp_locator_set(node,
389 def vpp_set_lisp_eid_table(node, eid_table):
390 """Set lisp eid tables on VPP node in topology.
392 :param node: VPP node.
393 :param eid_table: Dictionary containing information of eid_table.
395 :type eid_table: dict
398 if node['type'] != NodeType.DUT:
399 raise ValueError('Node is not DUT')
401 lisp_locator_set = LispLocatorSet()
402 lisp_eid = LispLocalEid()
403 for eid in eid_table:
405 eid_address = eid.get('eid')
406 eid_prefix_len = eid.get('eid-prefix-len')
407 locator_set_name = eid.get('locator-set')
408 lisp_locator_set.vpp_add_lisp_locator_set(node, locator_set_name)
409 lisp_eid.vpp_add_lisp_local_eid(node,
416 def vpp_unset_lisp_eid_table(node, eid_table):
417 """Unset lisp eid tables on VPP node in topology.
419 :param node: VPP node.
420 :param eid_table: Dictionary containing information of eid_table.
422 :type eid_table: dict
425 if node['type'] != NodeType.DUT:
426 raise ValueError('Node is not DUT')
428 locator_set_list = []
429 lisp_locator_set = LispLocatorSet()
430 lisp_eid = LispLocalEid()
431 for eid in eid_table:
433 eid_address = eid.get('eid')
434 eid_prefix_len = eid.get('eid-prefix-len')
435 locator_set_name = eid.get('locator-set')
436 if locator_set_name not in locator_set_list:
437 locator_set_list.append(locator_set_name)
439 lisp_eid.vpp_del_lisp_local_eid(node,
445 for locator_set_name in locator_set_list:
446 lisp_locator_set.vpp_del_lisp_locator_set(node, locator_set_name)
449 def vpp_set_lisp_map_resolver(node, map_resolver):
450 """Set lisp map resolvers on VPP node in topology.
452 :param node: VPP node.
453 :param map_resolver: Dictionary containing information of map resolver.
455 :type map_resolver: dict
458 lisp_map_res = LispMapResolver()
459 for map_ip in map_resolver:
460 lisp_map_res.vpp_add_map_resolver(node, map_ip.get('map resolver'))
463 def vpp_unset_lisp_map_resolver(node, map_resolver):
464 """Unset lisp map resolvers on VPP node in topology.
466 :param node: VPP node.
467 :param map_resolver: Dictionary containing information of map resolver.
469 :type map_resolver: dict
472 lisp_map_res = LispMapResolver()
473 for map_ip in map_resolver:
474 lisp_map_res.vpp_del_map_resolver(node, map_ip.get('map resolver'))
477 def vpp_lisp_gpe_interface_status(node, state):
478 """Set lisp gpe interface status on VPP node in topology.
480 :param node: VPP node.
481 :param state: State of the gpe iface, up or down
487 lgi.vpp_lisp_gpe_iface(node, state)