PCEP modificaton to support PCEP-LS

Change-Id: Ic829dd17b0398ad76ec412b4e8293de564b5b56b
diff --git a/protocols/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepMessageVer1.java b/protocols/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepMessageVer1.java
index 2169a67..5e4db6c 100644
--- a/protocols/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepMessageVer1.java
+++ b/protocols/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepMessageVer1.java
@@ -17,10 +17,12 @@
 package org.onosproject.pcepio.protocol.ver1;
 
 import org.jboss.netty.buffer.ChannelBuffer;
+import org.onosproject.pcepio.exceptions.PcepOutOfBoundMessageException;
 import org.onosproject.pcepio.exceptions.PcepParseException;
 import org.onosproject.pcepio.protocol.PcepFactories;
 import org.onosproject.pcepio.protocol.PcepMessage;
 import org.onosproject.pcepio.protocol.PcepMessageReader;
+import org.onosproject.pcepio.protocol.PcepType;
 import org.onosproject.pcepio.types.PcepErrorDetailInfo;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -33,21 +35,11 @@
     protected static final Logger log = LoggerFactory.getLogger(PcepFactories.class);
 
     // version: 1.0
-    static final byte WIRE_VERSION = 1;
-    static final int MINIMUM_LENGTH = 4;
-    static final int PACKET_VERSION = 1;
-    static final byte OPEN_MSG_TYPE = 0x1;
-    static final byte KEEPALIVE_MSG_TYPE = 0x2;
-    static final byte REPORT_MSG_TYPE = 0xa;
-    static final byte TE_REPORT_MSG_TYPE = 0xe;
-    static final byte UPDATE_MSG_TYPE = 0xb;
-    static final byte INITIATE_MSG_TYPE = 0xc;
-    static final byte CLOSE_MSG_TYPE = 0x7;
-    static final byte ERROR_MSG_TYPE = 0x6;
-    static final byte LABEL_UPDATE_MSG_TYPE = 0xD;
-    static final byte LABEL_RANGE_RESV_MSG_TYPE = 0xF;
+    public static final byte WIRE_VERSION = 1;
+    public static final int MINIMUM_LENGTH = 4;
+    public static final int PACKET_VERSION = 1;
     public static final int SHIFT_FLAG = 5;
-    static final int MINIMUM_COMMON_HEADER_LENGTH = 4;
+    public static final int MINIMUM_COMMON_HEADER_LENGTH = 4;
 
     public static final PcepMessageVer1.Reader READER = new Reader();
 
@@ -56,7 +48,7 @@
      */
     static class Reader implements PcepMessageReader<PcepMessage> {
         @Override
-        public PcepMessage readFrom(ChannelBuffer cb) throws PcepParseException {
+        public PcepMessage readFrom(ChannelBuffer cb) throws PcepParseException, PcepOutOfBoundMessageException {
 
             if (cb.readableBytes() < MINIMUM_LENGTH) {
                 throw new PcepParseException("Packet should have minimum length: " + MINIMUM_LENGTH);
@@ -75,53 +67,43 @@
                 short length = cb.readShort();
                 cb.readerIndex(start);
 
-                switch (type) {
+                // Check the out-of-bound message.
+                // If the message is out-of-bound then throw PcepOutOfBoundException.
+                if ((length - MINIMUM_COMMON_HEADER_LENGTH) > cb.readableBytes()) {
+                    throw new PcepOutOfBoundMessageException("Message is out-of-bound.");
+                }
 
-                case OPEN_MSG_TYPE:
+                if (type == (byte) PcepType.OPEN.getType()) {
                     log.debug("OPEN MESSAGE is received");
-                    // message type value 1 means it is open message
                     return PcepOpenMsgVer1.READER.readFrom(cb.readBytes(length));
-                case KEEPALIVE_MSG_TYPE:
+                } else if (type == (byte) PcepType.KEEP_ALIVE.getType()) {
                     log.debug("KEEPALIVE MESSAGE is received");
-                    // message type value 2 means it is Keepalive message
                     return PcepKeepaliveMsgVer1.READER.readFrom(cb.readBytes(length));
-                case ERROR_MSG_TYPE:
+                } else if (type == (byte) PcepType.ERROR.getType()) {
                     log.debug("ERROR MESSAGE is received");
-                    // message type value 6 means it is error message
                     return PcepErrorMsgVer1.READER.readFrom(cb.readBytes(length));
-                case REPORT_MSG_TYPE:
-                    log.debug("REPORT MESSAGE is received");
-                    // message type value 10 means it is Report message
-                    // return
-                    return PcepReportMsgVer1.READER.readFrom(cb.readBytes(length));
-                case UPDATE_MSG_TYPE:
-                    log.debug("UPDATE MESSAGE is received");
-                    //message type value 11 means it is Update message
-                    return PcepUpdateMsgVer1.READER.readFrom(cb.readBytes(length));
-                case INITIATE_MSG_TYPE:
-                    log.debug("INITIATE MESSAGE is received");
-                    //message type value 12 means it is PcInitiate message
-                    return PcepInitiateMsgVer1.READER.readFrom(cb.readBytes(length));
-                case CLOSE_MSG_TYPE:
+                } else if (type == (byte) PcepType.CLOSE.getType()) {
                     log.debug("CLOSE MESSAGE is received");
-                    // message type value 7 means it is Close message
                     return PcepCloseMsgVer1.READER.readFrom(cb.readBytes(length));
-                case TE_REPORT_MSG_TYPE:
-                    log.debug("TE REPORT MESSAGE is received");
-                    // message type value 14 means it is TE REPORT message
-                    // return
-                    return PcepTEReportMsgVer1.READER.readFrom(cb.readBytes(length));
-                case LABEL_UPDATE_MSG_TYPE:
-                    log.debug("LABEL UPDATE MESSAGE is received");
-                    // message type value 13 means it is LABEL UPDATE message
-                    // return
-                    return PcepLabelUpdateMsgVer1.READER.readFrom(cb.readBytes(length));
-                case LABEL_RANGE_RESV_MSG_TYPE:
+                } else if (type == (byte) PcepType.REPORT.getType()) {
+                    log.debug("REPORT MESSAGE is received");
+                    return PcepReportMsgVer1.READER.readFrom(cb.readBytes(length));
+                } else if (type == (byte) PcepType.UPDATE.getType()) {
+                    log.debug("UPDATE MESSAGE is received");
+                    return PcepUpdateMsgVer1.READER.readFrom(cb.readBytes(length));
+                } else if (type == (byte) PcepType.INITIATE.getType()) {
+                    log.debug("INITIATE MESSAGE is received");
+                    return PcepInitiateMsgVer1.READER.readFrom(cb.readBytes(length));
+                } else if (type == (byte) PcepType.LS_REPORT.getType()) {
+                    log.debug("LS REPORT MESSAGE is received");
+                    return PcepLSReportMsgVer1.READER.readFrom(cb.readBytes(length));
+                } else if (type == (byte) PcepType.LABEL_RANGE_RESERV.getType()) {
                     log.debug("LABEL RANGE RESERVE MESSAGE is received");
-                    // message type value 15 means it is LABEL RANGE RESERVE message
-                    // return
                     return PcepLabelRangeResvMsgVer1.READER.readFrom(cb.readBytes(length));
-                default:
+                } else if (type == (byte) PcepType.LABEL_UPDATE.getType()) {
+                    log.debug("LABEL UPDATE MESSAGE is received");
+                    return PcepLabelUpdateMsgVer1.READER.readFrom(cb.readBytes(length));
+                } else {
                     throw new PcepParseException("ERROR: UNKNOWN MESSAGE is received. Msg Type: " + type);
                 }
             } catch (IndexOutOfBoundsException e) {