VOL-1377 code changes required in voltha-go for flow handling in openolt adapter

Change-Id: I3edb766788cdd0b9c55efda8ca548f04e6d41c31
diff --git a/adapters/common/request_handler.go b/adapters/common/request_handler.go
index 5b839c6..d16ad95 100644
--- a/adapters/common/request_handler.go
+++ b/adapters/common/request_handler.go
@@ -24,6 +24,7 @@
 	"github.com/opencord/voltha-go/kafka"
 	ic "github.com/opencord/voltha-protos/go/inter_container"
 	"github.com/opencord/voltha-protos/go/voltha"
+        "github.com/opencord/voltha-protos/go/openflow_13"
 	"google.golang.org/grpc/codes"
 	"google.golang.org/grpc/status"
 )
@@ -134,6 +135,45 @@
 }
 
 func (rhp *RequestHandlerProxy) Update_flows_incrementally(args []*ic.Argument) (*empty.Empty, error) {
+        log.Debug("Update_flows_incrementally")
+	if len(args) < 3 {
+		log.Warn("Update_flows_incrementally-invalid-number-of-args", log.Fields{"args": args})
+		err := errors.New("invalid-number-of-args")
+		return nil, err
+	}
+	device := &voltha.Device{}
+	transactionID := &ic.StrType{}
+        flows := &openflow_13.FlowChanges{}
+        groups := &openflow_13.FlowGroupChanges{}
+	for _, arg := range args {
+		switch arg.Key {
+		case "device":
+			if err := ptypes.UnmarshalAny(arg.Value, device); err != nil {
+				log.Warnw("cannot-unmarshal-device", log.Fields{"error": err})
+				return nil, err
+			}
+		case "flow_changes":
+			if err := ptypes.UnmarshalAny(arg.Value, flows); err != nil {
+				log.Warnw("cannot-unmarshal-flows", log.Fields{"error": err})
+				return nil, err
+			}
+		case "group_changes":
+			if err := ptypes.UnmarshalAny(arg.Value, groups); err != nil {
+				log.Warnw("cannot-unmarshal-groups", log.Fields{"error": err})
+				return nil, err
+			}
+		case kafka.TransactionKey:
+			if err := ptypes.UnmarshalAny(arg.Value, transactionID); err != nil {
+				log.Warnw("cannot-unmarshal-transaction-ID", log.Fields{"error": err})
+				return nil, err
+			}
+		}
+	}
+        log.Debugw("Update_flows_incrementally",log.Fields{"flows":flows,"groups":groups})
+        //Invoke the adopt device on the adapter
+        if err := rhp.adapter.Update_flows_incrementally(device,flows,groups); err != nil {
+                return nil, status.Errorf(codes.NotFound, "%s", err.Error())
+        }
 	return new(empty.Empty), nil
 }
 
diff --git a/adapters/simulated_onu/adaptercore/device_handler.go b/adapters/simulated_onu/adaptercore/device_handler.go
index 2e3271c..e3d20fc 100644
--- a/adapters/simulated_onu/adaptercore/device_handler.go
+++ b/adapters/simulated_onu/adaptercore/device_handler.go
@@ -126,16 +126,32 @@
 	if err := dh.coreProxy.PortCreated(nil, cloned.Id, dh.uniPort); err != nil {
 		log.Errorw("error-creating-nni-port", log.Fields{"deviceId": device.Id, "error": err})
 	}
+        // Create UNI port in parent device
+        uniPort := &voltha.Port{
+		PortNo:     uni_port,
+		Label:      fmt.Sprintf("uni-%d", uni_port),
+		Type:       voltha.Port_ETHERNET_UNI,
+		AdminState: voltha.AdminState_ENABLED,
+		OperStatus: voltha.OperStatus_ACTIVE,
+	}
+	if err := dh.coreProxy.PortCreated(nil, cloned.ParentId, uniPort); err != nil {
+		log.Errorw("error-creating-nni-port", log.Fields{"deviceId": device.Id, "error": err})
+	}
 
+        // use Pon port number on which this ONU has been detected
+        ponPortNo := uint32(1)
+        if device.ParentPortNo != 0 {
+            ponPortNo = device.ParentPortNo
+        }
 	//	Now create the PON Port
 	dh.ponPort = &voltha.Port{
-		PortNo:     1,
-		Label:      fmt.Sprintf("pon-%d", 1),
+		PortNo:     ponPortNo,
+		Label:      fmt.Sprintf("pon-%d", ponPortNo),
 		Type:       voltha.Port_PON_ONU,
 		AdminState: voltha.AdminState_ENABLED,
 		OperStatus: voltha.OperStatus_ACTIVE,
-		Peers: []*voltha.Port_PeerPort{{DeviceId: cloned.ParentId,
-			PortNo: cloned.ParentPortNo}},
+		Peers: []*voltha.Port_PeerPort{{DeviceId: cloned.ParentId, // Peer device  is OLT
+			PortNo: uni_port}},            // Peer port is UNI port
 	}
 
 	// Synchronous call to update device - this method is run in its own go routine