SEBA-392 - MibUpload of 'ONT Data' and 'Circuit Pack' MEs

Ongoing development to add more ME handling capability in
the OMCI implementation of BBSIM. The Circuit Pack ME is
needed for subsequent handling of the T-CONT ME.

Change-Id: Ia4198313bc00147a09026de004ce7b48eb7a4b54
diff --git a/core/omci.go b/core/omci.go
index 3a4335d..d74ef92 100644
--- a/core/omci.go
+++ b/core/omci.go
@@ -20,12 +20,13 @@
 	"bytes"
 	"encoding/binary"
 
-	"gerrit.opencord.org/voltha-bbsim/common/logger"
-	"gerrit.opencord.org/voltha-bbsim/protos"
-	"gerrit.opencord.org/voltha-bbsim/device"
-	"time"
 	"context"
 	"errors"
+	"time"
+
+	"gerrit.opencord.org/voltha-bbsim/common/logger"
+	"gerrit.opencord.org/voltha-bbsim/device"
+	"gerrit.opencord.org/voltha-bbsim/protos"
 )
 
 //
@@ -87,7 +88,7 @@
 	Content       OmciContent
 }
 
-const NumMibUploads byte = 9
+const NumMibUploads byte = 18
 
 type OnuKey struct {
 	IntfId, OnuId uint32
@@ -98,7 +99,7 @@
 	mibUploadCtr uint16
 	uniGInstance uint8
 	pptpInstance uint8
-	init  istate
+	init         istate
 }
 
 type istate int
@@ -122,65 +123,65 @@
 
 var OnuOmciStateMap = map[OnuKey]*OnuOmciState{}
 
-func OmciRun(ctx context.Context, omciOut chan openolt.OmciMsg, omciIn chan openolt.OmciIndication, onumap map[uint32][] *device.Onu, errch chan error) {
+func OmciRun(ctx context.Context, omciOut chan openolt.OmciMsg, omciIn chan openolt.OmciIndication, onumap map[uint32][]*device.Onu, errch chan error) {
 	go func() { //For monitoring the OMCI states
 		t := time.NewTicker(1 * time.Second)
 		defer t.Stop()
 		for {
-			select{
-			case <- t.C:
+			select {
+			case <-t.C:
 				logger.Debug("Monitor omci init state")
 				if isAllOmciInitDone(onumap) {
 					logger.Info("OmciRun - All the omci initialization wes done")
 					close(errch)
 					return
 				}
-			case <- ctx.Done():
+			case <-ctx.Done():
 				logger.Debug("Omci Monitoring process was done")
 				return
 			}
 		}
 	}()
 
-	go func(){
+	go func() {
 		defer logger.Debug("Omci response process was done")
 		for {
 			var resp openolt.OmciIndication
-			select{
-				case m := <-omciOut:
-					transactionId, deviceId, msgType, class, instance, content, err := ParsePkt(m.Pkt)
-					if err != nil {
-						errch <- err
-						return
-					}
-
-					logger.Debug("OmciRun - transactionId: %d msgType: %d, ME Class: %d, ME Instance: %d",
-						transactionId, msgType, class, instance)
-
-					key := OnuKey{m.IntfId, m.OnuId}
-					if _, ok := OnuOmciStateMap[key]; !ok {
-						OnuOmciStateMap[key] = NewOnuOmciState()
-					}
-
-					if _, ok := Handlers[msgType]; !ok {
-						logger.Warn("Ignore omci msg (msgType %d not handled)", msgType)
-						continue
-					}
-
-					resp.Pkt, err = Handlers[msgType](class, content, key)
-					if err != nil {
-						errch <- err
-						return
-					}
-					resp.Pkt[0] = byte(transactionId >> 8)
-					resp.Pkt[1] = byte(transactionId & 0xFF)
-					resp.Pkt[2] = 0x2<<4 | byte(msgType)
-					resp.Pkt[3] = deviceId
-					resp.IntfId = m.IntfId
-					resp.OnuId = m.OnuId
-					omciIn <- resp
-				case <-ctx.Done():
+			select {
+			case m := <-omciOut:
+				transactionId, deviceId, msgType, class, instance, content, err := ParsePkt(m.Pkt)
+				if err != nil {
+					errch <- err
 					return
+				}
+
+				logger.Debug("OmciRun - transactionId: %d msgType: %d, ME Class: %d, ME Instance: %d",
+					transactionId, msgType, class, instance)
+
+				key := OnuKey{m.IntfId, m.OnuId}
+				if _, ok := OnuOmciStateMap[key]; !ok {
+					OnuOmciStateMap[key] = NewOnuOmciState()
+				}
+
+				if _, ok := Handlers[msgType]; !ok {
+					logger.Warn("Ignore omci msg (msgType %d not handled)", msgType)
+					continue
+				}
+
+				resp.Pkt, err = Handlers[msgType](class, content, key)
+				if err != nil {
+					errch <- err
+					return
+				}
+				resp.Pkt[0] = byte(transactionId >> 8)
+				resp.Pkt[1] = byte(transactionId & 0xFF)
+				resp.Pkt[2] = 0x2<<4 | byte(msgType)
+				resp.Pkt[3] = deviceId
+				resp.IntfId = m.IntfId
+				resp.OnuId = m.OnuId
+				omciIn <- resp
+			case <-ctx.Done():
+				return
 			}
 		}
 	}()
@@ -260,6 +261,87 @@
 
 	switch state.mibUploadCtr {
 	case 0:
+		// ONT Data (2)
+		pkt = []byte{
+			0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00,
+			0x00, 0x02, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00,
+			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
+	case 1:
+		// Circuit Pack (6) - #1
+		pkt = []byte{
+			0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00,
+			0x00, 0x06, 0x01, 0x01, 0xf0, 0x00, 0x2f, 0x04,
+			0x49, 0x53, 0x4b, 0x54, 0x71, 0xe8, 0x00, 0x80,
+			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+			0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00,
+			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
+	case 2:
+		// Circuit Pack (6) - #2
+		pkt = []byte{
+			0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00,
+			0x00, 0x06, 0x01, 0x01, 0x0f, 0x00, 0x42, 0x52,
+			0x43, 0x4d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
+	case 3:
+		// Circuit Pack (6) - #3
+		pkt = []byte{
+			0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00,
+			0x00, 0x06, 0x01, 0x01, 0x00, 0xf8, 0x20, 0x20,
+			0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+			0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+			0x20, 0x20, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00,
+			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
+	case 4:
+		// Circuit Pack (6) - #4
+		pkt = []byte{
+			0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00,
+			0x00, 0x06, 0x01, 0x01, 0x00, 0x04, 0x00, 0x00,
+			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
+	case 5:
+		// Circuit Pack (6) - #5
+		pkt = []byte{
+			0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00,
+			0x00, 0x06, 0x01, 0x80, 0xf0, 0x00, 0xee, 0x01,
+			0x49, 0x53, 0x4b, 0x54, 0x71, 0xe8, 0x00, 0x80,
+			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+			0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00,
+			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
+	case 6:
+		// Circuit Pack (6) - #6
+		pkt = []byte{
+			0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00,
+			0x00, 0x06, 0x01, 0x80, 0x0f, 0x00, 0x42, 0x52,
+			0x43, 0x4d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
+	case 7:
+		// Circuit Pack (6) - #7
+		pkt = []byte{
+			0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00,
+			0x00, 0x06, 0x01, 0x80, 0x00, 0xf8, 0x20, 0x20,
+			0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+			0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+			0x20, 0x20, 0x00, 0x08, 0x40, 0x10, 0x00, 0x00,
+			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
+	case 8:
+		// Circuit Pack (6) - #8
+		pkt = []byte{
+			0x00, 0x0f, 0x2e, 0x0a, 0x00, 0x02, 0x00, 0x00,
+			0x00, 0x06, 0x01, 0x80, 0x00, 0x04, 0x00, 0x00,
+			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
+	case 9:
 		// ANI-G
 		pkt = []byte{
 			0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00,
@@ -268,7 +350,7 @@
 			0x00, 0xe0, 0x54, 0xff, 0xff, 0x00, 0x00, 0x0c,
 			0x63, 0x81, 0x81, 0x00, 0x00, 0x00, 0x00, 0x00,
 			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
-	case 1, 2, 3, 4:
+	case 10, 11, 12, 13:
 		// UNI-G
 		pkt = []byte{
 			0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00,
@@ -279,7 +361,7 @@
 			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
 		pkt[11] = state.uniGInstance // ME Instance
 		state.uniGInstance++
-	case 5, 6, 7, 8:
+	case 14, 15, 16, 17:
 		pkt = []byte{
 			0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00,
 			0x00, 0x0b, 0x01, 0x01, 0xff, 0xfe, 0x00, 0x2f,
@@ -373,16 +455,15 @@
 	return pkt, nil
 }
 
-func isAllOmciInitDone(onumap map[uint32][] *device.Onu) bool {
+func isAllOmciInitDone(onumap map[uint32][]*device.Onu) bool {
 	for _, onus := range onumap {
-		for _, onu := range onus{
+		for _, onu := range onus {
 			key := OnuKey{onu.IntfID, onu.OnuID}
 			state := OnuOmciStateMap[key]
-			if state.init == INCOMPLETE{
+			if state.init == INCOMPLETE {
 				return false
 			}
 		}
 	}
 	return true
 }
-