summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorWataru Ishida <ishida.wataru@lab.ntt.co.jp>2016-10-22 15:02:18 +0000
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2016-10-27 14:41:57 -0700
commitf75d45bbc4a58d21c5c6e261c7b68eac7495f107 (patch)
tree99b72bb10de0587aa273eb2a9f1904a36a398d6a
parentbc0bf8c0fb36f42f40642a3036fa3616ba18c15e (diff)
bgp: remove duplicate large communities
closes #1143 Signed-off-by: Wataru Ishida <ishida.wataru@lab.ntt.co.jp>
-rw-r--r--packet/bgp/validate.go15
-rw-r--r--packet/bgp/validate_test.go15
2 files changed, 30 insertions, 0 deletions
diff --git a/packet/bgp/validate.go b/packet/bgp/validate.go
index da7aa5fc..5cf2afbb 100644
--- a/packet/bgp/validate.go
+++ b/packet/bgp/validate.go
@@ -159,6 +159,21 @@ func ValidateAttribute(a PathAttributeInterface, rfs map[RouteFamily]bool, doCon
}
}
}
+ case *PathAttributeLargeCommunities:
+ uniq := make([]*LargeCommunity, 0, len(p.Values))
+ for _, x := range p.Values {
+ found := false
+ for _, y := range uniq {
+ if x.String() == y.String() {
+ found = true
+ break
+ }
+ }
+ if !found {
+ uniq = append(uniq, x)
+ }
+ }
+ p.Values = uniq
case *PathAttributeUnknown:
if p.GetFlags()&BGP_ATTR_FLAG_OPTIONAL == 0 {
diff --git a/packet/bgp/validate_test.go b/packet/bgp/validate_test.go
index 66eb56d5..225f941d 100644
--- a/packet/bgp/validate_test.go
+++ b/packet/bgp/validate_test.go
@@ -384,3 +384,18 @@ func Test_Validate_flowspec(t *testing.T) {
_, err = ValidateAttribute(a, m, false)
assert.NotNil(err)
}
+
+func TestValidateLargeCommunities(t *testing.T) {
+ assert := assert.New(t)
+ c1, err := ParseLargeCommunity("10:10:10")
+ assert.Nil(err)
+ c2, err := ParseLargeCommunity("10:10:10")
+ assert.Nil(err)
+ c3, err := ParseLargeCommunity("10:10:20")
+ assert.Nil(err)
+ a := NewPathAttributeLargeCommunities([]*LargeCommunity{c1, c2, c3})
+ assert.True(len(a.Values) == 3)
+ _, err = ValidateAttribute(a, nil, false)
+ assert.Nil(err)
+ assert.True(len(a.Values) == 2)
+}