Skip to content

Commit

Permalink
Merge pull request #500 from wazsone/feature/remove-duplicated-ipam-code
Browse files Browse the repository at this point in the history
Remove duplicated IPAM code
  • Loading branch information
denis-tingaikin authored Jan 26, 2023
2 parents 9b92949 + c7c2485 commit 02f6c85
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 38 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require (
github.com/edwarnicke/grpcfd v1.1.2
github.com/kelseyhightower/envconfig v1.4.0
github.com/networkservicemesh/api v1.6.2-0.20221205183940-84c7ff837cdd
github.com/networkservicemesh/sdk v0.5.1-0.20221219152652-beec79b7ec9d
github.com/networkservicemesh/sdk v0.5.1-0.20230109230417-1492e69a650d
github.com/networkservicemesh/sdk-sriov v0.0.0-20221219180322-513bee7f52b7
github.com/pkg/errors v0.9.1
github.com/sirupsen/logrus v1.9.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,8 @@ github.com/miekg/dns v1.1.50 h1:DQUfb9uc6smULcREF09Uc+/Gd46YWqJd5DbpPE9xkcA=
github.com/miekg/dns v1.1.50/go.mod h1:e3IlAVfNqAllflbibAZEWOXOQ+Ynzk/dDozDxY7XnME=
github.com/networkservicemesh/api v1.6.2-0.20221205183940-84c7ff837cdd h1:26HR90HrJFZHIPPP3SCLGNRpPCMFoEnSSZfhHH8MPSo=
github.com/networkservicemesh/api v1.6.2-0.20221205183940-84c7ff837cdd/go.mod h1:hOF2844BSstH1311oDMDgqqXS+kdc77htZNPRKl9mf8=
github.com/networkservicemesh/sdk v0.5.1-0.20221219152652-beec79b7ec9d h1:cx0Z/xWuoW0JS3VmA+5Ckg5g+iirB7RJglGDnJzmGEo=
github.com/networkservicemesh/sdk v0.5.1-0.20221219152652-beec79b7ec9d/go.mod h1:++MSpR2wuFlCpCYoR6lELxJ4ILKd650vDQ8d9CtGAzA=
github.com/networkservicemesh/sdk v0.5.1-0.20230109230417-1492e69a650d h1:1EhczRkzfkutymvDj5XYinD68omLpFk2F2kJdhzYG+U=
github.com/networkservicemesh/sdk v0.5.1-0.20230109230417-1492e69a650d/go.mod h1:++MSpR2wuFlCpCYoR6lELxJ4ILKd650vDQ8d9CtGAzA=
github.com/networkservicemesh/sdk-sriov v0.0.0-20221219180322-513bee7f52b7 h1:warFgkj/xEmiV/KK33MQzOY/D54KHP4duCn+dSQf+0I=
github.com/networkservicemesh/sdk-sriov v0.0.0-20221219180322-513bee7f52b7/go.mod h1:uClz/S+Ty0doAV+ZKL+gg0PBkY9F6vyelPG40K4VVxw=
github.com/open-policy-agent/opa v0.44.0 h1:sEZthsrWBqIN+ShTMJ0Hcz6a3GkYsY4FaB2S/ou2hZk=
Expand Down
4 changes: 1 addition & 3 deletions internal/pkg/imports/imports_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ import (
_ "github.com/networkservicemesh/sdk/pkg/networkservice/common/onidle"
_ "github.com/networkservicemesh/sdk/pkg/networkservice/common/policyroute"
_ "github.com/networkservicemesh/sdk/pkg/networkservice/connectioncontext/dnscontext"
_ "github.com/networkservicemesh/sdk/pkg/networkservice/core/chain"
_ "github.com/networkservicemesh/sdk/pkg/networkservice/ipam/point2pointipam"
_ "github.com/networkservicemesh/sdk/pkg/networkservice/ipam/groupipam"
_ "github.com/networkservicemesh/sdk/pkg/registry/chains/client"
_ "github.com/networkservicemesh/sdk/pkg/registry/common/authorize"
_ "github.com/networkservicemesh/sdk/pkg/registry/common/begin"
Expand Down Expand Up @@ -65,7 +64,6 @@ import (
_ "google.golang.org/grpc/credentials"
_ "google.golang.org/grpc/health/grpc_health_v1"
_ "gopkg.in/yaml.v2"
_ "net"
_ "net/url"
_ "os"
_ "os/signal"
Expand Down
39 changes: 10 additions & 29 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright (c) 2020-2022 Doc.ai and/or its affiliates.
// Copyright (c) 2021-2022 Nordix and/or its affiliates.
// Copyright (c) 2020-2023 Doc.ai and/or its affiliates.
// Copyright (c) 2021-2023 Nordix and/or its affiliates.
//
// SPDX-License-Identifier: Apache-2.0
//
Expand All @@ -24,7 +24,6 @@ import (
"context"
"crypto/tls"
"fmt"
"net"
"net/url"
"os"
"os/signal"
Expand Down Expand Up @@ -61,8 +60,7 @@ import (
"github.com/networkservicemesh/sdk/pkg/networkservice/common/onidle"
"github.com/networkservicemesh/sdk/pkg/networkservice/common/policyroute"
"github.com/networkservicemesh/sdk/pkg/networkservice/connectioncontext/dnscontext"
"github.com/networkservicemesh/sdk/pkg/networkservice/core/chain"
"github.com/networkservicemesh/sdk/pkg/networkservice/ipam/point2pointipam"
"github.com/networkservicemesh/sdk/pkg/networkservice/ipam/groupipam"
registryclient "github.com/networkservicemesh/sdk/pkg/registry/chains/client"
registryauthorize "github.com/networkservicemesh/sdk/pkg/registry/common/authorize"
"github.com/networkservicemesh/sdk/pkg/registry/common/clientinfo"
Expand Down Expand Up @@ -140,10 +138,9 @@ func main() {
log.FromContext(ctx).Infof("the phases include:")
log.FromContext(ctx).Infof("1: get config from environment")
log.FromContext(ctx).Infof("2: retrieve spiffe svid")
log.FromContext(ctx).Infof("3: create icmp server ipam")
log.FromContext(ctx).Infof("4: create icmp server nse")
log.FromContext(ctx).Infof("5: create grpc and mount nse")
log.FromContext(ctx).Infof("6: register nse with nsm")
log.FromContext(ctx).Infof("3: create icmp server nse")
log.FromContext(ctx).Infof("4: create grpc and mount nse")
log.FromContext(ctx).Infof("5: register nse with nsm")
log.FromContext(ctx).Infof("a final success message with start time duration")

starttime := time.Now()
Expand Down Expand Up @@ -197,15 +194,7 @@ func main() {
tlsServerConfig.MinVersion = tls.VersionTLS12

// ********************************************************************************
log.FromContext(ctx).Infof("executing phase 3: creating icmp server ipam")
// ********************************************************************************

ipamChain := getIPAMChain(config.CidrPrefix)

log.FromContext(ctx).Infof("network prefixes parsed successfully")

// ********************************************************************************
log.FromContext(ctx).Infof("executing phase 4: create icmp-server network service endpoint")
log.FromContext(ctx).Infof("executing phase 3: create icmp-server network service endpoint")
// ********************************************************************************

tokenServer := getSriovTokenServerChainElement(ctx)
Expand All @@ -216,7 +205,7 @@ func main() {
endpoint.WithAuthorizeServer(authorize.NewServer()),
endpoint.WithAdditionalFunctionality(
onidle.NewServer(ctx, cancel, config.IdleTimeout),
ipamChain,
groupipam.NewServer(config.CidrPrefix),
policyroute.NewServer(newPolicyRoutesGetter(ctx, config.PBRConfigPath).Get),
recvfd.NewServer(),
mechanisms.NewServer(map[string]networkservice.NetworkServiceServer{
Expand All @@ -229,7 +218,7 @@ func main() {
),
)
// ********************************************************************************
log.FromContext(ctx).Infof("executing phase 5: create grpc server and register icmp-server")
log.FromContext(ctx).Infof("executing phase 4: create grpc server and register icmp-server")
// ********************************************************************************
options := append(
tracing.WithTracing(),
Expand All @@ -254,7 +243,7 @@ func main() {
log.FromContext(ctx).Infof("grpc server started")

// ********************************************************************************
log.FromContext(ctx).Infof("executing phase 6: register nse with nsm")
log.FromContext(ctx).Infof("executing phase 5: register nse with nsm")
// ********************************************************************************
clientOptions := append(
tracing.WithTracingDial(),
Expand Down Expand Up @@ -405,11 +394,3 @@ type policyRoutesGetter struct {
ctx context.Context
policyRoutes atomic.Value
}

func getIPAMChain(cIDRGroups [][]*net.IPNet) networkservice.NetworkServiceServer {
var ipamchain []networkservice.NetworkServiceServer
for _, cidrGroup := range cIDRGroups {
ipamchain = append(ipamchain, point2pointipam.NewServer(cidrGroup...))
}
return chain.NewNetworkServiceServer(ipamchain...)
}
6 changes: 3 additions & 3 deletions suite_setup_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) 2020-2023 Doc.ai and/or its affiliates.
//
// Copyright (c) 2020-2022 Cisco and/or its affiliates.
// Copyright (c) 2020-2023 Cisco and/or its affiliates.
//
// SPDX-License-Identifier: Apache-2.0
//
Expand Down Expand Up @@ -119,7 +119,7 @@ func (f *TestSuite) SetupSuite() {
registrybegin.NewNetworkServiceEndpointRegistryServer(),
updatepath.NewNetworkServiceEndpointRegistryServer(spiffejwt.TokenGeneratorFunc(source, f.config.MaxTokenLifetime)),
authorize.NewNetworkServiceEndpointRegistryServer(),
expire.NewNetworkServiceEndpointRegistryServer(f.ctx, time.Minute),
expire.NewNetworkServiceEndpointRegistryServer(f.ctx, expire.WithDefaultExpiration(time.Minute)),
registryrecvfd.NewNetworkServiceEndpointRegistryServer(),
memrg,
)
Expand Down

0 comments on commit 02f6c85

Please sign in to comment.