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
1eff34e0
Commit
1eff34e0
authored
6 years ago
by
Daniel Czerwonk
Browse files
Options
Downloads
Patches
Plain Diff
added asn4 cap to open message
parent
433f77dc
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/bgp/server/fsm.go
+19
-7
19 additions, 7 deletions
protocols/bgp/server/fsm.go
protocols/bgp/server/fsm_test.go
+98
-0
98 additions, 0 deletions
protocols/bgp/server/fsm_test.go
protocols/bgp/server/peer.go
+36
-17
36 additions, 17 deletions
protocols/bgp/server/peer.go
with
153 additions
and
24 deletions
protocols/bgp/server/fsm
2
.go
→
protocols/bgp/server/fsm.go
+
19
−
7
View file @
1eff34e0
...
...
@@ -219,13 +219,7 @@ func (fsm *FSM) resetConnectRetryCounter() {
}
func
(
fsm
*
FSM
)
sendOpen
()
error
{
msg
:=
packet
.
SerializeOpenMsg
(
&
packet
.
BGPOpen
{
Version
:
BGPVersion
,
ASN
:
uint16
(
fsm
.
peer
.
localASN
),
HoldTime
:
uint16
(
fsm
.
peer
.
holdTime
/
time
.
Second
),
BGPIdentifier
:
fsm
.
peer
.
server
.
routerID
,
OptParams
:
fsm
.
peer
.
optOpenParams
,
})
msg
:=
packet
.
SerializeOpenMsg
(
fsm
.
openMessage
())
_
,
err
:=
fsm
.
con
.
Write
(
msg
)
if
err
!=
nil
{
...
...
@@ -235,6 +229,24 @@ func (fsm *FSM) sendOpen() error {
return
nil
}
func
(
fsm
*
FSM
)
openMessage
()
*
packet
.
BGPOpen
{
return
&
packet
.
BGPOpen
{
Version
:
BGPVersion
,
ASN
:
fsm
.
local16BitASN
(),
HoldTime
:
uint16
(
fsm
.
peer
.
holdTime
/
time
.
Second
),
BGPIdentifier
:
fsm
.
peer
.
routerID
,
OptParams
:
fsm
.
peer
.
optOpenParams
,
}
}
func
(
fsm
*
FSM
)
local16BitASN
()
uint16
{
if
fsm
.
peer
.
localASN
>
uint32
(
^
uint16
(
0
))
{
return
packet
.
ASTransASN
}
return
uint16
(
fsm
.
peer
.
localASN
)
}
func
(
fsm
*
FSM
)
sendNotification
(
errorCode
uint8
,
errorSubCode
uint8
)
error
{
msg
:=
packet
.
SerializeNotificationMsg
(
&
packet
.
BGPNotification
{})
...
...
This diff is collapsed.
Click to expand it.
protocols/bgp/server/fsm_test.go
0 → 100644
+
98
−
0
View file @
1eff34e0
package
server
import
(
"testing"
"time"
"github.com/bio-routing/bio-rd/protocols/bgp/packet"
"github.com/stretchr/testify/assert"
)
func
TestOpenMessage
(
t
*
testing
.
T
)
{
tests
:=
[]
struct
{
name
string
localASN
uint32
holdTime
time
.
Duration
routerID
uint32
expected
packet
.
BGPOpen
}{
{
name
:
"16bit ASN"
,
localASN
:
12345
,
holdTime
:
time
.
Duration
(
30
*
time
.
Second
),
routerID
:
1
,
expected
:
packet
.
BGPOpen
{
ASN
:
12345
,
BGPIdentifier
:
1
,
HoldTime
:
30
,
OptParams
:
[]
packet
.
OptParam
{
packet
.
OptParam
{
Type
:
packet
.
CapabilitiesParamType
,
Value
:
packet
.
Capabilities
{
packet
.
Capability
{
Code
:
65
,
Value
:
packet
.
ASN4Capability
{
ASN4
:
12345
,
},
},
},
},
},
Version
:
4
,
},
},
{
name
:
"32bit ASN"
,
localASN
:
202739
,
holdTime
:
time
.
Duration
(
30
*
time
.
Second
),
routerID
:
1
,
expected
:
packet
.
BGPOpen
{
ASN
:
23456
,
BGPIdentifier
:
1
,
HoldTime
:
30
,
OptParams
:
[]
packet
.
OptParam
{
packet
.
OptParam
{
Type
:
packet
.
CapabilitiesParamType
,
Value
:
packet
.
Capabilities
{
packet
.
Capability
{
Code
:
65
,
Value
:
packet
.
ASN4Capability
{
ASN4
:
202739
,
},
},
},
},
},
Version
:
4
,
},
},
}
for
_
,
test
:=
range
tests
{
t
.
Run
(
test
.
name
,
func
(
t
*
testing
.
T
)
{
p
:=
Peer
{
localASN
:
test
.
localASN
,
holdTime
:
test
.
holdTime
,
routerID
:
test
.
routerID
,
optOpenParams
:
[]
packet
.
OptParam
{
packet
.
OptParam
{
Type
:
packet
.
CapabilitiesParamType
,
Value
:
packet
.
Capabilities
{
packet
.
Capability
{
Code
:
65
,
Value
:
packet
.
ASN4Capability
{
ASN4
:
test
.
localASN
,
},
},
},
},
},
}
fsm
:=
newFSM2
(
&
p
)
msg
:=
fsm
.
openMessage
()
assert
.
Equal
(
t
,
&
test
.
expected
,
msg
)
})
}
}
This diff is collapsed.
Click to expand it.
protocols/bgp/server/peer.go
+
36
−
17
View file @
1eff34e0
...
...
@@ -87,7 +87,6 @@ func NewPeer(c config.Peer, rib routingtable.RouteTableClient, server *BGPServer
server
:
server
,
addr
:
c
.
PeerAddress
,
peerASN
:
c
.
PeerAS
,
localASN
:
c
.
LocalAS
,
fsms
:
make
([]
*
FSM
,
0
),
rib
:
rib
,
addPathSend
:
c
.
AddPathSend
,
...
...
@@ -103,24 +102,12 @@ func NewPeer(c config.Peer, rib routingtable.RouteTableClient, server *BGPServer
caps
:=
make
([]
packet
.
Capability
,
0
)
addPath
:=
uint8
(
0
)
if
c
.
AddPathRecv
{
addPath
+=
packet
.
AddPathReceive
}
if
!
c
.
AddPathSend
.
BestOnly
{
addPath
+=
packet
.
AddPathSend
addPathEnabled
,
addPathCap
:=
handleAddPathCapability
(
c
)
if
addPathEnabled
{
caps
=
append
(
caps
,
addPathCap
)
}
if
addPath
>
0
{
caps
=
append
(
caps
,
packet
.
Capability
{
Code
:
packet
.
AddPathCapabilityCode
,
Value
:
packet
.
AddPathCapability
{
AFI
:
packet
.
IPv4AFI
,
SAFI
:
packet
.
UnicastSAFI
,
SendReceive
:
addPath
,
},
})
}
caps
=
append
(
caps
,
asn4Capability
(
c
))
for
_
,
cap
:=
range
caps
{
p
.
optOpenParams
=
append
(
p
.
optOpenParams
,
packet
.
OptParam
{
...
...
@@ -132,6 +119,38 @@ func NewPeer(c config.Peer, rib routingtable.RouteTableClient, server *BGPServer
return
p
,
nil
}
func
asn4Capability
(
c
config
.
Peer
)
packet
.
Capability
{
return
packet
.
Capability
{
Code
:
packet
.
ASN4CapabilityCode
,
Value
:
packet
.
ASN4Capability
{
ASN4
:
c
.
LocalAS
,
},
}
}
func
handleAddPathCapability
(
c
config
.
Peer
)
(
bool
,
packet
.
Capability
)
{
addPath
:=
uint8
(
0
)
if
c
.
AddPathRecv
{
addPath
+=
packet
.
AddPathReceive
}
if
!
c
.
AddPathSend
.
BestOnly
{
addPath
+=
packet
.
AddPathSend
}
if
addPath
==
0
{
return
false
,
packet
.
Capability
{}
}
return
true
,
packet
.
Capability
{
Code
:
packet
.
AddPathCapabilityCode
,
Value
:
packet
.
AddPathCapability
{
AFI
:
packet
.
IPv4AFI
,
SAFI
:
packet
.
UnicastSAFI
,
SendReceive
:
addPath
,
},
}
}
func
filterOrDefault
(
f
*
filter
.
Filter
)
*
filter
.
Filter
{
if
f
!=
nil
{
return
f
...
...
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