Skip to content

Commit 2484803

Browse files
committed
Add switch to add VTEP even with no VXLAN tunnel maps configured
1 parent d1b511c commit 2484803

File tree

7 files changed

+68
-47
lines changed

7 files changed

+68
-47
lines changed

configdb/configdb.go

Lines changed: 39 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,18 @@ func getLLDP(interval int) *LLDP {
265267
}
266268
}
267269

270+
func getLoopbackInterface(loopback string) map[string]struct{} {
271+
loopbackInterface := map[string]struct{}{
272+
"Loopback0": {},
273+
}
274+
275+
if loopback != "" {
276+
loopbackInterface[fmt.Sprintf("Loopback0|%s/32", loopback)] = struct{}{}
277+
}
278+
279+
return loopbackInterface
280+
}
281+
268282
func getMCLAGDomains(mclag values.MCLAG) map[string]MCLAGDomain {
269283
if mclag.KeepaliveVLAN == "" {
270284
return nil
@@ -549,8 +563,8 @@ func getVRFs(interconnects map[string]values.Interconnect, ports values.Ports, v
549563
return vrfs
550564
}
551565

552-
func getVXLAN(vteps []values.VTEP, loopback string) (*VXLANEVPN, map[string]VXLANTunnel, VXLANTunnelMap) {
553-
if len(vteps) == 0 {
566+
func getVXLAN(vtep values.VTEP, loopback string) (*VXLANEVPN, map[string]VXLANTunnel, VXLANTunnelMap) {
567+
if !vtep.AddVTEP && len(vtep.VXLANTunnelMaps) == 0 {
554568
return nil, nil, nil
555569
}
556570

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

569583
vxlanTunnelMap := make(VXLANTunnelMap)
570584

571-
for _, vtep := range vteps {
585+
for _, vtep := range vtep.VXLANTunnelMaps {
572586
vxlanTunnelMap["vtep|map_"+vtep.VNI+"_"+vtep.VLAN] = VXLANTunnelMapEntry{
573587
VLAN: vtep.VLAN,
574588
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+
add_vtep: true

tests/3/expected.json

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,7 @@
188188
}
189189
},
190190
"LOOPBACK_INTERFACE": {
191-
"Loopback0": {},
192-
"Loopback0|10.0.0.2/32": {}
191+
"Loopback0": {}
193192
},
194193
"MGMT_PORT": {
195194
"eth0": {
@@ -727,14 +726,6 @@
727726
}
728727
},
729728
"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-
}
729+
"vtep": {}
739730
}
740731
}

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+
add_vtep: 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+
AddVTEP bool `yaml:"add_vtep"`
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)