From 12bb31c82d463ef50ea1eef692d580af453e57b7 Mon Sep 17 00:00:00 2001
From: Oliver Herms <oliver.herms@exaring.de>
Date: Wed, 16 May 2018 15:36:31 +0200
Subject: [PATCH] Cleanup

---
 protocols/bgp/packet/decoder.go                |  1 -
 protocols/bgp/server/update_sender.go          |  9 ++++++---
 protocols/bgp/server/update_sender_add_path.go |  7 +++++--
 routingtable/locRIB/loc_rib.go                 | 12 ------------
 4 files changed, 11 insertions(+), 18 deletions(-)

diff --git a/protocols/bgp/packet/decoder.go b/protocols/bgp/packet/decoder.go
index a0179812..961789b3 100644
--- a/protocols/bgp/packet/decoder.go
+++ b/protocols/bgp/packet/decoder.go
@@ -182,7 +182,6 @@ func decodeOptParams(buf *bytes.Buffer, optParmLen uint8) ([]OptParam, error) {
 
 		read += 2
 
-		fmt.Printf("Type: %d\n", o.Type)
 		switch o.Type {
 		case CapabilitiesParamType:
 			caps, err := decodeCapabilities(buf, o.Length)
diff --git a/protocols/bgp/server/update_sender.go b/protocols/bgp/server/update_sender.go
index 07af48dd..95dded6f 100644
--- a/protocols/bgp/server/update_sender.go
+++ b/protocols/bgp/server/update_sender.go
@@ -11,6 +11,7 @@ import (
 	"github.com/bio-routing/bio-rd/routingtable"
 )
 
+// UpdateSender converts table changes into BGP update messages
 type UpdateSender struct {
 	routingtable.ClientManager
 	fsm *FSM
@@ -22,8 +23,8 @@ func newUpdateSender(fsm *FSM) *UpdateSender {
 	}
 }
 
+// AddPath serializes a new path and sends out a BGP update message
 func (u *UpdateSender) AddPath(pfx net.Prefix, p *route.Path) error {
-	fmt.Printf("SENDING AN BGP UPDATE\n")
 	asPathPA, err := packet.ParseASPathStr(fmt.Sprintf("%d %s", u.fsm.localASN, p.BGPPath.ASPath))
 	if err != nil {
 		return fmt.Errorf("Unable to parse AS path: %v", err)
@@ -53,7 +54,7 @@ func (u *UpdateSender) AddPath(pfx net.Prefix, p *route.Path) error {
 		log.Errorf("Unable to serialize BGP Update: %v", err)
 		return nil
 	}
-	fmt.Printf("Sending Update: %v\n", updateBytes)
+
 	_, err = u.fsm.con.Write(updateBytes)
 	if err != nil {
 		return fmt.Errorf("Failed sending Update: %v", err)
@@ -61,12 +62,14 @@ func (u *UpdateSender) AddPath(pfx net.Prefix, p *route.Path) error {
 	return nil
 }
 
+// RemovePath withdraws prefix `pfx` from a peer
 func (u *UpdateSender) RemovePath(pfx net.Prefix, p *route.Path) bool {
 	log.Warningf("BGP Update Sender: RemovePath not implemented")
 	return false
 }
 
+// UpdateNewClient does nothing
 func (u *UpdateSender) UpdateNewClient(client routingtable.RouteTableClient) error {
-	log.Warningf("BGP Update Sender: RemovePath not implemented")
+	log.Warningf("BGP Update Sender: UpdateNewClient() not supported")
 	return nil
 }
diff --git a/protocols/bgp/server/update_sender_add_path.go b/protocols/bgp/server/update_sender_add_path.go
index fc7fd0a7..c4fe7de5 100644
--- a/protocols/bgp/server/update_sender_add_path.go
+++ b/protocols/bgp/server/update_sender_add_path.go
@@ -11,6 +11,7 @@ import (
 	"github.com/bio-routing/bio-rd/routingtable"
 )
 
+// UpdateSenderAddPath converts table changes into BGP update messages with add path
 type UpdateSenderAddPath struct {
 	routingtable.ClientManager
 	fsm *FSM
@@ -22,8 +23,8 @@ func newUpdateSenderAddPath(fsm *FSM) *UpdateSenderAddPath {
 	}
 }
 
+// AddPath serializes a new path and sends out a BGP update message
 func (u *UpdateSenderAddPath) AddPath(pfx net.Prefix, p *route.Path) error {
-	fmt.Printf("SENDING AN BGP UPDATE WITH ADD PATH TO %s\n", u.fsm.remote.String())
 	asPathPA, err := packet.ParseASPathStr(fmt.Sprintf("%d %s", u.fsm.localASN, p.BGPPath.ASPath))
 	if err != nil {
 		return fmt.Errorf("Unable to parse AS path: %v", err)
@@ -54,7 +55,7 @@ func (u *UpdateSenderAddPath) AddPath(pfx net.Prefix, p *route.Path) error {
 		log.Errorf("Unable to serialize BGP Update: %v", err)
 		return nil
 	}
-	fmt.Printf("Sending Update: %v\n", updateBytes)
+
 	_, err = u.fsm.con.Write(updateBytes)
 	if err != nil {
 		return fmt.Errorf("Failed sending Update: %v", err)
@@ -62,11 +63,13 @@ func (u *UpdateSenderAddPath) AddPath(pfx net.Prefix, p *route.Path) error {
 	return nil
 }
 
+// RemovePath withdraws prefix `pfx` from a peer
 func (u *UpdateSenderAddPath) RemovePath(pfx net.Prefix, p *route.Path) bool {
 	log.Warningf("BGP Update Sender: RemovePath not implemented")
 	return false
 }
 
+// UpdateNewClient does nothing
 func (u *UpdateSenderAddPath) UpdateNewClient(client routingtable.RouteTableClient) error {
 	log.Warningf("BGP Update Sender: RemovePath not implemented")
 	return nil
diff --git a/routingtable/locRIB/loc_rib.go b/routingtable/locRIB/loc_rib.go
index 8d8632c0..dd06e100 100644
--- a/routingtable/locRIB/loc_rib.go
+++ b/routingtable/locRIB/loc_rib.go
@@ -59,12 +59,8 @@ func (a *LocRIB) AddPath(pfx net.Prefix, p *route.Path) error {
 	}
 
 	r.PathSelection()
-
 	newRoute := r.Copy()
 
-	fmt.Printf("NEW: %v\n", newRoute.Paths())
-	fmt.Printf("OLD: %v\n", oldRoute.Paths())
-
 	a.propagateChanges(oldRoute, newRoute)
 	return nil
 }
@@ -86,9 +82,6 @@ func (a *LocRIB) RemovePath(pfx net.Prefix, p *route.Path) bool {
 	r = a.rt.Get(pfx)
 	newRoute := r.Copy()
 
-	fmt.Printf("NEW: %v\n", newRoute.Paths())
-	fmt.Printf("OLD: %v\n", oldRoute.Paths())
-
 	a.propagateChanges(oldRoute, newRoute)
 	return true
 }
@@ -99,7 +92,6 @@ func (a *LocRIB) propagateChanges(oldRoute *route.Route, newRoute *route.Route)
 }
 
 func (a *LocRIB) addPathsToClients(oldRoute *route.Route, newRoute *route.Route) {
-	fmt.Printf("LocRIB: Updating %d clients\n", len(a.ClientManager.Clients()))
 	for _, client := range a.ClientManager.Clients() {
 		opts := a.ClientManager.GetOptions(client)
 		oldMaxPaths := opts.GetMaxPaths(oldRoute.ECMPPathCount())
@@ -108,11 +100,7 @@ func (a *LocRIB) addPathsToClients(oldRoute *route.Route, newRoute *route.Route)
 		oldPathsLimit := int(math.Min(float64(oldMaxPaths), float64(len(oldRoute.Paths()))))
 		newPathsLimit := int(math.Min(float64(newMaxPaths), float64(len(newRoute.Paths()))))
 
-		fmt.Printf("oldPathsLimit: %v\n", oldPathsLimit)
-		fmt.Printf("newPathsLimit: %v\n", newPathsLimit)
-
 		advertise := route.PathsDiff(newRoute.Paths()[0:newPathsLimit], oldRoute.Paths()[0:oldPathsLimit])
-		fmt.Printf("ADVERTISING PATHS %v TO CLIENTS\n", advertise)
 
 		for _, p := range advertise {
 			client.AddPath(newRoute.Prefix(), p)
-- 
GitLab