From c8e54e7f8a2a49c8c035d5becf33b21fc0babf25 Mon Sep 17 00:00:00 2001 From: Donatas Abraitis Date: Mon, 18 Oct 2021 10:05:04 +0300 Subject: tests: Check if ValidateOpenMsg() works agains router-id validation Signed-off-by: Donatas Abraitis --- pkg/server/fsm_test.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'pkg/server') 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() } -- cgit v1.2.3