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

Change-Id: If24299556ad6cacf9cd0f793167a2c908534729c
diff --git a/internal/pkg/ofagent/ofagent.go b/internal/pkg/ofagent/ofagent.go
index 419a988..f0ebd0e 100644
--- a/internal/pkg/ofagent/ofagent.go
+++ b/internal/pkg/ofagent/ofagent.go
@@ -18,14 +18,15 @@
 
 import (
 	"context"
-	"fmt"
+	"sync"
+	"time"
+
+	"github.com/opencord/ofagent-go/internal/pkg/holder"
 	"github.com/opencord/ofagent-go/internal/pkg/openflow"
 	"github.com/opencord/voltha-lib-go/v3/pkg/log"
 	"github.com/opencord/voltha-lib-go/v3/pkg/probe"
 	"github.com/opencord/voltha-protos/v3/go/voltha"
 	"google.golang.org/grpc"
-	"sync"
-	"time"
 )
 
 type ofaEvent byte
@@ -50,7 +51,7 @@
 	ConnectionRetryDelay      time.Duration
 
 	volthaConnection *grpc.ClientConn
-	volthaClient     voltha.VolthaServiceClient
+	volthaClient     *holder.VolthaServiceClientHolder
 	mapLock          sync.Mutex
 	clientMap        map[string]*openflow.OFClient
 	events           chan ofaEvent
@@ -67,6 +68,7 @@
 		DeviceListRefreshInterval: config.DeviceListRefreshInterval,
 		ConnectionMaxRetries:      config.ConnectionMaxRetries,
 		ConnectionRetryDelay:      config.ConnectionRetryDelay,
+		volthaClient:              &holder.VolthaServiceClientHolder{},
 		packetInChannel:           make(chan *voltha.PacketIn),
 		packetOutChannel:          make(chan *voltha.PacketOut),
 		changeEventChannel:        make(chan *voltha.ChangeEvent),
@@ -161,16 +163,6 @@
 				if state != ofaStateConnected {
 					state = ofaStateConnected
 					volthaCtx, volthaDone = context.WithCancel(context.Background())
-					// Reconnect clients
-					for _, client := range ofa.clientMap {
-						if logger.V(log.DebugLevel) {
-							logger.Debugw("reset-client-voltha-connection",
-								log.Fields{
-									"from": fmt.Sprintf("0x%p", &client.VolthaClient),
-									"to":   fmt.Sprintf("0x%p", &ofa.volthaClient)})
-						}
-						client.VolthaClient = ofa.volthaClient
-					}
 					go ofa.receiveChangeEvents(volthaCtx)
 					go ofa.receivePacketsIn(volthaCtx)
 					go ofa.streamPacketOut(volthaCtx)
@@ -184,16 +176,7 @@
 				logger.Debug("ofagent-voltha-disconnect-event")
 				if state == ofaStateConnected {
 					state = ofaStateDisconnected
-					ofa.volthaClient = nil
-					for _, client := range ofa.clientMap {
-						client.VolthaClient = nil
-						if logger.V(log.DebugLevel) {
-							logger.Debugw("reset-client-voltha-connection",
-								log.Fields{
-									"from": fmt.Sprintf("0x%p", &client.VolthaClient),
-									"to":   "nil"})
-						}
-					}
+					ofa.volthaClient.Clear()
 					volthaDone()
 					volthaDone = nil
 				}