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

Possible to up/down an interface

parent 37a98dd8
No related branches found
No related tags found
No related merge requests found
Pipeline #261956 failed
......@@ -101,6 +101,7 @@ func (yh *InterfacesHandler) Update(c ygot.ValidatedGoStruct, updates []*gnmi.Up
osInterface.Name = config.Name
osInterface.Type = config.Type
osInterface.MTU = config.Mtu
osInterface.Enabled = config.Enabled
}
if *osInterface.Name != "lo" && *osInterface.Name != "wlan0" {
......@@ -174,6 +175,7 @@ func (yh *InterfacesHandler) updateOrCreateInterface(localInterface *additions.I
config.Type = localInterface.Type
config.Mtu = localInterface.MTU
config.Name = localInterface.Name
config.Enabled = localInterface.Enabled
state.OperStatus = localInterface.OperState
state.AdminStatus = localInterface.AdminStatus
......
......@@ -25,6 +25,7 @@ type Interface struct {
Name *string
Type gnmitargetygot.E_IETFInterfaces_InterfaceType
MTU *uint16
Enabled *bool
OperState gnmitargetygot.E_OpenconfigInterfaces_Interfaces_Interface_State_OperStatus
AdminStatus gnmitargetygot.E_OpenconfigInterfaces_Interfaces_Interface_State_AdminStatus
LoopbackMode *bool
......
......@@ -49,6 +49,12 @@ func (oc *interfaces) SetInterface(interfaceToSet *Interface) error {
log.Debug("Current Interface-Name: ", link.Attrs().Name)
if *interfaceToSet.Enabled {
netlink.LinkSetUp(link)
} else {
netlink.LinkSetDown(link)
}
//TODO: add more set options for interface
if err := netlink.LinkSetMTU(link, int(*interfaceToSet.MTU)); err != nil {
log.Debugf("Failed to set MTU: %d ; err: %v", *interfaceToSet.MTU, err)
......@@ -148,6 +154,7 @@ func interfaceFromLink(localIface netlink.Link) (*Interface, error) {
AdminStatus: adminStatus,
LoopbackMode: loopbackMode,
OperState: setOperState(attributes.OperState),
Enabled: ygot.Bool(setConfigEnabled(attributes.OperState)),
Ipv4Addresses: IPv4Addresses,
Ipv6Addresses: IPv6Addresses,
}, nil
......@@ -173,3 +180,14 @@ func setOperState(state netlink.LinkOperState) gnmitargetygot.E_OpenconfigInterf
return gnmitargetygot.OpenconfigInterfaces_Interfaces_Interface_State_OperStatus_UNKNOWN
}
}
// setOperState helper function that allows to return the correct OperStatus
// type for openconfig interfaces based on a netlink LinkOperState
func setConfigEnabled(state netlink.LinkOperState) bool {
switch state {
case netlink.OperUp:
return true
default:
return false
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment