BUG-47: more subobject models
[bgpcep.git] / pcep / impl / src / main / java / org / opendaylight / protocol / pcep / impl / PCEPEROSubobjectParser.java
index 721cd98628c2bba8c536e7d9b5214c1a72e5159f..3632dcda1a246c9fc374ff65375c0ec8a30414c5 100644 (file)
@@ -10,22 +10,17 @@ package org.opendaylight.protocol.pcep.impl;
 import java.util.ArrayList;
 import java.util.List;
 
-import org.opendaylight.protocol.concepts.IPv4Prefix;
-import org.opendaylight.protocol.concepts.IPv6Prefix;
 import org.opendaylight.protocol.pcep.PCEPDeserializerException;
 import org.opendaylight.protocol.pcep.impl.subobject.EROExplicitExclusionRouteSubobjectParser;
 import org.opendaylight.protocol.pcep.impl.subobject.EROLabelSubobjectParser;
 import org.opendaylight.protocol.pcep.impl.subobject.EROPathKeyWith128PCEIDSubobjectParser;
 import org.opendaylight.protocol.pcep.impl.subobject.EROPathKeyWith32PCEIDSubobjectParser;
-import org.opendaylight.protocol.pcep.impl.subobject.EROProtectionSubobjectParser;
 import org.opendaylight.protocol.pcep.impl.subobject.EROUnnumberedInterfaceSubobjectParser;
 import org.opendaylight.protocol.pcep.subobject.EROAsNumberSubobject;
 import org.opendaylight.protocol.pcep.subobject.EROExplicitExclusionRouteSubobject;
-import org.opendaylight.protocol.pcep.subobject.EROIPPrefixSubobject;
 import org.opendaylight.protocol.pcep.subobject.EROLabelSubobject;
 import org.opendaylight.protocol.pcep.subobject.EROPathKeyWith128PCEIDSubobject;
 import org.opendaylight.protocol.pcep.subobject.EROPathKeyWith32PCEIDSubobject;
-import org.opendaylight.protocol.pcep.subobject.EROProtectionSubobject;
 import org.opendaylight.protocol.pcep.subobject.EROUnnumberedInterfaceSubobject;
 import org.opendaylight.protocol.pcep.subobject.ExplicitRouteSubobject;
 import org.opendaylight.protocol.util.ByteArray;
@@ -58,8 +53,9 @@ public class PCEPEROSubobjectParser {
                public static PCEPSubobjectType getFromInt(final int type) throws PCEPDeserializerException {
 
                        for (final PCEPSubobjectType type_e : PCEPSubobjectType.values()) {
-                               if (type_e.getIndicator() == type)
+                               if (type_e.getIndicator() == type) {
                                        return type_e;
+                               }
                        }
 
                        throw new PCEPDeserializerException("Unknown Subobject type. Passed: " + type + "; Known: " + PCEPSubobjectType.values() + ".");
@@ -80,8 +76,9 @@ public class PCEPEROSubobjectParser {
        public static final int SO_CONTENTS_OFFSET = LENGTH_F_OFFSET + LENGTH_F_LENGTH;
 
        public static List<ExplicitRouteSubobject> parse(final byte[] bytes) throws PCEPDeserializerException {
-               if (bytes == null)
+               if (bytes == null) {
                        throw new IllegalArgumentException("Byte array is mandatory.");
+               }
 
                final List<ExplicitRouteSubobject> subobjsList = new ArrayList<ExplicitRouteSubobject>();
                boolean loose_flag;
@@ -97,9 +94,10 @@ public class PCEPEROSubobjectParser {
 
                        type = PCEPSubobjectType.getFromInt((bytes[offset + TYPE_FLAG_F_OFFSET] & 0xff) & ~(1 << 7));
 
-                       if (length > bytes.length - offset)
+                       if (length > bytes.length - offset) {
                                throw new PCEPDeserializerException("Wrong length specified. Passed: " + length + "; Expected: <= "
                                                + (bytes.length - offset));
+                       }
 
                        soContentsBytes = new byte[length - SO_CONTENTS_OFFSET];
                        System.arraycopy(bytes, offset + SO_CONTENTS_OFFSET, soContentsBytes, 0, length - SO_CONTENTS_OFFSET);
@@ -142,15 +140,16 @@ public class PCEPEROSubobjectParser {
 
                byte[] soContentsBytes = null;
 
-               if (objToSerialize instanceof EROIPPrefixSubobject<?>
-                               && ((EROIPPrefixSubobject<?>) objToSerialize).getPrefix() instanceof IPv4Prefix) {
-                       typeIndicator = PCEPSubobjectType.IPv4_PREFIX.getIndicator();
-                       // soContentsBytes = EROIpPrefixSubobjectParser.put(objToSerialize);
-               } else if (objToSerialize instanceof EROIPPrefixSubobject<?>
-                               && ((EROIPPrefixSubobject<?>) objToSerialize).getPrefix() instanceof IPv6Prefix) {
-                       typeIndicator = PCEPSubobjectType.IPv6_PREFIX.getIndicator();
-                       // soContentsBytes = EROIPv6PrefixSubobjectParser.put(objToSerialize);
-               } else if (objToSerialize instanceof EROAsNumberSubobject) {
+               // if (objToSerialize instanceof EROIPPrefixSubobject<?>
+               // && ((EROIPPrefixSubobject<?>) objToSerialize).getPrefix() instanceof IPv4Prefix) {
+               // typeIndicator = PCEPSubobjectType.IPv4_PREFIX.getIndicator();
+               // // soContentsBytes = EROIpPrefixSubobjectParser.put(objToSerialize);
+               // } else if (objToSerialize instanceof EROIPPrefixSubobject<?>
+               // && ((EROIPPrefixSubobject<?>) objToSerialize).getPrefix() instanceof IPv6Prefix) {
+               // typeIndicator = PCEPSubobjectType.IPv6_PREFIX.getIndicator();
+               // // soContentsBytes = EROIPv6PrefixSubobjectParser.put(objToSerialize);
+               // } else
+               if (objToSerialize instanceof EROAsNumberSubobject) {
                        typeIndicator = PCEPSubobjectType.AS_NUMBER.getIndicator();
                        // soContentsBytes = EROAsNumberSubobjectParser.put(objToSerialize);
                } else if (objToSerialize instanceof EROUnnumberedInterfaceSubobject) {
@@ -168,11 +167,9 @@ public class PCEPEROSubobjectParser {
                } else if (objToSerialize instanceof EROPathKeyWith128PCEIDSubobject) {
                        typeIndicator = PCEPSubobjectType.PK_128.getIndicator();
                        soContentsBytes = EROPathKeyWith128PCEIDSubobjectParser.put((EROPathKeyWith128PCEIDSubobject) objToSerialize);
-               } else if (objToSerialize instanceof EROProtectionSubobject) {
-                       typeIndicator = PCEPSubobjectType.PROTECTION.getIndicator();
-                       soContentsBytes = EROProtectionSubobjectParser.put((EROProtectionSubobject) objToSerialize);
-               } else
+               } else {
                        throw new IllegalArgumentException("Unknown instance of PCEPSubobject. Passed: " + objToSerialize.getClass() + ".");
+               }
 
                final byte[] bytes = new byte[SO_CONTENTS_OFFSET + soContentsBytes.length];
 
@@ -206,8 +203,6 @@ public class PCEPEROSubobjectParser {
                        return EROPathKeyWith32PCEIDSubobjectParser.parse(soContentsBytes, loose_flag);
                case PK_128:
                        return EROPathKeyWith128PCEIDSubobjectParser.parse(soContentsBytes, loose_flag);
-               case PROTECTION:
-                       return EROProtectionSubobjectParser.parse(soContentsBytes, loose_flag);
                default:
                        throw new PCEPDeserializerException("Unknown Subobject type. Passed: " + type + ".");
                }