github.com/osrg/gobgp/v3@v3.30.0/pkg/packet/bgp/vpls_test.go (about) 1 package bgp 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/assert" 7 "github.com/stretchr/testify/require" 8 ) 9 10 func Test_VPLSExtended(t *testing.T) { 11 assert := assert.New(t) 12 exts := make([]ExtendedCommunityInterface, 0) 13 exts = append(exts, NewVPLSExtended(100, 1500)) 14 m1 := NewPathAttributeExtendedCommunities(exts) 15 buf1, err := m1.Serialize() 16 require.NoError(t, err) 17 18 m2 := NewPathAttributeExtendedCommunities(nil) 19 err = m2.DecodeFromBytes(buf1) 20 require.NoError(t, err) 21 22 _, err = m2.Serialize() 23 require.NoError(t, err) 24 25 assert.Equal(m1, m2) 26 } 27 28 func Test_VPLSExtended_decoding(t *testing.T) { 29 assert := assert.New(t) 30 buf := []byte{ 31 0xc0, 0x10, 0x10, 0x00, 0x02, 0xfd, 0xf9, 0x00, 0x00, 0x00, 32 0x68, 0x80, 0x0a, 0x13, 0x00, 0x05, 0xdc, 0x00, 0x64, 33 } 34 m1 := NewPathAttributeExtendedCommunities(nil) 35 err := m1.DecodeFromBytes(buf) 36 require.NoError(t, err) 37 38 exts := make([]ExtendedCommunityInterface, 0) 39 exts = append(exts, NewTwoOctetAsSpecificExtended(EC_SUBTYPE_ROUTE_TARGET, 65017, 104, true), NewVPLSExtended(0, 1500)) 40 m2 := NewPathAttributeExtendedCommunities(exts) 41 42 assert.Equal(m1, m2) 43 } 44 45 func Test_VPLSNLRI(t *testing.T) { 46 assert := assert.New(t) 47 n1 := NewVPLSNLRI(NewRouteDistinguisherTwoOctetAS(65500, 10), 1, 3, 8, 100) 48 buf1, err := n1.Serialize() 49 assert.Nil(err) 50 n2 := &VPLSNLRI{} 51 err = n2.DecodeFromBytes(buf1) 52 assert.Nil(err) 53 54 t.Logf("%s", n1) 55 t.Logf("%s", n2) 56 57 assert.Equal(n1, n1) 58 } 59 60 func Test_VPLSNLRI_decoding(t *testing.T) { 61 assert := assert.New(t) 62 buf := []byte{ 63 0x90, 0x0e, 0x00, 0x1c, 0x00, 0x19, 0x41, 0x04, 0xc0, 0x00, 0x02, 64 0x07, 0x00, 0x00, 0x11, 0x00, 0x00, 0xfd, 0xf9, 0x00, 0x00, 0x00, 65 0x68, 0x00, 0x01, 0x00, 0x01, 0x00, 0x08, 0xc3, 0x50, 0x01, 66 } 67 m1 := NewPathAttributeMpReachNLRI("", nil) 68 err := m1.DecodeFromBytes(buf) 69 require.NoError(t, err) 70 71 ns := make([]AddrPrefixInterface, 0) 72 ns = append(ns, NewVPLSNLRI(NewRouteDistinguisherTwoOctetAS(65017, 104), 1, 1, 8, 800000)) 73 m2 := NewPathAttributeMpReachNLRI("192.0.2.7", ns) 74 m2.PathAttribute.Flags |= BGP_ATTR_FLAG_EXTENDED_LENGTH 75 76 assert.Equal(m1, m2) 77 }