SEBA-471 : Include ONU Key in BBSIM logs for OMCI lib, SEBA-472 : Reset Subsequent MibUpload Count in MibReset

Change-Id: Icb53d3baa3ced22b2c11067a65e6d769ad4ea939
diff --git a/omci_common.go b/omci_common.go
index d4d2e35..2a478ce 100644
--- a/omci_common.go
+++ b/omci_common.go
@@ -29,3 +29,7 @@
 type OnuKey struct {
 	IntfId, OnuId uint32
 }
+
+func (k OnuKey) String() string {
+	return fmt.Sprintf("Onu {intfid:%d, onuid:%d}", k.IntfId, k.OnuId)
+}
diff --git a/omci_handlers.go b/omci_handlers.go
index 3354f2a..f4c955e 100644
--- a/omci_handlers.go
+++ b/omci_handlers.go
@@ -38,7 +38,11 @@
 func mibReset(class OmciClass, content OmciContent, key OnuKey) ([]byte, error) {
 	var pkt []byte
 
-	log.Printf("Omci MibReset")
+	log.Printf("%v - Omci MibReset",key)
+	if state, ok := OnuOmciStateMap[key]; ok{
+		log.Printf("%v - Reseting OnuOmciState",key)       
+		state.ResetOnuOmciState()
+	}
 
 	pkt = []byte{
 		0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00,
@@ -53,7 +57,7 @@
 func mibUpload(class OmciClass, content OmciContent, key OnuKey) ([]byte, error) {
 	var pkt []byte
 
-	log.Printf("Omci MibUpload")
+	log.Printf("%v - Omci MibUpload",key)
 
 	pkt = []byte{
 		0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00,
@@ -73,7 +77,7 @@
 
 	state := OnuOmciStateMap[key]
 
-	log.Printf("Omci MibUploadNext %d", state.mibUploadCtr)
+	log.Printf("%v - Omci MibUploadNext %d", key, state.mibUploadCtr)
 
 	switch state.mibUploadCtr {
 	case 0:
@@ -200,7 +204,8 @@
 		pkt[11] = state.uniGInstance // UNI-G ME Instance
 		state.uniGInstance++
 	default:
-		errstr := fmt.Sprintf("Invalid MibUpload request: %d", state.mibUploadCtr)
+		state.extraMibUploadCtr++
+		errstr := fmt.Sprintf("%v - Invalid MibUpload request: %d, extras: %d", key, state.mibUploadCtr, state.extraMibUploadCtr)
 		return nil, errors.New(errstr)
 	}
 
@@ -219,7 +224,7 @@
 		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
 		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
 
-	log.Printf("Omci Set")
+	log.Printf("%v - Omci Set",key)
 
 	return pkt, nil
 }
@@ -229,11 +234,11 @@
 
 	if class == GEMPortNetworkCTP {
 		if onuOmciState, ok := OnuOmciStateMap[key]; !ok {
-			log.Printf("ONU Key Error - IntfId: %d, OnuId:", key.IntfId, key.OnuId)
+			log.Printf("%v - ONU Key Error",key)
 			return nil, errors.New("ONU Key Error")
 		} else {
 			onuOmciState.gemPortId = binary.BigEndian.Uint16(content[:2])
-			log.Printf("ONU Key {intfid:%d, onuid:%d} Gem Port Id %d", key.IntfId, key.OnuId, onuOmciState.gemPortId)
+			log.Printf("%v - Gem Port Id %d", key, onuOmciState.gemPortId)
 			// FIXME
 			OnuOmciStateMap[key].state = DONE
 		}
@@ -247,7 +252,7 @@
 		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
 		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
 
-	log.Printf("Omci Create")
+	log.Printf("%v - Omci Create",key)
 
 	return pkt, nil
 }
@@ -263,7 +268,7 @@
 		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
 		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
 
-	log.Printf("Omci Get")
+	log.Printf("%v - Omci Get",key)
 
 	return pkt, nil
 }
@@ -279,7 +284,7 @@
 		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
 		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
 
-	log.Printf("Omci GetAllAlarms")
+	log.Printf("%v - Omci GetAllAlarms",key)
 
 	return pkt, nil
 }
diff --git a/omci_sim.go b/omci_sim.go
index 20fe8be..e629117 100644
--- a/omci_sim.go
+++ b/omci_sim.go
@@ -23,11 +23,12 @@
 
 	transactionId, deviceId, msgType, class, instance, content, err := ParsePkt(request)
 	if err != nil {
+		log.Printf("ONU {intfid:%d, onuid:%d} - Cannot parse omci msg", intfId, onuId)
 		return resp, &OmciError{"Cannot parse omci msg"}
 	}
 
-	log.Printf("OmciRun - transactionId: %d msgType: %d, ME Class: %d, ME Instance: %d",
-		transactionId, msgType, class, instance)
+	log.Printf("ONU {intfid:%d, onuid:%d} - OmciRun - transactionId: %d msgType: %d, ME Class: %d, ME Instance: %d",
+		intfId, onuId, transactionId, msgType, class, instance)
 
 	key := OnuKey{intfId, onuId}
 	if _, ok := OnuOmciStateMap[key]; !ok {
@@ -35,13 +36,13 @@
 	}
 
 	if _, ok := Handlers[msgType]; !ok {
-		log.Printf("Ignore omci msg (msgType %d not handled)", msgType)
+		log.Printf("ONU {intfid:%d, onuid:%d} - Ignore omci msg (msgType %d not handled)", intfId, onuId, msgType)
 		return resp, &OmciError{"Unimplemented omci msg"}
 	}
 
 	resp, err = Handlers[msgType](class, content, key)
 	if err != nil {
-		log.Println("%s", err)
+		log.Println("ONU {intfid:%d, onuid:%d} - Unable to send a successful response, error:%s", intfId, onuId, err)
 		return resp, nil
 	}
 
diff --git a/omci_state.go b/omci_state.go
index be2da36..09b300e 100644
--- a/omci_state.go
+++ b/omci_state.go
@@ -23,6 +23,7 @@
 type OnuOmciState struct {
 	gemPortId     uint16
 	mibUploadCtr  uint16
+	extraMibUploadCtr	uint16	//this is only for debug purposes, will be removed in the future
 	uniGInstance  uint8
 	tcontInstance uint8
 	pptpInstance  uint8
@@ -42,7 +43,14 @@
 func NewOnuOmciState() *OnuOmciState {
 	return &OnuOmciState{gemPortId: 0, mibUploadCtr: 0, uniGInstance: 1, tcontInstance: 0, pptpInstance: 1}
 }
-
+func (s *OnuOmciState) ResetOnuOmciState(){
+	s.mibUploadCtr = 0
+	s.extraMibUploadCtr = 0
+	s.gemPortId = 0
+	s.uniGInstance = 1
+	s.tcontInstance = 0
+	s.pptpInstance = 1
+}
 func GetOnuOmciState(intfId uint32, onuId uint32) istate {
 	key := OnuKey{intfId, onuId}
 	if onu, ok := OnuOmciStateMap[key]; ok {
@@ -57,6 +65,6 @@
 	if OnuOmciState, ok := OnuOmciStateMap[key]; ok {
 		return OnuOmciState.gemPortId, nil
 	}
-	errmsg := fmt.Sprintf("Failed to find a key in OnuOmciStateMap key{intfid:%d, onuid:%d}", intfId, onuId)
+	errmsg := fmt.Sprintf("ONU {intfid:%d, onuid:%d} - Failed to find a key in OnuOmciStateMap", intfId, onuId)
 	return 0, errors.New(errmsg)
 }