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;
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() + ".");
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;
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);
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) {
} 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];
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 + ".");
}