Skip to content

Commit

Permalink
Merge pull request #475 from glazychev-art/cidr_groups
Browse files Browse the repository at this point in the history
Add cidr groups
  • Loading branch information
denis-tingaikin authored Sep 19, 2022
2 parents aed5ce1 + 0b0872b commit c831d7d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
1 change: 1 addition & 0 deletions internal/imports/imports_linux.go

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

21 changes: 15 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ import (
registryclient "github.com/networkservicemesh/sdk/pkg/registry/chains/client"
"github.com/networkservicemesh/sdk/pkg/registry/common/clientinfo"
registrysendfd "github.com/networkservicemesh/sdk/pkg/registry/common/sendfd"
"github.com/networkservicemesh/sdk/pkg/tools/cidr"
"github.com/networkservicemesh/sdk/pkg/tools/debug"
"github.com/networkservicemesh/sdk/pkg/tools/grpcutils"
"github.com/networkservicemesh/sdk/pkg/tools/log"
Expand All @@ -75,7 +76,7 @@ type Config struct {
ServiceNames []string `default:"icmp-responder" desc:"Name of providing service" split_words:"true"`
Payload string `default:"ETHERNET" desc:"Name of provided service payload" split_words:"true"`
Labels map[string]string `default:"" desc:"Endpoint labels"`
CidrPrefix string `default:"169.254.0.0/16" desc:"CIDR Prefix to assign IPs from" split_words:"true"`
CidrPrefix cidr.Groups `default:"169.254.0.0/16" desc:"CIDR Prefix to assign IPs from" split_words:"true"`
RegisterService bool `default:"true" desc:"if true then registers network service on startup" split_words:"true"`
LogLevel string `default:"INFO" desc:"Log level" split_words:"true"`
OpenTelemetryEndpoint string `default:"otel-collector.observability.svc.cluster.local:4317" desc:"OpenTelemetry Collector Endpoint"`
Expand Down Expand Up @@ -174,10 +175,10 @@ func main() {
// ********************************************************************************
log.FromContext(ctx).Infof("executing phase 3: creating icmp server ipam")
// ********************************************************************************
_, ipnet, err := net.ParseCIDR(config.CidrPrefix)
if err != nil {
log.FromContext(ctx).Fatalf("error parsing cidr: %+v", err)
}

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")
Expand All @@ -190,7 +191,7 @@ func main() {
endpoint.WithName(config.Name),
endpoint.WithAuthorizeServer(authorize.NewServer()),
endpoint.WithAdditionalFunctionality(
point2pointipam.NewServer(ipnet),
ipamChain,
mechanisms.NewServer(map[string]networkservice.NetworkServiceServer{
memif.MECHANISM: chain.NewNetworkServiceServer(
sendfd.NewServer(),
Expand Down Expand Up @@ -320,3 +321,11 @@ 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 c831d7d

Please sign in to comment.