VOL-3042 Dynamic config of device admin state and oper state based on external config requests
Change-Id: If84b258c03d10531de6023bc9dc461da8b013057
diff --git a/internal/pkg/onuadaptercore/device_handler.go b/internal/pkg/onuadaptercore/device_handler.go
index dac5177..e5946f4 100644
--- a/internal/pkg/onuadaptercore/device_handler.go
+++ b/internal/pkg/onuadaptercore/device_handler.go
@@ -287,6 +287,34 @@
return nil
}
+func (dh *DeviceHandler) DisableDevice(device *voltha.Device) {
+ logger.Debug("disable-device", log.Fields{"DeviceId": device.Id, "SerialNumber": device.SerialNumber})
+ // and disable port
+ // yield self.disable_ports(lock_ports=True, device_disabled=True)
+ if err := dh.coreProxy.DeviceReasonUpdate(context.TODO(), dh.deviceID, "OmciAdminLock"); err != nil {
+ logger.Errorw("error-updating-reason-state", log.Fields{"deviceID": dh.deviceID, "error": err})
+ }
+
+ if err := dh.coreProxy.DeviceStateUpdate(context.TODO(), dh.deviceID, voltha.ConnectStatus_REACHABLE,
+ voltha.OperStatus_UNKNOWN); err != nil {
+ logger.Errorw("error-updating-device-state", log.Fields{"deviceID": dh.deviceID, "error": err})
+ }
+}
+
+func (dh *DeviceHandler) ReenableDevice(device *voltha.Device) {
+ logger.Debug("reenable-device", log.Fields{"DeviceId": device.Id, "SerialNumber": device.SerialNumber})
+ if err := dh.coreProxy.DeviceStateUpdate(context.TODO(), dh.deviceID, voltha.ConnectStatus_REACHABLE,
+ voltha.OperStatus_ACTIVE); err != nil {
+ logger.Errorw("error-updating-device-state", log.Fields{"deviceID": dh.deviceID, "error": err})
+ }
+
+ if err := dh.coreProxy.DeviceReasonUpdate(context.TODO(), dh.deviceID, "InitialMibDownloaded"); err != nil {
+ logger.Errorw("error-updating-reason-state", log.Fields{"deviceID": dh.deviceID, "error": err})
+ }
+ // and enable port
+ // yield self.enable_ports(device)
+}
+
func (dh *DeviceHandler) GetOfpPortInfo(device *voltha.Device,
portNo int64) (*ic.PortCapability, error) {
logger.Debugw("GetOfpPortInfo start", log.Fields{"deviceID": device.Id, "portNo": portNo})
diff --git a/internal/pkg/onuadaptercore/openonu.go b/internal/pkg/onuadaptercore/openonu.go
index 1cd7585..255af1d 100644
--- a/internal/pkg/onuadaptercore/openonu.go
+++ b/internal/pkg/onuadaptercore/openonu.go
@@ -226,12 +226,24 @@
//Disable_device disables the given device
func (oo *OpenONUAC) Disable_device(device *voltha.Device) error {
- return errors.New("unImplemented")
+ logger.Debug("Disable_device", device.Id)
+ if handler := oo.getDeviceHandler(device.Id); handler != nil {
+ go handler.DisableDevice(device)
+ return nil
+ }
+ logger.Warn("no handler found for reenable device 'device.Id'")
+ return fmt.Errorf(fmt.Sprintf("handler-not-found-%s", device.Id))
}
//Reenable_device enables the olt device after disable
func (oo *OpenONUAC) Reenable_device(device *voltha.Device) error {
- return errors.New("unImplemented")
+ logger.Debug("Reenable_device", device.Id)
+ if handler := oo.getDeviceHandler(device.Id); handler != nil {
+ go handler.ReenableDevice(device)
+ return nil
+ }
+ logger.Warn("no handler found for reenable device 'device.Id'")
+ return fmt.Errorf(fmt.Sprintf("handler-not-found-%s", device.Id))
}
//Reboot_device reboots the given device