77 "slices"
88 "strconv"
99
10- "github.com/metal-stack/sonic-configdb-utils/platform"
1110 p "github.com/metal-stack/sonic-configdb-utils/platform"
1211 "github.com/metal-stack/sonic-configdb-utils/values"
12+ v "github.com/metal-stack/sonic-configdb-utils/version"
1313)
1414
1515type ConfigDB struct {
@@ -44,7 +44,7 @@ type ConfigDB struct {
4444 VXLANTunnelMap VXLANTunnelMap `json:"VXLAN_TUNNEL_MAP,omitempty"`
4545}
4646
47- func GenerateConfigDB (input * values.Values , platform * p.Platform , environment * platform .Environment ) (* ConfigDB , error ) {
47+ func GenerateConfigDB (input * values.Values , platform * p.Platform , environment * p .Environment , version * v. Version ) (* ConfigDB , error ) {
4848 if input == nil {
4949 return nil , fmt .Errorf ("no input values provided" )
5050 }
@@ -66,6 +66,16 @@ func GenerateConfigDB(input *values.Values, platform *p.Platform, environment *p
6666 rules , tables := getACLRulesAndTables (input .SSHSourceranges )
6767 vxlanevpn , vxlanTunnel , vxlanTunnelMap := getVXLAN (input .VTEP , input .LoopbackAddress )
6868
69+ sag , err := getSAG (input .SAG , version )
70+ if err != nil {
71+ return nil , err
72+ }
73+
74+ vlanInterfaces , err := getVLANInterfaces (input .VLANs , version )
75+ if err != nil {
76+ return nil , err
77+ }
78+
6979 configdb := ConfigDB {
7080 ACLRules : rules ,
7181 ACLTables : tables ,
@@ -74,12 +84,13 @@ func GenerateConfigDB(input *values.Values, platform *p.Platform, environment *p
7484 DNSNameservers : getDNSNameservers (input .Nameservers ),
7585 Features : features ,
7686 Interfaces : getInterfaces (input .Ports , input .BGPPorts , input .Interconnects ),
77- LLDP : getLLDP (input .LLDPHelloTime ),
87+ LLDP : getLLDP (input .LLDPHelloTime , version ),
7888 LoopbackInterface : getLoopbackInterface (input .LoopbackAddress ),
7989 MCLAGDomains : getMCLAGDomains (input .MCLAG ),
8090 MCLAGInterfaces : getMCLAGInterfaces (input .MCLAG ),
8191 MCLAGUniqueIPs : getMCLAGUniqueIPs (input .MCLAG ),
8292 MgmtInterfaces : getMgmtInterfaces (input .MgmtInterface ),
93+ // FIX: some switches don't have an eth0
8394 MgmtPorts : map [string ]MgmtPort {
8495 "eth0" : {
8596 AdminStatus : AdminStatusUp ,
@@ -97,9 +108,9 @@ func GenerateConfigDB(input *values.Values, platform *p.Platform, environment *p
97108 Ports : ports ,
98109 PortChannels : getPortChannels (input .PortChannels ),
99110 PortChannelMembers : getPortChannelMembers (input .PortChannels .List ),
100- SAG : getSAG ( input . SAG ) ,
111+ SAG : sag ,
101112 VLANs : getVLANs (input .VLANs ),
102- VLANInterfaces : getVLANInterfaces ( input . VLANs ) ,
113+ VLANInterfaces : vlanInterfaces ,
103114 VLANMembers : getVLANMembers (input .VLANs ),
104115 VLANSubinterfaces : getVLANSubinterfaces (input .VLANSubinterfaces ),
105116 VRFs : getVRFs (input .Interconnects , input .Ports , input .VLANs ),
@@ -169,7 +180,7 @@ func getACLRulesAndTables(sourceRanges []string) (map[string]ACLRule, map[string
169180 return rules , tables
170181}
171182
172- func getDeviceMetadata (input * values.Values , environment * platform .Environment ) (* DeviceMetadata , error ) {
183+ func getDeviceMetadata (input * values.Values , environment * p .Environment ) (* DeviceMetadata , error ) {
173184 if environment .Platform == "" {
174185 return nil , fmt .Errorf ("no platform identifiert found in environment file" )
175186 }
@@ -266,15 +277,28 @@ func getInterfaces(ports values.Ports, bgpPorts []string, interconnects map[stri
266277 return interfaces
267278}
268279
269- func getLLDP (interval int ) * LLDP {
280+ func getLLDP (interval int , version * v. Version ) * LLDP {
270281 if interval < 1 {
271282 return nil
272283 }
273- return & LLDP {
274- Global : LLDPGlobal {
275- HelloTime : fmt .Sprintf ("%d" , interval ),
276- },
284+
285+ lldp := & LLDP {}
286+ global := LLDPGlobal {
287+ HelloTime : fmt .Sprintf ("%d" , interval ),
288+ }
289+
290+ switch version .Branch {
291+ case string (v .Branch202111 ):
292+ global202111 := LLDPGlobal202111 (global )
293+ lldp .Global202111 = & global202111
294+ case string (v .Branch202211 ):
295+ global202211 := LLDPGlobal202211 (global )
296+ lldp .Global202211 = & global202211
297+ default :
298+ lldp = nil
277299 }
300+
301+ return lldp
278302}
279303
280304func getLoopbackInterface (loopback string ) map [string ]struct {} {
@@ -473,16 +497,20 @@ func getPortsAndBreakouts(ports values.Ports, breakouts map[string]string, platf
473497 return configPorts , configBreakouts , nil
474498}
475499
476- func getSAG (sag values.SAG ) * SAG {
477- if sag .MAC == "" {
478- return nil
500+ func getSAG (sag * values.SAG , version * v.Version ) (* SAG , error ) {
501+ if version .Branch != string (v .Branch202211 ) && sag != nil {
502+ return nil , fmt .Errorf ("sag configuration only works with sonic versions from the ec202211 branch" )
503+ }
504+
505+ if sag == nil || sag .MAC == "" {
506+ return nil , nil
479507 }
480508
481509 return & SAG {
482510 SAGGlobal : SAGGlobal {
483511 GatewayMAC : sag .MAC ,
484512 },
485- }
513+ }, nil
486514}
487515
488516func getVLANs (vlans []values.VLAN ) map [string ]VLAN {
@@ -498,15 +526,23 @@ func getVLANs(vlans []values.VLAN) map[string]VLAN {
498526 return configVLANs
499527}
500528
501- func getVLANInterfaces (vlans []values.VLAN ) map [string ]VLANInterface {
529+ func getVLANInterfaces (vlans []values.VLAN , version * v. Version ) ( map [string ]VLANInterface , error ) {
502530 vlanInterfaces := make (map [string ]VLANInterface )
503531
504532 for _ , vlan := range vlans {
505533 var vlanInterface VLANInterface
506534
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+
507543 if vlan .VRF != "" {
508544 vlanInterface = VLANInterface {
509- StaticAnycastGateway : strconv . FormatBool ( vlan . SAG ) ,
545+ StaticAnycastGateway : sag ,
510546 VRFName : vlan .VRF ,
511547 }
512548 }
@@ -518,7 +554,7 @@ func getVLANInterfaces(vlans []values.VLAN) map[string]VLANInterface {
518554 vlanInterfaces ["Vlan" + vlan .ID + "|" + vlan .IP ] = VLANInterface {}
519555 }
520556
521- return vlanInterfaces
557+ return vlanInterfaces , nil
522558}
523559
524560func getVLANMembers (vlans []values.VLAN ) map [string ]VLANMember {
0 commit comments