VOL-3340: ONU events should contain both OLT and ONU device ID

Change-Id: Ia6a1317a842ac430a42e160768f5dd64996d6f90
diff --git a/internal/pkg/core/openolt_eventmgr.go b/internal/pkg/core/openolt_eventmgr.go
index 76d1ca7..fc9a342 100644
--- a/internal/pkg/core/openolt_eventmgr.go
+++ b/internal/pkg/core/openolt_eventmgr.go
@@ -87,6 +87,37 @@
 	base10 = 10
 )
 
+const (
+	// ContextOltOperState is for the operational state of the Olt in the context of the event
+	ContextOltOperState = "oper-state"
+	// ContextOnuOnuID is for the Onu Id in the context of the event
+	ContextOnuOnuID = "onu-id"
+	// ContextOnuPonIntfID is for the PON interface Id on which the Onu Event occurred
+	ContextOnuPonIntfID = "intf-id"
+	// ContextOnuSerialNumber is for the serial number of the ONU
+	ContextOnuSerialNumber = "serial-number"
+	// ContextOnuDeviceID is for the device id of the ONU generated by VOLTHA
+	ContextOnuDeviceID = "onu-device-id"
+	// ContextOltPonIntfID is for the PON interface Id on an OLT event
+	ContextOltPonIntfID = "intf-id"
+	// ContextOnuFailureReaseon is for the reason of failure of/at ONU indicated by the event
+	ContextOnuFailureReaseon = "fail-reason"
+	// ContextOnuDrift is for the drift of an ONU in the context of an event
+	ContextOnuDrift = "drift"
+	// ContextOnuNewEqd is for the New Eqd of an ONU in the context of an event
+	ContextOnuNewEqd = "new-eqd"
+	// ContextOnuInverseBitErrorRate is for the inverse bit error rate in the context of an ONU event
+	ContextOnuInverseBitErrorRate = "inverse-bit-error-rate"
+	// ContextOltPonIntfOperState is for the operational state of a PON port in the context of an OLT event
+	ContextOltPonIntfOperState = "oper-state"
+	// ContextOnuRemoteDefectIndicatorCount is for the rdi in the context of an ONU event
+	ContextOnuRemoteDefectIndicatorCount = "rdi-count"
+	// ContextOnuDelineationErrors is for the delineation errors if present in an ONU events context
+	ContextOnuDelineationErrors = "delineation-errors"
+	// ContextOnuDifferentialDistance is for the differential distance in an ONU event context
+	ContextOnuDifferentialDistance = "differential-distance"
+)
+
 // OpenOltEventMgr struct contains
 type OpenOltEventMgr struct {
 	eventProxy adapterif.EventProxy
@@ -171,7 +202,7 @@
 	var de voltha.DeviceEvent
 	context := make(map[string]string)
 	/* Populating event context */
-	context["oper-state"] = oltIndication.OperState
+	context[ContextOltOperState] = oltIndication.OperState
 	/* Populating device event body */
 	de.Context = context
 	de.ResourceId = deviceID
@@ -193,10 +224,10 @@
 	var de voltha.DeviceEvent
 	context := make(map[string]string)
 	/* Populating event context */
-	context["onu-id"] = strconv.FormatUint(uint64(OnuID), base10)
-	context["intf-id"] = strconv.FormatUint(uint64(onuDisc.IntfId), base10)
-	context["serial-number"] = serialNumber
-	context["onu-device-id"] = onuDeviceID
+	context[ContextOnuOnuID] = strconv.FormatUint(uint64(OnuID), base10)
+	context[ContextOnuPonIntfID] = strconv.FormatUint(uint64(onuDisc.IntfId), base10)
+	context[ContextOnuSerialNumber] = serialNumber
+	context[ContextOnuDeviceID] = onuDeviceID
 	/* Populating device event body */
 	de.Context = context
 	de.ResourceId = oltDeviceID
@@ -223,7 +254,7 @@
 
 	context := make(map[string]string)
 	/* Populating event context */
-	context["intf-id"] = strconv.FormatUint(uint64(oltLos.IntfId), base10)
+	context[ContextOltPonIntfID] = strconv.FormatUint(uint64(oltLos.IntfId), base10)
 	/* Populating device event body */
 	de.Context = context
 	de.ResourceId = deviceID
@@ -258,19 +289,28 @@
 	return nil
 }
 
-func (em *OpenOltEventMgr) onuDyingGaspIndication(ctx context.Context, dgi *oop.DyingGaspIndication, deviceID string, raisedTs int64) error {
-	var de voltha.DeviceEvent
-	var serialNumber string
-	context := make(map[string]string)
-	/* Populating event context */
-	serialNumber = ""
-	onu := em.handler.formOnuKey(dgi.IntfId, dgi.OnuId)
+func (em *OpenOltEventMgr) populateContextWithSerialDeviceID(context map[string]string, intfID, onuID uint32) {
+	var serialNumber = ""
+	var onuDeviceID = ""
+	onu := em.handler.formOnuKey(intfID, onuID)
 	if onu, ok := em.handler.onus.Load(onu); ok {
 		serialNumber = onu.(*OnuDevice).serialNumber
+		onuDeviceID = onu.(*OnuDevice).deviceID
 	}
-	context["serial-number"] = serialNumber
-	context["intf-id"] = strconv.FormatUint(uint64(dgi.IntfId), base10)
-	context["onu-id"] = strconv.FormatUint(uint64(dgi.OnuId), base10)
+
+	context[ContextOnuSerialNumber] = serialNumber
+	context[ContextOnuDeviceID] = onuDeviceID
+}
+
+func (em *OpenOltEventMgr) onuDyingGaspIndication(ctx context.Context, dgi *oop.DyingGaspIndication, deviceID string, raisedTs int64) error {
+	var de voltha.DeviceEvent
+	context := make(map[string]string)
+	/* Populating event context */
+	em.populateContextWithSerialDeviceID(context, dgi.IntfId, dgi.OnuId)
+
+	context[ContextOnuPonIntfID] = strconv.FormatUint(uint64(dgi.IntfId), base10)
+	context[ContextOnuOnuID] = strconv.FormatUint(uint64(dgi.OnuId), base10)
+
 	/* Populating device event body */
 	de.Context = context
 	de.ResourceId = deviceID
@@ -351,17 +391,12 @@
 
 func (em *OpenOltEventMgr) onuAlarmIndication(ctx context.Context, onuAlarm *oop.OnuAlarmIndication, deviceID string, raisedTs int64) error {
 	var de voltha.DeviceEvent
-	var serialNumber string
+
 	context := make(map[string]string)
 	/* Populating event context */
-	context["intf-id"] = strconv.FormatUint(uint64(onuAlarm.IntfId), base10)
-	context["onu-id"] = strconv.FormatUint(uint64(onuAlarm.OnuId), base10)
-	serialNumber = ""
-	onuKey := em.handler.formOnuKey(onuAlarm.IntfId, onuAlarm.OnuId)
-	if onu, ok := em.handler.onus.Load(onuKey); ok {
-		serialNumber = onu.(*OnuDevice).serialNumber
-	}
-	context["serial-number"] = serialNumber
+	context[ContextOnuPonIntfID] = strconv.FormatUint(uint64(onuAlarm.IntfId), base10)
+	context[ContextOnuOnuID] = strconv.FormatUint(uint64(onuAlarm.OnuId), base10)
+	em.populateContextWithSerialDeviceID(context, onuAlarm.IntfId, onuAlarm.OnuId)
 
 	/* Populating device event body */
 	de.Context = context
@@ -409,9 +444,12 @@
 	var de voltha.DeviceEvent
 	context := make(map[string]string)
 	/* Populating event context */
-	context["intf-id"] = strconv.FormatUint(uint64(oaf.IntfId), base10)
-	context["onu-id"] = strconv.FormatUint(uint64(oaf.OnuId), base10)
-	context["fail-reason"] = strconv.FormatUint(uint64(oaf.FailReason), base10)
+	context[ContextOnuPonIntfID] = strconv.FormatUint(uint64(oaf.IntfId), base10)
+	context[ContextOnuOnuID] = strconv.FormatUint(uint64(oaf.OnuId), base10)
+	context[ContextOnuFailureReaseon] = strconv.FormatUint(uint64(oaf.FailReason), base10)
+
+	em.populateContextWithSerialDeviceID(context, oaf.IntfId, oaf.OnuId)
+
 	/* Populating device event body */
 	de.Context = context
 	de.ResourceId = deviceID
@@ -428,8 +466,11 @@
 	var de voltha.DeviceEvent
 	context := make(map[string]string)
 	/* Populating event context */
-	context["intf-id"] = strconv.FormatUint(uint64(onuLossOmci.IntfId), base10)
-	context["onu-id"] = strconv.FormatUint(uint64(onuLossOmci.OnuId), base10)
+	context[ContextOnuPonIntfID] = strconv.FormatUint(uint64(onuLossOmci.IntfId), base10)
+	context[ContextOnuOnuID] = strconv.FormatUint(uint64(onuLossOmci.OnuId), base10)
+
+	em.populateContextWithSerialDeviceID(context, onuLossOmci.IntfId, onuLossOmci.OnuId)
+
 	/* Populating device event body */
 	de.Context = context
 	de.ResourceId = deviceID
@@ -450,10 +491,13 @@
 	var de voltha.DeviceEvent
 	context := make(map[string]string)
 	/* Populating event context */
-	context["intf-id"] = strconv.FormatUint(uint64(onuDriftWindow.IntfId), base10)
-	context["onu-id"] = strconv.FormatUint(uint64(onuDriftWindow.OnuId), base10)
-	context["drift"] = strconv.FormatUint(uint64(onuDriftWindow.Drift), base10)
-	context["new-eqd"] = strconv.FormatUint(uint64(onuDriftWindow.NewEqd), base10)
+	context[ContextOnuPonIntfID] = strconv.FormatUint(uint64(onuDriftWindow.IntfId), base10)
+	context[ContextOnuOnuID] = strconv.FormatUint(uint64(onuDriftWindow.OnuId), base10)
+	context[ContextOnuDrift] = strconv.FormatUint(uint64(onuDriftWindow.Drift), base10)
+	context[ContextOnuNewEqd] = strconv.FormatUint(uint64(onuDriftWindow.NewEqd), base10)
+
+	em.populateContextWithSerialDeviceID(context, onuDriftWindow.IntfId, onuDriftWindow.OnuId)
+
 	/* Populating device event body */
 	de.Context = context
 	de.ResourceId = deviceID
@@ -474,9 +518,12 @@
 	var de voltha.DeviceEvent
 	context := make(map[string]string)
 	/* Populating event context */
-	context["intf-id"] = strconv.FormatUint(uint64(onuSignalDegrade.IntfId), base10)
-	context["onu-id"] = strconv.FormatUint(uint64(onuSignalDegrade.OnuId), base10)
-	context["inverse-bit-error-rate"] = strconv.FormatUint(uint64(onuSignalDegrade.InverseBitErrorRate), base10)
+	context[ContextOnuPonIntfID] = strconv.FormatUint(uint64(onuSignalDegrade.IntfId), base10)
+	context[ContextOnuOnuID] = strconv.FormatUint(uint64(onuSignalDegrade.OnuId), base10)
+	context[ContextOnuInverseBitErrorRate] = strconv.FormatUint(uint64(onuSignalDegrade.InverseBitErrorRate), base10)
+
+	em.populateContextWithSerialDeviceID(context, onuSignalDegrade.IntfId, onuSignalDegrade.OnuId)
+
 	/* Populating device event body */
 	de.Context = context
 	de.ResourceId = deviceID
@@ -497,9 +544,11 @@
 	var de voltha.DeviceEvent
 	context := make(map[string]string)
 	/* Populating event context */
-	context["onu-id"] = strconv.FormatUint(uint64(onuSignalsFail.OnuId), base10)
-	context["intf-id"] = strconv.FormatUint(uint64(onuSignalsFail.IntfId), base10)
-	context["inverse-bit-error-rate"] = strconv.FormatUint(uint64(onuSignalsFail.InverseBitErrorRate), base10)
+	em.populateContextWithSerialDeviceID(context, onuSignalsFail.IntfId, onuSignalsFail.OnuId)
+
+	context[ContextOnuOnuID] = strconv.FormatUint(uint64(onuSignalsFail.OnuId), base10)
+	context[ContextOnuPonIntfID] = strconv.FormatUint(uint64(onuSignalsFail.IntfId), base10)
+	context[ContextOnuInverseBitErrorRate] = strconv.FormatUint(uint64(onuSignalsFail.InverseBitErrorRate), base10)
 	/* Populating device event body */
 	de.Context = context
 	de.ResourceId = deviceID
@@ -520,8 +569,10 @@
 	var de voltha.DeviceEvent
 	context := make(map[string]string)
 	/* Populating event context */
-	context["onu-id"] = strconv.FormatUint(uint64(onuStartupFail.OnuId), base10)
-	context["intf-id"] = strconv.FormatUint(uint64(onuStartupFail.IntfId), base10)
+	em.populateContextWithSerialDeviceID(context, onuStartupFail.IntfId, onuStartupFail.OnuId)
+
+	context[ContextOnuOnuID] = strconv.FormatUint(uint64(onuStartupFail.OnuId), base10)
+	context[ContextOnuPonIntfID] = strconv.FormatUint(uint64(onuStartupFail.IntfId), base10)
 
 	/* Populating device event body */
 	de.Context = context
@@ -543,8 +594,10 @@
 	var de voltha.DeviceEvent
 	context := make(map[string]string)
 	/* Populating event context */
-	context["onu-id"] = strconv.FormatUint(uint64(onuLOKI.OnuId), base10)
-	context["intf-id"] = strconv.FormatUint(uint64(onuLOKI.IntfId), base10)
+	em.populateContextWithSerialDeviceID(context, onuLOKI.IntfId, onuLOKI.OnuId)
+
+	context[ContextOnuOnuID] = strconv.FormatUint(uint64(onuLOKI.OnuId), base10)
+	context[ContextOnuPonIntfID] = strconv.FormatUint(uint64(onuLOKI.IntfId), base10)
 	/* Populating device event body */
 	de.Context = context
 	de.ResourceId = deviceID
@@ -582,7 +635,7 @@
 		}
 	}
 	/* Populating event context */
-	context["oper-state"] = ifindication.GetOperState()
+	context[ContextOltPonIntfOperState] = ifindication.GetOperState()
 	/* Populating device event body */
 	de.Context = context
 	de.ResourceId = deviceID
@@ -604,8 +657,10 @@
 	var de voltha.DeviceEvent
 	context := make(map[string]string)
 	/* Populating event context */
-	context["onu-id"] = strconv.FormatUint(uint64(onuDFI.OnuId), base10)
-	context["intf-id"] = strconv.FormatUint(uint64(onuDFI.IntfId), base10)
+	em.populateContextWithSerialDeviceID(context, onuDFI.IntfId, onuDFI.OnuId)
+
+	context[ContextOnuOnuID] = strconv.FormatUint(uint64(onuDFI.OnuId), base10)
+	context[ContextOnuPonIntfID] = strconv.FormatUint(uint64(onuDFI.IntfId), base10)
 	/* Populating device event body */
 	de.Context = context
 	de.ResourceId = deviceID
@@ -621,13 +676,16 @@
 	logger.Debugw(ctx, "onu-deactivation-failure-event-sent-to-kafka", log.Fields{"onu-id": onuDFI.OnuId, "intf-id": onuDFI.IntfId})
 	return nil
 }
+
 func (em *OpenOltEventMgr) onuRemoteDefectIndication(ctx context.Context, onuID uint32, intfID uint32, rdiCount uint64, status string, deviceID string, raisedTs int64) error {
 	/* Populating event context */
 	context := map[string]string{
-		"onu-id":    strconv.FormatUint(uint64(onuID), base10),
-		"intf-id":   strconv.FormatUint(uint64(intfID), base10),
-		"rdi-count": strconv.FormatUint(rdiCount, base10),
+		ContextOnuOnuID:                      strconv.FormatUint(uint64(onuID), base10),
+		ContextOnuPonIntfID:                  strconv.FormatUint(uint64(intfID), base10),
+		ContextOnuRemoteDefectIndicatorCount: strconv.FormatUint(rdiCount, base10),
 	}
+	em.populateContextWithSerialDeviceID(context, intfID, onuID)
+
 	/* Populating device event body */
 	de := &voltha.DeviceEvent{
 		Context:    context,
@@ -672,10 +730,12 @@
 func (em *OpenOltEventMgr) onuLossOfGEMChannelDelineationIndication(ctx context.Context, onuGCD *oop.OnuLossOfGEMChannelDelineationIndication, deviceID string, raisedTs int64) error {
 	/* Populating event context */
 	context := map[string]string{
-		"onu-id":             strconv.FormatUint(uint64(onuGCD.OnuId), base10),
-		"intf-id":            strconv.FormatUint(uint64(onuGCD.IntfId), base10),
-		"delineation-errors": strconv.FormatUint(uint64(onuGCD.DelineationErrors), base10),
+		ContextOnuOnuID:             strconv.FormatUint(uint64(onuGCD.OnuId), base10),
+		ContextOnuPonIntfID:         strconv.FormatUint(uint64(onuGCD.IntfId), base10),
+		ContextOnuDelineationErrors: strconv.FormatUint(uint64(onuGCD.DelineationErrors), base10),
 	}
+	em.populateContextWithSerialDeviceID(context, onuGCD.IntfId, onuGCD.OnuId)
+
 	/* Populating device event body */
 	de := &voltha.DeviceEvent{
 		Context:    context,
@@ -697,9 +757,10 @@
 func (em *OpenOltEventMgr) onuPhysicalEquipmentErrorIndication(ctx context.Context, onuErr *oop.OnuPhysicalEquipmentErrorIndication, deviceID string, raisedTs int64) error {
 	/* Populating event context */
 	context := map[string]string{
-		"onu-id":  strconv.FormatUint(uint64(onuErr.OnuId), base10),
-		"intf-id": strconv.FormatUint(uint64(onuErr.IntfId), base10),
+		ContextOnuOnuID:     strconv.FormatUint(uint64(onuErr.OnuId), base10),
+		ContextOnuPonIntfID: strconv.FormatUint(uint64(onuErr.IntfId), base10),
 	}
+	em.populateContextWithSerialDeviceID(context, onuErr.IntfId, onuErr.OnuId)
 	/* Populating device event body */
 	de := &voltha.DeviceEvent{
 		Context:    context,
@@ -721,9 +782,11 @@
 func (em *OpenOltEventMgr) onuLossOfAcknowledgementIndication(ctx context.Context, onuLOA *oop.OnuLossOfAcknowledgementIndication, deviceID string, raisedTs int64) error {
 	/* Populating event context */
 	context := map[string]string{
-		"onu-id":  strconv.FormatUint(uint64(onuLOA.OnuId), base10),
-		"intf-id": strconv.FormatUint(uint64(onuLOA.IntfId), base10),
+		ContextOnuOnuID:     strconv.FormatUint(uint64(onuLOA.OnuId), base10),
+		ContextOnuPonIntfID: strconv.FormatUint(uint64(onuLOA.IntfId), base10),
 	}
+	em.populateContextWithSerialDeviceID(context, onuLOA.IntfId, onuLOA.OnuId)
+
 	/* Populating device event body */
 	de := &voltha.DeviceEvent{
 		Context:    context,
@@ -745,10 +808,12 @@
 func (em *OpenOltEventMgr) onuDifferentialReachExceededIndication(ctx context.Context, onuDRE *oop.OnuDifferentialReachExceededIndication, deviceID string, raisedTs int64) error {
 	/* Populating event context */
 	context := map[string]string{
-		"onu-id":                strconv.FormatUint(uint64(onuDRE.OnuId), base10),
-		"intf-id":               strconv.FormatUint(uint64(onuDRE.IntfId), base10),
-		"differential-distance": strconv.FormatUint(uint64(onuDRE.Distance), base10),
+		ContextOnuOnuID:                strconv.FormatUint(uint64(onuDRE.OnuId), base10),
+		ContextOnuPonIntfID:            strconv.FormatUint(uint64(onuDRE.IntfId), base10),
+		ContextOnuDifferentialDistance: strconv.FormatUint(uint64(onuDRE.Distance), base10),
 	}
+	em.populateContextWithSerialDeviceID(context, onuDRE.IntfId, onuDRE.OnuId)
+
 	/* Populating device event body */
 	de := &voltha.DeviceEvent{
 		Context:    context,