[VOL-936] add changes for onu distance from OLT

Change-Id: If6201799946ac753780d0424c4bd986e2fb394d2
diff --git a/rw_core/core/device/agent.go b/rw_core/core/device/agent.go
index 264b44f..3857a6b 100755
--- a/rw_core/core/device/agent.go
+++ b/rw_core/core/device/agent.go
@@ -1732,3 +1732,34 @@
 	logger.Debugw("Omci_test_Request-Success-device-agent", log.Fields{"testResp": testResp})
 	return testResp, nil
 }
+
+func (agent *Agent) getExtValue(ctx context.Context, pdevice *voltha.Device, cdevice *voltha.Device, valueparam *voltha.ValueSpecifier) (*voltha.ReturnValues, error) {
+	log.Debugw("getExtValue", log.Fields{"device-id": agent.deviceID, "onuid": valueparam.Id, "valuetype": valueparam.Value})
+	if err := agent.requestQueue.WaitForGreenLight(ctx); err != nil {
+		return nil, err
+	}
+
+	//send request to adapter
+	ch, err := agent.adapterProxy.GetExtValue(ctx, pdevice, cdevice, valueparam.Id, valueparam.Value)
+	agent.requestQueue.RequestComplete()
+	if err != nil {
+		return nil, err
+	}
+
+	// Wait for the adapter response
+	rpcResponse, ok := <-ch
+	if !ok {
+		return nil, status.Errorf(codes.Aborted, "channel-closed-device-id-%s", agent.deviceID)
+	}
+	if rpcResponse.Err != nil {
+		return nil, rpcResponse.Err
+	}
+
+	// Unmarshal and return the response
+	Resp := &voltha.ReturnValues{}
+	if err := ptypes.UnmarshalAny(rpcResponse.Reply, Resp); err != nil {
+		return nil, status.Errorf(codes.InvalidArgument, "%s", err.Error())
+	}
+	logger.Debugw("getExtValue-Success-device-agent", log.Fields{"Resp": Resp})
+	return Resp, nil
+}
diff --git a/rw_core/core/device/manager.go b/rw_core/core/device/manager.go
index cd73f35..ad2af57 100755
--- a/rw_core/core/device/manager.go
+++ b/rw_core/core/device/manager.go
@@ -1563,3 +1563,25 @@
 	}
 	return nil, status.Errorf(codes.NotFound, "%s", omcitestrequest.Id)
 }
+
+func (dMgr *Manager) GetExtValue(ctx context.Context, value *voltha.ValueSpecifier) (*voltha.ReturnValues, error) {
+	log.Debugw("getExtValue", log.Fields{"onu-id": value.Id})
+	cDevice, err := dMgr.GetDevice(ctx, value.Id)
+	if err != nil {
+		return nil, status.Errorf(codes.Aborted, "%s", err.Error())
+	}
+	pDevice, err := dMgr.GetDevice(ctx, cDevice.ParentId)
+	if err != nil {
+		return nil, status.Errorf(codes.Aborted, "%s", err.Error())
+	}
+	if agent := dMgr.getDeviceAgent(ctx, cDevice.ParentId); agent != nil {
+		resp, err := agent.getExtValue(ctx, pDevice, cDevice, value)
+		if err != nil {
+			return nil, err
+		}
+		log.Debugw("getExtValue-result", log.Fields{"result": resp})
+		return resp, nil
+	}
+	return nil, status.Errorf(codes.NotFound, "%s", value.Id)
+
+}
diff --git a/rw_core/core/device/remote/adapter_proxy.go b/rw_core/core/device/remote/adapter_proxy.go
index 4b04ee5..f4579ef 100755
--- a/rw_core/core/device/remote/adapter_proxy.go
+++ b/rw_core/core/device/remote/adapter_proxy.go
@@ -430,3 +430,30 @@
 		&kafka.KVArg{Key: "device", Value: device},
 		&kafka.KVArg{Key: "omcitestrequest", Value: omcitestrequest})
 }
+
+func (ap *AdapterProxy) GetExtValue(ctx context.Context, pdevice *voltha.Device, cdevice *voltha.Device, id string, valuetype voltha.ValueType_Type) (chan *kafka.RpcResponse, error) {
+	log.Debugw("GetExtValue", log.Fields{"device-id": pdevice.Id, "onuid": id})
+	rpc := "get_ext_value"
+	toTopic, err := ap.getAdapterTopic(pdevice.Id, pdevice.Adapter)
+	if err != nil {
+		return nil, err
+	}
+	// Use a device specific topic to send the request.  The adapter handling the device creates a device
+	// specific topic
+	args := []*kafka.KVArg{
+		{
+			Key:   "pDeviceId",
+			Value: &ic.StrType{Val: pdevice.Id},
+		},
+		{
+			Key:   "device",
+			Value: cdevice,
+		},
+		{
+			Key:   "valuetype",
+			Value: &ic.IntType{Val: int64(valuetype)},
+		}}
+
+	replyToTopic := ap.getCoreTopic()
+	return ap.sendRPC(ctx, rpc, toTopic, &replyToTopic, true, pdevice.Id, args...)
+}