diff --git a/os_clients/ubuntu/ubuntu.go b/os_clients/ubuntu/ubuntu.go index 73213ddb50c812ede01e7566c5d7dde86e408138..b6367dfb186bd49d4769413e43f5408ceb22064c 100644 --- a/os_clients/ubuntu/ubuntu.go +++ b/os_clients/ubuntu/ubuntu.go @@ -1,7 +1,6 @@ package ubuntu import ( - "net" "os" "os/exec" "strings" @@ -73,9 +72,7 @@ func (ou OsclientUbuntu) createInterfaces(localIface netlink.Link, gt *gnmitarge config.Type = gnmitargetygot.IETFInterfaces_InterfaceType_UNSET config.Mtu = ygot.Uint16(uint16(attributes.MTU)) - if attributes.Flags&net.FlagUp != 0 { - state.OperStatus = gnmitargetygot.OpenconfigInterfaces_Interfaces_Interface_State_OperStatus_UP - } + state.OperStatus = setOperState(attributes.OperState) ipv4Addresses, err := netlink.AddrList(localIface, netlink.FAMILY_V4) if err != nil { @@ -124,6 +121,27 @@ func (ou OsclientUbuntu) createInterfaces(localIface netlink.Link, gt *gnmitarge } } +// setOperState helper function that allows to return the correct OperStatus +// type for openconfig interfaces based on a netlink LinkOperState +func setOperState(state netlink.LinkOperState) gnmitargetygot.E_OpenconfigInterfaces_Interfaces_Interface_State_OperStatus { + switch state { + case netlink.OperUp: + return gnmitargetygot.OpenconfigInterfaces_Interfaces_Interface_State_OperStatus_UP + case netlink.OperDown: + return gnmitargetygot.OpenconfigInterfaces_Interfaces_Interface_State_OperStatus_DOWN + case netlink.OperDormant: + return gnmitargetygot.OpenconfigInterfaces_Interfaces_Interface_State_OperStatus_DORMANT + case netlink.OperTesting: + return gnmitargetygot.OpenconfigInterfaces_Interfaces_Interface_State_OperStatus_TESTING + case netlink.OperNotPresent: + return gnmitargetygot.OpenconfigInterfaces_Interfaces_Interface_State_OperStatus_NOT_PRESENT + case netlink.OperLowerLayerDown: + return gnmitargetygot.OpenconfigInterfaces_Interfaces_Interface_State_OperStatus_LOWER_LAYER_DOWN + default: + return gnmitargetygot.OpenconfigInterfaces_Interfaces_Interface_State_OperStatus_UNKNOWN + } +} + func (ou *OsclientUbuntu) getSystem(gt *gnmitargetygot.Gnmitarget) { system := gt.GetOrCreateSystem()