diff options
author | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2014-12-16 19:37:22 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2014-12-16 19:40:53 +0900 |
commit | 95e585d7f09413fe5fc89397f8b4d50ac41556b8 (patch) | |
tree | d8df20d14dce6dffff90a24c8f23c7a505e181e4 | |
parent | 504bd6f749224c493f3aa49197674ec08e7c0efe (diff) |
table: remove temporary structures
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-rw-r--r-- | table/destination.go | 25 | ||||
-rw-r--r-- | table/destination_test.go | 12 | ||||
-rw-r--r-- | table/path.go | 18 | ||||
-rw-r--r-- | table/path_test.go | 16 | ||||
-rw-r--r-- | table/table_manager.go | 4 | ||||
-rw-r--r-- | table/table_manager_test.go | 37 | ||||
-rw-r--r-- | table/table_test.go | 12 | ||||
-rw-r--r-- | table/temporary_structs.go | 21 |
8 files changed, 63 insertions, 82 deletions
diff --git a/table/destination.go b/table/destination.go index 5e209712..c71e4464 100644 --- a/table/destination.go +++ b/table/destination.go @@ -38,6 +38,13 @@ const ( BPR_ROUTER_ID = "Router ID" ) +type PeerInfo struct { + AS uint32 + ID net.IP + VersionNum int + LocalID net.IP +} + type Destination interface { Calculate(localAsn uint32) (Path, string, error) getRouteFamily() RouteFamily @@ -55,7 +62,7 @@ type Destination interface { addWithdraw(withdraw Path) addNewPath(newPath Path) constructWithdrawPath() Path - removeOldPathsFromSource(source *Peer) []Path + removeOldPathsFromSource(source *PeerInfo) []Path } type DestinationDefault struct { @@ -136,7 +143,7 @@ func (dd *DestinationDefault) addNewPath(newPath Path) { dd.newPathList = append(dd.newPathList, newPath) } -func (dd *DestinationDefault) removeOldPathsFromSource(source *Peer) []Path { +func (dd *DestinationDefault) removeOldPathsFromSource(source *PeerInfo) []Path { removePaths := make([]Path, 0) sourceVerNum := source.VersionNum tempKnownPathList := make([]Path, 0) @@ -641,7 +648,7 @@ func compareByASNumber(localAsn uint32, path1, path2 Path) Path { if path.getSource() == nil { asn = localAsn } else { - asn = path.getSource().RemoteAs + asn = path.getSource().AS } return asn } @@ -680,19 +687,19 @@ func compareByRouterID(localAsn uint32, path1, path2 Path) (Path, error) { // RFC: http://tools.ietf.org/html/rfc5004 // We pick best path between two iBGP paths as usual. logger.Debugf("enter compareByRouterID") - getAsn := func(pathSource *Peer) uint32 { + getAsn := func(pathSource *PeerInfo) uint32 { if pathSource == nil { return localAsn } else { - return pathSource.RemoteAs + return pathSource.AS } } - getRouterId := func(pathSource *Peer, localBgpId uint32) uint32 { + getRouterId := func(pathSource *PeerInfo, localBgpId uint32) uint32 { if pathSource == nil { return localBgpId } else { - routerId := pathSource.protocol.recvOpenMsg.ID + routerId := pathSource.ID routerId_u32 := binary.BigEndian.Uint32(routerId) return routerId_u32 } @@ -725,10 +732,10 @@ func compareByRouterID(localAsn uint32, path1, path2 Path) (Path, error) { // At least one path is not coming from NC, so we get local bgp id. var localBgpId_u32 uint32 if pathSource1 != nil { - localBgpId := pathSource1.protocol.sentOpenMsg.ID + localBgpId := pathSource1.LocalID localBgpId_u32 = binary.BigEndian.Uint32(localBgpId) } else { - localBgpId := pathSource2.protocol.sentOpenMsg.ID + localBgpId := pathSource2.LocalID localBgpId_u32 = binary.BigEndian.Uint32(localBgpId) } diff --git a/table/destination_test.go b/table/destination_test.go index 066ee98b..7584ae47 100644 --- a/table/destination_test.go +++ b/table/destination_test.go @@ -110,14 +110,14 @@ func TestDestinationCalculate(t *testing.T) { assert.Nil(t, e) } -func DestCreatePeer() []*Peer { - peerD1 := &Peer{VersionNum: 4, RemoteAs: 65000} - peerD2 := &Peer{VersionNum: 4, RemoteAs: 65001} - peerD3 := &Peer{VersionNum: 4, RemoteAs: 65002} - peerD := []*Peer{peerD1, peerD2, peerD3} +func DestCreatePeer() []*PeerInfo { + peerD1 := &PeerInfo{VersionNum: 4, AS: 65000} + peerD2 := &PeerInfo{VersionNum: 4, AS: 65001} + peerD3 := &PeerInfo{VersionNum: 4, AS: 65002} + peerD := []*PeerInfo{peerD1, peerD2, peerD3} return peerD } -func DestCreateMSG(peerD []*Peer) []*ProcessMessage { +func DestCreateMSG(peerD []*PeerInfo) []*ProcessMessage { bgpMsgD1 := updateMsgD1() bgpMsgD2 := updateMsgD2() bgpMsgD3 := updateMsgD3() diff --git a/table/path.go b/table/path.go index 0d5fe519..649ab10a 100644 --- a/table/path.go +++ b/table/path.go @@ -29,8 +29,8 @@ type Path interface { clone(forWithdrawal bool) Path setRouteFamily(ROUTE_FAMILY RouteFamily) getRouteFamily() RouteFamily - setSource(source *Peer) - getSource() *Peer + setSource(source *PeerInfo) + getSource() *PeerInfo setNexthop(nexthop net.IP) getNexthop() net.IP setSourceVerNum(sourceVerNum int) @@ -46,7 +46,7 @@ type Path interface { type PathDefault struct { ROUTE_FAMILY RouteFamily - source *Peer + source *PeerInfo nexthop net.IP sourceVerNum int withdraw bool @@ -55,7 +55,7 @@ type PathDefault struct { medSetByTargetNeighbor bool } -func NewPathDefault(source *Peer, nlri bgp.AddrPrefixInterface, sourceVerNum int, nexthop net.IP, +func NewPathDefault(source *PeerInfo, nlri bgp.AddrPrefixInterface, sourceVerNum int, nexthop net.IP, isWithdraw bool, pattr *utils.OrderedMap, medSetByTargetNeighbor bool) *PathDefault { if !isWithdraw && (pattr == nil || nexthop == nil) { @@ -94,10 +94,10 @@ func (pd *PathDefault) getRouteFamily() RouteFamily { return pd.ROUTE_FAMILY } -func (pd *PathDefault) setSource(source *Peer) { +func (pd *PathDefault) setSource(source *PeerInfo) { pd.source = source } -func (pd *PathDefault) getSource() *Peer { +func (pd *PathDefault) getSource() *PeerInfo { return pd.source } @@ -248,7 +248,7 @@ func createPathAttributeMap(pathAttributes []bgp.PathAttributeInterface) *utils. } // create Path object based on route family -func CreatePath(source *Peer, nlri bgp.AddrPrefixInterface, +func CreatePath(source *PeerInfo, nlri bgp.AddrPrefixInterface, pathAttributes []bgp.PathAttributeInterface, isWithdraw bool) Path { rf := RouteFamily(int(nlri.AFI())<<16 | int(nlri.SAFI())) @@ -296,7 +296,7 @@ type IPv4Path struct { *PathDefault } -func NewIPv4Path(source *Peer, nlri bgp.AddrPrefixInterface, sourceVerNum int, nexthop net.IP, +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) @@ -315,7 +315,7 @@ type IPv6Path struct { *PathDefault } -func NewIPv6Path(source *Peer, nlri bgp.AddrPrefixInterface, sourceVerNum int, nexthop net.IP, +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) diff --git a/table/path_test.go b/table/path_test.go index b8ac3b9d..3de2561e 100644 --- a/table/path_test.go +++ b/table/path_test.go @@ -68,14 +68,14 @@ func TestPathGetRouteFamily(t *testing.T) { } func TestPathSetSource(t *testing.T) { pd := &PathDefault{} - pr := &Peer{RemoteAs: 65000, VersionNum: 4} + pr := &PeerInfo{AS: 65000, VersionNum: 4} pd.setSource(pr) r_pr := pd.getSource() assert.Equal(t, r_pr, pr) } func TestPathGetSource(t *testing.T) { pd := &PathDefault{} - pr := &Peer{RemoteAs: 65001, VersionNum: 4} + pr := &PeerInfo{AS: 65001, VersionNum: 4} pd.setSource(pr) r_pr := pd.getSource() assert.Equal(t, r_pr, pr) @@ -189,14 +189,14 @@ func TestPathClone(t *testing.T) { assert.Equal(t, clPath, pathP[0]) } -func PathCreatePeer() []*Peer { - peerP1 := &Peer{VersionNum: 4, RemoteAs: 65000} - peerP2 := &Peer{VersionNum: 4, RemoteAs: 65001} - peerP3 := &Peer{VersionNum: 4, RemoteAs: 65002} - peerP := []*Peer{peerP1, peerP2, peerP3} +func PathCreatePeer() []*PeerInfo { + peerP1 := &PeerInfo{VersionNum: 4, AS: 65000} + peerP2 := &PeerInfo{VersionNum: 4, AS: 65001} + peerP3 := &PeerInfo{VersionNum: 4, AS: 65002} + peerP := []*PeerInfo{peerP1, peerP2, peerP3} return peerP } -func PathCreateMSG(peerP []*Peer) []*ProcessMessage { +func PathCreateMSG(peerP []*PeerInfo) []*ProcessMessage { bgpMsgP1 := updateMsgP1() bgpMsgP2 := updateMsgP2() bgpMsgP3 := updateMsgP3() diff --git a/table/table_manager.go b/table/table_manager.go index 63c4a60c..542cd1c3 100644 --- a/table/table_manager.go +++ b/table/table_manager.go @@ -142,7 +142,7 @@ type TableManager struct { type ProcessMessage struct { innerMessage *bgp.BGPMessage - fromPeer *Peer + fromPeer *PeerInfo } func NewTableManager() *TableManager { @@ -303,7 +303,7 @@ LOOP: // process BGPUpdate message // this function processes only BGPUpdate -func (manager *TableManager) ProcessUpdate(fromPeer *Peer, message *bgp.BGPMessage) ([]Path, []Destination, error) { +func (manager *TableManager) ProcessUpdate(fromPeer *PeerInfo, message *bgp.BGPMessage) ([]Path, []Destination, error) { var bestPaths []Path = make([]Path, 0) var lostDest []Destination = make([]Destination, 0) diff --git a/table/table_manager_test.go b/table/table_manager_test.go index 20d056b7..cea108df 100644 --- a/table/table_manager_test.go +++ b/table/table_manager_test.go @@ -20,6 +20,7 @@ import ( log "github.com/Sirupsen/logrus" "github.com/osrg/gobgp/packet" "github.com/stretchr/testify/assert" + "net" "os" "reflect" "testing" @@ -35,36 +36,30 @@ func getLogger(lv log.Level) *log.Logger { return l } -func peerR1() *Peer { - proto := &BgpProtocol{} - proto.sentOpenMsg = bgp.NewBGPOpenMessage(65000, 300, "10.0.0.1", nil).Body.(*bgp.BGPOpen) - proto.recvOpenMsg = bgp.NewBGPOpenMessage(65000, 300, "10.0.0.3", nil).Body.(*bgp.BGPOpen) - - peer := &Peer{ +func peerR1() *PeerInfo { + peer := &PeerInfo{ VersionNum: 4, - RemoteAs: 65000, - protocol: proto, + AS: 65000, + ID: net.ParseIP("10.0.0.3").To4(), + LocalID: net.ParseIP("10.0.0.1").To4(), } return peer } -func peerR2() *Peer { - peer := &Peer{ +func peerR2() *PeerInfo { + peer := &PeerInfo{ VersionNum: 4, - RemoteAs: 65100, + AS: 65100, } return peer } -func peerR3() *Peer { - proto := &BgpProtocol{} - proto.sentOpenMsg = bgp.NewBGPOpenMessage(65000, 300, "10.0.0.1", nil).Body.(*bgp.BGPOpen) - proto.recvOpenMsg = bgp.NewBGPOpenMessage(65000, 300, "10.0.0.2", nil).Body.(*bgp.BGPOpen) - - peer := &Peer{ +func peerR3() *PeerInfo { + peer := &PeerInfo{ VersionNum: 4, - RemoteAs: 65000, - protocol: proto, + AS: 65000, + ID: net.ParseIP("10.0.0.2").To4(), + LocalID: net.ParseIP("10.0.0.1").To4(), } return peer } @@ -374,7 +369,7 @@ func TestProcessBGPUpdate_2_select_local_origin_ipv4(t *testing.T) { assert.Equal(t, 0, len(wList)) assert.NoError(t, err) - var peer2 *Peer = nil + var peer2 *PeerInfo = nil pList, wList, err = tm.ProcessUpdate(peer2, bgpMessage2) assert.Equal(t, 1, len(pList)) assert.Equal(t, 0, len(wList)) @@ -458,7 +453,7 @@ func TestProcessBGPUpdate_2_select_local_origin_ipv6(t *testing.T) { assert.Equal(t, 0, len(wList)) assert.NoError(t, err) - var peer2 *Peer = nil + var peer2 *PeerInfo = nil pList, wList, err = tm.ProcessUpdate(peer2, bgpMessage2) assert.Equal(t, 1, len(pList)) assert.Equal(t, 0, len(wList)) diff --git a/table/table_test.go b/table/table_test.go index 094b6500..63ae026f 100644 --- a/table/table_test.go +++ b/table/table_test.go @@ -106,14 +106,14 @@ func TestTableGetDestinations(t *testing.T) { assert.Equal(t, ds, destinations) } -func TableCreatePeer() []*Peer { - peerT1 := &Peer{VersionNum: 4, RemoteAs: 65000} - peerT2 := &Peer{VersionNum: 4, RemoteAs: 65001} - peerT3 := &Peer{VersionNum: 4, RemoteAs: 65002} - peerT := []*Peer{peerT1, peerT2, peerT3} +func TableCreatePeer() []*PeerInfo { + peerT1 := &PeerInfo{VersionNum: 4, AS: 65000} + peerT2 := &PeerInfo{VersionNum: 4, AS: 65001} + peerT3 := &PeerInfo{VersionNum: 4, AS: 65002} + peerT := []*PeerInfo{peerT1, peerT2, peerT3} return peerT } -func TableCreateMSG(peerT []*Peer) []*ProcessMessage { +func TableCreateMSG(peerT []*PeerInfo) []*ProcessMessage { bgpMsgT1 := updateMsgT1() bgpMsgT2 := updateMsgT2() bgpMsgT3 := updateMsgT3() diff --git a/table/temporary_structs.go b/table/temporary_structs.go deleted file mode 100644 index f892f625..00000000 --- a/table/temporary_structs.go +++ /dev/null @@ -1,21 +0,0 @@ -// core.go -package table - -import ( - "github.com/osrg/gobgp/packet" - "net" -) - -type Peer struct { - //need to define a structure - RemoteAs uint32 - VersionNum int - RemoteAddress net.IP - protocol *BgpProtocol -} - -type BgpProtocol struct { - //need to define a structure - recvOpenMsg *bgp.BGPOpen - sentOpenMsg *bgp.BGPOpen -} |