Skip to content

Commit

Permalink
tests: Check if ValidateOpenMsg() works agains router-id validation
Browse files Browse the repository at this point in the history
Signed-off-by: Donatas Abraitis <[email protected]>
  • Loading branch information
ton31337 authored and fujita committed Oct 18, 2021
1 parent d3ee05a commit c8e54e7
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions pkg/server/fsm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}),
Expand Down Expand Up @@ -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()
}

0 comments on commit c8e54e7

Please sign in to comment.