summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--server/fsm.go37
-rw-r--r--server/peer.go21
2 files changed, 16 insertions, 42 deletions
diff --git a/server/fsm.go b/server/fsm.go
index e215450a..c6309367 100644
--- a/server/fsm.go
+++ b/server/fsm.go
@@ -19,7 +19,6 @@ import (
log "github.com/Sirupsen/logrus"
"github.com/osrg/gobgp/config"
"github.com/osrg/gobgp/packet"
- "github.com/osrg/gobgp/table"
"gopkg.in/tomb.v2"
"net"
"time"
@@ -35,10 +34,6 @@ type FSM struct {
passiveConn *net.TCPConn
passiveConnCh chan *net.TCPConn
stateCh chan bgp.FSMState
-
- peerInfo *table.PeerInfo
- sourceVerNum int
- routerId net.IP
}
func (fsm *FSM) bgpMessageStateUpdate(MessageType uint8, isIn bool) {
@@ -92,7 +87,6 @@ func NewFSM(gConfig *config.GlobalType, pConfig *config.NeighborType, connCh cha
state: bgp.BGP_FSM_IDLE,
passiveConnCh: connCh,
stateCh: make(chan bgp.FSMState),
- sourceVerNum: 1,
}
}
@@ -105,27 +99,6 @@ func (fsm *FSM) StateChange(nextState bgp.FSMState) {
fsm.state = nextState
}
-func (fsm *FSM) PeerInfoGet() *table.PeerInfo {
- return fsm.peerInfo
-}
-
-func (fsm *FSM) createPeerInfo() {
- var rf bgp.RouteFamily
- if fsm.peerConfig.NeighborAddress.To4() != nil {
- rf = bgp.RF_IPv4_UC
- } else {
- rf = bgp.RF_IPv6_UC
- }
-
- fsm.peerInfo = &table.PeerInfo{
- AS: fsm.peerConfig.PeerAs,
- ID: fsm.routerId,
- VersionNum: fsm.sourceVerNum,
- LocalID: fsm.globalConfig.RouterId,
- RF: rf,
- }
-}
-
type FSMHandler struct {
t tomb.Tomb
fsm *FSM
@@ -265,7 +238,6 @@ func (h *FSMHandler) opensent() bgp.FSMState {
fsm.bgpMessageStateUpdate(m.Header.Type, true)
if m.Header.Type == bgp.BGP_MSG_OPEN {
fsm.incoming <- m
- fsm.routerId = m.Body.(*bgp.BGPOpen).ID
msg := bgp.NewBGPKeepAliveMessage()
b, _ := msg.Serialize()
fsm.passiveConn.Write(b)
@@ -412,15 +384,6 @@ func (h *FSMHandler) loop() error {
nextState = h.established()
}
- if nextState == bgp.BGP_FSM_ESTABLISHED {
- // everytime we go into BGP_FSM_ESTABLISHED, we create
- // a PeerInfo because sourceNum could be incremented
- fsm.createPeerInfo()
- }
- if fsm.state >= bgp.BGP_FSM_OPENSENT && nextState == bgp.BGP_FSM_IDLE {
- fsm.sourceVerNum++
- }
-
if nextState >= bgp.BGP_FSM_IDLE {
fsm.stateCh <- nextState
}
diff --git a/server/peer.go b/server/peer.go
index 35fc3d90..88a327e7 100644
--- a/server/peer.go
+++ b/server/peer.go
@@ -42,8 +42,9 @@ type Peer struct {
// here but it's the simplest and works our first target.
rib *table.TableManager
// for now we support only the same afi as transport
- rf bgp.RouteFamily
- capMap map[bgp.BGPCapabilityCode]bgp.ParameterCapabilityInterface
+ rf bgp.RouteFamily
+ capMap map[bgp.BGPCapabilityCode]bgp.ParameterCapabilityInterface
+ peerInfo *table.PeerInfo
}
func NewPeer(g config.GlobalType, peer config.NeighborType, outEventCh chan *message) *Peer {
@@ -64,6 +65,12 @@ func NewPeer(g config.GlobalType, peer config.NeighborType, outEventCh chan *mes
} else {
p.rf = bgp.RF_IPv6_UC
}
+ p.peerInfo = &table.PeerInfo{
+ AS: peer.PeerAs,
+ VersionNum: 1,
+ LocalID: g.RouterId,
+ RF: p.rf,
+ }
p.adjRib = table.NewAdjRib()
p.rib = table.NewTableManager()
p.t.Go(p.loop)
@@ -77,6 +84,7 @@ func (peer *Peer) handleBGPmessage(m *bgp.BGPMessage) {
switch m.Header.Type {
case bgp.BGP_MSG_OPEN:
body := m.Body.(*bgp.BGPOpen)
+ peer.peerInfo.ID = m.Body.(*bgp.BGPOpen).ID
for _, p := range body.OptParams {
paramCap, y := p.(*bgp.OptionParameterCapability)
if !y {
@@ -94,7 +102,7 @@ func (peer *Peer) handleBGPmessage(m *bgp.BGPMessage) {
peer.peerConfig.BgpNeighborCommonState.UpdateRecvTime = time.Now()
body := m.Body.(*bgp.BGPUpdate)
table.UpdatePathAttrs4ByteAs(body)
- msg := table.NewProcessMessage(m, peer.fsm.peerInfo)
+ msg := table.NewProcessMessage(m, peer.peerInfo)
pathList := msg.ToPathList()
if len(pathList) == 0 {
return
@@ -179,10 +187,13 @@ 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{}
- peer.sendToHub("", PEER_MSG_DOWN, peer.fsm.peerInfo)
+ peer.sendToHub("", PEER_MSG_DOWN, peer.peerInfo)
}
case <-peer.t.Dying():
close(peer.acceptedConnCh)
@@ -242,7 +253,7 @@ func (peer *Peer) MarshalJSON() ([]byte, error) {
CapEnhancedRefresh bool `json:"cap_enhanced_refresh"`
}{
RemoteIP: c.NeighborAddress.String(),
- Id: f.routerId.To4().String(),
+ Id: peer.peerInfo.ID.To4().String(),
//Description: "",
RemoteAS: c.PeerAs,
//LocalAddress: f.passiveConn.LocalAddr().String(),