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

Add setOperState helper function

Allows to set the right `OperState` based on the given netlink
`LinkOperState`.
parent 99bed399
No related branches found
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 (
"net"
"os" "os"
"os/exec" "os/exec"
"strings" "strings"
...@@ -73,9 +72,7 @@ func (ou OsclientUbuntu) createInterfaces(localIface netlink.Link, gt *gnmitarge ...@@ -73,9 +72,7 @@ func (ou OsclientUbuntu) createInterfaces(localIface netlink.Link, gt *gnmitarge
config.Type = gnmitargetygot.IETFInterfaces_InterfaceType_UNSET config.Type = gnmitargetygot.IETFInterfaces_InterfaceType_UNSET
config.Mtu = ygot.Uint16(uint16(attributes.MTU)) config.Mtu = ygot.Uint16(uint16(attributes.MTU))
if attributes.Flags&net.FlagUp != 0 { state.OperStatus = setOperState(attributes.OperState)
state.OperStatus = gnmitargetygot.OpenconfigInterfaces_Interfaces_Interface_State_OperStatus_UP
}
ipv4Addresses, err := netlink.AddrList(localIface, netlink.FAMILY_V4) ipv4Addresses, err := netlink.AddrList(localIface, netlink.FAMILY_V4)
if err != nil { if err != nil {
...@@ -124,6 +121,27 @@ func (ou OsclientUbuntu) createInterfaces(localIface netlink.Link, gt *gnmitarge ...@@ -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) { func (ou *OsclientUbuntu) getSystem(gt *gnmitargetygot.Gnmitarget) {
system := gt.GetOrCreateSystem() system := gt.GetOrCreateSystem()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment