Skip to content

Commit

Permalink
use dns target for interdomain scenarious
Browse files Browse the repository at this point in the history
Signed-off-by: denis-tingaikin <denis.tingajkin@xored.com>
  • Loading branch information
denis-tingaikin committed Jan 16, 2024
1 parent 4d02ed4 commit 3c5143f
Show file tree
Hide file tree
Showing 31 changed files with 1,110 additions and 789 deletions.
51 changes: 50 additions & 1 deletion pkg/networkservice/chains/nsmgr/dns_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright (c) 2020-2022 Doc.ai and/or its affiliates.
//
// Copyright (c) 2023 Cisco and/or its affiliates.
// Copyright (c) 2023-2024 Cisco and/or its affiliates.
//
// SPDX-License-Identifier: Apache-2.0
//
Expand All @@ -24,13 +24,15 @@ package nsmgr_test
import (
"context"
"net"
"net/url"
"testing"
"time"

"github.com/edwarnicke/genericsync"
"github.com/networkservicemesh/api/pkg/api/networkservice"
"github.com/networkservicemesh/api/pkg/api/networkservice/mechanisms/cls"
kernelmech "github.com/networkservicemesh/api/pkg/api/networkservice/mechanisms/kernel"
"github.com/sirupsen/logrus"
"github.com/stretchr/testify/require"
"go.uber.org/goleak"

Expand All @@ -55,6 +57,53 @@ func requireIPv4Lookup(ctx context.Context, t *testing.T, r *net.Resolver, host,
require.Equal(t, expected, addrs[0].String())
}

func Test_LocalUsecase_DNSTarget(t *testing.T) {
t.Cleanup(func() { goleak.VerifyNone(t) })

ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
defer cancel()

domain := sandbox.NewBuilder(ctx, t).
SetNodesCount(1).
SetNSMgrProxySupplier(nil).
SetRegistryProxySupplier(nil).
SetupDefaultDNSServer().
Build()

nsRegistryClient := domain.NewNSRegistryClient(ctx, sandbox.GenerateTestToken)

nsReg, err := nsRegistryClient.Register(ctx, defaultRegistryService(t.Name()))
require.NoError(t, err)

nseReg := defaultRegistryEndpoint(nsReg.Name)

nse := domain.Nodes[0].NewEndpoint(ctx, nseReg, sandbox.GenerateTestToken)

var addr, _ = url.Parse("dns://" + domain.DNSServer.URL.Host + "/nsmgr-0.cluster.local:" + domain.Nodes[0].NSMgr.URL.Port())
logrus.Error(addr)
nsc := domain.Nodes[0].NewClient(ctx, sandbox.GenerateTestToken, client.WithClientURL(addr))

request := &networkservice.NetworkServiceRequest{
MechanismPreferences: []*networkservice.Mechanism{
{Cls: cls.LOCAL, Type: kernelmech.MECHANISM},
},
Connection: &networkservice.Connection{
Id: "1",
NetworkService: nsReg.Name,
Labels: make(map[string]string),
},
}

conn, err := nsc.Request(ctx, request)
require.NoError(t, err)

_, err = nsc.Close(ctx, conn)
require.NoError(t, err)

_, err = nse.Unregister(ctx, nseReg)
require.NoError(t, err)
}

func Test_DNSUsecase(t *testing.T) {
t.Cleanup(func() { goleak.VerifyNone(t) })

Expand Down
6 changes: 6 additions & 0 deletions pkg/networkservice/chains/nsmgr/single_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Copyright (c) 2020-2022 Doc.ai and/or its affiliates.
//
// Copyright (c) 2024 Cisco and/or its affiliates.
//
// SPDX-License-Identifier: Apache-2.0
//
// Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -520,13 +522,15 @@ func Test_FailedRegistryAuthorization(t *testing.T) {
ctx context.Context,
tokenGenerator token.GeneratorFunc,
expiryDuration time.Duration,
nsmgrProxyURL *url.URL,
proxyRegistryURL *url.URL,
options ...grpc.DialOption) registry.Registry {
registryName := sandbox.UniqueName("registry-memory")

return memory.NewServer(
ctx,
tokenGeneratorFunc("spiffe://test.com/"+registryName),
memory.WithNSMgrProxyURL(nsmgrProxyURL),
memory.WithProxyRegistryURL(proxyRegistryURL),
memory.WithDefaultExpiration(expiryDuration),
memory.WithDialOptions(options...),
Expand Down Expand Up @@ -691,12 +695,14 @@ func Test_Expire(t *testing.T) {
ctx context.Context,
tokenGenerator token.GeneratorFunc,
expiryDuration time.Duration,
nsmgrProxyURL *url.URL,
proxyRegistryURL *url.URL,
options ...grpc.DialOption) registry.Registry {
return memory.NewServer(
ctx,
tokenGenerator,
memory.WithProxyRegistryURL(proxyRegistryURL),
memory.WithNSMgrProxyURL(nsmgrProxyURL),
memory.WithDefaultExpiration(expiryDuration),
memory.WithDialOptions(options...),
memory.WithAuthorizeNSRegistryServer(
Expand Down
57 changes: 24 additions & 33 deletions pkg/networkservice/chains/nsmgr/vl3_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2022-2023 Cisco and/or its affiliates.
// Copyright (c) 2022-2024 Cisco and/or its affiliates.
//
// SPDX-License-Identifier: Apache-2.0
//
Expand Down Expand Up @@ -325,20 +325,17 @@ func Test_Interdomain_vl3_dns(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), time.Second*15)
defer cancel()

var dnsServer = sandbox.NewFakeResolver()

cluster1 := sandbox.NewBuilder(ctx, t).
SetNodesCount(1).
SetDNSResolver(dnsServer).
SetDNSDomainName("cluster1").
Build()

cluster2 := sandbox.NewBuilder(ctx, t).
SetNodesCount(1).
SetDNSDomainName("cluster2").
SetDNSResolver(dnsServer).
var domains = sandbox.NewInterdomainBuilder(ctx, t).
BuildDomain(func(b *sandbox.Builder) *sandbox.Builder {
return b.SetNodesCount(1).SetName("cluster1")
}).
BuildDomain(func(b *sandbox.Builder) *sandbox.Builder {
return b.SetNodesCount(1).SetName("cluster2")
}).
Build()

cluster1 := domains[0]
cluster2 := domains[1]
nsRegistryClient := cluster2.NewNSRegistryClient(ctx, sandbox.GenerateTestToken)

nsReg, err := nsRegistryClient.Register(ctx, defaultRegistryService("vl3"))
Expand Down Expand Up @@ -418,27 +415,21 @@ func Test_FloatingInterdomain_vl3_dns(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), time.Second*15)
defer cancel()

var dnsServer = sandbox.NewFakeResolver()

cluster1 := sandbox.NewBuilder(ctx, t).
SetNodesCount(1).
SetDNSResolver(dnsServer).
SetDNSDomainName("cluster1").
var domains = sandbox.NewInterdomainBuilder(ctx, t).
BuildDomain(func(b *sandbox.Builder) *sandbox.Builder {
return b.SetNodesCount(1).SetName("cluster1")
}).
BuildDomain(func(b *sandbox.Builder) *sandbox.Builder {
return b.SetNodesCount(1).SetName("cluster2")
}).
BuildDomain(func(b *sandbox.Builder) *sandbox.Builder {
return b.SetNodesCount(0).SetNSMgrProxySupplier(nil).SetRegistryProxySupplier(nil).SetName("floating")
}).
Build()

cluster2 := sandbox.NewBuilder(ctx, t).
SetNodesCount(1).
SetDNSDomainName("cluster2").
SetDNSResolver(dnsServer).
Build()

floating := sandbox.NewBuilder(ctx, t).
SetNodesCount(0).
SetDNSDomainName("floating.domain").
SetDNSResolver(dnsServer).
SetNSMgrProxySupplier(nil).
SetRegistryProxySupplier(nil).
Build()
cluster1 := domains[0]
cluster2 := domains[1]
floating := domains[2]

nsRegistryClient := cluster2.NewNSRegistryClient(ctx, sandbox.GenerateTestToken)

Expand Down Expand Up @@ -492,7 +483,7 @@ func Test_FloatingInterdomain_vl3_dns(t *testing.T) {
req.Connection = resp.Clone()
require.Len(t, resp.GetContext().GetDnsContext().GetConfigs(), 1)
require.Len(t, resp.GetContext().GetDnsContext().GetConfigs()[0].DnsServerIps, 1)
require.Len(t, resp.GetContext().GetDnsContext().GetConfigs()[0].SearchDomains, 3)
require.Len(t, resp.GetContext().GetDnsContext().GetConfigs()[0].SearchDomains, 2)

searchDomain := resp.GetContext().GetDnsContext().GetConfigs()[0].SearchDomains[0]

Expand Down
Loading

0 comments on commit 3c5143f

Please sign in to comment.