[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})
+}