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/adapter_request_handler.go b/rw_core/core/adapter_request_handler.go
index 0de7953..dbd09e4 100644
--- a/rw_core/core/adapter_request_handler.go
+++ b/rw_core/core/adapter_request_handler.go
@@ -1067,16 +1067,22 @@
 	log.Debugw("PacketIn", log.Fields{"deviceId": deviceId.Id, "port": portNo.Val, "packet": packet,
 		"transactionID": transactionID.Val})
 
-	// For performance reason, we do not compete for packet-in.  We process it and send the packet in.  later in the
-	// processing flow the duplicate packet will be discarded
-
+	// Try to grab the transaction as this core may be competing with another Core
+	// TODO: If this adds too much latencies then needs to remove transaction and let OFAgent filter out
+	// duplicates.
+	if rhp.competeForTransaction() {
+		if txn, err := rhp.takeRequestOwnership(transactionID.Val, deviceId.Id); err != nil {
+			log.Debugw("Another core handled the request", log.Fields{"transactionID": transactionID})
+			return nil, nil
+		} else {
+			defer txn.Close()
+		}
+	}
 	if rhp.TestMode { // Execute only for test cases
 		return nil, nil
 	}
 	go rhp.deviceMgr.PacketIn(deviceId.Id, uint32(portNo.Val), transactionID.Val, packet.Payload)
-	//if err := rhp.deviceMgr.PacketIn(deviceId.Id, uint32(portNo.Val), transactionID.Val, packet.Payload); err != nil {
-	//	return nil, err
-	//}
+
 	return new(empty.Empty), nil
 }