summaryrefslogtreecommitdiffhomepage
path: root/pkg/server/fsm_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/server/fsm_test.go')
-rw-r--r--pkg/server/fsm_test.go28
1 files changed, 28 insertions, 0 deletions
diff --git a/pkg/server/fsm_test.go b/pkg/server/fsm_test.go
index 240f5185..b2cab3a6 100644
--- a/pkg/server/fsm_test.go
+++ b/pkg/server/fsm_test.go
@@ -352,6 +352,24 @@ func TestCheckOwnASLoop(t *testing.T) {
assert.False(hasOwnASLoop(65200, 0, aspath))
}
+func TestBadBGPIdentifier(t *testing.T) {
+ assert := assert.New(t)
+ msg1 := openWithBadBGPIdentifier_Zero()
+ msg2 := openWithBadBGPIdentifier_Same()
+ body1 := msg1.Body.(*bgp.BGPOpen)
+ body2 := msg2.Body.(*bgp.BGPOpen)
+
+ // Test if Bad BGP Identifier notification is sent if remote router-id is 0.0.0.0.
+ peerAs, err := bgp.ValidateOpenMsg(body1, 65000, 65001, net.ParseIP("192.168.1.1"))
+ assert.Equal(int(peerAs), 0)
+ assert.Equal(uint8(bgp.BGP_ERROR_SUB_BAD_BGP_IDENTIFIER), err.(*bgp.MessageError).SubTypeCode)
+
+ // Test if Bad BGP Identifier notification is sent if remote router-id is the same for iBGP.
+ peerAs, err = bgp.ValidateOpenMsg(body2, 65000, 65000, net.ParseIP("192.168.1.1"))
+ assert.Equal(int(peerAs), 0)
+ assert.Equal(uint8(bgp.BGP_ERROR_SUB_BAD_BGP_IDENTIFIER), err.(*bgp.MessageError).SubTypeCode)
+}
+
func makePeerAndHandler() (*peer, *fsmHandler) {
p := &peer{
fsm: newFSM(&config.Global{}, &config.Neighbor{}),
@@ -383,6 +401,16 @@ func open() *bgp.BGPMessage {
[]bgp.OptionParameterInterface{p1, p2, p3, p4})
}
+func openWithBadBGPIdentifier_Zero() *bgp.BGPMessage {
+ return bgp.NewBGPOpenMessage(65000, 303, "0.0.0.0",
+ []bgp.OptionParameterInterface{})
+}
+
+func openWithBadBGPIdentifier_Same() *bgp.BGPMessage {
+ return bgp.NewBGPOpenMessage(65000, 303, "192.168.1.1",
+ []bgp.OptionParameterInterface{})
+}
+
func keepalive() *bgp.BGPMessage {
return bgp.NewBGPKeepAliveMessage()
}