[VOL-3187]Pass Context down the execution call hierarchy across voltha-go codebase

Change-Id: I6bc2a0f7226c1beed4ae01a15d7b5c4dc04358d8
diff --git a/rw_core/route/common.go b/rw_core/route/common.go
index e47f8c9..8aaca26 100644
--- a/rw_core/route/common.go
+++ b/rw_core/route/common.go
@@ -21,12 +21,12 @@
 	"github.com/opencord/voltha-lib-go/v3/pkg/log"
 )
 
-var logger log.Logger
+var logger log.CLogger
 
 func init() {
 	// Setup this package so that it's log level can be modified at run time
 	var err error
-	logger, err = log.AddPackage(log.JSON, log.ErrorLevel, log.Fields{"pkg": "route"})
+	logger, err = log.RegisterPackage(log.JSON, log.ErrorLevel, log.Fields{"pkg": "route"})
 	if err != nil {
 		panic(err)
 	}
diff --git a/rw_core/route/device_route.go b/rw_core/route/device_route.go
index 5cd75f2..a1f2ae9 100644
--- a/rw_core/route/device_route.go
+++ b/rw_core/route/device_route.go
@@ -65,7 +65,7 @@
 }
 
 // NewDeviceRoutes creates device graph instance
-func NewDeviceRoutes(logicalDeviceID string, getDevice GetDeviceFunc) *DeviceRoutes {
+func NewDeviceRoutes(ctx context.Context, logicalDeviceID string, getDevice GetDeviceFunc) *DeviceRoutes {
 	var dr DeviceRoutes
 	dr.logicalDeviceID = logicalDeviceID
 	dr.getDeviceFromModel = getDevice
@@ -74,7 +74,7 @@
 	dr.devicesPonPorts = make(map[string][]*voltha.Port)
 	dr.childConnectionPort = make(map[string]uint32)
 	dr.logicalPorts = make(map[uint32]*voltha.LogicalPort)
-	logger.Debug("new device routes created ...")
+	logger.Debug(ctx, "new device routes created ...")
 	return &dr
 }
 
@@ -124,7 +124,7 @@
 	dr.routeBuildLock.Lock()
 	defer dr.routeBuildLock.Unlock()
 
-	logger.Debugw("computing-all-routes", log.Fields{"len-logical-ports": len(lps)})
+	logger.Debugw(ctx, "computing-all-routes", log.Fields{"len-logical-ports": len(lps)})
 	var err error
 	defer func() {
 		// On error, clear the routes - any flow request or a port add/delete will trigger the rebuild
@@ -175,7 +175,7 @@
 		}
 		for _, rootDevicePort := range rootDevice.Ports {
 			if rootDevicePort.Type == voltha.Port_PON_OLT {
-				logger.Debugw("peers", log.Fields{"root-device-id": rootDevice.Id, "port-no": rootDevicePort.PortNo, "len-peers": len(rootDevicePort.Peers)})
+				logger.Debugw(ctx, "peers", log.Fields{"root-device-id": rootDevice.Id, "port-no": rootDevicePort.PortNo, "len-peers": len(rootDevicePort.Peers)})
 				for _, rootDevicePeer := range rootDevicePort.Peers {
 					childDevice, err = dr.getDeviceWithCacheUpdate(ctx, rootDevicePeer.DeviceId)
 					if err != nil {
@@ -210,7 +210,7 @@
 // AddPort augments the current set of routes with new routes corresponding to the logical port "lp".  If the routes have
 // not been built yet then use logical port "lps" to compute all current routes (lps includes lp)
 func (dr *DeviceRoutes) AddPort(ctx context.Context, lp *voltha.LogicalPort, device *voltha.Device, lps map[uint32]*voltha.LogicalPort) error {
-	logger.Debugw("add-port-to-routes", log.Fields{"port": lp, "count-logical-ports": len(lps)})
+	logger.Debugw(ctx, "add-port-to-routes", log.Fields{"port": lp, "count-logical-ports": len(lps)})
 
 	// Adding NNI port
 	if lp.RootPort {
@@ -223,7 +223,7 @@
 
 // AddUNIPort setup routes between the logical UNI port lp and all registered NNI ports
 func (dr *DeviceRoutes) AddUNIPort(ctx context.Context, lp *voltha.LogicalPort, device *voltha.Device, lps map[uint32]*voltha.LogicalPort) error {
-	logger.Debugw("add-uni-port-to-routes", log.Fields{"port": lp, "count-logical-ports": len(lps)})
+	logger.Debugw(ctx, "add-uni-port-to-routes", log.Fields{"port": lp, "count-logical-ports": len(lps)})
 
 	dr.routeBuildLock.Lock()
 	defer dr.routeBuildLock.Unlock()
@@ -260,7 +260,7 @@
 
 // AddNNIPort setup routes between the logical NNI port lp and all registered UNI ports
 func (dr *DeviceRoutes) AddNNIPort(ctx context.Context, lp *voltha.LogicalPort, device *voltha.Device, lps map[uint32]*voltha.LogicalPort) error {
-	logger.Debugw("add-port-to-routes", log.Fields{"port": lp, "logical-ports-count": len(lps), "device-id": device.Id})
+	logger.Debugw(ctx, "add-port-to-routes", log.Fields{"port": lp, "logical-ports-count": len(lps), "device-id": device.Id})
 
 	dr.routeBuildLock.Lock()
 	defer dr.routeBuildLock.Unlock()
@@ -282,7 +282,7 @@
 
 	for _, rootDevicePort := range device.Ports {
 		if rootDevicePort.Type == voltha.Port_PON_OLT {
-			logger.Debugw("peers", log.Fields{"root-device-id": device.Id, "port-no": rootDevicePort.PortNo, "len-peers": len(rootDevicePort.Peers)})
+			logger.Debugw(ctx, "peers", log.Fields{"root-device-id": device.Id, "port-no": rootDevicePort.PortNo, "len-peers": len(rootDevicePort.Peers)})
 			for _, rootDevicePeer := range rootDevicePort.Peers {
 				childDevice, err := dr.getDeviceWithCacheUpdate(ctx, rootDevicePeer.DeviceId)
 				if err != nil {
@@ -318,7 +318,7 @@
 
 // AddAllPorts setups up new routes using all ports on the device. lps includes the device's logical port
 func (dr *DeviceRoutes) AddAllPorts(ctx context.Context, device *voltha.Device, lps map[uint32]*voltha.LogicalPort) error {
-	logger.Debugw("add-all-port-to-routes", log.Fields{"logical-ports-count": len(lps), "device-id": device.Id})
+	logger.Debugw(ctx, "add-all-port-to-routes", log.Fields{"logical-ports-count": len(lps), "device-id": device.Id})
 	for _, lp := range lps {
 		if lp.DeviceId == device.Id {
 			if err := dr.AddPort(ctx, lp, device, lps); err != nil {
@@ -330,10 +330,10 @@
 }
 
 // Print prints routes
-func (dr *DeviceRoutes) Print() error {
+func (dr *DeviceRoutes) Print(ctx context.Context) error {
 	dr.routeBuildLock.RLock()
 	defer dr.routeBuildLock.RUnlock()
-	logger.Debugw("Print", log.Fields{"logical-device-id": dr.logicalDeviceID, "logical-ports": dr.logicalPorts})
+	logger.Debugw(ctx, "Print", log.Fields{"logical-device-id": dr.logicalDeviceID, "logical-ports": dr.logicalPorts})
 	if logger.V(log.DebugLevel) {
 		output := ""
 		routeNumber := 1
@@ -348,9 +348,9 @@
 			routeNumber++
 		}
 		if len(dr.Routes) == 0 {
-			logger.Debugw("no-routes-found", log.Fields{"logical-device-id": dr.logicalDeviceID})
+			logger.Debugw(ctx, "no-routes-found", log.Fields{"logical-device-id": dr.logicalDeviceID})
 		} else {
-			logger.Debugw("graph_routes", log.Fields{"lDeviceId": dr.logicalDeviceID, "Routes": output})
+			logger.Debugw(ctx, "graph_routes", log.Fields{"lDeviceId": dr.logicalDeviceID, "Routes": output})
 		}
 	}
 	return nil
@@ -414,7 +414,7 @@
 func (dr *DeviceRoutes) getDeviceWithCacheUpdate(ctx context.Context, deviceID string) (*voltha.Device, error) {
 	device, err := dr.getDeviceFromModel(ctx, deviceID)
 	if err != nil {
-		logger.Errorw("device-not-found", log.Fields{"deviceId": deviceID, "error": err})
+		logger.Errorw(ctx, "device-not-found", log.Fields{"deviceId": deviceID, "error": err})
 		return nil, err
 	}
 	dr.updateCache(device)
@@ -477,7 +477,7 @@
 
 	// Get child device from model
 	if _, err := dr.getDeviceWithCacheUpdate(ctx, deviceID); err != nil {
-		logger.Errorw("device-not-found", log.Fields{"device-id": deviceID, "error": err})
+		logger.Errorw(ctx, "device-not-found", log.Fields{"device-id": deviceID, "error": err})
 		return 0, err
 	}
 
@@ -498,7 +498,7 @@
 
 	// Get parent device from the model
 	if _, err := dr.getDeviceWithCacheUpdate(ctx, deviceID); err != nil {
-		logger.Errorw("device-not-found", log.Fields{"deviceId": deviceID, "error": err})
+		logger.Errorw(ctx, "device-not-found", log.Fields{"deviceId": deviceID, "error": err})
 		return 0, err
 	}
 	// Try again
diff --git a/rw_core/route/device_route_test.go b/rw_core/route/device_route_test.go
index 4fe095b..0fd0836 100644
--- a/rw_core/route/device_route_test.go
+++ b/rw_core/route/device_route_test.go
@@ -77,8 +77,8 @@
 	}
 }
 
-func (ldM *logicalDeviceManager) start(getDevice GetDeviceFunc, buildRoutes bool) {
-	ldM.deviceRoutes = NewDeviceRoutes(ldM.logicalDeviceID, getDevice)
+func (ldM *logicalDeviceManager) start(ctx context.Context, getDevice GetDeviceFunc, buildRoutes bool) {
+	ldM.deviceRoutes = NewDeviceRoutes(ctx, ldM.logicalDeviceID, getDevice)
 	ofpPortNo := uint32(1)
 	for portReg := range ldM.ldChnl {
 		if portReg.port == nil {
@@ -274,7 +274,8 @@
 	onuMgr := newOnuManager(oltMgr, numOnuPerOltPonPort, numUniPerOnu, 2)
 	getDevice := onuMgr.GetDeviceHelper
 	// Start the managers.  Only the devices are created.  No routes will be built.
-	go ldMgr.start(getDevice, false)
+	ctx := context.Background()
+	go ldMgr.start(ctx, getDevice, false)
 	go oltMgr.start()
 	go onuMgr.start(numNNIPort+1, numPonPortOnOlt)
 
@@ -320,8 +321,10 @@
 	oltMgr := newOltManager(oltDeviceID, ldMgr, numNNIPort, numPonPortOnOlt, oltMgrChnl)
 	onuMgr := newOnuManager(oltMgr, numOnuPerOltPonPort, numUniPerOnu, 2)
 	getDevice := onuMgr.GetDeviceHelper
+
+	ctx := context.Background()
 	// Start the managers and trigger the routes to be built as the logical ports become available
-	go ldMgr.start(getDevice, true)
+	go ldMgr.start(ctx, getDevice, true)
 	go oltMgr.start()
 	go onuMgr.start(numNNIPort+1, numPonPortOnOlt)
 
@@ -330,7 +333,7 @@
 	close(oltMgrChnl)
 	close(ldMgrChnl)
 
-	ldMgr.deviceRoutes.Print()
+	ldMgr.deviceRoutes.Print(ctx)
 
 	// Validate the routes are up to date
 	assert.True(t, ldMgr.deviceRoutes.isUpToDate(ldMgr.ports))
@@ -364,8 +367,9 @@
 	oltMgr1 := newOltManager(oltDeviceID, ldMgr1, numNNIPort, numPonPortOnOlt, oltMgrChnl1)
 	onuMgr1 := newOnuManager(oltMgr1, numOnuPerOltPonPort, numUniPerOnu, 2)
 	getDevice := onuMgr1.GetDeviceHelper
+	ctx := context.Background()
 	// Start the managers.  Only the devices are created.  No routes will be built.
-	go ldMgr1.start(getDevice, false)
+	go ldMgr1.start(ctx, getDevice, false)
 	go oltMgr1.start()
 	go onuMgr1.start(numNNIPort+1, numPonPortOnOlt)
 
@@ -388,7 +392,7 @@
 	oltMgr2 := newOltManager(oltDeviceID, ldMgr2, numNNIPort, numPonPortOnOlt, oltMgrChnl2)
 	onuMgr2 := newOnuManager(oltMgr2, numOnuPerOltPonPort, numUniPerOnu, 2)
 	// Start the managers.  Only the devices are created.  No routes will be built.
-	go ldMgr2.start(getDevice, true)
+	go ldMgr2.start(ctx, getDevice, true)
 	go oltMgr2.start()
 	go onuMgr2.start(numNNIPort+1, numPonPortOnOlt)