diff options
author | Satoshi Fujimoto <satoshi.fujimoto7@gmail.com> | 2017-09-26 16:05:49 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2017-09-29 15:05:43 +0900 |
commit | ba395457213966dd8a49b5836b2341434f4025b9 (patch) | |
tree | e86f3ade4e0a24fa96dd610025bdbeb574599db0 /packet/bgp/bgp_test.go | |
parent | f70827b68c190e3793ace65f116fef8c7c36e752 (diff) |
packet/bgp: Add Unit Tests for Revised Error Handling
Signed-off-by: Satoshi Fujimoto <satoshi.fujimoto7@gmail.com>
Diffstat (limited to 'packet/bgp/bgp_test.go')
-rw-r--r-- | packet/bgp/bgp_test.go | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/packet/bgp/bgp_test.go b/packet/bgp/bgp_test.go index 2c1ead8e..7afda3bc 100644 --- a/packet/bgp/bgp_test.go +++ b/packet/bgp/bgp_test.go @@ -153,6 +153,84 @@ func Test_RouteTargetMembershipNLRIString(t *testing.T) { } +func Test_MalformedUpdateMsg(t *testing.T) { + assert := assert.New(t) + + // Invalid AGGREGATOR + bufin := []byte{ + 0x00, 0x00, // Withdraws(0) + 0x00, 0x16, // Attrs Len(22) + 0xc0, 0x07, 0x05, // Flag, Type(7), Length(5) + 0x00, 0x00, 0x00, 0x64, // aggregator - invalid length + 0x00, + 0x40, 0x01, 0x01, 0x00, // Attr(ORIGIN) + 0x40, 0x03, 0x04, 0xc0, // Attr(NEXT_HOP) + 0xa8, 0x01, 0x64, + 0x40, 0x02, 0x00, // Attr(AS_PATH) + } + + u := &BGPUpdate{} + err := u.DecodeFromBytes(bufin) + assert.Error(err) + assert.Equal(ERROR_HANDLING_ATTRIBUTE_DISCARD, err.(*MessageError).ErrorHandling) + + // Invalid MP_REACH_NLRI + bufin = []byte{ + 0x00, 0x00, // Withdraws(0) + 0x00, 0x27, // Attrs Len(39) + 0x80, 0x0e, 0x1d, // Flag, Type(14), Length(29) + 0x00, 0x02, 0x01, // afi(2), safi(1) + 0x0f, 0x00, 0x00, 0x00, // nexthop - invalid nexthop length + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0xff, + 0xff, 0x0a, 0x00, 0x00, + 0x00, // SNPA(0) + 0x40, 0x20, 0x01, 0x0d, // NLRI + 0xb8, 0x00, 0x01, 0x00, + 0x00, + 0x40, 0x01, 0x01, 0x00, // Attr(ORIGIN) + 0x40, 0x02, 0x00, // Attr(AS_PATH) + } + + err = u.DecodeFromBytes(bufin) + assert.Error(err) + assert.Equal(ERROR_HANDLING_AFISAFI_DISABLE, err.(*MessageError).ErrorHandling) + + // Invalid flag + bufin = []byte{ + 0x00, 0x00, // Withdraws(0) + 0x00, 0x0e, // Attrs Len(14) + 0xc0, 0x01, 0x01, 0x00, // Attr(ORIGIN) - invalid flag + 0x40, 0x03, 0x04, 0xc0, // Attr(NEXT_HOP) + 0xa8, 0x01, 0x64, + 0x40, 0x02, 0x00, // Attr(AS_PATH) + } + + err = u.DecodeFromBytes(bufin) + assert.Error(err) + assert.Equal(ERROR_HANDLING_TREAT_AS_WITHDRAW, err.(*MessageError).ErrorHandling) + + // Invalid AGGREGATOR and MULTI_EXIT_DESC + bufin = []byte{ + 0x00, 0x00, // Withdraws(0) + 0x00, 0x1e, // Attrs Len(30) + 0xc0, 0x07, 0x05, 0x00, // Attr(AGGREGATOR) - invalid length + 0x00, 0x00, 0x64, 0x00, + 0x80, 0x04, 0x05, 0x00, // Attr(MULTI_EXIT_DESC) - invalid length + 0x00, 0x00, 0x00, 0x64, + 0x40, 0x01, 0x01, 0x00, // Attr(ORIGIN) + 0x40, 0x02, 0x00, // Attr(AS_PATH) + 0x40, 0x03, 0x04, 0xc0, // Attr(NEXT_HOP) + 0xa8, 0x01, 0x64, + 0x20, 0xc8, 0xc8, 0xc8, // NLRI + 0xc8, + } + + err = u.DecodeFromBytes(bufin) + assert.Error(err) + assert.Equal(ERROR_HANDLING_TREAT_AS_WITHDRAW, err.(*MessageError).ErrorHandling) +} + func Test_RFC5512(t *testing.T) { assert := assert.New(t) |