-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated strict IPAM and added dualstack IP pool (#1679)
* add fix for ipam Signed-off-by: NikitaSkrynnik <nikita.skrynnik@xored.com> * another fix Signed-off-by: NikitaSkrynnik <nikita.skrynnik@xored.com> * add a unit test for ipam issue Signed-off-by: NikitaSkrynnik <nikita.skrynnik@xored.com> * add fix for ipam Signed-off-by: NikitaSkrynnik <nikita.skrynnik@xored.com> * another fix Signed-off-by: NikitaSkrynnik <nikita.skrynnik@xored.com> * add ip context validation Signed-off-by: NikitaSkrynnik <nikita.skrynnik@xored.com> * properly delete addresses Signed-off-by: NikitaSkrynnik <nikita.skrynnik@xored.com> * rework ip context validation Signed-off-by: NikitaSkrynnik <nikita.skrynnik@xored.com> * temporarily skip failing tests Signed-off-by: NikitaSkrynnik <nikita.skrynnik@xored.com> * fix CI issues Signed-off-by: NikitaSkrynnik <nikita.skrynnik@xored.com> * fix all tests Signed-off-by: NikitaSkrynnik <nikita.skrynnik@xored.com> * fix unit tests Signed-off-by: NikitaSkrynnik <nikita.skrynnik@xored.com> * fix go linter issues Signed-off-by: NikitaSkrynnik <nikita.skrynnik@xored.com> * cleanup Signed-off-by: NikitaSkrynnik <nikita.skrynnik@xored.com> * add ipv6 unit test Signed-off-by: NikitaSkrynnik <nikita.skrynnik@xored.com> * cleanup Signed-off-by: NikitaSkrynnik <nikita.skrynnik@xored.com> * fix go linter issues Signed-off-by: NikitaSkrynnik <nikita.skrynnik@xored.com> * Replaced strict ipam by filteripam implementation Signed-off-by: Vladislav Byrgazov <vladislav.byrgazov@xored.com> * Added dualstack ippool, updated tests Signed-off-by: Vladislav Byrgazov <vladislav.byrgazov@xored.com> * Fixed dualstack ippool Signed-off-by: Vladislav Byrgazov <vladislav.byrgazov@xored.com> * Fix linter errors Signed-off-by: Vladislav Byrgazov <vladislav.byrgazov@xored.com> * Fixed ippool test input data format Signed-off-by: Vladislav Byrgazov <vladislav.byrgazov@xored.com> --------- Signed-off-by: NikitaSkrynnik <nikita.skrynnik@xored.com> Signed-off-by: Vladislav Byrgazov <vladislav.byrgazov@xored.com> Co-authored-by: NikitaSkrynnik <nikita.skrynnik@xored.com> Co-authored-by: Vladislav Byrgazov <vladislav.byrgazov@xored.com>
- Loading branch information
1 parent
7ebf92e
commit 3801206
Showing
6 changed files
with
466 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,157 @@ | ||
// Copyright (c) 2024 Cisco and/or its affiliates. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at: | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package strictipam_test | ||
|
||
import ( | ||
"context" | ||
"net" | ||
"testing" | ||
|
||
"github.com/networkservicemesh/api/pkg/api/networkservice" | ||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/networkservicemesh/sdk/pkg/networkservice/core/chain" | ||
"github.com/networkservicemesh/sdk/pkg/networkservice/core/next" | ||
"github.com/networkservicemesh/sdk/pkg/networkservice/ipam/point2pointipam" | ||
"github.com/networkservicemesh/sdk/pkg/networkservice/ipam/strictipam" | ||
"github.com/networkservicemesh/sdk/pkg/networkservice/utils/checks/checkrequest" | ||
) | ||
|
||
func newRequest(connID string) *networkservice.NetworkServiceRequest { | ||
return &networkservice.NetworkServiceRequest{ | ||
Connection: &networkservice.Connection{ | ||
Id: connID, | ||
Context: &networkservice.ConnectionContext{ | ||
IpContext: new(networkservice.IPContext), | ||
}, | ||
}, | ||
} | ||
} | ||
func validateConns(t *testing.T, conn *networkservice.Connection, dsts, srcs []string) { | ||
for i, dst := range dsts { | ||
require.Equal(t, conn.Context.IpContext.DstIpAddrs[i], dst) | ||
require.Equal(t, conn.Context.IpContext.SrcRoutes[i].Prefix, dst) | ||
} | ||
for i, src := range srcs { | ||
require.Equal(t, conn.Context.IpContext.SrcIpAddrs[i], src) | ||
require.Equal(t, conn.Context.IpContext.DstRoutes[i].Prefix, src) | ||
} | ||
} | ||
|
||
// nolint: dupl | ||
func TestOverlappingAddresses(t *testing.T) { | ||
_, ipNet, err := net.ParseCIDR("172.16.0.0/24") | ||
require.NoError(t, err) | ||
|
||
srv := next.NewNetworkServiceServer(strictipam.NewServer(point2pointipam.NewServer, ipNet)) | ||
|
||
emptyRequest := newRequest("empty") | ||
|
||
request := newRequest("id") | ||
request.Connection.Context.IpContext.SrcIpAddrs = []string{"172.16.0.1/32", "172.16.0.25/32"} | ||
request.Connection.Context.IpContext.DstIpAddrs = []string{"172.16.0.0/32", "172.16.0.24/32"} | ||
request.Connection.Context.IpContext.SrcRoutes = []*networkservice.Route{{Prefix: "172.16.0.0/32"}, {Prefix: "172.16.0.24/32"}} | ||
request.Connection.Context.IpContext.DstRoutes = []*networkservice.Route{{Prefix: "172.16.0.1/32"}, {Prefix: "172.16.0.25/32"}} | ||
|
||
conn1, err := srv.Request(context.Background(), emptyRequest) | ||
require.NoError(t, err) | ||
validateConns(t, conn1, []string{"172.16.0.0/32"}, []string{"172.16.0.1/32"}) | ||
|
||
conn2, err := srv.Request(context.Background(), request.Clone()) | ||
require.NoError(t, err) | ||
validateConns(t, conn2, []string{"172.16.0.24/32"}, []string{"172.16.0.25/32"}) | ||
|
||
_, err = srv.Close(context.Background(), conn1) | ||
require.NoError(t, err) | ||
|
||
conn2, err = srv.Request(context.Background(), request) | ||
require.NoError(t, err) | ||
validateConns(t, conn2, []string{"172.16.0.0/32", "172.16.0.24/32"}, []string{"172.16.0.1/32", "172.16.0.25/32"}) | ||
} | ||
|
||
// nolint: dupl | ||
func TestOverlappingAddressesIPv6(t *testing.T) { | ||
_, ipNet, err := net.ParseCIDR("fe80::/64") | ||
require.NoError(t, err) | ||
|
||
srv := next.NewNetworkServiceServer(strictipam.NewServer(point2pointipam.NewServer, ipNet)) | ||
|
||
emptyRequest := newRequest("empty") | ||
|
||
request := newRequest("id") | ||
request.Connection.Id = "id" | ||
request.Connection.Context.IpContext.SrcIpAddrs = []string{"fe80::1/128", "fe80::fa01/128"} | ||
request.Connection.Context.IpContext.DstIpAddrs = []string{"fe80::/128", "fe80::fa00/128"} | ||
request.Connection.Context.IpContext.SrcRoutes = []*networkservice.Route{{Prefix: "fe80::/128"}, {Prefix: "fe80::fa00/128"}} | ||
request.Connection.Context.IpContext.DstRoutes = []*networkservice.Route{{Prefix: "fe80::1/128"}, {Prefix: "fe80::fa01/128"}} | ||
|
||
conn1, err := srv.Request(context.Background(), emptyRequest) | ||
require.NoError(t, err) | ||
validateConns(t, conn1, []string{"fe80::/128"}, []string{"fe80::1/128"}) | ||
|
||
conn2, err := srv.Request(context.Background(), request.Clone()) | ||
require.NoError(t, err) | ||
validateConns(t, conn2, []string{"fe80::fa00/128"}, []string{"fe80::fa01/128"}) | ||
|
||
_, err = srv.Close(context.Background(), conn1) | ||
require.NoError(t, err) | ||
|
||
conn2, err = srv.Request(context.Background(), request) | ||
require.NoError(t, err) | ||
validateConns(t, conn2, []string{"fe80::/128", "fe80::fa00/128"}, []string{"fe80::1/128", "fe80::fa01/128"}) | ||
} | ||
|
||
func Test_StrictIPAM_PositiveScenario(t *testing.T) { | ||
_, ipNet, err := net.ParseCIDR("172.16.1.0/29") | ||
require.NoError(t, err) | ||
|
||
var s = strictipam.NewServer(func(i ...*net.IPNet) networkservice.NetworkServiceServer { | ||
return chain.NewNetworkServiceServer( | ||
checkrequest.NewServer(t, func(t *testing.T, nsr *networkservice.NetworkServiceRequest) { | ||
require.NotEqual(t, networkservice.IPContext{}, *nsr.GetConnection().Context.GetIpContext(), "ip context should not be empty") | ||
}), | ||
point2pointipam.NewServer(ipNet)) | ||
}, ipNet) | ||
|
||
_, err = s.Request(context.TODO(), &networkservice.NetworkServiceRequest{ | ||
Connection: &networkservice.Connection{ | ||
Context: &networkservice.ConnectionContext{ | ||
IpContext: &networkservice.IPContext{ | ||
SrcIpAddrs: []string{"172.16.1.0/32"}, | ||
}, | ||
}, | ||
}, | ||
}) | ||
require.NoError(t, err) | ||
} | ||
|
||
func TestNSEReplace(t *testing.T) { | ||
_, ipNet, err := net.ParseCIDR("172.16.2.0/29") | ||
require.NoError(t, err) | ||
|
||
srv := next.NewNetworkServiceServer(strictipam.NewServer(point2pointipam.NewServer, ipNet)) | ||
|
||
request := newRequest("id1") | ||
request.Connection.Context.IpContext.SrcIpAddrs = []string{"172.16.1.1/32"} | ||
request.Connection.Context.IpContext.DstIpAddrs = []string{"172.16.1.0/32"} | ||
request.Connection.Context.IpContext.SrcRoutes = []*networkservice.Route{{Prefix: "172.16.1.0/32"}} | ||
request.Connection.Context.IpContext.DstRoutes = []*networkservice.Route{{Prefix: "172.16.1.1/32"}} | ||
|
||
conn, err := srv.Request(context.Background(), request.Clone()) | ||
require.NoError(t, err) | ||
validateConns(t, conn, []string{"172.16.2.0/32"}, []string{"172.16.2.1/32"}) | ||
} |
Oops, something went wrong.