forked from networkservicemesh/sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: apply changes for distributed vl3 dns after manual testing (netw…
…orkservicemesh#1315) * apply vl3dns fixes Signed-off-by: Denis Tingaikin <denis.tingajkin@xored.com> * fix linter issues Signed-off-by: denis-tingaikin <denis.tingajkin@xored.com> * handle corner cases Signed-off-by: Denis Tingaikin <denis.tingajkin@xored.com> Signed-off-by: anastasia.malysheva <anastasia.malysheva@xored.com>
- Loading branch information
1 parent
7eccc15
commit 9bbbceb
Showing
6 changed files
with
246 additions
and
51 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
84 changes: 84 additions & 0 deletions
84
pkg/networkservice/connectioncontext/dnscontext/vl3dns/client.go
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,84 @@ | ||
// Copyright (c) 2022 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 vl3dns | ||
|
||
import ( | ||
"context" | ||
"net" | ||
|
||
"github.com/golang/protobuf/ptypes/empty" | ||
"github.com/networkservicemesh/api/pkg/api/networkservice" | ||
"google.golang.org/grpc" | ||
|
||
"github.com/networkservicemesh/sdk/pkg/networkservice/core/next" | ||
) | ||
|
||
type vl3DNSClient struct { | ||
dnsServerIP net.IP | ||
dnsConfigs *Map | ||
} | ||
|
||
// NewClient - returns a new null client that does nothing but call next.Client(ctx).{Request/Close} and return the result | ||
// This is very useful in testing | ||
func NewClient(dnsServerIP net.IP, dnsConfigs *Map) networkservice.NetworkServiceClient { | ||
return &vl3DNSClient{ | ||
dnsServerIP: dnsServerIP, | ||
dnsConfigs: dnsConfigs, | ||
} | ||
} | ||
|
||
func (n *vl3DNSClient) Request(ctx context.Context, request *networkservice.NetworkServiceRequest, opts ...grpc.CallOption) (*networkservice.Connection, error) { | ||
if request.GetConnection() == nil { | ||
request.Connection = new(networkservice.Connection) | ||
} | ||
if request.GetConnection().GetContext() == nil { | ||
request.GetConnection().Context = new(networkservice.ConnectionContext) | ||
} | ||
if request.GetConnection().GetContext().GetDnsContext() == nil { | ||
request.GetConnection().GetContext().DnsContext = new(networkservice.DNSContext) | ||
} | ||
|
||
request.GetConnection().GetContext().GetDnsContext().Configs = []*networkservice.DNSConfig{ | ||
{ | ||
DnsServerIps: []string{n.dnsServerIP.String()}, | ||
}, | ||
} | ||
resp, err := next.Client(ctx).Request(ctx, request, opts...) | ||
|
||
if err == nil { | ||
for _, config := range resp.GetContext().GetDnsContext().GetConfigs() { | ||
var skip = false | ||
for _, ip := range config.DnsServerIps { | ||
if ip == n.dnsServerIP.String() { | ||
skip = true | ||
break | ||
} | ||
} | ||
if skip { | ||
continue | ||
} | ||
n.dnsConfigs.Store(resp.GetId(), config) | ||
} | ||
} | ||
|
||
return resp, err | ||
} | ||
|
||
func (n *vl3DNSClient) Close(ctx context.Context, conn *networkservice.Connection, opts ...grpc.CallOption) (*empty.Empty, error) { | ||
n.dnsConfigs.Delete(conn.GetId()) | ||
return next.Client(ctx).Close(ctx, conn, opts...) | ||
} |
26 changes: 26 additions & 0 deletions
26
pkg/networkservice/connectioncontext/dnscontext/vl3dns/gen.go
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,26 @@ | ||
// Copyright (c) 2022 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 vl3dns | ||
|
||
import ( | ||
"sync" | ||
) | ||
|
||
//go:generate go-syncmap -output map.gen.go -type Map<string,*github.com/networkservicemesh/api/pkg/api/networkservice.DNSConfig> | ||
|
||
// Map - sync.Map with key == string and value == networkservice.DNSConfig | ||
type Map sync.Map |
75 changes: 75 additions & 0 deletions
75
pkg/networkservice/connectioncontext/dnscontext/vl3dns/map.gen.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Oops, something went wrong.