[VOL-2451] Reporting UNI Link Up

Check if receiving PPTP sets for admin down or up
If so send a link up (oper up) or link down

Change-Id: I97f2885dc2bef5068b4b62f9e29df1cdd8df014f
diff --git a/VERSION b/VERSION
index 8acdd82..4e379d2 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-0.0.1
+0.0.2
diff --git a/omci_defs.go b/omci_defs.go
index 44347ef..d84e878 100644
--- a/omci_defs.go
+++ b/omci_defs.go
@@ -28,12 +28,16 @@
 type ChMessageType int
 
 const (
-	GemPortAdded ChMessageType = iota
+	GemPortAdded ChMessageType = 0
+	UniLinkUp ChMessageType = 1
+	UniLinkDown ChMessageType = 2
 )
 
 func (m ChMessageType) String() string {
 	names := [...]string{
 		"GemPortAdded",
+		"UniLinkUp",
+		"UniLinkDown",
 	}
 	return names[m]
 }
@@ -46,6 +50,7 @@
 type OmciChMessage struct {
 	Type ChMessageType
 	Data OmciChMessageData
+	Packet []byte
 }
 
 //
diff --git a/omci_sim.go b/omci_sim.go
index a792911..c971d54 100644
--- a/omci_sim.go
+++ b/omci_sim.go
@@ -21,7 +21,7 @@
 	log "github.com/sirupsen/logrus"
 )
 
-var omciCh = make(chan OmciChMessage)
+var omciCh = make(chan OmciChMessage, 4096)
 
 func GetChannel() chan OmciChMessage {
 	return omciCh
@@ -48,7 +48,7 @@
 		"MeInstance": instance,
 		//"Conent": content,
 		"omciMsg": fmt.Sprintf("%x", content),
-	}).Tracef("Processing OMCI pakcet")
+	}).Tracef("Processing OMCI packet")
 
 	key := OnuKey{intfId, onuId}
 	OnuOmciStateMapLock.Lock()
@@ -105,6 +105,62 @@
 		}
 	}
 
+	if (class == 11 && instance == 257 && msgType == Set) {
+		// This is a set on a PPTP instance 257 (lan port 1)
+		// Determine if its setting admin up or down and alarm appropriately
+
+		// attrmask for what specifically sets/gets is 2 bytes
+		attrmask := content[0:2]
+		// actual content is the rest, as specified by attrmask.  but for this case we are only interested in 1 byte
+		firstattr := content[2:3]
+
+		// attribute bit 5 (admin state) in the PPTP is being set, its value is 1, lock
+		if (attrmask[0] == 0x08 && firstattr[0] == 0x01) {
+			log.Info("Send UNI Link Down Alarm on OMCI Sim channel")
+
+			linkMsgDown := []byte{
+				0x00, 0x00, 0x10, 0x0a, 0x00, 0x0b, 0x01, 0x01,
+				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, 0x00, 0x00, 0x00, 0x00}
+
+			msg := OmciChMessage{
+				Type: UniLinkDown,
+				Data: OmciChMessageData{
+					OnuId:  key.OnuId,
+					IntfId: key.IntfId,
+				},
+				Packet: linkMsgDown,
+			}
+			omciCh <- msg
+		}
+
+		// attribute bit 5 (admin state) in the PPTP is being set, its value is 0, unlock
+		if (attrmask[0] == 0x08 && firstattr[0] == 0x00) {
+			log.Info("Send UNI Link Up Alarm on OMCI Sim channel")
+
+			linkMsgUp := []byte{
+				0x00, 0x00, 0x10, 0x0a, 0x00, 0x0b, 0x01, 0x01,
+				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, 0x00, 0x00, 0x00, 0x00, 0x00}
+
+			msg := OmciChMessage{
+				Type: UniLinkUp,
+				Data: OmciChMessageData{
+					OnuId:  key.OnuId,
+					IntfId: key.IntfId,
+				},
+				Packet: linkMsgUp,
+			}
+			omciCh <- msg
+		}
+	}
+
 	log.WithFields(log.Fields{
 		"IntfId": intfId,
 		"OnuId": onuId,