Skip to content
Snippets Groups Projects
Commit afa2a7fa authored by Malte Bauch's avatar Malte Bauch
Browse files

Merge branch 'master-into-develop2' into 'master'

Master into develop2 into master

See merge request !244
parents db2d6379 c5f06abd
No related branches found
No related tags found
No related merge requests found
Pipeline #96694 passed with warnings
Showing
with 438 additions and 836 deletions
/*
Copyright © 2021 da/net research group <danet.fbi.h-da.de>
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
package cmd
import (
"code.fbi.h-da.de/danet/gosdn/cli"
"github.com/spf13/cobra"
)
// requestCmd represents the request command
var requestCmd = &cobra.Command{
Use: "request",
Args: cobra.ExactArgs(1),
Short: "requests a path from a specified device on the controller",
Long: `Requests a path from a specified device on the controller.
The request path is passed as positional argument.`,
RunE: func(cmd *cobra.Command, args []string) error {
return cli.HTTPGet(
apiEndpoint,
"request",
"uuid="+uuid,
"sbi="+cliSbi,
"pnd="+cliPnd,
"path="+args[0],
)
},
}
func init() {
cliCmd.AddCommand(requestCmd)
requestCmd.Flags().StringVar(&uuid, "uuid", "", "uuid of the requested device")
}
/*
Copyright © 2021 da/net research group <danet.fbi.h-da.de>
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
package cmd
import (
"code.fbi.h-da.de/danet/gosdn/cli"
"github.com/spf13/cobra"
)
// requestAllCmd represents the requestAll command
var requestAllCmd = &cobra.Command{
Use: "request-all",
Args: cobra.ExactArgs(1),
Short: "requests specified path from all devices on the controller",
Long: `Requests a path from all devices on the controller known by
the controller.
The request path is passed as positional argument.`,
RunE: func(cmd *cobra.Command, args []string) error {
return cli.HTTPGet(
apiEndpoint,
"requestAll",
"sbi="+cliSbi,
"pnd="+cliPnd,
"path="+args[0],
)
},
}
func init() {
cliCmd.AddCommand(requestAllCmd)
}
......@@ -34,8 +34,10 @@ package cmd
import (
"context"
"os"
"path/filepath"
"code.fbi.h-da.de/danet/gosdn"
"code.fbi.h-da.de/danet/gosdn/nucleus"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
......@@ -43,13 +45,9 @@ import (
)
var cfgFile string
var username string
var password string
var address string
var loglevel string
var grpcPort string
var cliPnd string
var cliSbi string
var csbiOrchestrator string
// rootCmd represents the base command when called without any subcommands
var rootCmd = &cobra.Command{
......@@ -60,7 +58,7 @@ for REST API calls.`,
RunE: func(cmd *cobra.Command, args []string) error {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
return nucleus.Run(ctx)
return gosdn.Run(ctx)
},
}
......@@ -77,24 +75,28 @@ func init() {
cobra.OnInitialize(initConfig)
rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is ./configs/gosdn.toml)")
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(&address, "address", "a", "ceos-cocsn.apps.ocp.fbi.h-da.de:6030", "address of a gnmi target")
rootCmd.PersistentFlags().StringVarP(&loglevel, "log-level", "l", "", "log level 'debug' or 'trace'")
rootCmd.Flags().StringVar(&grpcPort, "grpc-port", "55055", "port for gRPC NBI")
rootCmd.Flags().StringVar(&grpcPort, "grpc-port", "", "port for gRPC NBI")
rootCmd.Flags().StringVar(&csbiOrchestrator, "csbi-orchestrator", "", "csbi orchestrator address")
}
const (
configHome string = "./configs"
configName string = "gosdn"
configType string = "toml"
)
// initConfig reads in config file and ENV variables if set.
func initConfig() {
if cfgFile != "" {
// Use config file from the flag.
viper.SetConfigFile(cfgFile)
} else {
viper.AddConfigPath("./configs")
viper.AddConfigPath(configHome)
viper.AddConfigPath("/usr/local/etc/gosdn/")
viper.SetConfigType("toml")
viper.SetConfigName("gosdn")
viper.SetConfigType(configType)
viper.SetConfigName(configName)
}
viper.AutomaticEnv() // read in environment variables that match
......@@ -102,11 +104,15 @@ func initConfig() {
// If a config file is found, read it in.
if err := viper.ReadInConfig(); err == nil {
log.Debug("Using config file:", viper.ConfigFileUsed())
} else {
ensureViperConfigFileExists()
}
viper.SetDefault("socket", ":"+grpcPort)
cliPnd = viper.GetString("CLI_PND")
cliSbi = viper.GetString("CLI_SBI")
if err := viper.BindPFlags(rootCmd.Flags()); err != nil {
log.Fatal(err)
}
viper.SetDefault("socket", ":55055")
viper.SetDefault("csbi-orchestrator", "localhost:55056")
ll := viper.GetString("GOSDN_LOG")
if ll != "" {
......@@ -123,4 +129,30 @@ func initConfig() {
log.SetFormatter(&log.JSONFormatter{})
log.SetReportCaller(false)
}
log.WithFields(viper.AllSettings()).Debug("current viper config")
}
func ensureFileSystemStoreExists(pathToFile string) error {
emptyString := []byte("")
err := os.WriteFile(pathToFile, emptyString, 0600)
if err != nil {
return err
}
return nil
}
func ensureViperConfigFileExists() {
// Viper will crash if you call 'WriteConfig()' and the file does
// not exists yet.
// Therefore we handle this case here.
// Inspired by //https://github.com/spf13/viper/issues/430#issuecomment-661945101
configPath := filepath.Join(configHome, configName+"."+configType)
if _, err := os.Stat(configPath); os.IsNotExist(err) {
err := ensureFileSystemStoreExists(configPath)
if err != nil {
panic(err)
}
}
}
/*
Copyright © 2021 da/net research group <danet.fbi.h-da.de>
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
package cmd
import (
"code.fbi.h-da.de/danet/gosdn/cli"
"github.com/spf13/cobra"
)
var typ string
// setCmd represents the set command
var setCmd = &cobra.Command{
Use: "set",
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(address, username, password, typ, args...)
},
}
func init() {
rootCmd.AddCommand(setCmd)
setCmd.Flags().StringVarP(&typ, "type", "t", "update", "Type of the set request. "+
"Possible values: 'update', 'replace', and 'delete'")
}
/*
Copyright © 2021 da/net research group <danet.fbi.h-da.de>
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
package cmd
import (
"code.fbi.h-da.de/danet/gosdn/cli"
"github.com/spf13/cobra"
)
var sampleInterval int64
var heartbeatInterval int64
// subscribeCmd represents the subscribe command
var subscribeCmd = &cobra.Command{
Use: "subscribe",
Short: "subscribe to target",
Long: `Starts a gNMI subscriber requesting the specified paths on the target and logs the response to stdout.
Only 'stream' mode with 'sample' operation supported.`,
RunE: func(cmd *cobra.Command, args []string) error {
return cli.Subscribe(address, username, password, sampleInterval, heartbeatInterval, args...)
},
}
func init() {
rootCmd.AddCommand(subscribeCmd)
subscribeCmd.Flags().Int64Var(&sampleInterval, "sample-rate", 5, "Sample rate per second.")
subscribeCmd.Flags().Int64Var(&heartbeatInterval, "heartbeat-rate", 1, "Heartbeat rate per second.")
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
File moved
This diff is collapsed.
package nucleus
package gosdn
import (
"context"
......@@ -27,12 +27,8 @@ func TestRun(t *testing.T) {
args: args{request: apiEndpoint + "/readyz"},
want: http.StatusOK,
},
{
name: "init",
args: args{request: apiEndpoint + "/api?q=init"},
want: http.StatusOK,
},
}
ctx, cancel := context.WithCancel(context.Background())
go func() {
if err := Run(ctx); err != nil {
......@@ -49,7 +45,7 @@ func TestRun(t *testing.T) {
if !reflect.DeepEqual(got.StatusCode, tests[0].want) {
t.Errorf("livez got: %v, want %v", got.StatusCode, tests[0].want)
}
got, err = http.Get(tests[0].args.request)
got, err = http.Get(tests[1].args.request)
if err != nil {
t.Error(err)
return
......@@ -57,14 +53,6 @@ func TestRun(t *testing.T) {
if !reflect.DeepEqual(got.StatusCode, tests[1].want) {
t.Errorf("readyz got: %v, want %v", got.StatusCode, tests[1].want)
}
got, err = http.Get(tests[0].args.request)
if err != nil {
t.Error(err)
return
}
if !reflect.DeepEqual(got.StatusCode, tests[2].want) {
t.Errorf("api init got: %v, want %v", got.StatusCode, tests[2].want)
}
})
cancel()
......
This diff is collapsed.
This diff is collapsed.
File moved
<mxfile host="Electron" modified="2022-02-17T14:42:51.009Z" agent="5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) draw.io/16.5.1 Chrome/96.0.4664.110 Electron/16.0.7 Safari/537.36" etag="oVOpiNiALXjf1fX8wkFb" version="16.5.1" type="device"><diagram id="pwvA0ZA2h6faCE5rpLjt" name="Seite-1">7Vpbd5s4EP41fqwPd8NjTJJut23Wu845bfOmgAzayMgVIrb3168E4iaU2ElwtnuO/RI0Iw1i5ptvBoWJHa53HynYpF9JDPHEMuLdxL6cWJZpGh7/IyT7SuIHViVIKIrlpFawRP9AKTSktEAxzHsTGSGYoU1fGJEsgxHryQClZNuftiK4f9cNSOBAsI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ct5bAUZ3F5xRlrWTzKbt20zbBRtJ21fdPQZQ2z/V0lDJLvSzLbCdtBhXr25Elb6tQ2Vv3hlDpM1LJv5dqE4ee1MiQr6yEPTmzGZXfKrGORpE7Qx2mNbqdDWEO7Be8L9mHfmDjqeCrhSViU/dOqvlNTB4A41Wsc/X3Z7bVtbg19adqv6czjzD5bnsZs095U1d4AltV8fr+Jq/TVsyjg5UvCheZk+k+WZLMc8S7A1Zwkzd0iWakKNRpbemSyV5D81WbqGAgHjOLIci+M0b55LcTJzbgfPDDcCw/FmQH1tdocc55tTDcudrCU0f32aa85eTk1z5jvxnGMqPOcd9w+bV/Bc4QJ/Ft1YLAcbJ7oNzD/vTM03Eude7sx0faYb0JompV7AdGbgD5jO8zTdnPV2ntNi3vpVaU5LOX2yei6JjwjKWz8gcU7VlfFh+7VYNb395s6++hc=</diagram></mxfile>
\ No newline at end of file
This diff is collapsed.
manual @ 302c0bdd
This diff is collapsed.
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment