Skip to content
Snippets Groups Projects
update_sender_test.go 72.5 KiB
Newer Older
Oliver Herms's avatar
Oliver Herms committed
package server

import (
	"bytes"
	"errors"
Oliver Herms's avatar
Oliver Herms committed
	"reflect"
	"testing"
	"time"

	"github.com/bio-routing/bio-rd/protocols/bgp/packet"

Oliver Herms's avatar
Oliver Herms committed
	"github.com/stretchr/testify/assert"

	bnet "github.com/bio-routing/bio-rd/net"
	"github.com/bio-routing/bio-rd/protocols/bgp/types"
	"github.com/bio-routing/bio-rd/route"
	"github.com/bio-routing/bio-rd/routingtable/filter"
	"github.com/bio-routing/bio-rd/routingtable/locRIB"
	btest "github.com/bio-routing/bio-rd/testing"
)

func TestSender(t *testing.T) {
	tests := []struct {
		name            string
		paths           []pathPfxs
		generateNLRIs   uint64
		expectedUpdates [][]byte
		addPath         bool
Oliver Herms's avatar
Oliver Herms committed
	}{
		{
			name: "Two paths with 3 NLRIs each",
			afi:  packet.IPv4AFI,
Oliver Herms's avatar
Oliver Herms committed
			paths: []pathPfxs{
				{
					path: &route.Path{
						Type: 2,
						BGPPath: &route.BGPPath{
							LocalPref: 100,
						},
					},
					pfxs: []bnet.Prefix{
						bnet.NewPfx(bnet.IPv4FromOctets(10, 0, 0, 0), 8),
						bnet.NewPfx(bnet.IPv4FromOctets(11, 0, 0, 0), 8),
						bnet.NewPfx(bnet.IPv4FromOctets(12, 0, 0, 0), 8),
						bnet.NewPfx(bnet.IPv4FromOctets(13, 0, 0, 0), 32),
Oliver Herms's avatar
Oliver Herms committed
					},
				},
				{
					path: &route.Path{
						Type: 2,
						BGPPath: &route.BGPPath{
							LocalPref: 200,
						},
					},
					pfxs: []bnet.Prefix{
						bnet.NewPfx(bnet.IPv4FromOctets(20, 0, 0, 0), 8),
						bnet.NewPfx(bnet.IPv4FromOctets(21, 0, 0, 0), 8),
						bnet.NewPfx(bnet.IPv4FromOctets(22, 0, 0, 0), 8),
						bnet.NewPfx(bnet.IPv4FromOctets(23, 0, 0, 0), 8),
Oliver Herms's avatar
Oliver Herms committed
					},
				},
			},
			expectedUpdates: [][]byte{
				{
					255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
					0, 52,
					2,
					0, 0, 0, 21, 64, 2, 0, 64, 1, 1, 0, 64, 3, 4, 0, 0, 0, 0, 64, 5, 4, 0, 0, 0, 200,
					8, 23, 8, 22, 8, 21, 8, 20,

					255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
					0, 55,
					2,
					0, 0, 0, 21, 64, 2, 0, 64, 1, 1, 0, 64, 3, 4, 0, 0, 0, 0, 64, 5, 4, 0, 0, 0, 100,
					32, 13, 0, 0, 0, 8, 12, 8, 11, 8, 10,
				},
				{
					255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
					0, 55,
					2,
					0, 0, 0, 21, 64, 2, 0, 64, 1, 1, 0, 64, 3, 4, 0, 0, 0, 0, 64, 5, 4, 0, 0, 0, 100,
					32, 13, 0, 0, 0, 8, 12, 8, 11, 8, 10,

					255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
					0, 52,
					2,
					0, 0, 0, 21, 64, 2, 0, 64, 1, 1, 0, 64, 3, 4, 0, 0, 0, 0, 64, 5, 4, 0, 0, 0, 200,
					8, 23, 8, 22, 8, 21, 8, 20,
				},
			},
		},
		{
			name:    "Two paths with 3 NLRIs each with BGP Add Path",
			afi:     packet.IPv4AFI,
Oliver Herms's avatar
Oliver Herms committed
			addPath: true,
			paths: []pathPfxs{
				{
					path: &route.Path{
						Type: 2,
						BGPPath: &route.BGPPath{
							LocalPref: 100,
						},
					},
					pfxs: []bnet.Prefix{
						bnet.NewPfx(bnet.IPv4FromOctets(10, 0, 0, 0), 8),
						bnet.NewPfx(bnet.IPv4FromOctets(11, 0, 0, 0), 8),
						bnet.NewPfx(bnet.IPv4FromOctets(12, 0, 0, 0), 8),
						bnet.NewPfx(bnet.IPv4FromOctets(13, 0, 0, 0), 32),
Oliver Herms's avatar
Oliver Herms committed
					},
				},
				{
					path: &route.Path{
						Type: 2,
						BGPPath: &route.BGPPath{
							LocalPref: 200,
						},
					},
					pfxs: []bnet.Prefix{
						bnet.NewPfx(bnet.IPv4FromOctets(20, 0, 0, 0), 8),
						bnet.NewPfx(bnet.IPv4FromOctets(21, 0, 0, 0), 8),
						bnet.NewPfx(bnet.IPv4FromOctets(22, 0, 0, 0), 8),
						bnet.NewPfx(bnet.IPv4FromOctets(23, 0, 0, 0), 8),
Oliver Herms's avatar
Oliver Herms committed
					},
				},
			},
			expectedUpdates: [][]byte{
				{
					255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
					0, 71,
					2,
					0, 0,
					0, 21, 64, 2, 0, 64, 1, 1, 0, 64, 3, 4, 0, 0, 0, 0, 64, 5, 4, 0, 0, 0, 100,
					0, 0, 0, 0, 32, 13, 0, 0, 0,
					0, 0, 0, 0, 8, 12,
					0, 0, 0, 0, 8, 11,
					0, 0, 0, 0, 8, 10,

					255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
					0, 68,
					2,
					0, 0,
					0, 21, 64, 2, 0, 64, 1, 1, 0, 64, 3, 4, 0, 0, 0, 0, 64, 5, 4, 0, 0, 0, 200,
					0, 0, 0, 0, 8, 23,
					0, 0, 0, 0, 8, 22,
					0, 0, 0, 0, 8, 21,
					0, 0, 0, 0, 8, 20,
				},
				{
					255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
					0, 68,
					2,
					0, 0,
					0, 21, 64, 2, 0, 64, 1, 1, 0, 64, 3, 4, 0, 0, 0, 0, 64, 5, 4, 0, 0, 0, 200,
					0, 0, 0, 0, 8, 23,
					0, 0, 0, 0, 8, 22,
					0, 0, 0, 0, 8, 21,
					0, 0, 0, 0, 8, 20,

					255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
					0, 71,
					2,
					0, 0,
					0, 21, 64, 2, 0, 64, 1, 1, 0, 64, 3, 4, 0, 0, 0, 0, 64, 5, 4, 0, 0, 0, 100,
					0, 0, 0, 0, 32, 13, 0, 0, 0,
					0, 0, 0, 0, 8, 12,
					0, 0, 0, 0, 8, 11,
					0, 0, 0, 0, 8, 10,
				},
			},
		},
		{
			name: "Overflow. Too many NLRIs.",
			afi:  packet.IPv4AFI,
Oliver Herms's avatar
Oliver Herms committed
			paths: []pathPfxs{
				{
					path: &route.Path{
						Type: 2,
						BGPPath: &route.BGPPath{
							LocalPref: 100,
						},
					},
				},
			},
			generateNLRIs: 1000,
			expectedUpdates: [][]byte{
				{
					255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
					15, 239, 2, 0, 0, 0, 21, 64, 2, 0, 64, 1, 1, 0, 64, 3, 4, 0, 0, 0, 0, 64, 5, 4, 0, 0, 0, 100,
					32, 10, 0, 3, 35, 32, 10, 0, 3, 34, 32, 10, 0, 3, 33, 32, 10, 0, 3, 32, 32, 10, 0, 3, 31, 32, 10, 0, 3, 30, 32, 10, 0, 3, 29,
					32, 10, 0, 3, 28, 32, 10, 0, 3, 27, 32, 10, 0, 3, 26, 32, 10, 0, 3, 25, 32, 10, 0, 3, 24, 32, 10, 0, 3, 23, 32, 10, 0, 3, 22,
					32, 10, 0, 3, 21, 32, 10, 0, 3, 20, 32, 10, 0, 3, 19, 32, 10, 0, 3, 18, 32, 10, 0, 3, 17, 32, 10, 0, 3, 16, 32, 10, 0, 3, 15,
					32, 10, 0, 3, 14, 32, 10, 0, 3, 13, 32, 10, 0, 3, 12, 32, 10, 0, 3, 11, 32, 10, 0, 3, 10, 32, 10, 0, 3, 9, 32, 10, 0, 3, 8,
					32, 10, 0, 3, 7, 32, 10, 0, 3, 6, 32, 10, 0, 3, 5, 32, 10, 0, 3, 4, 32, 10, 0, 3, 3, 32, 10, 0, 3, 2, 32, 10, 0, 3, 1,
					32, 10, 0, 3, 0, 32, 10, 0, 3, 255, 32, 10, 0, 3, 254, 32, 10, 0, 3, 253, 32, 10, 0, 2, 253, 32, 10, 0, 2, 252, 32, 10, 0, 2, 251,
					32, 10, 0, 2, 250, 32, 10, 0, 2, 249, 32, 10, 0, 2, 248, 32, 10, 0, 2, 247, 32, 10, 0, 2, 246, 32, 10, 0, 2, 245, 32, 10, 0, 2, 244,
					32, 10, 0, 2, 243, 32, 10, 0, 2, 242, 32, 10, 0, 2, 241, 32, 10, 0, 2, 240, 32, 10, 0, 2, 239, 32, 10, 0, 2, 238, 32, 10, 0, 2, 237,
					32, 10, 0, 2, 236, 32, 10, 0, 2, 235, 32, 10, 0, 2, 234, 32, 10, 0, 2, 233, 32, 10, 0, 2, 232, 32, 10, 0, 2, 231, 32, 10, 0, 2, 230,
					32, 10, 0, 2, 229, 32, 10, 0, 2, 228, 32, 10, 0, 2, 227, 32, 10, 0, 2, 226, 32, 10, 0, 2, 225, 32, 10, 0, 2, 224, 32, 10, 0, 2, 223,
					32, 10, 0, 2, 222, 32, 10, 0, 2, 221, 32, 10, 0, 2, 220, 32, 10, 0, 2, 219, 32, 10, 0, 2, 218, 32, 10, 0, 2, 217, 32, 10, 0, 2, 216,
Loading
Loading full blame...