X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=pcep%2Fimpl%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fprotocol%2Fpcep%2Fimpl%2Fsubobject%2FEROAsNumberSubobjectParser.java;h=60d14e968031bf766ca0d376bd8cb9ced4e2fbb2;hb=e47c73b73d01011798a032632f22006119d5847e;hp=7ef9fe05c8f5ad1c2c9b9a5e8f3c2ae29d52c4ba;hpb=ce6991a8596c022555b003e128077a8f5468ec5e;p=bgpcep.git diff --git a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/subobject/EROAsNumberSubobjectParser.java b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/subobject/EROAsNumberSubobjectParser.java index 7ef9fe05c8..60d14e9680 100644 --- a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/subobject/EROAsNumberSubobjectParser.java +++ b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/subobject/EROAsNumberSubobjectParser.java @@ -8,53 +8,42 @@ package org.opendaylight.protocol.pcep.impl.subobject; import org.opendaylight.protocol.pcep.PCEPDeserializerException; -import org.opendaylight.protocol.pcep.spi.SubobjectParser; -import org.opendaylight.protocol.pcep.spi.SubobjectSerializer; +import org.opendaylight.protocol.pcep.subobject.EROAsNumberSubobject; +import org.opendaylight.protocol.pcep.subobject.ExplicitRouteSubobject; import org.opendaylight.protocol.util.ByteArray; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.AsNumber; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.AsNumberSubobject; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.CSubobject; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.route.subobjects.subobject.type.AsNumberBuilder; /** - * Parser for {@link AsNumberSubobject} + * Parser for {@link org.opendaylight.protocol.pcep.subobject.EROAsNumberSubobject EROAsNumberSubobject} */ -public class EROAsNumberSubobjectParser implements SubobjectParser, SubobjectSerializer { - - public static final int TYPE = 32; - - public static final int AS_NUMBER_LENGTH = 4; +public class EROAsNumberSubobjectParser { + public static final int AS_NUMBER_LENGTH = 2; public static final int AS_NUMBER_OFFSET = 0; public static final int CONTENT_LENGTH = AS_NUMBER_LENGTH + AS_NUMBER_OFFSET; - public AsNumberSubobject parseSubobject(byte[] buffer) throws PCEPDeserializerException { - if (buffer == null || buffer.length == 0) + public static EROAsNumberSubobject parse(final byte[] soContentsBytes, final boolean loose) throws PCEPDeserializerException { + if (soContentsBytes == null || soContentsBytes.length == 0) throw new IllegalArgumentException("Array of bytes is mandatory. Can't be null or empty."); - if (buffer.length != CONTENT_LENGTH) - throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.length + "; Expected: " + if (soContentsBytes.length != CONTENT_LENGTH) + throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + soContentsBytes.length + "; Expected: " + CONTENT_LENGTH + "."); - return new AsNumberBuilder().setAsNumber(new AsNumber(ByteArray.bytesToLong(buffer))).build(); + return new EROAsNumberSubobject(new AsNumber((long) (ByteArray.bytesToShort(soContentsBytes) & 0xFFFF)), loose); } - public byte[] serializeSubobject(CSubobject subobject) { - if (!(subobject instanceof AsNumberSubobject)) - throw new IllegalArgumentException("Unknown subobject instance. Passed " + subobject.getClass() - + ". Needed AsNumberSubobject."); + public static byte[] put(final ExplicitRouteSubobject objToSerialize) { + if (!(objToSerialize instanceof EROAsNumberSubobject)) + throw new IllegalArgumentException("Unknown ExplicitRouteSubobject instance. Passed " + objToSerialize.getClass() + + ". Needed EROAsNumberSubobject."); final byte[] retBytes = new byte[CONTENT_LENGTH]; - System.arraycopy(ByteArray.longToBytes(((AsNumberSubobject) subobject).getAsNumber().getValue()), Long.SIZE / Byte.SIZE + System.arraycopy(ByteArray.longToBytes(((EROAsNumberSubobject) objToSerialize).getASNumber().getValue()), Long.SIZE / Byte.SIZE - AS_NUMBER_LENGTH, retBytes, AS_NUMBER_OFFSET, AS_NUMBER_LENGTH); return retBytes; } - - @Override - public int getType() { - return TYPE; - } }