uses object;
list subobjects {
- uses rsvp:record-route-subobjects;
+ uses rsvp:record-route-subobjects {
+ augment "subobject-type" {
+ case path-key {
+ container path-key {
+ uses path-key-subobject;
+ }
+ }
+ }
+ }
}
}
import org.opendaylight.protocol.pcep.impl.subobject.EROUnnumberedInterfaceSubobjectParser;
import org.opendaylight.protocol.pcep.impl.subobject.GeneralizedLabelChannelSetParser;
import org.opendaylight.protocol.pcep.impl.subobject.GeneralizedLabelParser;
-import org.opendaylight.protocol.pcep.impl.subobject.RROAsNumberSubobjectParser;
import org.opendaylight.protocol.pcep.impl.subobject.RROIpPrefixSubobjectParser;
import org.opendaylight.protocol.pcep.impl.subobject.RROLabelSubobjectParser;
import org.opendaylight.protocol.pcep.impl.subobject.RROPathKeySubobjectParser;
context.registerRROSubobjectParser(RROIpPrefixSubobjectParser.TYPE, new RROIpPrefixSubobjectParser());
context.registerRROSubobjectParser(RROIpPrefixSubobjectParser.TYPE6, new RROIpPrefixSubobjectParser());
context.registerRROSubobjectParser(RROLabelSubobjectParser.TYPE, new RROLabelSubobjectParser(labelReg));
- context.registerRROSubobjectParser(RROAsNumberSubobjectParser.TYPE, new RROAsNumberSubobjectParser());
context.registerRROSubobjectParser(RROUnnumberedInterfaceSubobjectParser.TYPE, new RROUnnumberedInterfaceSubobjectParser());
context.registerRROSubobjectParser(RROPathKeySubobjectParser.TYPE, new RROPathKeySubobjectParser());
context.registerRROSubobjectParser(RROPathKeySubobjectParser.TYPE128, new RROPathKeySubobjectParser());
context.registerRROSubobjectSerializer(IpPrefixSubobject.class, new RROIpPrefixSubobjectParser());
context.registerRROSubobjectSerializer(LabelSubobject.class, new RROLabelSubobjectParser(labelReg));
- context.registerRROSubobjectSerializer(AsNumberSubobject.class, new RROAsNumberSubobjectParser());
context.registerRROSubobjectSerializer(UnnumberedSubobject.class, new RROUnnumberedInterfaceSubobjectParser());
context.registerRROSubobjectSerializer(PathKeySubobject.class, new RROPathKeySubobjectParser());
+++ /dev/null
-/*
- * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.protocol.pcep.impl.subobject;
-
-import org.opendaylight.protocol.pcep.PCEPDeserializerException;
-import org.opendaylight.protocol.pcep.spi.RROSubobjectParser;
-import org.opendaylight.protocol.pcep.spi.RROSubobjectSerializer;
-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.pcep.types.rev131005.reported.route.object.Subobjects;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reported.route.object.SubobjectsBuilder;
-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.basic.explicit.route.subobjects.subobject.type.AsNumberBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.record.route.subobjects.SubobjectType;
-
-/**
- * Parser for {@link org.opendaylight.protocol.pcep.subobject.RROAsNumberSubobject RROAsNumberSubobject}
- */
-
-public class RROAsNumberSubobjectParser implements RROSubobjectParser, RROSubobjectSerializer {
-
- public static final int TYPE = 32;
-
- 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;
-
- @Override
- public Subobjects parseSubobject(final byte[] buffer) throws PCEPDeserializerException {
- if (buffer == null || buffer.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: "
- + CONTENT_LENGTH + ".");
-
- return new SubobjectsBuilder().setSubobjectType(
- (SubobjectType) new AsNumberBuilder().setAsNumber(new AsNumber(ByteArray.bytesToLong(buffer))).build()).build();
- }
-
- @Override
- public byte[] serializeSubobject(final Subobjects subobject) {
- if (!(subobject.getSubobjectType() instanceof AsNumberSubobject))
- throw new IllegalArgumentException("Unknown ReportedRouteSubobject instance. Passed " + subobject.getSubobjectType().getClass()
- + ". Needed AsNumberSubobject.");
-
- final byte[] retBytes = new byte[CONTENT_LENGTH];
-
- final AsNumberSubobject obj = (AsNumberSubobject) subobject.getSubobjectType();
-
- System.arraycopy(ByteArray.longToBytes(obj.getAsNumber().getValue()), Long.SIZE / Byte.SIZE - AS_NUMBER_LENGTH, retBytes,
- AS_NUMBER_OFFSET, AS_NUMBER_LENGTH);
-
- return retBytes;
- }
-
- @Override
- public int getType() {
- return TYPE;
- }
-}
import java.util.BitSet;
import org.opendaylight.protocol.concepts.Ipv4Util;
+import org.opendaylight.protocol.concepts.Ipv6Util;
import org.opendaylight.protocol.pcep.PCEPDeserializerException;
import org.opendaylight.protocol.pcep.spi.RROSubobjectParser;
import org.opendaylight.protocol.pcep.spi.RROSubobjectSerializer;
public static final int TYPE6 = 2;
- public static final int IP4_F_LENGTH = 4;
- public static final int PREFIX4_F_LENGTH = 1;
- public static final int FLAGS4_F_LENGTH = 1;
+ private static final int IP4_F_LENGTH = 4;
+ private static final int IP_F_LENGTH = 16;
- public static final int IP4_F_OFFSET = 0;
- public static final int PREFIX4_F_OFFSET = IP4_F_OFFSET + IP4_F_LENGTH;
- public static final int FLAGS4_F_OFFSET = PREFIX4_F_OFFSET + PREFIX4_F_LENGTH;
+ private static final int PREFIX_F_LENGTH = 1;
+ private static final int FLAGS_F_LENGTH = 1;
- public static final int CONTENT4_LENGTH = FLAGS4_F_OFFSET + FLAGS4_F_LENGTH;
+ private static final int IP_F_OFFSET = 0;
- public static final int IP_F_LENGTH = 16;
- public static final int PREFIX_F_LENGTH = 1;
- public static final int FLAGS_F_LENGTH = 1;
+ private static final int PREFIX4_F_OFFSET = IP_F_OFFSET + IP4_F_LENGTH;
+ private static final int FLAGS4_F_OFFSET = PREFIX4_F_OFFSET + PREFIX_F_LENGTH;
- public static final int IP_F_OFFSET = 0;
- public static final int PREFIX_F_OFFSET = IP_F_OFFSET + IP_F_LENGTH;
- public static final int FLAGS_F_OFFSET = PREFIX_F_OFFSET + PREFIX_F_LENGTH;
+ private static final int CONTENT4_LENGTH = IP4_F_LENGTH + PREFIX_F_LENGTH + FLAGS_F_LENGTH;
- public static final int CONTENT_LENGTH = FLAGS_F_OFFSET + FLAGS_F_LENGTH;
+ private static final int PREFIX_F_OFFSET = IP_F_OFFSET + IP_F_LENGTH;
+ private static final int FLAGS_F_OFFSET = PREFIX_F_OFFSET + PREFIX_F_LENGTH;
- /*
- * flags offset in bits
- */
- public static final int LPA_F_OFFSET = 7;
- public static final int LPIU_F_OFFSET = 6;
+ private static final int CONTENT_LENGTH = IP_F_LENGTH + PREFIX_F_LENGTH + FLAGS_F_LENGTH;
+
+ private static final int LPA_F_OFFSET = 7;
+ private static final int LPIU_F_OFFSET = 6;
@Override
public Subobjects parseSubobject(final byte[] buffer) throws PCEPDeserializerException {
- if (buffer == null || buffer.length == 0)
+ if (buffer == null || buffer.length == 0) {
throw new IllegalArgumentException("Array of bytes is mandatory. Can't be null or empty.");
- if (buffer.length != CONTENT4_LENGTH || buffer.length != CONTENT_LENGTH)
- throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.length + ";");
-
- final int length = UnsignedBytes.toInt(buffer[PREFIX4_F_OFFSET]);
-
- final BitSet flags = ByteArray.bytesToBitSet(Arrays.copyOfRange(buffer, FLAGS4_F_OFFSET, FLAGS4_F_OFFSET + FLAGS4_F_LENGTH));
-
+ }
final SubobjectsBuilder builder = new SubobjectsBuilder();
- builder.setProtectionAvailable(flags.get(LPA_F_OFFSET));
- builder.setProtectionInUse(flags.get(LPIU_F_OFFSET));
- builder.setSubobjectType(new IpPrefixBuilder().setIpPrefix(
- new IpPrefix(Ipv4Util.prefixForBytes(ByteArray.subByte(buffer, IP4_F_OFFSET, IP4_F_LENGTH), length))).build());
-
+ if (buffer.length == CONTENT4_LENGTH) {
+ final int length = UnsignedBytes.toInt(buffer[PREFIX4_F_OFFSET]);
+ final BitSet flags = ByteArray.bytesToBitSet(Arrays.copyOfRange(buffer, FLAGS4_F_OFFSET, FLAGS4_F_OFFSET + FLAGS_F_LENGTH));
+ builder.setProtectionAvailable(flags.get(LPA_F_OFFSET));
+ builder.setProtectionInUse(flags.get(LPIU_F_OFFSET));
+ builder.setSubobjectType(new IpPrefixBuilder().setIpPrefix(
+ new IpPrefix(Ipv4Util.prefixForBytes(ByteArray.subByte(buffer, IP_F_OFFSET, IP4_F_LENGTH), length))).build());
+ } else if (buffer.length == CONTENT_LENGTH) {
+ final int length = UnsignedBytes.toInt(buffer[PREFIX_F_OFFSET]);
+ final BitSet flags = ByteArray.bytesToBitSet(Arrays.copyOfRange(buffer, FLAGS_F_OFFSET, FLAGS_F_OFFSET + FLAGS_F_LENGTH));
+ builder.setProtectionAvailable(flags.get(LPA_F_OFFSET));
+ builder.setProtectionInUse(flags.get(LPIU_F_OFFSET));
+ builder.setSubobjectType(new IpPrefixBuilder().setIpPrefix(
+ new IpPrefix(Ipv6Util.prefixForBytes(ByteArray.subByte(buffer, IP_F_OFFSET, IP_F_LENGTH), length))).build());
+ } else {
+ throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.length + ";");
+ }
return builder.build();
}
@Override
public byte[] serializeSubobject(final Subobjects subobject) {
- if (!(subobject instanceof IpPrefixSubobject))
+ if (!(subobject.getSubobjectType() instanceof IpPrefixSubobject)) {
throw new IllegalArgumentException("Unknown ReportedRouteSubobject instance. Passed " + subobject.getClass()
+ ". Needed RROIPAddressSubobject.");
+ }
- final IpPrefixSubobject specObj = (IpPrefixSubobject) subobject;
+ final IpPrefixSubobject specObj = (IpPrefixSubobject) subobject.getSubobjectType();
final IpPrefix prefix = specObj.getIpPrefix();
- if (prefix.getIpv4Prefix() == null && prefix.getIpv6Prefix() == null)
+ if (prefix.getIpv4Prefix() == null && prefix.getIpv6Prefix() == null) {
throw new IllegalArgumentException("Unknown AbstractPrefix instance. Passed " + prefix.getClass() + ".");
+ }
- final BitSet flags = new BitSet(FLAGS4_F_LENGTH * Byte.SIZE);
-
+ final BitSet flags = new BitSet(FLAGS_F_LENGTH * Byte.SIZE);
flags.set(LPA_F_OFFSET, subobject.isProtectionAvailable());
flags.set(LPIU_F_OFFSET, subobject.isProtectionInUse());
- final byte[] retBytes = new byte[CONTENT4_LENGTH];
-
if (prefix.getIpv4Prefix() != null) {
- ByteArray.copyWhole(prefix.getIpv4Prefix().getValue().getBytes(), retBytes, IP4_F_OFFSET);
- retBytes[PREFIX4_F_OFFSET] = ByteArray.intToBytes(Ipv4Util.getPrefixLength(prefix))[Integer.SIZE / Byte.SIZE - 1];
- ByteArray.copyWhole(ByteArray.bitSetToBytes(flags, FLAGS4_F_LENGTH), retBytes, FLAGS4_F_OFFSET);
+ final byte[] retBytes = new byte[CONTENT4_LENGTH];
+ ByteArray.copyWhole(Ipv4Util.bytesForPrefix(prefix.getIpv4Prefix()), retBytes, IP_F_OFFSET);
+ retBytes[PREFIX4_F_OFFSET] = UnsignedBytes.checkedCast(Ipv4Util.getPrefixLength(prefix));
+ ByteArray.copyWhole(ByteArray.bitSetToBytes(flags, FLAGS_F_LENGTH), retBytes, FLAGS4_F_OFFSET);
+ return retBytes;
} else {
- ByteArray.copyWhole(prefix.getIpv6Prefix().getValue().getBytes(), retBytes, IP_F_OFFSET);
- retBytes[PREFIX_F_OFFSET] = ByteArray.intToBytes(Ipv4Util.getPrefixLength(prefix))[Integer.SIZE / Byte.SIZE - 1];
+ final byte[] retBytes = new byte[CONTENT_LENGTH];
+ ByteArray.copyWhole(Ipv6Util.bytesForPrefix(prefix.getIpv6Prefix()), retBytes, IP_F_OFFSET);
+ retBytes[PREFIX_F_OFFSET] = UnsignedBytes.checkedCast(Ipv4Util.getPrefixLength(prefix));
ByteArray.copyWhole(ByteArray.bitSetToBytes(flags, FLAGS_F_LENGTH), retBytes, FLAGS_F_OFFSET);
+ return retBytes;
}
- return retBytes;
}
@Override
import org.opendaylight.protocol.pcep.spi.RROSubobjectParser;
import org.opendaylight.protocol.pcep.spi.RROSubobjectSerializer;
import org.opendaylight.protocol.util.ByteArray;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.PathKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.PceId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reported.route.object.Subobjects;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reported.route.object.SubobjectsBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reported.route.object.subobjects.subobject.type.PathKeyBuilder;
public class RROPathKeySubobjectParser implements RROSubobjectParser, RROSubobjectSerializer {
public static final int TYPE128 = 65;
- public static final int PK_F_LENGTH = 2;
- public static final int PCE_ID_F_LENGTH = 4;
+ private static final int PK_F_LENGTH = 2;
+ private static final int PCE_ID_F_LENGTH = 4;
- public static final int PCE128_ID_F_LENGTH = 16;
+ private static final int PCE128_ID_F_LENGTH = 16;
- public static final int PK_F_OFFSET = 0;
- public static final int PCE_ID_F_OFFSET = PK_F_OFFSET + PK_F_LENGTH;
+ private static final int PK_F_OFFSET = 0;
+ private static final int PCE_ID_F_OFFSET = PK_F_OFFSET + PK_F_LENGTH;
- public static final int CONTENT_LENGTH = PCE_ID_F_OFFSET + PCE_ID_F_LENGTH;
+ private static final int CONTENT_LENGTH = PCE_ID_F_OFFSET + PCE_ID_F_LENGTH;
+ private static final int CONTENT128_LENGTH = PCE_ID_F_OFFSET + PCE128_ID_F_LENGTH;
@Override
public Subobjects parseSubobject(final byte[] buffer) throws PCEPDeserializerException {
- if (buffer == null || buffer.length == 0)
+ if (buffer == null || buffer.length == 0) {
throw new IllegalArgumentException("Array of bytes is mandatory. Can't be null or empty.");
- if (buffer.length != CONTENT_LENGTH)
+ }
+ byte[] pceId = null;
+ if (buffer.length == CONTENT_LENGTH) {
+ pceId = Arrays.copyOfRange(buffer, PCE_ID_F_OFFSET, CONTENT_LENGTH);
+ } else if (buffer.length == CONTENT128_LENGTH) {
+ pceId = Arrays.copyOfRange(buffer, PCE_ID_F_OFFSET, CONTENT128_LENGTH);
+ } else {
throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.length + "; Expected: >"
+ CONTENT_LENGTH + ".");
-
- final int pathKey = ByteArray.bytesToShort(Arrays.copyOfRange(buffer, PK_F_OFFSET, PCE_ID_F_OFFSET)) & 0xFFFF;
-
- final byte[] pceId = Arrays.copyOfRange(buffer, PCE_ID_F_OFFSET, CONTENT_LENGTH);
-
+ }
+ final int pathKey = ByteArray.bytesToShort(Arrays.copyOfRange(buffer, PK_F_OFFSET, PCE_ID_F_OFFSET));
final SubobjectsBuilder builder = new SubobjectsBuilder();
- // builder.setSubobjectType(value);
+ final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reported.route.object.subobjects.subobject.type.path.key.PathKeyBuilder pBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reported.route.object.subobjects.subobject.type.path.key.PathKeyBuilder();
+ pBuilder.setPceId(new PceId(pceId));
+ pBuilder.setPathKey(new PathKey(pathKey));
+ builder.setSubobjectType(new PathKeyBuilder().setPathKey(pBuilder.build()).build());
return builder.build();
}
@Override
public byte[] serializeSubobject(final Subobjects subobject) {
- final byte[] retBytes = new byte[CONTENT_LENGTH];
-
- // System.arraycopy(ByteArray.shortToBytes((short) objToSerialize.getPathKey()), 0, retBytes, PK_F_OFFSET,
- // PK_F_LENGTH);
- //
- // if (objToSerialize.getPceId().length != PCE_ID_F_LENGTH)
- // throw new IllegalArgumentException("Wrong length of pce id. Passed: " + objToSerialize.getPceId().length +
- // ". Expected: ="
- // + PCE_ID_F_LENGTH);
- // System.arraycopy(objToSerialize.getPceId(), 0, retBytes, PCE_ID_F_OFFSET, PCE_ID_F_LENGTH);
-
+ final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reported.route.object.subobjects.subobject.type.PathKey pk = (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reported.route.object.subobjects.subobject.type.PathKey) subobject.getSubobjectType();
+ final int pathKey = pk.getPathKey().getPathKey().getValue();
+ final byte[] pceId = pk.getPathKey().getPceId().getBinary();
+ final byte[] retBytes = new byte[PK_F_LENGTH + pceId.length];
+ System.arraycopy(ByteArray.shortToBytes((short) pathKey), 0, retBytes, PK_F_OFFSET, PK_F_LENGTH);
+ System.arraycopy(pceId, 0, retBytes, PCE_ID_F_OFFSET, pceId.length);
return retBytes;
}
*/
package org.opendaylight.protocol.pcep.impl.subobject;
+import java.util.Arrays;
+import java.util.BitSet;
+
import org.opendaylight.protocol.pcep.PCEPDeserializerException;
import org.opendaylight.protocol.pcep.spi.RROSubobjectParser;
import org.opendaylight.protocol.pcep.spi.RROSubobjectSerializer;
import com.google.common.primitives.UnsignedInts;
/**
- * Parser for {@link org.opendaylight.protocol.pcep.subobject.RROUnnumberedInterfaceSubobject
- * RROUnnumberedInterfaceSubobject}
+ * Parser for {@link UnnumberedSubobject}
*/
public class RROUnnumberedInterfaceSubobjectParser implements RROSubobjectParser, RROSubobjectSerializer {
public static final int TYPE = 4;
- public static final int ROUTER_ID_NUMBER_LENGTH = 4;
- public static final int INTERFACE_ID_NUMBER_LENGTH = 4;
+ private static final int FLAGS_F_LENGTH = 1;
+ private static final int ROUTER_ID_NUMBER_LENGTH = 4;
+ private static final int INTERFACE_ID_NUMBER_LENGTH = 4;
+
+ private static final int ROUTER_ID_NUMBER_OFFSET = 2;
+ private static final int INTERFACE_ID_NUMBER_OFFSET = ROUTER_ID_NUMBER_OFFSET + ROUTER_ID_NUMBER_LENGTH;
- public static final int ROUTER_ID_NUMBER_OFFSET = 2; // added reserved field of size 2
- public static final int INTERFACE_ID_NUMBER_OFFSET = ROUTER_ID_NUMBER_OFFSET + ROUTER_ID_NUMBER_LENGTH;
+ private static final int CONTENT_LENGTH = INTERFACE_ID_NUMBER_OFFSET + INTERFACE_ID_NUMBER_LENGTH;
- public static final int CONTENT_LENGTH = INTERFACE_ID_NUMBER_OFFSET + INTERFACE_ID_NUMBER_LENGTH;
+ private static final int LPA_F_OFFSET = 7;
+ private static final int LPIU_F_OFFSET = 6;
@Override
public Subobjects parseSubobject(final byte[] buffer) throws PCEPDeserializerException {
- if (buffer == null || buffer.length == 0)
+ if (buffer == null || buffer.length == 0) {
throw new IllegalArgumentException("Array of bytes is mandatory. Can't be null or empty.");
- if (buffer.length != CONTENT_LENGTH)
+ }
+ if (buffer.length != CONTENT_LENGTH) {
throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.length + "; Expected: "
+ CONTENT_LENGTH + ".");
+ }
final SubobjectsBuilder builder = new SubobjectsBuilder();
+ final BitSet flags = ByteArray.bytesToBitSet(Arrays.copyOfRange(buffer, 0, FLAGS_F_LENGTH));
+ builder.setProtectionAvailable(flags.get(LPA_F_OFFSET));
+ builder.setProtectionInUse(flags.get(LPIU_F_OFFSET));
final UnnumberedBuilder ubuilder = new UnnumberedBuilder();
ubuilder.setRouterId(ByteArray.bytesToLong(ByteArray.subByte(buffer, ROUTER_ID_NUMBER_OFFSET, ROUTER_ID_NUMBER_LENGTH)));
ubuilder.setInterfaceId(UnsignedInts.toLong(ByteArray.bytesToInt(ByteArray.subByte(buffer, INTERFACE_ID_NUMBER_OFFSET,
@Override
public byte[] serializeSubobject(final Subobjects subobject) {
- if (!(subobject.getSubobjectType() instanceof UnnumberedSubobject))
+ if (!(subobject.getSubobjectType() instanceof UnnumberedSubobject)) {
throw new IllegalArgumentException("Unknown ReportedRouteSubobject instance. Passed " + subobject.getSubobjectType().getClass()
+ ". Needed UnnumberedSubobject.");
-
- byte[] retBytes;
- retBytes = new byte[CONTENT_LENGTH];
+ }
+ final byte[] retBytes = new byte[CONTENT_LENGTH];
final UnnumberedSubobject specObj = (UnnumberedSubobject) subobject.getSubobjectType();
-
- ByteArray.copyWhole(ByteArray.longToBytes(specObj.getRouterId()), retBytes, ROUTER_ID_NUMBER_OFFSET);
+ final BitSet flags = new BitSet(FLAGS_F_LENGTH * Byte.SIZE);
+ flags.set(LPA_F_OFFSET, subobject.isProtectionAvailable());
+ flags.set(LPIU_F_OFFSET, subobject.isProtectionInUse());
+ retBytes[0] = ByteArray.bitSetToBytes(flags, FLAGS_F_LENGTH)[0];
+ ByteArray.copyWhole(ByteArray.subByte(ByteArray.longToBytes(specObj.getRouterId()), 4, ROUTER_ID_NUMBER_LENGTH), retBytes,
+ ROUTER_ID_NUMBER_OFFSET);
System.arraycopy(ByteArray.longToBytes(specObj.getInterfaceId()), Long.SIZE / Byte.SIZE - INTERFACE_ID_NUMBER_LENGTH, retBytes,
INTERFACE_ID_NUMBER_OFFSET, INTERFACE_ID_NUMBER_LENGTH);
-
return retBytes;
}
--- /dev/null
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.protocol.pcep.impl;
+
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+import org.opendaylight.protocol.concepts.Ipv6Util;
+import org.opendaylight.protocol.pcep.PCEPDeserializerException;
+import org.opendaylight.protocol.pcep.impl.subobject.RROIpPrefixSubobjectParser;
+import org.opendaylight.protocol.pcep.impl.subobject.RROPathKeySubobjectParser;
+import org.opendaylight.protocol.pcep.impl.subobject.RROUnnumberedInterfaceSubobjectParser;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpPrefix;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Prefix;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.PathKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.PceId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reported.route.object.SubobjectsBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reported.route.object.subobjects.subobject.type.PathKeyBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.record.route.subobjects.subobject.type.IpPrefixBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.record.route.subobjects.subobject.type.UnnumberedBuilder;
+
+public class PCEPRROSubobjectParserTest {
+
+ private static final byte[] ip4PrefixBytes = { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0x16, (byte) 0x01 };
+ private static final byte[] ip6PrefixBytes = { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
+ (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
+ (byte) 0xFF, (byte) 0x16, (byte) 0x02 };
+ private static final byte[] unnumberedBytes = { (byte) 0x02, (byte) 0x00, (byte) 0x12, (byte) 0x34, (byte) 0x50, (byte) 0x00,
+ (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF };
+ private static final byte[] pathKey32Bytes = { (byte) 0x12, (byte) 0x34, (byte) 0x12, (byte) 0x34, (byte) 0x50, (byte) 0x00 };
+ private static final byte[] pathKey128Bytes = { (byte) 0x12, (byte) 0x34, (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78,
+ (byte) 0x9A, (byte) 0xBC, (byte) 0xDE, (byte) 0x12, (byte) 0x34, (byte) 0x54, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00 };
+
+ @Test
+ public void testRROIp4PrefixSubobject() throws PCEPDeserializerException {
+ final RROIpPrefixSubobjectParser parser = new RROIpPrefixSubobjectParser();
+ final SubobjectsBuilder subs = new SubobjectsBuilder();
+ subs.setProtectionAvailable(true);
+ subs.setProtectionInUse(false);
+ subs.setSubobjectType(new IpPrefixBuilder().setIpPrefix(new IpPrefix(new Ipv4Prefix("255.255.255.255/22"))).build());
+ assertEquals(subs.build(), parser.parseSubobject(ip4PrefixBytes));
+ assertArrayEquals(ip4PrefixBytes, parser.serializeSubobject(subs.build()));
+ }
+
+ @Test
+ public void testRROIp6PrefixSubobject() throws PCEPDeserializerException {
+ final RROIpPrefixSubobjectParser parser = new RROIpPrefixSubobjectParser();
+ final SubobjectsBuilder subs = new SubobjectsBuilder();
+ subs.setProtectionAvailable(false);
+ subs.setProtectionInUse(true);
+ subs.setSubobjectType(new IpPrefixBuilder().setIpPrefix(
+ new IpPrefix(Ipv6Util.prefixForBytes(new byte[] { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
+ (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
+ (byte) 0xFF, (byte) 0xFF, (byte) 0xFF }, 22))).build());
+ assertEquals(subs.build(), parser.parseSubobject(ip6PrefixBytes));
+ assertArrayEquals(ip6PrefixBytes, parser.serializeSubobject(subs.build()));
+ }
+
+ @Test
+ public void testRROUnnumberedSubobject() throws PCEPDeserializerException {
+ final RROUnnumberedInterfaceSubobjectParser parser = new RROUnnumberedInterfaceSubobjectParser();
+ final SubobjectsBuilder subs = new SubobjectsBuilder();
+ subs.setProtectionAvailable(false);
+ subs.setProtectionInUse(true);
+ subs.setSubobjectType(new UnnumberedBuilder().setRouterId(0x12345000L).setInterfaceId(0xffffffffL).build());
+ assertEquals(subs.build(), parser.parseSubobject(unnumberedBytes));
+ assertArrayEquals(unnumberedBytes, parser.serializeSubobject(subs.build()));
+ }
+
+ @Test
+ public void testRROPathKey32Subobject() throws PCEPDeserializerException {
+ final RROPathKeySubobjectParser parser = new RROPathKeySubobjectParser();
+ final SubobjectsBuilder subs = new SubobjectsBuilder();
+ final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reported.route.object.subobjects.subobject.type.path.key.PathKeyBuilder pBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reported.route.object.subobjects.subobject.type.path.key.PathKeyBuilder();
+ pBuilder.setPceId(new PceId(new byte[] { (byte) 0x12, (byte) 0x34, (byte) 0x50, (byte) 0x00 }));
+ pBuilder.setPathKey(new PathKey(4660));
+ subs.setSubobjectType(new PathKeyBuilder().setPathKey(pBuilder.build()).build());
+ assertEquals(subs.build(), parser.parseSubobject(pathKey32Bytes));
+ assertArrayEquals(pathKey32Bytes, parser.serializeSubobject(subs.build()));
+ }
+
+ @Test
+ public void testRROPathKey128Subobject() throws PCEPDeserializerException {
+ final RROPathKeySubobjectParser parser = new RROPathKeySubobjectParser();
+ final SubobjectsBuilder subs = new SubobjectsBuilder();
+ final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reported.route.object.subobjects.subobject.type.path.key.PathKeyBuilder pBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reported.route.object.subobjects.subobject.type.path.key.PathKeyBuilder();
+ pBuilder.setPceId(new PceId(new byte[] { (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78, (byte) 0x9A, (byte) 0xBC, (byte) 0xDE,
+ (byte) 0x12, (byte) 0x34, (byte) 0x54, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00 }));
+ pBuilder.setPathKey(new PathKey(4660));
+ subs.setSubobjectType(new PathKeyBuilder().setPathKey(pBuilder.build()).build());
+ assertEquals(subs.build(), parser.parseSubobject(pathKey128Bytes));
+ assertArrayEquals(pathKey128Bytes, parser.serializeSubobject(subs.build()));
+ }
+}