functional version

Change-Id: Ic089d1fc7a2c6bc51e00371c993a6fc6aaa17863
diff --git a/grpc/changeEvent.go b/grpc/changeEvent.go
index ace6bc7..c6f6376 100644
--- a/grpc/changeEvent.go
+++ b/grpc/changeEvent.go
@@ -22,7 +22,7 @@
 	ofp "github.com/donNewtonAlpha/goloxi/of13"
 	"github.com/golang/protobuf/ptypes/empty"
 	"github.com/opencord/ofagent-go/openflow"
-	pb "github.com/opencord/voltha-protos/go/voltha"
+	pb "github.com/opencord/voltha-protos/v2/go/voltha"
 	"google.golang.org/grpc"
 	"log"
 	"net"
@@ -33,7 +33,7 @@
 	opt := grpc.EmptyCallOption{}
 	stream, err := client.ReceiveChangeEvents(context.Background(), &empty.Empty{}, opt)
 	if err != nil {
-		log.Fatalln("Unable to establish stream")
+		log.Fatalln("Unable to establish Receive Change Event Stream")
 	}
 	for {
 		changeEvent, err := stream.Recv()
@@ -80,7 +80,6 @@
 		var client = clientMap[deviceId]
 		if client == nil {
 			client = addClient(deviceId)
-
 			time.Sleep(2 * time.Second)
 		}
 		client.SendMessage(ofPortStatus)
diff --git a/grpc/client.go b/grpc/client.go
index ea32986..4116461 100644
--- a/grpc/client.go
+++ b/grpc/client.go
@@ -18,6 +18,7 @@
 
 import (
 	"context"
+	"sync"
 	"time"
 
 	"github.com/golang/protobuf/ptypes/empty"
@@ -27,7 +28,7 @@
 	"fmt"
 	"log"
 
-	pb "github.com/opencord/voltha-protos/go/voltha"
+	pb "github.com/opencord/voltha-protos/v2/go/voltha"
 	"google.golang.org/grpc"
 )
 
@@ -35,6 +36,7 @@
 var clientMap map[string]*openflow.Client
 var ofAddress string
 var ofPort uint16
+var mapLock sync.Mutex
 
 func StartClient(endpointAddress string, endpointPort uint16, openFlowAddress string, openFlowPort uint16) {
 	ofAddress = openFlowAddress
@@ -69,6 +71,7 @@
 }
 func refreshDeviceList(devices []*pb.LogicalDevice) {
 	//first find the new ones
+
 	var toAdd []string
 	var toDel []string
 	var deviceIdMap = make(map[string]string)
@@ -91,12 +94,20 @@
 	}
 	for i := 0; i < len(toDel); i++ {
 		clientMap[toDel[i]].End()
+		mapLock.Lock()
 		delete(clientMap, toDel[i])
+		mapLock.Unlock()
 	}
 }
 func addClient(deviceId string) *openflow.Client {
-	client := openflow.NewClient(ofAddress, ofPort, deviceId, true)
-	clientMap[deviceId] = client
+	mapLock.Lock()
+	var client *openflow.Client
+	client = clientMap[deviceId]
+	if client == nil {
+		client = openflow.NewClient(ofAddress, ofPort, deviceId, true)
+		clientMap[deviceId] = client
+	}
+	mapLock.Unlock()
 	return client
 }
 func GetClient(deviceId string) *openflow.Client {
diff --git a/grpc/packetIn.go b/grpc/packetIn.go
index 8200a37..44e537b 100644
--- a/grpc/packetIn.go
+++ b/grpc/packetIn.go
@@ -18,12 +18,13 @@
 
 import (
 	"context"
+	"encoding/json"
 	"github.com/donNewtonAlpha/goloxi"
 	ofp "github.com/donNewtonAlpha/goloxi/of13"
 	"github.com/golang/protobuf/ptypes/empty"
 	"github.com/opencord/ofagent-go/openflow"
-	"github.com/opencord/voltha-protos/go/openflow_13"
-	pb "github.com/opencord/voltha-protos/go/voltha"
+	"github.com/opencord/voltha-protos/v2/go/openflow_13"
+	pb "github.com/opencord/voltha-protos/v2/go/voltha"
 	"google.golang.org/grpc"
 	"log"
 )
@@ -41,6 +42,8 @@
 		if err != nil {
 			log.Fatalf("error on stream.Rec %v", err)
 		}
+		js, _ := json.Marshal(packetIn)
+		log.Printf("PACKET IN %s", js)
 		deviceID := packet.GetId()
 		ofPacketIn := ofp.NewPacketIn()
 		ofPacketIn.SetVersion(uint8(4))
diff --git a/grpc/packetOut.go b/grpc/packetOut.go
index ee58a31..f1891e1 100644
--- a/grpc/packetOut.go
+++ b/grpc/packetOut.go
@@ -19,7 +19,7 @@
 import (
 	"encoding/json"
 	"github.com/opencord/ofagent-go/openflow"
-	pb "github.com/opencord/voltha-protos/go/voltha"
+	pb "github.com/opencord/voltha-protos/v2/go/voltha"
 	"google.golang.org/grpc"
 	"log"
 )