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

trying to walk through config and call functions based on values

parent 03968a97
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
...@@ -215,8 +215,6 @@ github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWb ...@@ -215,8 +215,6 @@ github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWb
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
github.com/openconfig/gnmi v0.0.0-20200414194230-1597cc0f2600/go.mod h1:M/EcuapNQgvzxo1DDXHK4tx3QpYM/uG4l591v33jG2A= github.com/openconfig/gnmi v0.0.0-20200414194230-1597cc0f2600/go.mod h1:M/EcuapNQgvzxo1DDXHK4tx3QpYM/uG4l591v33jG2A=
github.com/openconfig/gnmi v0.0.0-20200508230933-d19cebf5e7be/go.mod h1:M/EcuapNQgvzxo1DDXHK4tx3QpYM/uG4l591v33jG2A= github.com/openconfig/gnmi v0.0.0-20200508230933-d19cebf5e7be/go.mod h1:M/EcuapNQgvzxo1DDXHK4tx3QpYM/uG4l591v33jG2A=
github.com/openconfig/gnmi v0.0.0-20210914185457-51254b657b7d h1:ENKx1I2+/8C70C69qGDw8zfHXFsPnSMtZyf9F2GjN/k=
github.com/openconfig/gnmi v0.0.0-20210914185457-51254b657b7d/go.mod h1:h365Ifq35G6kLZDQlRvrccTt2LKK90VpjZLMNGxJRYc=
github.com/openconfig/gnmi v0.0.0-20220503232738-6eb133c65a13 h1:6MHJ6YxMDr/dhS4mnM3sZxmolqgJw36ibOtwXNHTo6M= github.com/openconfig/gnmi v0.0.0-20220503232738-6eb133c65a13 h1:6MHJ6YxMDr/dhS4mnM3sZxmolqgJw36ibOtwXNHTo6M=
github.com/openconfig/gnmi v0.0.0-20220503232738-6eb133c65a13/go.mod h1:h365Ifq35G6kLZDQlRvrccTt2LKK90VpjZLMNGxJRYc= github.com/openconfig/gnmi v0.0.0-20220503232738-6eb133c65a13/go.mod h1:h365Ifq35G6kLZDQlRvrccTt2LKK90VpjZLMNGxJRYc=
github.com/openconfig/goyang v0.0.0-20200115183954-d0a48929f0ea/go.mod h1:dhXaV0JgHJzdrHi2l+w0fZrwArtXL7jEFoiqLEdmkvU= github.com/openconfig/goyang v0.0.0-20200115183954-d0a48929f0ea/go.mod h1:dhXaV0JgHJzdrHi2l+w0fZrwArtXL7jEFoiqLEdmkvU=
......
...@@ -4,8 +4,10 @@ import ( ...@@ -4,8 +4,10 @@ import (
"fmt" "fmt"
"net" "net"
"code.fbi.h-da.de/danet/gnmi-target/modeldata/gnmitargetygot"
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/ygot/util"
"github.com/vishvananda/netlink" "github.com/vishvananda/netlink"
) )
...@@ -21,6 +23,9 @@ var supportedPaths = map[string]osc.PathFunc{ ...@@ -21,6 +23,9 @@ var supportedPaths = map[string]osc.PathFunc{
//} //}
return nil return nil
}, },
"/interfaces/interface": func(path *gnmi.Path, val *gnmi.TypedValue) error {
return nil
},
"/interfaces/interface/subinterfaces/subinterface/ipv4/addresses/address/ip": func(path *gnmi.Path, val *gnmi.TypedValue) error { "/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 //NOTE: this is just for testing purpose. Normally the information from
// different paths should be combined // different paths should be combined
...@@ -66,6 +71,92 @@ var supportedPaths = map[string]osc.PathFunc{ ...@@ -66,6 +71,92 @@ var supportedPaths = map[string]osc.PathFunc{
}, },
} }
func walkThroughConfig(config any) error {
conf, ok := config.(*gnmitargetygot.Gnmitarget)
if !ok {
return fmt.Errorf("failed type assertion for %T", (*gnmitargetygot.Gnmitarget)(nil))
}
if interfaces := conf.Interfaces; interfaces != nil {
if intfMap := interfaces.Interface; intfMap != nil {
for intfKey, intf := range intfMap {
if subinterfaces := intf.Subinterfaces; subinterfaces != nil {
if subintfMap := subinterfaces.Subinterface; subintfMap != nil {
for _, subintf := range subintfMap {
go generateSubinterface(subintf, intfKey)
}
}
}
}
}
}
return nil
}
func generateSubinterface(subintf *gnmitargetygot.OpenconfigInterfaces_Interfaces_Interface_Subinterfaces_Subinterface, key string) error {
link, err := netlink.LinkByName(key)
if err != nil {
_, ok := err.(netlink.LinkNotFoundError)
if !ok {
return err
}
link = &netlink.Dummy{
LinkAttrs: netlink.LinkAttrs{
Flags: net.FlagUp,
Name: key,
},
}
}
errs := make([]error, 0)
for _, addr := range subintf.Ipv4.Addresses.Address {
if !util.IsValueNil(addr.Config.Ip) && !util.IsValueNil(addr.Config.PrefixLength) {
netlinkAddr := &netlink.Addr{
IPNet: &net.IPNet{
IP: net.ParseIP(*addr.Config.Ip),
// just for testing should come from other path
Mask: net.CIDRMask(int(*addr.Config.PrefixLength), 32),
},
}
if err := netlink.AddrAdd(link, netlinkAddr); err != nil {
errs = append(errs, err)
}
}
}
if len(errs) != 0 {
return fmt.Errorf("encountered %v errors during address adding \n%v", len(errs), errs)
}
return nil
}
func generateRouting(linkKey string) error {
link, err := netlink.LinkByName(linkKey)
if err != nil {
_, ok := err.(netlink.LinkNotFoundError)
if !ok {
return err
}
link = &netlink.Dummy{
LinkAttrs: netlink.LinkAttrs{
Flags: net.FlagUp,
Name: linkKey,
},
}
}
fmt.Println(link.Attrs().Index)
//dst := &net.IPNet{
// IP: dstip,
// Mask: net.CIDRMask(32, 32),
//}
//route = netlink.Route{LinkIndex: link.Attrs().Index, Dst: dst}
//netlink.RouteAdd(&route)
return nil
}
func filterKeys(path *gnmi.Path) []map[string]string { func filterKeys(path *gnmi.Path) []map[string]string {
keyMap := make([]map[string]string, 0) keyMap := make([]map[string]string, 0)
for _, p := range path.GetElem() { for _, p := range path.GetElem() {
......
...@@ -84,14 +84,15 @@ func (ou *OsclientUbuntu) callbackFunc(config ygot.ValidatedGoStruct) error { ...@@ -84,14 +84,15 @@ func (ou *OsclientUbuntu) callbackFunc(config ygot.ValidatedGoStruct) error {
if err := fn(diff.GetPath(), diff.GetVal()); err != nil { if err := fn(diff.GetPath(), diff.GetVal()); err != nil {
return err return err
} }
} else {
//ignore all other paths for now
return fmt.Errorf("the path: %s is not supported", schemaPath)
} }
//ignore all other paths for now
//return fmt.Errorf("the path: %s is not supported", schemaPath)
} }
return nil return nil
} }
func (ou OsclientUbuntu) createInterfaces(localIface netlink.Link, gt *gnmitargetygot.Gnmitarget) { func (ou *OsclientUbuntu) createInterfaces(localIface netlink.Link, gt *gnmitargetygot.Gnmitarget) {
//experiment with the ygot struct //experiment with the ygot struct
//populate with data HERE //populate with data HERE
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment