[VOL-1605] Update disable/reenable device management logic
This is the initial commit of updating the device management
logic around disable and reenable of a device.
Change-Id: If6d40a0055e5e1ab61503b9ae9c5a4070ec53f35
diff --git a/adapters/simulated_olt/adaptercore/device_handler.go b/adapters/simulated_olt/adaptercore/device_handler.go
index 9aaeea4..07f31ff 100644
--- a/adapters/simulated_olt/adaptercore/device_handler.go
+++ b/adapters/simulated_olt/adaptercore/device_handler.go
@@ -200,3 +200,44 @@
log.Debugw("Process_inter_adapter_message", log.Fields{"msgId": msg.Header.Id})
return nil
}
+
+func (dh *DeviceHandler) DisableDevice(device *voltha.Device) {
+ cloned := proto.Clone(device).(*voltha.Device)
+ // Update the all ports state on that device to disable
+ if err := dh.coreProxy.PortsStateUpdate(nil, cloned.Id, voltha.OperStatus_UNKNOWN); err != nil {
+ log.Errorw("updating-ports-failed", log.Fields{"deviceId": device.Id, "error": err})
+ return
+ }
+
+ //Update the device state
+ cloned.ConnectStatus = voltha.ConnectStatus_UNREACHABLE
+ cloned.OperStatus = voltha.OperStatus_UNKNOWN
+ dh.device = cloned
+
+ if err := dh.coreProxy.DeviceStateUpdate(nil, cloned.Id, cloned.ConnectStatus, cloned.OperStatus); err != nil {
+ log.Errorw("device-state-update-failed", log.Fields{"deviceId": device.Id, "error": err})
+ return
+ }
+ log.Debugw("DisableDevice-end", log.Fields{"deviceId": device.Id})
+}
+
+func (dh *DeviceHandler) ReEnableDevice(device *voltha.Device) {
+
+ cloned := proto.Clone(device).(*voltha.Device)
+ // Update the all ports state on that device to enable
+ if err := dh.coreProxy.PortsStateUpdate(nil, cloned.Id, voltha.OperStatus_ACTIVE); err != nil {
+ log.Errorw("updating-ports-failed", log.Fields{"deviceId": device.Id, "error": err})
+ return
+ }
+
+ //Update the device state
+ cloned.ConnectStatus = voltha.ConnectStatus_REACHABLE
+ cloned.OperStatus = voltha.OperStatus_ACTIVE
+ dh.device = cloned
+
+ if err := dh.coreProxy.DeviceStateUpdate(nil, cloned.Id, cloned.ConnectStatus, cloned.OperStatus); err != nil {
+ log.Errorw("device-state-update-failed", log.Fields{"deviceId": device.Id, "error": err})
+ return
+ }
+ log.Debugw("ReEnableDevice-end", log.Fields{"deviceId": device.Id})
+}
diff --git a/adapters/simulated_olt/adaptercore/simulated_olt.go b/adapters/simulated_olt/adaptercore/simulated_olt.go
index 029f032..fee4dc8 100644
--- a/adapters/simulated_olt/adaptercore/simulated_olt.go
+++ b/adapters/simulated_olt/adaptercore/simulated_olt.go
@@ -165,11 +165,29 @@
}
func (so *SimulatedOLT) Disable_device(device *voltha.Device) error {
- return errors.New("UnImplemented")
+ if device == nil {
+ log.Warn("device-is-nil")
+ return errors.New("nil-device")
+ }
+ log.Infow("disable-device", log.Fields{"deviceId": device.Id})
+ var handler *DeviceHandler
+ if handler = so.getDeviceHandler(device.Id); handler != nil {
+ go handler.DisableDevice(device)
+ }
+ return nil
}
func (so *SimulatedOLT) Reenable_device(device *voltha.Device) error {
- return errors.New("UnImplemented")
+ if device == nil {
+ log.Warn("device-is-nil")
+ return errors.New("nil-device")
+ }
+ log.Infow("reenable-device", log.Fields{"deviceId": device.Id})
+ var handler *DeviceHandler
+ if handler = so.getDeviceHandler(device.Id); handler != nil {
+ go handler.ReEnableDevice(device)
+ }
+ return nil
}
func (so *SimulatedOLT) Reboot_device(device *voltha.Device) error {