VOL-2894 - reference the voltha GRPC end point via a holder

Change-Id: If24299556ad6cacf9cd0f793167a2c908534729c
diff --git a/internal/pkg/openflow/client.go b/internal/pkg/openflow/client.go
index aeac406..3f48e0c 100644
--- a/internal/pkg/openflow/client.go
+++ b/internal/pkg/openflow/client.go
@@ -19,11 +19,13 @@
 import (
 	"context"
 	"errors"
-	ofp "github.com/donNewtonAlpha/goloxi/of13"
-	"github.com/opencord/voltha-lib-go/v3/pkg/log"
-	"github.com/opencord/voltha-protos/v3/go/voltha"
 	"sync"
 	"time"
+
+	ofp "github.com/donNewtonAlpha/goloxi/of13"
+	"github.com/opencord/ofagent-go/internal/pkg/holder"
+	"github.com/opencord/voltha-lib-go/v3/pkg/log"
+	"github.com/opencord/voltha-protos/v3/go/voltha"
 )
 
 var NoVolthaConnectionError = errors.New("no-voltha-connection")
@@ -87,7 +89,7 @@
 type OFClient struct {
 	OFControllerEndPoints []string
 	DeviceID              string
-	VolthaClient          voltha.VolthaServiceClient
+	VolthaClient          *holder.VolthaServiceClientHolder
 	PacketOutChannel      chan *voltha.PacketOut
 	ConnectionMaxRetries  int
 	ConnectionRetryDelay  time.Duration
diff --git a/internal/pkg/openflow/connection.go b/internal/pkg/openflow/connection.go
index 7d57d34..691644c 100644
--- a/internal/pkg/openflow/connection.go
+++ b/internal/pkg/openflow/connection.go
@@ -21,19 +21,21 @@
 	"encoding/binary"
 	"encoding/json"
 	"errors"
-	"github.com/donNewtonAlpha/goloxi"
-	ofp "github.com/donNewtonAlpha/goloxi/of13"
-	"github.com/opencord/voltha-lib-go/v3/pkg/log"
-	"github.com/opencord/voltha-protos/v3/go/voltha"
 	"io"
 	"net"
 	"time"
+
+	"github.com/donNewtonAlpha/goloxi"
+	ofp "github.com/donNewtonAlpha/goloxi/of13"
+	"github.com/opencord/ofagent-go/internal/pkg/holder"
+	"github.com/opencord/voltha-lib-go/v3/pkg/log"
+	"github.com/opencord/voltha-protos/v3/go/voltha"
 )
 
 type OFConnection struct {
 	OFControllerEndPoint string
 	DeviceID             string
-	VolthaClient         voltha.VolthaServiceClient
+	VolthaClient         *holder.VolthaServiceClientHolder
 	PacketOutChannel     chan *voltha.PacketOut
 	ConnectionMaxRetries int
 	ConnectionRetryDelay time.Duration
diff --git a/internal/pkg/openflow/feature.go b/internal/pkg/openflow/feature.go
index 82353db..99da50c 100644
--- a/internal/pkg/openflow/feature.go
+++ b/internal/pkg/openflow/feature.go
@@ -19,6 +19,7 @@
 import (
 	"context"
 	"encoding/json"
+
 	ofp "github.com/donNewtonAlpha/goloxi/of13"
 	"github.com/opencord/voltha-lib-go/v3/pkg/log"
 	"github.com/opencord/voltha-protos/v3/go/common"
@@ -32,11 +33,12 @@
 				"device-id": ofc.DeviceID,
 				"request":   js})
 	}
-	if ofc.VolthaClient == nil {
+	volthaClient := ofc.VolthaClient.Get()
+	if volthaClient == nil {
 		return NoVolthaConnectionError
 	}
 	var id = common.ID{Id: ofc.DeviceID}
-	logicalDevice, err := ofc.VolthaClient.GetLogicalDevice(context.Background(), &id)
+	logicalDevice, err := volthaClient.GetLogicalDevice(context.Background(), &id)
 	if err != nil {
 		return err
 	}
diff --git a/internal/pkg/openflow/flowMod.go b/internal/pkg/openflow/flowMod.go
index 114a012..5424c12 100644
--- a/internal/pkg/openflow/flowMod.go
+++ b/internal/pkg/openflow/flowMod.go
@@ -20,11 +20,12 @@
 	"context"
 	"encoding/binary"
 	"encoding/json"
+	"unsafe"
+
 	ofp "github.com/donNewtonAlpha/goloxi/of13"
 	"github.com/opencord/voltha-lib-go/v3/pkg/log"
 	"github.com/opencord/voltha-protos/v3/go/openflow_13"
 	"github.com/opencord/voltha-protos/v3/go/voltha"
-	"unsafe"
 )
 
 var oxmMap = map[string]int32{
@@ -80,7 +81,8 @@
 				"params":    js})
 	}
 
-	if ofc.VolthaClient == nil {
+	volthaClient := ofc.VolthaClient.Get()
+	if volthaClient == nil {
 		logger.Errorw("no-voltha-connection",
 			log.Fields{"device-id": ofc.DeviceID})
 		return
@@ -227,7 +229,7 @@
 				"flow-mod-object":  flowUpdate,
 				"flow-mod-request": flowUpdateJs})
 	}
-	if _, err := ofc.VolthaClient.UpdateLogicalDeviceFlowTable(context.Background(), &flowUpdate); err != nil {
+	if _, err := volthaClient.UpdateLogicalDeviceFlowTable(context.Background(), &flowUpdate); err != nil {
 		logger.Errorw("Error calling FlowAdd ",
 			log.Fields{
 				"device-id": ofc.DeviceID,
@@ -311,7 +313,8 @@
 				"flow-delete-strict": js})
 	}
 
-	if ofc.VolthaClient == nil {
+	volthaClient := ofc.VolthaClient.Get()
+	if volthaClient == nil {
 		logger.Errorw("no-voltha-connection",
 			log.Fields{"device-id": ofc.DeviceID})
 		return
@@ -412,7 +415,7 @@
 				"device-id":   ofc.DeviceID,
 				"flow-update": flowUpdateJs})
 	}
-	if _, err := ofc.VolthaClient.UpdateLogicalDeviceFlowTable(context.Background(), &flowUpdate); err != nil {
+	if _, err := volthaClient.UpdateLogicalDeviceFlowTable(context.Background(), &flowUpdate); err != nil {
 		logger.Errorw("Error calling FlowDelete ",
 			log.Fields{
 				"device-id": ofc.DeviceID,
diff --git a/internal/pkg/openflow/meter.go b/internal/pkg/openflow/meter.go
index c8ee22c..574e505 100644
--- a/internal/pkg/openflow/meter.go
+++ b/internal/pkg/openflow/meter.go
@@ -17,6 +17,7 @@
 
 import (
 	"encoding/json"
+
 	ofp "github.com/donNewtonAlpha/goloxi/of13"
 	"github.com/opencord/voltha-lib-go/v3/pkg/log"
 	"github.com/opencord/voltha-protos/v3/go/openflow_13"
@@ -32,7 +33,8 @@
 				"request":   js})
 	}
 
-	if ofc.VolthaClient == nil {
+	volthaClient := ofc.VolthaClient.Get()
+	if volthaClient == nil {
 		logger.Errorw("no-voltha-connection",
 			log.Fields{"device-id": ofc.DeviceID})
 		return
@@ -91,7 +93,7 @@
 				"device-id":         ofc.DeviceID,
 				"meter-mod-request": meterModJS})
 	}
-	if _, err := ofc.VolthaClient.UpdateLogicalDeviceMeterTable(context.Background(), &meterModUpdate); err != nil {
+	if _, err := volthaClient.UpdateLogicalDeviceMeterTable(context.Background(), &meterModUpdate); err != nil {
 		logger.Errorw("Error calling UpdateLogicalDeviceMeterTable",
 			log.Fields{
 				"device-id": ofc.DeviceID,
diff --git a/internal/pkg/openflow/stats.go b/internal/pkg/openflow/stats.go
index 86c06d6..246bc80 100644
--- a/internal/pkg/openflow/stats.go
+++ b/internal/pkg/openflow/stats.go
@@ -19,13 +19,14 @@
 import (
 	"context"
 	"encoding/json"
+	"net"
+	"unsafe"
+
 	"github.com/donNewtonAlpha/goloxi"
 	ofp "github.com/donNewtonAlpha/goloxi/of13"
 	"github.com/opencord/voltha-lib-go/v3/pkg/log"
 	"github.com/opencord/voltha-protos/v3/go/common"
 	"github.com/opencord/voltha-protos/v3/go/openflow_13"
-	"net"
-	"unsafe"
 )
 
 func (ofc *OFConnection) handleStatsRequest(request ofp.IHeader, statType uint16) error {
@@ -289,7 +290,8 @@
 }
 
 func (ofc *OFConnection) handleDescStatsRequest(request *ofp.DescStatsRequest) (*ofp.DescStatsReply, error) {
-	if ofc.VolthaClient == nil {
+	volthaClient := ofc.VolthaClient.Get()
+	if volthaClient == nil {
 		return nil, NoVolthaConnectionError
 	}
 	response := ofp.NewDescStatsReply()
@@ -297,7 +299,7 @@
 	response.SetVersion(request.GetVersion())
 	response.SetFlags(ofp.StatsReplyFlags(request.GetFlags()))
 
-	resp, err := ofc.VolthaClient.GetLogicalDevice(context.Background(),
+	resp, err := volthaClient.GetLogicalDevice(context.Background(),
 		&common.ID{Id: ofc.DeviceID})
 	if err != nil {
 		return nil, err
@@ -313,14 +315,15 @@
 }
 
 func (ofc *OFConnection) handleFlowStatsRequest(request *ofp.FlowStatsRequest) (*ofp.FlowStatsReply, error) {
-	if ofc.VolthaClient == nil {
+	volthaClient := ofc.VolthaClient.Get()
+	if volthaClient == nil {
 		return nil, NoVolthaConnectionError
 	}
 	response := ofp.NewFlowStatsReply()
 	response.SetXid(request.GetXid())
 	response.SetVersion(4)
 	response.SetFlags(ofp.StatsReplyFlags(request.GetFlags()))
-	resp, err := ofc.VolthaClient.ListLogicalDeviceFlows(context.Background(),
+	resp, err := volthaClient.ListLogicalDeviceFlows(context.Background(),
 		&common.ID{Id: ofc.DeviceID})
 	if err != nil {
 		return nil, err
@@ -388,14 +391,15 @@
 }
 
 func (ofc *OFConnection) handleGroupStatsRequest(request *ofp.GroupStatsRequest) (*ofp.GroupStatsReply, error) {
-	if ofc.VolthaClient == nil {
+	volthaClient := ofc.VolthaClient.Get()
+	if volthaClient == nil {
 		return nil, NoVolthaConnectionError
 	}
 	response := ofp.NewGroupStatsReply()
 	response.SetVersion(request.GetVersion())
 	response.SetXid(request.GetXid())
 	response.SetFlags(ofp.StatsReplyFlags(request.GetFlags()))
-	reply, err := ofc.VolthaClient.ListLogicalDeviceFlowGroups(context.Background(),
+	reply, err := volthaClient.ListLogicalDeviceFlowGroups(context.Background(),
 		&common.ID{Id: ofc.DeviceID})
 	if err != nil {
 		return nil, err
@@ -426,14 +430,15 @@
 }
 
 func (ofc *OFConnection) handleGroupStatsDescRequest(request *ofp.GroupDescStatsRequest) (*ofp.GroupDescStatsReply, error) {
-	if ofc.VolthaClient == nil {
+	volthaClient := ofc.VolthaClient.Get()
+	if volthaClient == nil {
 		return nil, NoVolthaConnectionError
 	}
 	response := ofp.NewGroupDescStatsReply()
 	response.SetVersion(request.GetVersion())
 	response.SetXid(request.GetXid())
 	response.SetFlags(ofp.StatsReplyFlags(request.GetFlags()))
-	reply, err := ofc.VolthaClient.ListLogicalDeviceFlowGroups(context.Background(),
+	reply, err := volthaClient.ListLogicalDeviceFlowGroups(context.Background(),
 		&common.ID{Id: ofc.DeviceID})
 	if err != nil {
 		return nil, err
@@ -468,14 +473,15 @@
 }
 
 func (ofc *OFConnection) handleMeterStatsRequest(request *ofp.MeterStatsRequest) (*ofp.MeterStatsReply, error) {
-	if ofc.VolthaClient == nil {
+	volthaClient := ofc.VolthaClient.Get()
+	if volthaClient == nil {
 		return nil, NoVolthaConnectionError
 	}
 	response := ofp.NewMeterStatsReply()
 	response.SetVersion(request.GetVersion())
 	response.SetXid(request.GetXid())
 	response.SetFlags(ofp.StatsReplyFlags(request.GetFlags()))
-	resp, err := ofc.VolthaClient.ListLogicalDeviceMeters(context.Background(),
+	resp, err := volthaClient.ListLogicalDeviceMeters(context.Background(),
 		&common.ID{Id: ofc.DeviceID})
 	if err != nil {
 		return nil, err
@@ -546,14 +552,15 @@
 }
 
 func (ofc *OFConnection) handlePortStatsRequest(request *ofp.PortStatsRequest) (*ofp.PortStatsReply, error) {
-	if ofc.VolthaClient == nil {
+	volthaClient := ofc.VolthaClient.Get()
+	if volthaClient == nil {
 		return nil, NoVolthaConnectionError
 	}
 	response := ofp.NewPortStatsReply()
 	response.SetXid(request.GetXid())
 	response.SetVersion(request.GetVersion())
 	response.SetFlags(ofp.StatsReplyFlags(request.GetFlags()))
-	reply, err := ofc.VolthaClient.ListLogicalDevicePorts(context.Background(),
+	reply, err := volthaClient.ListLogicalDevicePorts(context.Background(),
 		&common.ID{Id: ofc.DeviceID})
 	if err != nil {
 		return nil, err
@@ -575,14 +582,15 @@
 }
 
 func (ofc *OFConnection) handlePortDescStatsRequest(request *ofp.PortDescStatsRequest) (*ofp.PortDescStatsReply, error) {
-	if ofc.VolthaClient == nil {
+	volthaClient := ofc.VolthaClient.Get()
+	if volthaClient == nil {
 		return nil, NoVolthaConnectionError
 	}
 	response := ofp.NewPortDescStatsReply()
 	response.SetVersion(request.GetVersion())
 	response.SetXid(request.GetXid())
 	response.SetFlags(ofp.StatsReplyFlags(request.GetFlags()))
-	logicalDevice, err := ofc.VolthaClient.GetLogicalDevice(context.Background(),
+	logicalDevice, err := volthaClient.GetLogicalDevice(context.Background(),
 		&common.ID{Id: ofc.DeviceID})
 	if err != nil {
 		return nil, err