Skip to content
Snippets Groups Projects
Commit f68bcee1 authored by Oliver Herms's avatar Oliver Herms
Browse files

Renaming FSM2 to FSM

parent 3536eaee
No related branches found
No related tags found
No related merge requests found
...@@ -26,8 +26,8 @@ type state interface { ...@@ -26,8 +26,8 @@ type state interface {
run() (state, string) run() (state, string)
} }
// FSM2 implements the BGP finite state machine (RFC4271) // FSM implements the BGP finite state machine (RFC4271)
type FSM2 struct { type FSM struct {
peer *Peer peer *Peer
eventCh chan int eventCh chan int
con net.Conn con net.Conn
...@@ -72,7 +72,7 @@ type FSM2 struct { ...@@ -72,7 +72,7 @@ type FSM2 struct {
} }
// NewPassiveFSM2 initiates a new passive FSM // NewPassiveFSM2 initiates a new passive FSM
func NewPassiveFSM2(peer *Peer, con *net.TCPConn) *FSM2 { func NewPassiveFSM2(peer *Peer, con *net.TCPConn) *FSM {
fsm := newFSM2(peer) fsm := newFSM2(peer)
fsm.con = con fsm.con = con
fsm.state = newIdleState(fsm) fsm.state = newIdleState(fsm)
...@@ -80,15 +80,15 @@ func NewPassiveFSM2(peer *Peer, con *net.TCPConn) *FSM2 { ...@@ -80,15 +80,15 @@ func NewPassiveFSM2(peer *Peer, con *net.TCPConn) *FSM2 {
} }
// NewActiveFSM2 initiates a new passive FSM // NewActiveFSM2 initiates a new passive FSM
func NewActiveFSM2(peer *Peer) *FSM2 { func NewActiveFSM2(peer *Peer) *FSM {
fsm := newFSM2(peer) fsm := newFSM2(peer)
fsm.active = true fsm.active = true
fsm.state = newIdleState(fsm) fsm.state = newIdleState(fsm)
return fsm return fsm
} }
func newFSM2(peer *Peer) *FSM2 { func newFSM2(peer *Peer) *FSM {
return &FSM2{ return &FSM{
connectRetryTime: time.Minute, connectRetryTime: time.Minute,
peer: peer, peer: peer,
eventCh: make(chan int), eventCh: make(chan int),
...@@ -102,17 +102,17 @@ func newFSM2(peer *Peer) *FSM2 { ...@@ -102,17 +102,17 @@ func newFSM2(peer *Peer) *FSM2 {
} }
} }
func (fsm *FSM2) start() { func (fsm *FSM) start() {
go fsm.run() go fsm.run()
go fsm.tcpConnector() go fsm.tcpConnector()
return return
} }
func (fsm *FSM2) activate() { func (fsm *FSM) activate() {
fsm.eventCh <- AutomaticStart fsm.eventCh <- AutomaticStart
} }
func (fsm *FSM2) run() { func (fsm *FSM) run() {
next, reason := fsm.state.run() next, reason := fsm.state.run()
for { for {
newState := stateName(next) newState := stateName(next)
...@@ -160,11 +160,11 @@ func stateName(s state) string { ...@@ -160,11 +160,11 @@ func stateName(s state) string {
} }
} }
func (fsm *FSM2) cease() { func (fsm *FSM) cease() {
fsm.eventCh <- Cease fsm.eventCh <- Cease
} }
func (fsm *FSM2) tcpConnector() error { func (fsm *FSM) tcpConnector() error {
for { for {
select { select {
case <-fsm.initiateCon: case <-fsm.initiateCon:
...@@ -189,11 +189,11 @@ func (fsm *FSM2) tcpConnector() error { ...@@ -189,11 +189,11 @@ func (fsm *FSM2) tcpConnector() error {
} }
} }
func (fsm *FSM2) tcpConnect() { func (fsm *FSM) tcpConnect() {
fsm.initiateCon <- struct{}{} fsm.initiateCon <- struct{}{}
} }
func (fsm *FSM2) msgReceiver() error { func (fsm *FSM) msgReceiver() error {
for { for {
msg, err := recvMsg(fsm.con) msg, err := recvMsg(fsm.con)
if err != nil { if err != nil {
...@@ -204,21 +204,21 @@ func (fsm *FSM2) msgReceiver() error { ...@@ -204,21 +204,21 @@ func (fsm *FSM2) msgReceiver() error {
} }
} }
func (fsm *FSM2) startConnectRetryTimer() { func (fsm *FSM) startConnectRetryTimer() {
fsm.connectRetryTimer = time.NewTimer(fsm.connectRetryTime) fsm.connectRetryTimer = time.NewTimer(fsm.connectRetryTime)
} }
func (fsm *FSM2) resetConnectRetryTimer() { func (fsm *FSM) resetConnectRetryTimer() {
if !fsm.connectRetryTimer.Reset(fsm.connectRetryTime) { if !fsm.connectRetryTimer.Reset(fsm.connectRetryTime) {
<-fsm.connectRetryTimer.C <-fsm.connectRetryTimer.C
} }
} }
func (fsm *FSM2) resetConnectRetryCounter() { func (fsm *FSM) resetConnectRetryCounter() {
fsm.connectRetryCounter = 0 fsm.connectRetryCounter = 0
} }
func (fsm *FSM2) sendOpen() error { func (fsm *FSM) sendOpen() error {
msg := packet.SerializeOpenMsg(&packet.BGPOpen{ msg := packet.SerializeOpenMsg(&packet.BGPOpen{
Version: BGPVersion, Version: BGPVersion,
AS: uint16(fsm.peer.localASN), AS: uint16(fsm.peer.localASN),
...@@ -235,7 +235,7 @@ func (fsm *FSM2) sendOpen() error { ...@@ -235,7 +235,7 @@ func (fsm *FSM2) sendOpen() error {
return nil return nil
} }
func (fsm *FSM2) sendNotification(errorCode uint8, errorSubCode uint8) error { func (fsm *FSM) sendNotification(errorCode uint8, errorSubCode uint8) error {
msg := packet.SerializeNotificationMsg(&packet.BGPNotification{}) msg := packet.SerializeNotificationMsg(&packet.BGPNotification{})
_, err := fsm.con.Write(msg) _, err := fsm.con.Write(msg)
...@@ -246,7 +246,7 @@ func (fsm *FSM2) sendNotification(errorCode uint8, errorSubCode uint8) error { ...@@ -246,7 +246,7 @@ func (fsm *FSM2) sendNotification(errorCode uint8, errorSubCode uint8) error {
return nil return nil
} }
func (fsm *FSM2) sendKeepalive() error { func (fsm *FSM) sendKeepalive() error {
msg := packet.SerializeKeepaliveMsg() msg := packet.SerializeKeepaliveMsg()
_, err := fsm.con.Write(msg) _, err := fsm.con.Write(msg)
......
...@@ -7,10 +7,10 @@ import ( ...@@ -7,10 +7,10 @@ import (
) )
type activeState struct { type activeState struct {
fsm *FSM2 fsm *FSM
} }
func newActiveState(fsm *FSM2) *activeState { func newActiveState(fsm *FSM) *activeState {
return &activeState{ return &activeState{
fsm: fsm, fsm: fsm,
} }
......
...@@ -7,10 +7,10 @@ import ( ...@@ -7,10 +7,10 @@ import (
) )
type connectState struct { type connectState struct {
fsm *FSM2 fsm *FSM
} }
func newConnectState(fsm *FSM2) *connectState { func newConnectState(fsm *FSM) *connectState {
return &connectState{ return &connectState{
fsm: fsm, fsm: fsm,
} }
......
...@@ -14,10 +14,10 @@ import ( ...@@ -14,10 +14,10 @@ import (
) )
type establishedState struct { type establishedState struct {
fsm *FSM2 fsm *FSM
} }
func newEstablishedState(fsm *FSM2) *establishedState { func newEstablishedState(fsm *FSM) *establishedState {
return &establishedState{ return &establishedState{
fsm: fsm, fsm: fsm,
} }
......
...@@ -5,11 +5,11 @@ import ( ...@@ -5,11 +5,11 @@ import (
) )
type idleState struct { type idleState struct {
fsm *FSM2 fsm *FSM
newStateReason string newStateReason string
} }
func newIdleState(fsm *FSM2) *idleState { func newIdleState(fsm *FSM) *idleState {
return &idleState{ return &idleState{
fsm: fsm, fsm: fsm,
} }
......
...@@ -3,12 +3,12 @@ package server ...@@ -3,12 +3,12 @@ package server
import "net" import "net"
type fsmManager struct { type fsmManager struct {
fsms map[string][]*FSM2 fsms map[string][]*FSM
} }
func newFSMManager() *fsmManager { func newFSMManager() *fsmManager {
return &fsmManager{ return &fsmManager{
fsms: make(map[string][]*FSM2, 0), fsms: make(map[string][]*FSM, 0),
} }
} }
...@@ -16,10 +16,10 @@ func (m *fsmManager) resolveCollision(addr net.IP) { ...@@ -16,10 +16,10 @@ func (m *fsmManager) resolveCollision(addr net.IP) {
} }
func (m *fsmManager) newFSMPassive() *FSM2 { func (m *fsmManager) newFSMPassive() *FSM {
return &FSM2{} return &FSM{}
} }
func (m *fsmManager) newFSMActive() *FSM2 { func (m *fsmManager) newFSMActive() *FSM {
return &FSM2{} return &FSM{}
} }
...@@ -8,10 +8,10 @@ import ( ...@@ -8,10 +8,10 @@ import (
) )
type openConfirmState struct { type openConfirmState struct {
fsm *FSM2 fsm *FSM
} }
func newOpenConfirmState(fsm *FSM2) *openConfirmState { func newOpenConfirmState(fsm *FSM) *openConfirmState {
return &openConfirmState{ return &openConfirmState{
fsm: fsm, fsm: fsm,
} }
......
...@@ -10,10 +10,10 @@ import ( ...@@ -10,10 +10,10 @@ import (
) )
type openSentState struct { type openSentState struct {
fsm *FSM2 fsm *FSM
} }
func newOpenSentState(fsm *FSM2) *openSentState { func newOpenSentState(fsm *FSM) *openSentState {
return &openSentState{ return &openSentState{
fsm: fsm, fsm: fsm,
} }
......
...@@ -16,7 +16,7 @@ type Peer struct { ...@@ -16,7 +16,7 @@ type Peer struct {
addr net.IP addr net.IP
peerASN uint32 peerASN uint32
localASN uint32 localASN uint32
fsms []*FSM2 fsms []*FSM
fsmsMu sync.Mutex fsmsMu sync.Mutex
rib routingtable.RouteTableClient rib routingtable.RouteTableClient
routerID uint32 routerID uint32
...@@ -30,7 +30,7 @@ type Peer struct { ...@@ -30,7 +30,7 @@ type Peer struct {
exportFilter *filter.Filter exportFilter *filter.Filter
} }
func (p *Peer) collisionHandling(callingFSM *FSM2) bool { func (p *Peer) collisionHandling(callingFSM *FSM) bool {
p.fsmsMu.Lock() p.fsmsMu.Lock()
defer p.fsmsMu.Unlock() defer p.fsmsMu.Unlock()
...@@ -88,7 +88,7 @@ func NewPeer(c config.Peer, rib routingtable.RouteTableClient, server *BGPServer ...@@ -88,7 +88,7 @@ func NewPeer(c config.Peer, rib routingtable.RouteTableClient, server *BGPServer
addr: c.PeerAddress, addr: c.PeerAddress,
peerASN: c.PeerAS, peerASN: c.PeerAS,
localASN: c.LocalAS, localASN: c.LocalAS,
fsms: make([]*FSM2, 0), fsms: make([]*FSM, 0),
rib: rib, rib: rib,
addPathSend: c.AddPathSend, addPathSend: c.AddPathSend,
addPathRecv: c.AddPathRecv, addPathRecv: c.AddPathRecv,
......
...@@ -10,7 +10,7 @@ import ( ...@@ -10,7 +10,7 @@ import (
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
) )
func pathAttribues(p *route.Path, fsm *FSM2) (*packet.PathAttribute, error) { func pathAttribues(p *route.Path, fsm *FSM) (*packet.PathAttribute, error) {
asPathPA, err := packet.ParseASPathStr(strings.TrimRight(fmt.Sprintf("%d %s", fsm.peer.localASN, p.BGPPath.ASPath), " ")) asPathPA, err := packet.ParseASPathStr(strings.TrimRight(fmt.Sprintf("%d %s", fsm.peer.localASN, p.BGPPath.ASPath), " "))
if err != nil { if err != nil {
return nil, fmt.Errorf("Unable to parse AS path: %v", err) return nil, fmt.Errorf("Unable to parse AS path: %v", err)
......
...@@ -15,11 +15,11 @@ import ( ...@@ -15,11 +15,11 @@ import (
// UpdateSender converts table changes into BGP update messages // UpdateSender converts table changes into BGP update messages
type UpdateSender struct { type UpdateSender struct {
routingtable.ClientManager routingtable.ClientManager
fsm *FSM2 fsm *FSM
iBGP bool iBGP bool
} }
func newUpdateSender(fsm *FSM2) *UpdateSender { func newUpdateSender(fsm *FSM) *UpdateSender {
return &UpdateSender{ return &UpdateSender{
fsm: fsm, fsm: fsm,
iBGP: fsm.peer.localASN == fsm.peer.peerASN, iBGP: fsm.peer.localASN == fsm.peer.peerASN,
......
...@@ -12,11 +12,11 @@ import ( ...@@ -12,11 +12,11 @@ import (
// UpdateSenderAddPath converts table changes into BGP update messages with add path // UpdateSenderAddPath converts table changes into BGP update messages with add path
type UpdateSenderAddPath struct { type UpdateSenderAddPath struct {
routingtable.ClientManager routingtable.ClientManager
fsm *FSM2 fsm *FSM
iBGP bool iBGP bool
} }
func newUpdateSenderAddPath(fsm *FSM2) *UpdateSenderAddPath { func newUpdateSenderAddPath(fsm *FSM) *UpdateSenderAddPath {
return &UpdateSenderAddPath{ return &UpdateSenderAddPath{
fsm: fsm, fsm: fsm,
iBGP: fsm.peer.localASN == fsm.peer.peerASN, iBGP: fsm.peer.localASN == fsm.peer.peerASN,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment