Fix pylint warnings in python libraries
[csit.git] / resources / libraries / python / LispSetup.py
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:
5 #
6 #     http://www.apache.org/licenses/LICENSE-2.0
7 #
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.
13
14 """Library to set up Lisp in topology."""
15
16 from resources.libraries.python.topology import NodeType
17 from resources.libraries.python.VatExecutor import VatExecutor
18
19
20 class LispStatus(object):
21     """Class for lisp API."""
22
23     def __init__(self):
24         pass
25
26     @staticmethod
27     def vpp_lisp_enable_disable(node, state):
28         """Enable/Disable lisp in the VPP node in topology.
29
30         :param node: Node of the test topology.
31         :param state: State of the lisp, enable or disable.
32         :type node: dict
33         :type state: str
34         """
35
36         VatExecutor.cmd_from_template(node,
37                                       'lisp/lisp_status.vat',
38                                       state=state)
39
40
41 class LispRemoteMapping(object):
42     """Class for lisp remote mapping API."""
43
44     def __init__(self):
45         pass
46
47     @staticmethod
48     def vpp_add_lisp_remote_mapping(node, vni, deid, deid_prefix, seid,
49                                     seid_prefix, rloc):
50         """Add lisp remote mapping on the VPP node in topology.
51
52         :param node: VPP node.
53         :param vni: Vni.
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.
59         :type node: dict
60         :type vni: int
61         :type deid: str
62         :type deid_prefix: int
63         :type seid: str
64         :type seid_prefix: int
65         :type rloc: str
66         """
67
68         VatExecutor.cmd_from_template(node,
69                                       'lisp/add_lisp_remote_mapping.vat',
70                                       vni=vni,
71                                       deid=deid,
72                                       deid_prefix=deid_prefix,
73                                       seid=seid,
74                                       seid_prefix=seid_prefix,
75                                       rloc=rloc)
76
77     @staticmethod
78     def vpp_del_lisp_remote_mapping(node, vni, deid, deid_prefix, seid,
79                                     seid_prefix, rloc):
80         """Delete lisp remote mapping on the VPP node in topology.
81
82         :param node: VPP node.
83         :param vni: Vni.
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.
89         :type node: dict
90         :type vni: int
91         :type deid: str
92         :type deid_prefix: int
93         :type seid: str
94         :type seid_prefix: int
95         :type rloc: str
96         """
97
98         VatExecutor.cmd_from_template(node,
99                                       'lisp/del_lisp_remote_mapping.vat',
100                                       vni=vni,
101                                       deid=deid,
102                                       deid_prefix=deid_prefix,
103                                       seid=seid,
104                                       seid_prefix=seid_prefix,
105                                       rloc=rloc)
106
107
108 class LispAdjacency(object):
109     """Class for lisp adjacency API."""
110
111     def __init__(self):
112         pass
113
114     @staticmethod
115     def vpp_add_lisp_adjacency(node, vni, deid, deid_prefix, seid,
116                                seid_prefix):
117         """Add lisp adjacency on the VPP node in topology.
118
119         :param node: VPP node.
120         :param vni: Vni.
121         :param deid: Destination eid address.
122         :param deid_prefix: Destination eid address prefix_len.
123         :param seid: Source eid address.
124         :param seid_prefix: Source eid address prefix_len.
125         :type node: dict
126         :type vni: int
127         :type deid: str
128         :type deid_prefix: int
129         :type seid: str
130         :type seid_prefix: int
131         """
132
133         VatExecutor.cmd_from_template(node,
134                                       'lisp/add_lisp_adjacency.vat',
135                                       vni=vni,
136                                       deid=deid,
137                                       deid_prefix=deid_prefix,
138                                       seid=seid,
139                                       seid_prefix=seid_prefix)
140
141     @staticmethod
142     def vpp_del_lisp_adjacency(node, vni, deid, deid_prefix, seid,
143                                seid_prefix):
144         """Delete lisp adjacency on the VPP node in topology.
145
146         :param node: VPP node.
147         :param vni: Vni.
148         :param deid: Destination eid address.
149         :param deid_prefix: Destination eid address prefix_len.
150         :param seid: Source eid address.
151         :param seid_prefix: Source eid address prefix_len.
152         :type node: dict
153         :type vni: int
154         :type deid: str
155         :type deid_prefix: int
156         :type seid: str
157         :type seid_prefix: int
158         """
159
160         VatExecutor.cmd_from_template(node,
161                                       'lisp/del_lisp_adjacency.vat',
162                                       vni=vni,
163                                       deid=deid,
164                                       deid_prefix=deid_prefix,
165                                       seid=seid,
166                                       seid_prefix=seid_prefix)
167
168
169 class LispGpeStatus(object):
170     """Clas for LISP GPE status manipulation."""
171
172     def __init__(self):
173         pass
174
175     @staticmethod
176     def vpp_lisp_gpe_enable_disable(node, state):
177         """Change the state of LISP GPE - enable or disable.
178
179         :param node: VPP node.
180         :param state: Requested state - enable or disable.
181         :type node: dict
182         :type state: str
183         """
184
185         VatExecutor.cmd_from_template(node, 'lisp/lisp_gpe_status.vat',
186                                       state=state)
187
188
189 class LispGpeIface(object):
190     """Class for Lisp gpe interface API."""
191
192     def __init__(self):
193         pass
194
195     @staticmethod
196     def vpp_lisp_gpe_iface(node, state):
197         """Set lisp gpe interface up or down on the VPP node in topology.
198
199         :param node: VPP node.
200         :param state: State of the gpe iface, up or down.
201         :type node: dict
202         :type state: str
203         """
204
205         VatExecutor.cmd_from_template(node, 'lisp/lisp_gpe_iface.vat',
206                                       state=state)
207
208
209 class LispGpeForwardEntry(object):
210     """The functionality needed for these methods is not implemented in VPP
211     (VAT). Bug https://jira.fd.io/browse/VPP-334 was open to cover this issue.
212
213     TODO: Implement when VPP-334 is fixed.
214     """
215
216     def __init__(self):
217         pass
218
219     @staticmethod
220     def add_lisp_gpe_forward_entry(node, *args):
221         """Not implemented"""
222         # TODO: Implement when VPP-334 is fixed.
223         pass
224
225     @staticmethod
226     def del_lisp_gpe_forward_entry(node, *args):
227         """Not implemented"""
228         # TODO: Implement when VPP-334 is fixed.
229         pass
230
231
232 class LispMapResolver(object):
233     """Class for Lisp map resolver API."""
234
235     def __init__(self):
236         pass
237
238     @staticmethod
239     def vpp_add_map_resolver(node, map_resolver_ip):
240         """Set lisp map resolver on the VPP node in topology.
241
242         :param node: VPP node.
243         :param map_resolver_ip: IP address of the map resolver.
244         :type node: dict
245         :type map_resolver_ip: str
246         """
247
248         VatExecutor.cmd_from_template(node,
249                                       'lisp/add_lisp_map_resolver.vat',
250                                       address=map_resolver_ip)
251
252     @staticmethod
253     def vpp_del_map_resolver(node, map_resolver_ip):
254         """Unset lisp map resolver on the VPP node in topology.
255
256         :param node: VPP node.
257         :param map_resolver_ip: IP address of the map resolver.
258         :type node: dict
259         :type map_resolver_ip: str
260         """
261
262         VatExecutor.cmd_from_template(node,
263                                       'lisp/del_lisp_map_resolver.vat',
264                                       address=map_resolver_ip)
265
266
267 class LispLocalEid(object):
268     """Class for Lisp local eid API."""
269
270     def __init__(self):
271         pass
272
273     @staticmethod
274     def vpp_add_lisp_local_eid(node, locator_set_name, vni, eid,
275                                prefix_len=None):
276         """Set lisp eid address on the VPP node in topology.
277
278         :param node: VPP node.
279         :param locator_set_name: Name of the locator_set.
280         :param vni: vni value.
281         :param eid: Eid value.
282         :param prefix_len: prefix len if the eid is IP address.
283         :type node: dict
284         :type locator_set_name: str
285         :type vni: int
286         :type eid: str
287         :type prefix_len: int
288         """
289
290         if prefix_len is not None:
291             VatExecutor.cmd_from_template(node,
292                                           'lisp/add_lisp_local_eid.vat',
293                                           vni=vni,
294                                           eid=eid,
295                                           eid_prefix=prefix_len,
296                                           locator_name=locator_set_name)
297         else:
298             VatExecutor.cmd_from_template(node,
299                                           'lisp/add_lisp_local_eid_mac.vat',
300                                           vni=vni,
301                                           eid=eid,
302                                           locator_name=locator_set_name)
303
304     @staticmethod
305     def vpp_del_lisp_local_eid(node, locator_set_name, vni, eid,
306                                prefix_len=None):
307         """Set lisp eid addres on the VPP node in topology.
308
309         :param node: VPP node.
310         :param locator_set_name: Name of the locator_set.
311         :param vni: vni value.
312         :param eid: Eid value.
313         :param prefix_len: prefix len if the eid is IP address.
314         :type node: dict
315         :type locator_set_name: str
316         :type vni: int
317         :type eid: str
318         :type prefix_len: int
319         """
320
321         if prefix_len is not None:
322             VatExecutor.cmd_from_template(node,
323                                           'lisp/del_lisp_local_eid.vat',
324                                           vni=vni,
325                                           eid=eid,
326                                           eid_prefix=prefix_len,
327                                           locator_name=locator_set_name)
328         else:
329             VatExecutor.cmd_from_template(node,
330                                           'lisp/del_lisp_local_eid_mac.vat',
331                                           vni=vni,
332                                           eid=eid,
333                                           locator_name=locator_set_name)
334
335
336 class LispLocator(object):
337     """Class for the Lisp Locator API."""
338
339     def __init__(self):
340         pass
341
342     @staticmethod
343     def vpp_add_lisp_locator(node, locator_name, sw_if_index, priority, weight):
344         """Set lisp locator on the VPP node in topology.
345
346         :param node: VPP node.
347         :param locator_name: Name of the locator_set.
348         :param sw_if_index: sw_if_index if the interface.
349         :param priority: priority of the locator.
350         :param weight: weight of the locator.
351         :type node: dict
352         :type locator_name: str
353         :type sw_if_index: int
354         :type priority: int
355         :type weight: int
356         """
357
358         VatExecutor.cmd_from_template(node,
359                                       'lisp/add_lisp_locator.vat',
360                                       lisp_name=locator_name,
361                                       sw_if_index=sw_if_index,
362                                       priority=priority,
363                                       weight=weight)
364
365     @staticmethod
366     def vpp_del_lisp_locator(node, locator_name, sw_if_index, priority, weight):
367         """Unset lisp locator on the VPP node in topology.
368
369         :param node: VPP node.
370         :param locator_name: Name of the locator_set.
371         :param sw_if_index: sw_if_index if the interface.
372         :param priority: priority of the locator.
373         :param weight: weight of the locator.
374         :type node: dict
375         :type locator_name: str
376         :type sw_if_index: int
377         :type priority: int
378         :type weight: int
379         """
380
381         VatExecutor.cmd_from_template(node,
382                                       'lisp/del_lisp_locator.vat',
383                                       lisp_name=locator_name,
384                                       sw_if_index=sw_if_index,
385                                       priority=priority,
386                                       weight=weight)
387
388
389 class LispLocatorSet(object):
390     """Class for Lisp Locator Set API."""
391
392     def __init__(self):
393         pass
394
395     @staticmethod
396     def vpp_add_lisp_locator_set(node, name):
397         """Add lisp locator_set on VPP.
398
399         :param node: VPP node.
400         :param name: VPP locator name.
401         :type node: dict
402         :type name: str
403         """
404
405         VatExecutor.cmd_from_template(node,
406                                       'lisp/add_lisp_locator_set.vat',
407                                       lisp_name=name)
408
409     @staticmethod
410     def vpp_del_lisp_locator_set(node, name):
411         """Del lisp locator_set on VPP.
412
413         :param node: VPP node.
414         :param name: VPP locator name.
415         :type node: dict
416         :type name: str
417         """
418
419         VatExecutor.cmd_from_template(node,
420                                       'lisp/del_lisp_locator_set.vat',
421                                       lisp_name=name)
422
423
424 class LispSetup(object):
425     """Lisp setup in topology."""
426
427     def __init__(self):
428         pass
429
430     @staticmethod
431     def vpp_set_lisp_locator_set(node, locator_set_list):
432         """Set lisp locator_sets on VPP node in topology.
433
434         :param node: VPP node.
435         :param locator_set_list: List of locator_set.
436         :type node: dict
437         :type locator_set_list: list
438         """
439
440         if node['type'] != NodeType.DUT:
441             raise ValueError('Node is not DUT')
442
443         lisp_locator = LispLocator()
444         lisp_locator_set = LispLocatorSet()
445         for locator_set in locator_set_list:
446             locator_set_name = locator_set.get('locator-set')
447             locator_list = locator_set.get('locator')
448             lisp_locator_set.vpp_add_lisp_locator_set(node,
449                                                       locator_set_name)
450             for locator in locator_list:
451                 sw_if_index = locator.get('locator-index')
452                 priority = locator.get('priority')
453                 weight = locator.get('weight')
454                 lisp_locator.vpp_add_lisp_locator(node,
455                                                   locator_set_name,
456                                                   sw_if_index,
457                                                   priority,
458                                                   weight)
459
460     @staticmethod
461     def vpp_unset_lisp_locator_set(node, locator_set_list):
462         """Unset lisp locator_sets on VPP node in topology.
463
464         :param node: VPP node.
465         :param locator_set_list: List of locator_set.
466         :type node: dict
467         :type locator_set_list: list
468         """
469
470         if node['type'] != NodeType.DUT:
471             raise ValueError('Lisp locator set, node is not DUT')
472
473         lisp_locator = LispLocator()
474         lisp_locator_set = LispLocatorSet()
475         for locator_set in locator_set_list:
476             locator_set_name = locator_set.get('locator-set')
477             locator_list = locator_set.get('locator')
478             for locator in locator_list:
479                 sw_if_index = locator.get('locator-index')
480                 priority = locator.get('priority')
481                 weight = locator.get('weight')
482                 lisp_locator.vpp_del_lisp_locator(node,
483                                                   locator_set_name,
484                                                   sw_if_index,
485                                                   priority,
486                                                   weight)
487
488             lisp_locator_set.vpp_del_lisp_locator_set(node,
489                                                       locator_set_name)
490
491     @staticmethod
492     def vpp_set_lisp_eid_table(node, eid_table):
493         """Set lisp eid tables on VPP node in topology.
494
495         :param node: VPP node.
496         :param eid_table: Dictionary containing information of eid_table.
497         :type node: dict
498         :type eid_table: dict
499         """
500
501         if node['type'] != NodeType.DUT:
502             raise ValueError('Node is not DUT')
503
504         lisp_locator_set = LispLocatorSet()
505         lisp_eid = LispLocalEid()
506         for eid in eid_table:
507             vni = eid.get('vni')
508             eid_address = eid.get('eid')
509             eid_prefix_len = eid.get('eid-prefix-len')
510             locator_set_name = eid.get('locator-set')
511             lisp_locator_set.vpp_add_lisp_locator_set(node, locator_set_name)
512             lisp_eid.vpp_add_lisp_local_eid(node,
513                                             locator_set_name,
514                                             vni,
515                                             eid_address,
516                                             eid_prefix_len)
517
518     @staticmethod
519     def vpp_unset_lisp_eid_table(node, eid_table):
520         """Unset lisp eid tables on VPP node in topology.
521
522         :param node: VPP node.
523         :param eid_table: Dictionary containing information of eid_table.
524         :type node: dict
525         :type eid_table: dict
526         """
527
528         if node['type'] != NodeType.DUT:
529             raise ValueError('Node is not DUT')
530
531         locator_set_list = []
532         lisp_locator_set = LispLocatorSet()
533         lisp_eid = LispLocalEid()
534         for eid in eid_table:
535             vni = eid.get('vni')
536             eid_address = eid.get('eid')
537             eid_prefix_len = eid.get('eid-prefix-len')
538             locator_set_name = eid.get('locator-set')
539             if locator_set_name not in locator_set_list:
540                 locator_set_list.append(locator_set_name)
541
542             lisp_eid.vpp_del_lisp_local_eid(node,
543                                             locator_set_name,
544                                             vni,
545                                             eid_address,
546                                             eid_prefix_len)
547
548         for locator_set_name in locator_set_list:
549             lisp_locator_set.vpp_del_lisp_locator_set(node, locator_set_name)
550
551     @staticmethod
552     def vpp_set_lisp_map_resolver(node, map_resolver):
553         """Set lisp map resolvers on VPP node in topology.
554
555         :param node: VPP node.
556         :param map_resolver: Dictionary containing information of map resolver.
557         :type node: dict
558         :type map_resolver: dict
559         """
560
561         lisp_map_res = LispMapResolver()
562         for map_ip in map_resolver:
563             lisp_map_res.vpp_add_map_resolver(node, map_ip.get('map resolver'))
564
565     @staticmethod
566     def vpp_unset_lisp_map_resolver(node, map_resolver):
567         """Unset lisp map resolvers on VPP node in topology.
568
569         :param node: VPP node.
570         :param map_resolver: Dictionary containing information of map resolver.
571         :type node: dict
572         :type map_resolver: dict
573         """
574
575         lisp_map_res = LispMapResolver()
576         for map_ip in map_resolver:
577             lisp_map_res.vpp_del_map_resolver(node, map_ip.get('map resolver'))
578
579     @staticmethod
580     def vpp_lisp_gpe_interface_status(node, state):
581         """Set lisp gpe interface status on VPP node in topology.
582
583         :param node: VPP node.
584         :param state: State of the gpe iface, up or down
585         :type node: dict
586         :type state: str
587         """
588
589         lgi = LispGpeIface()
590         lgi.vpp_lisp_gpe_iface(node, state)

©2016 FD.io a Linux Foundation Collaborative Project. All Rights Reserved.
Linux Foundation is a registered trademark of The Linux Foundation. Linux is a registered trademark of Linus Torvalds.
Please see our privacy policy and terms of use.