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

Fixing magic numbers

parent 0a6c0821
No related branches found
No related tags found
No related merge requests found
...@@ -7,6 +7,11 @@ import ( ...@@ -7,6 +7,11 @@ import (
"github.com/bio-routing/bio-rd/util/decoder" "github.com/bio-routing/bio-rd/util/decoder"
) )
const (
reasonMin = 1
reasonMax = 3
)
// PeerDownNotification represents a peer down notification // PeerDownNotification represents a peer down notification
type PeerDownNotification struct { type PeerDownNotification struct {
CommonHeader *CommonHeader CommonHeader *CommonHeader
...@@ -41,7 +46,7 @@ func decodePeerDownNotification(buf *bytes.Buffer, ch *CommonHeader) (*PeerDownN ...@@ -41,7 +46,7 @@ func decodePeerDownNotification(buf *bytes.Buffer, ch *CommonHeader) (*PeerDownN
return nil, err return nil, err
} }
if p.Reason < 1 || p.Reason > 3 { if p.Reason < reasonMin || p.Reason > reasonMax {
return p, nil return p, nil
} }
......
...@@ -11,13 +11,15 @@ import ( ...@@ -11,13 +11,15 @@ import (
) )
type router struct { type router struct {
address net.IP address net.IP
port uint16 port uint16
con net.Conn con net.Conn
reconnectTime int reconnectTimeMin int
reconnectTimer *time.Timer reconnectTimeMax int
rib4 *locRIB.LocRIB reconnectTime int
rib6 *locRIB.LocRIB reconnectTimer *time.Timer
rib4 *locRIB.LocRIB
rib6 *locRIB.LocRIB
} }
func (r *router) serve() { func (r *router) serve() {
......
...@@ -9,6 +9,7 @@ import ( ...@@ -9,6 +9,7 @@ import (
"github.com/bio-routing/bio-rd/protocols/bgp/packet" "github.com/bio-routing/bio-rd/protocols/bgp/packet"
"github.com/bio-routing/bio-rd/routingtable/locRIB" "github.com/bio-routing/bio-rd/routingtable/locRIB"
"github.com/bio-routing/tflow2/convert"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
) )
...@@ -17,8 +18,9 @@ const ( ...@@ -17,8 +18,9 @@ const (
) )
type BMPServer struct { type BMPServer struct {
routers map[string]*router routers map[string]*router
routersMu sync.RWMutex routersMu sync.RWMutex
reconnectTime uint
} }
func NewServer() *BMPServer { func NewServer() *BMPServer {
...@@ -29,12 +31,13 @@ func NewServer() *BMPServer { ...@@ -29,12 +31,13 @@ func NewServer() *BMPServer {
func (b *BMPServer) AddRouter(addr net.IP, port uint16, rib4 *locRIB.LocRIB, rib6 *locRIB.LocRIB) { func (b *BMPServer) AddRouter(addr net.IP, port uint16, rib4 *locRIB.LocRIB, rib6 *locRIB.LocRIB) {
r := &router{ r := &router{
address: addr, address: addr,
port: port, port: port,
reconnectTime: 0, reconnectTimeMin: 30, // Suggested by RFC 7854
reconnectTimer: time.NewTimer(time.Duration(0)), reconnectTimeMax: 720, // Suggested by RFC 7854
rib4: rib4, reconnectTimer: time.NewTimer(time.Duration(0)),
rib6: rib6, rib4: rib4,
rib6: rib6,
} }
b.routersMu.Lock() b.routersMu.Lock()
...@@ -48,8 +51,8 @@ func (b *BMPServer) AddRouter(addr net.IP, port uint16, rib4 *locRIB.LocRIB, rib ...@@ -48,8 +51,8 @@ func (b *BMPServer) AddRouter(addr net.IP, port uint16, rib4 *locRIB.LocRIB, rib
if err != nil { if err != nil {
log.Infof("Unable to connect to BMP router: %v", err) log.Infof("Unable to connect to BMP router: %v", err)
if r.reconnectTime == 0 { if r.reconnectTime == 0 {
r.reconnectTime = 30 r.reconnectTime = r.reconnectTimeMin
} else if r.reconnectTime < 720 { } else if r.reconnectTime < r.reconnectTimeMax {
r.reconnectTime *= 2 r.reconnectTime *= 2
} }
r.reconnectTimer = time.NewTimer(time.Second * time.Duration(r.reconnectTime)) r.reconnectTimer = time.NewTimer(time.Second * time.Duration(r.reconnectTime))
...@@ -70,7 +73,7 @@ func recvMsg(c net.Conn) (msg []byte, err error) { ...@@ -70,7 +73,7 @@ func recvMsg(c net.Conn) (msg []byte, err error) {
return nil, fmt.Errorf("Read failed: %v", err) return nil, fmt.Errorf("Read failed: %v", err)
} }
l := int(buffer[1])*256*256*256 + int(buffer[2])*256*256 + int(buffer[3])*256 + int(buffer[4]) l := convert.Uint32b(buffer[1:3])
if l > defaultBufferLen { if l > defaultBufferLen {
tmp := buffer tmp := buffer
buffer = make([]byte, l) buffer = make([]byte, l)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment