Skip to content

Commit

Permalink
Remove fec config from sonic applier (#132)
Browse files Browse the repository at this point in the history
  • Loading branch information
iljarotar authored Oct 16, 2024
1 parent 4ab8042 commit 4be4306
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 68 deletions.
10 changes: 0 additions & 10 deletions cmd/internal/switcher/sonic/db/asicdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,3 @@ func (d *AsicDB) ExistRouterInterface(ctx context.Context, rif OID) (bool, error

return d.c.Exists(ctx, key)
}

func (d *AsicDB) InFecModeRs(ctx context.Context, port OID) (bool, error) {
key := Key{"ASIC_STATE", "SAI_OBJECT_TYPE_PORT", string(port)}

result, err := d.c.HGet(ctx, key, "SAI_PORT_ATTR_FEC_MODE")
if err != nil {
return false, err
}
return result == "SAI_PORT_FEC_MODE_RS", err
}
18 changes: 0 additions & 18 deletions cmd/internal/switcher/sonic/db/configdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ const (
adminStatusUp = "up"
adminStatusDown = "down"
mtu = "mtu"
fec = "fec"
fecRS = "rs"
fecNone = "none"
)

type ConfigDB struct {
Expand All @@ -30,7 +27,6 @@ type ConfigDB struct {
type Port struct {
AdminStatus bool
Mtu string
FecRs bool
}

func newConfigDB(addr string, id int, sep string) *ConfigDB {
Expand Down Expand Up @@ -182,23 +178,9 @@ func (d *ConfigDB) GetPort(ctx context.Context, interfaceName string) (*Port, er
return &Port{
AdminStatus: result[adminStatus] == adminStatusUp,
Mtu: result[mtu],
FecRs: result[fec] == fecRS,
}, nil
}

func (d *ConfigDB) SetPortFecMode(ctx context.Context, interfaceName string, isFecRs bool) error {
key := Key{portTable, interfaceName}

var mode string
if isFecRs {
mode = fecRS
} else {
mode = fecNone
}

return d.c.HSet(ctx, key, Val{fec: mode})
}

func (d *ConfigDB) SetPortMtu(ctx context.Context, interfaceName string, val string) error {
key := Key{portTable, interfaceName}

Expand Down
8 changes: 4 additions & 4 deletions cmd/internal/switcher/sonic/redis/applier.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func (a *Applier) configureUnprovisionedPort(interfaceName string, isUp bool, px
}

// unprovisioned ports should be up
if err := a.ensurePortConfiguration(ctx, interfaceName, "9000", true, isUp); err != nil {
if err := a.ensurePortConfiguration(ctx, interfaceName, "9000", isUp); err != nil {
return fmt.Errorf("failed to update Port info for interface %s: %w", interfaceName, err)
}

Expand All @@ -143,7 +143,7 @@ func (a *Applier) configureFirewallPort(interfaceName string, isUp bool) error {
}

// a firewall port should always be up
if err := a.ensurePortConfiguration(ctx, interfaceName, "9216", true, isUp); err != nil {
if err := a.ensurePortConfiguration(ctx, interfaceName, "9216", isUp); err != nil {
return fmt.Errorf("failed to update Port info for interface %s: %w", interfaceName, err)
}

Expand All @@ -155,7 +155,7 @@ func (a *Applier) configureUnderlayPort(interfaceName string, isUp bool) error {
defer cancel()

// underlay ports should be up
if err := a.ensurePortConfiguration(ctx, interfaceName, "9216", false, isUp); err != nil {
if err := a.ensurePortConfiguration(ctx, interfaceName, "9216", isUp); err != nil {
return fmt.Errorf("failed to update Port info for interface %s: %w", interfaceName, err)
}
return a.ensureLinkLocalOnlyIsEnabled(ctx, interfaceName)
Expand All @@ -175,7 +175,7 @@ func (a *Applier) configureVrfNeighbor(interfaceName, vrfName string, isUp bool)
return err
}

if err := a.ensurePortConfiguration(ctx, interfaceName, "9000", true, isUp); err != nil {
if err := a.ensurePortConfiguration(ctx, interfaceName, "9000", isUp); err != nil {
return fmt.Errorf("failed to update Port info for interface %s: %w", interfaceName, err)
}

Expand Down
37 changes: 1 addition & 36 deletions cmd/internal/switcher/sonic/redis/port.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,14 @@ package redis
import (
"context"
"fmt"

"github.com/avast/retry-go/v4"
)

func (a *Applier) ensurePortConfiguration(ctx context.Context, portName, mtu string, isFecRs, isUp bool) error {
func (a *Applier) ensurePortConfiguration(ctx context.Context, portName, mtu string, isUp bool) error {
p, err := a.db.Config.GetPort(ctx, portName)
if err != nil {
return fmt.Errorf("could not retrieve port info for %s from redis: %w", portName, err)
}

if p.FecRs != isFecRs {
a.log.Debug("set port rs mode to", "port", portName, "mode", isFecRs)
err = a.ensurePortFecMode(ctx, portName, isFecRs)
if err != nil {
return err
}
}

if p.Mtu != mtu {
a.log.Debug("set port mtu to", "port", portName, "mtu", mtu)
err = a.db.Config.SetPortMtu(ctx, portName, mtu)
Expand All @@ -36,28 +26,3 @@ func (a *Applier) ensurePortConfiguration(ctx context.Context, portName, mtu str

return nil
}

func (a *Applier) ensurePortFecMode(ctx context.Context, portName string, wantFecRs bool) error {
err := a.db.Config.SetPortFecMode(ctx, portName, wantFecRs)
if err != nil {
return fmt.Errorf("could not update Fec for port %s: %w", portName, err)
}

oid, ok := a.portOidMap[portName]
if !ok {
return fmt.Errorf("no mapping of port %s to OID", portName)
}

return retry.Do(
func() error {
isFecRs, err := a.db.Asic.InFecModeRs(ctx, oid)
if err != nil {
return err
}
if isFecRs != wantFecRs {
return fmt.Errorf("port %s still has rs mode = %v, but want %v", portName, isFecRs, wantFecRs)
}
return nil
},
)
}

0 comments on commit 4be4306

Please sign in to comment.