diff --git a/os_clients/ubuntu/ubuntu.go b/os_clients/ubuntu/ubuntu.go index d902767fe01f2966d0366ec949b3c782d6d145f3..849d4cce8d4833464251051ad7e699df052506a3 100644 --- a/os_clients/ubuntu/ubuntu.go +++ b/os_clients/ubuntu/ubuntu.go @@ -5,10 +5,12 @@ import ( "net" "os" "os/exec" + "strconv" "strings" "time" "code.fbi.h-da.de/danet/gnmi-target/modeldata/gnmitargetygot" + "code.fbi.h-da.de/danet/gnmi-target/os_clients/freebsd" "github.com/openconfig/ygot/ygot" log "github.com/sirupsen/logrus" @@ -51,7 +53,8 @@ func (ou OsclientUbuntu) createInterfaces(localIface *net.Interface, gt *gnmitar interfaces := gt.GetOrCreateInterfaces() iface, err := interfaces.NewInterface(localIface.Name) if err != nil { - + log.Error("failed to create new interface") + log.WithFields(log.Fields{}).Error(err) } state := iface.GetOrCreateState() @@ -67,6 +70,36 @@ func (ou OsclientUbuntu) createInterfaces(localIface *net.Interface, gt *gnmitar state.OperStatus = gnmitargetygot.OpenconfigInterfaces_Interfaces_Interface_State_OperStatus_UP } + addresses, err := localIface.Addrs() + if err != nil { + log.Error("failed to get addresses") + log.WithFields(log.Fields{}).Error(err) + } + + for i, currAddr := range addresses { + subiface := iface.GetOrCreateSubinterfaces().GetOrCreateSubinterface(uint32(i)) + subiface.GetOrCreateConfig() + subiface.GetOrCreateState() + + addr := strings.Split(currAddr.String(), "/") + convPrefix64, _ := strconv.ParseUint(addr[1], 10, 8) + convPrefix := uint8(convPrefix64) + + if freebsd.IsIPv4Addr(addr[0]) { + ipv4 := subiface.GetOrCreateIpv4() + ipv4Addr := ipv4.GetOrCreateAddresses().GetOrCreateAddress(addr[0]) + ipv4AddrConf := ipv4Addr.GetOrCreateConfig() + ipv4AddrConf.Ip = ygot.String(addr[0]) + ipv4AddrConf.PrefixLength = &convPrefix + } else if freebsd.IsIPv6Addr(addr[0]) { + ipv6 := subiface.GetOrCreateIpv6() + ipv6Addr := ipv6.GetOrCreateAddresses().GetOrCreateAddress(addr[0]) + ipv6AddrConf := ipv6Addr.GetOrCreateConfig() + ipv6AddrConf.Ip = ygot.String(addr[0]) + ipv6AddrConf.PrefixLength = &convPrefix + } + } + //validate struct if err := iface.Validate(); err != nil { log.Error("failed to validate interface on gnmitarget")