SEBA-594: added missing OMCI message handling for Tech Profiles in BBSim

Change-Id: I330f547580901a3ead3f59badb6a44535ab9bf93
diff --git a/omci_handlers.go b/omci_handlers.go
index e8c8890..d5ce6d7 100644
--- a/omci_handlers.go
+++ b/omci_handlers.go
@@ -19,30 +19,31 @@
 import (
 	"encoding/binary"
 	"errors"
-	"log"
 	"fmt"
+	"log"
 )
 
 type OmciMsgHandler func(class OmciClass, content OmciContent, key OnuKey) ([]byte, error)
 
 var Handlers = map[OmciMsgType]OmciMsgHandler{
-	MibReset:      mibReset,
-	MibUpload:     mibUpload,
-	MibUploadNext: mibUploadNext,
-	Set:           set,
-	Create:        create,
-	Get:           get,
-	GetAllAlarms:  getAllAlarms,
-	GetAllAlarmsNext:	getAllAlarmsNext,
-	SynchronizeTime:	syncTime,
+	MibReset:         mibReset,
+	MibUpload:        mibUpload,
+	MibUploadNext:    mibUploadNext,
+	Set:              set,
+	Create:           create,
+	Get:              get,
+	GetAllAlarms:     getAllAlarms,
+	GetAllAlarmsNext: getAllAlarmsNext,
+	SynchronizeTime:  syncTime,
+	Delete:           delete,
 }
 
 func mibReset(class OmciClass, content OmciContent, key OnuKey) ([]byte, error) {
 	var pkt []byte
 
-	log.Printf("%v - Omci MibReset",key)
-	if state, ok := OnuOmciStateMap[key]; ok{
-		log.Printf("%v - Reseting OnuOmciState",key)       
+	log.Printf("%v - Omci MibReset", key)
+	if state, ok := OnuOmciStateMap[key]; ok {
+		log.Printf("%v - Reseting OnuOmciState", key)
 		state.ResetOnuOmciState()
 	}
 
@@ -59,7 +60,7 @@
 func mibUpload(class OmciClass, content OmciContent, key OnuKey) ([]byte, error) {
 	var pkt []byte
 
-	log.Printf("%v - Omci MibUpload",key)
+	log.Printf("%v - Omci MibUpload", key)
 
 	pkt = []byte{
 		0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00,
@@ -205,6 +206,98 @@
 			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
 		pkt[11] = state.uniGInstance // UNI-G ME Instance
 		state.uniGInstance++
+
+	case 26, 30, 34, 38, 42, 46, 50, 54:
+		// Prior-Q with mask downstream
+		log.Println("Mib-upload for prior-q with mask")
+		// For downstream PQ, pkt[10] is 0x00
+		// So the instanceId will be like 0x0001, 0x0002,... etc
+		pkt = []byte{
+			0x00, 0x42, 0x2e, 0x0a, 0x00, 0x02, 0x00, 0x00,
+			0x01, 0x15, 0x00, 0x00, 0x00, 0x0f, 0xff, 0xff,
+			0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+			0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+		}
+		state.priorQInstance++
+		pkt[11] = state.priorQInstance
+
+	case 27, 31, 35, 39, 43, 47, 51, 55:
+		// Prior-Q with attribute list downstream
+		log.Println("Mib-upload for prior-q with attribute list")
+		pkt = []byte{
+			0x00, 0x43, 0x2e, 0x0a, 0x00, 0x02, 0x00, 0x00,
+			0x01, 0x15, 0x00, 0x00, 0xff, 0xf0, 0x00, 0x01,
+			0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
+			0x20, 0x00, 0x00, 0x01, 0x20, 0x01, 0x00, 0x01,
+			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+		}
+
+		pkt[11] = state.priorQInstance
+		state.tcontInstance--
+		pkt[24] = state.tcontInstance // related port points to tcont
+		pkt[28] = state.tcontInstance
+
+	case 28, 32, 36, 40, 44, 48, 52, 56:
+		// Prior-Q with mask upstream
+		log.Println("Mib-upload for prior-q with mask")
+		pkt = []byte{
+			0x00, 0x42, 0x2e, 0x0a, 0x00, 0x02, 0x00, 0x00,
+			0x01, 0x15, 0x80, 0x00, 0x00, 0x0f, 0xff, 0xff,
+			0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+			0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+		}
+		pkt[11] = state.priorQInstance
+
+	case 29, 33, 37, 41, 45, 49, 53, 57:
+		// Prior-Q with attribute list upstream
+		log.Println("Mib-upload for prior-q with attribute list")
+		// For upstream pkt[10] is fixed as 80
+		// So for upstream PQ, instanceId will be like 0x8001, 0x8002 ... etc
+		pkt = []byte{
+			0x00, 0x43, 0x2e, 0x0a, 0x00, 0x02, 0x00, 0x00,
+			0x01, 0x15, 0x80, 0x00, 0xff, 0xf0, 0x00, 0x01,
+			0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80,
+			0x20, 0x00, 0x00, 0x80, 0x20, 0x01, 0x00, 0x01,
+			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+		}
+
+		pkt[11] = state.priorQInstance
+		pkt[24] = state.tcontInstance // related port points to tcont
+		pkt[28] = state.tcontInstance
+
+	case 58, 59, 60, 61, 62, 63, 64, 65:
+		// Traffic Scheduler
+		log.Println("Traffic Scheduler")
+		pkt = []byte{
+			0x02, 0xa4, 0x2e, 0x0a, 0x00, 0x02, 0x00, 0x00,
+			0x01, 0x16, 0x80, 0x00, 0xf0, 0x00, 0x80, 0x00,
+			0x00, 0x00, 0x02, 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,
+		}
+
+		pkt[15] = state.tcontInstance
+		state.tcontInstance++
+
+	case 66:
+		// ONT-2G
+		log.Println("ONT-2G")
+		pkt = []byte{
+			0x00, 0x16, 0x2e, 0x0a, 0x00, 0x02, 0x00, 0x00,
+			0x01, 0x01, 0x00, 0x00, 0x07, 0xfc, 0x00, 0x40,
+			0x08, 0x01, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00,
+			0x00, 0x7f, 0x00, 0x00, 0x3f, 0x00, 0x01, 0x00,
+			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+		}
+
 	default:
 		state.extraMibUploadCtr++
 		errstr := fmt.Sprintf("%v - Invalid MibUpload request: %d, extras: %d", key, state.mibUploadCtr, state.extraMibUploadCtr)
@@ -226,7 +319,7 @@
 		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
 		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
 
-	log.Printf("%v - Omci Set",key)
+	log.Printf("%v - Omci Set", key)
 
 	return pkt, nil
 }
@@ -236,7 +329,7 @@
 
 	if class == GEMPortNetworkCTP {
 		if onuOmciState, ok := OnuOmciStateMap[key]; !ok {
-			log.Printf("%v - ONU Key Error",key)
+			log.Printf("%v - ONU Key Error", key)
 			return nil, errors.New("ONU Key Error")
 		} else {
 			onuOmciState.gemPortId = binary.BigEndian.Uint16(content[:2])
@@ -254,7 +347,7 @@
 		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
 		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
 
-	log.Printf("%v - Omci Create",key)
+	log.Printf("%v - Omci Create", key)
 
 	return pkt, nil
 }
@@ -270,7 +363,7 @@
 		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
 		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
 
-	log.Printf("%v - Omci Get",key)
+	log.Printf("%v - Omci Get", key)
 
 	return pkt, nil
 }
@@ -286,12 +379,11 @@
 		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
 		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
 
-	log.Printf("%v - Omci GetAllAlarms",key)
+	log.Printf("%v - Omci GetAllAlarms", key)
 
 	return pkt, nil
 }
 
-
 func syncTime(class OmciClass, content OmciContent, key OnuKey) ([]byte, error) {
 	var pkt []byte
 
@@ -303,7 +395,7 @@
 		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
 		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
 
-	log.Printf("%v - Omci syncTime",key)
+	log.Printf("%v - Omci syncTime", key)
 
 	return pkt, nil
 }
@@ -319,7 +411,23 @@
 		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
 		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
 
-	log.Printf("%v - Omci GetAllAlarmsNext",key)
+	log.Printf("%v - Omci GetAllAlarmsNext", key)
+
+	return pkt, nil
+}
+
+func delete(class OmciClass, content OmciContent, key OnuKey) ([]byte, error) {
+	var pkt []byte
+
+	pkt = []byte{
+		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+		0x00, 0x0b, 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}
+
+	log.Printf("%v - Omci Delete", key)
 
 	return pkt, nil
 }
diff --git a/omci_mib.go b/omci_mib.go
index 6fba4fd..fa5943c 100644
--- a/omci_mib.go
+++ b/omci_mib.go
@@ -16,4 +16,4 @@
 
 package core
 
-const NumMibUploads byte = 26
+const NumMibUploads byte = 0x43 // NumMibUploads is the number of mibs to be sent in subsequent mibuploadnext
diff --git a/omci_sim.go b/omci_sim.go
index e629117..2d723c0 100644
--- a/omci_sim.go
+++ b/omci_sim.go
@@ -46,10 +46,37 @@
 		return resp, nil
 	}
 
+	// In the OMCI message, first 2-bytes is the Transaction Correlation ID
 	resp[0] = byte(transactionId >> 8)
 	resp[1] = byte(transactionId & 0xFF)
-	resp[2] = 0x2<<4 | byte(msgType)
+	resp[2] = 0x2<<4 | byte(msgType) // Upper nibble 0x2 is fixed (0010), Lower nibbles defines the msg type (i.e., mib-upload, mib-upload-next, etc)
 	resp[3] = deviceId
 
+	// for create, get and set
+	if ((msgType & 0xFF) != MibUploadNext) && ((msgType & 0xFF) != MibReset) && ((msgType & 0xFF) != MibUpload) {
+		log.Println("CREATE GET OR SET OPERATION")
+		// Common fields for create, get, and set
+		resp[4] = byte(class >> 8)
+		resp[5] = byte(class & 0xFF)
+		resp[6] = byte(instance >> 8)
+		resp[7] = byte(instance & 0xFF)
+		resp[8] = 0 // Result: Command Processed Successfully
+
+		// Hardcoding class specific values for Get
+		if (class == 0x82) && ((msgType & 0x0F) == Get) {
+			resp[9] = 0
+			resp[10] = 0x78
+
+		} else if (class == 0x2F) && ((msgType & 0x0F) == Get) {
+			resp[9] = 0x0F
+			resp[10] = 0xB8
+		} else if (class == 0x138) && ((msgType & 0x0F) == Get) {
+			resp[9] = content[0] // 0xBE
+			resp[10] = 0x00
+		}
+	}
+
+	log.Printf("OMCI-SIM Response %+x\n", resp)
+
 	return resp, nil
 }
diff --git a/omci_state.go b/omci_state.go
index 23b0121..4050b22 100644
--- a/omci_state.go
+++ b/omci_state.go
@@ -21,13 +21,14 @@
 )
 
 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
-	state         istate
+	gemPortId         uint16
+	mibUploadCtr      uint16
+	extraMibUploadCtr uint16 //this is only for debug purposes, will be removed in the future
+	uniGInstance      uint8
+	tcontInstance     uint8
+	pptpInstance      uint8
+	priorQInstance    uint8 //To assign incrementing value to PQ instance-Id
+	state             istate
 }
 
 type istate int
@@ -43,7 +44,7 @@
 func NewOnuOmciState() *OnuOmciState {
 	return &OnuOmciState{gemPortId: 0, mibUploadCtr: 0, uniGInstance: 1, tcontInstance: 0, pptpInstance: 1}
 }
-func (s *OnuOmciState) ResetOnuOmciState(){
+func (s *OnuOmciState) ResetOnuOmciState() {
 	s.mibUploadCtr = 0
 	s.extraMibUploadCtr = 0
 	s.gemPortId = 0