Skip to content
Snippets Groups Projects
fsm_address_family_test.go 1.33 KiB
Newer Older
  • Learn to ignore specific revisions
  • package server
    
    import (
    	"testing"
    
    	"github.com/bio-routing/bio-rd/protocols/bgp/packet"
    
    Oliver Herms's avatar
    Oliver Herms committed
    	"github.com/bio-routing/bio-rd/protocols/bgp/types"
    
    	"github.com/bio-routing/bio-rd/route"
    	"github.com/stretchr/testify/assert"
    )
    
    
    Oliver Herms's avatar
    Oliver Herms committed
    func TestProcessAttributes(t *testing.T) {
    
    	unknown3 := &packet.PathAttribute{
    		Transitive: true,
    		TypeCode:   100,
    		Value:      []byte{1, 2, 3, 4},
    		Next:       nil,
    	}
    
    	unknown2 := &packet.PathAttribute{
    		Transitive: false,
    		TypeCode:   150,
    		Value:      []byte{20},
    		Next:       unknown3,
    	}
    
    	unknown1 := &packet.PathAttribute{
    		Transitive: true,
    		TypeCode:   200,
    		Value:      []byte{5, 6},
    		Next:       unknown2,
    	}
    
    	asPath := &packet.PathAttribute{
    		Transitive: true,
    		TypeCode:   packet.ASPathAttr,
    
    Oliver Herms's avatar
    Oliver Herms committed
    		Value: types.ASPath{
    			types.ASPathSegment{
    				Type: types.ASSequence,
    				ASNs: []uint32{},
    
    			},
    		},
    		Next: unknown1,
    	}
    
    
    	f := &fsmAddressFamily{}
    
    
    	p := &route.Path{
    		BGPPath: &route.BGPPath{},
    	}
    
    	f.processAttributes(asPath, p)
    
    
    	expectedCodes := []uint8{200, 100}
    	expectedValues := [][]byte{[]byte{5, 6}, []byte{1, 2, 3, 4}}
    
    	i := 0
    
    Oliver Herms's avatar
    Oliver Herms committed
    	for _, attr := range p.BGPPath.UnknownAttributes {
    
    		assert.Equal(t, true, attr.Transitive, "Transitive")
    		assert.Equal(t, expectedCodes[i], attr.TypeCode, "Code")
    		assert.Equal(t, expectedValues[i], attr.Value, "Value")
    		i++
    	}
    
    
    Oliver Herms's avatar
    Oliver Herms committed
    	assert.Equal(t, 2, i, "Count")