Skip to content

Commit

Permalink
oopt: forbid over-subscription by default
Browse files Browse the repository at this point in the history
Signed-off-by: Wataru Ishida <ishida@nel-america.com>
  • Loading branch information
Wataru Ishida committed Feb 26, 2019
1 parent 32f8888 commit 2350104
Show file tree
Hide file tree
Showing 5 changed files with 1,321 additions and 1,104 deletions.
45 changes: 40 additions & 5 deletions cmd/oopt/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,23 @@ func validateFinal(config *model.PacketTransponder) error {
return fmt.Errorf("invalid num-channels %d for port %s", *bMode.NumChannels, k)
}
}
for k, v := range config.OpticalModule {
if err := sonic.FillTransportDefaultConfig(v, config); err != nil {
return err
}
if *v.AllowOversubscription {
continue
}
for ch, s := range v.ChannelStats {
f, err := strconv.ParseFloat(*s.Occupancy, 64)
if err != nil {
return err
}
if f > 100.0 {
return fmt.Errorf("name: %s, channel: %s over-subscribed: %f%%", k, ch, f)
}
}
}
return nil
}

Expand Down Expand Up @@ -266,12 +283,13 @@ const (
opticalModuleNum = 8
)

func newInterface(t *model.PacketTransponder, name string) error {
func newInterface(t *model.PacketTransponder, name string, speed model.E_OpenconfigIfEthernet_ETHERNET_SPEED) error {
iface, err := t.NewInterface(name)
if err != nil {
return err
}
iface.Mtu = ygot.Uint16(1500)
iface.PortSpeed = speed
return nil
}

Expand All @@ -282,11 +300,12 @@ func defaultConfiguration() (*model.PacketTransponder, error) {
if err != nil {
return nil, fmt.Errorf("failed to create port: %v", err)
}
speed := model.OpenconfigIfEthernet_ETHERNET_SPEED_SPEED_100GB
port.BreakoutMode = &model.PacketTransponder_Port_BreakoutMode{
ChannelSpeed: model.OpenconfigIfEthernet_ETHERNET_SPEED_SPEED_100GB,
ChannelSpeed: speed,
NumChannels: ygot.Uint8(1),
}
err = newInterface(d, fmt.Sprintf("Ethernet%d", i))
err = newInterface(d, fmt.Sprintf("Ethernet%d", i), speed)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -436,6 +455,19 @@ func NewPortCmd() *cobra.Command {
}

current.Port[name].BreakoutMode.ChannelSpeed = speed

portNum, err := strconv.Atoi(name[len("Port"):])
if err != nil {
return err
}

ethName := fmt.Sprintf("Ethernet%d", portNum)

for k, v := range current.Interface {
if k == ethName || strings.HasPrefix(k, ethName+"_") {
v.PortSpeed = speed
}
}
return nil
},
}
Expand Down Expand Up @@ -469,14 +501,14 @@ func NewPortCmd() *cobra.Command {
for i := 1; i <= 4; i++ {
delete(current.Interface, fmt.Sprintf("Ethernet%d_%d", portNum, i))
}
err = newInterface(current, fmt.Sprintf("Ethernet%d", portNum))
err = newInterface(current, fmt.Sprintf("Ethernet%d", portNum), current.Port[name].BreakoutMode.ChannelSpeed)
if err != nil {
return err
}
case 4:
delete(current.Interface, fmt.Sprintf("Ethernet%d", portNum))
for i := 1; i <= 4; i++ {
err = newInterface(current, fmt.Sprintf("Ethernet%d_%d", portNum, i))
err = newInterface(current, fmt.Sprintf("Ethernet%d_%d", portNum, i), current.Port[name].BreakoutMode.ChannelSpeed)
if err != nil {
return err
}
Expand Down Expand Up @@ -1123,6 +1155,9 @@ func commit(commitMessage string, reboot bool) error {
if err != nil {
return err
}
if dry {
return nil
}
iter, err := repo.Log(&git.LogOptions{})
if err != nil {
return err
Expand Down
Loading

0 comments on commit 2350104

Please sign in to comment.