[VOL-2440] : code changes to update port status on PON disable

Change-Id: I8839f2083509ebbd5fba7f1c683f9ec1c5f033e5
diff --git a/adaptercore/device_handler.go b/adaptercore/device_handler.go
index 36bb01a..ee53736 100644
--- a/adaptercore/device_handler.go
+++ b/adaptercore/device_handler.go
@@ -240,6 +240,24 @@
 		log.Errorw("Invalid-port-label", log.Fields{"portNum": portNum, "portType": portType})
 		return
 	}
+
+	device, err := dh.coreProxy.GetDevice(context.TODO(), dh.device.Id, dh.device.Id)
+	if err != nil || device == nil {
+		log.Errorw("Failed-to-fetch-device", log.Fields{"err": err})
+		return
+	}
+	if device.Ports != nil {
+		for _, dPort := range device.Ports {
+			if dPort.Type == portType && dPort.PortNo == portNum {
+				log.Debug("port-already-exists-updating-oper-status-of-port")
+				if err := dh.coreProxy.PortStateUpdate(context.TODO(), dh.device.Id, portType, portNum, operStatus); err != nil {
+					log.Errorw("failed-to-update-port-state", log.Fields{"err": err})
+					return
+				}
+				return
+			}
+		}
+	}
 	//    Now create  Port
 	port := &voltha.Port{
 		PortNo:     portNum,
@@ -247,11 +265,13 @@
 		Type:       portType,
 		OperStatus: operStatus,
 	}
-	log.Debugw("Sending port update to core", log.Fields{"port": port})
+	log.Debugw("Sending-port-update-to-core", log.Fields{"port": port})
 	// Synchronous call to update device - this method is run in its own go routine
 	if err := dh.coreProxy.PortCreated(context.TODO(), dh.device.Id, port); err != nil {
-		log.Errorw("error-creating-nni-port", log.Fields{"deviceID": dh.device.Id, "portType": portType, "error": err})
+		log.Errorw("Error-creating-port", log.Fields{"deviceID": dh.device.Id, "portType": portType, "error": err})
+		return
 	}
+	return
 }
 
 // readIndications to read the indications from the OLT device
diff --git a/go.mod b/go.mod
index a8d791e..addbbe9 100644
--- a/go.mod
+++ b/go.mod
@@ -7,7 +7,7 @@
 	github.com/cenkalti/backoff/v3 v3.1.1
 	github.com/gogo/protobuf v1.3.1
 	github.com/golang/protobuf v1.3.2
-	github.com/opencord/voltha-lib-go/v2 v2.2.25
+	github.com/opencord/voltha-lib-go/v2 v2.2.26
 	github.com/opencord/voltha-protos/v2 v2.1.2
 	go.etcd.io/etcd v0.0.0-20190930204107-236ac2a90522
 	google.golang.org/grpc v1.25.1
diff --git a/go.sum b/go.sum
index 8fda01b..916f084 100644
--- a/go.sum
+++ b/go.sum
@@ -196,8 +196,8 @@
 github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
 github.com/onsi/gomega v1.4.2 h1:3mYCb7aPxS/RU7TI1y4rkEn1oKmPRjNJLNEXgw7MH2I=
 github.com/onsi/gomega v1.4.2/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
-github.com/opencord/voltha-lib-go/v2 v2.2.25 h1:8YZE2caHN7niAd0ojzegSQpjH+y7/83CkWaZJCojf/M=
-github.com/opencord/voltha-lib-go/v2 v2.2.25/go.mod h1:CoY2amUEsbO2grCbJRk7G+Fl1Xb7vQLw3/uGLbTz0Ms=
+github.com/opencord/voltha-lib-go/v2 v2.2.26 h1:0JlaG6a7cUuzOkMZ6K/JL6hTyiKKZkjEYvyVl9V9JQ4=
+github.com/opencord/voltha-lib-go/v2 v2.2.26/go.mod h1:CoY2amUEsbO2grCbJRk7G+Fl1Xb7vQLw3/uGLbTz0Ms=
 github.com/opencord/voltha-protos/v2 v2.1.0/go.mod h1:6kOcfYi1CadWowFxI2SH5wLfHrsRECZLZlD2MFK6WDI=
 github.com/opencord/voltha-protos/v2 v2.1.2 h1:/eX+kXhANbzxTpBHgC6vjwBUGRKKvGUOQRDdDgROp9E=
 github.com/opencord/voltha-protos/v2 v2.1.2/go.mod h1:6kOcfYi1CadWowFxI2SH5wLfHrsRECZLZlD2MFK6WDI=
diff --git a/mocks/mockCoreProxy.go b/mocks/mockCoreProxy.go
index b5a9d63..24f60c8 100644
--- a/mocks/mockCoreProxy.go
+++ b/mocks/mockCoreProxy.go
@@ -206,3 +206,9 @@
 func (mcp *MockCoreProxy) DevicePMConfigUpdate(ctx context.Context, pmConfigs *voltha.PmConfigs) error {
 	return nil
 }
+
+// PortStateUpdate implements mock PortStateUpdate
+func (mcp *MockCoreProxy) PortStateUpdate(ctx context.Context, deviceID string, pType voltha.Port_PortType, portNo uint32,
+	operStatus voltha.OperStatus_OperStatus) error {
+	return nil
+}
diff --git a/vendor/github.com/opencord/voltha-lib-go/v2/pkg/adapters/adapterif/core_proxy_if.go b/vendor/github.com/opencord/voltha-lib-go/v2/pkg/adapters/adapterif/core_proxy_if.go
index 9286c0d..c7af374 100644
--- a/vendor/github.com/opencord/voltha-lib-go/v2/pkg/adapters/adapterif/core_proxy_if.go
+++ b/vendor/github.com/opencord/voltha-lib-go/v2/pkg/adapters/adapterif/core_proxy_if.go
@@ -48,4 +48,6 @@
 	GetChildDevices(ctx context.Context, parentDeviceID string) (*voltha.Devices, error)
 	SendPacketIn(ctx context.Context, deviceID string, port uint32, pktPayload []byte) error
 	DeviceReasonUpdate(ctx context.Context, deviceID string, deviceReason string) error
+	PortStateUpdate(ctx context.Context, deviceID string, pType voltha.Port_PortType, portNo uint32,
+		operStatus voltha.OperStatus_OperStatus) error
 }
diff --git a/vendor/github.com/opencord/voltha-lib-go/v2/pkg/adapters/common/core_proxy.go b/vendor/github.com/opencord/voltha-lib-go/v2/pkg/adapters/common/core_proxy.go
index b0f7f32..a69d9b4 100644
--- a/vendor/github.com/opencord/voltha-lib-go/v2/pkg/adapters/common/core_proxy.go
+++ b/vendor/github.com/opencord/voltha-lib-go/v2/pkg/adapters/common/core_proxy.go
@@ -17,6 +17,8 @@
 
 import (
 	"context"
+	"sync"
+
 	"github.com/golang/protobuf/ptypes"
 	a "github.com/golang/protobuf/ptypes/any"
 	"github.com/opencord/voltha-lib-go/v2/pkg/kafka"
@@ -25,7 +27,6 @@
 	"github.com/opencord/voltha-protos/v2/go/voltha"
 	"google.golang.org/grpc/codes"
 	"google.golang.org/grpc/status"
-	"sync"
 )
 
 type CoreProxy struct {
@@ -558,3 +559,40 @@
 	log.Debugw("ReconcileChildDevices-response", log.Fields{"pDeviceId": parentDeviceId, "success": success})
 	return unPackResponse(rpc, parentDeviceId, success, result)
 }
+
+func (ap *CoreProxy) PortStateUpdate(ctx context.Context, deviceId string, pType voltha.Port_PortType, portNum uint32,
+	operStatus voltha.OperStatus_OperStatus) error {
+	log.Debugw("PortStateUpdate", log.Fields{"deviceId": deviceId, "portType": pType, "portNo": portNum, "operation_status": operStatus})
+	rpc := "PortStateUpdate"
+	// Use a device specific topic to send the request.  The adapter handling the device creates a device
+	// specific topic
+	toTopic := ap.getCoreTopic(deviceId)
+	args := make([]*kafka.KVArg, 4)
+	deviceID := &voltha.ID{Id: deviceId}
+	portNo := &ic.IntType{Val: int64(portNum)}
+	portType := &ic.IntType{Val: int64(pType)}
+	oStatus := &ic.IntType{Val: int64(operStatus)}
+
+	args[0] = &kafka.KVArg{
+		Key:   "device_id",
+		Value: deviceID,
+	}
+	args[1] = &kafka.KVArg{
+		Key:   "oper_status",
+		Value: oStatus,
+	}
+	args[2] = &kafka.KVArg{
+		Key:   "port_type",
+		Value: portType,
+	}
+	args[3] = &kafka.KVArg{
+		Key:   "port_no",
+		Value: portNo,
+	}
+
+	// Use a device specific topic as we are the only adaptercore handling requests for this device
+	replyToTopic := ap.getAdapterTopic()
+	success, result := ap.kafkaICProxy.InvokeRPC(nil, rpc, &toTopic, &replyToTopic, true, deviceId, args...)
+	log.Debugw("PortStateUpdate-response", log.Fields{"deviceId": deviceId, "success": success})
+	return unPackResponse(rpc, deviceId, success, result)
+}
diff --git a/vendor/modules.txt b/vendor/modules.txt
index 860b4a2..2c11425 100644
--- a/vendor/modules.txt
+++ b/vendor/modules.txt
@@ -63,7 +63,7 @@
 github.com/mitchellh/go-homedir
 # github.com/mitchellh/mapstructure v1.1.2
 github.com/mitchellh/mapstructure
-# github.com/opencord/voltha-lib-go/v2 v2.2.25
+# github.com/opencord/voltha-lib-go/v2 v2.2.26
 github.com/opencord/voltha-lib-go/v2/pkg/adapters
 github.com/opencord/voltha-lib-go/v2/pkg/adapters/adapterif
 github.com/opencord/voltha-lib-go/v2/pkg/adapters/common