Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
bio-rd
Manage
Activity
Members
Labels
Plan
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
danet
bio-rd
Commits
9bca195a
Commit
9bca195a
authored
6 years ago
by
Oliver Herms
Browse files
Options
Downloads
Patches
Plain Diff
Fixing magic numbers
parent
0a6c0821
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
protocols/bmp/packet/peer_down.go
+6
-1
6 additions, 1 deletion
protocols/bmp/packet/peer_down.go
protocols/bmp/server/router.go
+9
-7
9 additions, 7 deletions
protocols/bmp/server/router.go
protocols/bmp/server/server.go
+14
-11
14 additions, 11 deletions
protocols/bmp/server/server.go
with
29 additions
and
19 deletions
protocols/bmp/packet/peer_down.go
+
6
−
1
View file @
9bca195a
...
@@ -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
}
}
...
...
This diff is collapsed.
Click to expand it.
protocols/bmp/server/router.go
+
9
−
7
View file @
9bca195a
...
@@ -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
()
{
...
...
This diff is collapsed.
Click to expand it.
protocols/bmp/server/server.go
+
14
−
11
View file @
9bca195a
...
@@ -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
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment