summaryrefslogtreecommitdiffhomepage
path: root/table
diff options
context:
space:
mode:
Diffstat (limited to 'table')
-rw-r--r--table/path.go22
-rw-r--r--table/path_test.go21
2 files changed, 21 insertions, 22 deletions
diff --git a/table/path.go b/table/path.go
index 444fe838..a5c08e8f 100644
--- a/table/path.go
+++ b/table/path.go
@@ -27,7 +27,6 @@ type Path interface {
getPathAttributeMap() *utils.OrderedMap
getPathAttribute(int) bgp.PathAttributeInterface
clone(forWithdrawal bool) Path
- setRouteFamily(ROUTE_FAMILY RouteFamily)
getRouteFamily() RouteFamily
setSource(source *PeerInfo)
getSource() *PeerInfo
@@ -44,7 +43,7 @@ type Path interface {
}
type PathDefault struct {
- ROUTE_FAMILY RouteFamily
+ routeFamily RouteFamily
source *PeerInfo
nexthop net.IP
sourceVerNum int
@@ -54,7 +53,7 @@ type PathDefault struct {
medSetByTargetNeighbor bool
}
-func NewPathDefault(source *PeerInfo, nlri bgp.AddrPrefixInterface, sourceVerNum int, nexthop net.IP,
+func NewPathDefault(rf RouteFamily, source *PeerInfo, nlri bgp.AddrPrefixInterface, sourceVerNum int, nexthop net.IP,
isWithdraw bool, pattr *utils.OrderedMap, medSetByTargetNeighbor bool) *PathDefault {
if !isWithdraw && (pattr == nil || nexthop == nil) {
@@ -63,7 +62,7 @@ func NewPathDefault(source *PeerInfo, nlri bgp.AddrPrefixInterface, sourceVerNum
}
path := &PathDefault{}
- path.ROUTE_FAMILY = RF_IPv4_UC
+ path.routeFamily = rf
path.pattrMap = utils.NewOrderedMap()
if pattr != nil {
keyList := pattr.KeyLists()
@@ -86,11 +85,8 @@ func NewPathDefault(source *PeerInfo, nlri bgp.AddrPrefixInterface, sourceVerNum
return path
}
-func (pd *PathDefault) setRouteFamily(ROUTE_FAMILY RouteFamily) {
- pd.ROUTE_FAMILY = ROUTE_FAMILY
-}
func (pd *PathDefault) getRouteFamily() RouteFamily {
- return pd.ROUTE_FAMILY
+ return pd.routeFamily
}
func (pd *PathDefault) setSource(source *PeerInfo) {
@@ -165,9 +161,9 @@ func (pi *PathDefault) clone(forWithdrawal bool) Path {
if !forWithdrawal {
pathAttrs = pi.getPathAttributeMap()
}
- def := NewPathDefault(pi.getSource(), pi.GetNlri(), pi.getSourceVerNum(),
+ def := NewPathDefault(pi.getRouteFamily(), pi.getSource(), pi.GetNlri(), pi.getSourceVerNum(),
pi.getNexthop(), forWithdrawal, pathAttrs, pi.getMedSetByTargetNeighbor())
- switch pi.ROUTE_FAMILY {
+ switch pi.getRouteFamily() {
case RF_IPv4_UC:
return &IPv4Path{PathDefault: def}
case RF_IPv6_UC:
@@ -294,8 +290,7 @@ type IPv4Path struct {
func NewIPv4Path(source *PeerInfo, nlri bgp.AddrPrefixInterface, sourceVerNum int, nexthop net.IP,
isWithdraw bool, pattr *utils.OrderedMap, medSetByTargetNeighbor bool) *IPv4Path {
ipv4Path := &IPv4Path{}
- ipv4Path.PathDefault = NewPathDefault(source, nlri, sourceVerNum, nexthop, isWithdraw, pattr, medSetByTargetNeighbor)
- ipv4Path.PathDefault.ROUTE_FAMILY = RF_IPv4_UC
+ ipv4Path.PathDefault = NewPathDefault(RF_IPv4_UC, source, nlri, sourceVerNum, nexthop, isWithdraw, pattr, medSetByTargetNeighbor)
return ipv4Path
}
@@ -313,8 +308,7 @@ type IPv6Path struct {
func NewIPv6Path(source *PeerInfo, nlri bgp.AddrPrefixInterface, sourceVerNum int, nexthop net.IP,
isWithdraw bool, pattr *utils.OrderedMap, medSetByTargetNeighbor bool) *IPv6Path {
ipv6Path := &IPv6Path{}
- ipv6Path.PathDefault = NewPathDefault(source, nlri, sourceVerNum, nexthop, isWithdraw, pattr, medSetByTargetNeighbor)
- ipv6Path.PathDefault.ROUTE_FAMILY = RF_IPv6_UC
+ ipv6Path.PathDefault = NewPathDefault(RF_IPv6_UC, source, nlri, sourceVerNum, nexthop, isWithdraw, pattr, medSetByTargetNeighbor)
return ipv6Path
}
diff --git a/table/path_test.go b/table/path_test.go
index e5a2397f..cc2ca1a7 100644
--- a/table/path_test.go
+++ b/table/path_test.go
@@ -33,6 +33,7 @@ func TestPathIPv4SetDefault(t *testing.T) {
r_pd := ipv4p.getPathDefault()
assert.Equal(t, r_pd, pd)
}
+
func TestPathIPv4GetDefault(t *testing.T) {
pd := &PathDefault{withdraw: false}
ipv4p := &IPv4Path{}
@@ -40,6 +41,7 @@ func TestPathIPv4GetDefault(t *testing.T) {
r_pd := ipv4p.getPathDefault()
assert.Equal(t, r_pd, pd)
}
+
func TestPathIPv6SetDefault(t *testing.T) {
pd := &PathDefault{sourceVerNum: 4}
ipv6p := &IPv6Path{}
@@ -47,6 +49,7 @@ func TestPathIPv6SetDefault(t *testing.T) {
r_pd := ipv6p.getPathDefault()
assert.Equal(t, r_pd, pd)
}
+
func TestPathIPv6GetDefault(t *testing.T) {
pd := &PathDefault{sourceVerNum: 5}
ipv6p := &IPv6Path{}
@@ -54,18 +57,13 @@ func TestPathIPv6GetDefault(t *testing.T) {
r_pd := ipv6p.getPathDefault()
assert.Equal(t, r_pd, pd)
}
-func TestPathSetRouteFamily(t *testing.T) {
- pd := &PathDefault{}
- pd.setRouteFamily(RF_IPv4_UC)
- rf := pd.getRouteFamily()
- assert.Equal(t, rf, RF_IPv4_UC)
-}
+
func TestPathGetRouteFamily(t *testing.T) {
- pd := &PathDefault{}
- pd.setRouteFamily(RF_IPv6_UC)
+ pd := &PathDefault{routeFamily: RF_IPv6_UC}
rf := pd.getRouteFamily()
assert.Equal(t, rf, RF_IPv6_UC)
}
+
func TestPathSetSource(t *testing.T) {
pd := &PathDefault{}
pr := &PeerInfo{AS: 65000, VersionNum: 4}
@@ -73,6 +71,7 @@ func TestPathSetSource(t *testing.T) {
r_pr := pd.getSource()
assert.Equal(t, r_pr, pr)
}
+
func TestPathGetSource(t *testing.T) {
pd := &PathDefault{}
pr := &PeerInfo{AS: 65001, VersionNum: 4}
@@ -80,6 +79,7 @@ func TestPathGetSource(t *testing.T) {
r_pr := pd.getSource()
assert.Equal(t, r_pr, pr)
}
+
func TestPathSetNexthop(t *testing.T) {
pd := &PathDefault{}
ip := net.ParseIP("192.168.0.1")
@@ -87,6 +87,7 @@ func TestPathSetNexthop(t *testing.T) {
nh := pd.getNexthop()
assert.Equal(t, nh, ip)
}
+
func TestPathgetNexthop(t *testing.T) {
pd := &PathDefault{}
ip := net.ParseIP("192.168.0.2")
@@ -94,6 +95,7 @@ func TestPathgetNexthop(t *testing.T) {
nh := pd.getNexthop()
assert.Equal(t, nh, ip)
}
+
func TestPathSetSourceVerNum(t *testing.T) {
pd := &PathDefault{}
svn := 4
@@ -101,6 +103,7 @@ func TestPathSetSourceVerNum(t *testing.T) {
r_svn := pd.getSourceVerNum()
assert.Equal(t, r_svn, svn)
}
+
func TestPathGetSourceVerNum(t *testing.T) {
pd := &PathDefault{}
svn := 5
@@ -108,6 +111,7 @@ func TestPathGetSourceVerNum(t *testing.T) {
r_svn := pd.getSourceVerNum()
assert.Equal(t, r_svn, svn)
}
+
func TestPathSetWithdraw(t *testing.T) {
pd := &PathDefault{}
wd := true
@@ -115,6 +119,7 @@ func TestPathSetWithdraw(t *testing.T) {
r_wd := pd.isWithdraw()
assert.Equal(t, r_wd, wd)
}
+
func TestPathGetWithdaw(t *testing.T) {
pd := &PathDefault{}
wd := false