From dfdd6f2b5fd10051ebfa0566e822457f66e8ed36 Mon Sep 17 00:00:00 2001 From: Bharath Horatti Date: Fri, 9 Apr 2021 10:58:23 +0000 Subject: [PATCH] Support kernel-forwarder dataplane in vl3 Code changes needed to support kernel-forwarder data plane in vl3. The choice of dataplane between vpp and kernel-forwarder would be config driven through an env variable. --- cmd/vl3-nse/nse.go | 122 ++++++++++++++++++++++++++++----------------- 1 file changed, 75 insertions(+), 47 deletions(-) diff --git a/cmd/vl3-nse/nse.go b/cmd/vl3-nse/nse.go index 5c7081e..584dce7 100644 --- a/cmd/vl3-nse/nse.go +++ b/cmd/vl3-nse/nse.go @@ -25,6 +25,8 @@ import ( "github.com/networkservicemesh/networkservicemesh/controlplane/api/networkservice" "github.com/networkservicemesh/networkservicemesh/pkg/tools" "github.com/networkservicemesh/networkservicemesh/sdk/common" + "github.com/networkservicemesh/networkservicemesh/sdk/endpoint" + "github.com/networkservicemesh/networkservicemesh/controlplane/api/connectioncontext" "github.com/prometheus/client_golang/prometheus" "github.com/sirupsen/logrus" @@ -85,34 +87,6 @@ func (e vL3CompositeEndpoint) AddCompositeEndpoints(nsConfig *common.NSConfigura return &compositeEndpoints } -// exported the symbol named "CompositeEndpointPlugin" - -func main() { - // Capture signals to cleanup before exiting - logrus.Info("starting endpoint") - c := tools.NewOSSignalChannel() - - logrus.SetOutput(os.Stdout) - logrus.SetLevel(logrus.TraceLevel) - - mainFlags := &Flags{} - mainFlags.Process() - - InitializeMetrics() - - // Capture signals to cleanup before exiting - prometheus.NewBuildInfoCollector() - - ctx, cancel := context.WithCancel(context.Background()) - defer cancel() - vl3 := vL3CompositeEndpoint{} - ucnfNse := ucnf.NewUcnfNse(mainFlags.ConfigPath, mainFlags.Verify, &vppagent.UniversalCNFVPPAgentBackend{}, vl3, ctx) - logrus.Info("endpoint started") - - defer ucnfNse.Cleanup() - <-c -} - func InitializeMetrics() { metricsPort := os.Getenv(metricsPortEnv) if metricsPort == "" { @@ -123,37 +97,91 @@ func InitializeMetrics() { metrics.ServeMetrics(addr, metricsPath) } -/* var ( - nsmEndpoint *endpoint.NsmEndpoint + nsmEndpoint endpoint.NsmEndpoint ) +func getStringListFromString(str string) []string { + return strings.Split(str, ",") +} + func main() { // Capture signals to cleanup before exiting c := tools.NewOSSignalChannel() - composite := endpoint.NewCompositeEndpoint( - endpoint.NewMonitorEndpoint(nil), - endpoint.NewIpamEndpoint(nil), - newVL3ConnectComposite(nil), - endpoint.NewConnectionEndpoint(nil)) + logrus.SetOutput(os.Stdout) + logrus.SetLevel(logrus.TraceLevel) - nsme, err := endpoint.NewNSMEndpoint(context.TODO(), nil, composite) - if err != nil { - logrus.Fatalf("%v", err) - } - nsmEndpoint = nsme - _ = nsmEndpoint.Start() - logrus.Infof("Started NSE --got name %s", nsmEndpoint.GetName()) - defer func() { _ = nsmEndpoint.Delete() }() + dataplane := os.Getenv("DATAPLANE") - // Capture signals to cleanup before exiting - <-c + if dataplane == "vpp" { + + mainFlags := &Flags{} + mainFlags.Process() + + InitializeMetrics() + + // Capture signals to cleanup before exiting + prometheus.NewBuildInfoCollector() + + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + vl3 := vL3CompositeEndpoint{} + ucnfNse := ucnf.NewUcnfNse(mainFlags.ConfigPath, mainFlags.Verify, &vppagent.UniversalCNFVPPAgentBackend{}, vl3, ctx) + logrus.Info("endpoint started") + + defer ucnfNse.Cleanup() + <-c + + } else { + + configuration := common.FromEnv() + + endpoints := []networkservice.NetworkServiceServer{ + endpoint.NewMonitorEndpoint(configuration), + endpoint.NewConnectionEndpoint(configuration), + endpoint.NewIpamEndpoint(configuration), + } + + dstRoutes := os.Getenv("DST_ROUTES") + if dstRoutes != "" { + dstRouteMutator := endpoint.CreateRouteMutator(getStringListFromString(dstRoutes)) + endpoints = append(endpoints, endpoint.NewCustomFuncEndpoint("route", dstRouteMutator)) + } + + dnsNameServers := os.Getenv("DNS_NAMESERVERS") + dnsDomains := os.Getenv("DNS_DOMAINS") + if dnsNameServers != "" { + dnsMutator := endpoint.NewAddDNSConfigs(&connectioncontext.DNSConfig{ + DnsServerIps: getStringListFromString(dnsNameServers), + SearchDomains: getStringListFromString(dnsDomains), + }) + endpoints = append(endpoints, dnsMutator) + } + + composite := endpoint.NewCompositeEndpoint(endpoints...) + + nsme, err := endpoint.NewNSMEndpoint(context.Background(), configuration, composite) + if err != nil { + logrus.Fatalf("%v", err) + } + + nsmEndpoint = nsme + + err = nsme.Start() + if err != nil { + logrus.Fatalf("Unable to start the endpoint: %v", err) + } + + logrus.Infof("Started NSE --got name %s", nsme.GetName()) + defer func() { _ = nsme.Delete() }() + + // Capture signals to cleanup before exiting + <-c + } } func GetMyNseName() string { return nsmEndpoint.GetName() } - -*/