From b3432311f8373786b86250913dd68e84e6a721fd Mon Sep 17 00:00:00 2001 From: simcod Date: Thu, 4 Jul 2024 11:27:55 +0200 Subject: [PATCH 01/13] Make it possible to manually configure VLAN --- cmd/config.go | 1 + cmd/internal/core/core.go | 5 +++++ cmd/internal/core/reconfigure-switch.go | 16 ++++++++++++---- cmd/internal/switcher/sonic/redis/applier.go | 9 ++++++--- cmd/internal/switcher/types/types.go | 1 + cmd/internal/vlan/reservation.go | 6 +++--- cmd/server.go | 1 + 7 files changed, 29 insertions(+), 10 deletions(-) diff --git a/cmd/config.go b/cmd/config.go index 20a659a0..d80bf98c 100644 --- a/cmd/config.go +++ b/cmd/config.go @@ -30,4 +30,5 @@ type Config struct { GrpcCACertFile string `required:"false" desc:"the gRPC CA certificate file" envconfig:"grpc_ca_cert_file"` GrpcClientCertFile string `required:"false" desc:"the gRPC client certificate file" envconfig:"grpc_client_cert_file"` GrpcClientKeyFile string `required:"false" desc:"the gRPC client key file" envconfig:"grpc_client_key_file"` + Vlan uint16 `required:"false" desc:"the configuration of the vlan" envconfig:"vlan"` } diff --git a/cmd/internal/core/core.go b/cmd/internal/core/core.go index 972c2c0c..940a572b 100644 --- a/cmd/internal/core/core.go +++ b/cmd/internal/core/core.go @@ -32,6 +32,8 @@ type Core struct { eventServiceClient v1.EventServiceClient metrics *metrics.Metrics + + vlan uint16 } type Config struct { @@ -56,6 +58,8 @@ type Config struct { EventServiceClient v1.EventServiceClient Metrics *metrics.Metrics + + Vlan uint16 } func New(c Config) *Core { @@ -77,5 +81,6 @@ func New(c Config) *Core { driver: c.Driver, eventServiceClient: c.EventServiceClient, metrics: c.Metrics, + vlan: c.Vlan, } } diff --git a/cmd/internal/core/reconfigure-switch.go b/cmd/internal/core/reconfigure-switch.go index 409d139f..27c87f86 100644 --- a/cmd/internal/core/reconfigure-switch.go +++ b/cmd/internal/core/reconfigure-switch.go @@ -116,6 +116,16 @@ func (c *Core) buildSwitcherConfig(s *models.V1SwitchResponse) (*types.Conf, err if err != nil { return nil, err } + + m, err := vlan.ReadMapping() + if err != nil { + return nil, err + } + + if c.vlan >= vlan.VlanIDMin && c.vlan <= vlan.VlanIDMax { + return nil, fmt.Errorf("configured VLAN is in the reserved area of %v, %v", vlan.VlanIDMin, vlan.VlanIDMax) + } + switcherConfig := &types.Conf{ Name: s.Name, LogLevel: mapLogLevel(c.logLevel), @@ -123,6 +133,7 @@ func (c *Core) buildSwitcherConfig(s *models.V1SwitchResponse) (*types.Conf, err Loopback: c.loopbackIP, MetalCoreCIDR: c.cidr, AdditionalBridgeVIDs: c.additionalBridgeVIDs, + Vlan: c.vlan, } p := types.Ports{ @@ -187,10 +198,7 @@ func (c *Core) buildSwitcherConfig(s *models.V1SwitchResponse) (*types.Conf, err c.nos.SanitizeConfig(switcherConfig) switcherConfig.FillRouteMapsAndIPPrefixLists() - m, err := vlan.ReadMapping() - if err != nil { - return nil, err - } + err = switcherConfig.FillVLANIDs(m) if err != nil { return nil, err diff --git a/cmd/internal/switcher/sonic/redis/applier.go b/cmd/internal/switcher/sonic/redis/applier.go index 1c691524..f5af685b 100644 --- a/cmd/internal/switcher/sonic/redis/applier.go +++ b/cmd/internal/switcher/sonic/redis/applier.go @@ -5,6 +5,7 @@ import ( "errors" "fmt" "log/slog" + "strconv" "time" "github.com/google/go-cmp/cmp" @@ -55,7 +56,7 @@ func (a *Applier) Apply(cfg *types.Conf) error { } for _, interfaceName := range cfg.Ports.Unprovisioned { - if err := a.configureUnprovisionedPort(interfaceName, !cfg.Ports.DownPorts[interfaceName]); err != nil { + if err := a.configureUnprovisionedPort(interfaceName, !cfg.Ports.DownPorts[interfaceName], cfg.Vlan); err != nil { errs = append(errs, err) } } @@ -115,7 +116,7 @@ func (a *Applier) refreshOidMaps() error { return nil } -func (a *Applier) configureUnprovisionedPort(interfaceName string, isUp bool) error { +func (a *Applier) configureUnprovisionedPort(interfaceName string, isUp bool, vlan uint16) error { ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) defer cancel() @@ -129,7 +130,9 @@ func (a *Applier) configureUnprovisionedPort(interfaceName string, isUp bool) er return fmt.Errorf("failed to update Port info for interface %s: %w", interfaceName, err) } - return a.ensureInterfaceIsVlanMember(ctx, interfaceName, "Vlan4000") + vl := "Vlan" + strconv.FormatUint(uint64(vlan), 10) + + return a.ensureInterfaceIsVlanMember(ctx, interfaceName, vl) } func (a *Applier) configureFirewallPort(interfaceName string, isUp bool) error { diff --git a/cmd/internal/switcher/types/types.go b/cmd/internal/switcher/types/types.go index 21c4fd27..1a678b05 100644 --- a/cmd/internal/switcher/types/types.go +++ b/cmd/internal/switcher/types/types.go @@ -13,6 +13,7 @@ type Conf struct { Ports Ports MetalCoreCIDR string AdditionalBridgeVIDs []string + Vlan uint16 } type Ports struct { diff --git a/cmd/internal/vlan/reservation.go b/cmd/internal/vlan/reservation.go index c1c95136..a72ad7ce 100644 --- a/cmd/internal/vlan/reservation.go +++ b/cmd/internal/vlan/reservation.go @@ -4,15 +4,15 @@ import "fmt" const ( // vlanIDMin specifies the min VLAN-ID we want to use on our switches - vlanIDMin uint16 = 1001 + VlanIDMin uint16 = 1001 // vlanIDMax specifies the max VLAN-ID we want to use on our switches - vlanIDMax uint16 = 2000 + VlanIDMax uint16 = 2000 ) // ReserveVlanIDs tries to reserve n VLAN-IDs given the current switch configuration func (m Mapping) ReserveVlanIDs(n uint16) ([]uint16, error) { - return m.reserveVlanIDs(vlanIDMin, vlanIDMax, n) + return m.reserveVlanIDs(VlanIDMin, VlanIDMax, n) } func (m Mapping) reserveVlanIDs(min, max, n uint16) ([]uint16, error) { diff --git a/cmd/server.go b/cmd/server.go index fe324215..9094f0e4 100644 --- a/cmd/server.go +++ b/cmd/server.go @@ -101,6 +101,7 @@ func Run() { Driver: driver, EventServiceClient: grpcClient.NewEventClient(), Metrics: metrics, + Vlan: cfg.Vlan, }) err = c.RegisterSwitch() From 7e4ca4fdd46e9472580fd6d84d2144832a0c2b19 Mon Sep 17 00:00:00 2001 From: simcod Date: Thu, 4 Jul 2024 11:57:43 +0200 Subject: [PATCH 02/13] Add default vlan value --- cmd/config.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/config.go b/cmd/config.go index d80bf98c..b6e157a6 100644 --- a/cmd/config.go +++ b/cmd/config.go @@ -30,5 +30,5 @@ type Config struct { GrpcCACertFile string `required:"false" desc:"the gRPC CA certificate file" envconfig:"grpc_ca_cert_file"` GrpcClientCertFile string `required:"false" desc:"the gRPC client certificate file" envconfig:"grpc_client_cert_file"` GrpcClientKeyFile string `required:"false" desc:"the gRPC client key file" envconfig:"grpc_client_key_file"` - Vlan uint16 `required:"false" desc:"the configuration of the vlan" envconfig:"vlan"` + Vlan uint16 `required:"false" default:"4000" desc:"the configuration of the vlan" envconfig:"vlan"` } From c95a201da5ba24c333ebb69cc8a49be59f02302a Mon Sep 17 00:00:00 2001 From: simcod Date: Thu, 4 Jul 2024 14:40:39 +0200 Subject: [PATCH 03/13] Adjust naming --- cmd/config.go | 2 +- cmd/internal/core/core.go | 6 +++--- cmd/internal/core/reconfigure-switch.go | 14 ++++++-------- cmd/internal/switcher/sonic/redis/applier.go | 6 +++--- cmd/internal/switcher/types/types.go | 2 +- cmd/server.go | 2 +- 6 files changed, 15 insertions(+), 17 deletions(-) diff --git a/cmd/config.go b/cmd/config.go index b6e157a6..05fa828d 100644 --- a/cmd/config.go +++ b/cmd/config.go @@ -30,5 +30,5 @@ type Config struct { GrpcCACertFile string `required:"false" desc:"the gRPC CA certificate file" envconfig:"grpc_ca_cert_file"` GrpcClientCertFile string `required:"false" desc:"the gRPC client certificate file" envconfig:"grpc_client_cert_file"` GrpcClientKeyFile string `required:"false" desc:"the gRPC client key file" envconfig:"grpc_client_key_file"` - Vlan uint16 `required:"false" default:"4000" desc:"the configuration of the vlan" envconfig:"vlan"` + PXEVlan uint16 `required:"false" default:"4000" desc:"the configuration of the pxe vlan" envconfig:"pxe_vlan"` } diff --git a/cmd/internal/core/core.go b/cmd/internal/core/core.go index 940a572b..e85e0ef5 100644 --- a/cmd/internal/core/core.go +++ b/cmd/internal/core/core.go @@ -33,7 +33,7 @@ type Core struct { metrics *metrics.Metrics - vlan uint16 + pxeVlan uint16 } type Config struct { @@ -59,7 +59,7 @@ type Config struct { Metrics *metrics.Metrics - Vlan uint16 + PXEVlan uint16 } func New(c Config) *Core { @@ -81,6 +81,6 @@ func New(c Config) *Core { driver: c.Driver, eventServiceClient: c.EventServiceClient, metrics: c.Metrics, - vlan: c.Vlan, + pxeVlan: c.PXEVlan, } } diff --git a/cmd/internal/core/reconfigure-switch.go b/cmd/internal/core/reconfigure-switch.go index 27c87f86..9697416f 100644 --- a/cmd/internal/core/reconfigure-switch.go +++ b/cmd/internal/core/reconfigure-switch.go @@ -117,12 +117,7 @@ func (c *Core) buildSwitcherConfig(s *models.V1SwitchResponse) (*types.Conf, err return nil, err } - m, err := vlan.ReadMapping() - if err != nil { - return nil, err - } - - if c.vlan >= vlan.VlanIDMin && c.vlan <= vlan.VlanIDMax { + if c.pxeVlan >= vlan.VlanIDMin && c.pxeVlan <= vlan.VlanIDMax { return nil, fmt.Errorf("configured VLAN is in the reserved area of %v, %v", vlan.VlanIDMin, vlan.VlanIDMax) } @@ -133,7 +128,7 @@ func (c *Core) buildSwitcherConfig(s *models.V1SwitchResponse) (*types.Conf, err Loopback: c.loopbackIP, MetalCoreCIDR: c.cidr, AdditionalBridgeVIDs: c.additionalBridgeVIDs, - Vlan: c.vlan, + PXEVlan: c.pxeVlan, } p := types.Ports{ @@ -198,7 +193,10 @@ func (c *Core) buildSwitcherConfig(s *models.V1SwitchResponse) (*types.Conf, err c.nos.SanitizeConfig(switcherConfig) switcherConfig.FillRouteMapsAndIPPrefixLists() - + m, err := vlan.ReadMapping() + if err != nil { + return nil, err + } err = switcherConfig.FillVLANIDs(m) if err != nil { return nil, err diff --git a/cmd/internal/switcher/sonic/redis/applier.go b/cmd/internal/switcher/sonic/redis/applier.go index f5af685b..7058262f 100644 --- a/cmd/internal/switcher/sonic/redis/applier.go +++ b/cmd/internal/switcher/sonic/redis/applier.go @@ -56,7 +56,7 @@ func (a *Applier) Apply(cfg *types.Conf) error { } for _, interfaceName := range cfg.Ports.Unprovisioned { - if err := a.configureUnprovisionedPort(interfaceName, !cfg.Ports.DownPorts[interfaceName], cfg.Vlan); err != nil { + if err := a.configureUnprovisionedPort(interfaceName, !cfg.Ports.DownPorts[interfaceName], cfg.PXEVlan); err != nil { errs = append(errs, err) } } @@ -116,7 +116,7 @@ func (a *Applier) refreshOidMaps() error { return nil } -func (a *Applier) configureUnprovisionedPort(interfaceName string, isUp bool, vlan uint16) error { +func (a *Applier) configureUnprovisionedPort(interfaceName string, isUp bool, pxeVlan uint16) error { ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) defer cancel() @@ -130,7 +130,7 @@ func (a *Applier) configureUnprovisionedPort(interfaceName string, isUp bool, vl return fmt.Errorf("failed to update Port info for interface %s: %w", interfaceName, err) } - vl := "Vlan" + strconv.FormatUint(uint64(vlan), 10) + vl := "Vlan" + strconv.FormatUint(uint64(pxeVlan), 10) return a.ensureInterfaceIsVlanMember(ctx, interfaceName, vl) } diff --git a/cmd/internal/switcher/types/types.go b/cmd/internal/switcher/types/types.go index 1a678b05..62d4f64b 100644 --- a/cmd/internal/switcher/types/types.go +++ b/cmd/internal/switcher/types/types.go @@ -13,7 +13,7 @@ type Conf struct { Ports Ports MetalCoreCIDR string AdditionalBridgeVIDs []string - Vlan uint16 + PXEVlan uint16 } type Ports struct { diff --git a/cmd/server.go b/cmd/server.go index 9094f0e4..283624e7 100644 --- a/cmd/server.go +++ b/cmd/server.go @@ -101,7 +101,7 @@ func Run() { Driver: driver, EventServiceClient: grpcClient.NewEventClient(), Metrics: metrics, - Vlan: cfg.Vlan, + PXEVlan: cfg.PXEVlan, }) err = c.RegisterSwitch() From a1df785fbb5d21d607dd0c3ffcae88c1c36c8583 Mon Sep 17 00:00:00 2001 From: simcod Date: Fri, 5 Jul 2024 07:52:12 +0200 Subject: [PATCH 04/13] Renaming --- cmd/config.go | 2 +- cmd/internal/core/core.go | 6 +++--- cmd/internal/core/reconfigure-switch.go | 4 ++-- cmd/internal/switcher/sonic/redis/applier.go | 8 ++++---- cmd/internal/switcher/types/types.go | 2 +- cmd/server.go | 2 +- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/cmd/config.go b/cmd/config.go index 05fa828d..84bb4864 100644 --- a/cmd/config.go +++ b/cmd/config.go @@ -30,5 +30,5 @@ type Config struct { GrpcCACertFile string `required:"false" desc:"the gRPC CA certificate file" envconfig:"grpc_ca_cert_file"` GrpcClientCertFile string `required:"false" desc:"the gRPC client certificate file" envconfig:"grpc_client_cert_file"` GrpcClientKeyFile string `required:"false" desc:"the gRPC client key file" envconfig:"grpc_client_key_file"` - PXEVlan uint16 `required:"false" default:"4000" desc:"the configuration of the pxe vlan" envconfig:"pxe_vlan"` + PXEVlanID uint16 `required:"false" default:"4000" desc:"the id of the pxe vlan" envconfig:"pxe_vlan_id"` } diff --git a/cmd/internal/core/core.go b/cmd/internal/core/core.go index e85e0ef5..1e77a5f4 100644 --- a/cmd/internal/core/core.go +++ b/cmd/internal/core/core.go @@ -33,7 +33,7 @@ type Core struct { metrics *metrics.Metrics - pxeVlan uint16 + pxeVlanID uint16 } type Config struct { @@ -59,7 +59,7 @@ type Config struct { Metrics *metrics.Metrics - PXEVlan uint16 + PXEVlanID uint16 } func New(c Config) *Core { @@ -81,6 +81,6 @@ func New(c Config) *Core { driver: c.Driver, eventServiceClient: c.EventServiceClient, metrics: c.Metrics, - pxeVlan: c.PXEVlan, + pxeVlanID: c.PXEVlanID, } } diff --git a/cmd/internal/core/reconfigure-switch.go b/cmd/internal/core/reconfigure-switch.go index 9697416f..cf58695a 100644 --- a/cmd/internal/core/reconfigure-switch.go +++ b/cmd/internal/core/reconfigure-switch.go @@ -117,7 +117,7 @@ func (c *Core) buildSwitcherConfig(s *models.V1SwitchResponse) (*types.Conf, err return nil, err } - if c.pxeVlan >= vlan.VlanIDMin && c.pxeVlan <= vlan.VlanIDMax { + if c.pxeVlanID >= vlan.VlanIDMin && c.pxeVlanID <= vlan.VlanIDMax { return nil, fmt.Errorf("configured VLAN is in the reserved area of %v, %v", vlan.VlanIDMin, vlan.VlanIDMax) } @@ -128,7 +128,7 @@ func (c *Core) buildSwitcherConfig(s *models.V1SwitchResponse) (*types.Conf, err Loopback: c.loopbackIP, MetalCoreCIDR: c.cidr, AdditionalBridgeVIDs: c.additionalBridgeVIDs, - PXEVlan: c.pxeVlan, + PXEVlanID: c.pxeVlanID, } p := types.Ports{ diff --git a/cmd/internal/switcher/sonic/redis/applier.go b/cmd/internal/switcher/sonic/redis/applier.go index 7058262f..9b141240 100644 --- a/cmd/internal/switcher/sonic/redis/applier.go +++ b/cmd/internal/switcher/sonic/redis/applier.go @@ -56,7 +56,7 @@ func (a *Applier) Apply(cfg *types.Conf) error { } for _, interfaceName := range cfg.Ports.Unprovisioned { - if err := a.configureUnprovisionedPort(interfaceName, !cfg.Ports.DownPorts[interfaceName], cfg.PXEVlan); err != nil { + if err := a.configureUnprovisionedPort(interfaceName, !cfg.Ports.DownPorts[interfaceName], cfg.PXEVlanID); err != nil { errs = append(errs, err) } } @@ -116,7 +116,7 @@ func (a *Applier) refreshOidMaps() error { return nil } -func (a *Applier) configureUnprovisionedPort(interfaceName string, isUp bool, pxeVlan uint16) error { +func (a *Applier) configureUnprovisionedPort(interfaceName string, isUp bool, pxeVlanID uint16) error { ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) defer cancel() @@ -130,9 +130,9 @@ func (a *Applier) configureUnprovisionedPort(interfaceName string, isUp bool, px return fmt.Errorf("failed to update Port info for interface %s: %w", interfaceName, err) } - vl := "Vlan" + strconv.FormatUint(uint64(pxeVlan), 10) + vlan := "Vlan" + strconv.FormatUint(uint64(pxeVlanID), 10) - return a.ensureInterfaceIsVlanMember(ctx, interfaceName, vl) + return a.ensureInterfaceIsVlanMember(ctx, interfaceName, vlan) } func (a *Applier) configureFirewallPort(interfaceName string, isUp bool) error { diff --git a/cmd/internal/switcher/types/types.go b/cmd/internal/switcher/types/types.go index 62d4f64b..06795780 100644 --- a/cmd/internal/switcher/types/types.go +++ b/cmd/internal/switcher/types/types.go @@ -13,7 +13,7 @@ type Conf struct { Ports Ports MetalCoreCIDR string AdditionalBridgeVIDs []string - PXEVlan uint16 + PXEVlanID uint16 } type Ports struct { diff --git a/cmd/server.go b/cmd/server.go index 283624e7..6b6aec90 100644 --- a/cmd/server.go +++ b/cmd/server.go @@ -101,7 +101,7 @@ func Run() { Driver: driver, EventServiceClient: grpcClient.NewEventClient(), Metrics: metrics, - PXEVlan: cfg.PXEVlan, + PXEVlanID: cfg.PXEVlanID, }) err = c.RegisterSwitch() From 8ddb488ff4c8ae6a259a556e7fcd7cab7d52434d Mon Sep 17 00:00:00 2001 From: simcod Date: Fri, 5 Jul 2024 07:57:20 +0200 Subject: [PATCH 05/13] Implement review --- cmd/internal/core/reconfigure-switch.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/internal/core/reconfigure-switch.go b/cmd/internal/core/reconfigure-switch.go index cf58695a..7784df14 100644 --- a/cmd/internal/core/reconfigure-switch.go +++ b/cmd/internal/core/reconfigure-switch.go @@ -118,7 +118,7 @@ func (c *Core) buildSwitcherConfig(s *models.V1SwitchResponse) (*types.Conf, err } if c.pxeVlanID >= vlan.VlanIDMin && c.pxeVlanID <= vlan.VlanIDMax { - return nil, fmt.Errorf("configured VLAN is in the reserved area of %v, %v", vlan.VlanIDMin, vlan.VlanIDMax) + return nil, fmt.Errorf("configured VLAN ID is in the reserved area of %v, %v", vlan.VlanIDMin, vlan.VlanIDMax) } switcherConfig := &types.Conf{ From 4f2d5eabb2525fb442725816da07cb17d050b0d2 Mon Sep 17 00:00:00 2001 From: simcod Date: Fri, 5 Jul 2024 08:10:33 +0200 Subject: [PATCH 06/13] Implement review --- cmd/internal/core/reconfigure-switch.go | 2 +- cmd/internal/switcher/sonic/redis/applier.go | 7 +++---- cmd/internal/vlan/reservation.go | 4 ++-- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/cmd/internal/core/reconfigure-switch.go b/cmd/internal/core/reconfigure-switch.go index 7784df14..2e273fe0 100644 --- a/cmd/internal/core/reconfigure-switch.go +++ b/cmd/internal/core/reconfigure-switch.go @@ -118,7 +118,7 @@ func (c *Core) buildSwitcherConfig(s *models.V1SwitchResponse) (*types.Conf, err } if c.pxeVlanID >= vlan.VlanIDMin && c.pxeVlanID <= vlan.VlanIDMax { - return nil, fmt.Errorf("configured VLAN ID is in the reserved area of %v, %v", vlan.VlanIDMin, vlan.VlanIDMax) + return nil, fmt.Errorf("configured PXE VLAN ID is in the reserved area of %d, %d", vlan.VlanIDMin, vlan.VlanIDMax) } switcherConfig := &types.Conf{ diff --git a/cmd/internal/switcher/sonic/redis/applier.go b/cmd/internal/switcher/sonic/redis/applier.go index 9b141240..ecda3be8 100644 --- a/cmd/internal/switcher/sonic/redis/applier.go +++ b/cmd/internal/switcher/sonic/redis/applier.go @@ -56,7 +56,8 @@ func (a *Applier) Apply(cfg *types.Conf) error { } for _, interfaceName := range cfg.Ports.Unprovisioned { - if err := a.configureUnprovisionedPort(interfaceName, !cfg.Ports.DownPorts[interfaceName], cfg.PXEVlanID); err != nil { + vlan := "Vlan" + strconv.FormatUint(uint64(cfg.PXEVlanID), 10) + if err := a.configureUnprovisionedPort(interfaceName, !cfg.Ports.DownPorts[interfaceName], vlan); err != nil { errs = append(errs, err) } } @@ -116,7 +117,7 @@ func (a *Applier) refreshOidMaps() error { return nil } -func (a *Applier) configureUnprovisionedPort(interfaceName string, isUp bool, pxeVlanID uint16) error { +func (a *Applier) configureUnprovisionedPort(interfaceName string, isUp bool, vlan string) error { ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) defer cancel() @@ -130,8 +131,6 @@ func (a *Applier) configureUnprovisionedPort(interfaceName string, isUp bool, px return fmt.Errorf("failed to update Port info for interface %s: %w", interfaceName, err) } - vlan := "Vlan" + strconv.FormatUint(uint64(pxeVlanID), 10) - return a.ensureInterfaceIsVlanMember(ctx, interfaceName, vlan) } diff --git a/cmd/internal/vlan/reservation.go b/cmd/internal/vlan/reservation.go index a72ad7ce..8b3a6efa 100644 --- a/cmd/internal/vlan/reservation.go +++ b/cmd/internal/vlan/reservation.go @@ -3,10 +3,10 @@ package vlan import "fmt" const ( - // vlanIDMin specifies the min VLAN-ID we want to use on our switches + // VlanIDMin specifies the min VLAN-ID we want to use on our switches VlanIDMin uint16 = 1001 - // vlanIDMax specifies the max VLAN-ID we want to use on our switches + // VlanIDMax specifies the max VLAN-ID we want to use on our switches VlanIDMax uint16 = 2000 ) From 5b596645c20b4dbd50b239c68308f8153397ea71 Mon Sep 17 00:00:00 2001 From: Robert Volkmann Date: Fri, 5 Jul 2024 08:18:01 +0200 Subject: [PATCH 07/13] Change naming from vlan to pxeVlan --- cmd/internal/switcher/sonic/redis/applier.go | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/cmd/internal/switcher/sonic/redis/applier.go b/cmd/internal/switcher/sonic/redis/applier.go index ecda3be8..4c43a94e 100644 --- a/cmd/internal/switcher/sonic/redis/applier.go +++ b/cmd/internal/switcher/sonic/redis/applier.go @@ -5,7 +5,6 @@ import ( "errors" "fmt" "log/slog" - "strconv" "time" "github.com/google/go-cmp/cmp" @@ -56,8 +55,8 @@ func (a *Applier) Apply(cfg *types.Conf) error { } for _, interfaceName := range cfg.Ports.Unprovisioned { - vlan := "Vlan" + strconv.FormatUint(uint64(cfg.PXEVlanID), 10) - if err := a.configureUnprovisionedPort(interfaceName, !cfg.Ports.DownPorts[interfaceName], vlan); err != nil { + pxeVlan := fmt.Sprintf("Vlan%d", cfg.PXEVlanID) + if err := a.configureUnprovisionedPort(interfaceName, !cfg.Ports.DownPorts[interfaceName], pxeVlan); err != nil { errs = append(errs, err) } } @@ -117,7 +116,7 @@ func (a *Applier) refreshOidMaps() error { return nil } -func (a *Applier) configureUnprovisionedPort(interfaceName string, isUp bool, vlan string) error { +func (a *Applier) configureUnprovisionedPort(interfaceName string, isUp bool, pxeVlan string) error { ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) defer cancel() @@ -131,7 +130,7 @@ func (a *Applier) configureUnprovisionedPort(interfaceName string, isUp bool, vl return fmt.Errorf("failed to update Port info for interface %s: %w", interfaceName, err) } - return a.ensureInterfaceIsVlanMember(ctx, interfaceName, vlan) + return a.ensureInterfaceIsVlanMember(ctx, interfaceName, pxeVlan) } func (a *Applier) configureFirewallPort(interfaceName string, isUp bool) error { From 7305bcc44b963cbe8672ca50228990012efdd965 Mon Sep 17 00:00:00 2001 From: Robert Volkmann Date: Fri, 5 Jul 2024 08:18:58 +0200 Subject: [PATCH 08/13] Use VLAN ID instead of VLAN-ID in the comments --- cmd/internal/switcher/types/conf.go | 4 ++-- cmd/internal/vlan/mapping.go | 2 +- cmd/internal/vlan/reservation.go | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/cmd/internal/switcher/types/conf.go b/cmd/internal/switcher/types/conf.go index 58ba991d..94193207 100644 --- a/cmd/internal/switcher/types/conf.go +++ b/cmd/internal/switcher/types/conf.go @@ -6,9 +6,9 @@ import ( "golang.org/x/text/language" ) -// FillVLANIDs fills the given configuration object with switch-local VLAN-IDs +// FillVLANIDs fills the given configuration object with switch-local VLAN IDs // if they are present in the given VLAN-Mapping -// otherwise: new available VLAN-IDs will be used +// otherwise: new available VLAN IDs will be used func (c *Conf) FillVLANIDs(m vlan.Mapping) error { outer_loop: for _, t := range c.Ports.Vrfs { diff --git a/cmd/internal/vlan/mapping.go b/cmd/internal/vlan/mapping.go index 73f5032f..47711132 100644 --- a/cmd/internal/vlan/mapping.go +++ b/cmd/internal/vlan/mapping.go @@ -6,7 +6,7 @@ import ( "github.com/vishvananda/netlink" ) -// Mapping holds the current mapping of VLAN-IDs to VNIs of the switch +// Mapping holds the current mapping of VLAN IDs to VNIs of the switch type Mapping map[uint16]uint32 // ReadMapping reads the current VLAN to VNI mapping with the help of netlink diff --git a/cmd/internal/vlan/reservation.go b/cmd/internal/vlan/reservation.go index 8b3a6efa..ec317cd9 100644 --- a/cmd/internal/vlan/reservation.go +++ b/cmd/internal/vlan/reservation.go @@ -3,14 +3,14 @@ package vlan import "fmt" const ( - // VlanIDMin specifies the min VLAN-ID we want to use on our switches + // VlanIDMin specifies the min VLAN ID we want to use on our switches VlanIDMin uint16 = 1001 - // VlanIDMax specifies the max VLAN-ID we want to use on our switches + // VlanIDMax specifies the max VLAN ID we want to use on our switches VlanIDMax uint16 = 2000 ) -// ReserveVlanIDs tries to reserve n VLAN-IDs given the current switch configuration +// ReserveVlanIDs tries to reserve n VLAN IDs given the current switch configuration func (m Mapping) ReserveVlanIDs(n uint16) ([]uint16, error) { return m.reserveVlanIDs(VlanIDMin, VlanIDMax, n) } From d13c8b299f0dc757a065d586b91d1ab2b0228399 Mon Sep 17 00:00:00 2001 From: simcod Date: Mon, 8 Jul 2024 07:54:05 +0200 Subject: [PATCH 09/13] Configure PXEVlan for cumulus --- .../switcher/templates/test_data/dev/conf.yaml | 1 + .../test_data/dev/customtpl/interfaces.tpl | 16 ++++++++-------- .../switcher/templates/tpl/interfaces.tpl | 16 ++++++++-------- 3 files changed, 17 insertions(+), 16 deletions(-) diff --git a/cmd/internal/switcher/templates/test_data/dev/conf.yaml b/cmd/internal/switcher/templates/test_data/dev/conf.yaml index bbef9185..39c7eee3 100644 --- a/cmd/internal/switcher/templates/test_data/dev/conf.yaml +++ b/cmd/internal/switcher/templates/test_data/dev/conf.yaml @@ -39,3 +39,4 @@ ports: additionalbridgevids: - 201-256 - 301-356 +pxevlanid: 966 diff --git a/cmd/internal/switcher/templates/test_data/dev/customtpl/interfaces.tpl b/cmd/internal/switcher/templates/test_data/dev/customtpl/interfaces.tpl index aa207bb2..9f1dcc5f 100644 --- a/cmd/internal/switcher/templates/test_data/dev/customtpl/interfaces.tpl +++ b/cmd/internal/switcher/templates/test_data/dev/customtpl/interfaces.tpl @@ -75,21 +75,21 @@ iface vni{{ $t.VNI }} {{- end }} # PXE-Config -auto vlan4000 -iface vlan4000 +auto vlan{{ PXEVlanID }} +iface vlan{{ PXEVlanID }} mtu 9000 address {{ .MetalCoreCIDR }} - vlan-id 4000 + vlan-id {{ PXEVlanID }} vlan-raw-device bridge -auto vni104000 -iface vni104000 +auto vni10{{ PXEVlanID }} +iface vni10{{ PXEVlanID }} mtu 9000 - bridge-access 4000 + bridge-access {{ PXEVlanID }} bridge-learning off mstpctl-bpduguard yes mstpctl-portbpdufilter yes - vxlan-id 104000 + vxlan-id 10{{ PXEVlanID }} vxlan-local-tunnelip {{ $IPLoopback }} {{- range .Ports.Unprovisioned }} @@ -97,5 +97,5 @@ iface vni104000 auto {{ . }} iface {{ . }} mtu 9000 - bridge-access 4000 + bridge-access {{ PXEVlanID }} {{- end }} diff --git a/cmd/internal/switcher/templates/tpl/interfaces.tpl b/cmd/internal/switcher/templates/tpl/interfaces.tpl index aa207bb2..9f1dcc5f 100644 --- a/cmd/internal/switcher/templates/tpl/interfaces.tpl +++ b/cmd/internal/switcher/templates/tpl/interfaces.tpl @@ -75,21 +75,21 @@ iface vni{{ $t.VNI }} {{- end }} # PXE-Config -auto vlan4000 -iface vlan4000 +auto vlan{{ PXEVlanID }} +iface vlan{{ PXEVlanID }} mtu 9000 address {{ .MetalCoreCIDR }} - vlan-id 4000 + vlan-id {{ PXEVlanID }} vlan-raw-device bridge -auto vni104000 -iface vni104000 +auto vni10{{ PXEVlanID }} +iface vni10{{ PXEVlanID }} mtu 9000 - bridge-access 4000 + bridge-access {{ PXEVlanID }} bridge-learning off mstpctl-bpduguard yes mstpctl-portbpdufilter yes - vxlan-id 104000 + vxlan-id 10{{ PXEVlanID }} vxlan-local-tunnelip {{ $IPLoopback }} {{- range .Ports.Unprovisioned }} @@ -97,5 +97,5 @@ iface vni104000 auto {{ . }} iface {{ . }} mtu 9000 - bridge-access 4000 + bridge-access {{ PXEVlanID }} {{- end }} From fb5a00ac24d428b779b8e5da7117376fd9973a67 Mon Sep 17 00:00:00 2001 From: simcod Date: Mon, 8 Jul 2024 08:08:05 +0200 Subject: [PATCH 10/13] Fix build --- .../test_data/dev/customtpl/interfaces.tpl | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/cmd/internal/switcher/templates/test_data/dev/customtpl/interfaces.tpl b/cmd/internal/switcher/templates/test_data/dev/customtpl/interfaces.tpl index 9f1dcc5f..db39414d 100644 --- a/cmd/internal/switcher/templates/test_data/dev/customtpl/interfaces.tpl +++ b/cmd/internal/switcher/templates/test_data/dev/customtpl/interfaces.tpl @@ -75,21 +75,21 @@ iface vni{{ $t.VNI }} {{- end }} # PXE-Config -auto vlan{{ PXEVlanID }} -iface vlan{{ PXEVlanID }} +auto vlan{{ .PXEVlanID }} +iface vlan{{ .PXEVlanID }} mtu 9000 address {{ .MetalCoreCIDR }} - vlan-id {{ PXEVlanID }} + vlan-id {{ .PXEVlanID }} vlan-raw-device bridge -auto vni10{{ PXEVlanID }} -iface vni10{{ PXEVlanID }} +auto vni10{{ .PXEVlanID }} +iface vni10{{ .PXEVlanID }} mtu 9000 - bridge-access {{ PXEVlanID }} + bridge-access {{ .PXEVlanID }} bridge-learning off mstpctl-bpduguard yes mstpctl-portbpdufilter yes - vxlan-id 10{{ PXEVlanID }} + vxlan-id 10{{ .PXEVlanID }} vxlan-local-tunnelip {{ $IPLoopback }} {{- range .Ports.Unprovisioned }} @@ -97,5 +97,5 @@ iface vni10{{ PXEVlanID }} auto {{ . }} iface {{ . }} mtu 9000 - bridge-access {{ PXEVlanID }} + bridge-access {{ .PXEVlanID }} {{- end }} From 379bdc54c989f5e55521ffd34c410b5529abc9f5 Mon Sep 17 00:00:00 2001 From: simcod Date: Mon, 8 Jul 2024 08:11:33 +0200 Subject: [PATCH 11/13] Fix build --- .../switcher/templates/tpl/interfaces.tpl | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/cmd/internal/switcher/templates/tpl/interfaces.tpl b/cmd/internal/switcher/templates/tpl/interfaces.tpl index 9f1dcc5f..db39414d 100644 --- a/cmd/internal/switcher/templates/tpl/interfaces.tpl +++ b/cmd/internal/switcher/templates/tpl/interfaces.tpl @@ -75,21 +75,21 @@ iface vni{{ $t.VNI }} {{- end }} # PXE-Config -auto vlan{{ PXEVlanID }} -iface vlan{{ PXEVlanID }} +auto vlan{{ .PXEVlanID }} +iface vlan{{ .PXEVlanID }} mtu 9000 address {{ .MetalCoreCIDR }} - vlan-id {{ PXEVlanID }} + vlan-id {{ .PXEVlanID }} vlan-raw-device bridge -auto vni10{{ PXEVlanID }} -iface vni10{{ PXEVlanID }} +auto vni10{{ .PXEVlanID }} +iface vni10{{ .PXEVlanID }} mtu 9000 - bridge-access {{ PXEVlanID }} + bridge-access {{ .PXEVlanID }} bridge-learning off mstpctl-bpduguard yes mstpctl-portbpdufilter yes - vxlan-id 10{{ PXEVlanID }} + vxlan-id 10{{ .PXEVlanID }} vxlan-local-tunnelip {{ $IPLoopback }} {{- range .Ports.Unprovisioned }} @@ -97,5 +97,5 @@ iface vni10{{ PXEVlanID }} auto {{ . }} iface {{ . }} mtu 9000 - bridge-access {{ PXEVlanID }} + bridge-access {{ .PXEVlanID }} {{- end }} From f32b9d14f778af7d5355bebb7a2aec6b5ee9a1d0 Mon Sep 17 00:00:00 2001 From: simcod Date: Mon, 8 Jul 2024 10:23:35 +0200 Subject: [PATCH 12/13] Add vni configuration to all tests and templates --- .../test_data/dev/customtpl/interfaces | 22 +++++++++---------- .../test_data/dev/customtpl/interfaces.tpl | 21 +++++++++--------- .../templates/test_data/dev/interfaces | 22 +++++++++---------- .../templates/test_data/lab/conf.yaml | 1 + .../templates/test_data/lab/interfaces | 22 +++++++++---------- .../templates/test_data/notenants/conf.yaml | 3 ++- .../templates/test_data/notenants/interfaces | 22 +++++++++---------- .../conf_with_downports.yaml | 1 + .../interfaces_with_downports | 22 +++++++++---------- .../switcher/templates/tpl/interfaces.tpl | 21 +++++++++--------- 10 files changed, 81 insertions(+), 76 deletions(-) diff --git a/cmd/internal/switcher/templates/test_data/dev/customtpl/interfaces b/cmd/internal/switcher/templates/test_data/dev/customtpl/interfaces index e846e97a..a2a5b210 100644 --- a/cmd/internal/switcher/templates/test_data/dev/customtpl/interfaces +++ b/cmd/internal/switcher/templates/test_data/dev/customtpl/interfaces @@ -34,8 +34,8 @@ iface swp3 auto bridge iface bridge - bridge-ports vni104000 swp4 swp5 swp7 swp8 vni104001 - bridge-vids 4000 4001 201-256 301-356 + bridge-ports vni10966 swp4 swp5 swp7 swp8 vni104001 + bridge-vids 966 4001 201-256 301-356 bridge-vlan-aware yes # Tenants @@ -75,29 +75,29 @@ iface vni104001 vxlan-local-tunnelip 10.0.0.10 # PXE-Config -auto vlan4000 -iface vlan4000 +auto vlan966 +iface vlan966 mtu 9000 address 10.255.255.2/24 - vlan-id 4000 + vlan-id 966 vlan-raw-device bridge -auto vni104000 -iface vni104000 +auto vni10966 +iface vni10966 mtu 9000 - bridge-access 4000 + bridge-access 966 bridge-learning off mstpctl-bpduguard yes mstpctl-portbpdufilter yes - vxlan-id 104000 + vxlan-id 10966 vxlan-local-tunnelip 10.0.0.10 auto swp4 iface swp4 mtu 9000 - bridge-access 4000 + bridge-access 966 auto swp5 iface swp5 mtu 9000 - bridge-access 4000 + bridge-access 966 diff --git a/cmd/internal/switcher/templates/test_data/dev/customtpl/interfaces.tpl b/cmd/internal/switcher/templates/test_data/dev/customtpl/interfaces.tpl index db39414d..e9674968 100644 --- a/cmd/internal/switcher/templates/test_data/dev/customtpl/interfaces.tpl +++ b/cmd/internal/switcher/templates/test_data/dev/customtpl/interfaces.tpl @@ -1,4 +1,5 @@ {{- $IPLoopback := .Loopback -}} +{{- $PXEVlanID := .PXEVlanID -}} # This file describes the network interfaces available on your system # and how to activate them. For more information, see interfaces(5). @@ -35,8 +36,8 @@ iface {{ .Port }} auto bridge iface bridge - bridge-ports vni104000{{ range .Ports.Unprovisioned }} {{ . }}{{ end }}{{ range .Ports.BladePorts }} {{ . }}{{ end }}{{ range $vrf, $t := .Ports.Vrfs }} vni{{ $t.VNI }}{{ end }} - bridge-vids 4000{{ range $vrf, $t := .Ports.Vrfs }} {{ $t.VLANID }}{{ end }}{{ range $vids := .AdditionalBridgeVIDs }} {{ $vids }}{{ end }} + bridge-ports vni10{{ $PXEVlanID }} {{ range .Ports.Unprovisioned }}{{ . }} {{ end }}{{ range .Ports.BladePorts }}{{ . }} {{ end }}{{ range $vrf, $t := .Ports.Vrfs }}vni{{ $t.VNI }}{{ end }} + bridge-vids {{ $PXEVlanID }} {{ range $vrf, $t := .Ports.Vrfs }}{{ $t.VLANID }}{{ end }}{{ range $vids := .AdditionalBridgeVIDs }} {{ $vids }}{{ end }} bridge-vlan-aware yes # Tenants @@ -75,21 +76,21 @@ iface vni{{ $t.VNI }} {{- end }} # PXE-Config -auto vlan{{ .PXEVlanID }} -iface vlan{{ .PXEVlanID }} +auto vlan{{ $PXEVlanID }} +iface vlan{{ $PXEVlanID }} mtu 9000 address {{ .MetalCoreCIDR }} - vlan-id {{ .PXEVlanID }} + vlan-id {{ $PXEVlanID }} vlan-raw-device bridge -auto vni10{{ .PXEVlanID }} -iface vni10{{ .PXEVlanID }} +auto vni10{{ $PXEVlanID }} +iface vni10{{ $PXEVlanID }} mtu 9000 - bridge-access {{ .PXEVlanID }} + bridge-access {{ $PXEVlanID }} bridge-learning off mstpctl-bpduguard yes mstpctl-portbpdufilter yes - vxlan-id 10{{ .PXEVlanID }} + vxlan-id 10{{ $PXEVlanID }} vxlan-local-tunnelip {{ $IPLoopback }} {{- range .Ports.Unprovisioned }} @@ -97,5 +98,5 @@ iface vni10{{ .PXEVlanID }} auto {{ . }} iface {{ . }} mtu 9000 - bridge-access {{ .PXEVlanID }} + bridge-access {{ $PXEVlanID }} {{- end }} diff --git a/cmd/internal/switcher/templates/test_data/dev/interfaces b/cmd/internal/switcher/templates/test_data/dev/interfaces index e846e97a..a2a5b210 100644 --- a/cmd/internal/switcher/templates/test_data/dev/interfaces +++ b/cmd/internal/switcher/templates/test_data/dev/interfaces @@ -34,8 +34,8 @@ iface swp3 auto bridge iface bridge - bridge-ports vni104000 swp4 swp5 swp7 swp8 vni104001 - bridge-vids 4000 4001 201-256 301-356 + bridge-ports vni10966 swp4 swp5 swp7 swp8 vni104001 + bridge-vids 966 4001 201-256 301-356 bridge-vlan-aware yes # Tenants @@ -75,29 +75,29 @@ iface vni104001 vxlan-local-tunnelip 10.0.0.10 # PXE-Config -auto vlan4000 -iface vlan4000 +auto vlan966 +iface vlan966 mtu 9000 address 10.255.255.2/24 - vlan-id 4000 + vlan-id 966 vlan-raw-device bridge -auto vni104000 -iface vni104000 +auto vni10966 +iface vni10966 mtu 9000 - bridge-access 4000 + bridge-access 966 bridge-learning off mstpctl-bpduguard yes mstpctl-portbpdufilter yes - vxlan-id 104000 + vxlan-id 10966 vxlan-local-tunnelip 10.0.0.10 auto swp4 iface swp4 mtu 9000 - bridge-access 4000 + bridge-access 966 auto swp5 iface swp5 mtu 9000 - bridge-access 4000 + bridge-access 966 diff --git a/cmd/internal/switcher/templates/test_data/lab/conf.yaml b/cmd/internal/switcher/templates/test_data/lab/conf.yaml index 562ba4f6..f6051784 100644 --- a/cmd/internal/switcher/templates/test_data/lab/conf.yaml +++ b/cmd/internal/switcher/templates/test_data/lab/conf.yaml @@ -30,3 +30,4 @@ ports: neighbors: - swp1 - swp2 +pxevlanid: 966 diff --git a/cmd/internal/switcher/templates/test_data/lab/interfaces b/cmd/internal/switcher/templates/test_data/lab/interfaces index a54513bb..387f4b9a 100644 --- a/cmd/internal/switcher/templates/test_data/lab/interfaces +++ b/cmd/internal/switcher/templates/test_data/lab/interfaces @@ -34,8 +34,8 @@ iface swp3 auto bridge iface bridge - bridge-ports vni104000 swp4 swp5 vni104001 - bridge-vids 4000 4001 + bridge-ports vni10966 swp4 swp5 vni104001 + bridge-vids 966 4001 bridge-vlan-aware yes # Tenants @@ -75,29 +75,29 @@ iface vni104001 vxlan-local-tunnelip 10.0.0.10 # PXE-Config -auto vlan4000 -iface vlan4000 +auto vlan966 +iface vlan966 mtu 9000 address 10.255.255.2/24 - vlan-id 4000 + vlan-id 966 vlan-raw-device bridge -auto vni104000 -iface vni104000 +auto vni10966 +iface vni10966 mtu 9000 - bridge-access 4000 + bridge-access 966 bridge-learning off mstpctl-bpduguard yes mstpctl-portbpdufilter yes - vxlan-id 104000 + vxlan-id 10966 vxlan-local-tunnelip 10.0.0.10 auto swp4 iface swp4 mtu 9000 - bridge-access 4000 + bridge-access 966 auto swp5 iface swp5 mtu 9000 - bridge-access 4000 + bridge-access 966 diff --git a/cmd/internal/switcher/templates/test_data/notenants/conf.yaml b/cmd/internal/switcher/templates/test_data/notenants/conf.yaml index 0f598160..a0920ad5 100644 --- a/cmd/internal/switcher/templates/test_data/notenants/conf.yaml +++ b/cmd/internal/switcher/templates/test_data/notenants/conf.yaml @@ -13,4 +13,5 @@ ports: - swp32 unprovisioned: - swp1 - - swp2 \ No newline at end of file + - swp2 +pxevlanid: 966 diff --git a/cmd/internal/switcher/templates/test_data/notenants/interfaces b/cmd/internal/switcher/templates/test_data/notenants/interfaces index 96ea84a0..8c1797cb 100644 --- a/cmd/internal/switcher/templates/test_data/notenants/interfaces +++ b/cmd/internal/switcher/templates/test_data/notenants/interfaces @@ -30,36 +30,36 @@ iface swp32 auto bridge iface bridge - bridge-ports vni104000 swp1 swp2 - bridge-vids 4000 + bridge-ports vni10966 swp1 swp2 + bridge-vids 966 bridge-vlan-aware yes # Tenants # PXE-Config -auto vlan4000 -iface vlan4000 +auto vlan966 +iface vlan966 mtu 9000 address 10.255.255.2/24 - vlan-id 4000 + vlan-id 966 vlan-raw-device bridge -auto vni104000 -iface vni104000 +auto vni10966 +iface vni10966 mtu 9000 - bridge-access 4000 + bridge-access 966 bridge-learning off mstpctl-bpduguard yes mstpctl-portbpdufilter yes - vxlan-id 104000 + vxlan-id 10966 vxlan-local-tunnelip 10.0.0.10 auto swp1 iface swp1 mtu 9000 - bridge-access 4000 + bridge-access 966 auto swp2 iface swp2 mtu 9000 - bridge-access 4000 + bridge-access 966 diff --git a/cmd/internal/switcher/templates/test_down_interfaces/conf_with_downports.yaml b/cmd/internal/switcher/templates/test_down_interfaces/conf_with_downports.yaml index 54de56d6..df278021 100644 --- a/cmd/internal/switcher/templates/test_down_interfaces/conf_with_downports.yaml +++ b/cmd/internal/switcher/templates/test_down_interfaces/conf_with_downports.yaml @@ -24,3 +24,4 @@ ports: - swp2 downports: swp3: True +pxevlanid: 966 diff --git a/cmd/internal/switcher/templates/test_down_interfaces/interfaces_with_downports b/cmd/internal/switcher/templates/test_down_interfaces/interfaces_with_downports index 67c75bfb..3308eae5 100644 --- a/cmd/internal/switcher/templates/test_down_interfaces/interfaces_with_downports +++ b/cmd/internal/switcher/templates/test_down_interfaces/interfaces_with_downports @@ -30,8 +30,8 @@ iface swp32 auto bridge iface bridge - bridge-ports vni104000 swp1 swp2 vni1 - bridge-vids 4000 2 + bridge-ports vni10966 swp1 swp2 vni1 + bridge-vids 966 2 bridge-vlan-aware yes # Tenants @@ -59,29 +59,29 @@ iface vni1 vxlan-local-tunnelip 10.0.0.10 # PXE-Config -auto vlan4000 -iface vlan4000 +auto vlan966 +iface vlan966 mtu 9000 address 10.255.255.2/24 - vlan-id 4000 + vlan-id 966 vlan-raw-device bridge -auto vni104000 -iface vni104000 +auto vni10966 +iface vni10966 mtu 9000 - bridge-access 4000 + bridge-access 966 bridge-learning off mstpctl-bpduguard yes mstpctl-portbpdufilter yes - vxlan-id 104000 + vxlan-id 10966 vxlan-local-tunnelip 10.0.0.10 auto swp1 iface swp1 mtu 9000 - bridge-access 4000 + bridge-access 966 auto swp2 iface swp2 mtu 9000 - bridge-access 4000 + bridge-access 966 diff --git a/cmd/internal/switcher/templates/tpl/interfaces.tpl b/cmd/internal/switcher/templates/tpl/interfaces.tpl index db39414d..fb04a659 100644 --- a/cmd/internal/switcher/templates/tpl/interfaces.tpl +++ b/cmd/internal/switcher/templates/tpl/interfaces.tpl @@ -1,4 +1,5 @@ {{- $IPLoopback := .Loopback -}} +{{- $PXEVlanID := .PXEVlanID -}} # This file describes the network interfaces available on your system # and how to activate them. For more information, see interfaces(5). @@ -35,8 +36,8 @@ iface {{ .Port }} auto bridge iface bridge - bridge-ports vni104000{{ range .Ports.Unprovisioned }} {{ . }}{{ end }}{{ range .Ports.BladePorts }} {{ . }}{{ end }}{{ range $vrf, $t := .Ports.Vrfs }} vni{{ $t.VNI }}{{ end }} - bridge-vids 4000{{ range $vrf, $t := .Ports.Vrfs }} {{ $t.VLANID }}{{ end }}{{ range $vids := .AdditionalBridgeVIDs }} {{ $vids }}{{ end }} + bridge-ports vni10{{ $PXEVlanID }}{{ range .Ports.Unprovisioned }} {{ . }}{{ end }}{{ range .Ports.BladePorts }} {{ . }}{{ end }}{{ range $vrf, $t := .Ports.Vrfs }} vni{{ $t.VNI }}{{ end }} + bridge-vids {{ $PXEVlanID }}{{ range $vrf, $t := .Ports.Vrfs }} {{ $t.VLANID }}{{ end }}{{ range $vids := .AdditionalBridgeVIDs }} {{ $vids }}{{ end }} bridge-vlan-aware yes # Tenants @@ -75,21 +76,21 @@ iface vni{{ $t.VNI }} {{- end }} # PXE-Config -auto vlan{{ .PXEVlanID }} -iface vlan{{ .PXEVlanID }} +auto vlan{{ $PXEVlanID }} +iface vlan{{ $PXEVlanID }} mtu 9000 address {{ .MetalCoreCIDR }} - vlan-id {{ .PXEVlanID }} + vlan-id {{ $PXEVlanID }} vlan-raw-device bridge -auto vni10{{ .PXEVlanID }} -iface vni10{{ .PXEVlanID }} +auto vni10{{ $PXEVlanID }} +iface vni10{{ $PXEVlanID }} mtu 9000 - bridge-access {{ .PXEVlanID }} + bridge-access {{ $PXEVlanID }} bridge-learning off mstpctl-bpduguard yes mstpctl-portbpdufilter yes - vxlan-id 10{{ .PXEVlanID }} + vxlan-id 10{{ $PXEVlanID }} vxlan-local-tunnelip {{ $IPLoopback }} {{- range .Ports.Unprovisioned }} @@ -97,5 +98,5 @@ iface vni10{{ .PXEVlanID }} auto {{ . }} iface {{ . }} mtu 9000 - bridge-access {{ .PXEVlanID }} + bridge-access {{ $PXEVlanID }} {{- end }} From 29f5383ba362b011d72426e5a68b23fbea02e4f6 Mon Sep 17 00:00:00 2001 From: simcod Date: Mon, 8 Jul 2024 15:01:27 +0200 Subject: [PATCH 13/13] Adjust vni name --- .../test_data/dev/customtpl/interfaces | 22 +++++++++--------- .../test_data/dev/customtpl/interfaces.tpl | 23 +++++++++---------- .../templates/test_data/dev/interfaces | 8 +++---- .../templates/test_data/lab/interfaces | 8 +++---- .../templates/test_data/notenants/interfaces | 8 +++---- .../interfaces_with_downports | 8 +++---- .../switcher/templates/tpl/interfaces.tpl | 9 ++++---- 7 files changed, 43 insertions(+), 43 deletions(-) diff --git a/cmd/internal/switcher/templates/test_data/dev/customtpl/interfaces b/cmd/internal/switcher/templates/test_data/dev/customtpl/interfaces index a2a5b210..d3892a80 100644 --- a/cmd/internal/switcher/templates/test_data/dev/customtpl/interfaces +++ b/cmd/internal/switcher/templates/test_data/dev/customtpl/interfaces @@ -34,8 +34,8 @@ iface swp3 auto bridge iface bridge - bridge-ports vni10966 swp4 swp5 swp7 swp8 vni104001 - bridge-vids 966 4001 201-256 301-356 + bridge-ports vni104000 swp4 swp5 swp7 swp8 vni104001 + bridge-vids 4000 4001 201-256 301-356 bridge-vlan-aware yes # Tenants @@ -75,29 +75,29 @@ iface vni104001 vxlan-local-tunnelip 10.0.0.10 # PXE-Config -auto vlan966 -iface vlan966 +auto vlan4000 +iface vlan4000 mtu 9000 address 10.255.255.2/24 - vlan-id 966 + vlan-id 4000 vlan-raw-device bridge -auto vni10966 -iface vni10966 +auto vni104000 +iface vni104000 mtu 9000 - bridge-access 966 + bridge-access 4000 bridge-learning off mstpctl-bpduguard yes mstpctl-portbpdufilter yes - vxlan-id 10966 + vxlan-id 104000 vxlan-local-tunnelip 10.0.0.10 auto swp4 iface swp4 mtu 9000 - bridge-access 966 + bridge-access 4000 auto swp5 iface swp5 mtu 9000 - bridge-access 966 + bridge-access 4000 \ No newline at end of file diff --git a/cmd/internal/switcher/templates/test_data/dev/customtpl/interfaces.tpl b/cmd/internal/switcher/templates/test_data/dev/customtpl/interfaces.tpl index e9674968..0a887873 100644 --- a/cmd/internal/switcher/templates/test_data/dev/customtpl/interfaces.tpl +++ b/cmd/internal/switcher/templates/test_data/dev/customtpl/interfaces.tpl @@ -1,5 +1,4 @@ {{- $IPLoopback := .Loopback -}} -{{- $PXEVlanID := .PXEVlanID -}} # This file describes the network interfaces available on your system # and how to activate them. For more information, see interfaces(5). @@ -36,8 +35,8 @@ iface {{ .Port }} auto bridge iface bridge - bridge-ports vni10{{ $PXEVlanID }} {{ range .Ports.Unprovisioned }}{{ . }} {{ end }}{{ range .Ports.BladePorts }}{{ . }} {{ end }}{{ range $vrf, $t := .Ports.Vrfs }}vni{{ $t.VNI }}{{ end }} - bridge-vids {{ $PXEVlanID }} {{ range $vrf, $t := .Ports.Vrfs }}{{ $t.VLANID }}{{ end }}{{ range $vids := .AdditionalBridgeVIDs }} {{ $vids }}{{ end }} + bridge-ports vni104000{{ range .Ports.Unprovisioned }} {{ . }}{{ end }}{{ range .Ports.BladePorts }} {{ . }}{{ end }}{{ range $vrf, $t := .Ports.Vrfs }} vni{{ $t.VNI }}{{ end }} + bridge-vids 4000{{ range $vrf, $t := .Ports.Vrfs }} {{ $t.VLANID }}{{ end }}{{ range $vids := .AdditionalBridgeVIDs }} {{ $vids }}{{ end }} bridge-vlan-aware yes # Tenants @@ -76,21 +75,21 @@ iface vni{{ $t.VNI }} {{- end }} # PXE-Config -auto vlan{{ $PXEVlanID }} -iface vlan{{ $PXEVlanID }} +auto vlan4000 +iface vlan4000 mtu 9000 address {{ .MetalCoreCIDR }} - vlan-id {{ $PXEVlanID }} + vlan-id 4000 vlan-raw-device bridge -auto vni10{{ $PXEVlanID }} -iface vni10{{ $PXEVlanID }} +auto vni104000 +iface vni104000 mtu 9000 - bridge-access {{ $PXEVlanID }} + bridge-access 4000 bridge-learning off mstpctl-bpduguard yes mstpctl-portbpdufilter yes - vxlan-id 10{{ $PXEVlanID }} + vxlan-id 104000 vxlan-local-tunnelip {{ $IPLoopback }} {{- range .Ports.Unprovisioned }} @@ -98,5 +97,5 @@ iface vni10{{ $PXEVlanID }} auto {{ . }} iface {{ . }} mtu 9000 - bridge-access {{ $PXEVlanID }} -{{- end }} + bridge-access 4000 +{{- end }} \ No newline at end of file diff --git a/cmd/internal/switcher/templates/test_data/dev/interfaces b/cmd/internal/switcher/templates/test_data/dev/interfaces index a2a5b210..a9fc2416 100644 --- a/cmd/internal/switcher/templates/test_data/dev/interfaces +++ b/cmd/internal/switcher/templates/test_data/dev/interfaces @@ -34,7 +34,7 @@ iface swp3 auto bridge iface bridge - bridge-ports vni10966 swp4 swp5 swp7 swp8 vni104001 + bridge-ports vni100966 swp4 swp5 swp7 swp8 vni104001 bridge-vids 966 4001 201-256 301-356 bridge-vlan-aware yes @@ -82,14 +82,14 @@ iface vlan966 vlan-id 966 vlan-raw-device bridge -auto vni10966 -iface vni10966 +auto vni100966 +iface vni100966 mtu 9000 bridge-access 966 bridge-learning off mstpctl-bpduguard yes mstpctl-portbpdufilter yes - vxlan-id 10966 + vxlan-id 100966 vxlan-local-tunnelip 10.0.0.10 auto swp4 diff --git a/cmd/internal/switcher/templates/test_data/lab/interfaces b/cmd/internal/switcher/templates/test_data/lab/interfaces index 387f4b9a..8d46ea23 100644 --- a/cmd/internal/switcher/templates/test_data/lab/interfaces +++ b/cmd/internal/switcher/templates/test_data/lab/interfaces @@ -34,7 +34,7 @@ iface swp3 auto bridge iface bridge - bridge-ports vni10966 swp4 swp5 vni104001 + bridge-ports vni100966 swp4 swp5 vni104001 bridge-vids 966 4001 bridge-vlan-aware yes @@ -82,14 +82,14 @@ iface vlan966 vlan-id 966 vlan-raw-device bridge -auto vni10966 -iface vni10966 +auto vni100966 +iface vni100966 mtu 9000 bridge-access 966 bridge-learning off mstpctl-bpduguard yes mstpctl-portbpdufilter yes - vxlan-id 10966 + vxlan-id 100966 vxlan-local-tunnelip 10.0.0.10 auto swp4 diff --git a/cmd/internal/switcher/templates/test_data/notenants/interfaces b/cmd/internal/switcher/templates/test_data/notenants/interfaces index 8c1797cb..af323e66 100644 --- a/cmd/internal/switcher/templates/test_data/notenants/interfaces +++ b/cmd/internal/switcher/templates/test_data/notenants/interfaces @@ -30,7 +30,7 @@ iface swp32 auto bridge iface bridge - bridge-ports vni10966 swp1 swp2 + bridge-ports vni100966 swp1 swp2 bridge-vids 966 bridge-vlan-aware yes @@ -44,14 +44,14 @@ iface vlan966 vlan-id 966 vlan-raw-device bridge -auto vni10966 -iface vni10966 +auto vni100966 +iface vni100966 mtu 9000 bridge-access 966 bridge-learning off mstpctl-bpduguard yes mstpctl-portbpdufilter yes - vxlan-id 10966 + vxlan-id 100966 vxlan-local-tunnelip 10.0.0.10 auto swp1 diff --git a/cmd/internal/switcher/templates/test_down_interfaces/interfaces_with_downports b/cmd/internal/switcher/templates/test_down_interfaces/interfaces_with_downports index 3308eae5..341e4d12 100644 --- a/cmd/internal/switcher/templates/test_down_interfaces/interfaces_with_downports +++ b/cmd/internal/switcher/templates/test_down_interfaces/interfaces_with_downports @@ -30,7 +30,7 @@ iface swp32 auto bridge iface bridge - bridge-ports vni10966 swp1 swp2 vni1 + bridge-ports vni100966 swp1 swp2 vni1 bridge-vids 966 2 bridge-vlan-aware yes @@ -66,14 +66,14 @@ iface vlan966 vlan-id 966 vlan-raw-device bridge -auto vni10966 -iface vni10966 +auto vni100966 +iface vni100966 mtu 9000 bridge-access 966 bridge-learning off mstpctl-bpduguard yes mstpctl-portbpdufilter yes - vxlan-id 10966 + vxlan-id 100966 vxlan-local-tunnelip 10.0.0.10 auto swp1 diff --git a/cmd/internal/switcher/templates/tpl/interfaces.tpl b/cmd/internal/switcher/templates/tpl/interfaces.tpl index fb04a659..e4ddec12 100644 --- a/cmd/internal/switcher/templates/tpl/interfaces.tpl +++ b/cmd/internal/switcher/templates/tpl/interfaces.tpl @@ -1,5 +1,6 @@ {{- $IPLoopback := .Loopback -}} {{- $PXEVlanID := .PXEVlanID -}} +{{- $PXEVni := printf "10%04d" $PXEVlanID -}} # This file describes the network interfaces available on your system # and how to activate them. For more information, see interfaces(5). @@ -36,7 +37,7 @@ iface {{ .Port }} auto bridge iface bridge - bridge-ports vni10{{ $PXEVlanID }}{{ range .Ports.Unprovisioned }} {{ . }}{{ end }}{{ range .Ports.BladePorts }} {{ . }}{{ end }}{{ range $vrf, $t := .Ports.Vrfs }} vni{{ $t.VNI }}{{ end }} + bridge-ports vni{{ $PXEVni }}{{ range .Ports.Unprovisioned }} {{ . }}{{ end }}{{ range .Ports.BladePorts }} {{ . }}{{ end }}{{ range $vrf, $t := .Ports.Vrfs }} vni{{ $t.VNI }}{{ end }} bridge-vids {{ $PXEVlanID }}{{ range $vrf, $t := .Ports.Vrfs }} {{ $t.VLANID }}{{ end }}{{ range $vids := .AdditionalBridgeVIDs }} {{ $vids }}{{ end }} bridge-vlan-aware yes @@ -83,14 +84,14 @@ iface vlan{{ $PXEVlanID }} vlan-id {{ $PXEVlanID }} vlan-raw-device bridge -auto vni10{{ $PXEVlanID }} -iface vni10{{ $PXEVlanID }} +auto vni{{ $PXEVni }} +iface vni{{ $PXEVni }} mtu 9000 bridge-access {{ $PXEVlanID }} bridge-learning off mstpctl-bpduguard yes mstpctl-portbpdufilter yes - vxlan-id 10{{ $PXEVlanID }} + vxlan-id {{ $PXEVni }} vxlan-local-tunnelip {{ $IPLoopback }} {{- range .Ports.Unprovisioned }}