VOL-2639: Creation of common errors package

Change-Id: Iac2ab83826bf072c84af81e9e2bccf61d40c07ed
diff --git a/internal/pkg/core/openolt_flowmgr.go b/internal/pkg/core/openolt_flowmgr.go
index 3ed340f..c6bad46 100644
--- a/internal/pkg/core/openolt_flowmgr.go
+++ b/internal/pkg/core/openolt_flowmgr.go
@@ -41,6 +41,7 @@
 
 	//deepcopy "github.com/getlantern/deepcopy"
 	"github.com/EagleChen/mapmutex"
+	"github.com/opencord/voltha-openolt-adapter/internal/pkg/olterrors"
 	"google.golang.org/grpc/codes"
 	"google.golang.org/grpc/status"
 )
@@ -271,7 +272,7 @@
 		log.Debug("multicast flow, shifting id")
 		return 0x2<<15 | uint64(flowID), nil
 	} else {
-		return 0, NewErrInvalidValue(log.Fields{"direction": direction}, nil).Log()
+		return 0, olterrors.NewErrInvalidValue(log.Fields{"direction": direction}, nil).Log()
 	}
 }
 
@@ -364,7 +365,7 @@
 			log.Debug("Scheduler already created for upstream")
 			return nil
 		}
-		return NewErrInvalidValue(log.Fields{
+		return olterrors.NewErrInvalidValue(log.Fields{
 			"unsupported":       "meter-id",
 			"kv-store-meter-id": KvStoreMeter.MeterId,
 			"meter-id-in-flow":  sq.meterID}, nil).Log()
@@ -396,13 +397,13 @@
 		log.Error("Flow-metadata-is-not-present-in-flow")
 	}
 	if meterConfig == nil {
-		return NewErrNotFound("meterbands", log.Fields{
+		return olterrors.NewErrNotFound("meterbands", log.Fields{
 			"reason":        "Could-not-get-meterbands-from-flowMetadata",
 			"flow-metadata": sq.flowMetadata,
 			"meter-id":      sq.meterID}, nil).Log()
 	} else if len(meterConfig.Bands) < MaxMeterBand {
 		log.Errorw("Invalid-number-of-bands-in-meter", log.Fields{"Bands": meterConfig.Bands, "MeterID": sq.meterID})
-		return NewErrInvalidValue(log.Fields{
+		return olterrors.NewErrInvalidValue(log.Fields{
 			"reason":          "Invalid-number-of-bands-in-meter",
 			"meterband-count": len(meterConfig.Bands),
 			"metabands":       meterConfig.Bands,
@@ -661,7 +662,7 @@
 	}
 	//Make sure we have as many tech_profiles as there are pon ports on the device
 	if tpCount != int(f.resourceMgr.DevInfo.GetPonPorts()) {
-		return NewErrInvalidValue(log.Fields{
+		return olterrors.NewErrInvalidValue(log.Fields{
 			"reason":             "TP count does not match number of PON ports",
 			"tech-profile-count": tpCount,
 			"pon-port-count":     f.resourceMgr.DevInfo.GetPonPorts()}, nil).Log()
@@ -708,7 +709,7 @@
 	if ok {
 		downlinkAction[VlanVid] = dlClVid & 0xfff
 	} else {
-		return NewErrInvalidValue(log.Fields{
+		return olterrors.NewErrInvalidValue(log.Fields{
 			"reason":  "failed to convert VLANID classifier",
 			"vlan-id": VlanVid}, nil).Log()
 	}
@@ -744,21 +745,21 @@
 	}
 	flowID, err := f.resourceMgr.GetFlowID(ctx, intfID, int32(onuID), int32(uniID), gemPortID, flowStoreCookie, HsiaFlow, vlanPbit)
 	if err != nil {
-		return NewErrNotFound("hsia-flow-id", log.Fields{"direction": direction}, err).Log()
+		return olterrors.NewErrNotFound("hsia-flow-id", log.Fields{"direction": direction}, err).Log()
 	}
 	classifierProto, err := makeOpenOltClassifierField(classifier)
 	if err != nil {
-		return NewErrInvalidValue(log.Fields{"classifier": classifier}, err).Log()
+		return olterrors.NewErrInvalidValue(log.Fields{"classifier": classifier}, err).Log()
 	}
 	log.Debugw("Created classifier proto", log.Fields{"classifier": *classifierProto})
 	actionProto, err := makeOpenOltActionField(action)
 	if err != nil {
-		return NewErrInvalidValue(log.Fields{"action": action}, err).Log()
+		return olterrors.NewErrInvalidValue(log.Fields{"action": action}, err).Log()
 	}
 	log.Debugw("Created action proto", log.Fields{"action": *actionProto})
 	networkIntfID, err := getNniIntfID(classifier, action)
 	if err != nil {
-		return NewErrNotFound("nni-interface-id",
+		return olterrors.NewErrNotFound("nni-interface-id",
 			log.Fields{
 				"classifier": classifier,
 				"action":     action,
@@ -778,7 +779,7 @@
 		Cookie:        logicalFlow.Cookie,
 		PortNo:        portNo}
 	if err := f.addFlowToDevice(ctx, logicalFlow, &flow); err != nil {
-		return NewErrFlowOp("add", flowID, nil, err).Log()
+		return olterrors.NewErrFlowOp("add", flowID, nil, err).Log()
 	}
 	log.Debug("HSIA flow added to device successfully", log.Fields{"direction": direction})
 	flowsToKVStore := f.getUpdatedFlowInfo(ctx, &flow, flowStoreCookie, HsiaFlow, flowID, logicalFlow.Id)
@@ -786,7 +787,7 @@
 		flow.OnuId,
 		flow.UniId,
 		flow.FlowId /*flowCategory,*/, flowsToKVStore); err != nil {
-		return NewErrPersistence("update", "flow", flowID, log.Fields{"flow": flow}, err).Log()
+		return olterrors.NewErrPersistence("update", "flow", flowID, log.Fields{"flow": flow}, err).Log()
 	}
 	return nil
 }
@@ -795,7 +796,7 @@
 
 	networkIntfID, err := getNniIntfID(classifier, action)
 	if err != nil {
-		return NewErrNotFound("nni-interface-id", log.Fields{
+		return olterrors.NewErrNotFound("nni-interface-id", log.Fields{
 			"classifier": classifier,
 			"action":     action},
 			err).Log()
@@ -821,7 +822,7 @@
 	flowID, err := f.resourceMgr.GetFlowID(ctx, intfID, int32(onuID), int32(uniID), gemPortID, flowStoreCookie, DhcpFlow, 0 /*classifier[VLAN_PCP].(uint32)*/)
 
 	if err != nil {
-		return NewErrNotFound("flow", log.Fields{
+		return olterrors.NewErrNotFound("flow", log.Fields{
 			"interface-id": intfID,
 			"gem-port":     gemPortID,
 			"cookie":       flowStoreCookie},
@@ -832,12 +833,12 @@
 
 	classifierProto, err := makeOpenOltClassifierField(classifier)
 	if err != nil {
-		return NewErrInvalidValue(log.Fields{"classifier": classifier}, err).Log()
+		return olterrors.NewErrInvalidValue(log.Fields{"classifier": classifier}, err).Log()
 	}
 	log.Debugw("Created classifier proto", log.Fields{"classifier": *classifierProto})
 	actionProto, err := makeOpenOltActionField(action)
 	if err != nil {
-		return NewErrInvalidValue(log.Fields{"action": action}, err).Log()
+		return olterrors.NewErrInvalidValue(log.Fields{"action": action}, err).Log()
 	}
 
 	dhcpFlow := openoltpb2.Flow{AccessIntfId: int32(intfID),
@@ -855,7 +856,7 @@
 		PortNo:        portNo}
 
 	if err := f.addFlowToDevice(ctx, logicalFlow, &dhcpFlow); err != nil {
-		return NewErrFlowOp("add", flowID, log.Fields{"dhcp-flow": dhcpFlow}, err).Log()
+		return olterrors.NewErrFlowOp("add", flowID, log.Fields{"dhcp-flow": dhcpFlow}, err).Log()
 	}
 	log.Debug("DHCP UL flow added to device successfully")
 	flowsToKVStore := f.getUpdatedFlowInfo(ctx, &dhcpFlow, flowStoreCookie, "DHCP", flowID, logicalFlow.Id)
@@ -863,7 +864,7 @@
 		dhcpFlow.OnuId,
 		dhcpFlow.UniId,
 		dhcpFlow.FlowId, flowsToKVStore); err != nil {
-		return NewErrPersistence("update", "flow", dhcpFlow.FlowId, log.Fields{"flow": dhcpFlow}, err).Log()
+		return olterrors.NewErrPersistence("update", "flow", dhcpFlow.FlowId, log.Fields{"flow": dhcpFlow}, err).Log()
 	}
 
 	return nil
@@ -881,7 +882,7 @@
 
 	networkIntfID, err := getNniIntfID(classifier, action)
 	if err != nil {
-		return NewErrNotFound("nni-interface-id", log.Fields{
+		return olterrors.NewErrNotFound("nni-interface-id", log.Fields{
 			"classifier": classifier,
 			"action":     action},
 			err).Log()
@@ -905,7 +906,7 @@
 	flowID, err := f.resourceMgr.GetFlowID(ctx, intfID, int32(onuID), int32(uniID), gemPortID, flowStoreCookie, flowType, 0, 0 /*classifier[VLAN_PCP].(uint32)*/)
 
 	if err != nil {
-		return NewErrNotFound("flow-id", log.Fields{
+		return olterrors.NewErrNotFound("flow-id", log.Fields{
 			"interface-id": intfID,
 			"oni-id":       onuID,
 			"cookie":       flowStoreCookie,
@@ -917,12 +918,12 @@
 
 	classifierProto, err := makeOpenOltClassifierField(classifier)
 	if err != nil {
-		return NewErrInvalidValue(log.Fields{"classifier": classifier}, err).Log()
+		return olterrors.NewErrInvalidValue(log.Fields{"classifier": classifier}, err).Log()
 	}
 	log.Debugw("Created classifier proto", log.Fields{"classifier": *classifierProto})
 	actionProto, err := makeOpenOltActionField(action)
 	if err != nil {
-		return NewErrInvalidValue(log.Fields{"action": action}, err).Log()
+		return olterrors.NewErrInvalidValue(log.Fields{"action": action}, err).Log()
 	}
 
 	flow := openoltpb2.Flow{AccessIntfId: int32(intfID),
@@ -940,7 +941,7 @@
 		PortNo:        portNo}
 
 	if err := f.addFlowToDevice(ctx, logicalFlow, &flow); err != nil {
-		return NewErrFlowOp("add", flowID, log.Fields{"flow": flow}, err).Log()
+		return olterrors.NewErrFlowOp("add", flowID, log.Fields{"flow": flow}, err).Log()
 	}
 	log.Debugf("%s UL flow added to device successfully", flowType)
 
@@ -949,7 +950,7 @@
 		flow.OnuId,
 		flow.UniId,
 		flow.FlowId, flowsToKVStore); err != nil {
-		return NewErrPersistence("update", "flow", flow.FlowId, log.Fields{"flow": flow}, err).Log()
+		return olterrors.NewErrPersistence("update", "flow", flow.FlowId, log.Fields{"flow": flow}, err).Log()
 	}
 
 	return nil
@@ -976,7 +977,7 @@
 	//Add Uplink EAPOL Flow
 	uplinkFlowID, err := f.resourceMgr.GetFlowID(ctx, intfID, int32(onuID), int32(uniID), gemPortID, flowStoreCookie, "", 0)
 	if err != nil {
-		return NewErrNotFound("flow-id", log.Fields{
+		return olterrors.NewErrNotFound("flow-id", log.Fields{
 			"interface-id": intfID,
 			"onu-id":       onuID,
 			"coookie":      flowStoreCookie},
@@ -986,17 +987,17 @@
 
 	classifierProto, err := makeOpenOltClassifierField(uplinkClassifier)
 	if err != nil {
-		return NewErrInvalidValue(log.Fields{"classifier": uplinkClassifier}, err).Log()
+		return olterrors.NewErrInvalidValue(log.Fields{"classifier": uplinkClassifier}, err).Log()
 	}
 	log.Debugw("Created classifier proto", log.Fields{"classifier": *classifierProto})
 	actionProto, err := makeOpenOltActionField(uplinkAction)
 	if err != nil {
-		return NewErrInvalidValue(log.Fields{"action": uplinkAction}, err).Log()
+		return olterrors.NewErrInvalidValue(log.Fields{"action": uplinkAction}, err).Log()
 	}
 	log.Debugw("Created action proto", log.Fields{"action": *actionProto})
 	networkIntfID, err := getNniIntfID(classifier, action)
 	if err != nil {
-		return NewErrNotFound("nni-interface-id", log.Fields{
+		return olterrors.NewErrNotFound("nni-interface-id", log.Fields{
 			"classifier": classifier,
 			"action":     action},
 			err).Log()
@@ -1016,7 +1017,7 @@
 		Cookie:        logicalFlow.Cookie,
 		PortNo:        portNo}
 	if err := f.addFlowToDevice(ctx, logicalFlow, &upstreamFlow); err != nil {
-		return NewErrFlowOp("add", uplinkFlowID, log.Fields{"flow": upstreamFlow}, err).Log()
+		return olterrors.NewErrFlowOp("add", uplinkFlowID, log.Fields{"flow": upstreamFlow}, err).Log()
 	}
 	log.Debug("EAPOL UL flow added to device successfully")
 	flowCategory := "EAPOL"
@@ -1027,7 +1028,7 @@
 		upstreamFlow.FlowId,
 		/* lowCategory, */
 		flowsToKVStore); err != nil {
-		return NewErrPersistence("update", "flow", upstreamFlow.FlowId, log.Fields{"flow": upstreamFlow}, err).Log()
+		return olterrors.NewErrPersistence("update", "flow", upstreamFlow.FlowId, log.Fields{"flow": upstreamFlow}, err).Log()
 	}
 
 	log.Debugw("Added EAPOL flows to device successfully", log.Fields{"flow": logicalFlow})
@@ -1070,7 +1071,7 @@
 		case DoubleTag:
 		case Untagged:
 		default:
-			return nil, NewErrInvalidValue(log.Fields{"packet-tag-type": pktTagType}, nil).Log()
+			return nil, olterrors.NewErrInvalidValue(log.Fields{"packet-tag-type": pktTagType}, nil).Log()
 		}
 	}
 	return &classifier, nil
@@ -1089,7 +1090,7 @@
 	} else if _, ok := actionInfo[TrapToHost]; ok {
 		action.Cmd.TrapToHost = actionInfo[TrapToHost].(bool)
 	} else {
-		return nil, NewErrInvalidValue(log.Fields{"action-command": actionInfo}, nil).Log()
+		return nil, olterrors.NewErrInvalidValue(log.Fields{"action-command": actionInfo}, nil).Log()
 	}
 	return &action, nil
 }
@@ -1307,7 +1308,7 @@
 
 	networkInterfaceID, err := IntfIDFromNniPortNum(portNo)
 	if err != nil {
-		return NewErrInvalidValue(log.Fields{"nni-port-number": portNo}, err).Log()
+		return olterrors.NewErrInvalidValue(log.Fields{"nni-port-number": portNo}, err).Log()
 	}
 	var flowStoreCookie = getFlowStoreCookie(classifierInfo, uint32(0))
 	if present := f.resourceMgr.IsFlowCookieOnKVStore(ctx, uint32(networkInterfaceID), int32(onuID), int32(uniID), flowStoreCookie); present {
@@ -1317,7 +1318,7 @@
 	flowID, err := f.resourceMgr.GetFlowID(ctx, uint32(networkInterfaceID), int32(onuID), int32(uniID), uint32(gemPortID), flowStoreCookie, "", 0)
 
 	if err != nil {
-		return NewErrNotFound("flow-id", log.Fields{
+		return olterrors.NewErrNotFound("flow-id", log.Fields{
 			"interface-id": networkInterfaceID,
 			"onu-id":       onuID,
 			"uni-id":       uniID,
@@ -1327,12 +1328,12 @@
 	}
 	classifierProto, err := makeOpenOltClassifierField(classifierInfo)
 	if err != nil {
-		return NewErrInvalidValue(log.Fields{"classifier": classifierInfo}, err).Log()
+		return olterrors.NewErrInvalidValue(log.Fields{"classifier": classifierInfo}, err).Log()
 	}
 	log.Debugw("Created classifier proto", log.Fields{"classifier": *classifierProto})
 	actionProto, err := makeOpenOltActionField(actionInfo)
 	if err != nil {
-		return NewErrInvalidValue(log.Fields{"action": actionInfo}, err).Log()
+		return olterrors.NewErrInvalidValue(log.Fields{"action": actionInfo}, err).Log()
 	}
 	log.Debugw("Created action proto", log.Fields{"action": *actionProto})
 
@@ -1349,7 +1350,7 @@
 		Cookie:        flow.Cookie,
 		PortNo:        portNo}
 	if err := f.addFlowToDevice(ctx, flow, &downstreamflow); err != nil {
-		return NewErrFlowOp("add", flowID, log.Fields{"flow": downstreamflow}, err).Log()
+		return olterrors.NewErrFlowOp("add", flowID, log.Fields{"flow": downstreamflow}, err).Log()
 	}
 	log.Debug("LLDP trap on NNI flow added to device successfully")
 	flowsToKVStore := f.getUpdatedFlowInfo(ctx, &downstreamflow, flowStoreCookie, "", flowID, flow.Id)
@@ -1357,7 +1358,7 @@
 		int32(onuID),
 		int32(uniID),
 		flowID, flowsToKVStore); err != nil {
-		return NewErrPersistence("update", "flow", flowID, log.Fields{"flow": downstreamflow}, err).Log()
+		return olterrors.NewErrPersistence("update", "flow", flowID, log.Fields{"flow": downstreamflow}, err).Log()
 	}
 	return nil
 }
@@ -1372,7 +1373,7 @@
 	parentPortNo := IntfIDToPortNo(intfID, voltha.Port_PON_OLT)
 	onuDevice, err := f.deviceHandler.GetChildDevice(parentPortNo, onuID)
 	if err != nil {
-		return nil, NewErrNotFound("onu", log.Fields{
+		return nil, olterrors.NewErrNotFound("onu", log.Fields{
 			"interface-id": parentPortNo,
 			"onu-id":       onuID},
 			err).Log()
@@ -1910,7 +1911,7 @@
 
 	inPort, err := f.getInPortOfMulticastFlow(ctx, classifierInfo)
 	if err != nil {
-		return NewErrNotFound("multicast-in-port", log.Fields{"classifier": classifierInfo}, err).Log()
+		return olterrors.NewErrNotFound("multicast-in-port", log.Fields{"classifier": classifierInfo}, err).Log()
 	}
 	//replace ipDst with ethDst
 	if ipv4Dst, ok := classifierInfo[Ipv4Dst]; ok &&
@@ -1929,7 +1930,7 @@
 
 	networkInterfaceID, err := IntfIDFromNniPortNum(inPort)
 	if err != nil {
-		return NewErrInvalidValue(log.Fields{"nni-in-port-number": inPort}, err).Log()
+		return olterrors.NewErrInvalidValue(log.Fields{"nni-in-port-number": inPort}, err).Log()
 	}
 
 	flowStoreCookie := getFlowStoreCookie(classifierInfo, uint32(0))
@@ -1939,7 +1940,7 @@
 	}
 	flowID, err := f.resourceMgr.GetFlowID(ctx, uint32(networkInterfaceID), int32(onuID), int32(uniID), uint32(gemPortID), flowStoreCookie, "", 0, 0)
 	if err != nil {
-		return NewErrNotFound("multicast-flow-id", log.Fields{
+		return olterrors.NewErrNotFound("multicast-flow-id", log.Fields{
 			"interface-id": networkInterfaceID,
 			"onu-id":       onuID,
 			"uni-id":       uniID,
@@ -1949,7 +1950,7 @@
 	}
 	classifierProto, err := makeOpenOltClassifierField(classifierInfo)
 	if err != nil {
-		return NewErrInvalidValue(log.Fields{"classifier": classifierInfo}, err).Log()
+		return olterrors.NewErrInvalidValue(log.Fields{"classifier": classifierInfo}, err).Log()
 	}
 	groupID := actionInfo[GroupID].(uint32)
 	multicastFlow := openoltpb2.Flow{
@@ -1962,7 +1963,7 @@
 		Cookie:        flow.Cookie}
 
 	if err = f.addFlowToDevice(ctx, flow, &multicastFlow); err != nil {
-		return NewErrFlowOp("add", flowID, log.Fields{"flow": multicastFlow}, err).Log()
+		return olterrors.NewErrFlowOp("add", flowID, log.Fields{"flow": multicastFlow}, err).Log()
 	}
 	log.Debug("multicast flow added to device successfully")
 	//get cached group
@@ -1980,7 +1981,7 @@
 		int32(onuID),
 		int32(uniID),
 		flowID, flowsToKVStore); err != nil {
-		return NewErrPersistence("update", "flow", flowID, log.Fields{"flow": multicastFlow}, err).Log()
+		return olterrors.NewErrPersistence("update", "flow", flowID, log.Fields{"flow": multicastFlow}, err).Log()
 	}
 	return nil
 }
@@ -1995,7 +1996,7 @@
 	if e == nil && len(nniPorts) > 0 {
 		return nniPorts[0], nil
 	}
-	return 0, NewErrNotFound("nni-port", nil, e).Log()
+	return 0, olterrors.NewErrNotFound("nni-port", nil, e).Log()
 }
 
 // AddGroup add or update the group
@@ -2285,7 +2286,7 @@
 			}
 		}
 	}
-	return uint32(0), NewErrNotFound("onu-id", log.Fields{
+	return uint32(0), olterrors.NewErrNotFound("onu-id", log.Fields{
 		"serial-number": serialNumber,
 		"interface-id":  intfID,
 		"gem-port-id":   gemPortID},
@@ -2416,7 +2417,7 @@
 	allocID := -1
 	networkInterfaceID, err := getNniIntfID(classifier, action)
 	if err != nil {
-		return NewErrNotFound("nni-intreface-id", log.Fields{
+		return olterrors.NewErrNotFound("nni-intreface-id", log.Fields{
 			"classifier": classifier,
 			"action":     action},
 			err).Log()
@@ -2429,7 +2430,7 @@
 	}
 	flowID, err := f.resourceMgr.GetFlowID(ctx, uint32(networkInterfaceID), int32(onuID), int32(uniID), uint32(gemPortID), flowStoreCookie, "", 0)
 	if err != nil {
-		return NewErrNotFound("dhcp-trap-nni-flow-id", log.Fields{
+		return olterrors.NewErrNotFound("dhcp-trap-nni-flow-id", log.Fields{
 			"interface-id": networkInterfaceID,
 			"onu-id":       onuID,
 			"uni-id":       uniID,
@@ -2439,12 +2440,12 @@
 	}
 	classifierProto, err := makeOpenOltClassifierField(classifier)
 	if err != nil {
-		return NewErrInvalidValue(log.Fields{"classifier": classifier}, err).Log()
+		return olterrors.NewErrInvalidValue(log.Fields{"classifier": classifier}, err).Log()
 	}
 	log.Debugw("Created classifier proto", log.Fields{"classifier": *classifierProto})
 	actionProto, err := makeOpenOltActionField(action)
 	if err != nil {
-		return NewErrInvalidValue(log.Fields{"action": action}, err).Log()
+		return olterrors.NewErrInvalidValue(log.Fields{"action": action}, err).Log()
 	}
 	log.Debugw("Created action proto", log.Fields{"action": *actionProto})
 	downstreamflow := openoltpb2.Flow{AccessIntfId: int32(-1), // AccessIntfId not required
@@ -2461,7 +2462,7 @@
 		Cookie:        logicalFlow.Cookie,
 		PortNo:        portNo}
 	if err := f.addFlowToDevice(ctx, logicalFlow, &downstreamflow); err != nil {
-		return NewErrFlowOp("add", flowID, log.Fields{"flow": downstreamflow}, err).Log()
+		return olterrors.NewErrFlowOp("add", flowID, log.Fields{"flow": downstreamflow}, err).Log()
 	}
 	log.Debug("DHCP trap on NNI flow added to device successfully")
 	flowsToKVStore := f.getUpdatedFlowInfo(ctx, &downstreamflow, flowStoreCookie, "", flowID, logicalFlow.Id)
@@ -2469,7 +2470,7 @@
 		int32(onuID),
 		int32(uniID),
 		flowID, flowsToKVStore); err != nil {
-		return NewErrPersistence("update", "flow", flowID, log.Fields{"flow": downstreamflow}, err).Log()
+		return olterrors.NewErrPersistence("update", "flow", flowID, log.Fields{"flow": downstreamflow}, err).Log()
 	}
 	return nil
 }
@@ -2523,7 +2524,7 @@
 	allocID := -1
 	networkInterfaceID, err := getNniIntfID(classifier, action)
 	if err != nil {
-		return NewErrNotFound("nni-interface-id", log.Fields{
+		return olterrors.NewErrNotFound("nni-interface-id", log.Fields{
 			"classifier": classifier,
 			"action":     action},
 			err).Log()
@@ -2535,7 +2536,7 @@
 	}
 	flowID, err := f.resourceMgr.GetFlowID(ctx, uint32(networkInterfaceID), int32(onuID), int32(uniID), uint32(gemPortID), flowStoreCookie, "", 0, 0)
 	if err != nil {
-		return NewErrNotFound("igmp-flow-id", log.Fields{
+		return olterrors.NewErrNotFound("igmp-flow-id", log.Fields{
 			"interface-id": networkInterfaceID,
 			"onu-id":       onuID,
 			"uni-id":       uniID,
@@ -2545,12 +2546,12 @@
 	}
 	classifierProto, err := makeOpenOltClassifierField(classifier)
 	if err != nil {
-		return NewErrInvalidValue(log.Fields{"classifier": classifier}, err).Log()
+		return olterrors.NewErrInvalidValue(log.Fields{"classifier": classifier}, err).Log()
 	}
 	log.Debugw("Created classifier proto for the IGMP flow", log.Fields{"classifier": *classifierProto})
 	actionProto, err := makeOpenOltActionField(action)
 	if err != nil {
-		return NewErrInvalidValue(log.Fields{"action": action}, err).Log()
+		return olterrors.NewErrInvalidValue(log.Fields{"action": action}, err).Log()
 	}
 	log.Debugw("Created action proto for the IGMP flow", log.Fields{"action": *actionProto})
 	downstreamflow := openoltpb2.Flow{AccessIntfId: int32(-1), // AccessIntfId not required
@@ -2567,7 +2568,7 @@
 		Cookie:        logicalFlow.Cookie,
 		PortNo:        portNo}
 	if err := f.addFlowToDevice(ctx, logicalFlow, &downstreamflow); err != nil {
-		return NewErrFlowOp("add", flowID, log.Fields{"flow": downstreamflow}, err).Log()
+		return olterrors.NewErrFlowOp("add", flowID, log.Fields{"flow": downstreamflow}, err).Log()
 	}
 	log.Debug("IGMP Trap on NNI flow added to device successfully")
 	flowsToKVStore := f.getUpdatedFlowInfo(ctx, &downstreamflow, flowStoreCookie, "", flowID, logicalFlow.Id)
@@ -2575,14 +2576,14 @@
 		int32(onuID),
 		int32(uniID),
 		flowID, flowsToKVStore); err != nil {
-		return NewErrPersistence("update", "flow", flowID, log.Fields{"flow": downstreamflow}, err).Log()
+		return olterrors.NewErrPersistence("update", "flow", flowID, log.Fields{"flow": downstreamflow}, err).Log()
 	}
 	return nil
 }
 
 func verifyMeterIDAndGetDirection(MeterID uint32, Dir tp_pb.Direction) (string, error) {
 	if MeterID == 0 { // This should never happen
-		return "", NewErrInvalidValue(log.Fields{"meter-id": MeterID}, nil).Log()
+		return "", olterrors.NewErrInvalidValue(log.Fields{"meter-id": MeterID}, nil).Log()
 	}
 	if Dir == tp_pb.Direction_UPSTREAM {
 		return "upstream", nil
@@ -2777,7 +2778,7 @@
 				actionInfo[Output] = out.GetPort()
 				log.Debugw("action-type-output", log.Fields{"out_port": actionInfo[Output].(uint32)})
 			} else {
-				return NewErrInvalidValue(log.Fields{"output-port": nil}, nil).Log()
+				return olterrors.NewErrInvalidValue(log.Fields{"output-port": nil}, nil).Log()
 			}
 		} else if action.Type == flows.POP_VLAN {
 			actionInfo[PopVlan] = true
@@ -2797,7 +2798,7 @@
 			if out := action.GetSetField(); out != nil {
 				if field := out.GetField(); field != nil {
 					if ofClass := field.GetOxmClass(); ofClass != ofp.OfpOxmClass_OFPXMC_OPENFLOW_BASIC {
-						return NewErrInvalidValue(log.Fields{"openflow-class": ofClass}, nil).Log()
+						return olterrors.NewErrInvalidValue(log.Fields{"openflow-class": ofClass}, nil).Log()
 					}
 					/*log.Debugw("action-type-set-field",log.Fields{"field": field, "in_port": classifierInfo[IN_PORT].(uint32)})*/
 					formulateSetFieldActionInfoFromFlow(field, actionInfo)
@@ -2806,7 +2807,7 @@
 		} else if action.Type == flows.GROUP {
 			formulateGroupActionInfoFromFlow(action, actionInfo)
 		} else {
-			return NewErrInvalidValue(log.Fields{"action-type": action.Type}, nil).Log()
+			return olterrors.NewErrInvalidValue(log.Fields{"action-type": action.Type}, nil).Log()
 		}
 	}
 	return nil
@@ -2845,7 +2846,7 @@
 				classifierInfo[InPort] = uniPort
 				log.Debugw("upstream pon-to-controller-flow,inport-in-tunnelid", log.Fields{"newInPort": classifierInfo[InPort].(uint32), "outPort": actionInfo[Output].(uint32)})
 			} else {
-				return NewErrNotFound("child-in-port", log.Fields{
+				return olterrors.NewErrNotFound("child-in-port", log.Fields{
 					"reason": "upstream pon-to-controller-flow, NO-inport-in-tunnelid",
 					"flow":   flow}, nil).Log()
 			}
@@ -2858,7 +2859,7 @@
 				actionInfo[Output] = uniPort
 				log.Debugw("downstream-nni-to-pon-port-flow, outport-in-tunnelid", log.Fields{"newOutPort": actionInfo[Output].(uint32), "outPort": actionInfo[Output].(uint32)})
 			} else {
-				return NewErrNotFound("out-port", log.Fields{
+				return olterrors.NewErrNotFound("out-port", log.Fields{
 					"reason": "downstream-nni-to-pon-port-flow, no-outport-in-tunnelid",
 					"flow":   flow}, nil).Log()
 			}
@@ -2869,7 +2870,7 @@
 				log.Debugw("upstream-pon-to-nni-port-flow, inport-in-tunnelid", log.Fields{"newInPort": actionInfo[Output].(uint32),
 					"outport": actionInfo[Output].(uint32)})
 			} else {
-				return NewErrNotFound("nni-port", log.Fields{
+				return olterrors.NewErrNotFound("nni-port", log.Fields{
 					"reason":   "upstream-pon-to-nni-port-flow, no-inport-in-tunnelid",
 					"in-port":  classifierInfo[InPort].(uint32),
 					"out-port": actionInfo[Output].(uint32),
@@ -2890,7 +2891,7 @@
 	*/
 	metadata := flows.GetMetadataFromWriteMetadataAction(flow)
 	if metadata == 0 {
-		return 0, NewErrNotFound("metadata", log.Fields{"flow": flow}, nil).Log()
+		return 0, olterrors.NewErrNotFound("metadata", log.Fields{"flow": flow}, nil).Log()
 	}
 	TpID := flows.GetTechProfileIDFromWriteMetaData(metadata)
 	return uint32(TpID), nil
@@ -3014,7 +3015,7 @@
 func (f *OpenOltFlowMgr) GetFlowGroupFromKVStore(ctx context.Context, groupID uint32, cached bool) (*ofp.OfpGroupEntry, bool, error) {
 	exists, groupInfo, err := f.resourceMgr.GetFlowGroupFromKVStore(ctx, groupID, cached)
 	if err != nil {
-		return nil, false, NewErrNotFound("flow-group", log.Fields{"group-id": groupID}, err).Log()
+		return nil, false, olterrors.NewErrNotFound("flow-group", log.Fields{"group-id": groupID}, err).Log()
 	}
 	if exists {
 		return newGroup(groupInfo.GroupID, groupInfo.OutPorts), exists, nil