Skip to content

Commit

Permalink
Remove duplicated IPAM code for NSE applications
Browse files Browse the repository at this point in the history
NSM issue link: networkservicemesh/sdk#1409

Signed-off-by: Botond Szirtes <botond.szirtes@est.tech>
  • Loading branch information
bszirtes committed Mar 22, 2024
1 parent 027947a commit 6ccc85c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 28 deletions.
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: 10 additions & 26 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
//
// Copyright (c) 2023 Cisco and/or its affiliates.
//
// Copyright (c) 2024 Nordix Foundation.
//
// SPDX-License-Identifier: Apache-2.0
//
// Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -24,7 +26,6 @@ package main
import (
"context"
"crypto/tls"
"net"
"net/url"
"os"
"os/signal"
Expand Down Expand Up @@ -55,7 +56,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 @@ -121,10 +122,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 @@ -179,15 +179,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 @@ -197,7 +189,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 @@ -210,7 +202,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 @@ -235,7 +227,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 @@ -327,11 +319,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...)
}

0 comments on commit 6ccc85c

Please sign in to comment.