diff --git a/cli/capabilities.go b/cli/capabilities.go index 215380e3bde648388584b9ccdf042633c4bcf1ea..a972822b1ab086bd3f7ed0c81104c07a861fc526 100644 --- a/cli/capabilities.go +++ b/cli/capabilities.go @@ -9,11 +9,13 @@ import ( "strings" ) -func Capabilities() error { +// Capabilities sends a gNMI Capabilities request to the specified target +// and prints the supported models to stdout +func Capabilities(a, u , p string) error { cfg := gnmi.Config{ - Addr: "portainer.danet.fbi.h-da.de:6030", - Username: "admin", - Password: "arista", + Addr: a, + Username: u, + Password: p, Encoding: gpb.Encoding_JSON_IETF, } opts := &nucleus.GnmiTransportOptions{Config: cfg} diff --git a/cli/get.go b/cli/get.go index f5e1e061581c956c691f45313ae44f8d7e42b8e9..a0984961c5acd325f8bdefb010ee62c3c224ca41 100644 --- a/cli/get.go +++ b/cli/get.go @@ -3,54 +3,31 @@ package cli import ( "code.fbi.h-da.de/cocsn/gosdn/forks/goarista/gnmi" "code.fbi.h-da.de/cocsn/gosdn/nucleus" - "github.com/google/uuid" + "context" gpb "github.com/openconfig/gnmi/proto/gnmi" log "github.com/sirupsen/logrus" ) -/* - Simple gnmi request program. Use with cauton and leaf paths only. - Bootstrapping of pnd, device and transport simplified not idiomatic -*/ - -func Get() error { +// Get sends a gNMI Get request to the specified target and prints the response to stdout +func Get(a, u, p string, args...string) error { sbi := &nucleus.OpenConfig{} opts := &nucleus.GnmiTransportOptions{ Config: gnmi.Config{ - Addr: "portainer.danet.fbi.h-da.de:6030", - Username: "admin", - Password: "arista", + Addr: a, + Username: u, + Password: p, Encoding: gpb.Encoding_JSON_IETF, }, SetNode: sbi.SetNode(), } - device, err := nucleus.NewDevice(sbi, opts) + t, err := nucleus.NewGnmiTransport(opts) if err != nil { return err } - pnd, err := nucleus.NewPND("openconfig", "test description", uuid.New(), sbi) + resp, err := t.Get(context.Background(), args...) if err != nil { return err } - if err := pnd.AddDevice(device); err != nil { - return err - } - - p := []string{"/interfaces/interface"} - errors := 0 - for _, path := range p { - err := pnd.RequestAll(path) - if err != nil { - log.Debug(err) - errors++ - break - } - } - - percentage := float64(errors) / float64(len(p)) * 100.0 - if errors != 0 { - log.Error("%v errors", errors) - log.Error("%v percent failed", percentage) - } + log.Info(resp) return nil } diff --git a/cli/init.go b/cli/init.go index c4c06a575e88d4b783d961c0c21afe1c03f342ee..44d5df8ea052f9c138a895dae446259c87024b8f 100644 --- a/cli/init.go +++ b/cli/init.go @@ -6,11 +6,11 @@ import ( log "github.com/sirupsen/logrus" ) -var schema *ytypes.Schema +var testSchema *ytypes.Schema func init(){ var err error - schema, err = model.Schema() + testSchema, err = model.Schema() if err != nil { log.Fatal(err) } diff --git a/cli/path_traversal.go b/cli/path_traversal.go index 06f2dbf3709cbcc99539fac03a299daad0bcab2d..1be78ec58e763451180293e26fc084ef63edaf00 100644 --- a/cli/path_traversal.go +++ b/cli/path_traversal.go @@ -7,7 +7,7 @@ import ( func PathTraversal() error { log.SetLevel(log.DebugLevel) - paths, err := path.ParseSchema(schema, "device") + paths, err := path.ParseSchema(testSchema, "device") if err != nil { return err } diff --git a/cli/set.go b/cli/set.go index e818caeb7e4556931cbd807e23fe2f312577f3a9..50dda7bb1af3d7310243d38f22e470ff78499a98 100644 --- a/cli/set.go +++ b/cli/set.go @@ -6,20 +6,16 @@ import ( "code.fbi.h-da.de/cocsn/gosdn/nucleus/util/proto" "context" pb "google.golang.org/protobuf/proto" - "os" ) -func Set() error { - a := os.Getenv("GOSDN_TEST_ENDPOINT") - if a == "" { - a = "portainer.danet.fbi.h-da.de:6030" - } - +// Set sends a gNMI Set request to the specified target. Only one +// request per invocation supported. +func Set(a, u, p, typ string, args ...string) error { opts := &nucleus.GnmiTransportOptions{ Config: gnmi.Config{ Addr: a, - Username: "admin", - Password: "arista", + Username: u, + Password: p, }, } t, err := nucleus.NewGnmiTransport(opts) @@ -27,21 +23,18 @@ func Set() error { return err } - reqs := []interface{}{ + path := gnmi.SplitPath(args[0]) + req := []interface{}{ &gnmi.Operation{ - Type: "update", + Type: typ, Origin: "", Target: "", - Path: []string{ - "system", - "config", - "hostname", - }, - Val: "ceos3000", + Path: path, + Val: args[1], }, } - resp, err := t.Set(context.Background(), reqs...) + resp, err := t.Set(context.Background(), req...) if err != nil { return err } diff --git a/cli/subscribe.go b/cli/subscribe.go index e953c070efa054bc598af2ceacc9132ef0ccf354..bfdd9d008d48b52a02e0d846b88412ad8088faac 100644 --- a/cli/subscribe.go +++ b/cli/subscribe.go @@ -5,7 +5,6 @@ import ( "code.fbi.h-da.de/cocsn/gosdn/nucleus" "context" "fmt" - "github.com/google/uuid" gpb "github.com/openconfig/gnmi/proto/gnmi" log "github.com/sirupsen/logrus" "os" @@ -13,46 +12,38 @@ import ( "syscall" "time" ) - -func Subscribe() error{ +// Subscribe starts a gNMI subscriber requersting the specified paths on the target and +// logs the response to stdout. Only 'stream' mode with 'sample' operation supported. +func Subscribe(a, u, p string, sample, heartbeat int64, args...string) error{ log.SetLevel(log.DebugLevel) sbi := &nucleus.OpenConfig{} - - device, err := nucleus.NewDevice(sbi, - &nucleus.GnmiTransportOptions{ - Config: gnmi.Config{ - Addr: "portainer.danet.fbi.h-da.de:6030", - Username: "admin", - Password: "arista", - Encoding: gpb.Encoding_JSON_IETF, - }, - SetNode: sbi.SetNode(), - RespChan: make(chan *gpb.SubscribeResponse), - }) - if err != nil { - return err + tOpts := &nucleus.GnmiTransportOptions{ + Config: gnmi.Config{ + Addr: a, + Username: u, + Password: p, + Encoding: gpb.Encoding_JSON_IETF, + }, + SetNode: sbi.SetNode(), + RespChan: make(chan *gpb.SubscribeResponse), } - pnd, err := nucleus.NewPND("openconfig", "a simple openconfig PND", uuid.New(), sbi) + + device, err := nucleus.NewDevice(sbi,tOpts) if err != nil { return err } - if err := pnd.AddDevice(device); err != nil { - return err - } - - paths := []string{"/interfaces/interface/name"} opts := &gnmi.SubscribeOptions{ UpdatesOnly: false, Prefix: "", Mode: "stream", StreamMode: "sample", - SampleInterval: uint64(10 * time.Second.Nanoseconds()), + SampleInterval: uint64(sample * time.Second.Nanoseconds()), SuppressRedundant: false, - HeartbeatInterval: uint64(time.Second.Nanoseconds()), - Paths: gnmi.SplitPaths(paths), + HeartbeatInterval: uint64(heartbeat * time.Second.Nanoseconds()), + Paths: gnmi.SplitPaths(args), Origin: "", - Target: "portainer.danet.fbi.h-da.de:6030", + Target: a, } done := make(chan os.Signal, 1) signal.Notify(done, syscall.SIGILL, syscall.SIGTERM) diff --git a/cli/target.go b/cli/target.go index 0513487ac803622578bff56374759a19d3f0a656..c81936375abd30d3a251e075f0adaecbd2274028 100644 --- a/cli/target.go +++ b/cli/target.go @@ -2,12 +2,12 @@ package cli import ( "code.fbi.h-da.de/cocsn/gosdn/forks/google/gnmi" - "code.fbi.h-da.de/cocsn/gosdn/forks/google/gnmi/modeldata" - oc "code.fbi.h-da.de/cocsn/yang-models/generated/arista" + oc "code.fbi.h-da.de/cocsn/yang-models/generated/openconfig" "context" - "flag" "github.com/google/gnxi/utils/credentials" pb "github.com/openconfig/gnmi/proto/gnmi" + "github.com/openconfig/goyang/pkg/yang" + "github.com/openconfig/ygot/util" "github.com/openconfig/ygot/ygot" log "github.com/sirupsen/logrus" "google.golang.org/grpc" @@ -18,10 +18,6 @@ import ( "reflect" ) -var ( - bindAddr = flag.String("bind_address", ":9339", "Bind to address:port or just :port") -) - type server struct { *gnmi.Server } @@ -65,10 +61,20 @@ func (s *server) Set(ctx context.Context, req *pb.SetRequest) (*pb.SetResponse, } */ -func Target() error { +// Target starts a gNMI target listening on the specified port. +func Target(bindAddr string) error { + entries := make([]*yang.Entry, 0) + for _,e := range oc.SchemaTree { + entries = append(entries, e) + } + modelData, err := util.FindModelData(entries) + if err != nil { + return err + } // Google stuff from here - model := gnmi.NewModel(modeldata.ModelData, + model := gnmi.NewModel( + modelData, reflect.TypeOf((*oc.Device)(nil)), oc.SchemaTree["Device"], oc.Unmarshal, @@ -84,8 +90,8 @@ func Target() error { pb.RegisterGNMIServer(g, s) reflection.Register(g) - log.Infof("starting to listen on %s", *bindAddr) - listen, err := net.Listen("tcp", *bindAddr) + log.Infof("starting to listen on %s", bindAddr) + listen, err := net.Listen("tcp", bindAddr) if err != nil { return err } diff --git a/cli/ygot.go b/cli/ygot.go index e89e7cffe50675385994c25b609054df5b2c0037..a414ff2a8c43add11d4d99491fe342a49e9ab3f0 100644 --- a/cli/ygot.go +++ b/cli/ygot.go @@ -6,7 +6,7 @@ import ( ) func LeafPaths() error { - for _,v := range schema.SchemaTree { + for _,v := range testSchema.SchemaTree { entry, err := util.FindLeafRefSchema(v, "/interface/") if err != nil { log.Error(err) diff --git a/cmd/capabilities.go b/cmd/capabilities.go index 69f1bbb460acc11e2dd233ffefd7cad18aefe416..623de1c425c80bba4490af218162b9238243a501 100644 --- a/cmd/capabilities.go +++ b/cmd/capabilities.go @@ -38,15 +38,11 @@ import ( // capabilitiesCmd represents the capabilities command var capabilitiesCmd = &cobra.Command{ Use: "capabilities", - Short: "A brief description of your command", - Long: `A longer description that spans multiple lines and likely contains examples -and usage of using your command. For example: - -Cobra is a CLI library for Go that empowers applications. -This application is a tool to generate the needed files -to quickly create a Cobra application.`, + Short: "capabilities request", + Long: `Sends a gNMI Capabilities request to the specified target +// and prints the supported models to stdout.`, RunE: func(cmd *cobra.Command, args []string) error { - return cli.Capabilities() + return cli.Capabilities(username, password, address) }, } diff --git a/cmd/get.go b/cmd/get.go index 2eecd66344539a486fe24562164bed88d8bebdcc..8cd17622d5c5c62ec7aeaba21932536eac260544 100644 --- a/cmd/get.go +++ b/cmd/get.go @@ -37,29 +37,14 @@ import ( // getCmd represents the get command var getCmd = &cobra.Command{ - Use: "get", - Short: "A brief description of your command", - Long: `A longer description that spans multiple lines and likely contains examples -and usage of using your command. For example: - -Cobra is a CLI library for Go that empowers applications. -This application is a tool to generate the needed files -to quickly create a Cobra application.`, + Use: "gosdn get", + Short: "get request", + Long: `Sends a gNMI Get request to the specified target and prints the response to stdout`, RunE: func(cmd *cobra.Command, args []string) error { - return cli.Get() + return cli.Get(address, username, password, args...) }, } func init() { rootCmd.AddCommand(getCmd) - - // Here you will define your flags and configuration settings. - - // Cobra supports Persistent Flags which will work for this command - // and all subcommands, e.g.: - // getCmd.PersistentFlags().String("foo", "", "A help for foo") - - // Cobra supports local flags which will only run when this command - // is called directly, e.g.: - // getCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") } diff --git a/cmd/legacy.go b/cmd/legacy.go index 183857713ed710971882783733828e1cdecb7d5b..8d589320f5c19e6df9c6a5df3e8ae6289ecde719 100644 --- a/cmd/legacy.go +++ b/cmd/legacy.go @@ -31,35 +31,20 @@ POSSIBILITY OF SUCH DAMAGE. package cmd import ( - "code.fbi.h-da.de/cocsn/gosdn/cli" + "errors" "github.com/spf13/cobra" ) // legacyCmd represents the legacy command var legacyCmd = &cobra.Command{ Use: "legacy", - Short: "A brief description of your command", - Long: `A longer description that spans multiple lines and likely contains examples -and usage of using your command. For example: - -Cobra is a CLI library for Go that empowers applications. -This application is a tool to generate the needed files -to quickly create a Cobra application.`, + Short: "multiple ygot utils - not yet implemented", + Long: ``, RunE: func(cmd *cobra.Command, args []string) error { - return cli.PathTraversal() + return errors.New("not implemented") }, } func init() { pathCmd.AddCommand(legacyCmd) - - // Here you will define your flags and configuration settings. - - // Cobra supports Persistent Flags which will work for this command - // and all subcommands, e.g.: - // legacyCmd.PersistentFlags().String("foo", "", "A help for foo") - - // Cobra supports local flags which will only run when this command - // is called directly, e.g.: - // legacyCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") } diff --git a/cmd/path.go b/cmd/path.go index 713265798520f46a5afb98a3abf227338d7cdece..0c4b45da9790f81c3574f8410bb32abf7af698c4 100644 --- a/cmd/path.go +++ b/cmd/path.go @@ -38,28 +38,13 @@ import ( // pathCmd represents the path command var pathCmd = &cobra.Command{ Use: "path", - Short: "A brief description of your command", - Long: `A longer description that spans multiple lines and likely contains examples -and usage of using your command. For example: - -Cobra is a CLI library for Go that empowers applications. -This application is a tool to generate the needed files -to quickly create a Cobra application.`, + Short: "multiple ygot utils - not yet implemented", + Long: ``, RunE: func(cmd *cobra.Command, args []string) error { - return errors.New("path needs either [ygot] or [legacy] command") + return errors.New("not implemented") }, } func init() { rootCmd.AddCommand(pathCmd) - - // Here you will define your flags and configuration settings. - - // Cobra supports Persistent Flags which will work for this command - // and all subcommands, e.g.: - // pathCmd.PersistentFlags().String("foo", "", "A help for foo") - - // Cobra supports local flags which will only run when this command - // is called directly, e.g.: - // pathCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") } diff --git a/cmd/root.go b/cmd/root.go index 4ee3a3b26f86f4516e6dfa707ce7a8983f2baa17..2ff4970dac6b41ff959e1a08fbf352bd80696c07 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -31,8 +31,9 @@ POSSIBILITY OF SUCH DAMAGE. package cmd import ( - "code.fbi.h-da.de/cocsn/gosdn/cli" + "code.fbi.h-da.de/cocsn/gosdn/nucleus" "fmt" + log "github.com/sirupsen/logrus" "github.com/spf13/cobra" "os" @@ -41,20 +42,19 @@ import ( var cfgFile string +var username string +var password string +var address string // rootCmd represents the base command when called without any subcommands var rootCmd = &cobra.Command{ Use: "gosdn", - Short: "A brief description of your application", - Long: `A longer description that spans multiple lines and likely contains -examples and usage of using your application. For example: - -Cobra is a CLI library for Go that empowers applications. -This application is a tool to generate the needed files -to quickly create a Cobra application.`, + Short: "starts the gosdn controller", + Long: `Set GOSDN_DEBUG environment variable to enalbe debug logging.`, RunE: func(cmd *cobra.Command, args []string) error { - return cli.Gosdn() + rc := make(chan bool) + return nucleus.StartAndRun(rc) }, } @@ -75,11 +75,9 @@ func init() { // will be global for your application. rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is ./configs/gosdn.toml)") - - - // Cobra also supports local flags, which will only run - // when this action is called directly. - rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") + rootCmd.PersistentFlags().StringVarP(&username, "username", "u", "admin", "username for a gnmi resource") + rootCmd.PersistentFlags().StringVarP(&password, "password", "p", "arista", "password for a gnmi resource") + rootCmd.PersistentFlags().StringVarP(&username, "address", "a", "ceos-cocsn.apps.ocp.fbi.h-da.de:6030", "address to a gnmi resource") } @@ -99,5 +97,8 @@ func initConfig() { if err := viper.ReadInConfig(); err == nil { fmt.Println("Using config file:", viper.ConfigFileUsed()) } + if viper.IsSet("GOSDN_DEBUG") { + log.SetLevel(log.DebugLevel) + } } diff --git a/cmd/set.go b/cmd/set.go index 6631f08fb44efe3ed33f5eed16389183a569cf90..46beef8c98a0fe3bc8647139619036c9a89314d9 100644 --- a/cmd/set.go +++ b/cmd/set.go @@ -35,31 +35,22 @@ import ( "github.com/spf13/cobra" ) +var typ string + // setCmd represents the set command var setCmd = &cobra.Command{ Use: "set", - Short: "A brief description of your command", - Long: `A longer description that spans multiple lines and likely contains examples -and usage of using your command. For example: - -Cobra is a CLI library for Go that empowers applications. -This application is a tool to generate the needed files -to quickly create a Cobra application.`, + Short: "set request", + Long: `Sends a gNMI Set request to the specified target. Only one + request per invocation supported.`, RunE: func(cmd *cobra.Command, args []string) error { - return cli.Set() + return cli.Set(address, username, password, typ, args...) }, } func init() { rootCmd.AddCommand(setCmd) - // Here you will define your flags and configuration settings. - - // Cobra supports Persistent Flags which will work for this command - // and all subcommands, e.g.: - // setCmd.PersistentFlags().String("foo", "", "A help for foo") - - // Cobra supports local flags which will only run when this command - // is called directly, e.g.: - // setCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") + setCmd.Flags().StringVarP(&typ, "type", "t", "update", "Type of the set request. " + + "Possible values: 'update', 'replace', and 'delete'") } diff --git a/cmd/subscribe.go b/cmd/subscribe.go index c60671693ec6f580b2698ea1b5fa65a9aca16163..68b3cd99f83e291c66e34f238ede56231f185750 100644 --- a/cmd/subscribe.go +++ b/cmd/subscribe.go @@ -35,31 +35,24 @@ import ( "github.com/spf13/cobra" ) +var sampleInterval int64 +var heartbeatInterval int64 + // subscribeCmd represents the subscribe command var subscribeCmd = &cobra.Command{ Use: "subscribe", - Short: "A brief description of your command", - Long: `A longer description that spans multiple lines and likely contains examples -and usage of using your command. For example: + Short: "subscribe to target", + Long: `Starts a gNMI subscriber requersting the specified paths on the target and logs the response to stdout. -Cobra is a CLI library for Go that empowers applications. -This application is a tool to generate the needed files -to quickly create a Cobra application.`, + Only 'stream' mode with 'sample' operation supported.`, RunE: func(cmd *cobra.Command, args []string) error { - return cli.Subscribe() + return cli.Subscribe(address, username, password, sampleInterval, heartbeatInterval, args...) }, } func init() { rootCmd.AddCommand(subscribeCmd) - // Here you will define your flags and configuration settings. - - // Cobra supports Persistent Flags which will work for this command - // and all subcommands, e.g.: - // subscribeCmd.PersistentFlags().String("foo", "", "A help for foo") - - // Cobra supports local flags which will only run when this command - // is called directly, e.g.: - // subscribeCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") + subscribeCmd.Flags().Int64Var(&sampleInterval, "sample-rate", 5, "Sample rate per second.") + subscribeCmd.Flags().Int64Var(&heartbeatInterval, "heartbeat-rate", 1, "Heartbeat rate per second.") } diff --git a/cmd/target.go b/cmd/target.go index 379ddcb7d770d39280aa7a043b2427a037186c7f..2aeb616f72a0c3da13f335301851e3c9d405d22e 100644 --- a/cmd/target.go +++ b/cmd/target.go @@ -36,31 +36,20 @@ import ( "github.com/spf13/cobra" ) +var bindAddr string + // targetCmd represents the target command var targetCmd = &cobra.Command{ Use: "target", - Short: "A brief description of your command", - Long: `A longer description that spans multiple lines and likely contains examples -and usage of using your command. For example: - -Cobra is a CLI library for Go that empowers applications. -This application is a tool to generate the needed files -to quickly create a Cobra application.`, + Short: "start gnmi target", + Long: `Starts a gNMI target listening on the specified port.`, RunE: func(cmd *cobra.Command, args []string) error { - return cli.Target() + return cli.Target(bindAddr) }, } func init() { rootCmd.AddCommand(targetCmd) - // Here you will define your flags and configuration settings. - - // Cobra supports Persistent Flags which will work for this command - // and all subcommands, e.g.: - // targetCmd.PersistentFlags().String("foo", "", "A help for foo") - - // Cobra supports local flags which will only run when this command - // is called directly, e.g.: - // targetCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") + targetCmd.Flags().StringVar(&bindAddr, "bind-address", ":9339", "listen address of the target: [address]:port") } diff --git a/cmd/util.go b/cmd/util.go index 432e5a54083af02a5477c3b591fcc1480d583d86..c97a75dd988eba3cadc58e020880e57a966bb183 100644 --- a/cmd/util.go +++ b/cmd/util.go @@ -31,35 +31,20 @@ POSSIBILITY OF SUCH DAMAGE. package cmd import ( - "code.fbi.h-da.de/cocsn/gosdn/cli" + "errors" "github.com/spf13/cobra" ) // utilCmd represents the util command var utilCmd = &cobra.Command{ Use: "util", - Short: "A brief description of your command", - Long: `A longer description that spans multiple lines and likely contains examples -and usage of using your command. For example: - -Cobra is a CLI library for Go that empowers applications. -This application is a tool to generate the needed files -to quickly create a Cobra application.`, + Short: "multiple ygot utils - not yet implemented", + Long: ``, RunE: func(cmd *cobra.Command, args []string) error { - return cli.LeafPaths() + return errors.New("not implemented") }, } func init() { ygotCmd.AddCommand(utilCmd) - - // Here you will define your flags and configuration settings. - - // Cobra supports Persistent Flags which will work for this command - // and all subcommands, e.g.: - // utilCmd.PersistentFlags().String("foo", "", "A help for foo") - - // Cobra supports local flags which will only run when this command - // is called directly, e.g.: - // utilCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") } diff --git a/cmd/ygot.go b/cmd/ygot.go index d5298bd15d3844d05c964054b02ddcdf4eed4cc3..504a4f4f0ef465efd0bdc6e78b5b6fbe6c881657 100644 --- a/cmd/ygot.go +++ b/cmd/ygot.go @@ -39,13 +39,8 @@ import ( // ygotCmd represents the ygot command var ygotCmd = &cobra.Command{ Use: "ygot", - Short: "A brief description of your command", - Long: `A longer description that spans multiple lines and likely contains examples -and usage of using your command. For example: - -Cobra is a CLI library for Go that empowers applications. -This application is a tool to generate the needed files -to quickly create a Cobra application.`, + Short: "multiple ygot utils - not yet implemented", + Long: ``, RunE: func(cmd *cobra.Command, args []string) error { return errors.New("not implemented") }, @@ -53,14 +48,4 @@ to quickly create a Cobra application.`, func init() { rootCmd.AddCommand(ygotCmd) - - // Here you will define your flags and configuration settings. - - // Cobra supports Persistent Flags which will work for this command - // and all subcommands, e.g.: - // ygotCmd.PersistentFlags().String("foo", "", "A help for foo") - - // Cobra supports local flags which will only run when this command - // is called directly, e.g.: - // ygotCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") } diff --git a/nucleus/nucleus-core.go b/nucleus/nucleus-core.go index 99dcb95046e730d787ee3f7308279aa113aa0217..1256182d1ab456247945d7af5c5242ad3dd8a04d 100644 --- a/nucleus/nucleus-core.go +++ b/nucleus/nucleus-core.go @@ -6,7 +6,7 @@ import ( log "github.com/sirupsen/logrus" ) -//StartAndRun is used to start the core of the controller and any auxiliary services. +//StartAndRun starts the gosdn core and auxiliary services. func StartAndRun(IsRunningChannel chan bool) error { log.Info("This is the network superintendent...") log.Info("Starting my ducks") @@ -16,7 +16,6 @@ func StartAndRun(IsRunningChannel chan bool) error { if err := core.Initialize(IsRunningChannel); err != nil { return err } - // Start the GRCP CLI go core.Shutdown() log.Info("and ready for take off") diff --git a/test/targets.go b/test/targets.go index b9c30787f451dcc445c9a50ff35bbd382b7ab385..ec405e446314e00a341a03765b283d14a51c1b00 100644 --- a/test/targets.go +++ b/test/targets.go @@ -2,9 +2,10 @@ package test import ( "code.fbi.h-da.de/cocsn/gosdn/forks/google/gnmi" - "code.fbi.h-da.de/cocsn/gosdn/forks/google/gnmi/modeldata" oc "code.fbi.h-da.de/cocsn/yang-models/generated/arista" pb "github.com/openconfig/gnmi/proto/gnmi" + "github.com/openconfig/goyang/pkg/yang" + "github.com/openconfig/ygot/util" "github.com/openconfig/ygot/ygot" log "github.com/sirupsen/logrus" "google.golang.org/grpc" @@ -62,8 +63,19 @@ func GnmiTarget(stop chan bool, bindAddr string) error { bindAddr = "localhost:13371" } + entries := make([]*yang.Entry, 0) + for _,e := range oc.SchemaTree { + entries = append(entries, e) + } + + modelData, err := util.FindModelData(entries) + if err != nil { + return err + } + // Google stuff from here - model := gnmi.NewModel(modeldata.ModelData, + model := gnmi.NewModel( + modelData, reflect.TypeOf((*oc.Device)(nil)), oc.SchemaTree["Device"], oc.Unmarshal,