diff --git a/go.sum b/go.sum index 89806953b7ac6ddf695df5c80f4a865c07b235d5..a6b5bfa4254eaeb9aa0c3308ccbf880ace220885 100644 --- a/go.sum +++ b/go.sum @@ -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/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-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/go.mod h1:h365Ifq35G6kLZDQlRvrccTt2LKK90VpjZLMNGxJRYc= github.com/openconfig/goyang v0.0.0-20200115183954-d0a48929f0ea/go.mod h1:dhXaV0JgHJzdrHi2l+w0fZrwArtXL7jEFoiqLEdmkvU= diff --git a/os_clients/ubuntu/supportedPaths.go b/os_clients/ubuntu/supportedPaths.go index ddfafd10111cd40deeab5a10468c3d6aec8906be..292b61e7315b04914b05b374e52ff3a2eebd2702 100644 --- a/os_clients/ubuntu/supportedPaths.go +++ b/os_clients/ubuntu/supportedPaths.go @@ -4,8 +4,10 @@ import ( "fmt" "net" + "code.fbi.h-da.de/danet/gnmi-target/modeldata/gnmitargetygot" osc "code.fbi.h-da.de/danet/gnmi-target/os_clients" "github.com/openconfig/gnmi/proto/gnmi" + "github.com/openconfig/ygot/util" "github.com/vishvananda/netlink" ) @@ -21,6 +23,9 @@ var supportedPaths = map[string]osc.PathFunc{ //} 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 { //NOTE: this is just for testing purpose. Normally the information from // different paths should be combined @@ -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 { keyMap := make([]map[string]string, 0) for _, p := range path.GetElem() { diff --git a/os_clients/ubuntu/ubuntu.go b/os_clients/ubuntu/ubuntu.go index 9bda5bc7068a8bfab3e2f9a9ca27de79b6636637..5e4dba38de431b8bec6f928b35c004850c8b9910 100644 --- a/os_clients/ubuntu/ubuntu.go +++ b/os_clients/ubuntu/ubuntu.go @@ -84,14 +84,15 @@ func (ou *OsclientUbuntu) callbackFunc(config ygot.ValidatedGoStruct) error { if err := fn(diff.GetPath(), diff.GetVal()); err != nil { 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 } -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 //populate with data HERE