fixes for vgc add device config and IsNniPort func

Change-Id: Id7002792a5a811ebaca630bde5dadadc10dff048
diff --git a/internal/pkg/application/application.go b/internal/pkg/application/application.go
index 730be6c..73a88a9 100644
--- a/internal/pkg/application/application.go
+++ b/internal/pkg/application/application.go
@@ -237,7 +237,7 @@
 	d.GlobalDhcpFlowAdded = false
 	if config, ok := GetApplication().DevicesConfig.Load(slno); ok {
 		//Update nni dhcp vid
-		deviceConfig := config.(DeviceConfig)
+		deviceConfig := config.(*DeviceConfig)
 		d.NniDhcpTrapVid = of.VlanType(deviceConfig.NniDhcpTrapVid)
 	}
 	return &d
@@ -455,7 +455,7 @@
 	SerialNumber       string `json:"id"`
 	HardwareIdentifier string `json:"hardwareIdentifier"`
 	IPAddress          string `json:"ipAddress"`
-	UplinkPort         int    `json:"uplinkPort"`
+	UplinkPort         string `json:"uplinkPort"`
 	NasID              string `json:"nasId"`
 	NniDhcpTrapVid     int    `json:"nniDhcpTrapVid"`
 }
@@ -573,7 +573,7 @@
 	return nil
 }
 
-func (va *VoltApplication) AddDeviceConfig(cntx context.Context, serialNum, hardwareIdentifier, nasID, ipAddress string, uplinkPort, nniDhcpTrapId int) error {
+func (va *VoltApplication) AddDeviceConfig(cntx context.Context, serialNum, hardwareIdentifier, nasID, ipAddress, uplinkPort string, nniDhcpTrapId int) error {
 	var dc *DeviceConfig
 
 	deviceConfig := &DeviceConfig{
@@ -832,7 +832,7 @@
 // protection mechanism (LAG, ERPS, etc.). The aggregate of the such protection
 // is represented by a single NNI port
 func (va *VoltApplication) AddDevice(cntx context.Context, device string, slno, southBoundID string) {
-	logger.Warnw(ctx, "Received Device Ind: Add", log.Fields{"Device": device, "SrNo": slno})
+	logger.Warnw(ctx, "Received Device Ind: Add", log.Fields{"Device": device, "SrNo": slno, "southBoundID": southBoundID})
 	if _, ok := va.DevicesDisc.Load(device); ok {
 		logger.Warnw(ctx, "Device Exists", log.Fields{"Device": device})
 	}
diff --git a/internal/pkg/application/vnets.go b/internal/pkg/application/vnets.go
index a95104c..548879f 100644
--- a/internal/pkg/application/vnets.go
+++ b/internal/pkg/application/vnets.go
@@ -510,16 +510,6 @@
 	vpv.IgmpEnabled = false
 	vpv.MacAddr, _ = net.ParseMAC("00:00:00:00:00:00")
 	vpv.LearntMacAddr, _ = net.ParseMAC("00:00:00:00:00:00")
-	// for OLTCVLAN SVLAN=CVLAN, UNIVLAN can differ.
-	/*
-	if vpv.VlanControl == ONUCVlan {
-		vpv.CVlan = vpv.SVlan
-	}
-	// for OLTSVLAN  CVLAN=UNIVLAN , SVLAN can differ,
-	// hence assigning UNIVLAN to CVLAN, so that ONU will transparently forward the packet.
-	if vpv.VlanControl == OLTSVlan {
-		vpv.CVlan = vpv.UniVlan
-	}*/
 	vpv.servicesCount = atomic.NewUint64(0)
 	vpv.SchedID = 0
 	vpv.PendingDeleteFlow = make(map[string]bool)
@@ -781,20 +771,13 @@
 		//If NNI port is not mached to nb nni port dont send flows
 		devConfig := GetApplication().GetDeviceConfig(device.SerialNum)
 		if devConfig != nil {
-			if devConfig.UplinkPort != int(nniPort.ID) {
-				logger.Errorw(ctx, "NNI port not configured from NB, not pushing flows", log.Fields{"NNI Port": devConfig.UplinkPort, "NB NNI port": nniPort.ID})
+			if devConfig.UplinkPort != strconv.Itoa(int(nniPort.ID)) {
+				logger.Errorw(ctx, "NNI port not configured from NB, not pushing flows", log.Fields{"NB NNI Port": devConfig.UplinkPort, "SB NNI port": nniPort.ID})
 				return
 			}
 		}
 	}
 
-	if vp := device.GetPort(port); vp != nil {
-		if vpv.PonPort != 0xFF && vpv.PonPort != vp.PonPort {
-			logger.Errorw(ctx, "UNI port discovered on wrong PON Port. Dropping Flow Config for VPV", log.Fields{"Device": device.Name, "Port": port, "DetectedPon": vp.PonPort, "ExpectedPon": vpv.PonPort, "Vnet": vpv.VnetName})
-			return
-		}
-	}
-
 	if vpv.Blocked {
 		logger.Errorw(ctx, "VPV Bocked for Processing. Ignoring flow push request", log.Fields{"Port": vpv.Port, "Vnet": vpv.VnetName})
 		return
@@ -815,13 +798,13 @@
 		if vpv.MacLearning == MacLearningNone || NonZeroMacAddress(vpv.MacAddr) {
 			logger.Infow(ctx, "Port Up - DS Flows", log.Fields{"Device": device.Name, "Port": port})
 			/*In case of DPU_MGMT_TRAFFIC, need to install both US and DS traffic */
-			if  vpv.VnetType == DPU_MGMT_TRAFFIC {
+			if vpv.VnetType == DPU_MGMT_TRAFFIC {
 				vpv.RangeOnServices(cntx, AddUsHsiaFlows)
 			}
 			// US & DS DHCP, US HSIA flows are already installed
 			// install only DS HSIA flow here.
 			// no HSIA flows for multicast service
-			if !vpv.McastService  {
+			if !vpv.McastService {
 				vpv.RangeOnServices(cntx, AddDsHsiaFlows)
 			}
 		}
@@ -1051,17 +1034,6 @@
 	logger.Debugw(ctx, "Added MAC to VPV", log.Fields{"MacLearning": vpv.MacLearning, "VPV": vpv})
 	//Reconfigure Vlans based on Vlan Control type
 	svc.VlanControl = vpv.VlanControl
-	//TODO Is it good to change NB config?? commenting for now
-	/*
-	// for OLTCVLAN SVLAN=CVLAN, UNIVLAN can differ.
-	if vpv.VlanControl == ONUCVlan {
-		svc.CVlan = svc.SVlan
-	}
-	// for OLTSVLAN  CVLAN=UNIVLAN , SVLAN can differ,
-	// hence assigning UNIVLAN to CVLAN, so that ONU will transparently forward the packet.
-	if vpv.VlanControl == OLTSVlan {
-		svc.CVlan = svc.UniVlan
-	}*/
 	if svc.McastService {
 		vpv.McastService = true
 		vpv.McastTechProfileID = svc.TechProfileID
@@ -1099,8 +1071,8 @@
 	//If NNI port is not mached to nb nni port
 	devConfig := GetApplication().GetDeviceConfig(voltDevice.SerialNum)
 
-	if strconv.Itoa(devConfig.UplinkPort) != voltDevice.NniPort {
-		logger.Errorw(ctx, "NNI port mismatch", log.Fields{"NNI Port": devConfig.UplinkPort, "NB NNI port": voltDevice.NniPort})
+	if devConfig.UplinkPort != voltDevice.NniPort {
+		logger.Errorw(ctx, "NNI port mismatch", log.Fields{"NB NNI Port": devConfig.UplinkPort, "SB NNI port": voltDevice.NniPort})
 		return
 	}
 	//Push Service Flows if DHCP relay is not configured
@@ -1234,7 +1206,7 @@
 // AddMeterToDevice to add meter config to device, used in FTTB case
 func AddMeterToDevice(cntx context.Context, key, value interface{}) bool {
 	svc := value.(*VoltService)
-	if err:= svc.AddMeterToDevice(cntx); err != nil {
+	if err := svc.AddMeterToDevice(cntx); err != nil {
 		logger.Warnw(ctx, "Add Meter failed", log.Fields{"service": svc.Name, "Error": err})
 	}
 	return true
@@ -1706,7 +1678,6 @@
 	subFlow := of.NewVoltSubFlow()
 	subFlow.SetTableID(0)
 
-
 	if vpv.VnetType == DPU_MGMT_TRAFFIC {
 		subFlow.SetMatchVlan(vpv.CVlan)
 		subFlow.SetMatchPbit(vpv.UsPonCTagPriority)
diff --git a/internal/pkg/util/utils.go b/internal/pkg/util/utils.go
index 0711053..313a8ff 100644
--- a/internal/pkg/util/utils.go
+++ b/internal/pkg/util/utils.go
@@ -11,7 +11,7 @@
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
-*/
+ */
 
 package util
 
@@ -89,7 +89,7 @@
 
 // IsNniPort is to check if given port is Nni Port.
 func IsNniPort(id uint32) bool {
-	return (id >= 0x100000)
+	return (id >= 0x1000000)
 }
 
 // Uint32ToByte to convert uint32 to byte
diff --git a/internal/pkg/vpagent/changeEvent.go b/internal/pkg/vpagent/changeEvent.go
index 9300671..3e536b9 100644
--- a/internal/pkg/vpagent/changeEvent.go
+++ b/internal/pkg/vpagent/changeEvent.go
@@ -19,8 +19,9 @@
 	"context"
 	"io"
 
-	"github.com/golang/protobuf/ptypes/empty"
 	"voltha-go-controller/log"
+
+	"github.com/golang/protobuf/ptypes/empty"
 	"google.golang.org/grpc"
 )
 
@@ -60,7 +61,7 @@
 		default:
 			ce, err := stream.Recv()
 			if err == io.EOF {
-				logger.Infow(ctx, "EOF for receiveChangeEvents stream, reconnecting", log.Fields{"err": err})
+				logger.Warnw(ctx, "EOF for receiveChangeEvents stream, reconnecting", log.Fields{"err": err})
 				stream, err = vServiceClient.ReceiveChangeEvents(streamCtx, &empty.Empty{}, opt)
 				if err != nil {
 					logger.Errorw(ctx, "Unable to establish Receive Change Event Stream",
@@ -95,7 +96,7 @@
 		case changeEvent := <-vpa.changeEventChannel:
 			logger.Debugw(ctx, "Change Event", log.Fields{"Device": changeEvent.Id})
 			if vpc := vpa.getVPClient(changeEvent.Id); vpc != nil {
-				if err:= vpc.ChangeEvent(changeEvent); err != nil {
+				if err := vpc.ChangeEvent(changeEvent); err != nil {
 					logger.Errorw(ctx, "error handling Change Event", log.Fields{"Error": err, "Device": changeEvent.Id})
 				}
 			}
diff --git a/voltha-go-controller/nbi/bwprofile.go b/voltha-go-controller/nbi/bwprofile.go
index a02554f..b18b5e1 100644
--- a/voltha-go-controller/nbi/bwprofile.go
+++ b/voltha-go-controller/nbi/bwprofile.go
@@ -11,7 +11,7 @@
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
-*/
+ */
 
 package nbi
 
@@ -21,14 +21,16 @@
 	"encoding/json"
 	"net/http"
 
-	"github.com/gorilla/mux"
 	app "voltha-go-controller/internal/pkg/application"
 	"voltha-go-controller/log"
+
+	"github.com/gorilla/mux"
 )
 
 type BWEntry struct {
 	Entries []BWProfile `json:"entry"`
 }
+
 //BWProfile - Sadis BW Profile
 type BWProfile struct {
 	ID                        string `json:"id"`
@@ -68,9 +70,12 @@
 
 // AddProfile to add meter
 func (mh *ProfileHandle) AddProfile(cntx context.Context, w http.ResponseWriter, r *http.Request) {
+
+	vars := mux.Vars(r)
+	profileName := vars["id"]
 	// Get the payload to process the request
 	d := new(bytes.Buffer)
-	if _, err := d.ReadFrom(r.Body);  err != nil {
+	if _, err := d.ReadFrom(r.Body); err != nil {
 		logger.Warnw(ctx, "Error reading buffer", log.Fields{"Reason": err.Error()})
 		return
 	}
@@ -84,7 +89,7 @@
 	}
 	logger.Debugw(ctx, "Received-northbound-add-meter-request", log.Fields{"req": req, "d": d.String()})
 	metercfg := app.VoltMeter{
-		Name: req.ID,
+		Name: profileName,
 		Cir:  req.CommittedInformationRate,
 		Cbs:  req.CommittedBurstSize,
 		Pir:  req.PeakInformationRate,
@@ -113,15 +118,15 @@
 		return
 	}
 	profileResp := BWProfile{
-		ID: cfg.Name,
-		CommittedInformationRate : cfg.Cir,
-		CommittedBurstSize : cfg.Cbs,
-		PeakInformationRate: cfg.Pir,
-		PeakBurstSize: cfg.Pbs,
-		AssuredInformationRate: cfg.Air,
+		ID:                        cfg.Name,
+		CommittedInformationRate:  cfg.Cir,
+		CommittedBurstSize:        cfg.Cbs,
+		PeakInformationRate:       cfg.Pir,
+		PeakBurstSize:             cfg.Pbs,
+		AssuredInformationRate:    cfg.Air,
 		GuaranteedInformationRate: cfg.Gir,
-		ExceededInformationRate: cfg.Eir,
-		ExceededBurstSize: cfg.Ebs,
+		ExceededInformationRate:   cfg.Eir,
+		ExceededBurstSize:         cfg.Ebs,
 	}
 	bwEntryResp.Entries = append(bwEntryResp.Entries, profileResp)
 	profileRespJSON, err := json.Marshal(bwEntryResp)
@@ -142,9 +147,11 @@
 
 // DelProfile to delete meter
 func (mh *ProfileHandle) DelProfile(cntx context.Context, w http.ResponseWriter, r *http.Request) {
+	vars := mux.Vars(r)
+	profileName := vars["id"]
 	//TODO : Change the URL and Mux to fetch meter id from the request
 	d := new(bytes.Buffer)
-	if _, err := d.ReadFrom(r.Body);  err != nil {
+	if _, err := d.ReadFrom(r.Body); err != nil {
 		logger.Warnw(ctx, "Error reading buffer", log.Fields{"Reason": err.Error()})
 		return
 	}
@@ -157,7 +164,7 @@
 	}
 	logger.Debugw(ctx, "Received-northbound-del-meter-request", log.Fields{"req": req})
 
-	meterName := req.ID
+	meterName := profileName
 	if err := app.GetApplication().DelMeterProf(cntx, meterName); err != nil {
 		logger.Errorw(ctx, "northbound-del-meter-failed", log.Fields{"req": req})
 		http.Error(w, err.Error(), http.StatusConflict)
diff --git a/voltha-go-controller/nbi/subscriber.go b/voltha-go-controller/nbi/subscriber.go
index 8067306..4f7dc76 100644
--- a/voltha-go-controller/nbi/subscriber.go
+++ b/voltha-go-controller/nbi/subscriber.go
@@ -36,7 +36,7 @@
 type SubscriberDeviceInfo struct {
 	ID                 string              `json:"id"`
 	NasPortID          string              `json:"nasPortId"`
-	UplinkPort         int                 `json:"uplinkPort"`
+	UplinkPort         string              `json:"uplinkPort"`
 	Slot               int                 `json:"slot"`
 	HardwareIdentifier string              `json:"hardwareIdentifier"`
 	IPAddress          string              `json:"ipAddress"`
@@ -116,7 +116,7 @@
 
 	//vsCfgList := getVoltServiceFromSrvInfo(req)
 
-	go addAllService(cntx, req)
+	addAllService(cntx, req)
 }
 
 func addAllService(cntx context.Context, srvInfo *SubscriberDeviceInfo) {
@@ -249,5 +249,5 @@
 	w.WriteHeader(http.StatusAccepted)
 
 	logger.Warnw(ctx, "northbound-del-service-req", log.Fields{"ServiceName": id})
-	go app.GetApplication().DelServiceWithPrefix(cntx, id)
+	app.GetApplication().DelServiceWithPrefix(cntx, id)
 }