This commit fixes some issues in the Core:

1) Fix the loading of the logical device agent in the Core that does
not own the device.
2) Fix an issue when UNI logical ports were ready to be added but
the logical device was not fully ready.
3) Fix an issue with a deadlock condition when multiple flows were
added to the same device
4) Update the logic when receiving requests to process flows from
OFAgent.  The logic will need to be revamped in a subsequent
commit once OFAgent is able to send transactions IDs when issueing
Flow updates.
5) Setup device ownership after a device has been loaded in memory.

Change-Id: I2d604e2ba89e5af21f96871414852c2b6ef85f08
diff --git a/rw_core/core/device_manager.go b/rw_core/core/device_manager.go
index a96166d..faf8da8 100755
--- a/rw_core/core/device_manager.go
+++ b/rw_core/core/device_manager.go
@@ -21,6 +21,7 @@
 	"github.com/opencord/voltha-go/common/log"
 	"github.com/opencord/voltha-go/db/model"
 	"github.com/opencord/voltha-go/kafka"
+	"github.com/opencord/voltha-go/rw_core/utils"
 	ic "github.com/opencord/voltha-protos/go/inter_container"
 	ofp "github.com/opencord/voltha-protos/go/openflow_13"
 	"github.com/opencord/voltha-protos/go/voltha"
@@ -121,14 +122,21 @@
 		dMgr.lockDeviceAgentsMap.RUnlock()
 		return agent
 	} else {
-		//	Try to load into memory - loading will also create the device agent
+		//	Try to load into memory - loading will also create the device agent and set the device ownership
 		dMgr.lockDeviceAgentsMap.RUnlock()
 		if err := dMgr.load(deviceId); err == nil {
 			dMgr.lockDeviceAgentsMap.RLock()
 			defer dMgr.lockDeviceAgentsMap.RUnlock()
-			if agent, ok = dMgr.deviceAgents[deviceId]; ok {
+			if agent, ok = dMgr.deviceAgents[deviceId]; !ok {
+				return nil
+			} else {
+				// Register this device for ownership tracking
+				go dMgr.core.deviceOwnership.OwnedByMe(&utils.DeviceID{Id: deviceId})
 				return agent
 			}
+		} else {
+			//TODO: Change the return params to return an error as well
+			log.Errorw("loading-device-failed", log.Fields{"deviceId": deviceId, "error": err})
 		}
 	}
 	return nil