FTTH-48015 Rest api to fetch ports per device with device id changes

Change-Id: Ieb9e42ceeb026a838a1ef9fe093e23e8e252c1e0
diff --git a/voltha-go-controller/onos_nbi/deviceportadapter.go b/voltha-go-controller/onos_nbi/deviceportadapter.go
index 800d497..740ac31 100644
--- a/voltha-go-controller/onos_nbi/deviceportadapter.go
+++ b/voltha-go-controller/onos_nbi/deviceportadapter.go
@@ -11,7 +11,7 @@
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
-*/
+ */
 
 package onos_nbi
 
@@ -19,9 +19,10 @@
 	"encoding/json"
 	"net/http"
 
-	"github.com/gorilla/mux"
 	app "voltha-go-controller/internal/pkg/application"
 	"voltha-go-controller/log"
+
+	"github.com/gorilla/mux"
 )
 
 // DeviceHandle Handle DeviceIDList Requests
@@ -42,6 +43,7 @@
 		logger.Warnw(ctx, "Unsupported Method", log.Fields{"Method": r.Method})
 	}
 }
+
 // GetDeviceList to get device id list
 func (dh *DeviceHandle) GetDeviceList(w http.ResponseWriter, r *http.Request) {
 
@@ -100,13 +102,14 @@
 	vars := mux.Vars(r)
 	deviceID := vars["olt_of_id"]
 
-	var portListResp PortEntry
-	portListResp.Ports = []Port{}
+	var devicePortListResp DevicePortEntry
+	devicePortListResp.Device = Device{}
+	devicePortListResp.Ports = []Port{}
 
 	getPortList := func(key, value interface{}) bool {
 		voltPort := value.(*app.VoltPort)
 		port := convertVoltPortToPort(voltPort)
-		portListResp.Ports = append(portListResp.Ports, port)
+		devicePortListResp.Ports = append(devicePortListResp.Ports, port)
 		return true
 	}
 	if len(deviceID) > 0 {
@@ -114,10 +117,12 @@
 		voltDevice := app.GetApplication().GetDevice(deviceID)
 		if voltDevice != nil {
 			logger.Infow(ctx, "Found device", log.Fields{"deviceID": deviceID})
+			devicePortListResp.Device = convertVoltDeviceToDevice(voltDevice)
 			voltDevice.Ports.Range(getPortList)
 		}
+
 	}
-	portListJSON, err := json.Marshal(portListResp)
+	portListJSON, err := json.Marshal(devicePortListResp)
 	if err != nil {
 		logger.Errorw(ctx, "Error occurred while marshaling port list response", log.Fields{"Error": err})
 		w.WriteHeader(http.StatusInternalServerError)
@@ -131,6 +136,7 @@
 		w.WriteHeader(http.StatusInternalServerError)
 	}
 }
+
 // GetPortList to get device id list
 func (dh *DevicePortHandle) GetPortList(w http.ResponseWriter, r *http.Request) {
 
@@ -166,4 +172,3 @@
 		w.WriteHeader(http.StatusInternalServerError)
 	}
 }
-
diff --git a/voltha-go-controller/onos_nbi/models.go b/voltha-go-controller/onos_nbi/models.go
index 5f8f923..abf4950 100644
--- a/voltha-go-controller/onos_nbi/models.go
+++ b/voltha-go-controller/onos_nbi/models.go
@@ -248,6 +248,12 @@
 	FAILED string = "FAILED"
 
 	PENDING string = "PENDING"
+
+	FAILED_ADD string = "FAILED_ADD"
+
+	PENDING_ADD string = "PENDING_ADD"
+
+	PENDING_REMOVE string = "PENDING_REMOVE"
 )
 
 // Selector Critrtion structs
@@ -508,13 +514,27 @@
 	return flowEntry
 }
 
+func FlowStateMapping(state uint8) string {
+	var flowState string
+	if state == of.FlowAddSuccess {
+		flowState = ADDED
+	} else if state == of.FlowAddFailure {
+		flowState = FAILED_ADD
+	} else if state == of.FlowAddPending {
+		flowState = PENDING_ADD
+	} else if state == of.FlowDelPending {
+		flowState = PENDING_REMOVE
+	}
+	return flowState
+}
+
 func ConvertVoltSubFlowToOnosFlow(subFlow *of.VoltSubFlow) Flow {
 	var flow Flow
 	flow.ID = strconv.FormatUint(subFlow.Cookie, 10)
 	flow.TableID = int(subFlow.TableID)
 	flow.Priority = int(subFlow.Priority)
-	//flow.State = subFlow.State
-
+	state := FlowStateMapping(subFlow.State)
+	flow.State = state
 	// Fill Match criteria
 	if subFlow.InPort != 0 {
 		portSelector := PortSelector{
@@ -723,6 +743,11 @@
 	Ports []Port `json:"ports"`
 }
 
+type DevicePortEntry struct {
+	Device Device `json:"device"`
+	Ports  []Port `json:"ports"`
+}
+
 type Port struct {
 	Element     string          `json:"element"`
 	Port        string          `json:"port"`