1 # -*- coding: utf-8 -*-
3 # Copyright 2019 Atos - CoE Telco NFV Team
6 # Contributors: Oscar Luis Peral, Atos
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
12 # http://www.apache.org/licenses/LICENSE-2.0
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
20 # For those usages not covered by the Apache License, Version 2.0 please
21 # contact with: <oscarluis.peral@atos.net>
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.
27 # This work has been performed in the context of Arista Telefonica OSM PoC.
31 class AristaSDNConfigLet
:
34 _VLAN_MLAG
= "VLAN-MLAG"
35 _VXLAN_MLAG
= "VXLAN-MLAG"
36 topology
= _VXLAN_MLAG
38 def __init__(self
, topology
=_VXLAN_MLAG
):
39 self
.topology
= topology
45 switchport mode {type}
46 switchport {switchport_def}
49 _int_SRIOV
= "trunk group {service}{vlan_id}"
50 _int_PASSTROUGH
= "access vlan {vlan_id}"
52 def _get_interface(self
, uuid
, interface
, vlan_id
, s_type
, index
, i_type
):
54 switchport_def
= self
._int
_SRIOV
.format(service
=s_type
, vlan_id
=vlan_id
)
56 switchport_def
= self
._int
_PASSTROUGH
.format(vlan_id
=vlan_id
)
57 return self
._basic
_int
.format(uuid
=uuid
,
60 switchport_def
=switchport_def
)
62 def getElan_sriov(self
, uuid
, interface
, vlan_id
, index
):
63 return self
._get
_interface
(uuid
, interface
, vlan_id
, "ELAN", index
, "trunk")
65 def getEline_sriov(self
, uuid
, interface
, vlan_id
, index
):
66 return self
._get
_interface
(uuid
, interface
, vlan_id
, "ELINE", index
, "trunk")
68 def getElan_passthrough(self
, uuid
, interface
, vlan_id
, index
):
69 return self
._get
_interface
(uuid
, interface
, vlan_id
, "ELAN", index
, "dot1q-tunnel")
71 def getEline_passthrough(self
, uuid
, interface
, vlan_id
, index
):
72 return self
._get
_interface
(uuid
, interface
, vlan_id
, "ELINE", index
, "dot1q-tunnel")
76 !! service: {service} {vlan} {uuid}
78 trunk group {service}{vlan}
80 _basic_mlag
= """ trunk group MLAGPEER
82 _basic_vxlan
= """interface VXLAN1
83 VXLAN vlan {vlan} vni {vni}
87 _configLet_VLAN
= _basic_vlan
+ _basic_end
88 _configLet_VXLAN
= _basic_vlan
+ _basic_vxlan
+ _basic_end
89 _configLet_VLAN_MLAG
= _basic_vlan
+ _basic_mlag
+ _basic_end
90 _configLet_VXLAN_MLAG
= _basic_vlan
+ _basic_mlag
+ _basic_vxlan
+ _basic_end
92 def _get_vlan(self
, uuid
, vlan_id
, vni_id
, s_type
):
93 if self
.topology
== self
._VLAN
:
94 return self
._configLet
_VLAN
.format(service
=s_type
, vlan
=vlan_id
, uuid
=uuid
)
95 if self
.topology
== self
._VLAN
_MLAG
:
96 return self
._configLet
_VLAN
_MLAG
.format(service
=s_type
, vlan
=vlan_id
, uuid
=uuid
)
97 if self
.topology
== self
._VXLAN
:
98 return self
._configLet
_VXLAN
.format(service
=s_type
, vlan
=vlan_id
, uuid
=uuid
, vni
=vni_id
)
99 if self
.topology
== self
._VXLAN
_MLAG
:
100 return self
._configLet
_VXLAN
_MLAG
.format(service
=s_type
, vlan
=vlan_id
, uuid
=uuid
, vni
=vni_id
)
102 def getElan_vlan(self
, uuid
, vlan_id
, vni_id
):
103 return self
._get
_vlan
(uuid
, vlan_id
, vni_id
, "ELAN")
105 def getEline_vlan(self
, uuid
, vlan_id
, vni_id
):
106 return self
._get
_vlan
(uuid
, vlan_id
, vni_id
, "ELINE")
113 route-target both {vni}:{vni}
118 def _get_bgp(self
, uuid
, vlan_id
, vni_id
, loopback0
, bgp
, s_type
):
119 if self
.topology
== self
._VXLAN
or self
.topology
== self
._VXLAN
_MLAG
:
120 return self
._configLet
_BGP
.format(uuid
=uuid
,
126 def getElan_bgp(self
, uuid
, vlan_id
, vni_id
, loopback0
, bgp
):
127 return self
._get
_bgp
(uuid
, vlan_id
, vni_id
, loopback0
, bgp
, "ELAN")
129 def getEline_bgp(self
, uuid
, vlan_id
, vni_id
, loopback0
, bgp
):
130 return self
._get
_bgp
(uuid
, vlan_id
, vni_id
, loopback0
, bgp
, "ELINE")