From 5c028ffbff73899a302dda6929bb5db5ad6789f3 Mon Sep 17 00:00:00 2001
From: Oliver Herms <oliver.herms@exaring.de>
Date: Wed, 20 Jun 2018 13:42:48 +0200
Subject: [PATCH] Cleanup

---
 protocols/bgp/server/fsm2.go                  | 23 -------------------
 protocols/bgp/server/fsm_active.go            |  3 ---
 protocols/bgp/server/fsm_connect.go           |  2 --
 protocols/bgp/server/fsm_established.go       |  5 +++-
 protocols/bgp/server/fsm_idle.go              |  2 --
 protocols/bgp/server/fsm_open_sent.go         |  1 -
 protocols/bgp/server/server.go                |  1 +
 .../bgp/server/update_sender_add_path.go      |  2 +-
 8 files changed, 6 insertions(+), 33 deletions(-)

diff --git a/protocols/bgp/server/fsm2.go b/protocols/bgp/server/fsm2.go
index 86725c68..b365e41c 100644
--- a/protocols/bgp/server/fsm2.go
+++ b/protocols/bgp/server/fsm2.go
@@ -74,7 +74,6 @@ type FSM2 struct {
 
 // NewPassiveFSM2 initiates a new passive FSM
 func NewPassiveFSM2(peer *Peer, con *net.TCPConn) *FSM2 {
-	fmt.Printf("NewPassiveFSM2\n")
 	fsm := newFSM2(peer)
 	fsm.con = con
 	fsm.state = newIdleState(fsm)
@@ -83,7 +82,6 @@ func NewPassiveFSM2(peer *Peer, con *net.TCPConn) *FSM2 {
 
 // NewActiveFSM2 initiates a new passive FSM
 func NewActiveFSM2(peer *Peer) *FSM2 {
-	fmt.Printf("NewActiveFSM2\n")
 	fsm := newFSM2(peer)
 	fsm.active = true
 	fsm.state = newIdleState(fsm)
@@ -116,7 +114,6 @@ func (fsm *FSM2) activate() {
 }
 
 func (fsm *FSM2) run() {
-	//fmt.Printf("Starting FSM\n")
 	next, reason := fsm.state.run()
 	for {
 		newState := stateName(next)
@@ -135,13 +132,10 @@ func (fsm *FSM2) run() {
 			return
 		}
 
-		//fmt.Printf("Aquiring lock...\n")
 		fsm.stateMu.Lock()
 		fsm.state = next
-		//fmt.Printf("Releasing lock...\n")
 		fsm.stateMu.Unlock()
 
-		//fmt.Printf("Running new state\n")
 		next, reason = fsm.state.run()
 	}
 }
@@ -172,12 +166,9 @@ func (fsm *FSM2) cease() {
 }
 
 func (fsm *FSM2) tcpConnector() error {
-	fmt.Printf("TCP CONNECTOR STARTED\n")
 	for {
-		//fmt.Printf("READING FROM fsm.initiateCon\n")
 		select {
 		case <-fsm.initiateCon:
-			fmt.Printf("Initiating connection to %s\n", fsm.peer.addr.String())
 			c, err := net.DialTCP("tcp", &net.TCPAddr{IP: fsm.local}, &net.TCPAddr{IP: fsm.peer.addr, Port: BGPPORT})
 			if err != nil {
 				select {
@@ -188,7 +179,6 @@ func (fsm *FSM2) tcpConnector() error {
 				}
 			}
 
-			//fmt.Printf("GOT CONNECTION!\n")
 			select {
 			case fsm.conCh <- c:
 				continue
@@ -210,21 +200,12 @@ func (fsm *FSM2) msgReceiver() error {
 		if err != nil {
 			fsm.msgRecvFailCh <- err
 			return nil
-
-			/*select {
-			case fsm.msgRecvFailCh <- msgRecvErr{err: err, con: c}:
-				continue
-			case <-time.NewTimer(time.Second * 60).C:
-				return nil
-			}*/
 		}
-		fmt.Printf("Message received for %s: %v\n", fsm.con.RemoteAddr().String(), msg[18])
 		fsm.msgRecvCh <- msg
 	}
 }
 
 func (fsm *FSM2) startConnectRetryTimer() {
-	fmt.Printf("Initializing connectRetryTimer: %d\n", fsm.connectRetryTime)
 	fsm.connectRetryTimer = time.NewTimer(fsm.connectRetryTime)
 }
 
@@ -239,8 +220,6 @@ func (fsm *FSM2) resetConnectRetryCounter() {
 }
 
 func (fsm *FSM2) sendOpen() error {
-	fmt.Printf("Sending OPEN Message to %s\n", fsm.con.RemoteAddr().String())
-
 	msg := packet.SerializeOpenMsg(&packet.BGPOpen{
 		Version:       BGPVersion,
 		AS:            uint16(fsm.peer.localASN),
@@ -258,7 +237,6 @@ func (fsm *FSM2) sendOpen() error {
 }
 
 func (fsm *FSM2) sendNotification(errorCode uint8, errorSubCode uint8) error {
-	fmt.Printf("Sending NOTIFICATION Message to %s\n", fsm.con.RemoteAddr().String())
 	msg := packet.SerializeNotificationMsg(&packet.BGPNotification{})
 
 	_, err := fsm.con.Write(msg)
@@ -270,7 +248,6 @@ func (fsm *FSM2) sendNotification(errorCode uint8, errorSubCode uint8) error {
 }
 
 func (fsm *FSM2) sendKeepalive() error {
-	fmt.Printf("Sending KEEPALIVE to %s\n", fsm.con.RemoteAddr().String())
 	msg := packet.SerializeKeepaliveMsg()
 
 	_, err := fsm.con.Write(msg)
diff --git a/protocols/bgp/server/fsm_active.go b/protocols/bgp/server/fsm_active.go
index 2b269242..f8fa6b39 100644
--- a/protocols/bgp/server/fsm_active.go
+++ b/protocols/bgp/server/fsm_active.go
@@ -17,7 +17,6 @@ func newActiveState(fsm *FSM2) *activeState {
 }
 
 func (s activeState) run() (state, string) {
-	fmt.Printf("THIS IS ACTIVE STATE\n")
 	for {
 		select {
 		case e := <-s.fsm.eventCh:
@@ -32,7 +31,6 @@ func (s activeState) run() (state, string) {
 		case <-s.fsm.connectRetryTimer.C:
 			return s.connectRetryTimerExpired()
 		case c := <-s.fsm.conCh:
-			fmt.Printf("Received a connection in active state\n")
 			return s.connectionSuccess(c)
 		}
 	}
@@ -66,6 +64,5 @@ func (s *activeState) connectionSuccess(con net.Conn) (state, string) {
 		return newIdleState(s.fsm), fmt.Sprintf("Sending OPEN message failed: %v", err)
 	}
 	s.fsm.holdTimer = time.NewTimer(time.Minute * 4)
-	fmt.Printf("Next state: OpenSent!\n")
 	return newOpenSentState(s.fsm), "Sent OPEN message"
 }
diff --git a/protocols/bgp/server/fsm_connect.go b/protocols/bgp/server/fsm_connect.go
index eac14594..cc9ce060 100644
--- a/protocols/bgp/server/fsm_connect.go
+++ b/protocols/bgp/server/fsm_connect.go
@@ -38,7 +38,6 @@ func (s connectState) run() (state, string) {
 }
 
 func (s *connectState) connectionSuccess(c net.Conn) (state, string) {
-	fmt.Printf("GOT A TCP CONNECTION!\n")
 	s.fsm.con = c
 	stopTimer(s.fsm.connectRetryTimer)
 	err := s.fsm.sendOpen()
@@ -50,7 +49,6 @@ func (s *connectState) connectionSuccess(c net.Conn) (state, string) {
 }
 
 func (s *connectState) connectRetryTimerExpired() {
-	fmt.Printf("Connect retry timer expired\n")
 	s.fsm.resetConnectRetryTimer()
 	s.fsm.tcpConnect()
 }
diff --git a/protocols/bgp/server/fsm_established.go b/protocols/bgp/server/fsm_established.go
index faebad99..02f5ac24 100644
--- a/protocols/bgp/server/fsm_established.go
+++ b/protocols/bgp/server/fsm_established.go
@@ -201,11 +201,14 @@ func (s *establishedState) updates(u *packet.BGPUpdate) {
 			case packet.MEDAttr:
 				path.BGPPath.MED = pa.Value.(uint32)
 			case packet.NextHopAttr:
-				fmt.Printf("RECEIVED NEXT_HOP: %d\n", pa.Value.(uint32))
 				path.BGPPath.NextHop = pa.Value.(uint32)
 			case packet.ASPathAttr:
 				path.BGPPath.ASPath = pa.ASPathString()
 				path.BGPPath.ASPathLen = pa.ASPathLen()
+			case packet.CommunitiesAttr:
+				path.BGPPath.Communities = pa.CommunityString()
+			case packet.LargeCommunitiesAttr:
+				path.BGPPath.LargeCommunities = pa.LargeCommunityString()
 			}
 		}
 		s.fsm.adjRIBIn.AddPath(pfx, path)
diff --git a/protocols/bgp/server/fsm_idle.go b/protocols/bgp/server/fsm_idle.go
index 87d57f79..ce4cc105 100644
--- a/protocols/bgp/server/fsm_idle.go
+++ b/protocols/bgp/server/fsm_idle.go
@@ -1,7 +1,6 @@
 package server
 
 import (
-	"fmt"
 	"time"
 )
 
@@ -23,7 +22,6 @@ func (s idleState) run() (state, string) {
 	}
 	for {
 		event := <-s.fsm.eventCh
-		fmt.Printf("Event: %d\n", event)
 		switch event {
 		case ManualStart:
 			return s.manualStart()
diff --git a/protocols/bgp/server/fsm_open_sent.go b/protocols/bgp/server/fsm_open_sent.go
index bb29ef6f..5504a525 100644
--- a/protocols/bgp/server/fsm_open_sent.go
+++ b/protocols/bgp/server/fsm_open_sent.go
@@ -14,7 +14,6 @@ type openSentState struct {
 }
 
 func newOpenSentState(fsm *FSM2) *openSentState {
-	fmt.Printf("newOpenSentState\n")
 	return &openSentState{
 		fsm: fsm,
 	}
diff --git a/protocols/bgp/server/server.go b/protocols/bgp/server/server.go
index 6cd2de5e..bd1f662b 100644
--- a/protocols/bgp/server/server.go
+++ b/protocols/bgp/server/server.go
@@ -60,6 +60,7 @@ func (b *BGPServer) Start(c *config.Global) error {
 
 func (b *BGPServer) incomingConnectionWorker() {
 	for {
+		// Disabled. We're active only for now.
 		/*c := <-b.acceptCh
 		fmt.Printf("Incoming connection!\n")
 		fmt.Printf("Connection from: %v\n", c.RemoteAddr())
diff --git a/protocols/bgp/server/update_sender_add_path.go b/protocols/bgp/server/update_sender_add_path.go
index e777180c..7d22bcaa 100644
--- a/protocols/bgp/server/update_sender_add_path.go
+++ b/protocols/bgp/server/update_sender_add_path.go
@@ -50,6 +50,6 @@ func (u *UpdateSenderAddPath) RemovePath(pfx net.Prefix, p *route.Path) bool {
 
 // UpdateNewClient does nothing
 func (u *UpdateSenderAddPath) UpdateNewClient(client routingtable.RouteTableClient) error {
-	log.Warningf("BGP Update Sender: RemovePath not implemented")
+	log.Warningf("BGP Update Sender: UpdateNewClient not implemented")
 	return nil
 }
-- 
GitLab