Skip to content

Commit

Permalink
Merge pull request #834 from VladoLavor/logs-errors-sr
Browse files Browse the repository at this point in the history
sr-plugin: logs & errors
  • Loading branch information
ondrej-fabry committed Aug 28, 2018
2 parents 2361cdb + 51fd19b commit f933fe3
Show file tree
Hide file tree
Showing 5 changed files with 260 additions and 176 deletions.
36 changes: 24 additions & 12 deletions plugins/vpp/data_change.go
Original file line number Diff line number Diff line change
Expand Up @@ -716,43 +716,55 @@ func (plugin *Plugin) dataChangeIPSecTunnel(diff bool, value, prevValue *ipsec.T
// DataChangeLocalSID handles change events from ETCD related to local SIDs
func (plugin *Plugin) dataChangeLocalSID(diff bool, value *srv6.LocalSID, prevValue *srv6.LocalSID, changeType datasync.Op) error {
plugin.Log.Debug("dataChangeLocalSIDs ", diff, " ", changeType, " ", value, " ", prevValue)
var err error
if datasync.Delete == changeType {
return plugin.srv6Configurator.DeleteLocalSID(prevValue)
err = plugin.srv6Configurator.DeleteLocalSID(prevValue)
} else if diff {
return plugin.srv6Configurator.ModifyLocalSID(value, prevValue)
err = plugin.srv6Configurator.ModifyLocalSID(value, prevValue)
} else {
err = plugin.srv6Configurator.AddLocalSID(value)
}
return plugin.srv6Configurator.AddLocalSID(value)
return plugin.srv6Configurator.LogError(err)
}

// dataChangePolicy handles change events from ETCD related to policies
func (plugin *Plugin) dataChangePolicy(diff bool, value *srv6.Policy, prevValue *srv6.Policy, changeType datasync.Op) error {
plugin.Log.Debug("dataChangePolicy ", diff, " ", changeType, " ", value, " ", prevValue)
var err error
if datasync.Delete == changeType {
return plugin.srv6Configurator.RemovePolicy(prevValue)
err = plugin.srv6Configurator.RemovePolicy(prevValue)
} else if diff {
return plugin.srv6Configurator.ModifyPolicy(value, prevValue)
err = plugin.srv6Configurator.ModifyPolicy(value, prevValue)
} else {
err = plugin.srv6Configurator.AddPolicy(value)
}
return plugin.srv6Configurator.AddPolicy(value)
return plugin.srv6Configurator.LogError(err)
}

// dataChangePolicySegment handles change events from ETCD related to policies segments
func (plugin *Plugin) dataChangePolicySegment(segmentName string, diff bool, value *srv6.PolicySegment, prevValue *srv6.PolicySegment, changeType datasync.Op) error {
plugin.Log.Debug("dataChangePolicySegment ", segmentName, " ", diff, " ", changeType, " ", value, " ", prevValue)
var err error
if datasync.Delete == changeType {
return plugin.srv6Configurator.RemovePolicySegment(segmentName, prevValue)
err = plugin.srv6Configurator.RemovePolicySegment(segmentName, prevValue)
} else if diff {
return plugin.srv6Configurator.ModifyPolicySegment(segmentName, value, prevValue)
err = plugin.srv6Configurator.ModifyPolicySegment(segmentName, value, prevValue)
} else {
err = plugin.srv6Configurator.AddPolicySegment(segmentName, value)
}
return plugin.srv6Configurator.AddPolicySegment(segmentName, value)
return plugin.srv6Configurator.LogError(err)
}

// dataChangeSteering handles change events from ETCD related to steering
func (plugin *Plugin) dataChangeSteering(steeringName string, diff bool, value *srv6.Steering, prevValue *srv6.Steering, changeType datasync.Op) error {
plugin.Log.Debug("dataChangeSteering ", steeringName, " ", diff, " ", changeType, " ", value, " ", prevValue)
var err error
if datasync.Delete == changeType {
return plugin.srv6Configurator.RemoveSteering(steeringName, prevValue)
err = plugin.srv6Configurator.RemoveSteering(steeringName, prevValue)
} else if diff {
return plugin.srv6Configurator.ModifySteering(steeringName, value, prevValue)
err = plugin.srv6Configurator.ModifySteering(steeringName, value, prevValue)
} else {
err = plugin.srv6Configurator.AddSteering(steeringName, value)
}
return plugin.srv6Configurator.AddSteering(steeringName, value)
return plugin.srv6Configurator.LogError(err)
}
2 changes: 1 addition & 1 deletion plugins/vpp/data_resync.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ func (plugin *Plugin) resyncConfig(req *DataResyncReq) error {
}
if !plugin.droppedFromResync(srv6.BasePrefix()) {
if err := plugin.srv6Configurator.Resync(req.LocalSids, req.SrPolicies, req.SrPolicySegments, req.SrSteerings); err != nil {
resyncErrs = append(resyncErrs, err)
resyncErrs = append(resyncErrs, plugin.srv6Configurator.LogError(err))
}
}
// log errors if any
Expand Down
2 changes: 1 addition & 1 deletion plugins/vpp/plugin_impl_vpp.go
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@ func (plugin *Plugin) initSR(ctx context.Context) (err error) {
// Init SR configurator
plugin.srv6Configurator = &srplugin.SRv6Configurator{}
if err := plugin.srv6Configurator.Init(plugin.Log, plugin.GoVppmux, plugin.swIfIndexes, plugin.enableStopwatch, nil); err != nil {
return err
return plugin.srv6Configurator.LogError(err)
}

plugin.Log.Debug("SRConfigurator Initialized")
Expand Down
29 changes: 12 additions & 17 deletions plugins/vpp/srplugin/data_resync.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package srplugin

import (
"github.com/go-errors/errors"
"github.com/ligato/vpp-agent/plugins/vpp/model/srv6"
)

Expand All @@ -32,42 +33,36 @@ type NamedSteering struct {
}

// Resync writes missing segment routing configs to the VPP and removes obsolete ones.
func (plugin *SRv6Configurator) Resync(localSids []*srv6.LocalSID, policies []*srv6.Policy, namedSegments []*NamedPolicySegment, namedSteerings []*NamedSteering) error {
plugin.log.Debug("RESYNC SR begin.")

func (c *SRv6Configurator) Resync(localSids []*srv6.LocalSID, policies []*srv6.Policy, namedSegments []*NamedPolicySegment, namedSteerings []*NamedSteering) error {
// Re-initialize cache
plugin.clearMapping()
c.clearMapping()

// TODO: dump existing configuration from VPP, compare it with etcd and change vpp according to etcd (now is handled only case when VPP is clean, i.e. from starting)

for _, localsid := range localSids {
if err := plugin.AddLocalSID(localsid); err != nil {
plugin.log.Error(err)
continue
if err := c.AddLocalSID(localsid); err != nil {
return errors.Errorf("sr resync error: failed to add local sid %s: %v", localsid, err)
}
}

for _, policy := range policies {
if err := plugin.AddPolicy(policy); err != nil {
plugin.log.Error(err)
continue
if err := c.AddPolicy(policy); err != nil {
return errors.Errorf("sr resync error: failed to add policy %s: %v", policy.GetBsid(), err)
}
}

for _, namedSegment := range namedSegments {
if err := plugin.AddPolicySegment(namedSegment.Name, namedSegment.Segment); err != nil {
plugin.log.Error(err)
continue
if err := c.AddPolicySegment(namedSegment.Name, namedSegment.Segment); err != nil {
return errors.Errorf("sr resync error: failed to add policy segment %s: %v", namedSegment.Name, err)
}
}

for _, namedSteering := range namedSteerings {
if err := plugin.AddSteering(namedSteering.Name, namedSteering.Steering); err != nil {
plugin.log.Error(err)
continue
if err := c.AddSteering(namedSteering.Name, namedSteering.Steering); err != nil {
return errors.Errorf("sr resync error: failed to add steering %s: %v", namedSteering.Name, err)
}
}

plugin.log.Debug("RESYNC SR end.")
c.log.Info("Segment routing resync done")
return nil
}

0 comments on commit f933fe3

Please sign in to comment.