diff options
author | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2014-12-27 06:26:18 -0800 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2014-12-27 06:27:00 -0800 |
commit | eff70c21375742b44ae5ebfd845dba38d0f3fcfc (patch) | |
tree | b9d6cceaa69fc74250265f2df2262e65fe23ebda /table | |
parent | f5447b5599060a60acbf61ab7310807d85799628 (diff) |
support IPv6_UC route family
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Diffstat (limited to 'table')
-rw-r--r-- | table/destination.go | 3 | ||||
-rw-r--r-- | table/path.go | 40 | ||||
-rw-r--r-- | table/path_test.go | 2 | ||||
-rw-r--r-- | table/table.go | 4 | ||||
-rw-r--r-- | table/table_manager.go | 6 | ||||
-rw-r--r-- | table/table_test.go | 2 |
6 files changed, 44 insertions, 13 deletions
diff --git a/table/destination.go b/table/destination.go index f99af8ef..4bb77ae7 100644 --- a/table/destination.go +++ b/table/destination.go @@ -45,6 +45,7 @@ type PeerInfo struct { ID net.IP VersionNum int LocalID net.IP + RF RouteFamily } type Destination interface { @@ -185,7 +186,7 @@ func (dd *DestinationDefault) removeOldPathsFromSource(source *PeerInfo) []Path } func (dd *DestinationDefault) validatePath(path Path) { - if path == nil || path.getRouteFamily() != dd.ROUTE_FAMILY { + if path == nil || path.GetRouteFamily() != dd.ROUTE_FAMILY { log.Error("Invalid path. Expected %s path got %s.", dd.ROUTE_FAMILY, path) } } diff --git a/table/path.go b/table/path.go index 66b2dc4a..1ccbb1a2 100644 --- a/table/path.go +++ b/table/path.go @@ -28,7 +28,7 @@ type Path interface { String() string GetPathAttrs() []bgp.PathAttributeInterface GetPathAttr(bgp.BGPAttrType) (int, bgp.PathAttributeInterface) - getRouteFamily() RouteFamily + GetRouteFamily() RouteFamily setSource(source *PeerInfo) getSource() *PeerInfo setNexthop(nexthop net.IP) @@ -100,7 +100,7 @@ func (pd *PathDefault) MarshalJSON() ([]byte, error) { return json.Marshal(struct { Network string //Nexthop string - Attrs []bgp.PathAttributeInterface + Attrs []bgp.PathAttributeInterface //Metric string //origin string Best string @@ -108,8 +108,8 @@ func (pd *PathDefault) MarshalJSON() ([]byte, error) { Network: prefix.String() + "/" + fmt.Sprint(prefixLen), //Nexthop: pd.nexthop.String(), //Metric: fmt.Sprint(med), - Attrs: pd.GetPathAttrs(), - Best: fmt.Sprint(pd.isBest), + Attrs: pd.GetPathAttrs(), + Best: fmt.Sprint(pd.isBest), }) } @@ -133,7 +133,7 @@ func (pd *PathDefault) Clone(isWithdraw bool) Path { return CreatePath(pd.source, nlri, copiedAttrs, isWithdraw) } -func (pd *PathDefault) getRouteFamily() RouteFamily { +func (pd *PathDefault) GetRouteFamily() RouteFamily { return pd.routeFamily } @@ -293,6 +293,36 @@ func NewIPv6Path(source *PeerInfo, nlri bgp.AddrPrefixInterface, sourceVerNum in return ipv6Path } +func (ipv6p *IPv6Path) Clone(isWithdraw bool) Path { + copiedAttrs := []bgp.PathAttributeInterface(nil) + nlri := ipv6p.nlri + if isWithdraw { + if !ipv6p.IsWithdraw() { + copiedAttrs = append(copiedAttrs, ipv6p.GetPathAttrs()...) + 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) + } + idx, attr := ipv6p.GetPathAttr(bgp.BGP_ATTR_TYPE_MP_REACH_NLRI) + reach := attr.(*bgp.PathAttributeMpReachNLRI) + copiedAttrs[idx] = bgp.NewPathAttributeMpUnreachNLRI(reach.Value) + } else { + copiedAttrs = ipv6p.GetPathAttrs() + } + } else { + copiedAttrs = append(copiedAttrs, ipv6p.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(ipv6p.source, nlri, copiedAttrs, isWithdraw) +} + func (ipv6p *IPv6Path) setPathDefault(pd *PathDefault) { ipv6p.PathDefault = pd } diff --git a/table/path_test.go b/table/path_test.go index b779c84b..786dad26 100644 --- a/table/path_test.go +++ b/table/path_test.go @@ -58,7 +58,7 @@ func TestPathIPv6GetDefault(t *testing.T) { func TestPathGetRouteFamily(t *testing.T) { pd := &PathDefault{routeFamily: RF_IPv6_UC} - rf := pd.getRouteFamily() + rf := pd.GetRouteFamily() assert.Equal(t, rf, RF_IPv6_UC) } diff --git a/table/table.go b/table/table.go index a9d742aa..7021f025 100644 --- a/table/table.go +++ b/table/table.go @@ -63,7 +63,7 @@ func (td *TableDefault) MarshalJSON() ([]byte, error) { }) } -func (td *TableDefault) getRoutefamily() RouteFamily { +func (td *TableDefault) GetRoutefamily() RouteFamily { return td.ROUTE_FAMILY } @@ -142,7 +142,7 @@ func deleteDest(table Table, dest Destination) { } func (td *TableDefault) validatePath(path Path) { - if path == nil || path.getRouteFamily() != td.ROUTE_FAMILY { + if path == nil || path.GetRouteFamily() != td.ROUTE_FAMILY { log.Errorf("Invalid path. Expected instance of %s route family path, got %s.", td.ROUTE_FAMILY, path) } } diff --git a/table/table_manager.go b/table/table_manager.go index 18dbfb2d..4a0c70d6 100644 --- a/table/table_manager.go +++ b/table/table_manager.go @@ -223,14 +223,14 @@ func (manager *TableManager) calculate(destinationList []Destination) ([]Path, [ } func (manager *TableManager) DeletePathsforPeer(peerInfo *PeerInfo) ([]Path, []Destination, error) { - destinationList := manager.Tables[RF_IPv4_UC].DeleteDestByPeer(peerInfo) + destinationList := manager.Tables[peerInfo.RF].DeleteDestByPeer(peerInfo) return manager.calculate(destinationList) } func (manager *TableManager) ProcessPaths(pathList []Path) ([]Path, []Destination, error) { destinationList := make([]Destination, 0) for _, path := range pathList { - rf := path.getRouteFamily() + rf := path.GetRouteFamily() // push Path into table destination := insert(manager.Tables[rf], path) destinationList = append(destinationList, destination) @@ -277,7 +277,7 @@ func NewAdjRib() *AdjRib { func (adj *AdjRib) update(rib map[RouteFamily]map[string]*ReceivedRoute, pathList []Path) { for _, path := range pathList { - rf := path.getRouteFamily() + rf := path.GetRouteFamily() key := path.getPrefix().String() if path.IsWithdraw() { _, found := rib[rf][key] diff --git a/table/table_test.go b/table/table_test.go index 47213a82..8a347d30 100644 --- a/table/table_test.go +++ b/table/table_test.go @@ -71,7 +71,7 @@ func TestTableDeleteDest(t *testing.T) { func TestTableGetRouteFamily(t *testing.T) { ipv4t := NewIPv4Table(0) - rf := ipv4t.getRoutefamily() + rf := ipv4t.GetRoutefamily() assert.Equal(t, rf, RF_IPv4_UC) } |