import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.rsvp.error.spec.tlv.RsvpErrorSpec;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.stateful.capability.tlv.Stateful;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.symbolic.path.name.tlv.SymbolicPathName;
-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.IpPrefixSubobject;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.LabelSubobject;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.UnnumberedSubobject;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.basic.explicit.route.subobjects.subobject.type.AsNumber;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.basic.explicit.route.subobjects.subobject.type.IpPrefix;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.basic.explicit.route.subobjects.subobject.type.Label;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.basic.explicit.route.subobjects.subobject.type.Srlg;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.basic.explicit.route.subobjects.subobject.type.Unnumbered;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.label.subobject.label.type.GeneralizedLabel;
context.registerEROSubobjectParser(EROPathKeySubobjectParser.TYPE, new EROPathKeySubobjectParser());
context.registerEROSubobjectParser(EROPathKeySubobjectParser.TYPE128, new EROPathKeySubobjectParser());
- context.registerEROSubobjectSerializer(IpPrefixSubobject.class, new EROIpPrefixSubobjectParser());
- context.registerEROSubobjectSerializer(AsNumberSubobject.class, new EROAsNumberSubobjectParser());
- context.registerEROSubobjectSerializer(LabelSubobject.class, new EROLabelSubobjectParser(labelReg));
- context.registerEROSubobjectSerializer(UnnumberedSubobject.class, new EROUnnumberedInterfaceSubobjectParser());
- context.registerEROSubobjectSerializer(PathKeySubobject.class, new EROPathKeySubobjectParser());
+ context.registerEROSubobjectSerializer(IpPrefix.class, new EROIpPrefixSubobjectParser());
+ context.registerEROSubobjectSerializer(AsNumber.class, new EROAsNumberSubobjectParser());
+ context.registerEROSubobjectSerializer(Label.class, new EROLabelSubobjectParser(labelReg));
+ context.registerEROSubobjectSerializer(Unnumbered.class, new EROUnnumberedInterfaceSubobjectParser());
+ context.registerEROSubobjectSerializer(
+ org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.subobjects.subobject.type.PathKey.class,
+ new EROPathKeySubobjectParser());
final RROSubobjectHandlerRegistry rroSubReg = context.getRROSubobjectHandlerRegistry();
context.registerRROSubobjectParser(RROIpPrefixSubobjectParser.TYPE, new RROIpPrefixSubobjectParser());
import com.google.common.base.Preconditions;
import com.google.common.collect.Lists;
+import com.google.common.primitives.UnsignedBytes;
public abstract class AbstractEROWithSubobjectsParser implements ObjectParser, ObjectSerializer {
public static final int LENGTH_F_OFFSET = TYPE_FLAG_F_OFFSET + SUB_TYPE_FLAG_F_LENGTH;
public static final int SO_CONTENTS_OFFSET = LENGTH_F_OFFSET + SUB_LENGTH_F_LENGTH;
- protected static final int PADDED_TO = 4;
-
private final EROSubobjectHandlerRegistry subobjReg;
protected AbstractEROWithSubobjectsParser(final EROSubobjectHandlerRegistry subobjReg) {
boolean loose_flag = false;
int type;
-
byte[] soContentsBytes;
int length;
int offset = 0;
for (final Subobjects subobject : subobjects) {
- final EROSubobjectSerializer serializer = this.subobjReg.getSubobjectSerializer(subobject);
+ final EROSubobjectSerializer serializer = this.subobjReg.getSubobjectSerializer(subobject.getSubobjectType());
final byte[] valueBytes = serializer.serializeSubobject(subobject);
final byte[] bytes = new byte[SUB_HEADER_LENGTH + valueBytes.length];
- final byte typeBytes = (byte) (ByteArray.cutBytes(ByteArray.intToBytes(serializer.getType()), (Integer.SIZE / 8) - 1)[0] | (subobject.isLoose() ? 1 << 7
- : 0));
- final byte lengthBytes = ByteArray.cutBytes(ByteArray.intToBytes(valueBytes.length), (Integer.SIZE / 8) - 1)[0];
+ final byte typeBytes = (byte) (UnsignedBytes.checkedCast(serializer.getType()) | (subobject.isLoose() ? 1 << 7 : 0));
+ final byte lengthBytes = UnsignedBytes.checkedCast(valueBytes.length + SUB_HEADER_LENGTH);
bytes[0] = typeBytes;
bytes[1] = lengthBytes;
throw new IllegalArgumentException("Wrong instance of PCEPObject. Passed " + object.getClass()
+ ". Needed ExplicitRouteObject.");
}
-
final ExplicitRouteObject ero = ((ExplicitRouteObject) object);
assert !(ero.getSubobjects().isEmpty()) : "Empty Explicit Route Object.";
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 ROUTER_ID_NUMBER_LENGTH = 4;
+ private static final int INTERFACE_ID_NUMBER_LENGTH = 4;
- 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 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 CONTENT_LENGTH = INTERFACE_ID_NUMBER_OFFSET + INTERFACE_ID_NUMBER_LENGTH;
+ private static final int CONTENT_LENGTH = INTERFACE_ID_NUMBER_OFFSET + INTERFACE_ID_NUMBER_LENGTH;
@Override
public Subobjects parseSubobject(final byte[] buffer, final boolean loose) throws PCEPDeserializerException {
import java.math.BigInteger;
import java.util.List;
+import org.apache.commons.codec.binary.Hex;
import org.junit.Before;
import org.junit.Test;
import org.opendaylight.protocol.concepts.Ipv4Util;
import org.opendaylight.protocol.pcep.impl.object.PCEPEndPointsObjectParser;
import org.opendaylight.protocol.pcep.impl.object.PCEPErrorObjectParser;
import org.opendaylight.protocol.pcep.impl.object.PCEPExcludeRouteObjectParser;
+import org.opendaylight.protocol.pcep.impl.object.PCEPExplicitRouteObjectParser;
import org.opendaylight.protocol.pcep.impl.object.PCEPGlobalConstraintsObjectParser;
import org.opendaylight.protocol.pcep.impl.object.PCEPLoadBalancingObjectParser;
import org.opendaylight.protocol.pcep.impl.object.PCEPLspObjectParser;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.message.open.message.OpenBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.order.tlv.OrderBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.overload.duration.tlv.OverloadDurationBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.path.definition.ExplicitRouteBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcep.error.object.TlvsBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcerr.message.pcerr.message.ErrorsBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcinitiate.message.pcinitiate.message.requests.EndpointsBuilder;
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.basic.explicit.route.subobjects.subobject.type.AsNumberBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.basic.explicit.route.subobjects.subobject.type.IpPrefixBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.basic.explicit.route.subobjects.subobject.type.UnnumberedBuilder;
import com.google.common.collect.Lists;
import com.google.common.primitives.UnsignedBytes;
assertArrayEquals(result, parser.serializeObject(builder.build()));
}
- //
- // @Test
- // public void testERObjectSerDeser() throws IOException, PCEPDeserializerException, PCEPDocumentedException {
- // final byte[] bytesFromFile =
- // ByteArray.fileToBytes("src/test/resources/PCEPExplicitRouteObject1PackOfSubobjects.bin");
- //
- // MockitoAnnotations.initMocks(this);
- // PCEPExplicitRouteObjectParser parser = new PCEPExplicitRouteObjectParser(registry);
- // doReturn(parser).when(registry).getObjectParser(PCEPExplicitRouteObjectParser.TYPE,
- // PCEPExplicitRouteObjectParser.CLASS);
- // doReturn(new EROAsNumberSubobjectParser()).when(registry).getSubobjectParser(EROAsNumberSubobjectParser.TYPE);
- // ObjectHeader h = new ObjectHeader() {
- //
- // @Override
- // public Class<? extends DataContainer> getImplementedInterface() {
- // // TODO Auto-generated method stub
- // return null;
- // }
- //
- // @Override
- // public Boolean isProcessingRule() {
- // return false;
- // }
- //
- // @Override
- // public Boolean isIgnore() {
- // return false;
- // }
- // };
- //
- // final ExplicitRouteSubobject specObj = (ExplicitRouteSubobject)
- // registry.getObjectParser(PCEPExplicitRouteObjectParser.TYPE, PCEPExplicitRouteObjectParser.CLASS).parseObject(h,
- // bytesFromFile);
- //
- // System.out.println(specObj.toString());
- //
- // //final byte[] bytesActual = PCEPObjectFactory.put(Arrays.asList((PCEPObject) specObj));
- // //assertArrayEquals(bytesFromFile, bytesActual);
- // }
+ @Test
+ public void testEROObject() throws Exception {
+ final PCEPExplicitRouteObjectParser parser = new PCEPExplicitRouteObjectParser(PCEPExtensionProviderContextImpl.create().getEROSubobjectHandlerRegistry());
+ final byte[] result = ByteArray.fileToBytes("src/test/resources/PCEPExplicitRouteObject1PackOfSubobjects.bin");
+
+ final ExplicitRouteBuilder builder = new ExplicitRouteBuilder();
+ builder.setProcessingRule(false);
+ builder.setIgnore(false);
+ final List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.Subobjects> subs = Lists.newArrayList();
+ subs.add(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.SubobjectsBuilder().setLoose(
+ true).setSubobjectType(new AsNumberBuilder().setAsNumber(new AsNumber(0xffffL)).build()).build());
+ subs.add(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.SubobjectsBuilder().setLoose(
+ true).setSubobjectType(new IpPrefixBuilder().setIpPrefix(new IpPrefix(new Ipv4Prefix("255.255.255.255/32"))).build()).build());
+ subs.add(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.SubobjectsBuilder().setLoose(
+ true).setSubobjectType(new UnnumberedBuilder().setRouterId(0xffffffffL).setInterfaceId(0xffffffffL).build()).build());
+ builder.setSubobjects(subs);
+
+ assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(false, false), result));
+ System.out.println(new String(Hex.encodeHex(parser.serializeObject(builder.build()))));
+ assertArrayEquals(result, parser.serializeObject(builder.build()));
+ }
+
//
// @Test
// public void testIRObjectSerDeser() throws IOException, PCEPDeserializerException, PCEPDocumentedException {
*/
package org.opendaylight.protocol.pcep.spi;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.Subobjects;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.basic.explicit.route.subobjects.SubobjectType;
public interface EROSubobjectHandlerRegistry {
public EROSubobjectParser getSubobjectParser(int subobjectType);
- public EROSubobjectSerializer getSubobjectSerializer(Subobjects subobject);
+
+ public EROSubobjectSerializer getSubobjectSerializer(SubobjectType subobject);
}
public AutoCloseable registerEROSubobjectParser(int subobjectType, EROSubobjectParser parser);
- public AutoCloseable registerEROSubobjectSerializer(Class<? extends CSubobject> subobjectClass, EROSubobjectSerializer serializer);
+ public AutoCloseable registerEROSubobjectSerializer(Class<? extends SubobjectType> subobjectClass, EROSubobjectSerializer serializer);
public AutoCloseable registerMessageParser(int messageType, MessageParser parser);
}
@Override
- public AutoCloseable registerEROSubobjectSerializer(final Class<? extends CSubobject> subobjectClass,
+ public AutoCloseable registerEROSubobjectSerializer(final Class<? extends SubobjectType> subobjectClass,
final EROSubobjectSerializer serializer) {
// TODO Auto-generated method stub
return null;
}
@Override
- public AutoCloseable registerEROSubobjectSerializer(final Class<? extends CSubobject> subobjectClass,
+ public AutoCloseable registerEROSubobjectSerializer(final Class<? extends SubobjectType> subobjectClass,
final EROSubobjectSerializer serializer) {
return this.eroSubReg.registerSubobjectSerializer(subobjectClass, serializer);
}
import org.opendaylight.protocol.pcep.spi.EROSubobjectParser;
import org.opendaylight.protocol.pcep.spi.EROSubobjectSerializer;
import org.opendaylight.protocol.util.Util;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.Subobjects;
-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.basic.explicit.route.subobjects.SubobjectType;
import org.opendaylight.yangtools.yang.binding.DataContainer;
import com.google.common.base.Preconditions;
return this.handlers.registerParser(subobjectType, parser);
}
- public AutoCloseable registerSubobjectSerializer(final Class<? extends CSubobject> subobjectClass,
+ public AutoCloseable registerSubobjectSerializer(final Class<? extends SubobjectType> subobjectClass,
final EROSubobjectSerializer serializer) {
return this.handlers.registerSerializer(subobjectClass, serializer);
}
}
@Override
- public EROSubobjectSerializer getSubobjectSerializer(final Subobjects subobject) {
+ public EROSubobjectSerializer getSubobjectSerializer(final SubobjectType subobject) {
return this.handlers.getSerializer(subobject.getImplementedInterface());
}
}