summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2015-03-06 17:05:18 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2015-03-06 17:05:18 +0900
commit162a6137ac625552c5e248fa36d56edf89ddd06c (patch)
tree065dbcda7eb30202dbd1c59caeaf00699d951aef
parenta085ce2d338e9a79b98d0f9ea24c5b80bccdf0e1 (diff)
table: NewTableManager takes route families
NewTableManager creates tables for only specified route families. Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-rw-r--r--server/peer.go2
-rw-r--r--server/peer_test.go6
-rw-r--r--table/table_manager.go13
-rw-r--r--table/table_manager_test.go48
4 files changed, 38 insertions, 31 deletions
diff --git a/server/peer.go b/server/peer.go
index 8f456b83..4e079c13 100644
--- a/server/peer.go
+++ b/server/peer.go
@@ -92,7 +92,7 @@ func NewPeer(g config.Global, peer config.Neighbor, serverMsgCh chan *serverMsg,
Address: peer.NeighborAddress,
}
p.adjRib = table.NewAdjRib()
- p.rib = table.NewTableManager(p.peerConfig.NeighborAddress.String())
+ p.rib = table.NewTableManager(p.peerConfig.NeighborAddress.String(), []bgp.RouteFamily{p.rf})
p.t.Go(p.loop)
return p
}
diff --git a/server/peer_test.go b/server/peer_test.go
index 9c5a9452..7c78427c 100644
--- a/server/peer_test.go
+++ b/server/peer_test.go
@@ -62,7 +62,7 @@ func update_fromRC3() *bgp.BGPMessage {
}
func TestProcessBGPUpdate_fourbyteAS(t *testing.T) {
- rib1 := table.NewTableManager("peer_test")
+ rib1 := table.NewTableManager("peer_test", []bgp.RouteFamily{bgp.RF_IPv4_UC, bgp.RF_IPv6_UC})
m := update_fromRC3()
peerInfo := peerRC3()
@@ -86,7 +86,7 @@ func TestProcessBGPUpdate_fourbyteAS(t *testing.T) {
assert.Equal(t, len(attrAS.Value), 1)
assert.Equal(t, attrAS.Value[0].(*bgp.AsPathParam).AS, []uint16{bgp.AS_TRANS, 4000, bgp.AS_TRANS})
- rib2 := table.NewTableManager("peer_test")
+ rib2 := table.NewTableManager("peer_test", []bgp.RouteFamily{bgp.RF_IPv4_UC, bgp.RF_IPv6_UC})
pList2, wList2, _ := rib2.ProcessPaths(pathList)
assert.Equal(t, len(pList2), 1)
assert.Equal(t, len(wList2), 0)
@@ -524,7 +524,7 @@ func makePeer(globalConfig config.Global, peerConfig config.Neighbor) *Peer {
Address: peerConfig.NeighborAddress,
}
p.adjRib = table.NewAdjRib()
- p.rib = table.NewTableManager(p.peerConfig.NeighborAddress.String())
+ p.rib = table.NewTableManager(p.peerConfig.NeighborAddress.String(), []bgp.RouteFamily{bgp.RF_IPv4_UC, bgp.RF_IPv6_UC})
return p
}
diff --git a/table/table_manager.go b/table/table_manager.go
index be068e40..e7815af6 100644
--- a/table/table_manager.go
+++ b/table/table_manager.go
@@ -128,11 +128,18 @@ type TableManager struct {
owner string
}
-func NewTableManager(owner string) *TableManager {
+func NewTableManager(owner string, rfList []bgp.RouteFamily) *TableManager {
t := &TableManager{}
t.Tables = make(map[bgp.RouteFamily]Table)
- t.Tables[bgp.RF_IPv4_UC] = NewIPv4Table(0)
- t.Tables[bgp.RF_IPv6_UC] = NewIPv6Table(0)
+ for _, rf := range rfList {
+ // FIXME: NewIPTable() should handle all cases.
+ switch rf {
+ case bgp.RF_IPv4_UC:
+ t.Tables[bgp.RF_IPv4_UC] = NewIPv4Table(0)
+ case bgp.RF_IPv6_UC:
+ t.Tables[bgp.RF_IPv6_UC] = NewIPv6Table(0)
+ }
+ }
t.owner = owner
return t
}
diff --git a/table/table_manager_test.go b/table/table_manager_test.go
index 24c506d4..601a292a 100644
--- a/table/table_manager_test.go
+++ b/table/table_manager_test.go
@@ -67,7 +67,7 @@ func peerR3() *PeerInfo {
// test best path calculation and check the result path is from R1
func TestProcessBGPUpdate_0_select_onlypath_ipv4(t *testing.T) {
- tm := NewTableManager("TestProcessBGPUpdate_0_select_onlypath_ipv4")
+ tm := NewTableManager("TestProcessBGPUpdate_0_select_onlypath_ipv4", []bgp.RouteFamily{bgp.RF_IPv4_UC})
bgpMessage := update_fromR1()
peer := peerR1()
@@ -118,7 +118,7 @@ func TestProcessBGPUpdate_0_select_onlypath_ipv4(t *testing.T) {
// test best path calculation and check the result path is from R1
func TestProcessBGPUpdate_0_select_onlypath_ipv6(t *testing.T) {
- tm := NewTableManager("TestProcessBGPUpdate_0_select_onlypath_ipv6")
+ tm := NewTableManager("TestProcessBGPUpdate_0_select_onlypath_ipv6", []bgp.RouteFamily{bgp.RF_IPv6_UC})
bgpMessage := update_fromR1_ipv6()
peer := peerR1()
@@ -170,7 +170,7 @@ func TestProcessBGPUpdate_0_select_onlypath_ipv6(t *testing.T) {
// test: compare localpref
func TestProcessBGPUpdate_1_select_high_localpref_ipv4(t *testing.T) {
- tm := NewTableManager("TestProcessBGPUpdate_1_select_high_localpref_ipv4")
+ tm := NewTableManager("TestProcessBGPUpdate_1_select_high_localpref_ipv4", []bgp.RouteFamily{bgp.RF_IPv4_UC})
var err error
// low localpref message
@@ -254,7 +254,7 @@ func TestProcessBGPUpdate_1_select_high_localpref_ipv4(t *testing.T) {
func TestProcessBGPUpdate_1_select_high_localpref_ipv6(t *testing.T) {
- tm := NewTableManager("TestProcessBGPUpdate_1_select_high_localpref_ipv6")
+ tm := NewTableManager("TestProcessBGPUpdate_1_select_high_localpref_ipv6", []bgp.RouteFamily{bgp.RF_IPv6_UC})
var err error
origin1 := bgp.NewPathAttributeOrigin(0)
@@ -342,7 +342,7 @@ func TestProcessBGPUpdate_1_select_high_localpref_ipv6(t *testing.T) {
// test: compare localOrigin
func TestProcessBGPUpdate_2_select_local_origin_ipv4(t *testing.T) {
- tm := NewTableManager("TestProcessBGPUpdate_2_select_local_origin_ipv4")
+ tm := NewTableManager("TestProcessBGPUpdate_2_select_local_origin_ipv4", []bgp.RouteFamily{bgp.RF_IPv4_UC})
var err error
// low localpref message
@@ -428,7 +428,7 @@ func TestProcessBGPUpdate_2_select_local_origin_ipv4(t *testing.T) {
func TestProcessBGPUpdate_2_select_local_origin_ipv6(t *testing.T) {
- tm := NewTableManager("TestProcessBGPUpdate_2_select_local_origin_ipv6")
+ tm := NewTableManager("TestProcessBGPUpdate_2_select_local_origin_ipv6", []bgp.RouteFamily{bgp.RF_IPv6_UC})
var err error
origin1 := bgp.NewPathAttributeOrigin(0)
@@ -519,7 +519,7 @@ func TestProcessBGPUpdate_2_select_local_origin_ipv6(t *testing.T) {
// test: compare AS_PATH
func TestProcessBGPUpdate_3_select_aspath_ipv4(t *testing.T) {
- tm := NewTableManager("TestProcessBGPUpdate_3_select_aspath_ipv4")
+ tm := NewTableManager("TestProcessBGPUpdate_3_select_aspath_ipv4", []bgp.RouteFamily{bgp.RF_IPv4_UC})
var err error
bgpMessage1 := update_fromR2viaR1()
@@ -576,7 +576,7 @@ func TestProcessBGPUpdate_3_select_aspath_ipv4(t *testing.T) {
func TestProcessBGPUpdate_3_select_aspath_ipv6(t *testing.T) {
- tm := NewTableManager("TestProcessBGPUpdate_3_select_aspath_ipv6")
+ tm := NewTableManager("TestProcessBGPUpdate_3_select_aspath_ipv6", []bgp.RouteFamily{bgp.RF_IPv6_UC})
var err error
bgpMessage1 := update_fromR2viaR1_ipv6()
@@ -635,7 +635,7 @@ func TestProcessBGPUpdate_3_select_aspath_ipv6(t *testing.T) {
// test: compare Origin
func TestProcessBGPUpdate_4_select_low_origin_ipv4(t *testing.T) {
- tm := NewTableManager("TestProcessBGPUpdate_4_select_low_origin_ipv4")
+ tm := NewTableManager("TestProcessBGPUpdate_4_select_low_origin_ipv4", []bgp.RouteFamily{bgp.RF_IPv4_UC})
var err error
// low origin message
@@ -719,7 +719,7 @@ func TestProcessBGPUpdate_4_select_low_origin_ipv4(t *testing.T) {
func TestProcessBGPUpdate_4_select_low_origin_ipv6(t *testing.T) {
- tm := NewTableManager("TestProcessBGPUpdate_4_select_low_origin_ipv6")
+ tm := NewTableManager("TestProcessBGPUpdate_4_select_low_origin_ipv6", []bgp.RouteFamily{bgp.RF_IPv6_UC})
var err error
origin1 := bgp.NewPathAttributeOrigin(1)
@@ -807,7 +807,7 @@ func TestProcessBGPUpdate_4_select_low_origin_ipv6(t *testing.T) {
// test: compare MED
func TestProcessBGPUpdate_5_select_low_med_ipv4(t *testing.T) {
- tm := NewTableManager("TestProcessBGPUpdate_5_select_low_med_ipv4")
+ tm := NewTableManager("TestProcessBGPUpdate_5_select_low_med_ipv4", []bgp.RouteFamily{bgp.RF_IPv4_UC})
var err error
// low origin message
@@ -891,7 +891,7 @@ func TestProcessBGPUpdate_5_select_low_med_ipv4(t *testing.T) {
func TestProcessBGPUpdate_5_select_low_med_ipv6(t *testing.T) {
- tm := NewTableManager("TestProcessBGPUpdate_5_select_low_med_ipv6")
+ tm := NewTableManager("TestProcessBGPUpdate_5_select_low_med_ipv6", []bgp.RouteFamily{bgp.RF_IPv6_UC})
var err error
origin1 := bgp.NewPathAttributeOrigin(0)
@@ -979,7 +979,7 @@ func TestProcessBGPUpdate_5_select_low_med_ipv6(t *testing.T) {
// test: compare AS_NUMBER(prefer eBGP path)
func TestProcessBGPUpdate_6_select_ebgp_path_ipv4(t *testing.T) {
- tm := NewTableManager("TestProcessBGPUpdate_6_select_ebgp_path_ipv4")
+ tm := NewTableManager("TestProcessBGPUpdate_6_select_ebgp_path_ipv4", []bgp.RouteFamily{bgp.RF_IPv4_UC})
tm.localAsn = uint32(65000)
var err error
@@ -1065,7 +1065,7 @@ func TestProcessBGPUpdate_6_select_ebgp_path_ipv4(t *testing.T) {
func TestProcessBGPUpdate_6_select_ebgp_path_ipv6(t *testing.T) {
- tm := NewTableManager("TestProcessBGPUpdate_6_select_ebgp_path_ipv6")
+ tm := NewTableManager("TestProcessBGPUpdate_6_select_ebgp_path_ipv6", []bgp.RouteFamily{bgp.RF_IPv6_UC})
tm.localAsn = uint32(65000)
var err error
@@ -1156,7 +1156,7 @@ func TestProcessBGPUpdate_6_select_ebgp_path_ipv6(t *testing.T) {
// test: compare Router ID
func TestProcessBGPUpdate_7_select_low_routerid_path_ipv4(t *testing.T) {
- tm := NewTableManager("TestProcessBGPUpdate_7_select_low_routerid_path_ipv4")
+ tm := NewTableManager("TestProcessBGPUpdate_7_select_low_routerid_path_ipv4", []bgp.RouteFamily{bgp.RF_IPv4_UC})
tm.localAsn = uint32(65000)
var err error
@@ -1242,7 +1242,7 @@ func TestProcessBGPUpdate_7_select_low_routerid_path_ipv4(t *testing.T) {
func TestProcessBGPUpdate_7_select_low_routerid_path_ipv6(t *testing.T) {
- tm := NewTableManager("TestProcessBGPUpdate_7_select_low_routerid_path_ipv6")
+ tm := NewTableManager("TestProcessBGPUpdate_7_select_low_routerid_path_ipv6", []bgp.RouteFamily{bgp.RF_IPv6_UC})
tm.localAsn = uint32(65000)
var err error
@@ -1331,7 +1331,7 @@ func TestProcessBGPUpdate_7_select_low_routerid_path_ipv6(t *testing.T) {
// test: withdraw and mpunreach path
func TestProcessBGPUpdate_8_withdraw_path_ipv4(t *testing.T) {
- tm := NewTableManager("TestProcessBGPUpdate_8_withdraw_path_ipv4")
+ tm := NewTableManager("TestProcessBGPUpdate_8_withdraw_path_ipv4", []bgp.RouteFamily{bgp.RF_IPv4_UC})
//setLogger(getLogger(log.DebugLevel))
var err error
@@ -1440,7 +1440,7 @@ func TestProcessBGPUpdate_8_withdraw_path_ipv4(t *testing.T) {
// TODO MP_UNREACH
func TestProcessBGPUpdate_8_mpunreach_path_ipv6(t *testing.T) {
- tm := NewTableManager("TestProcessBGPUpdate_8_mpunreach_path_ipv6")
+ tm := NewTableManager("TestProcessBGPUpdate_8_mpunreach_path_ipv6", []bgp.RouteFamily{bgp.RF_IPv6_UC})
var err error
origin1 := bgp.NewPathAttributeOrigin(0)
@@ -1576,7 +1576,7 @@ func TestProcessBGPUpdate_8_mpunreach_path_ipv6(t *testing.T) {
// handle bestpath lost
func TestProcessBGPUpdate_bestpath_lost_ipv4(t *testing.T) {
- tm := NewTableManager("TestProcessBGPUpdate_bestpath_lost_ipv4")
+ tm := NewTableManager("TestProcessBGPUpdate_bestpath_lost_ipv4", []bgp.RouteFamily{bgp.RF_IPv4_UC})
//setLogger(getLogger(log.DebugLevel))
var err error
@@ -1649,7 +1649,7 @@ func TestProcessBGPUpdate_bestpath_lost_ipv4(t *testing.T) {
func TestProcessBGPUpdate_bestpath_lost_ipv6(t *testing.T) {
- tm := NewTableManager("TestProcessBGPUpdate_bestpath_lost_ipv6")
+ tm := NewTableManager("TestProcessBGPUpdate_bestpath_lost_ipv6", []bgp.RouteFamily{bgp.RF_IPv6_UC})
var err error
origin1 := bgp.NewPathAttributeOrigin(0)
@@ -1725,7 +1725,7 @@ func TestProcessBGPUpdate_bestpath_lost_ipv6(t *testing.T) {
// test: implicit withdrawal case
func TestProcessBGPUpdate_implicit_withdrwal_ipv4(t *testing.T) {
- tm := NewTableManager("TestProcessBGPUpdate_implicit_withdrwal_ipv4")
+ tm := NewTableManager("TestProcessBGPUpdate_implicit_withdrwal_ipv4", []bgp.RouteFamily{bgp.RF_IPv4_UC})
//setLogger(getLogger(log.DebugLevel))
var err error
@@ -1811,7 +1811,7 @@ func TestProcessBGPUpdate_implicit_withdrwal_ipv4(t *testing.T) {
func TestProcessBGPUpdate_implicit_withdrwal_ipv6(t *testing.T) {
- tm := NewTableManager("TestProcessBGPUpdate_implicit_withdrwal_ipv6")
+ tm := NewTableManager("TestProcessBGPUpdate_implicit_withdrwal_ipv6", []bgp.RouteFamily{bgp.RF_IPv6_UC})
var err error
origin1 := bgp.NewPathAttributeOrigin(0)
@@ -1924,7 +1924,7 @@ func TestProcessBGPUpdate_implicit_withdrwal_ipv6(t *testing.T) {
// check multiple paths
func TestProcessBGPUpdate_multiple_nlri_ipv4(t *testing.T) {
- tm := NewTableManager("TestProcessBGPUpdate_multiple_nlri_ipv4")
+ tm := NewTableManager("TestProcessBGPUpdate_multiple_nlri_ipv4", []bgp.RouteFamily{bgp.RF_IPv4_UC})
//setLogger(getLogger(log.DebugLevel))
var err error
@@ -2054,7 +2054,7 @@ func TestProcessBGPUpdate_multiple_nlri_ipv4(t *testing.T) {
// check multiple paths
func TestProcessBGPUpdate_multiple_nlri_ipv6(t *testing.T) {
- tm := NewTableManager("TestProcessBGPUpdate_multiple_nlri_ipv6")
+ tm := NewTableManager("TestProcessBGPUpdate_multiple_nlri_ipv6", []bgp.RouteFamily{bgp.RF_IPv6_UC})
//setLogger(getLogger(log.DebugLevel))
var err error