[VOL-936] add changes for onu distance from OLT
Change-Id: If6201799946ac753780d0424c4bd986e2fb394d2
diff --git a/rw_core/core/api/grpc_nbi_handler.go b/rw_core/core/api/grpc_nbi_handler.go
index 0bacb33..3e06cf7 100755
--- a/rw_core/core/api/grpc_nbi_handler.go
+++ b/rw_core/core/api/grpc_nbi_handler.go
@@ -807,6 +807,6 @@
}
func (handler *NBIHandler) GetExtValue(ctx context.Context, valueparam *voltha.ValueSpecifier) (*voltha.ReturnValues, error) {
- log.Debugw("GetValue-request", log.Fields{"onu-id": valueparam.Id})
- return nil, errors.New("UnImplemented")
+ log.Debugw("GetExtValue-request", log.Fields{"onu-id": valueparam.Id})
+ return handler.deviceMgr.GetExtValue(ctx, valueparam)
}
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...)
+}
diff --git a/rw_core/mocks/adapter.go b/rw_core/mocks/adapter.go
index 6a8fb22..e14457d 100644
--- a/rw_core/mocks/adapter.go
+++ b/rw_core/mocks/adapter.go
@@ -259,3 +259,7 @@
func (ta *Adapter) Start_omci_test(device *voltha.Device, request *voltha.OmciTestRequest) (*voltha.TestResponse, error) { //nolint
return nil, nil
}
+
+func (ta *Adapter) Get_ext_value(deviceId string, device *voltha.Device, valueflag voltha.ValueType_Type) (*voltha.ReturnValues, error) { //nolint
+ return nil, nil
+}
diff --git a/rw_core/mocks/adapter_olt.go b/rw_core/mocks/adapter_olt.go
index 5f67da7..07077c8 100644
--- a/rw_core/mocks/adapter_olt.go
+++ b/rw_core/mocks/adapter_olt.go
@@ -332,3 +332,10 @@
oltA.flows = map[uint64]*voltha.OfpFlowStats{}
}
+
+func (oltA *OLTAdapter) Get_ext_value(deviceId string, device *voltha.Device, valueflag voltha.ValueType_Type) (*voltha.ReturnValues, error) { // nolint
+ _ = deviceId
+ _ = device
+ _ = valueflag
+ return nil, errors.New("get-ext-value-not-implemented")
+}
diff --git a/rw_core/mocks/adapter_onu.go b/rw_core/mocks/adapter_onu.go
index 549e016..5f4a5e6 100644
--- a/rw_core/mocks/adapter_onu.go
+++ b/rw_core/mocks/adapter_onu.go
@@ -18,6 +18,7 @@
import (
"context"
+ "errors"
"fmt"
"strings"
"sync"
@@ -240,3 +241,10 @@
onuA.flows = map[uint64]*voltha.OfpFlowStats{}
}
+
+func (onuA *ONUAdapter) Get_ext_value(deviceId string, device *voltha.Device, valueflag voltha.ValueType_Type) (*voltha.ReturnValues, error) { // nolint
+ _ = deviceId
+ _ = device
+ _ = valueflag
+ return nil, errors.New("get-ext-value-not-implemented")
+}