Skip to content

Commit

Permalink
Address comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
guoshiuan committed Sep 18, 2024
1 parent 3f2a637 commit 1399268
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 24 deletions.
13 changes: 7 additions & 6 deletions dataplane/dplanerc/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,10 +204,14 @@ func (ni *Reconciler) StartInterface(ctx context.Context, client *ygnmi.Client)
if !ok || (root.Interface == nil && root.Lldp.Interface == nil) {
return ygnmi.Continue
}
for _, i := range root.Interface {
ni.reconcile(cancelCtx, i)
if root.Interface != nil {
for _, i := range root.Interface {
ni.reconcile(cancelCtx, i)
}
}
if root.Lldp.Interface != nil {
ni.reconcileLldp(cancelCtx, root)
}
ni.reconcileLldp(cancelCtx, root)
return ygnmi.Continue
})
linkDoneCh := make(chan struct{})
Expand Down Expand Up @@ -513,9 +517,6 @@ func (ni *Reconciler) setMinLinks(intf ocInterface, data *interfaceData, minLink

// reconcileLldp compares the LLDP config with state and modifies state to match config.
func (ni *Reconciler) reconcileLldp(ctx context.Context, intent *oc.Root) {
if intent.Lldp.Interface == nil {
return
}
if err := ni.lldp.Reconcile(ctx, intent, ni.c); err != nil {
log.Warningf("error found LLDP reconciliation: %v", err)
}
Expand Down
22 changes: 4 additions & 18 deletions dataplane/protocol/lldp/lldp.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func (d *Daemon) Stop() {
d.portDaemons = nil
}

// changePortState tries to change the port state and returns whether the state is acutally changed.
// changePortState tries to change the port state and returns whether the state is actually changed.
func (d *Daemon) changePortState(intf *oc.Lldp_Interface) bool {
// Update the PD state.
wantActive := d.enabled && intf.GetEnabled()
Expand All @@ -91,32 +91,18 @@ func (d *Daemon) changePortState(intf *oc.Lldp_Interface) bool {
return false
}

func (d *Daemon) reconcileLldpEnabled(sb *ygnmi.SetBatch, intent *oc.Root, c *ygnmi.Client) error {
// Reconcile reconciles LLDP for all ports.
func (d *Daemon) Reconcile(ctx context.Context, intent *oc.Root, c *ygnmi.Client) error {
sb := &ygnmi.SetBatch{}
if wantEnabled := intent.Lldp.GetEnabled(); d.enabled != wantEnabled {
d.enabled = wantEnabled
gnmiclient.BatchUpdate(sb, ocpath.Root().Lldp().Enabled().State(), d.enabled)
}
return nil
}

func (d *Daemon) reconcileLldpInterfaceEnabled(sb *ygnmi.SetBatch, intent *oc.Root, c *ygnmi.Client) error {
for _, intf := range intent.GetLldp().Interface {
if changed := d.changePortState(intf); changed {
gnmiclient.BatchUpdate(sb, ocpath.Root().Lldp().Interface(intf.GetName()).Enabled().State(), intf.GetEnabled())
}
}
return nil
}

// Reconcile reconciles LLDP for all ports.
func (d *Daemon) Reconcile(ctx context.Context, intent *oc.Root, c *ygnmi.Client) error {
sb := &ygnmi.SetBatch{}
for _, f := range []func(*ygnmi.SetBatch, *oc.Root, *ygnmi.Client) error{
d.reconcileLldpEnabled,
d.reconcileLldpInterfaceEnabled,
} {
f(sb, intent, c)
}
if _, err := sb.Set(ctx, c); err != nil {
return fmt.Errorf("failed to update LLDP enable state: %v", err)
}
Expand Down

0 comments on commit 1399268

Please sign in to comment.