[VOL-2995] Improve Core performance

This commit consists of the following changes with the aim to
improve the Core performance:

1) Use a hybrid approach of pre-route calculation and route
calculation on-demand.  For example, attempts to pre-calculate
routes will be done whenever a nni/uni port is discovered.  The
attempt may fail if there are not enough ports to generate a
route.  When a flow is received and the route is not available
then only the route relevant to that flow will be created on
demand.

2) Changes some of the route calculation flow such that the
process does not need to go and grab the latest version of the
device which could lead to higher latency, expecially if that
device is busy with other processing.

3) Change the logic when reporting added ports to ONOS such that
routes are calculated (at least an attempt made) before sending
a port create notification to ONOS.

4) Move peer port creation into its own go routine thereby
removing the lock on a child device much earlier.

5) Wait until a request for port capability is received before
removing the lock on a device.   A better approach is required
where the adapter will need to report the port capability along
with the port creation event.  However, this require another
Jira as changes will be required in the API.

6) Remove some unnecessary proto.clones.  Those are the obvious
ones.  Removal of other proto.clones will be done in a separate
commit.

7) Fix a core panic when concurrent requests are made to the
route map

Change-Id: I2bafc99dbf10d7026572a44af0b88a31b5eb1887
diff --git a/rw_core/route/device_route_test.go b/rw_core/route/device_route_test.go
index 1f90ecd..fbbc802 100644
--- a/rw_core/route/device_route_test.go
+++ b/rw_core/route/device_route_test.go
@@ -35,6 +35,10 @@
 	oltDeviceID     = "olt"
 )
 
+const testSetupPhase contextKey = "testSetupPhase"
+
+type contextKey string
+
 //portRegistration is a message sent from an OLT device to a logical device to create a logical port
 type portRegistration struct {
 	port     *voltha.Port
@@ -82,7 +86,11 @@
 		}
 		ldM.logicalDevice.Ports = append(ldM.logicalDevice.Ports, lp)
 		if buildRoutes {
-			err := ldM.deviceRoutes.AddPort(context.Background(), lp, ldM.logicalDevice.Ports)
+			device, err := getDevice(context.WithValue(context.Background(), testSetupPhase, true), lp.DeviceId)
+			if err != nil {
+				fmt.Println("Error when getting device:", lp.DeviceId, err)
+			}
+			err = ldM.deviceRoutes.AddPort(context.Background(), lp, device, ldM.logicalDevice.Ports)
 			if err != nil && !strings.Contains(err.Error(), "code = FailedPrecondition") {
 				fmt.Println("(Error when adding port:", lp, len(ldM.logicalDevice.Ports), err)
 			}
@@ -225,10 +233,12 @@
 	return nil
 }
 
-func (onuM *onuManager) GetDeviceHelper(_ context.Context, id string) (*voltha.Device, error) {
-	onuM.numGetDeviceInvokedLock.Lock()
-	onuM.numGetDeviceInvoked++
-	onuM.numGetDeviceInvokedLock.Unlock()
+func (onuM *onuManager) GetDeviceHelper(ctx context.Context, id string) (*voltha.Device, error) {
+	if ctx.Value(testSetupPhase) != true {
+		onuM.numGetDeviceInvokedLock.Lock()
+		onuM.numGetDeviceInvoked++
+		onuM.numGetDeviceInvokedLock.Unlock()
+	}
 	if id == oltDeviceID {
 		return onuM.oltMgr.olt, nil
 	}
@@ -241,7 +251,7 @@
 func TestDeviceRoutes_ComputeRoutes(t *testing.T) {
 	numNNIPort := 2
 	numPonPortOnOlt := 8
-	numOnuPerOltPonPort := 32
+	numOnuPerOltPonPort := 256
 	numUniPerOnu := 4
 	done := make(chan struct{})
 
@@ -272,7 +282,7 @@
 	assert.Nil(t, err)
 
 	// Validate the routes are up to date
-	assert.True(t, ldMgr.deviceRoutes.IsUpToDate(ld))
+	assert.True(t, ldMgr.deviceRoutes.isUpToDate(ld))
 
 	// Validate the expected number of routes
 	assert.EqualValues(t, 2*numNNIPort*numPonPortOnOlt*numOnuPerOltPonPort*numUniPerOnu, len(ldMgr.deviceRoutes.Routes))
@@ -286,8 +296,8 @@
 
 func TestDeviceRoutes_AddPort(t *testing.T) {
 	numNNIPort := 2
-	numPonPortOnOlt := 8
-	numOnuPerOltPonPort := 32
+	numPonPortOnOlt := 16
+	numOnuPerOltPonPort := 256
 	numUniPerOnu := 4
 	done := make(chan struct{})
 
@@ -316,7 +326,7 @@
 	ldMgr.deviceRoutes.Print()
 
 	// Validate the routes are up to date
-	assert.True(t, ldMgr.deviceRoutes.IsUpToDate(ld))
+	assert.True(t, ldMgr.deviceRoutes.isUpToDate(ld))
 
 	// Validate the expected number of routes
 	assert.EqualValues(t, 2*numNNIPort*numPonPortOnOlt*numOnuPerOltPonPort*numUniPerOnu, len(ldMgr.deviceRoutes.Routes))