Skip to content

Commit e0bcec5

Browse files
committed
disallow sag on vlan interfaces if sonic version is not from branch 202211
1 parent 6ba4fdb commit e0bcec5

File tree

6 files changed

+36
-17
lines changed

6 files changed

+36
-17
lines changed

configdb/configdb.go

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,11 @@ func GenerateConfigDB(input *values.Values, platform *p.Platform, environment *p
7171
return nil, err
7272
}
7373

74+
vlanInterfaces, err := getVLANInterfaces(input.VLANs, version)
75+
if err != nil {
76+
return nil, err
77+
}
78+
7479
configdb := ConfigDB{
7580
ACLRules: rules,
7681
ACLTables: tables,
@@ -105,7 +110,7 @@ func GenerateConfigDB(input *values.Values, platform *p.Platform, environment *p
105110
PortChannelMembers: getPortChannelMembers(input.PortChannels.List),
106111
SAG: sag,
107112
VLANs: getVLANs(input.VLANs),
108-
VLANInterfaces: getVLANInterfaces(input.VLANs),
113+
VLANInterfaces: vlanInterfaces,
109114
VLANMembers: getVLANMembers(input.VLANs),
110115
VLANSubinterfaces: getVLANSubinterfaces(input.VLANSubinterfaces),
111116
VRFs: getVRFs(input.Interconnects, input.Ports, input.VLANs),
@@ -493,7 +498,7 @@ func getPortsAndBreakouts(ports values.Ports, breakouts map[string]string, platf
493498
}
494499

495500
func getSAG(sag values.SAG, version *v.Version) (*SAG, error) {
496-
if version.Branch != string(v.Branch202211) {
501+
if version.Branch != string(v.Branch202211) && sag.MAC != "" {
497502
return nil, fmt.Errorf("sag configuration only works with sonic versions from the ec202211 branch")
498503
}
499504

@@ -521,15 +526,23 @@ func getVLANs(vlans []values.VLAN) map[string]VLAN {
521526
return configVLANs
522527
}
523528

524-
func getVLANInterfaces(vlans []values.VLAN) map[string]VLANInterface {
529+
func getVLANInterfaces(vlans []values.VLAN, version *v.Version) (map[string]VLANInterface, error) {
525530
vlanInterfaces := make(map[string]VLANInterface)
526531

527532
for _, vlan := range vlans {
528533
var vlanInterface VLANInterface
529534

535+
if version.Branch != string(v.Branch202211) && vlan.SAG != nil {
536+
return nil, fmt.Errorf("sag only works for sonic builds from branch 202211")
537+
}
538+
var sag string
539+
if vlan.SAG != nil {
540+
sag = strconv.FormatBool(*vlan.SAG)
541+
}
542+
530543
if vlan.VRF != "" {
531544
vlanInterface = VLANInterface{
532-
StaticAnycastGateway: strconv.FormatBool(vlan.SAG),
545+
StaticAnycastGateway: sag,
533546
VRFName: vlan.VRF,
534547
}
535548
}
@@ -541,7 +554,7 @@ func getVLANInterfaces(vlans []values.VLAN) map[string]VLANInterface {
541554
vlanInterfaces["Vlan"+vlan.ID+"|"+vlan.IP] = VLANInterface{}
542555
}
543556

544-
return vlanInterfaces
557+
return vlanInterfaces, nil
545558
}
546559

547560
func getVLANMembers(vlans []values.VLAN) map[string]VLANMember {

tests/1/expected.json

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -582,11 +582,6 @@
582582
"PortChannel01|Ethernet4": {},
583583
"PortChannel01|Ethernet5": {}
584584
},
585-
"SAG": {
586-
"GLOBAL": {
587-
"gateway_mac": "bb:bb:bb:bb:bb:bb"
588-
}
589-
},
590585
"VLAN": {
591586
"Vlan4000": {
592587
"dhcp_servers": [
@@ -601,7 +596,6 @@
601596
},
602597
"VLAN_INTERFACE": {
603598
"Vlan4000": {
604-
"static_anycast_gateway": "true",
605599
"vrf_name": "Vrf45"
606600
},
607601
"Vlan4000|10.9.7.0": {},

tests/1/sonic-config.yaml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,6 @@ ports:
8787
vrf: VrfInternet
8888
- name: Ethernet120
8989

90-
sag:
91-
mac: bb:bb:bb:bb:bb:bb
92-
9390
ssh_sourceranges:
9491
- 10.1.23.1/30
9592

@@ -99,7 +96,6 @@ vlans:
9996
- 10.9.8.7
10097
- 10.9.8.6
10198
ip: 10.9.7.0
102-
sag: true
10399
tagged_ports:
104100
- PortChannel01
105101
untagged_ports:

tests/4/expected.json

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -642,13 +642,21 @@
642642
"speed": "1000"
643643
}
644644
},
645+
"SAG": {
646+
"GLOBAL": {
647+
"gateway_mac": "bb:bb:bb:bb:bb:bb"
648+
}
649+
},
645650
"VLAN": {
646651
"Vlan4000": {
647652
"vlanid": "4000"
648653
}
649654
},
650655
"VLAN_INTERFACE": {
651-
"Vlan4000": {},
656+
"Vlan4000": {
657+
"static_anycast_gateway": "true",
658+
"vrf_name": "Vrf45"
659+
},
652660
"Vlan4000|10.255.1.1/24": {}
653661
},
654662
"VLAN_SUB_INTERFACE": {
@@ -657,5 +665,8 @@
657665
"vrf_name": "Vrf45"
658666
},
659667
"Ethernet0.1000|1.2.3.0/24": {}
668+
},
669+
"VRF": {
670+
"Vrf45": {}
660671
}
661672
}

tests/4/sonic-config.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ ntp:
1515
- 162.159.200.1
1616
- 162.159.200.123
1717

18+
sag:
19+
mac: bb:bb:bb:bb:bb:bb
20+
1821
vlan_subinterfaces:
1922
- cidr: 1.2.3.0/24
2023
port: Ethernet0
@@ -24,3 +27,5 @@ vlan_subinterfaces:
2427
vlans:
2528
- id: 4000
2629
ip: 10.255.1.1/24
30+
sag: true
31+
vrf: Vrf45

values/values.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ type VLAN struct {
124124
DHCPServers []string `yaml:"dhcp_servers"`
125125
ID string `yaml:"id"`
126126
IP string `yaml:"ip"`
127-
SAG bool `yaml:"sag"`
127+
SAG *bool `yaml:"sag"`
128128
TaggedPorts []string `yaml:"tagged_ports"`
129129
UntaggedPorts []string `yaml:"untagged_ports"`
130130
VRF string `yaml:"vrf"`

0 commit comments

Comments
 (0)