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

Fix vl3 ipam refresh #1601

Merged
merged 1 commit into from
Mar 26, 2024
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
17 changes: 17 additions & 0 deletions pkg/networkservice/chains/nsmgr/vl3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"github.com/google/uuid"
"github.com/stretchr/testify/require"
"go.uber.org/goleak"
"google.golang.org/protobuf/proto"

"github.com/networkservicemesh/api/pkg/api/networkservice"
"github.com/networkservicemesh/api/pkg/api/networkservice/mechanisms/cls"
Expand Down Expand Up @@ -528,9 +529,17 @@ func Test_NSC_ConnectsTo_vl3NSE_With_Invalid_IpContext(t *testing.T) {
req := defaultRequest(nsReg.Name)
conn, err := nsc.Request(ctx, req)
require.NoError(t, err)
require.True(t, checkIPContext(conn.Context.IpContext, prefix1))

// Refresh
clonedConn := conn.Clone()
req.Connection = conn
conn, err = nsc.Request(ctx, req)
require.NoError(t, err)
require.True(t, checkIPContext(conn.Context.IpContext, prefix1))
require.True(t, proto.Equal(clonedConn.GetContext().IpContext, conn.GetContext().IpContext))

// Reset ipam with a new prefix
err = serverIpam.Reset(prefix2)
require.NoError(t, err)

Expand All @@ -540,6 +549,14 @@ func Test_NSC_ConnectsTo_vl3NSE_With_Invalid_IpContext(t *testing.T) {

require.False(t, checkIPContext(conn.Context.IpContext, prefix1))
require.True(t, checkIPContext(conn.Context.IpContext, prefix2))

// Refresh
clonedConn = conn.Clone()
req.Connection = conn
conn, err = nsc.Request(ctx, req)
require.NoError(t, err)
require.True(t, checkIPContext(conn.Context.IpContext, prefix2))
require.True(t, proto.Equal(clonedConn.GetContext().IpContext, conn.GetContext().IpContext))
}

func checkIPContext(ipContext *networkservice.IPContext, prefix string) bool {
Expand Down
9 changes: 8 additions & 1 deletion pkg/networkservice/connectioncontext/ipcontext/vl3/ipam.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,5 +185,12 @@
func (p *IPAM) ContainsNetString(ipNet string) bool {
p.Lock()
defer p.Unlock()
return p.ipPool.ContainsNetString(ipNet)
selfAddress := &net.IPNet{
IP: p.self.IP,
Mask: net.CIDRMask(
int(p.clientMask),
int(p.clientMask),
),
}
return p.ipPool.ContainsNetString(ipNet) || selfAddress.String() == ipNet

Check warning on line 195 in pkg/networkservice/connectioncontext/ipcontext/vl3/ipam.go

View check run for this annotation

Codecov / codecov/patch

pkg/networkservice/connectioncontext/ipcontext/vl3/ipam.go#L188-L195

Added lines #L188 - L195 were not covered by tests
}
Loading