Fix bug 1598 - tweaking timings in the locks
[osm/RO.git] / RO-SDN-arista_cloudvision / osm_rosdn_arista_cloudvision / aristaConfigLet.py
1 # -*- coding: utf-8 -*-
2 ##
3 # Copyright 2019 Atos - CoE Telco NFV Team
4 # All Rights Reserved.
5 #
6 # Contributors: Oscar Luis Peral, Atos
7 #
8 # Licensed under the Apache License, Version 2.0 (the "License"); you may
9 # not use this file except in compliance with the License. You may obtain
10 # a copy of the License at
11 #
12 # http://www.apache.org/licenses/LICENSE-2.0
13 #
14 # Unless required by applicable law or agreed to in writing, software
15 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
16 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
17 # License for the specific language governing permissions and limitations
18 # under the License.
19 #
20 # For those usages not covered by the Apache License, Version 2.0 please
21 # contact with: <oscarluis.peral@atos.net>
22 #
23 # Neither the name of Atos nor the names of its
24 # contributors may be used to endorse or promote products derived from
25 # this software without specific prior written permission.
26 #
27 # This work has been performed in the context of Arista Telefonica OSM PoC.
28 ##
29
30
31 class AristaSDNConfigLet:
32 _VLAN = "VLAN"
33 _VXLAN = "VXLAN"
34 _VLAN_MLAG = "VLAN-MLAG"
35 _VXLAN_MLAG = "VXLAN-MLAG"
36 topology = _VXLAN_MLAG
37
38 def __init__(self, topology=_VXLAN_MLAG):
39 self.topology = topology
40
41 _basic_int = """
42 interface {interface}
43 !! service: {uuid}
44 switchport
45 switchport mode {type}
46 switchport {switchport_def}
47 !
48 """
49 _int_SRIOV = "trunk group {service}{vlan_id}"
50 _int_PASSTROUGH = "access vlan {vlan_id}"
51
52 def _get_interface(self, uuid, interface, vlan_id, s_type, index, i_type):
53 if i_type == "trunk":
54 switchport_def = self._int_SRIOV.format(service=s_type, vlan_id=vlan_id)
55 else:
56 switchport_def = self._int_PASSTROUGH.format(vlan_id=vlan_id)
57
58 return self._basic_int.format(
59 uuid=uuid, interface=interface, type=i_type, switchport_def=switchport_def
60 )
61
62 def getElan_sriov(self, uuid, interface, vlan_id, index):
63 return self._get_interface(uuid, interface, vlan_id, "ELAN", index, "trunk")
64
65 def getEline_sriov(self, uuid, interface, vlan_id, index):
66 return self._get_interface(uuid, interface, vlan_id, "ELINE", index, "trunk")
67
68 def getElan_passthrough(self, uuid, interface, vlan_id, index):
69 return self._get_interface(
70 uuid, interface, vlan_id, "ELAN", index, "dot1q-tunnel"
71 )
72
73 def getEline_passthrough(self, uuid, interface, vlan_id, index):
74 return self._get_interface(
75 uuid, interface, vlan_id, "ELINE", index, "dot1q-tunnel"
76 )
77
78 _basic_vlan = """
79 vlan {vlan}
80 !! service: {service} {vlan} {uuid}
81 name {service}{vlan}
82 trunk group {service}{vlan}
83 """
84 _basic_mlag = """ trunk group MLAGPEER
85 """
86 _basic_vxlan = """interface VXLAN1
87 VXLAN vlan {vlan} vni {vni}
88 """
89 _basic_end = "!"
90
91 _configLet_VLAN = _basic_vlan + _basic_end
92 _configLet_VXLAN = _basic_vlan + _basic_vxlan + _basic_end
93 _configLet_VLAN_MLAG = _basic_vlan + _basic_mlag + _basic_end
94 _configLet_VXLAN_MLAG = _basic_vlan + _basic_mlag + _basic_vxlan + _basic_end
95
96 def _get_vlan(self, uuid, vlan_id, vni_id, s_type):
97 if self.topology == self._VLAN:
98 return self._configLet_VLAN.format(service=s_type, vlan=vlan_id, uuid=uuid)
99
100 if self.topology == self._VLAN_MLAG:
101 return self._configLet_VLAN_MLAG.format(
102 service=s_type, vlan=vlan_id, uuid=uuid
103 )
104
105 if self.topology == self._VXLAN:
106 return self._configLet_VXLAN.format(
107 service=s_type, vlan=vlan_id, uuid=uuid, vni=vni_id
108 )
109
110 if self.topology == self._VXLAN_MLAG:
111 return self._configLet_VXLAN_MLAG.format(
112 service=s_type, vlan=vlan_id, uuid=uuid, vni=vni_id
113 )
114
115 def getElan_vlan(self, uuid, vlan_id, vni_id):
116 return self._get_vlan(uuid, vlan_id, vni_id, "ELAN")
117
118 def getEline_vlan(self, uuid, vlan_id, vni_id):
119 return self._get_vlan(uuid, vlan_id, vni_id, "ELINE")
120
121 _configLet_BGP = """
122 router bgp {bgp}
123 vlan {vlan}
124 !! service: {uuid}
125 rd {loopback}:{vni}
126 route-target both {vni}:{vni}
127 redistribute learned
128 !
129 """
130
131 def _get_bgp(self, uuid, vlan_id, vni_id, loopback0, bgp, s_type):
132 if self.topology == self._VXLAN or self.topology == self._VXLAN_MLAG:
133 return self._configLet_BGP.format(
134 uuid=uuid, bgp=bgp, vlan=vlan_id, loopback=loopback0, vni=vni_id
135 )
136
137 def getElan_bgp(self, uuid, vlan_id, vni_id, loopback0, bgp):
138 return self._get_bgp(uuid, vlan_id, vni_id, loopback0, bgp, "ELAN")
139
140 def getEline_bgp(self, uuid, vlan_id, vni_id, loopback0, bgp):
141 return self._get_bgp(uuid, vlan_id, vni_id, loopback0, bgp, "ELINE")