summaryrefslogtreecommitdiffhomepage
path: root/table/path.go
diff options
context:
space:
mode:
authorFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2014-12-27 06:26:18 -0800
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2014-12-27 06:27:00 -0800
commiteff70c21375742b44ae5ebfd845dba38d0f3fcfc (patch)
treeb9d6cceaa69fc74250265f2df2262e65fe23ebda /table/path.go
parentf5447b5599060a60acbf61ab7310807d85799628 (diff)
support IPv6_UC route family
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Diffstat (limited to 'table/path.go')
-rw-r--r--table/path.go40
1 files changed, 35 insertions, 5 deletions
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
}