diff options
author | Donatas Abraitis <donatas.abraitis@gmail.com> | 2021-10-18 10:05:04 +0300 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@gmail.com> | 2021-10-18 16:58:11 +0900 |
commit | c8e54e7f8a2a49c8c035d5becf33b21fc0babf25 (patch) | |
tree | 1c65c97506f87028ca128cd5c24fa3eb1db8671c | |
parent | d3ee05ad24192ff0f2b876532fb6fd9776d540dd (diff) |
tests: Check if ValidateOpenMsg() works agains router-id validation
Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
-rw-r--r-- | pkg/server/fsm_test.go | 28 |
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() } |