[VOL-5535] update deviceconfig

Change-Id: Ibeb7767fedeef4d81ed913adbc3e8ec0b5074bbc
Signed-off-by: Akash Reddy Kankanala <akash.kankanala@radisys.com>
diff --git a/VERSION b/VERSION
index e8e277f..04c5555 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-0.1.16
+0.1.17
diff --git a/voltha-go-controller/nbi/rest.go b/voltha-go-controller/nbi/rest.go
index 966f69a..6a9be34 100644
--- a/voltha-go-controller/nbi/rest.go
+++ b/voltha-go-controller/nbi/rest.go
@@ -87,6 +87,7 @@
 	NetConfigPath                     string = "/network-configurations"
 	DeviceConfigPath                  string = "/olt/{serialNumber}"
 	FlowProvisionStatus               string = "/flow-status/{portName}"
+	Uplinkpath                        string = "/uplink/{deviceId}"
 )
 
 // RestStart to execute for API
@@ -133,6 +134,7 @@
 	mu.HandleFunc(BasePath+NetConfigPath, prometheusMiddleware((&NetConfigHandle{}).NetConfigServeHTTP))
 	mu.HandleFunc(BasePath+DeviceConfigPath, prometheusMiddleware((&onosnbi.DeviceConfigHandle{}).ServeHTTP))
 	mu.HandleFunc(BasePath+FlowProvisionStatus, prometheusMiddleware((&SubscriberHandle{}).StatusServeHTTP))
+	mu.HandleFunc(BasePath+Uplinkpath, (&onosnbi.UpdateUplinkDeviceConfigHandle{}).ServeHTTP)
 
 	err := http.ListenAndServe(":8181", mu)
 	if p != nil {
diff --git a/voltha-go-controller/onos_nbi/deviceconfig.go b/voltha-go-controller/onos_nbi/deviceconfig.go
index 949b447..afb2afe 100644
--- a/voltha-go-controller/onos_nbi/deviceconfig.go
+++ b/voltha-go-controller/onos_nbi/deviceconfig.go
@@ -38,6 +38,9 @@
 type DeviceConfigHandle struct {
 }
 
+type UpdateUplinkDeviceConfigHandle struct {
+}
+
 // ServeHTTP to serve HTTP requests
 func (oh *DeviceConfigHandle) ServeHTTP(w http.ResponseWriter, r *http.Request) {
 	logger.Infow(ctx, "Received-northbound-request", log.Fields{"Method": r.Method, "URL": r.URL})
@@ -53,6 +56,19 @@
 	}
 }
 
+// ServeHTTP to serve HTTP requests
+func (oh *UpdateUplinkDeviceConfigHandle) ServeHTTP(w http.ResponseWriter, r *http.Request) {
+	logger.Infow(ctx, "Received-northbound-request", log.Fields{"Method": r.Method, "URL": r.URL})
+	switch r.Method {
+	case cPost:
+		oh.UpdateDeviceConfig(context.Background(), w, r)
+	default:
+		logger.Warnw(ctx, "Unsupported Method", log.Fields{"Method": r.Method})
+		err := errorCodes.ErrOperationNotSupported
+		http.Error(w, err.Error(), http.StatusBadRequest)
+	}
+}
+
 func (oh *DeviceConfigHandle) AddDeviceConfig(cntx context.Context, w http.ResponseWriter, r *http.Request) {
 	logger.Debug(cntx, "Inside AddDeviceConfig method")
 	// Get the payload to process the request
@@ -104,3 +120,31 @@
 		http.Error(w, err.Error(), http.StatusBadRequest)
 	}
 }
+
+func (oh *UpdateUplinkDeviceConfigHandle) UpdateDeviceConfig(cntx context.Context, w http.ResponseWriter, r *http.Request) {
+	logger.Debug(cntx, "Inside UpdateDeviceConfig method")
+	// Get the payload to process the request
+	d := new(bytes.Buffer)
+	if _, err := d.ReadFrom(r.Body); err != nil {
+		logger.Errorw(ctx, "Error reading buffer", log.Fields{"Reason": err.Error()})
+		http.Error(w, err.Error(), http.StatusConflict)
+		return
+	}
+	// Unmarshal the request into device configuration structure
+	req := &app.DeviceConfig{}
+	if err := json.Unmarshal(d.Bytes(), req); err != nil {
+		logger.Errorw(ctx, "Unmarshal Failed", log.Fields{"Reason": err.Error()})
+		http.Error(w, err.Error(), http.StatusConflict)
+		return
+	}
+	if len(req.NniPorts) == 0 {
+		logger.Errorw(ctx, "No NNI ports to update", log.Fields{"Req": req})
+		err := errorCodes.ErrInvalidParamInRequest
+		http.Error(w, err.Error(), http.StatusBadRequest)
+		return
+	}
+	devConfig := app.GetApplication().GetDeviceConfig(req.SerialNumber)
+	devConfig.NniPorts = req.NniPorts
+	app.GetApplication().UpdateDeviceConfig(cntx, devConfig)
+	logger.Infow(ctx, "updated Device Config ", log.Fields{"Req": req})
+}