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

WIP

parent 585bb2d6
Branches
No related tags found
4 merge requests!17Build basic ci,!10Add simple modem support on linux through modemmanager,!8General refactoring,!5Draft: Add basic set support for ip/routing via gnmi
package ubuntu package ubuntu
import ( import (
"syscall" "fmt"
"net"
osc "code.fbi.h-da.de/danet/gnmi-target/os_clients" osc "code.fbi.h-da.de/danet/gnmi-target/os_clients"
"github.com/openconfig/gnmi/proto/gnmi" "github.com/openconfig/gnmi/proto/gnmi"
"github.com/openconfig/gnmi/value" "github.com/vishvananda/netlink"
) )
var supportedPaths = map[string]osc.PathFunc{ var supportedPaths = map[string]osc.PathFunc{
"/system/config/hostname": func(path *gnmi.Path, val *gnmi.TypedValue) error { "/system/config/hostname": func(path *gnmi.Path, val *gnmi.TypedValue) error {
value, err := value.ToScalar(val) //value, err := value.ToScalar(val)
if err != nil { //if err != nil {
return err // return err
//}
//err = syscall.Sethostname([]byte(value.(string)))
//if err != nil {
// return err
//}
return nil
},
"/interfaces/interface/subinterfaces/subinterface/ipv4/addresses/address/ip": func(path *gnmi.Path, val *gnmi.TypedValue) error {
//NOTE: this is just for testing purpose. Normally the information from
// different paths should be combined
keys := filterKeys(path)
linkName, ok := keys[0]["name"]
if !ok {
return fmt.Errorf("internal error: no interface key has been provided within path:")
} }
err = syscall.Sethostname([]byte(value.(string)))
link, err := netlink.LinkByName(linkName)
if err != nil { if err != nil {
_, ok := err.(netlink.LinkNotFoundError)
if !ok {
return err
}
link = &netlink.Dummy{
LinkAttrs: netlink.LinkAttrs{
Flags: net.FlagUp,
Name: linkName,
},
}
}
addr := &netlink.Addr{
IPNet: &net.IPNet{
IP: net.ParseIP(val.GetStringVal()),
// just for testing should come from other path
Mask: net.CIDRMask(24, 32),
},
}
if err := netlink.AddrAdd(link, addr); err != nil {
fmt.Println("adding the address has failed: ", err)
return err return err
} }
return nil return nil
}, },
"/interfaces/interface/name": func(path *gnmi.Path, val *gnmi.TypedValue) error { "/interfaces/interface/name": func(path *gnmi.Path, val *gnmi.TypedValue) error {
fmt.Printf("we were in: %s", "/interfaces/interface/name")
return nil return nil
}, },
} }
func filterKeys(path *gnmi.Path) []map[string]string {
keyMap := make([]map[string]string, 0)
for _, p := range path.GetElem() {
if key := p.GetKey(); key != nil {
keyMap = append(keyMap, key)
}
}
return keyMap
}
package ubuntu package ubuntu
import ( import (
"fmt"
"net" "net"
"os" "os"
"os/exec" "os/exec"
...@@ -59,10 +60,21 @@ func (ou *OsclientUbuntu) GetCallbackFunc() func(ygot.ValidatedGoStruct) error { ...@@ -59,10 +60,21 @@ func (ou *OsclientUbuntu) GetCallbackFunc() func(ygot.ValidatedGoStruct) error {
} }
func (ou *OsclientUbuntu) callbackFunc(config ygot.ValidatedGoStruct) error { func (ou *OsclientUbuntu) callbackFunc(config ygot.ValidatedGoStruct) error {
//opts := []ygot.DiffOpt{
// &ygot.DiffPathOpt{MapToSinglePath: true},
//}
diffs, err := ygot.Diff(ou.GetConfig(), config) diffs, err := ygot.Diff(ou.GetConfig(), config)
if err != nil { if err != nil {
return err return err
} }
for _, path := range diffs.GetDelete() {
stringPath, err := ygot.PathToString(path)
if err != nil {
return err
}
fmt.Println("PathToDelete: ", stringPath)
}
for _, diff := range diffs.GetUpdate() { for _, diff := range diffs.GetUpdate() {
schemaPath, err := ygot.PathToSchemaPath(diff.GetPath()) schemaPath, err := ygot.PathToSchemaPath(diff.GetPath())
if err != nil { if err != nil {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment