diff options
author | FUJITA Tomonori <fujita.tomonori@gmail.com> | 2018-12-22 16:33:37 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@gmail.com> | 2018-12-23 19:29:23 +0900 |
commit | ababf3068c48d665e2d9d7816cbb521c74fc47c5 (patch) | |
tree | 2fc2f54823294768e88ca94eb7bdc4fb74da9259 /pkg/server/server_test.go | |
parent | 5d008d7b7c22cab84d974cfb7a90a002b391538a (diff) |
make Add/Delete/ListPath APIs symmetric
- AddPath() with an api.Path object then DeletePath() works with the same api.Path object.
- ListPath() returns an api.Path object then DeletePath() works with the same api.Path object.
The above is guaranteed with and without PeerInfo (SourceAsn and SourceId).
Signed-off-by: FUJITA Tomonori <fujita.tomonori@gmail.com>
Diffstat (limited to 'pkg/server/server_test.go')
-rw-r--r-- | pkg/server/server_test.go | 120 |
1 files changed, 120 insertions, 0 deletions
diff --git a/pkg/server/server_test.go b/pkg/server/server_test.go index 3bd47304..984cf53a 100644 --- a/pkg/server/server_test.go +++ b/pkg/server/server_test.go @@ -23,6 +23,8 @@ import ( "testing" "time" + "github.com/golang/protobuf/ptypes" + "github.com/golang/protobuf/ptypes/any" log "github.com/sirupsen/logrus" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -1050,3 +1052,121 @@ func TestDoNotReactToDuplicateRTCMemberships(t *testing.T) { s1.StopBgp(context.Background(), &api.StopBgpRequest{}) s2.StopBgp(context.Background(), &api.StopBgpRequest{}) } + +func TestAddDeletePath(t *testing.T) { + ctx := context.Background() + s := runNewServer(1, "1.1.1.1", 10179) + + nlri, _ := ptypes.MarshalAny(&api.IPAddressPrefix{ + Prefix: "10.0.0.0", + PrefixLen: 24, + }) + + a1, _ := ptypes.MarshalAny(&api.OriginAttribute{ + Origin: 0, + }) + a2, _ := ptypes.MarshalAny(&api.NextHopAttribute{ + NextHop: "10.0.0.1", + }) + attrs := []*any.Any{a1, a2} + + family := &api.Family{ + Afi: api.Family_AFI_IP, + Safi: api.Family_SAFI_UNICAST, + } + + listRib := func() []*api.Destination { + l := make([]*api.Destination, 0) + s.ListPath(ctx, &api.ListPathRequest{Type: api.Resource_GLOBAL, Family: family}, func(d *api.Destination) { l = append(l, d) }) + return l + } + + var err error + // DeletePath(AddPath()) without PeerInfo + getPath := func() *api.Path { + return &api.Path{ + Family: family, + Nlri: nlri, + Pattrs: attrs, + } + } + + p1 := getPath() + _, err = s.AddPath(ctx, &api.AddPathRequest{ + Resource: api.Resource_GLOBAL, + Path: p1, + }) + assert.Nil(t, err) + assert.Equal(t, len(listRib()), 1) + err = s.DeletePath(ctx, &api.DeletePathRequest{ + Resource: api.Resource_GLOBAL, + Path: p1, + }) + assert.Nil(t, err) + assert.Equal(t, len(listRib()), 0) + + // DeletePath(ListPath()) without PeerInfo + _, err = s.AddPath(ctx, &api.AddPathRequest{ + Resource: api.Resource_GLOBAL, + Path: p1, + }) + assert.Nil(t, err) + l := listRib() + assert.Equal(t, len(l), 1) + err = s.DeletePath(ctx, &api.DeletePathRequest{ + Resource: api.Resource_GLOBAL, + Path: l[0].Paths[0], + }) + assert.Nil(t, err) + assert.Equal(t, len(listRib()), 0) + + p2 := getPath() + p2.SourceAsn = 1 + p2.SourceId = "1.1.1.1" + + // DeletePath(AddPath()) with PeerInfo + _, err = s.AddPath(ctx, &api.AddPathRequest{ + Resource: api.Resource_GLOBAL, + Path: p2, + }) + assert.Nil(t, err) + assert.Equal(t, len(listRib()), 1) + err = s.DeletePath(ctx, &api.DeletePathRequest{ + Resource: api.Resource_GLOBAL, + Path: p2, + }) + assert.Nil(t, err) + assert.Equal(t, len(listRib()), 0) + + // DeletePath(ListPath()) with PeerInfo + _, err = s.AddPath(ctx, &api.AddPathRequest{ + Resource: api.Resource_GLOBAL, + Path: p2, + }) + assert.Nil(t, err) + l = listRib() + assert.Equal(t, len(l), 1) + err = s.DeletePath(ctx, &api.DeletePathRequest{ + Resource: api.Resource_GLOBAL, + Path: l[0].Paths[0], + }) + assert.Nil(t, err) + assert.Equal(t, len(listRib()), 0) + + // DeletePath(AddPath()) with different PeerInfo + _, err = s.AddPath(ctx, &api.AddPathRequest{ + Resource: api.Resource_GLOBAL, + Path: p2, + }) + assert.Nil(t, err) + assert.Equal(t, len(listRib()), 1) + p3 := getPath() + p3.SourceAsn = 2 + p3.SourceId = "1.1.1.2" + err = s.DeletePath(ctx, &api.DeletePathRequest{ + Resource: api.Resource_GLOBAL, + Path: p3, + }) + assert.Nil(t, err) + assert.Equal(t, len(listRib()), 1) +} |