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 LispGpeIface(object):
21 """Class for Lisp gpe interface API."""
27 def vpp_lisp_gpe_iface(node, state):
28 """Set lisp gpe interface up or down on the VPP node in topology.
30 :param node: VPP node.
31 :param state: State of the gpe iface, up or down
36 VatExecutor.cmd_from_template(node,
37 'lisp/lisp_gpe_iface.vat',
41 class LispMapResolver(object):
42 """Class for Lisp map resolver API."""
48 def vpp_add_map_resolver(node, map_resolver_ip):
49 """Set lisp map resolver on the VPP node in topology.
51 :param node: VPP node.
52 :param map_resolver_ip: IP address of the map resolver.
54 :type map_resolver_ip: str
57 VatExecutor.cmd_from_template(node,
58 'lisp/add_lisp_map_resolver.vat',
59 address=map_resolver_ip)
62 def vpp_del_map_resolver(node, map_resolver_ip):
63 """Unset lisp map resolver on the VPP node in topology.
65 :param node: VPP node.
66 :param map_resolver_ip: IP address of the map resolver.
68 :type map_resolver_ip: str
71 VatExecutor.cmd_from_template(node,
72 'lisp/del_lisp_map_resolver.vat',
73 address=map_resolver_ip)
76 class LispLocalEid(object):
77 """Class for Lisp local eid API."""
83 def vpp_add_lisp_local_eid(node, locator_set_name, address, prefix_len):
84 """Set lisp eid addres on the VPP node in topology.
86 :param node: VPP node.
87 :param locator_set_name: Name of the locator_set.
88 :param address: Eid IP address.
89 :param prefix_len: prefix len of the eid IP address.
91 :type locator_set_name: str
96 VatExecutor.cmd_from_template(node,
97 'lisp/add_lisp_local_eid.vat',
99 eid_prefix=prefix_len,
100 locator_name=locator_set_name)
103 def vpp_del_lisp_local_eid(node, locator_set_name, address, prefix_len):
104 """Set lisp eid addres on the VPP node in topology.
106 :param node: VPP node.
107 :param locator_set_name: Name of the locator_set.
108 :param address: Eid IP address.
109 :param prefix_len: prefix len of the eid IP address.
111 :type locator_set_name: str
113 :type prefix_len: int
116 VatExecutor.cmd_from_template(node,
117 'lisp/del_lisp_local_eid.vat',
119 eid_prefix=prefix_len,
120 locator_name=locator_set_name)
123 class LispLocator(object):
124 """Class for the Lisp Locator API."""
130 def vpp_add_lisp_locator(node, locator_name, sw_if_index, priority, weight):
131 """Set lisp locator on the VPP node in topology.
133 :param node: VPP node.
134 :param locator_name: Name of the locator_set.
135 :param sw_if_index: sw_if_index if the interface.
136 :param priority: priority of the locator.
137 :param weight: weight of the locator.
139 :type locator_name: str
140 :type sw_if_index: int
145 VatExecutor.cmd_from_template(node,
146 'lisp/add_lisp_locator.vat',
147 lisp_name=locator_name,
148 sw_if_index=sw_if_index,
153 def vpp_del_lisp_locator(node, locator_name, sw_if_index, priority, weight):
154 """Unset lisp locator on the VPP node in topology.
156 :param node: VPP node.
157 :param locator_name: Name of the locator_set.
158 :param sw_if_index: sw_if_index if the interface.
159 :param priority: priority of the locator.
160 :param weight: weight of the locator.
162 :type locator_name: str
163 :type sw_if_index: int
168 VatExecutor.cmd_from_template(node,
169 'lisp/del_lisp_locator.vat',
170 lisp_name=locator_name,
171 sw_if_index=sw_if_index,
176 class LispLocatorSet(object):
177 """Class for Lisp Locator Set API."""
183 def vpp_add_lisp_locator_set(node, name):
184 """Add lisp locator_set on VPP.
186 :param node: VPP node.
187 :param name: VPP locator name.
192 VatExecutor.cmd_from_template(node,
193 'lisp/add_lisp_locator_set.vat',
197 def vpp_del_lisp_locator_set(node, name):
198 """Del lisp locator_set on VPP.
200 :param node: VPP node.
201 :param name: VPP locator name.
206 VatExecutor.cmd_from_template(node,
207 'lisp/del_lisp_locator_set.vat',
211 class LispSetup(object):
212 """Lisp setup in topology."""
218 def vpp_set_lisp_locator_set(node, locator_sets):
219 """Set lisp locator_sets on VPP node in topology.
221 There are two ways how set lisp locator_set.
222 One locator_set can contain multiple locators.
223 Add new locator_set with same name as it already save in vpp
224 will reset locator_set and his locator.
225 To not reset locator_set, use "normal" type of generate data,
226 where the locator_set is set just once.
227 To test reset locator_set use "reset" type of generate data,
228 where the locator_set will be set multiple times.
230 :param node: VPP node.
231 :param locator_sets: Dictionary containing information of locator_set.
233 :type locator_sets: dict
236 if node['type'] != NodeType.DUT:
237 raise ValueError('Lisp locator set, node is not DUT')
239 lisp_locator_set = LispLocatorSet()
240 lisp_locator = LispLocator()
241 for locator_set_type, item in locator_sets.iteritems():
242 if locator_set_type == 'normal':
244 elif locator_set_type == 'reset':
247 raise ValueError('Unknown locator_set_type value: '
248 '{}'.format(locator_set_type))
250 locator_set_list = []
251 for locator_set in item:
252 locator_name = locator_set.get('locator-set')
253 sw_if_index = locator_set.get('locator')
254 priority = locator_set.get('priority')
255 weight = locator_set.get('weight')
257 if locator_name not in locator_set_list:
258 locator_set_list.append(locator_name)
259 lisp_locator_set.vpp_add_lisp_locator_set(node,
262 lisp_locator_set.vpp_add_lisp_locator_set(node,
264 lisp_locator.vpp_add_lisp_locator(node,
271 def vpp_unset_lisp_locator_set(node, locator_sets):
272 """Unset lisp locator_sets on VPP node in topology.
274 :param node: VPP node.
275 :param locator_sets: Dictionary containing information of locator_set.
277 :type locator_sets: dict
280 if node['type'] != NodeType.DUT:
281 raise ValueError('Lisp locator set, node is not DUT')
283 lisp_locator = LispLocator()
284 lisp_locator_set = LispLocatorSet()
285 for locator_set_type, item in locator_sets.iteritems():
286 if locator_set_type == 'normal':
288 elif locator_set_type == 'reset':
291 raise ValueError('Unknown locator_set_type value: '
292 '{}'.format(locator_set_type))
294 locator_set_list = []
295 for locator_set in item:
296 locator_set_name = locator_set.get('locator-set')
297 sw_if_index = locator_set.get('locator')
298 priority = locator_set.get('priority')
299 weight = locator_set.get('weight')
301 if locator_set_name not in locator_set_list:
302 locator_set_list.append(locator_set_name)
304 lisp_locator.vpp_del_lisp_locator(node,
310 for locator_set_name in locator_set_list:
311 lisp_locator_set.vpp_del_lisp_locator_set(node, locator_set_name)
314 def vpp_set_lisp_eid_table(node, eid_table):
315 """Set lisp eid tables on VPP node in topology.
317 :param node: VPP node.
318 :param eid_table: Dictionary containing information of eid_table.
320 :type eid_table: dict
323 if node['type'] != NodeType.DUT:
324 raise ValueError('Lisp locator set, node is not DUT')
326 lisp_locator_set = LispLocatorSet()
327 lisp_eid = LispLocalEid()
328 for eid in eid_table:
329 eid_address = eid.get('eid address')
330 eid_prefix_len = eid.get('eid prefix len')
331 locator_set_name = eid.get('locator-set')
332 lisp_locator_set.vpp_add_lisp_locator_set(node, locator_set_name)
333 lisp_eid.vpp_add_lisp_local_eid(node,
339 def vpp_unset_lisp_eid_table(node, eid_table):
340 """Unset lisp eid tables on VPP node in topology.
342 :param node: VPP node.
343 :param eid_table: Dictionary containing information of eid_table.
345 :type eid_table: dict
348 if node['type'] != NodeType.DUT:
349 raise ValueError('Lisp locator set, node is not DUT')
351 locator_set_list = []
352 lisp_locator_set = LispLocatorSet()
353 lisp_eid = LispLocalEid()
354 for eid in eid_table:
355 eid_address = eid.get('eid address')
356 eid_prefix_len = eid.get('eid prefix len')
357 locator_set_name = eid.get('locator-set')
358 if locator_set_name not in locator_set_list:
359 locator_set_list.append(locator_set_name)
361 lisp_eid.vpp_del_lisp_local_eid(node,
366 for locator_set_name in locator_set_list:
367 lisp_locator_set.vpp_del_lisp_locator_set(node, locator_set_name)
370 def vpp_set_lisp_map_resolver(node, map_resolver):
371 """Set lisp map resolvers on VPP node in topology.
373 :param node: VPP node.
374 :param map_resolver: Dictionary containing information of map resolver.
376 :type map_resolver: dict
379 lisp_map_res = LispMapResolver()
380 for map_ip in map_resolver:
381 lisp_map_res.vpp_add_map_resolver(node, map_ip.get('map resolver'))
384 def vpp_unset_lisp_map_resolver(node, map_resolver):
385 """Unset lisp map resolvers on VPP node in topology.
387 :param node: VPP node.
388 :param map_resolver: Dictionary containing information of map resolver.
390 :type map_resolver: dict
393 lisp_map_res = LispMapResolver()
394 for map_ip in map_resolver:
395 lisp_map_res.vpp_del_map_resolver(node, map_ip.get('map resolver'))
398 def vpp_lisp_gpe_interface_status(node, state):
399 """Set lisp gpe interface status on VPP node in topology.
401 :param node: VPP node.
402 :param state: State of the gpe iface, up or down
408 lgi.vpp_lisp_gpe_iface(node, state)