package org.opendaylight.protocol.pcep.impl.subobject;
import org.opendaylight.protocol.pcep.PCEPDeserializerException;
-import org.opendaylight.protocol.pcep.subobject.ExcludeRouteSubobject;
-import org.opendaylight.protocol.pcep.subobject.XROSRLGSubobject;
+import org.opendaylight.protocol.pcep.spi.XROSubobjectParser;
+import org.opendaylight.protocol.pcep.spi.XROSubobjectSerializer;
+import org.opendaylight.protocol.util.ByteArray;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.exclude.route.object.Subobjects;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.exclude.route.object.SubobjectsBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.ExcludeRouteSubobjects.Attribute;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.SrlgId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.SrlgSubobject;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.basic.explicit.route.subobjects.subobject.type.SrlgBuilder;
/**
- * Parser for {@link org.opendaylight.protocol.pcep.subobject. XROSRLGSubobject XROSRLGSubobject}
+ * Parser for {@link SrlgSubobject}
*/
-public class XROSRLGSubobjectParser {
+public class XROSRLGSubobjectParser implements XROSubobjectParser, XROSubobjectSerializer {
+
+ public static final int TYPE = 34;
+
public static final int SRLG_ID_NUMBER_LENGTH = 4;
public static final int ATTRIBUTE_LENGTH = 1;
public static final int CONTENT_LENGTH = ATTRIBUTE_OFFSET + ATTRIBUTE_LENGTH;
- public static XROSRLGSubobject parse(final byte[] soContentsBytes, final boolean mandatory) throws PCEPDeserializerException {
- if (soContentsBytes == null || soContentsBytes.length == 0)
+ @Override
+ public Subobjects parseSubobject(final byte[] buffer, final boolean mandatory) throws PCEPDeserializerException {
+ if (buffer == null || buffer.length == 0)
throw new IllegalArgumentException("Array of bytes is mandatory. Can't be null or empty.");
- if (soContentsBytes.length != CONTENT_LENGTH)
- throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + soContentsBytes.length + "; Expected: "
+ if (buffer.length != CONTENT_LENGTH)
+ throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.length + "; Expected: "
+ CONTENT_LENGTH + ".");
- // return new XROSRLGSubobject(new
- // SharedRiskLinkGroup(UnsignedInts.toLong(ByteArray.bytesToInt(ByteArray.subByte(soContentsBytes,
- // SRLG_ID_NUMBER_OFFSET,
- // SRLG_ID_NUMBER_LENGTH)))), mandatory);
- return null;
+ final SubobjectsBuilder builder = new SubobjectsBuilder();
+ builder.setMandatory(mandatory);
+ builder.setAttribute(Attribute.Srlg);
+ builder.setSubobjectType(new SrlgBuilder().setSrlgId(
+ new SrlgId(ByteArray.bytesToLong(ByteArray.subByte(buffer, SRLG_ID_NUMBER_OFFSET, SRLG_ID_NUMBER_LENGTH)))).build());
+ return builder.build();
}
- public static byte[] put(final ExcludeRouteSubobject objToSerialize) {
- if (!(objToSerialize instanceof XROSRLGSubobject))
- throw new IllegalArgumentException("Unknown PCEPXROSubobject instance. Passed " + objToSerialize.getClass()
- + ". Needed XROSRLGSubobject.");
+ @Override
+ public byte[] serializeSubobject(final Subobjects subobject) {
+ if (!(subobject.getSubobjectType() instanceof SrlgSubobject))
+ throw new IllegalArgumentException("Unknown PCEPXROSubobject instance. Passed " + subobject.getSubobjectType().getClass()
+ + ". Needed SrlgSubobject.");
byte[] retBytes;
retBytes = new byte[CONTENT_LENGTH];
- final XROSRLGSubobject specObj = (XROSRLGSubobject) objToSerialize;
+ final SrlgSubobject specObj = (SrlgSubobject) subobject.getSubobjectType();
- // ByteArray.copyWhole(ByteArray.intToBytes((int) specObj.getSrlgId().getValue()), retBytes,
- // SRLG_ID_NUMBER_OFFSET);
- retBytes[ATTRIBUTE_OFFSET] = (byte) XROSubobjectAttributeMapping.getInstance().getFromAttributeEnum(specObj.getAttribute());
+ ByteArray.copyWhole(ByteArray.longToBytes(specObj.getSrlgId().getValue()), retBytes, SRLG_ID_NUMBER_OFFSET);
+ retBytes[ATTRIBUTE_OFFSET] = (byte) subobject.getAttribute().getIntValue();
return retBytes;
}
+
+ @Override
+ public int getType() {
+ return TYPE;
+ }
}