diff options
author | Hiroshi Yokoi <yokoi.hiroshi@po.ntts.co.jp> | 2015-01-27 20:46:01 +0900 |
---|---|---|
committer | Hiroshi Yokoi <yokoi.hiroshi@po.ntts.co.jp> | 2015-01-28 14:53:24 +0900 |
commit | 959994eb57ae2e9a2d852bc4b71ba35fda911680 (patch) | |
tree | e951870d8155265ee9d0fceacc84ce3b5f384831 | |
parent | 838cf25f000481f4adf9e508e1e533ec7e8977d4 (diff) |
table: add owner to NewTableManager's arguments
-rw-r--r-- | server/peer.go | 2 | ||||
-rw-r--r-- | server/peer_test.go | 4 | ||||
-rw-r--r-- | table/destination.go | 1 | ||||
-rw-r--r-- | table/table_manager.go | 45 | ||||
-rw-r--r-- | table/table_manager_test.go | 62 |
5 files changed, 65 insertions, 49 deletions
diff --git a/server/peer.go b/server/peer.go index ff75d354..28561619 100644 --- a/server/peer.go +++ b/server/peer.go @@ -93,7 +93,7 @@ func NewPeer(g config.GlobalType, peer config.NeighborType, serverMsgCh chan *se Address: peer.NeighborAddress, } p.adjRib = table.NewAdjRib() - p.rib = table.NewTableManager() + p.rib = table.NewTableManager(p.peerConfig.NeighborAddress.String()) p.t.Go(p.loop) return p } diff --git a/server/peer_test.go b/server/peer_test.go index eaea842a..4f310512 100644 --- a/server/peer_test.go +++ b/server/peer_test.go @@ -57,7 +57,7 @@ func update_fromRC3() *bgp.BGPMessage { } func TestProcessBGPUpdate_fourbyteAS(t *testing.T) { - rib1 := table.NewTableManager() + rib1 := table.NewTableManager("peer_test") m := update_fromRC3() peerInfo := peerRC3() @@ -81,7 +81,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() + rib2 := table.NewTableManager("peer_test") pList2, wList2, _ := rib2.ProcessPaths(pathList) assert.Equal(t, len(pList2), 1) assert.Equal(t, len(wList2), 0) diff --git a/table/destination.go b/table/destination.go index 1eda5f7c..769e6545 100644 --- a/table/destination.go +++ b/table/destination.go @@ -63,7 +63,6 @@ type Destination interface { getKnownPathList() []Path setKnownPathList([]Path) String() string - getPrefix() net.IP addWithdraw(withdraw Path) addNewPath(newPath Path) constructWithdrawPath() Path diff --git a/table/table_manager.go b/table/table_manager.go index d6dde9d0..10d76565 100644 --- a/table/table_manager.go +++ b/table/table_manager.go @@ -124,13 +124,15 @@ func (p *ProcessMessage) ToPathList() []Path { type TableManager struct { Tables map[bgp.RouteFamily]Table localAsn uint32 + owner string } -func NewTableManager() *TableManager { +func NewTableManager(owner string) *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) + t.owner = owner return t } @@ -143,18 +145,12 @@ func (manager *TableManager) calculate(destinationList []Destination) ([]Path, [ log.WithFields(log.Fields{ "Topic": "table", - "Key": destination.getPrefix().String(), + "Owner": manager.owner, + "Key": destination.getNlri().String(), }).Info("Processing destination") newBestPath, reason, err := destination.Calculate(manager.localAsn) - log.WithFields(log.Fields{ - "Topic": "table", - "Key": destination.getPrefix().String(), - "new": newBestPath, - "reason": reason, - }).Debug("new best path") - if err != nil { log.Error(err) continue @@ -166,8 +162,12 @@ func (manager *TableManager) calculate(destinationList []Destination) ([]Path, [ if newBestPath != nil && currentBestPath == newBestPath { // best path is not changed log.WithFields(log.Fields{ - "Topic": "table", - "Key": destination.getPrefix().String(), + "Topic": "table", + "Owner": manager.owner, + "Key": destination.getNlri().String(), + "peer": newBestPath.getSource().Address, + "next_hop": newBestPath.getNexthop().String(), + "reason": reason, }).Debug("best path is not changed") continue } @@ -175,15 +175,19 @@ func (manager *TableManager) calculate(destinationList []Destination) ([]Path, [ if newBestPath == nil { log.WithFields(log.Fields{ "Topic": "table", - "Key": destination.getPrefix().String(), + "Owner": manager.owner, + "Key": destination.getNlri().String(), }).Debug("best path is nil") if len(destination.getKnownPathList()) == 0 { // create withdraw path if currentBestPath != nil { log.WithFields(log.Fields{ - "Topic": "table", - "Key": destination.getPrefix().String(), + "Topic": "table", + "Owner": manager.owner, + "Key": destination.getNlri().String(), + "peer": currentBestPath.getSource().Address, + "next_hop": currentBestPath.getNexthop().String(), }).Debug("best path is lost") p := destination.getBestPath() @@ -195,13 +199,16 @@ func (manager *TableManager) calculate(destinationList []Destination) ([]Path, [ log.WithFields(log.Fields{ "Topic": "table", - "Key": destination.getPrefix().String(), + "Owner": manager.owner, + "Key": destination.getNlri().String(), }).Error("known path list is not empty") } } else { log.WithFields(log.Fields{ "Topic": "table", - "Key": newBestPath.getPrefix(), + "Owner": manager.owner, + "Key": newBestPath.getNlri().String(), + "peer": newBestPath.getSource().Address, "next_hop": newBestPath.getNexthop(), "reason": reason, }).Debug("new best path") @@ -216,7 +223,8 @@ func (manager *TableManager) calculate(destinationList []Destination) ([]Path, [ deleteDest(t, destination) log.WithFields(log.Fields{ "Topic": "table", - "Key": destination.getPrefix().String(), + "Owner": manager.owner, + "Key": destination.getNlri().String(), "route_family": rf, }).Debug("destination removed") } @@ -248,8 +256,9 @@ func (manager *TableManager) ProcessUpdate(fromPeer *PeerInfo, message *bgp.BGPM if message.Header.Type != bgp.BGP_MSG_UPDATE { log.WithFields(log.Fields{ "Topic": "table", + "Owner": manager.owner, "key": fromPeer.Address.String(), - "type": message.Header.Type, + "Type": message.Header.Type, }).Warn("message is not BGPUpdate") return []Path{}, []Path{}, nil } diff --git a/table/table_manager_test.go b/table/table_manager_test.go index 0cb81b6e..24c506d4 100644 --- a/table/table_manager_test.go +++ b/table/table_manager_test.go @@ -41,13 +41,15 @@ func peerR1() *PeerInfo { AS: 65000, ID: net.ParseIP("10.0.0.3").To4(), LocalID: net.ParseIP("10.0.0.1").To4(), + Address: net.ParseIP("10.0.0.1").To4(), } return peer } func peerR2() *PeerInfo { peer := &PeerInfo{ - AS: 65100, + AS: 65100, + Address: net.ParseIP("10.0.0.2").To4(), } return peer } @@ -57,6 +59,7 @@ func peerR3() *PeerInfo { AS: 65000, ID: net.ParseIP("10.0.0.2").To4(), LocalID: net.ParseIP("10.0.0.1").To4(), + Address: net.ParseIP("10.0.0.3").To4(), } return peer } @@ -64,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() + tm := NewTableManager("TestProcessBGPUpdate_0_select_onlypath_ipv4") bgpMessage := update_fromR1() peer := peerR1() @@ -115,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() + tm := NewTableManager("TestProcessBGPUpdate_0_select_onlypath_ipv6") bgpMessage := update_fromR1_ipv6() peer := peerR1() @@ -167,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() + tm := NewTableManager("TestProcessBGPUpdate_1_select_high_localpref_ipv4") var err error // low localpref message @@ -251,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() + tm := NewTableManager("TestProcessBGPUpdate_1_select_high_localpref_ipv6") var err error origin1 := bgp.NewPathAttributeOrigin(0) @@ -339,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() + tm := NewTableManager("TestProcessBGPUpdate_2_select_local_origin_ipv4") var err error // low localpref message @@ -376,7 +379,9 @@ func TestProcessBGPUpdate_2_select_local_origin_ipv4(t *testing.T) { assert.Equal(t, 0, len(wList)) assert.NoError(t, err) - var peer2 *PeerInfo = nil + var peer2 *PeerInfo = &PeerInfo{ + Address: net.ParseIP("0.0.0.0"), + } pList, wList, err = tm.ProcessUpdate(peer2, bgpMessage2) assert.Equal(t, 1, len(pList)) assert.Equal(t, 0, len(wList)) @@ -423,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() + tm := NewTableManager("TestProcessBGPUpdate_2_select_local_origin_ipv6") var err error origin1 := bgp.NewPathAttributeOrigin(0) @@ -462,7 +467,10 @@ func TestProcessBGPUpdate_2_select_local_origin_ipv6(t *testing.T) { assert.Equal(t, 0, len(wList)) assert.NoError(t, err) - var peer2 *PeerInfo = nil + var peer2 *PeerInfo = &PeerInfo{ + Address: net.ParseIP("0.0.0.0"), + } + pList, wList, err = tm.ProcessUpdate(peer2, bgpMessage2) assert.Equal(t, 1, len(pList)) assert.Equal(t, 0, len(wList)) @@ -511,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() + tm := NewTableManager("TestProcessBGPUpdate_3_select_aspath_ipv4") var err error bgpMessage1 := update_fromR2viaR1() @@ -568,7 +576,7 @@ func TestProcessBGPUpdate_3_select_aspath_ipv4(t *testing.T) { func TestProcessBGPUpdate_3_select_aspath_ipv6(t *testing.T) { - tm := NewTableManager() + tm := NewTableManager("TestProcessBGPUpdate_3_select_aspath_ipv6") var err error bgpMessage1 := update_fromR2viaR1_ipv6() @@ -627,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() + tm := NewTableManager("TestProcessBGPUpdate_4_select_low_origin_ipv4") var err error // low origin message @@ -711,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() + tm := NewTableManager("TestProcessBGPUpdate_4_select_low_origin_ipv6") var err error origin1 := bgp.NewPathAttributeOrigin(1) @@ -799,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() + tm := NewTableManager("TestProcessBGPUpdate_5_select_low_med_ipv4") var err error // low origin message @@ -883,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() + tm := NewTableManager("TestProcessBGPUpdate_5_select_low_med_ipv6") var err error origin1 := bgp.NewPathAttributeOrigin(0) @@ -971,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() + tm := NewTableManager("TestProcessBGPUpdate_6_select_ebgp_path_ipv4") tm.localAsn = uint32(65000) var err error @@ -1057,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() + tm := NewTableManager("TestProcessBGPUpdate_6_select_ebgp_path_ipv6") tm.localAsn = uint32(65000) var err error @@ -1148,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() + tm := NewTableManager("TestProcessBGPUpdate_7_select_low_routerid_path_ipv4") tm.localAsn = uint32(65000) var err error @@ -1234,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() + tm := NewTableManager("TestProcessBGPUpdate_7_select_low_routerid_path_ipv6") tm.localAsn = uint32(65000) var err error @@ -1323,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() + tm := NewTableManager("TestProcessBGPUpdate_8_withdraw_path_ipv4") //setLogger(getLogger(log.DebugLevel)) var err error @@ -1432,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() + tm := NewTableManager("TestProcessBGPUpdate_8_mpunreach_path_ipv6") var err error origin1 := bgp.NewPathAttributeOrigin(0) @@ -1568,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() + tm := NewTableManager("TestProcessBGPUpdate_bestpath_lost_ipv4") //setLogger(getLogger(log.DebugLevel)) var err error @@ -1641,7 +1649,7 @@ func TestProcessBGPUpdate_bestpath_lost_ipv4(t *testing.T) { func TestProcessBGPUpdate_bestpath_lost_ipv6(t *testing.T) { - tm := NewTableManager() + tm := NewTableManager("TestProcessBGPUpdate_bestpath_lost_ipv6") var err error origin1 := bgp.NewPathAttributeOrigin(0) @@ -1717,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() + tm := NewTableManager("TestProcessBGPUpdate_implicit_withdrwal_ipv4") //setLogger(getLogger(log.DebugLevel)) var err error @@ -1803,7 +1811,7 @@ func TestProcessBGPUpdate_implicit_withdrwal_ipv4(t *testing.T) { func TestProcessBGPUpdate_implicit_withdrwal_ipv6(t *testing.T) { - tm := NewTableManager() + tm := NewTableManager("TestProcessBGPUpdate_implicit_withdrwal_ipv6") var err error origin1 := bgp.NewPathAttributeOrigin(0) @@ -1916,7 +1924,7 @@ func TestProcessBGPUpdate_implicit_withdrwal_ipv6(t *testing.T) { // check multiple paths func TestProcessBGPUpdate_multiple_nlri_ipv4(t *testing.T) { - tm := NewTableManager() + tm := NewTableManager("TestProcessBGPUpdate_multiple_nlri_ipv4") //setLogger(getLogger(log.DebugLevel)) var err error @@ -2046,7 +2054,7 @@ func TestProcessBGPUpdate_multiple_nlri_ipv4(t *testing.T) { // check multiple paths func TestProcessBGPUpdate_multiple_nlri_ipv6(t *testing.T) { - tm := NewTableManager() + tm := NewTableManager("TestProcessBGPUpdate_multiple_nlri_ipv6") //setLogger(getLogger(log.DebugLevel)) var err error |