Bug 9127: Make IT more robust when receiving packets
[lispflowmapping.git] / mappingservice / lisp-proto / src / main / java / org / opendaylight / lispflowmapping / lisp / serializer / MapNotifySerializer.java
index c039752f8ea194430e67c0efd12de9072253083e..24a2c709c4c00b1308dfe8a15d15ebfb257515ab 100644 (file)
@@ -87,10 +87,15 @@ public final class MapNotifySerializer {
     @SuppressWarnings("checkstyle:IllegalCatch")
     public MapNotify deserialize(ByteBuffer notifyBuffer) {
         try {
+            final byte typeAndFlags = notifyBuffer.get();
+            final int type = typeAndFlags >> 4;
+            if (MessageType.forValue(type) != MessageType.MapNotify) {
+                throw new LispSerializationException("Expected Map-Notify packet (type 4), but was type " + type);
+            }
+
             MapNotifyBuilder builder = new MapNotifyBuilder();
             builder.setMappingRecordItem(new ArrayList<MappingRecordItem>());
 
-            byte typeAndFlags = notifyBuffer.get();
             boolean xtrSiteIdPresent = ByteUtil.extractBit(typeAndFlags, Flags.XTRSITEID);
             builder.setXtrSiteIdPresent(xtrSiteIdPresent);