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

Remove duplicated IPAM code #513

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
3 changes: 1 addition & 2 deletions internal/imports/imports_linux.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 9 additions & 27 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2021-2022 Doc.ai and/or its affiliates.
// Copyright (c) 2021-2023 Doc.ai and/or its affiliates.
//
// SPDX-License-Identifier: Apache-2.0
//
Expand All @@ -23,7 +23,6 @@ import (
"context"
"crypto/tls"
"io/ioutil"
"net"
"net/url"
"os"
"os/signal"
Expand Down Expand Up @@ -53,7 +52,7 @@ import (
"github.com/networkservicemesh/sdk/pkg/networkservice/common/mechanisms"
"github.com/networkservicemesh/sdk/pkg/networkservice/common/mechanisms/sendfd"
"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 @@ -118,10 +117,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 @@ -176,15 +174,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")
// ********************************************************************************
vppConn, vppErrCh := vpphelper.StartAndDialContext(ctx)
exitOnErr(ctx, cancel, vppErrCh)
Expand All @@ -194,7 +184,7 @@ func main() {
endpoint.WithName(config.Name),
endpoint.WithAuthorizeServer(authorize.NewServer()),
endpoint.WithAdditionalFunctionality(
ipamChain,
groupipam.NewServer(config.CidrPrefix),
mechanisms.NewServer(map[string]networkservice.NetworkServiceServer{
memif.MECHANISM: chain.NewNetworkServiceServer(
sendfd.NewServer(),
Expand All @@ -207,7 +197,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 @@ -232,7 +222,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 @@ -324,11 +314,3 @@ func notifyContext() (context.Context, context.CancelFunc) {
syscall.SIGQUIT,
)
}

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...)
}