Skip to content

Commit

Permalink
fixed SRv6 segment lists delete problems (ligato#1456)
Browse files Browse the repository at this point in the history
Signed-off-by: Filip Gschwandtner <filip.gschwandtner@pantheon.tech>
  • Loading branch information
jgallo542 authored and ondrej-fabry committed Sep 4, 2019
1 parent b106be8 commit db302e2
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions plugins/vpp/srplugin/descriptor/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package descriptor
import (
"github.com/pkg/errors"

"github.com/gogo/protobuf/proto"
"github.com/ligato/cn-infra/logging"
"github.com/ligato/vpp-agent/api/models/vpp/l3"
srv6 "github.com/ligato/vpp-agent/api/models/vpp/srv6"
Expand Down Expand Up @@ -54,7 +55,7 @@ type PolicyDescriptor struct {

// PolicyMetadata are Policy-related metadata that KVscheduler bundles with Policy data. They are served by KVScheduler in Create/Update descriptor methods.
type PolicyMetadata struct {
segmentListIndexes map[*srv6.Policy_SegmentList]uint32
segmentListIndexes map[string]uint32 // map[marshalled segment list]index in policy
}

// NewPolicyDescriptor creates a new instance of the Srv6 policy descriptor.
Expand Down Expand Up @@ -122,9 +123,9 @@ func (d *PolicyDescriptor) Create(key string, policy *srv6.Policy) (metadata int
}

// retrieve from VPP indexes of just added Policy/Segment Lists and store it as metadata
_, slIndexes, err := d.srHandler.RetrievePolicyIndexInfo(policy)
slIndexes, err := d.policyIndexInfo(policy)
if err != nil {
return nil, errors.Errorf("can't retrieve indexes of created srv6 policy with bsid %v : %v", policy.GetBsid(), err)
return nil, errors.Wrapf(err, "can't retrieve indexes of created srv6 policy with bsid %v", policy.GetBsid())
}
metadata = &PolicyMetadata{
segmentListIndexes: slIndexes,
Expand Down Expand Up @@ -172,7 +173,7 @@ func (d *PolicyDescriptor) Update(key string, oldPolicy, newPolicy *srv6.Policy,
// remove old segment lists not present in newPolicy
slIndexes := oldMetadata.(*PolicyMetadata).segmentListIndexes
for _, sl := range removePool {
index, exists := slIndexes[sl]
index, exists := slIndexes[proto.CompactTextString(sl)]
if !exists {
return nil, errors.Errorf("failed update policy: failed to find index for segment list "+
"%+v in policy with bsid %v (metadata segment list indexes: %+v)", sl, oldPolicy.GetBsid(), slIndexes)
Expand All @@ -183,9 +184,9 @@ func (d *PolicyDescriptor) Update(key string, oldPolicy, newPolicy *srv6.Policy,
}

// update metadata be recreation it from scratch
_, slIndexes, err = d.srHandler.RetrievePolicyIndexInfo(newPolicy)
slIndexes, err = d.policyIndexInfo(newPolicy)
if err != nil {
return nil, errors.Errorf("can't retrieve indexes of updated srv6 policy with bsid %v : %v", newPolicy.GetBsid(), err)
return nil, errors.Wrapf(err, "can't retrieve indexes of updated srv6 policy with bsid %v", newPolicy.GetBsid())
}
newMetadata = &PolicyMetadata{
segmentListIndexes: slIndexes,
Expand All @@ -194,6 +195,19 @@ func (d *PolicyDescriptor) Update(key string, oldPolicy, newPolicy *srv6.Policy,
return newMetadata, nil
}

// policyIndexInfo retrieves indexes for segment lists of given policy
func (d *PolicyDescriptor) policyIndexInfo(policy *srv6.Policy) (map[string]uint32, error) {
_, indexes, err := d.srHandler.RetrievePolicyIndexInfo(policy)
if err != nil {
return nil, errors.Wrapf(err, "can't retrieve indexes of srv6 policy with bsid %v from vpp", policy.GetBsid())
}
result := make(map[string]uint32)
for slist, index := range indexes {
result[proto.CompactTextString(slist)] = index
}
return result, nil
}

// UpdateWithRecreate define whether update case should be handled by complete policy recreation
func (d *PolicyDescriptor) UpdateWithRecreate(key string, oldPolicy, newPolicy *srv6.Policy, oldMetadata interface{}) bool {
return !d.equivalentPolicyAttributes(oldPolicy, newPolicy) // update with recreate only when policy attributes changes because segment list change can be handled more efficiently
Expand Down

0 comments on commit db302e2

Please sign in to comment.