summaryrefslogtreecommitdiffhomepage
path: root/table
diff options
context:
space:
mode:
Diffstat (limited to 'table')
-rw-r--r--table/table_manager.go13
-rw-r--r--table/table_manager_test.go48
2 files changed, 34 insertions, 27 deletions
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