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

Add cidr groups #475

Merged
merged 1 commit into from
Sep 19, 2022
Merged
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
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...)
}