VOL-3248 Support for SetExtValue API

         This commits adds a new SetExtValue API in the VOLTHA
         core and also the handling of the request.

Change-Id: I45b76e4bcc3234842c8404514f5220573ac33211
diff --git a/rw_core/core/device/agent.go b/rw_core/core/device/agent.go
index 03cc3b8..053d9f3 100755
--- a/rw_core/core/device/agent.go
+++ b/rw_core/core/device/agent.go
@@ -26,6 +26,7 @@
 	"time"
 
 	"github.com/golang/protobuf/ptypes"
+	"github.com/golang/protobuf/ptypes/empty"
 	"github.com/opencord/voltha-go/rw_core/core/adapter"
 	"github.com/opencord/voltha-go/rw_core/core/device/flow"
 	"github.com/opencord/voltha-go/rw_core/core/device/group"
@@ -792,3 +793,30 @@
 	logger.Debugw(ctx, "getExtValue-Success-device-agent", log.Fields{"Resp": Resp})
 	return Resp, nil
 }
+
+func (agent *Agent) setExtValue(ctx context.Context, device *voltha.Device, value *voltha.ValueSet) (*empty.Empty, error) {
+	logger.Debugw(ctx, "setExtValue", log.Fields{"device-id": value.Id})
+	if err := agent.requestQueue.WaitForGreenLight(ctx); err != nil {
+		return nil, err
+	}
+
+	//send request to adapter
+	ch, err := agent.adapterProxy.SetExtValue(ctx, device, 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
+	logger.Debug(ctx, "setExtValue-Success-device-agent")
+	return &empty.Empty{}, nil
+}
diff --git a/rw_core/core/device/manager.go b/rw_core/core/device/manager.go
index 345255f..fc6a3dd 100755
--- a/rw_core/core/device/manager.go
+++ b/rw_core/core/device/manager.go
@@ -1563,3 +1563,22 @@
 	return nil, status.Errorf(codes.NotFound, "%s", value.Id)
 
 }
+
+// SetExtValue  set some given configs or value
+func (dMgr *Manager) SetExtValue(ctx context.Context, value *voltha.ValueSet) (*empty.Empty, error) {
+	logger.Debugw(ctx, "setExtValue", log.Fields{"onu-id": value.Id})
+	device, err := dMgr.getDeviceReadOnly(ctx, value.Id)
+	if err != nil {
+		return nil, status.Errorf(codes.Aborted, "%s", err.Error())
+	}
+	if agent := dMgr.getDeviceAgent(ctx, device.Id); agent != nil {
+		resp, err := agent.setExtValue(ctx, device, value)
+		if err != nil {
+			return nil, err
+		}
+		logger.Debugw(ctx, "setExtValue-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 e8681c4..f3d3358 100755
--- a/rw_core/core/device/remote/adapter_proxy.go
+++ b/rw_core/core/device/remote/adapter_proxy.go
@@ -454,3 +454,23 @@
 	replyToTopic := ap.getCoreTopic()
 	return ap.sendRPC(ctx, rpc, toTopic, &replyToTopic, true, pdevice.Id, args...)
 }
+
+// SetExtValue  set some given configs or value
+func (ap *AdapterProxy) SetExtValue(ctx context.Context, device *voltha.Device, value *voltha.ValueSet) (chan *kafka.RpcResponse, error) {
+	logger.Debugw(ctx, "SetExtValue", log.Fields{"device-id": value.Id})
+	rpc := "set_ext_value"
+	toTopic, err := ap.getAdapterTopic(ctx, value.Id, device.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:   "value",
+			Value: value,
+		},
+	}
+	replyToTopic := ap.getCoreTopic()
+	return ap.sendRPC(ctx, rpc, toTopic, &replyToTopic, true, value.Id, args...)
+}