Newer
Older
Max Bohling
committed
/*
Copyright © 2023 da/net Research Group <danet@h-da.de>
Max Bohling
committed
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.
Max Bohling
committed
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.
Max Bohling
committed
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.
Max Bohling
committed
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 (
Malte Bauch
committed
gnmitarget "code.fbi.h-da.de/danet/gnmi-target"
"code.fbi.h-da.de/danet/gnmi-target/examples/example01/etsiqkdnclient"
"code.fbi.h-da.de/danet/gnmi-target/examples/example01/handlers/danet"
"code.fbi.h-da.de/danet/gnmi-target/examples/example01/handlers/etsi"
Malte Bauch
committed
"code.fbi.h-da.de/danet/gnmi-target/examples/example01/handlers/interfaces"
networkinstances "code.fbi.h-da.de/danet/gnmi-target/examples/example01/handlers/network-instances"
"code.fbi.h-da.de/danet/gnmi-target/examples/example01/handlers/system"
gnmitargetygot "code.fbi.h-da.de/danet/gnmi-target/examples/example01/model"
"code.fbi.h-da.de/danet/gnmi-target/handler"
Max Bohling
committed
"github.com/spf13/cobra"
Max Bohling
committed
)
bindAddress string // IP/Port to bind to listen for the gnmi server
configFile string // my config file to use
osclient string // TODO unclear
logLevel string // which loglevel to use
certFile string // the location of the file containing the X.509 certificates for the gnmi server
Malte Bauch
committed
caFile string // the location of the file containing the ca certificate to verify client certificates
keyFile string // the location of the file containing the key for the certificates for the gnmi server
insecure *bool // set to true if insecure operations is needed, i.e., do not use TLS
// Below is qkdn specific information
udpQL1AddrString string
ql1Name string
udpQL2AddrString string
ql2Name string
// End of qkdn specific information
Max Bohling
committed
// startCmd represents the start command
var startCmd = &cobra.Command{
Use: "start",
Max Bohling
committed
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("Startup of GNMI Target...")
lvl := viper.GetString("logLevel")
// parse string, this is built-in feature of logrus
ll, err := logrus.ParseLevel(lvl)
if err != nil {
ll = logrus.InfoLevel
}
// set global log level
logrus.SetLevel(ll)
kmsConfig := &etsiqkdnclient.Config{}
logrus.Println(viper.GetString("kms-config"))
file, err := os.ReadFile(viper.GetString("kms-config"))
if err != nil {
logrus.Fatal(err)
}
if err := yaml.Unmarshal(file, kmsConfig); err != nil {
logrus.Fatal(err)
qkdnClient := etsiqkdnclient.NewQkdnClient(kmsConfig)
Malte Bauch
committed
schema, err := gnmitargetygot.Schema()
if err != nil {
logrus.Fatal(err)
}
// The registered path handlers sorted by priority. If specific
// handlers should be able to process their workload before others,
// then they should be placed in the front of the slice.
handlers := []handler.PathHandler{
//acl.NewACLYangHandler(),
interfaces.NewInterfacesHandler(),
networkinstances.NewNetworkInstanceHandler(),
//danet.NewModemYangHandler(),
system.NewHostnameHandler(),
system.NewMemoryHandler(),
system.NewMotdHandler(),
system.NewStateHandler(),
system.NewSystemHandler(),
etsi.NewETSI15Handler(qkdnClient),
danet.NewAssignForwardingHandler(qkdnClient),
Malte Bauch
committed
}
gnmitTarget := gnmitarget.NewGnmiTarget(schema, &gnmitargetygot.Gnmitarget{}, gnmitargetygot.ΓModelData, gnmitargetygot.Unmarshal, gnmitargetygot.ΛEnum, handlers...)
Malte Bauch
committed
if err := gnmitTarget.Start(viper.GetString("bindAddress"), viper.GetString("certFile"), viper.GetString("keyFile"), viper.GetString("caFile"), *insecure); err != nil {
Max Bohling
committed
},
}
func init() {
// Here you will define your flags and configuration settings.
startCmd.Flags().StringVarP(&configFile, "config", "c", "config/openconfig.json", "system configuration")
startCmd.Flags().StringVarP(&bindAddress, "bind_address", "a", ":7030", "address to bind to")
startCmd.Flags().StringVarP(&logLevel, "log", "l", "info", "loglevel")
insecure = startCmd.Flags().Bool("insecure", false, "If true do not use TLS")
startCmd.Flags().StringVarP(&certFile, "cert", "", "", "location of the cert file")
startCmd.Flags().StringVarP(&keyFile, "key", "", "", "location of the key file")
Malte Bauch
committed
startCmd.Flags().StringVarP(&caFile, "ca_file", "", "", "location of the ca file")
startCmd.Flags().StringVarP(&osclient, "osclient", "o", "ubuntu", "os client to use by system")
startCmd.Flags().StringVarP(&udpQL1AddrString, "my_QLE_socket", "", "[::1]:50900", "local quantum element's address")
startCmd.Flags().StringVarP(&ql1Name, "my_name", "", "ekms-ql1", "The name of the local quantumlayer")
startCmd.Flags().StringVarP(&udpQL2AddrString, "remote_QLE_socket", "", "[::1]:50901", "remote quantum element's address")
startCmd.Flags().StringVarP(&ql2Name, "remote_name", "", "ekms-ql2", "The name of the remote quantumlayer")
startCmd.Flags().StringVarP(&kmsConfig, "kms_config", "", "/usr/bin/config/kms.yaml", "Path to the kms config file (yaml)")
Max Bohling
committed
viper.BindPFlag("bindAddress", startCmd.Flags().Lookup("bind_address"))
viper.BindPFlag("configFile", startCmd.Flags().Lookup("config"))
viper.BindPFlag("logLevel", startCmd.Flags().Lookup("log"))
viper.BindPFlag("insecure", startCmd.Flags().Lookup("insecure"))
viper.BindPFlag("certFile", startCmd.Flags().Lookup("cert"))
viper.BindPFlag("keyFile", startCmd.Flags().Lookup("key"))
Malte Bauch
committed
viper.BindPFlag("caFile", startCmd.Flags().Lookup("ca_file"))
viper.BindPFlag("osclient", startCmd.Flags().Lookup("osclient"))
viper.BindPFlag("my_QLE_socket", startCmd.Flags().Lookup("my-address"))
viper.BindPFlag("my_name", startCmd.Flags().Lookup("my-name"))
viper.BindPFlag("remote_QLE_socket", startCmd.Flags().Lookup("remote-address"))
viper.BindPFlag("remote_name", startCmd.Flags().Lookup("remote-name"))
viper.BindPFlag("kms-config", startCmd.Flags().Lookup("kms_config"))
Max Bohling
committed