}
public V get(final K key) {
- return current.get(key);
+ return this.current.get(key);
}
}
<groupId>org.opendaylight.yangtools.model</groupId>
<artifactId>ietf-inet-types</artifactId>
</dependency>
+
+ <!--test dependencies -->
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ </dependency>
</dependencies>
<build>
import org.opendaylight.protocol.pcep.spi.pojo.AbstractPCEPExtensionProviderActivator;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.initiated._00.rev140113.Pcinitiate;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.initiated._00.rev140113.lsp.cleanup.tlv.LspCleanup;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.stateful._02.rev140110.stateful.capability.tlv.Stateful;
public class InitiatedActivator extends AbstractPCEPExtensionProviderActivator {
@Override
regs.add(context.registerTlvSerializer(LspCleanup.class, new LSPCleanupTlvParser()));
regs.add(context.registerTlvParser(PCEStatefulCapabilityTlvParser.TYPE, new PCEStatefulCapabilityTlvParser()));
- // regs.add(context.registerTlvSerializer(Stateful.class, new PCEStatefulCapabilityTlvParser()));
+ regs.add(context.registerTlvSerializer(Stateful.class, new PCEStatefulCapabilityTlvParser()));
return regs;
}
if (sfi != null) {
flags.set(I_FLAG_OFFSET, sfi.isInitiation());
}
-
- flags.set(U_FLAG_OFFSET, sct.isLspUpdateCapability());
- flags.set(S_FLAG_OFFSET, sct.isIncludeDbVersion());
-
+ if (sct.isLspUpdateCapability() != null && sct.isLspUpdateCapability()) {
+ flags.set(U_FLAG_OFFSET, sct.isLspUpdateCapability());
+ }
+ if (sct.isIncludeDbVersion() != null && sct.isIncludeDbVersion()) {
+ flags.set(S_FLAG_OFFSET, sct.isIncludeDbVersion());
+ }
return ByteArray.bitSetToBytes(flags, FLAGS_F_LENGTH);
}
--- /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.ietf;
+
+import static org.junit.Assert.assertArrayEquals;
+
+import java.io.IOException;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.opendaylight.protocol.pcep.ietf.stateful02.PCEPOpenObjectParser;
+import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
+import org.opendaylight.protocol.pcep.spi.TlvHandlerRegistry;
+import org.opendaylight.protocol.pcep.spi.pojo.ServiceLoaderPCEPExtensionProviderContext;
+import org.opendaylight.protocol.util.ByteArray;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.initiated._00.rev140113.Stateful1;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.initiated._00.rev140113.Stateful1Builder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.stateful._02.rev140110.Tlvs2;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.stateful._02.rev140110.Tlvs2Builder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.stateful._02.rev140110.stateful.capability.tlv.Stateful;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.stateful._02.rev140110.stateful.capability.tlv.StatefulBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ProtocolVersion;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.OpenBuilder;
+
+public class PCEPObjectParserTest {
+
+ private TlvHandlerRegistry tlvRegistry;
+
+ @Before
+ public void setUp() throws Exception {
+ this.tlvRegistry = ServiceLoaderPCEPExtensionProviderContext.create().getTlvHandlerRegistry();
+ }
+
+ @Test
+ public void testOpenObjectWithTLV() throws PCEPDeserializerException, IOException {
+ final PCEPOpenObjectParser parser = new PCEPOpenObjectParser(this.tlvRegistry);
+ final byte[] result = ByteArray.fileToBytes("src/test/resources/PCEPOpenObject1.bin");
+
+ final OpenBuilder builder = new OpenBuilder();
+ builder.setProcessingRule(false);
+ builder.setIgnore(false);
+ builder.setVersion(new ProtocolVersion((short) 1));
+ builder.setKeepalive((short) 30);
+ builder.setDeadTimer((short) 120);
+ builder.setSessionId((short) 1);
+
+ final Stateful tlv1 = new StatefulBuilder().setLspUpdateCapability(Boolean.TRUE).setIncludeDbVersion(Boolean.FALSE).addAugmentation(
+ Stateful1.class, new Stateful1Builder().setInitiation(true).build()).build();
+
+ final Tlvs2Builder statBuilder = new Tlvs2Builder();
+ statBuilder.setStateful(tlv1);
+
+ builder.setTlvs(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.open.TlvsBuilder().addAugmentation(
+ Tlvs2.class, statBuilder.build()).build());
+
+ // FIXME: enable once the registry is rewritten
+ // assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(false, false),
+ // ByteArray.cutBytes(result, 4)));
+ // assertArrayEquals(result, parser.serializeObject(builder.build()));
+ }
+
+ @Test
+ public void testLspObjectWithTLV() throws IOException, PCEPDeserializerException {
+ // final PCEPLspObjectParser parser = new PCEPLspObjectParser(this.tlvRegistry);
+ // final byte[] result = ByteArray.fileToBytes("src/test/resources/PCEPLspObject1WithTLV.bin");
+ //
+ // final LspBuilder builder = new LspBuilder();
+ // builder.setProcessingRule(true);
+ // builder.setIgnore(true);
+ // builder.setDelegate(false);
+ // builder.setRemove(true);
+ // builder.setSync(false);
+ //
+ // final LspErrorCode tlv1 = new LspErrorCodeBuilder().setErrorCode(627610883L).build();
+ // final SymbolicPathName tlv2 = new SymbolicPathNameBuilder().setPathName(
+ // new
+ // org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.SymbolicPathName("Med".getBytes())).build();
+ // builder.setTlvs(new
+ // org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.lsp.object.lsp.TlvsBuilder().setLspErrorCode(
+ // tlv1).setSymbolicPathName(tlv2).build());
+ // assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), ByteArray.cutBytes(result,
+ // 4)));
+ // assertArrayEquals(result, parser.serializeObject(builder.build()));
+ }
+}
--- /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.ietf;
+
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+import org.opendaylight.protocol.concepts.Ipv4Util;
+import org.opendaylight.protocol.concepts.Ipv6Util;
+import org.opendaylight.protocol.pcep.ietf.stateful02.LspSymbolicNameTlvParser;
+import org.opendaylight.protocol.pcep.ietf.stateful02.PCEStatefulCapabilityTlvParser;
+import org.opendaylight.protocol.pcep.ietf.stateful02.RSVPErrorSpecTlvParser;
+import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.iana.rev130816.EnterpriseNumber;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.stateful._02.rev140110.rsvp.error.spec.tlv.RsvpErrorSpec;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.stateful._02.rev140110.rsvp.error.spec.tlv.RsvpErrorSpecBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.stateful._02.rev140110.rsvp.error.spec.tlv.rsvp.error.spec.error.type.RsvpCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.stateful._02.rev140110.rsvp.error.spec.tlv.rsvp.error.spec.error.type.UserCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.stateful._02.rev140110.rsvp.error.spec.tlv.rsvp.error.spec.error.type.rsvp._case.RsvpErrorBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.stateful._02.rev140110.rsvp.error.spec.tlv.rsvp.error.spec.error.type.user._case.UserErrorBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.stateful._02.rev140110.stateful.capability.tlv.Stateful;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.stateful._02.rev140110.stateful.capability.tlv.StatefulBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.stateful._02.rev140110.symbolic.path.name.tlv.SymbolicPathName;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.stateful._02.rev140110.symbolic.path.name.tlv.SymbolicPathNameBuilder;
+
+public class PCEPTlvParserTest {
+
+ private static final byte[] statefulBytes = { (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01 };
+ private static final byte[] symbolicNameBytes = { (byte) 0x4d, (byte) 0x65, (byte) 0x64, (byte) 0x20, (byte) 0x74, (byte) 0x65,
+ (byte) 0x73, (byte) 0x74, (byte) 0x20, (byte) 0x6f, (byte) 0x66, (byte) 0x20, (byte) 0x73, (byte) 0x79, (byte) 0x6d,
+ (byte) 0x62, (byte) 0x6f, (byte) 0x6c, (byte) 0x69, (byte) 0x63, (byte) 0x20, (byte) 0x6e, (byte) 0x61, (byte) 0x6d,
+ (byte) 0x65 };
+ private static final byte[] rsvpErrorBytes = { (byte) 0x06, (byte) 0x01, (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78,
+ (byte) 0x02, (byte) 0x92, (byte) 0x16, (byte) 0x02 };
+ private static final byte[] rsvpError6Bytes = { (byte) 0x06, (byte) 0x02, (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78,
+ (byte) 0x9a, (byte) 0xbc, (byte) 0xde, (byte) 0xf0, (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78, (byte) 0x9a,
+ (byte) 0xbc, (byte) 0xde, (byte) 0xf0, (byte) 0x02, (byte) 0xd5, (byte) 0xc5, (byte) 0xd9 };
+ private static final byte[] userErrorBytes = { (byte) 0xc2, (byte) 0x01, (byte) 0x00, (byte) 0x00, (byte) 0x30, (byte) 0x39,
+ (byte) 0x05, (byte) 0x09, (byte) 0x00, (byte) 0x26, (byte) 0x75, (byte) 0x73, (byte) 0x65, (byte) 0x72, (byte) 0x20,
+ (byte) 0x64, (byte) 0x65, (byte) 0x73, (byte) 0x63 };
+
+ @Test
+ public void testStatefulTlv() throws PCEPDeserializerException {
+ final PCEStatefulCapabilityTlvParser parser = new PCEStatefulCapabilityTlvParser();
+ final Stateful tlv = new StatefulBuilder().setLspUpdateCapability(Boolean.TRUE).setIncludeDbVersion(false).build();
+ assertEquals(tlv, parser.parseTlv(statefulBytes));
+ assertArrayEquals(statefulBytes, parser.serializeTlv(tlv));
+ }
+
+ @Test
+ public void testSymbolicNameTlv() throws PCEPDeserializerException {
+ final LspSymbolicNameTlvParser parser = new LspSymbolicNameTlvParser();
+ final SymbolicPathName tlv = new SymbolicPathNameBuilder().setPathName(
+ new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.stateful._02.rev140110.SymbolicPathName("Med test of symbolic name".getBytes())).build();
+ assertEquals(tlv, parser.parseTlv(symbolicNameBytes));
+ assertArrayEquals(symbolicNameBytes, parser.serializeTlv(tlv));
+ }
+
+ @Test
+ public void testRSVPError4SpecTlv() throws PCEPDeserializerException {
+ final RSVPErrorSpecTlvParser parser = new RSVPErrorSpecTlvParser();
+ final RsvpErrorBuilder builder = new RsvpErrorBuilder();
+ builder.setNode(new IpAddress(Ipv4Util.addressForBytes(new byte[] { (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78 })));
+ builder.setFlags(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.ErrorSpec.Flags(false, true));
+ builder.setCode((short) 146);
+ builder.setValue(5634);
+ final RsvpErrorSpec tlv = new RsvpErrorSpecBuilder().setErrorType(new RsvpCaseBuilder().setRsvpError(builder.build()).build()).build();
+ assertEquals(tlv, parser.parseTlv(rsvpErrorBytes));
+ assertArrayEquals(rsvpErrorBytes, parser.serializeTlv(tlv));
+ }
+
+ @Test
+ public void testRSVPError6SpecTlv() throws PCEPDeserializerException {
+ final RSVPErrorSpecTlvParser parser = new RSVPErrorSpecTlvParser();
+ final RsvpErrorBuilder builder = new RsvpErrorBuilder();
+ builder.setNode(new IpAddress(Ipv6Util.addressForBytes(new byte[] { (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78,
+ (byte) 0x9a, (byte) 0xbc, (byte) 0xde, (byte) 0xf0, (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78, (byte) 0x9a,
+ (byte) 0xbc, (byte) 0xde, (byte) 0xf0 })));
+ builder.setFlags(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.ErrorSpec.Flags(false, true));
+ builder.setCode((short) 213);
+ builder.setValue(50649);
+ final RsvpErrorSpec tlv = new RsvpErrorSpecBuilder().setErrorType(new RsvpCaseBuilder().setRsvpError(builder.build()).build()).build();
+ assertEquals(tlv, parser.parseTlv(rsvpError6Bytes));
+ assertArrayEquals(rsvpError6Bytes, parser.serializeTlv(tlv));
+ }
+
+ @Test
+ public void testUserErrorSpecTlv() throws PCEPDeserializerException {
+ final RSVPErrorSpecTlvParser parser = new RSVPErrorSpecTlvParser();
+ final UserErrorBuilder builder = new UserErrorBuilder();
+ builder.setEnterprise(new EnterpriseNumber(12345L));
+ builder.setSubOrg((short) 5);
+ builder.setValue(38);
+ builder.setDescription("user desc");
+ final RsvpErrorSpec tlv = new RsvpErrorSpecBuilder().setErrorType(new UserCaseBuilder().setUserError(builder.build()).build()).build();
+ assertEquals(tlv, parser.parseTlv(userErrorBytes));
+ assertArrayEquals(userErrorBytes, parser.serializeTlv(tlv));
+ }
+}
+++ /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.ietf.stateful07;
-
-import io.netty.buffer.ByteBuf;
-
-import java.util.List;
-
-import org.opendaylight.protocol.pcep.spi.AbstractMessageParser;
-import org.opendaylight.protocol.pcep.spi.ObjectHandlerRegistry;
-import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.OpenBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Message;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.OpenMessage;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.message.OpenMessageBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.Open;
-
-/**
- * Parser for {@link OpenMessage}
- */
-public class PCEPOpenMessageParser extends AbstractMessageParser {
-
- public static final int TYPE = 1;
-
- public PCEPOpenMessageParser(final ObjectHandlerRegistry registry) {
- super(registry);
- }
-
- @Override
- public void serializeMessage(final Message message, final ByteBuf buffer) {
- if (!(message instanceof OpenMessage)) {
- throw new IllegalArgumentException("Wrong instance of Message. Passed instance " + message.getClass() + ". Needed OpenMessage.");
- }
- final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.message.OpenMessage open = ((OpenMessage) message).getOpenMessage();
-
- if (open.getOpen() == null) {
- throw new IllegalArgumentException("Open Object must be present in Open Message.");
- }
-
- buffer.writeBytes(serializeObject(open.getOpen()));
- }
-
- @Override
- protected org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.Open validate(final List<Object> objects, final List<Message> errors) throws PCEPDeserializerException {
- if (objects == null) {
- throw new IllegalArgumentException("Passed list can't be null.");
- }
-
- if (objects.isEmpty() || !(objects.get(0) instanceof Open)) {
- throw new PCEPDeserializerException("Open message doesn't contain OPEN object.");
- }
-
- final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.message.OpenMessage msg = new OpenMessageBuilder().setOpen(
- (Open) objects.get(0)).build();
-
- objects.remove(0);
-
- if (!objects.isEmpty()) {
- throw new PCEPDeserializerException("Unprocessed Objects: " + objects);
- }
-
- return new OpenBuilder().setOpenMessage(msg).build();
- }
-
- @Override
- public int getMessageType() {
- return TYPE;
- }
-}
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcerr.message.pcerr.message.error.type.request._case.RequestBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcerr.message.pcerr.message.error.type.request._case.request.RpsBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.rp.object.Rp;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import com.google.common.base.Preconditions;
import com.google.common.collect.Lists;
public abstract class AbstractMessageParser implements MessageParser, MessageSerializer {
+ private static final Logger LOG = LoggerFactory.getLogger(AbstractMessageParser.class);
+
private static final int COMMON_OBJECT_HEADER_LENGTH = 4;
private static final int OC_F_LENGTH = 1;
return new byte[] {};
}
final ObjectSerializer serializer = this.registry.getObjectSerializer(object);
+ LOG.trace("Choosen serializer {}", serializer);
return serializer.serializeObject(object);
}
protected final byte[] serializeTlv(final Tlv tlv) {
final TlvSerializer serializer = this.tlvReg.getTlvSerializer(tlv);
+ LOG.trace("Choosen serializer {}", serializer);
final byte[] typeBytes = ByteArray.intToBytes(serializer.getType(), TLV_TYPE_F_LENGTH);