summaryrefslogtreecommitdiffhomepage
path: root/table
diff options
context:
space:
mode:
Diffstat (limited to 'table')
-rw-r--r--table/path.go21
-rw-r--r--table/table_manager.go16
-rw-r--r--table/table_manager_test.go2
3 files changed, 25 insertions, 14 deletions
diff --git a/table/path.go b/table/path.go
index 846c7e16..4ef9c070 100644
--- a/table/path.go
+++ b/table/path.go
@@ -39,7 +39,7 @@ type Path interface {
getPrefix() net.IP
setMedSetByTargetNeighbor(medSetByTargetNeighbor bool)
getMedSetByTargetNeighbor() bool
- Clone() Path
+ Clone(IsWithdraw bool) Path
}
type PathDefault struct {
@@ -74,15 +74,18 @@ func NewPathDefault(rf RouteFamily, source *PeerInfo, nlri bgp.AddrPrefixInterfa
}
// create new PathAttributes
-func (pd *PathDefault) Clone() Path {
- copiedAttrs := append([]bgp.PathAttributeInterface(nil), pd.pathAttrs...)
- for i, attr := range copiedAttrs {
- t, v := reflect.TypeOf(attr), reflect.ValueOf(attr)
- newAttrObjp := reflect.New(t.Elem())
- newAttrObjp.Elem().Set(v.Elem())
- copiedAttrs[i] = newAttrObjp.Interface().(bgp.PathAttributeInterface)
+func (pd *PathDefault) Clone(isWithdraw bool) Path {
+ copiedAttrs := []bgp.PathAttributeInterface(nil)
+ if !isWithdraw {
+ copiedAttrs = append(copiedAttrs, pd.pathAttrs...)
+ for i, attr := range copiedAttrs {
+ t, v := reflect.TypeOf(attr), reflect.ValueOf(attr)
+ newAttrObjp := reflect.New(t.Elem())
+ newAttrObjp.Elem().Set(v.Elem())
+ copiedAttrs[i] = newAttrObjp.Interface().(bgp.PathAttributeInterface)
+ }
}
- return CreatePath(pd.source, pd.nlri, copiedAttrs, pd.withdraw)
+ return CreatePath(pd.source, pd.nlri, copiedAttrs, isWithdraw)
}
func (pd *PathDefault) getRouteFamily() RouteFamily {
diff --git a/table/table_manager.go b/table/table_manager.go
index 7a913b6d..0967f5d1 100644
--- a/table/table_manager.go
+++ b/table/table_manager.go
@@ -336,21 +336,29 @@ func NewAdjRib() *AdjRib {
return r
}
-func (adj *AdjRib) UpdateIn(pathList []Path) {
+func (adj *AdjRib) update(rib map[RouteFamily]map[string]*ReceivedRoute, pathList []Path) {
for _, path := range pathList {
rf := path.getRouteFamily()
key := path.getPrefix().String()
if path.isWithdraw() {
- _, found := adj.adjRibIn[rf][key]
+ _, found := rib[rf][key]
if found {
- delete(adj.adjRibIn[rf], key)
+ delete(rib[rf], key)
}
} else {
- adj.adjRibIn[rf][key] = NewReceivedRoute(path, false)
+ rib[rf][key] = NewReceivedRoute(path, false)
}
}
}
+func (adj *AdjRib) UpdateIn(pathList []Path) {
+ adj.update(adj.adjRibIn, pathList)
+}
+
+func (adj *AdjRib) UpdateOut(pathList []Path) {
+ adj.update(adj.adjRibOut, pathList)
+}
+
type ReceivedRoute struct {
path Path
filtered bool
diff --git a/table/table_manager_test.go b/table/table_manager_test.go
index 8c9a8ab4..f3a146a9 100644
--- a/table/table_manager_test.go
+++ b/table/table_manager_test.go
@@ -2250,7 +2250,7 @@ func TestModifyPathAttribute(t *testing.T) {
assert.NoError(t, err)
path0 := pList[0]
- path1 := path0.Clone()
+ path1 := path0.Clone(false)
_, attr1 := path1.GetPathAttr(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC)
mx1 := attr1.(*bgp.PathAttributeMultiExitDisc)