Skip to content

Commit fe3f38b

Browse files
authored
Add switch to add VTEP with no VXLAN tunnel maps configured (#18)
1 parent d1b511c commit fe3f38b

File tree

7 files changed

+69
-56
lines changed

7 files changed

+69
-56
lines changed

configdb/configdb.go

Lines changed: 42 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,13 @@ type ConfigDB struct {
4343
}
4444

4545
func GenerateConfigDB(input *values.Values, platform *p.Platform, currentDeviceMetadata DeviceMetadata) (*ConfigDB, error) {
46+
if input == nil {
47+
return nil, fmt.Errorf("no input values provided")
48+
}
49+
if platform == nil {
50+
return nil, fmt.Errorf("no platform information provided")
51+
}
52+
4653
ports, breakouts, err := getPortsAndBreakouts(input.Ports, input.Breakouts, platform)
4754
if err != nil {
4855
return nil, err
@@ -55,25 +62,22 @@ func GenerateConfigDB(input *values.Values, platform *p.Platform, currentDeviceM
5562

5663
features := getFeatures(input.Features)
5764
rules, tables := getACLRulesAndTables(input.SSHSourceranges)
58-
vxlanevpn, vxlanTunnel, vxlanTunnelMap := getVXLAN(input.VTEPs, input.LoopbackAddress)
65+
vxlanevpn, vxlanTunnel, vxlanTunnelMap := getVXLAN(input.VTEP, input.LoopbackAddress)
5966

6067
configdb := ConfigDB{
61-
ACLRules: rules,
62-
ACLTables: tables,
63-
Breakouts: breakouts,
64-
DeviceMetadata: *deviceMetadata,
65-
DNSNameservers: getDNSNameservers(input.Nameservers),
66-
Features: features,
67-
Interfaces: getInterfaces(input.Ports, input.BGPPorts, input.Interconnects),
68-
LLDP: getLLDP(input.LLDPHelloTime),
69-
LoopbackInterface: map[string]struct{}{
70-
"Loopback0": {},
71-
"Loopback0|" + input.LoopbackAddress + "/32": {},
72-
},
73-
MCLAGDomains: getMCLAGDomains(input.MCLAG),
74-
MCLAGInterfaces: getMCLAGInterfaces(input.MCLAG),
75-
MCLAGUniqueIPs: getMCLAGUniqueIPs(input.MCLAG),
76-
MgmtInterfaces: getMgmtInterfaces(input.MgmtInterface),
68+
ACLRules: rules,
69+
ACLTables: tables,
70+
Breakouts: breakouts,
71+
DeviceMetadata: *deviceMetadata,
72+
DNSNameservers: getDNSNameservers(input.Nameservers),
73+
Features: features,
74+
Interfaces: getInterfaces(input.Ports, input.BGPPorts, input.Interconnects),
75+
LLDP: getLLDP(input.LLDPHelloTime),
76+
LoopbackInterface: getLoopbackInterface(input.LoopbackAddress),
77+
MCLAGDomains: getMCLAGDomains(input.MCLAG),
78+
MCLAGInterfaces: getMCLAGInterfaces(input.MCLAG),
79+
MCLAGUniqueIPs: getMCLAGUniqueIPs(input.MCLAG),
80+
MgmtInterfaces: getMgmtInterfaces(input.MgmtInterface),
7781
MgmtPorts: map[string]MgmtPort{
7882
"eth0": {
7983
AdminStatus: AdminStatusUp,
@@ -163,18 +167,16 @@ func getACLRulesAndTables(sourceRanges []string) (map[string]ACLRule, map[string
163167
}
164168

165169
func getDeviceMetadata(input *values.Values, currentMetadata DeviceMetadata) (*DeviceMetadata, error) {
166-
hint := "remove current config_db.json and run `config-setup factory` to generate an initial config_db.json with all the necessary information"
167-
168170
if currentMetadata.Localhost.Platform == "" {
169-
return nil, fmt.Errorf("missing platform from current device metadata\nhint: %s", hint)
171+
return nil, fmt.Errorf("missing platform from current device metadata")
170172
}
171173

172174
if currentMetadata.Localhost.HWSKU == "" {
173-
return nil, fmt.Errorf("missing hwsku from current device metadata\nhint: %s", hint)
175+
return nil, fmt.Errorf("missing hwsku from current device metadata")
174176
}
175177

176178
if currentMetadata.Localhost.MAC == "" {
177-
return nil, fmt.Errorf("missing mac from current device metadata\nhint: %s", hint)
179+
return nil, fmt.Errorf("missing mac from current device metadata")
178180
}
179181

180182
return &DeviceMetadata{
@@ -265,6 +267,17 @@ func getLLDP(interval int) *LLDP {
265267
}
266268
}
267269

270+
func getLoopbackInterface(loopback string) map[string]struct{} {
271+
if loopback == "" {
272+
return nil
273+
}
274+
275+
return map[string]struct{}{
276+
"Loopback0": {},
277+
fmt.Sprintf("Loopback0|%s/32", loopback): {},
278+
}
279+
}
280+
268281
func getMCLAGDomains(mclag values.MCLAG) map[string]MCLAGDomain {
269282
if mclag.KeepaliveVLAN == "" {
270283
return nil
@@ -549,8 +562,12 @@ func getVRFs(interconnects map[string]values.Interconnect, ports values.Ports, v
549562
return vrfs
550563
}
551564

552-
func getVXLAN(vteps []values.VTEP, loopback string) (*VXLANEVPN, map[string]VXLANTunnel, VXLANTunnelMap) {
553-
if len(vteps) == 0 {
565+
func getVXLAN(vtep values.VTEP, loopback string) (*VXLANEVPN, map[string]VXLANTunnel, VXLANTunnelMap) {
566+
if !vtep.Enabled && len(vtep.VXLANTunnelMaps) == 0 {
567+
return nil, nil, nil
568+
}
569+
570+
if loopback == "" {
554571
return nil, nil, nil
555572
}
556573

@@ -568,7 +585,7 @@ func getVXLAN(vteps []values.VTEP, loopback string) (*VXLANEVPN, map[string]VXLA
568585

569586
vxlanTunnelMap := make(VXLANTunnelMap)
570587

571-
for _, vtep := range vteps {
588+
for _, vtep := range vtep.VXLANTunnelMaps {
572589
vxlanTunnelMap["vtep|map_"+vtep.VNI+"_"+vtep.VLAN] = VXLANTunnelMapEntry{
573590
VLAN: vtep.VLAN,
574591
VNI: vtep.VNI,

tests/1/sonic-config.yaml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ vlans:
101101
vrf: Vrf45
102102
- id: 4001
103103

104-
vteps:
105-
- vni: 103999
106-
vlan: Vlan3999
104+
vtep:
105+
vxlan_tunnel_maps:
106+
- vni: 103999
107+
vlan: Vlan3999

tests/2/expected.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,5 +522,15 @@
522522
"Vlan4000": {},
523523
"Vlan4000|10.9.7.0": {},
524524
"Vlan4001": {}
525+
},
526+
"VXLAN_EVPN_NVO": {
527+
"nvo": {
528+
"source_vtep": "vtep"
529+
}
530+
},
531+
"VXLAN_TUNNEL": {
532+
"vtep": {
533+
"src_ip": "10.7.7.7"
534+
}
525535
}
526536
}

tests/2/sonic-config.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,6 @@ vlans:
5555
- 10.9.8.6
5656
ip: 10.9.7.0
5757
- id: 4001
58+
59+
vtep:
60+
enabled: true

tests/3/expected.json

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -187,10 +187,6 @@
187187
"vrf_name": "VrfInternet"
188188
}
189189
},
190-
"LOOPBACK_INTERFACE": {
191-
"Loopback0": {},
192-
"Loopback0|10.0.0.2/32": {}
193-
},
194190
"MGMT_PORT": {
195191
"eth0": {
196192
"admin_status": "up",
@@ -720,21 +716,5 @@
720716
},
721717
"VRF": {
722718
"VrfInternet": {}
723-
},
724-
"VXLAN_EVPN_NVO": {
725-
"nvo": {
726-
"source_vtep": "vtep"
727-
}
728-
},
729-
"VXLAN_TUNNEL": {
730-
"vtep": {
731-
"src_ip": "10.0.0.2"
732-
}
733-
},
734-
"VXLAN_TUNNEL_MAP": {
735-
"vtep|map_104009_Vlan4009": {
736-
"vlan": "Vlan4009",
737-
"vni": "104009"
738-
}
739719
}
740720
}

tests/3/sonic-config.yaml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
---
21
bgp_ports:
32
- Ethernet0
43
- Ethernet1
54

65
docker_routing_config_mode: split
76
frr_mgmt_framework_config: true
87
hostname: mgmtspine
9-
loopback_address: 10.0.0.2
108
mgmt_vrf: false
119

1210
ntp:
@@ -46,6 +44,5 @@ vlans:
4644
- Ethernet47
4745
- id: 4009
4846

49-
vteps:
50-
- vni: 104009
51-
vlan: Vlan4009
47+
vtep:
48+
enabled: true

values/values.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,15 @@ type MgmtInterface struct {
5151
}
5252

5353
type NTP struct {
54-
SrcInterface string `yaml:"src_interface"`
5554
Servers []string `yaml:"servers"`
55+
SrcInterface string `yaml:"src_interface"`
5656
VRF string `yaml:"vrf"`
5757
}
5858

5959
type Port struct {
6060
Autoneg AutonegMode `yaml:"autoneg"`
61-
IPs []string `yaml:"ips"`
6261
FECMode FECMode `yaml:"fec"`
62+
IPs []string `yaml:"ips"`
6363
MTU int `yaml:"mtu"`
6464
Name string `yaml:"name"`
6565
Speed int `yaml:"speed"`
@@ -109,7 +109,7 @@ type Values struct {
109109
SAG SAG `yaml:"sag"`
110110
SSHSourceranges []string `yaml:"ssh_sourceranges"`
111111
VLANs []VLAN `yaml:"vlans"`
112-
VTEPs []VTEP `yaml:"vteps"`
112+
VTEP VTEP `yaml:"vtep"`
113113
}
114114

115115
type VLAN struct {
@@ -123,6 +123,11 @@ type VLAN struct {
123123
}
124124

125125
type VTEP struct {
126+
Enabled bool `yaml:"enabled"`
127+
VXLANTunnelMaps []VXLANTunnelMap `yaml:"vxlan_tunnel_maps"`
128+
}
129+
130+
type VXLANTunnelMap struct {
126131
VNI string `yaml:"vni"`
127132
VLAN string `yaml:"vlan"`
128133
}

0 commit comments

Comments
 (0)