Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Data path healing should be disabled #1304

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions pkg/networkservice/ipam/singlepointipam/server.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2020-2021 Nordix and its affiliates.
// Copyright (c) 2020-2022 Nordix and its affiliates.
//
// SPDX-License-Identifier: Apache-2.0
//
Expand Down Expand Up @@ -113,7 +113,6 @@ func (sipam *singlePIpam) Request(ctx context.Context, request *networkservice.N
}

addAddr(&ipContext.SrcIpAddrs, connInfo.srcAddr)
addAddr(&ipContext.DstIpAddrs, connInfo.dstAddr)

conn, err = next.Server(ctx).Request(ctx, request)
if err != nil {
Expand Down
77 changes: 36 additions & 41 deletions pkg/networkservice/ipam/singlepointipam/server_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Copyright (c) 2020-2021 Doc.ai and/or its affiliates.
// Copyright (c) 2020-2022 Nordix and its affiliates.
//
// SPDX-License-Identifier: Apache-2.0
//
Expand All @@ -23,11 +24,10 @@ import (

"github.com/stretchr/testify/require"

"github.com/networkservicemesh/sdk/pkg/networkservice/core/chain"

"github.com/networkservicemesh/api/pkg/api/networkservice"

"github.com/networkservicemesh/sdk/pkg/networkservice/common/updatepath"
"github.com/networkservicemesh/sdk/pkg/networkservice/core/chain"
"github.com/networkservicemesh/sdk/pkg/networkservice/core/next"
"github.com/networkservicemesh/sdk/pkg/networkservice/ipam/singlepointipam"
"github.com/networkservicemesh/sdk/pkg/networkservice/utils/inject/injecterror"
Expand All @@ -52,17 +52,12 @@ func newRequest() *networkservice.NetworkServiceRequest {
}
}

func validateConn(t *testing.T, conn *networkservice.Connection, dst, src string) {
require.Equal(t, dst, conn.Context.IpContext.DstIpAddrs[0])
func validateConn(t *testing.T, conn *networkservice.Connection, src string) {
require.Equal(t, src, conn.Context.IpContext.SrcIpAddrs[0])
}

func validateConns(t *testing.T, conn *networkservice.Connection, dsts, srcs []string) {
require.Equal(t, len(dsts), len(conn.Context.IpContext.DstIpAddrs))
func validateConns(t *testing.T, conn *networkservice.Connection, srcs []string) {
require.Equal(t, len(srcs), len(conn.Context.IpContext.SrcIpAddrs))
for i, dst := range dsts {
require.Equal(t, dst, conn.Context.IpContext.DstIpAddrs[i])
}
for i, src := range srcs {
require.Equal(t, src, conn.Context.IpContext.SrcIpAddrs[i])
}
Expand All @@ -77,22 +72,22 @@ func TestServer(t *testing.T) {

conn1, err := srv.Request(context.Background(), newRequest())
require.NoError(t, err)
validateConn(t, conn1, "192.168.0.0/16", "192.168.0.1/16")
validateConn(t, conn1, "192.168.0.1/16")

conn2, err := srv.Request(context.Background(), newRequest())
require.NoError(t, err)
validateConn(t, conn2, "192.168.0.0/16", "192.168.0.2/16")
validateConn(t, conn2, "192.168.0.2/16")

_, err = srv.Close(context.Background(), conn1)
require.NoError(t, err)

conn3, err := srv.Request(context.Background(), newRequest())
require.NoError(t, err)
validateConn(t, conn3, "192.168.0.0/16", "192.168.0.1/16")
validateConn(t, conn3, "192.168.0.1/16")

conn4, err := srv.Request(context.Background(), newRequest())
require.NoError(t, err)
validateConn(t, conn4, "192.168.0.0/16", "192.168.0.3/16")
validateConn(t, conn4, "192.168.0.3/16")
}

//nolint:dupl
Expand All @@ -104,22 +99,22 @@ func TestServerIPv6(t *testing.T) {

conn1, err := srv.Request(context.Background(), newRequest())
require.NoError(t, err)
validateConn(t, conn1, "fe80::/64", "fe80::1/64")
validateConn(t, conn1, "fe80::1/64")

conn2, err := srv.Request(context.Background(), newRequest())
require.NoError(t, err)
validateConn(t, conn2, "fe80::/64", "fe80::2/64")
validateConn(t, conn2, "fe80::2/64")

_, err = srv.Close(context.Background(), conn1)
require.NoError(t, err)

conn3, err := srv.Request(context.Background(), newRequest())
require.NoError(t, err)
validateConn(t, conn3, "fe80::/64", "fe80::1/64")
validateConn(t, conn3, "fe80::1/64")

conn4, err := srv.Request(context.Background(), newRequest())
require.NoError(t, err)
validateConn(t, conn4, "fe80::/64", "fe80::3/64")
validateConn(t, conn4, "fe80::3/64")
}

func TestNilPrefixes(t *testing.T) {
Expand Down Expand Up @@ -160,21 +155,21 @@ func TestExclude32Prefix(t *testing.T) {
req1.Connection.Context.IpContext.ExcludedPrefixes = []string{"192.168.1.1/32", "192.168.1.3/32", "192.168.1.5/32"}
conn1, err := srv.Request(context.Background(), req1)
require.NoError(t, err)
validateConn(t, conn1, "192.168.1.0/24", "192.168.1.2/24")
validateConn(t, conn1, "192.168.1.2/24")

// Test exclude before assigned
req2 := newRequest()
req2.Connection.Context.IpContext.ExcludedPrefixes = []string{"192.168.1.1/32", "192.168.1.3/32", "192.168.1.5/32"}
conn2, err := srv.Request(context.Background(), req2)
require.NoError(t, err)
validateConn(t, conn2, "192.168.1.0/24", "192.168.1.4/24")
validateConn(t, conn2, "192.168.1.4/24")

// Test after assigned
req3 := newRequest()
req3.Connection.Context.IpContext.ExcludedPrefixes = []string{"192.168.1.1/32", "192.168.1.3/32", "192.168.1.5/32"}
conn3, err := srv.Request(context.Background(), req3)
require.NoError(t, err)
validateConn(t, conn3, "192.168.1.0/24", "192.168.1.6/24")
validateConn(t, conn3, "192.168.1.6/24")
}

//nolint:dupl
Expand All @@ -189,21 +184,21 @@ func TestExclude128PrefixIPv6(t *testing.T) {
req1.Connection.Context.IpContext.ExcludedPrefixes = []string{"fe80::1:1/128", "fe80::1:3/128", "fe80::1:5/128"}
conn1, err := srv.Request(context.Background(), req1)
require.NoError(t, err)
validateConn(t, conn1, "fe80::1:0/112", "fe80::1:2/112")
validateConn(t, conn1, "fe80::1:2/112")

// Test exclude before assigned
req2 := newRequest()
req2.Connection.Context.IpContext.ExcludedPrefixes = []string{"fe80::1:1/128", "fe80::1:3/128", "fe80::1:5/128"}
conn2, err := srv.Request(context.Background(), req2)
require.NoError(t, err)
validateConn(t, conn2, "fe80::1:0/112", "fe80::1:4/112")
validateConn(t, conn2, "fe80::1:4/112")

// Test after assigned
req3 := newRequest()
req3.Connection.Context.IpContext.ExcludedPrefixes = []string{"fe80::1:1/128", "fe80::1:3/128", "fe80::1:5/128"}
conn3, err := srv.Request(context.Background(), req3)
require.NoError(t, err)
validateConn(t, conn3, "fe80::1:0/112", "fe80::1:6/112")
validateConn(t, conn3, "fe80::1:6/112")
}

func TestOutOfIPs(t *testing.T) {
Expand All @@ -215,7 +210,7 @@ func TestOutOfIPs(t *testing.T) {
req1 := newRequest()
conn1, err := srv.Request(context.Background(), req1)
require.NoError(t, err)
validateConn(t, conn1, "192.168.1.2/31", "192.168.1.3/31")
validateConn(t, conn1, "192.168.1.3/31")

req2 := newRequest()
_, err = srv.Request(context.Background(), req2)
Expand All @@ -231,7 +226,7 @@ func TestOutOfIPsIPv6(t *testing.T) {
req1 := newRequest()
conn1, err := srv.Request(context.Background(), req1)
require.NoError(t, err)
validateConn(t, conn1, "fe80::1:2/127", "fe80::1:3/127")
validateConn(t, conn1, "fe80::1:3/127")

req2 := newRequest()
_, err = srv.Request(context.Background(), req2)
Expand Down Expand Up @@ -275,19 +270,19 @@ func TestRefreshRequest(t *testing.T) {
req.Connection.Context.IpContext.ExcludedPrefixes = []string{"192.168.0.1/32"}
conn, err := srv.Request(context.Background(), req)
require.NoError(t, err)
validateConn(t, conn, "192.168.0.0/16", "192.168.0.2/16")
validateConn(t, conn, "192.168.0.2/16")

req = newRequest()
req.Connection.Id = conn.Id
conn, err = srv.Request(context.Background(), req)
require.NoError(t, err)
validateConn(t, conn, "192.168.0.0/16", "192.168.0.2/16")
validateConn(t, conn, "192.168.0.2/16")

req.Connection = conn.Clone()
req.Connection.Context.IpContext.ExcludedPrefixes = []string{"192.168.0.1/30"}
conn, err = srv.Request(context.Background(), req)
require.NoError(t, err)
validateConn(t, conn, "192.168.0.4/16", "192.168.0.5/16")
validateConn(t, conn, "192.168.0.5/16")
}

//nolint:dupl
Expand All @@ -301,19 +296,19 @@ func TestRefreshRequestIPv6(t *testing.T) {
req.Connection.Context.IpContext.ExcludedPrefixes = []string{"fe80::1/128"}
conn, err := srv.Request(context.Background(), req)
require.NoError(t, err)
validateConn(t, conn, "fe80::/64", "fe80::2/64")
validateConn(t, conn, "fe80::2/64")

req = newRequest()
req.Connection.Id = conn.Id
conn, err = srv.Request(context.Background(), req)
require.NoError(t, err)
validateConn(t, conn, "fe80::/64", "fe80::2/64")
validateConn(t, conn, "fe80::2/64")

req.Connection = conn.Clone()
req.Connection.Context.IpContext.ExcludedPrefixes = []string{"fe80::/126"}
conn, err = srv.Request(context.Background(), req)
require.NoError(t, err)
validateConn(t, conn, "fe80::4/64", "fe80::5/64")
validateConn(t, conn, "fe80::5/64")
}

func TestNextError(t *testing.T) {
Expand All @@ -327,7 +322,7 @@ func TestNextError(t *testing.T) {

conn, err := srv.Request(context.Background(), newRequest())
require.NoError(t, err)
validateConn(t, conn, "192.168.0.0/16", "192.168.0.1/16")
validateConn(t, conn, "192.168.0.1/16")
}

func TestRefreshNextError(t *testing.T) {
Expand All @@ -339,15 +334,15 @@ func TestRefreshNextError(t *testing.T) {
req := newRequest()
conn, err := srv.Request(context.Background(), req)
require.NoError(t, err)
validateConn(t, conn, "192.168.0.0/16", "192.168.0.1/16")
validateConn(t, conn, "192.168.0.1/16")

req.Connection = conn.Clone()
_, err = next.NewNetworkServiceServer(srv, injecterror.NewServer()).Request(context.Background(), newRequest())
require.Error(t, err)

conn, err = srv.Request(context.Background(), newRequest())
require.NoError(t, err)
validateConn(t, conn, "192.168.0.0/16", "192.168.0.2/16")
validateConn(t, conn, "192.168.0.2/16")
}

//nolint:dupl
Expand All @@ -364,22 +359,22 @@ func TestServers(t *testing.T) {

conn1, err := srv.Request(context.Background(), newRequest())
require.NoError(t, err)
validateConns(t, conn1, []string{"192.168.0.0/16", "fd00::/8"}, []string{"192.168.0.1/16", "fd00::1/8"})
validateConns(t, conn1, []string{"192.168.0.1/16", "fd00::1/8"})

conn2, err := srv.Request(context.Background(), newRequest())
require.NoError(t, err)
validateConns(t, conn2, []string{"192.168.0.0/16", "fd00::/8"}, []string{"192.168.0.2/16", "fd00::2/8"})
validateConns(t, conn2, []string{"192.168.0.2/16", "fd00::2/8"})

_, err = srv.Close(context.Background(), conn1)
require.NoError(t, err)

conn3, err := srv.Request(context.Background(), newRequest())
require.NoError(t, err)
validateConns(t, conn3, []string{"192.168.0.0/16", "fd00::/8"}, []string{"192.168.0.1/16", "fd00::1/8"})
validateConns(t, conn3, []string{"192.168.0.1/16", "fd00::1/8"})

conn4, err := srv.Request(context.Background(), newRequest())
require.NoError(t, err)
validateConns(t, conn4, []string{"192.168.0.0/16", "fd00::/8"}, []string{"192.168.0.3/16", "fd00::3/8"})
validateConns(t, conn4, []string{"192.168.0.3/16", "fd00::3/8"})
}

//nolint:dupl
Expand All @@ -398,17 +393,17 @@ func TestRefreshRequestMultiServer(t *testing.T) {
req.Connection.Context.IpContext.ExcludedPrefixes = []string{"192.168.0.1/32", "fe80::1/128"}
conn, err := srv.Request(context.Background(), req)
require.NoError(t, err)
validateConns(t, conn, []string{"192.168.0.0/16", "fe80::/64"}, []string{"192.168.0.2/16", "fe80::2/64"})
validateConns(t, conn, []string{"192.168.0.2/16", "fe80::2/64"})

req = newRequest()
req.Connection = conn
conn, err = srv.Request(context.Background(), req)
require.NoError(t, err)
validateConns(t, conn, []string{"192.168.0.0/16", "fe80::/64"}, []string{"192.168.0.2/16", "fe80::2/64"})
validateConns(t, conn, []string{"192.168.0.2/16", "fe80::2/64"})

req.Connection = conn.Clone()
req.Connection.Context.IpContext.ExcludedPrefixes = []string{"192.168.0.1/30", "fe80::1/126"}
conn, err = srv.Request(context.Background(), req)
require.NoError(t, err)
validateConns(t, conn, []string{"192.168.0.4/16", "fe80::4/64"}, []string{"192.168.0.5/16", "fe80::5/64"})
validateConns(t, conn, []string{"192.168.0.5/16", "fe80::5/64"})
}