[VOL-1614] Device Management update in the Core
This commit went over the device management of devices in the Core
and made the following changes:
1) Update the device state machine to not remove logical
device or ports when a device is disabled.
2) Fix some issues around device deletion
3) Add additional APIs between the Core and Adapters to handle
the scenarios of enable/disable/delete a device
4) Update the simulated Adapters to handle disable/reenable/delete
5) Add a new set of tests for teh device state machine.
Change-Id: Ib2be87ec011762d5315a6d54581a87c1891e92be
diff --git a/adapters/simulated_onu/adaptercore/device_handler.go b/adapters/simulated_onu/adaptercore/device_handler.go
index a845427..96cb3d8 100644
--- a/adapters/simulated_onu/adaptercore/device_handler.go
+++ b/adapters/simulated_onu/adaptercore/device_handler.go
@@ -27,6 +27,7 @@
"strconv"
"strings"
"sync"
+ "time"
)
//DeviceHandler follows the same patterns as ponsim_olt. The only difference is that it does not
@@ -105,6 +106,27 @@
log.Errorw("error-updating-device", log.Fields{"deviceId": device.Id, "error": err})
}
+ // Update the device state to DISCOVERED
+ cloned.ConnectStatus = voltha.ConnectStatus_REACHABLE
+ cloned.OperStatus = voltha.OperStatus_DISCOVERED
+ if err := dh.coreProxy.DeviceStateUpdate(nil, cloned.Id, cloned.ConnectStatus, cloned.OperStatus); err != nil {
+ log.Errorw("error-creating-nni-port", log.Fields{"deviceId": device.Id, "error": err})
+ }
+
+ // Sleep to mimic the omci management channel creation with the OLT
+ time.Sleep(10 * time.Millisecond)
+
+ // Update the device state to ACTIVATING
+ cloned.ConnectStatus = voltha.ConnectStatus_REACHABLE
+ cloned.OperStatus = voltha.OperStatus_ACTIVATING
+ if err := dh.coreProxy.DeviceStateUpdate(nil, cloned.Id, cloned.ConnectStatus, cloned.OperStatus); err != nil {
+ log.Errorw("error-creating-nni-port", log.Fields{"deviceId": device.Id, "error": err})
+ }
+
+ // Sleep to mimic the omci discovery ( usually takes a few seconds but for ease of simulated environment we are
+ // setting it to 100ms only.
+ time.Sleep(100 * time.Millisecond)
+
// Use the channel Id, assigned by the parent device to me, as the port number
uni_port := uint32(2)
if device.ProxyAddress != nil {
@@ -223,3 +245,14 @@
}
log.Debugw("ReEnableDevice-end", log.Fields{"deviceId": device.Id})
}
+
+func (dh *DeviceHandler) DeleteDevice(device *voltha.Device) {
+ cloned := proto.Clone(device).(*voltha.Device)
+ // Update the all ports state on that device to disable
+ if err := dh.coreProxy.DeleteAllPorts(nil, cloned.Id); err != nil {
+ log.Errorw("delete-ports-failed", log.Fields{"deviceId": device.Id, "error": err})
+ return
+ }
+
+ log.Debugw("DeleteDevice-end", log.Fields{"deviceId": device.Id})
+}
diff --git a/adapters/simulated_onu/adaptercore/simulated_onu.go b/adapters/simulated_onu/adaptercore/simulated_onu.go
index a74b377..1bdd4bb 100644
--- a/adapters/simulated_onu/adaptercore/simulated_onu.go
+++ b/adapters/simulated_onu/adaptercore/simulated_onu.go
@@ -190,8 +190,17 @@
return errors.New("UnImplemented")
}
-func (so *SimulatedONU) Gelete_device(device *voltha.Device) error {
- return errors.New("UnImplemented")
+func (so *SimulatedONU) Delete_device(device *voltha.Device) error {
+ if device == nil {
+ log.Warn("device-is-nil")
+ return errors.New("nil-device")
+ }
+ log.Infow("delete-device", log.Fields{"deviceId": device.Id})
+ var handler *DeviceHandler
+ if handler = so.getDeviceHandler(device.Id); handler != nil {
+ go handler.DeleteDevice(device)
+ }
+ return nil
}
func (so *SimulatedONU) Get_device_details(device *voltha.Device) error {