summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--server/peer.go12
-rw-r--r--table/destination.go14
-rw-r--r--table/destination_test.go6
-rw-r--r--table/path.go35
-rw-r--r--table/path_test.go34
-rw-r--r--table/table.go2
-rw-r--r--table/table_manager_test.go17
-rw-r--r--table/table_test.go6
8 files changed, 42 insertions, 84 deletions
diff --git a/server/peer.go b/server/peer.go
index a54a8af4..516fc24e 100644
--- a/server/peer.go
+++ b/server/peer.go
@@ -84,11 +84,10 @@ func NewPeer(g config.GlobalType, peer config.NeighborType, serverMsgCh chan *se
p.rf = bgp.RF_IPv6_UC
}
p.peerInfo = &table.PeerInfo{
- AS: peer.PeerAs,
- VersionNum: 1,
- LocalID: g.RouterId,
- RF: p.rf,
- Address: peer.NeighborAddress,
+ AS: peer.PeerAs,
+ LocalID: g.RouterId,
+ RF: p.rf,
+ Address: peer.NeighborAddress,
}
p.adjRib = table.NewAdjRib()
p.rib = table.NewTableManager()
@@ -256,9 +255,6 @@ func (peer *Peer) loop() error {
peer.sendMessages(table.CreateUpdateMsgFromPaths(pathList))
peer.fsm.peerConfig.BgpNeighborCommonState.Uptime = time.Now()
peer.fsm.peerConfig.BgpNeighborCommonState.EstablishedCount++
- if oldState >= bgp.BGP_FSM_OPENSENT {
- peer.peerInfo.VersionNum++
- }
}
if oldState == bgp.BGP_FSM_ESTABLISHED {
peer.fsm.peerConfig.BgpNeighborCommonState.Uptime = time.Time{}
diff --git a/table/destination.go b/table/destination.go
index 73cae66c..2954c699 100644
--- a/table/destination.go
+++ b/table/destination.go
@@ -41,12 +41,11 @@ const (
)
type PeerInfo struct {
- AS uint32
- ID net.IP
- VersionNum int
- LocalID net.IP
- RF bgp.RouteFamily
- Address net.IP
+ AS uint32
+ ID net.IP
+ LocalID net.IP
+ RF bgp.RouteFamily
+ Address net.IP
}
type Destination interface {
@@ -172,11 +171,10 @@ func (dd *DestinationDefault) addNewPath(newPath Path) {
func (dd *DestinationDefault) removeOldPathsFromSource(source *PeerInfo) []Path {
removePaths := make([]Path, 0)
- sourceVerNum := source.VersionNum
tempKnownPathList := make([]Path, 0)
for _, path := range dd.knownPathList {
- if path.getSource() == source && path.getSourceVerNum() < sourceVerNum {
+ if path.getSource() == source {
removePaths = append(removePaths, path)
} else {
tempKnownPathList = append(tempKnownPathList, path)
diff --git a/table/destination_test.go b/table/destination_test.go
index e003ce67..2398773e 100644
--- a/table/destination_test.go
+++ b/table/destination_test.go
@@ -111,9 +111,9 @@ func TestDestinationCalculate(t *testing.T) {
}
func DestCreatePeer() []*PeerInfo {
- peerD1 := &PeerInfo{VersionNum: 4, AS: 65000}
- peerD2 := &PeerInfo{VersionNum: 4, AS: 65001}
- peerD3 := &PeerInfo{VersionNum: 4, AS: 65002}
+ peerD1 := &PeerInfo{AS: 65000}
+ peerD2 := &PeerInfo{AS: 65001}
+ peerD3 := &PeerInfo{AS: 65002}
peerD := []*PeerInfo{peerD1, peerD2, peerD3}
return peerD
}
diff --git a/table/path.go b/table/path.go
index bc92ed16..80969ab1 100644
--- a/table/path.go
+++ b/table/path.go
@@ -33,8 +33,6 @@ type Path interface {
getSource() *PeerInfo
setNexthop(nexthop net.IP)
getNexthop() net.IP
- setSourceVerNum(sourceVerNum int)
- getSourceVerNum() int
setWithdraw(withdraw bool)
IsWithdraw() bool
getNlri() bgp.AddrPrefixInterface
@@ -50,7 +48,6 @@ type PathDefault struct {
routeFamily bgp.RouteFamily
source *PeerInfo
nexthop net.IP
- sourceVerNum int
withdraw bool
nlri bgp.AddrPrefixInterface
pathAttrs []bgp.PathAttributeInterface
@@ -58,7 +55,7 @@ type PathDefault struct {
isBest bool
}
-func NewPathDefault(rf bgp.RouteFamily, source *PeerInfo, nlri bgp.AddrPrefixInterface, sourceVerNum int, nexthop net.IP, isWithdraw bool, pattrs []bgp.PathAttributeInterface, medSetByTargetNeighbor bool) *PathDefault {
+func NewPathDefault(rf bgp.RouteFamily, source *PeerInfo, nlri bgp.AddrPrefixInterface, nexthop net.IP, isWithdraw bool, pattrs []bgp.PathAttributeInterface, medSetByTargetNeighbor bool) *PathDefault {
if !isWithdraw && pattrs == nil {
log.Error("Need to provide nexthop and patattrs for path that is not a withdraw.")
@@ -71,7 +68,6 @@ func NewPathDefault(rf bgp.RouteFamily, source *PeerInfo, nlri bgp.AddrPrefixInt
path.nlri = nlri
path.source = source
path.nexthop = nexthop
- path.sourceVerNum = sourceVerNum
path.withdraw = isWithdraw
path.medSetByTargetNeighbor = medSetByTargetNeighbor
path.isBest = false
@@ -145,14 +141,6 @@ func (pd *PathDefault) getNexthop() net.IP {
return pd.nexthop
}
-func (pd *PathDefault) setSourceVerNum(sourceVerNum int) {
- pd.sourceVerNum = sourceVerNum
-}
-
-func (pd *PathDefault) getSourceVerNum() int {
- return pd.sourceVerNum
-}
-
func (pd *PathDefault) setWithdraw(withdraw bool) {
pd.withdraw = withdraw
}
@@ -206,7 +194,7 @@ func (pd *PathDefault) getPathAttr(pattrType bgp.BGPAttrType) (int, bgp.PathAttr
// return Path's string representation
func (pi *PathDefault) String() string {
- str := fmt.Sprintf("IPv4Path Source: %d, ", pi.getSourceVerNum())
+ str := fmt.Sprintf("IPv4Path Source: %v, ", pi.getSource())
str = str + fmt.Sprintf(" NLRI: %s, ", pi.getPrefix().String())
str = str + fmt.Sprintf(" nexthop: %s, ", pi.getNexthop().String())
str = str + fmt.Sprintf(" withdraw: %s, ", pi.IsWithdraw())
@@ -231,19 +219,14 @@ func CreatePath(source *PeerInfo, nlri bgp.AddrPrefixInterface, attrs []bgp.Path
rf := bgp.RouteFamily(int(nlri.AFI())<<16 | int(nlri.SAFI()))
log.Debugf("afi: %d, safi: %d ", int(nlri.AFI()), nlri.SAFI())
var path Path
- var sourceVerNum int = 1
-
- if source != nil {
- sourceVerNum = source.VersionNum
- }
switch rf {
case bgp.RF_IPv4_UC:
log.Debugf("RouteFamily : %s", bgp.RF_IPv4_UC.String())
- path = NewIPv4Path(source, nlri, sourceVerNum, isWithdraw, attrs, false)
+ path = NewIPv4Path(source, nlri, isWithdraw, attrs, false)
case bgp.RF_IPv6_UC:
log.Debugf("RouteFamily : %s", bgp.RF_IPv6_UC.String())
- path = NewIPv6Path(source, nlri, sourceVerNum, isWithdraw, attrs, false)
+ path = NewIPv6Path(source, nlri, isWithdraw, attrs, false)
}
return path
}
@@ -255,9 +238,9 @@ type IPv4Path struct {
*PathDefault
}
-func NewIPv4Path(source *PeerInfo, nlri bgp.AddrPrefixInterface, sourceVerNum int, isWithdraw bool, attrs []bgp.PathAttributeInterface, medSetByTargetNeighbor bool) *IPv4Path {
+func NewIPv4Path(source *PeerInfo, nlri bgp.AddrPrefixInterface, isWithdraw bool, attrs []bgp.PathAttributeInterface, medSetByTargetNeighbor bool) *IPv4Path {
ipv4Path := &IPv4Path{}
- ipv4Path.PathDefault = NewPathDefault(bgp.RF_IPv4_UC, source, nlri, sourceVerNum, nil, isWithdraw, attrs, medSetByTargetNeighbor)
+ ipv4Path.PathDefault = NewPathDefault(bgp.RF_IPv4_UC, source, nlri, nil, isWithdraw, attrs, medSetByTargetNeighbor)
if !isWithdraw {
_, nexthop_attr := ipv4Path.getPathAttr(bgp.BGP_ATTR_TYPE_NEXT_HOP)
ipv4Path.nexthop = nexthop_attr.(*bgp.PathAttributeNextHop).Value
@@ -276,9 +259,9 @@ type IPv6Path struct {
*PathDefault
}
-func NewIPv6Path(source *PeerInfo, nlri bgp.AddrPrefixInterface, sourceVerNum int, isWithdraw bool, attrs []bgp.PathAttributeInterface, medSetByTargetNeighbor bool) *IPv6Path {
+func NewIPv6Path(source *PeerInfo, nlri bgp.AddrPrefixInterface, isWithdraw bool, attrs []bgp.PathAttributeInterface, medSetByTargetNeighbor bool) *IPv6Path {
ipv6Path := &IPv6Path{}
- ipv6Path.PathDefault = NewPathDefault(bgp.RF_IPv6_UC, source, nlri, sourceVerNum, nil, isWithdraw, attrs, medSetByTargetNeighbor)
+ ipv6Path.PathDefault = NewPathDefault(bgp.RF_IPv6_UC, source, nlri, nil, isWithdraw, attrs, medSetByTargetNeighbor)
if !isWithdraw {
_, mpattr := ipv6Path.getPathAttr(bgp.BGP_ATTR_TYPE_MP_REACH_NLRI)
ipv6Path.nexthop = mpattr.(*bgp.PathAttributeMpReachNLRI).Nexthop
@@ -311,7 +294,7 @@ func (ipv6p *IPv6Path) getPrefix() net.IP {
// return IPv6Path's string representation
func (ipv6p *IPv6Path) String() string {
- str := fmt.Sprintf("IPv6Path Source: %d, ", ipv6p.getSourceVerNum())
+ str := fmt.Sprintf("IPv6Path Source: %v, ", ipv6p.getSource())
str = str + fmt.Sprintf(" NLRI: %s, ", ipv6p.getPrefix().String())
str = str + fmt.Sprintf(" nexthop: %s, ", ipv6p.getNexthop().String())
str = str + fmt.Sprintf(" withdraw: %s, ", ipv6p.IsWithdraw())
diff --git a/table/path_test.go b/table/path_test.go
index feed46ed..b913520f 100644
--- a/table/path_test.go
+++ b/table/path_test.go
@@ -13,14 +13,14 @@ func TestPathNewIPv4(t *testing.T) {
peerP := PathCreatePeer()
msgP := PathCreateMSG(peerP)
pathP := PathCreatePath(msgP)
- ipv4p := NewIPv4Path(pathP[0].getSource(), pathP[0].getNlri(), pathP[0].getSourceVerNum(), true, pathP[0].getPathAttrs(), pathP[0].getMedSetByTargetNeighbor())
+ ipv4p := NewIPv4Path(pathP[0].getSource(), pathP[0].getNlri(), true, pathP[0].getPathAttrs(), pathP[0].getMedSetByTargetNeighbor())
assert.NotNil(t, ipv4p)
}
func TestPathNewIPv6(t *testing.T) {
peerP := PathCreatePeer()
msgP := PathCreateMSG(peerP)
pathP := PathCreatePath(msgP)
- ipv6p := NewIPv6Path(pathP[0].getSource(), pathP[0].getNlri(), pathP[0].getSourceVerNum(), true, pathP[0].getPathAttrs(), pathP[0].getMedSetByTargetNeighbor())
+ ipv6p := NewIPv6Path(pathP[0].getSource(), pathP[0].getNlri(), true, pathP[0].getPathAttrs(), pathP[0].getMedSetByTargetNeighbor())
assert.NotNil(t, ipv6p)
}
@@ -41,7 +41,7 @@ func TestPathIPv4GetDefault(t *testing.T) {
}
func TestPathIPv6SetDefault(t *testing.T) {
- pd := &PathDefault{sourceVerNum: 4}
+ pd := &PathDefault{}
ipv6p := &IPv6Path{}
ipv6p.setPathDefault(pd)
r_pd := ipv6p.getPathDefault()
@@ -49,7 +49,7 @@ func TestPathIPv6SetDefault(t *testing.T) {
}
func TestPathIPv6GetDefault(t *testing.T) {
- pd := &PathDefault{sourceVerNum: 5}
+ pd := &PathDefault{}
ipv6p := &IPv6Path{}
ipv6p.setPathDefault(pd)
r_pd := ipv6p.getPathDefault()
@@ -64,7 +64,7 @@ func TestPathGetRouteFamily(t *testing.T) {
func TestPathSetSource(t *testing.T) {
pd := &PathDefault{}
- pr := &PeerInfo{AS: 65000, VersionNum: 4}
+ pr := &PeerInfo{AS: 65000}
pd.setSource(pr)
r_pr := pd.getSource()
assert.Equal(t, r_pr, pr)
@@ -72,7 +72,7 @@ func TestPathSetSource(t *testing.T) {
func TestPathGetSource(t *testing.T) {
pd := &PathDefault{}
- pr := &PeerInfo{AS: 65001, VersionNum: 4}
+ pr := &PeerInfo{AS: 65001}
pd.setSource(pr)
r_pr := pd.getSource()
assert.Equal(t, r_pr, pr)
@@ -94,22 +94,6 @@ func TestPathgetNexthop(t *testing.T) {
assert.Equal(t, nh, ip)
}
-func TestPathSetSourceVerNum(t *testing.T) {
- pd := &PathDefault{}
- svn := 4
- pd.setSourceVerNum(svn)
- r_svn := pd.getSourceVerNum()
- assert.Equal(t, r_svn, svn)
-}
-
-func TestPathGetSourceVerNum(t *testing.T) {
- pd := &PathDefault{}
- svn := 5
- pd.setSourceVerNum(svn)
- r_svn := pd.getSourceVerNum()
- assert.Equal(t, r_svn, svn)
-}
-
func TestPathSetWithdraw(t *testing.T) {
pd := &PathDefault{}
wd := true
@@ -182,9 +166,9 @@ func TestPathGetAttribute(t *testing.T) {
}
func PathCreatePeer() []*PeerInfo {
- peerP1 := &PeerInfo{VersionNum: 4, AS: 65000}
- peerP2 := &PeerInfo{VersionNum: 4, AS: 65001}
- peerP3 := &PeerInfo{VersionNum: 4, AS: 65002}
+ peerP1 := &PeerInfo{AS: 65000}
+ peerP2 := &PeerInfo{AS: 65001}
+ peerP3 := &PeerInfo{AS: 65002}
peerP := []*PeerInfo{peerP1, peerP2, peerP3}
return peerP
}
diff --git a/table/table.go b/table/table.go
index 0be4c75f..de36510d 100644
--- a/table/table.go
+++ b/table/table.go
@@ -114,7 +114,7 @@ func (td *TableDefault) DeleteDestByPeer(peerInfo *PeerInfo) []Destination {
for _, dest := range td.destinations {
newKnownPathList := make([]Path, 0)
for _, p := range dest.getKnownPathList() {
- if peerInfo != p.getSource() || peerInfo.VersionNum != p.getSourceVerNum() {
+ if p.getSource() != peerInfo {
newKnownPathList = append(newKnownPathList, p)
}
}
diff --git a/table/table_manager_test.go b/table/table_manager_test.go
index 63d114f3..4440a909 100644
--- a/table/table_manager_test.go
+++ b/table/table_manager_test.go
@@ -38,28 +38,25 @@ func getLogger(lv log.Level) *log.Logger {
func peerR1() *PeerInfo {
peer := &PeerInfo{
- VersionNum: 4,
- AS: 65000,
- ID: net.ParseIP("10.0.0.3").To4(),
- LocalID: net.ParseIP("10.0.0.1").To4(),
+ AS: 65000,
+ ID: net.ParseIP("10.0.0.3").To4(),
+ LocalID: net.ParseIP("10.0.0.1").To4(),
}
return peer
}
func peerR2() *PeerInfo {
peer := &PeerInfo{
- VersionNum: 4,
- AS: 65100,
+ AS: 65100,
}
return peer
}
func peerR3() *PeerInfo {
peer := &PeerInfo{
- VersionNum: 4,
- AS: 65000,
- ID: net.ParseIP("10.0.0.2").To4(),
- LocalID: net.ParseIP("10.0.0.1").To4(),
+ AS: 65000,
+ ID: net.ParseIP("10.0.0.2").To4(),
+ LocalID: net.ParseIP("10.0.0.1").To4(),
}
return peer
}
diff --git a/table/table_test.go b/table/table_test.go
index 0827df74..74381e8b 100644
--- a/table/table_test.go
+++ b/table/table_test.go
@@ -107,9 +107,9 @@ func TestTableGetDestinations(t *testing.T) {
}
func TableCreatePeer() []*PeerInfo {
- peerT1 := &PeerInfo{VersionNum: 4, AS: 65000}
- peerT2 := &PeerInfo{VersionNum: 4, AS: 65001}
- peerT3 := &PeerInfo{VersionNum: 4, AS: 65002}
+ peerT1 := &PeerInfo{AS: 65000}
+ peerT2 := &PeerInfo{AS: 65001}
+ peerT3 := &PeerInfo{AS: 65002}
peerT := []*PeerInfo{peerT1, peerT2, peerT3}
return peerT
}