BUG-50 : added tests for PCEP TLVs. 55/2155/1
authorDana Kutenicsova <dkutenic@cisco.com>
Thu, 24 Oct 2013 16:15:21 +0000 (18:15 +0200)
committerDana Kutenicsova <dkutenic@cisco.com>
Fri, 25 Oct 2013 09:06:24 +0000 (11:06 +0200)
Change-Id: I8e5b02a541a16c5953a5d7d82ddac9cb6ba1a4a8
Signed-off-by: Dana Kutenicsova <dkutenic@cisco.com>
27 files changed:
pcep/api/src/main/yang/pcep-types.yang
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/Activator.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/tlv/LSPIdentifierIPv4TlvParser.java [deleted file]
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/tlv/LSPIdentifierIPv6TlvParser.java [deleted file]
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/tlv/LSPIdentifierTlvParser.java [new file with mode: 0644]
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/tlv/LspDbVersionTlvParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/tlv/LspSymbolicNameTlvParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/tlv/LspUpdateErrorTlvParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/tlv/NoPathVectorTlvParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/tlv/OFListTlvParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/tlv/OrderTlvParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/tlv/OverloadedDurationTlvParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/tlv/PCEStatefulCapabilityTlvParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/tlv/RSVPErrorSpecTlvParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/tlv/ReqMissingTlvParser.java
pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/PCEPTlvParserTest.java
pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/pojo/SimpleEROSubobjectHandlerRegistry.java
pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/pojo/SimpleLabelHandlerRegistry.java
pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/pojo/SimpleMessageHandlerRegistry.java
pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/pojo/SimpleObjectHandlerRegistry.java
pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/pojo/SimpleRROSubobjectHandlerRegistry.java
pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/pojo/SimpleTlvHandlerRegistry.java
pcep/spi/src/main/java/org/opendaylight/protocol/pcep/spi/pojo/SimpleXROSubobjectHandlerRegistry.java
pcep/testtool/src/main/java/org/opendaylight/protocol/pcep/testtool/Main.java
pcep/testtool/src/main/java/org/opendaylight/protocol/pcep/testtool/SimpleSessionListener.java
pcep/testtool/src/main/java/org/opendaylight/protocol/pcep/testtool/TestingSessionListener.java
util/src/main/java/org/opendaylight/protocol/util/Util.java

index c5eaac79ce1b1cde45f9600b6bb243c195d57d52..1a359ea69315d8159bf8a8898c6cb0cdcc8689cf 100644 (file)
@@ -229,6 +229,7 @@ module pcep-types {
                                }
                        }
                }
+               // FIXME: add tunnel endpoint (from stateful-07) 
        }
 
        grouping symbolic-path-name-tlv {
index 02a7d2e778fad318ee1b8c3cfb0a9ad9eaad003d..7912c04795ff65cbd07508b94a21e085f37bd6e2 100644 (file)
@@ -61,8 +61,7 @@ import org.opendaylight.protocol.pcep.impl.subobject.XROIpPrefixSubobjectParser;
 import org.opendaylight.protocol.pcep.impl.subobject.XROPathKeySubobjectParser;
 import org.opendaylight.protocol.pcep.impl.subobject.XROSRLGSubobjectParser;
 import org.opendaylight.protocol.pcep.impl.subobject.XROUnnumberedInterfaceSubobjectParser;
-import org.opendaylight.protocol.pcep.impl.tlv.LSPIdentifierIPv4TlvParser;
-import org.opendaylight.protocol.pcep.impl.tlv.LSPIdentifierIPv6TlvParser;
+import org.opendaylight.protocol.pcep.impl.tlv.LSPIdentifierTlvParser;
 import org.opendaylight.protocol.pcep.impl.tlv.LspDbVersionTlvParser;
 import org.opendaylight.protocol.pcep.impl.tlv.LspSymbolicNameTlvParser;
 import org.opendaylight.protocol.pcep.impl.tlv.LspUpdateErrorTlvParser;
@@ -214,8 +213,8 @@ public final class Activator implements PCEPExtensionProviderActivator {
                context.registerTlvParser(OrderTlvParser.TYPE, new OrderTlvParser());
                context.registerTlvParser(PCEStatefulCapabilityTlvParser.TYPE, new PCEStatefulCapabilityTlvParser());
                context.registerTlvParser(LspSymbolicNameTlvParser.TYPE, new LspSymbolicNameTlvParser());
-               context.registerTlvParser(LSPIdentifierIPv4TlvParser.TYPE, new LSPIdentifierIPv4TlvParser());
-               context.registerTlvParser(LSPIdentifierIPv6TlvParser.TYPE, new LSPIdentifierIPv6TlvParser());
+               context.registerTlvParser(LSPIdentifierTlvParser.TYPE, new LSPIdentifierTlvParser());
+               context.registerTlvParser(LSPIdentifierTlvParser.TYPE_6, new LSPIdentifierTlvParser());
                context.registerTlvParser(LspUpdateErrorTlvParser.TYPE, new LspUpdateErrorTlvParser());
                context.registerTlvParser(RSVPErrorSpecTlvParser.TYPE, new RSVPErrorSpecTlvParser());
                context.registerTlvParser(LspDbVersionTlvParser.TYPE, new LspDbVersionTlvParser());
@@ -228,7 +227,7 @@ public final class Activator implements PCEPExtensionProviderActivator {
                context.registerTlvSerializer(OrderTlv.class, new OrderTlvParser());
                context.registerTlvSerializer(StatefulCapabilityTlv.class, new PCEStatefulCapabilityTlvParser());
                context.registerTlvSerializer(SymbolicPathNameTlv.class, new LspSymbolicNameTlvParser());
-               context.registerTlvSerializer(LspIdentifiersTlv.class, new LSPIdentifierIPv4TlvParser());
+               context.registerTlvSerializer(LspIdentifiersTlv.class, new LSPIdentifierTlvParser());
                context.registerTlvSerializer(LspErrorCodeTlv.class, new LspUpdateErrorTlvParser());
                context.registerTlvSerializer(RsvpErrorSpecTlv.class, new RSVPErrorSpecTlvParser());
                context.registerTlvSerializer(LspDbVersionTlv.class, new LspDbVersionTlvParser());
diff --git a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/tlv/LSPIdentifierIPv4TlvParser.java b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/tlv/LSPIdentifierIPv4TlvParser.java
deleted file mode 100644 (file)
index 7f93243..0000000
+++ /dev/null
@@ -1,85 +0,0 @@
-/*
- * 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.tlv;
-
-import org.opendaylight.protocol.concepts.Ipv4Util;
-import org.opendaylight.protocol.pcep.PCEPDeserializerException;
-import org.opendaylight.protocol.pcep.spi.TlvParser;
-import org.opendaylight.protocol.pcep.spi.TlvSerializer;
-import org.opendaylight.protocol.util.ByteArray;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.LspIdentifiersTlv;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Tlv;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lsp.identifiers.tlv.AddressFamily;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lsp.identifiers.tlv.address.family.Ipv4;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lsp.identifiers.tlv.address.family.Ipv4Builder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lsp.identifiers.tlv.address.family.Ipv6;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lsp.object.tlvs.LspIdentifiersBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.Ipv4ExtendedTunnelId;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.LspId;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.TunnelId;
-
-/**
- * Parser for {@link LspIdentifiersTlv}
- */
-public class LSPIdentifierIPv4TlvParser implements TlvParser, TlvSerializer {
-
-       public static final int TYPE = 18;
-
-       private static final int IP_F_LENGTH = 4;
-       private static final int LSP_ID_F_LENGTH = 2;
-       private static final int TUNNEL_ID_F_LENGTH = 2;
-       private static final int EX_TUNNEL_ID_F_LENGTH = 4;
-
-       @Override
-       public LspIdentifiersTlv parseTlv(final byte[] valueBytes) throws PCEPDeserializerException {
-               int position = 0;
-               if (valueBytes == null || valueBytes.length == 0)
-                       throw new IllegalArgumentException("Value bytes array is mandatory. Can't be null or empty.");
-
-               final AddressFamily afi = new Ipv4Builder().setIpv4TunnelSenderAddress(
-                               Ipv4Util.addressForBytes(ByteArray.subByte(valueBytes, position, IP_F_LENGTH))).setIpv4ExtendedTunnelId(
-                               new Ipv4ExtendedTunnelId(Ipv4Util.addressForBytes(ByteArray.subByte(valueBytes, position += IP_F_LENGTH,
-                                               EX_TUNNEL_ID_F_LENGTH)))).build();
-
-               return new LspIdentifiersBuilder().setAddressFamily(afi).setLspId(
-                               new LspId(ByteArray.bytesToLong(ByteArray.subByte(valueBytes, position += EX_TUNNEL_ID_F_LENGTH, LSP_ID_F_LENGTH)))).setTunnelId(
-                               new TunnelId(ByteArray.bytesToInt(ByteArray.subByte(valueBytes, position += LSP_ID_F_LENGTH, TUNNEL_ID_F_LENGTH)))).build();
-       }
-
-       @Override
-       public byte[] serializeTlv(final Tlv tlv) {
-               if (tlv == null)
-                       throw new IllegalArgumentException("LspIdentifiersTlv is mandatory.");
-               final LspIdentifiersTlv lsp = (LspIdentifiersTlv) tlv;
-               final AddressFamily afi = lsp.getAddressFamily();
-               if (afi.getClass().equals(Ipv4.class)) {
-                       final Ipv4 ipv4 = (Ipv4) afi;
-                       // buffer.writeBytes(ipv4.getIpv4TunnelSenderAddress().getValue().getBytes());
-                       // buffer.writeBytes(ByteArray.subByte(ByteArray.longToBytes(lsp.getLspId().getValue()), 6,
-                       // LSP_ID_F_LENGTH));
-                       // buffer.writeBytes(ByteArray.subByte(ByteArray.intToBytes(lsp.getTunnelId().getValue()), 2,
-                       // TUNNEL_ID_F_LENGTH));
-                       // buffer.writeBytes(ipv4.getIpv4TunnelSenderAddress().getValue().getBytes());
-               } else {
-                       final Ipv6 ipv6 = (Ipv6) afi;
-                       // buffer.writeBytes(ipv6.getIpv6TunnelSenderAddress().getValue().getBytes());
-                       // buffer.writeBytes(ByteArray.subByte(ByteArray.longToBytes(lsp.getLspId().getValue()), 6,
-                       // LSP_ID_F_LENGTH));
-                       // buffer.writeBytes(ByteArray.subByte(ByteArray.intToBytes(lsp.getTunnelId().getValue()), 2,
-                       // TUNNEL_ID_F_LENGTH));
-                       // buffer.writeBytes(ipv6.getIpv6TunnelSenderAddress().getValue().getBytes());
-               }
-               // FIXME finish
-               return null;
-       }
-
-       @Override
-       public int getType() {
-               return TYPE;
-       }
-}
diff --git a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/tlv/LSPIdentifierIPv6TlvParser.java b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/tlv/LSPIdentifierIPv6TlvParser.java
deleted file mode 100644 (file)
index 11206a5..0000000
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * 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.tlv;
-
-import org.opendaylight.protocol.concepts.Ipv6Util;
-import org.opendaylight.protocol.pcep.PCEPDeserializerException;
-import org.opendaylight.protocol.pcep.spi.TlvParser;
-import org.opendaylight.protocol.util.ByteArray;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.LspIdentifiersTlv;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lsp.identifiers.tlv.AddressFamily;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lsp.identifiers.tlv.address.family.Ipv6Builder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lsp.object.tlvs.LspIdentifiersBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.Ipv6ExtendedTunnelId;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.LspId;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.TunnelId;
-
-/**
- * Parser for {@link LspIdentifiersTlv}
- */
-public class LSPIdentifierIPv6TlvParser implements TlvParser {
-
-       public static final int TYPE = 19;
-
-       private static final int IP_F_LENGTH = 16;
-       private static final int LSP_ID_F_LENGTH = 2;
-       private static final int TUNNEL_ID_F_LENGTH = 2;
-       private static final int EX_TUNNEL_ID_F_LENGTH = 16;
-
-       @Override
-       public LspIdentifiersTlv parseTlv(final byte[] valueBytes) throws PCEPDeserializerException {
-               int position = 0;
-               if (valueBytes == null || valueBytes.length == 0)
-                       throw new IllegalArgumentException("Value bytes array is mandatory. Can't be null or empty.");
-
-               final AddressFamily afi = new Ipv6Builder().setIpv6TunnelSenderAddress(
-                               Ipv6Util.addressForBytes(ByteArray.subByte(valueBytes, position, IP_F_LENGTH))).setIpv6ExtendedTunnelId(
-                               new Ipv6ExtendedTunnelId(Ipv6Util.addressForBytes(ByteArray.subByte(valueBytes, position += IP_F_LENGTH,
-                                               EX_TUNNEL_ID_F_LENGTH)))).build();
-
-               return new LspIdentifiersBuilder().setAddressFamily(afi).setLspId(
-                               new LspId(ByteArray.bytesToLong(ByteArray.subByte(valueBytes, position += EX_TUNNEL_ID_F_LENGTH, LSP_ID_F_LENGTH)))).setTunnelId(
-                               new TunnelId(ByteArray.bytesToInt(ByteArray.subByte(valueBytes, position += LSP_ID_F_LENGTH, TUNNEL_ID_F_LENGTH)))).build();
-       }
-
-       public int getType() {
-               return TYPE;
-       }
-}
diff --git a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/tlv/LSPIdentifierTlvParser.java b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/tlv/LSPIdentifierTlvParser.java
new file mode 100644 (file)
index 0000000..1da47a5
--- /dev/null
@@ -0,0 +1,130 @@
+/*
+ * 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.tlv;
+
+import org.opendaylight.protocol.concepts.Ipv4Util;
+import org.opendaylight.protocol.concepts.Ipv6Util;
+import org.opendaylight.protocol.pcep.PCEPDeserializerException;
+import org.opendaylight.protocol.pcep.spi.TlvParser;
+import org.opendaylight.protocol.pcep.spi.TlvSerializer;
+import org.opendaylight.protocol.util.ByteArray;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.LspIdentifiersTlv;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Tlv;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lsp.identifiers.tlv.AddressFamily;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lsp.identifiers.tlv.address.family.Ipv4;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lsp.identifiers.tlv.address.family.Ipv4Builder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lsp.identifiers.tlv.address.family.Ipv6;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lsp.identifiers.tlv.address.family.Ipv6Builder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lsp.object.tlvs.LspIdentifiersBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.Ipv4ExtendedTunnelId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.Ipv6ExtendedTunnelId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.LspId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.TunnelId;
+
+/**
+ * Parser for {@link LspIdentifiersTlv}
+ */
+public class LSPIdentifierTlvParser implements TlvParser, TlvSerializer {
+
+       public static final int TYPE = 18;
+
+       public static final int TYPE_6 = 19;
+
+       private static final int IP6_F_LENGTH = 16;
+       private static final int EX_TUNNEL_ID6_F_LENGTH = 16;
+       private static final int IP4_F_LENGTH = 4;
+       private static final int EX_TUNNEL_ID4_F_LENGTH = 4;
+
+       private static final int LSP_ID_F_LENGTH = 2;
+       private static final int TUNNEL_ID_F_LENGTH = 2;
+
+       private static final int V4_LENGTH = 12;
+       private static final int V6_LENGTH = 36;
+
+       @Override
+       public LspIdentifiersTlv parseTlv(final byte[] valueBytes) throws PCEPDeserializerException {
+               int position = 0;
+               if (valueBytes == null || valueBytes.length == 0) {
+                       throw new IllegalArgumentException("Value bytes array is mandatory. Can't be null or empty.");
+               }
+               AddressFamily afi = null;
+               LspId lspId = null;
+               TunnelId tunnelId = null;
+               if (valueBytes.length == V4_LENGTH) {
+                       final Ipv4Builder builder = new Ipv4Builder();
+                       builder.setIpv4TunnelSenderAddress(Ipv4Util.addressForBytes(ByteArray.subByte(valueBytes, position, IP4_F_LENGTH)));
+                       position += IP4_F_LENGTH;
+                       lspId = new LspId(ByteArray.bytesToLong(ByteArray.subByte(valueBytes, position, LSP_ID_F_LENGTH)));
+                       position += LSP_ID_F_LENGTH;
+                       tunnelId = new TunnelId(ByteArray.bytesToInt(ByteArray.subByte(valueBytes, position, TUNNEL_ID_F_LENGTH)));
+                       position += TUNNEL_ID_F_LENGTH;
+                       builder.setIpv4ExtendedTunnelId(new Ipv4ExtendedTunnelId(Ipv4Util.addressForBytes(ByteArray.subByte(valueBytes, position,
+                                       EX_TUNNEL_ID4_F_LENGTH))));
+                       afi = builder.build();
+                       position += EX_TUNNEL_ID4_F_LENGTH;
+               } else if (valueBytes.length == V6_LENGTH) {
+                       final Ipv6Builder builder = new Ipv6Builder();
+                       builder.setIpv6TunnelSenderAddress(Ipv6Util.addressForBytes(ByteArray.subByte(valueBytes, position, IP6_F_LENGTH)));
+                       position += IP6_F_LENGTH;
+                       lspId = new LspId(ByteArray.bytesToLong(ByteArray.subByte(valueBytes, position, LSP_ID_F_LENGTH)));
+                       position += LSP_ID_F_LENGTH;
+                       tunnelId = new TunnelId(ByteArray.bytesToInt(ByteArray.subByte(valueBytes, position, TUNNEL_ID_F_LENGTH)));
+                       position += TUNNEL_ID_F_LENGTH;
+                       builder.setIpv6ExtendedTunnelId(new Ipv6ExtendedTunnelId(Ipv6Util.addressForBytes(ByteArray.subByte(valueBytes, position,
+                                       EX_TUNNEL_ID6_F_LENGTH))));
+                       afi = builder.build();
+                       position += EX_TUNNEL_ID6_F_LENGTH;
+               } else {
+                       throw new IllegalArgumentException("Length " + valueBytes.length + " does not match LSP Identifiers tlv lengths.");
+               }
+
+               return new LspIdentifiersBuilder().setAddressFamily(afi).setLspId(lspId).setTunnelId(tunnelId).build();
+       }
+
+       @Override
+       public byte[] serializeTlv(final Tlv tlv) {
+               if (tlv == null) {
+                       throw new IllegalArgumentException("LspIdentifiersTlv is mandatory.");
+               }
+               final LspIdentifiersTlv lsp = (LspIdentifiersTlv) tlv;
+               final AddressFamily afi = lsp.getAddressFamily();
+               int offset = 0;
+               if (afi.getImplementedInterface().equals(Ipv4.class)) {
+                       final byte[] bytes = new byte[V4_LENGTH];
+                       final Ipv4 ipv4 = (Ipv4) afi;
+                       ByteArray.copyWhole(Ipv4Util.bytesForAddress(ipv4.getIpv4TunnelSenderAddress()), bytes, offset);
+                       offset += IP4_F_LENGTH;
+                       ByteArray.copyWhole(ByteArray.subByte(ByteArray.longToBytes(lsp.getLspId().getValue()), 6, LSP_ID_F_LENGTH), bytes, offset);
+                       offset += LSP_ID_F_LENGTH;
+                       ByteArray.copyWhole(ByteArray.subByte(ByteArray.intToBytes(lsp.getTunnelId().getValue()), 2, TUNNEL_ID_F_LENGTH), bytes, offset);
+                       offset += TUNNEL_ID_F_LENGTH;
+                       ByteArray.copyWhole(Ipv4Util.bytesForAddress(ipv4.getIpv4ExtendedTunnelId()), bytes, offset);
+                       return bytes;
+               } else {
+                       final byte[] bytes = new byte[V6_LENGTH];
+                       final Ipv6 ipv6 = (Ipv6) afi;
+                       ByteArray.copyWhole(Ipv6Util.bytesForAddress(ipv6.getIpv6TunnelSenderAddress()), bytes, offset);
+                       offset += IP6_F_LENGTH;
+                       ByteArray.copyWhole(ByteArray.subByte(ByteArray.longToBytes(lsp.getLspId().getValue()), 6, LSP_ID_F_LENGTH), bytes, offset);
+                       offset += LSP_ID_F_LENGTH;
+                       ByteArray.copyWhole(ByteArray.subByte(ByteArray.intToBytes(lsp.getTunnelId().getValue()), 2, TUNNEL_ID_F_LENGTH), bytes, offset);
+                       offset += TUNNEL_ID_F_LENGTH;
+                       ByteArray.copyWhole(Ipv6Util.bytesForAddress(ipv6.getIpv6ExtendedTunnelId()), bytes, offset);
+                       return bytes;
+               }
+       }
+
+       @Override
+       public int getType() {
+               return TYPE;
+       }
+
+       public int getType6() {
+               return TYPE_6;
+       }
+}
index 904cf1b52cd3ebec0b70ebaa1598f26bf4179263..2930bcac890b2091a50df5ac483297c5a07c773c 100644 (file)
@@ -33,8 +33,9 @@ public class LspDbVersionTlvParser implements TlvParser, TlvSerializer {
 
        @Override
        public byte[] serializeTlv(final Tlv tlv) {
-               if (tlv == null)
+               if (tlv == null) {
                        throw new IllegalArgumentException("LspDbVersionTlv is mandatory.");
+               }
                final LspDbVersionTlv lsp = (LspDbVersionTlv) tlv;
                return ByteArray.subByte(lsp.getVersion().toByteArray(), 0, DBV_F_LENGTH);
        }
index 1b1ccbcfb619255f5ffee6b2ed67b39a7ae4c18a..7d6043f92ac8041f9120c4b6725f873df2536bcd 100644 (file)
@@ -28,8 +28,9 @@ public class LspSymbolicNameTlvParser implements TlvParser, TlvSerializer {
 
        @Override
        public byte[] serializeTlv(final Tlv tlv) {
-               if (tlv == null)
+               if (tlv == null) {
                        throw new IllegalArgumentException("SymbolicPathNameTlv is mandatory.");
+               }
                final SymbolicPathNameTlv spn = (SymbolicPathNameTlv) tlv;
                return spn.getPathName();
        }
index ad2f67616af17a1b7b425a7f0d4bb5b1bf43e199..6322b42d5590300d2c02524c95946856d577e37b 100644 (file)
@@ -31,10 +31,11 @@ public class LspUpdateErrorTlvParser implements TlvParser, TlvSerializer {
 
        @Override
        public byte[] serializeTlv(final Tlv tlv) {
-               if (tlv == null)
+               if (tlv == null) {
                        throw new IllegalArgumentException("LspErrorCodeTlv is mandatory.");
+               }
                final LspErrorCodeTlv lsp = (LspErrorCodeTlv) tlv;
-               return ByteArray.subByte(ByteArray.longToBytes(lsp.getErrorCode()), 0, UPDATE_ERR_CODE_LENGTH);
+               return ByteArray.subByte(ByteArray.longToBytes(lsp.getErrorCode()), UPDATE_ERR_CODE_LENGTH, UPDATE_ERR_CODE_LENGTH);
        }
 
        @Override
index 510d678043c70593d7d2253af57b69aec91d5b3a..2eba141a7fa374da6580f30252526e75d9f650b1 100644 (file)
@@ -25,56 +25,47 @@ public class NoPathVectorTlvParser implements TlvParser, TlvSerializer {
 
        public static final int TYPE = 1;
 
-       public static final int FLAGS_F_LENGTH = 4;
+       private static final int FLAGS_F_LENGTH = 4;
 
-       /*
-        * flags offsets inside flags field in bits
-        */
-       public static final int PCE_UNAVAILABLE = 31;
-       public static final int UNKNOWN_DEST = 30;
-       public static final int UNKNOWN_SRC = 29;
-
-       /*
-        * flags offsets of flags added by GCO extension
-        */
-       public static final int NO_GCO_SOLUTION = 25;
-       public static final int NO_GCO_MIGRATION_PATH = 26;
-
-       /*
-        * flags offsets of flags added by RFC 6006
-        */
-       public static final int REACHABLITY_PROBLEM = 24;
+       private static final int REACHABLITY_PROBLEM = 24;
+       private static final int NO_GCO_SOLUTION = 25;
+       private static final int NO_GCO_MIGRATION_PATH = 26;
+       private static final int PATH_KEY = 27;
+       private static final int CHAIN_UNAVAILABLE = 28;
+       private static final int UNKNOWN_SRC = 29;
+       private static final int UNKNOWN_DEST = 30;
+       private static final int PCE_UNAVAILABLE = 31;
 
        @Override
        public NoPathVectorTlv parseTlv(final byte[] valueBytes) throws PCEPDeserializerException {
-               if (valueBytes == null || valueBytes.length == 0)
+               if (valueBytes == null || valueBytes.length == 0) {
                        throw new IllegalArgumentException("Array of bytes is mandatory. Can't be null or empty.");
-
-               if (valueBytes.length != FLAGS_F_LENGTH)
+               }
+               if (valueBytes.length != FLAGS_F_LENGTH) {
                        throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + valueBytes.length + "; Expected: >="
                                        + FLAGS_F_LENGTH + ".");
-
+               }
                final BitSet flags = ByteArray.bytesToBitSet(valueBytes);
-
                return new NoPathVectorBuilder().setFlags(
-                               new Flags(false, flags.get(NO_GCO_MIGRATION_PATH), flags.get(NO_GCO_SOLUTION), flags.get(REACHABLITY_PROBLEM), false, flags.get(PCE_UNAVAILABLE), flags.get(UNKNOWN_DEST), flags.get(UNKNOWN_SRC))).build();
+                               new Flags(flags.get(CHAIN_UNAVAILABLE), flags.get(NO_GCO_MIGRATION_PATH), flags.get(NO_GCO_SOLUTION), flags.get(REACHABLITY_PROBLEM), flags.get(PATH_KEY), flags.get(PCE_UNAVAILABLE), flags.get(UNKNOWN_DEST), flags.get(UNKNOWN_SRC))).build();
        }
 
        @Override
        public byte[] serializeTlv(final Tlv tlvs) {
-               if (tlvs == null)
+               if (tlvs == null) {
                        throw new IllegalArgumentException("NoPathVectorTlv is mandatory.");
+               }
                final NoPathVectorTlv tlv = (NoPathVectorTlv) tlvs;
 
                final BitSet flags = new BitSet(FLAGS_F_LENGTH * Byte.SIZE);
-
-               flags.set(PCE_UNAVAILABLE, tlv.getFlags().isPceUnavailable());
-               flags.set(UNKNOWN_DEST, tlv.getFlags().isUnknownDestination());
-               flags.set(UNKNOWN_SRC, tlv.getFlags().isUnknownSource());
+               flags.set(REACHABLITY_PROBLEM, tlv.getFlags().isP2mpUnreachable());
                flags.set(NO_GCO_SOLUTION, tlv.getFlags().isNoGcoSolution());
                flags.set(NO_GCO_MIGRATION_PATH, tlv.getFlags().isNoGcoMigration());
-               flags.set(REACHABLITY_PROBLEM, tlv.getFlags().isP2mpUnreachable());
-
+               flags.set(PATH_KEY, tlv.getFlags().isPathKey());
+               flags.set(CHAIN_UNAVAILABLE, tlv.getFlags().isChainUnavailable());
+               flags.set(UNKNOWN_SRC, tlv.getFlags().isUnknownSource());
+               flags.set(UNKNOWN_DEST, tlv.getFlags().isUnknownDestination());
+               flags.set(PCE_UNAVAILABLE, tlv.getFlags().isPceUnavailable());
                return ByteArray.bitSetToBytes(flags, FLAGS_F_LENGTH);
        }
 
index 6be36248c74c282610c9911dba599e252e7aae5e..f0cb131590aa2aaee0813f87dbf109014d3dfcc9 100644 (file)
@@ -33,11 +33,12 @@ public class OFListTlvParser implements TlvParser, TlvSerializer {
 
        @Override
        public OfListTlv parseTlv(final byte[] valueBytes) throws PCEPDeserializerException {
-               if (valueBytes == null || valueBytes.length == 0)
+               if (valueBytes == null || valueBytes.length == 0) {
                        throw new IllegalArgumentException("Value bytes array is mandatory. Can't be null or empty.");
-               if (valueBytes.length % OF_CODE_ELEMENT_LENGTH != 0)
+               }
+               if (valueBytes.length % OF_CODE_ELEMENT_LENGTH != 0) {
                        throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + valueBytes.length + ".");
-
+               }
                final List<OfId> ofCodes = Lists.newArrayList();
                for (int i = 0; i < valueBytes.length; i += OF_CODE_ELEMENT_LENGTH) {
                        try {
@@ -51,8 +52,9 @@ public class OFListTlvParser implements TlvParser, TlvSerializer {
 
        @Override
        public byte[] serializeTlv(final Tlv tlv) {
-               if (tlv == null)
+               if (tlv == null) {
                        throw new IllegalArgumentException("OFListTlv is mandatory.");
+               }
                final OfListTlv oft = (OfListTlv) tlv;
 
                final List<OfId> ofCodes = oft.getCodes();
index 13b441dce906e4cbf6513447686fa6eb3cee9c10..3eb2cfe9f746fdb543407aa2d6cee3e955a16d62 100644 (file)
@@ -34,19 +34,16 @@ public class OrderTlvParser implements TlvParser, TlvSerializer {
 
        @Override
        public byte[] serializeTlv(final Tlv tlv) {
-               if (tlv == null)
+               if (tlv == null) {
                        throw new IllegalArgumentException("OrderTlv is mandatory.");
+               }
                final OrderTlv otlv = (OrderTlv) tlv;
-
-               // final byte[] bytes = new byte[];
-               // FIXME: finish
-
-               final byte[] delete = ByteArray.subByte(ByteArray.longToBytes(otlv.getDelete()), 4, ORDR_DEL_LENGTH);
-               // buffer.writeBytes(delete);
-               final byte[] setup = ByteArray.subByte(ByteArray.longToBytes(otlv.getSetup()), 4, ORDR_SETUP_LENGTH);
-               // buffer.writeBytes(setup);
-
-               return new byte[5];
+               final byte[] bytes = new byte[ORDR_DEL_LENGTH + ORDR_SETUP_LENGTH];
+               int offset = 0;
+               ByteArray.copyWhole(ByteArray.subByte(ByteArray.longToBytes(otlv.getDelete()), 4, ORDR_DEL_LENGTH), bytes, offset);
+               offset += ORDR_DEL_LENGTH;
+               ByteArray.copyWhole(ByteArray.subByte(ByteArray.longToBytes(otlv.getSetup()), 4, ORDR_SETUP_LENGTH), bytes, offset);
+               return bytes;
        }
 
        @Override
index b75a748dd8e8b971c0d418333ccef54d4af29634..b1879299895cb72bc87b0ab9e01c6ea11261f7c9 100644 (file)
@@ -1,5 +1,9 @@
-/**
- * 
+/*
+ * 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.tlv;
 
@@ -28,10 +32,11 @@ public class OverloadedDurationTlvParser implements TlvParser, TlvSerializer {
 
        @Override
        public byte[] serializeTlv(final Tlv tlv) {
-               if (tlv == null)
+               if (tlv == null) {
                        throw new IllegalArgumentException("OverloadedTlv is mandatory.");
+               }
                final OverloadDurationTlv odt = (OverloadDurationTlv) tlv;
-               return ByteArray.subByte(ByteArray.longToBytes(odt.getDuration()), 4, OVERLOADED_DURATION_LENGTH);
+               return ByteArray.subByte(ByteArray.longToBytes(odt.getDuration()), OVERLOADED_DURATION_LENGTH, OVERLOADED_DURATION_LENGTH);
        }
 
        @Override
index a20a9b1cb87263ce4e948b2045ac85d63a456e6b..aa8f7978a351e90132f41c9f5da1d6952d08f4ea 100644 (file)
@@ -24,25 +24,22 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.typ
 public final class PCEStatefulCapabilityTlvParser implements TlvParser, TlvSerializer {
 
        public static final int TYPE = 16;
-       /*
-        * Flags field length in Bytes
-        */
-       public static final int FLAGS_F_LENGTH = 4;
 
-       /*
-        * Offsets inside flags field in bits;
-        */
-       public static final int I_FLAG_OFFSET = 29;
-       public static final int S_FLAG_OFFSET = 30;
-       public static final int U_FLAG_OFFSET = 31;
+       private static final int FLAGS_F_LENGTH = 4;
+
+       private static final int I_FLAG_OFFSET = 29;
+       private static final int S_FLAG_OFFSET = 30;
+       private static final int U_FLAG_OFFSET = 31;
 
        @Override
        public StatefulCapabilityTlv parseTlv(final byte[] buffer) throws PCEPDeserializerException {
-               if (buffer == null || buffer.length == 0)
+               if (buffer == null || buffer.length == 0) {
                        throw new IllegalArgumentException("Value bytes array is mandatory. Can't be null or empty.");
-               if (buffer.length < FLAGS_F_LENGTH)
+               }
+               if (buffer.length < FLAGS_F_LENGTH) {
                        throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.length + "; Expected: >= "
                                        + FLAGS_F_LENGTH + ".");
+               }
 
                final BitSet flags = ByteArray.bytesToBitSet(ByteArray.subByte(buffer, 0, FLAGS_F_LENGTH));
                return new StatefulBuilder().setFlags(new Flags(flags.get(S_FLAG_OFFSET), flags.get(I_FLAG_OFFSET), flags.get(U_FLAG_OFFSET))).build();
@@ -50,8 +47,9 @@ public final class PCEStatefulCapabilityTlvParser implements TlvParser, TlvSeria
 
        @Override
        public byte[] serializeTlv(final Tlv tlv) {
-               if (tlv == null)
+               if (tlv == null) {
                        throw new IllegalArgumentException("StatefulCapabilityTlv is mandatory.");
+               }
                final StatefulCapabilityTlv sct = (StatefulCapabilityTlv) tlv;
 
                final BitSet flags = new BitSet(FLAGS_F_LENGTH * Byte.SIZE);
index c7513a232f82864131e13f65a469866f3e66221d..2fcdadbb39d1b56da811a95fc084724104cbf62b 100644 (file)
@@ -15,6 +15,7 @@ import org.opendaylight.protocol.pcep.PCEPDeserializerException;
 import org.opendaylight.protocol.pcep.spi.TlvParser;
 import org.opendaylight.protocol.pcep.spi.TlvSerializer;
 import org.opendaylight.protocol.util.ByteArray;
+import org.opendaylight.protocol.util.Util;
 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.types.rev131005.RsvpErrorSpecTlv;
@@ -23,9 +24,11 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.typ
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.rsvp.error.spec.tlv.ErrorType;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.rsvp.error.spec.tlv.error.type.Rsvp;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.rsvp.error.spec.tlv.error.type.RsvpBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.rsvp.error.spec.tlv.error.type.User;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.rsvp.error.spec.tlv.error.type.UserBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.rsvp.error.spec.tlv.error.type.rsvp.RsvpError;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.rsvp.error.spec.tlv.error.type.rsvp.RsvpErrorBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.rsvp.error.spec.tlv.error.type.user.UserError;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.rsvp.error.spec.tlv.error.type.user.UserErrorBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.ErrorSpec.Flags;
 
@@ -34,7 +37,9 @@ import com.google.common.primitives.UnsignedBytes;
 /**
  * Parser for {@link RsvpErrorSpecTlv}
  */
-public class RSVPErrorSpecTlvParser implements TlvParser, TlvSerializer {
+public final class RSVPErrorSpecTlvParser implements TlvParser, TlvSerializer {
+
+       public static final int TYPE = 21;
 
        private static final int IP4_F_LENGTH = 4;
        private static final int IP6_F_LENGTH = 16;
@@ -54,88 +59,139 @@ public class RSVPErrorSpecTlvParser implements TlvParser, TlvSerializer {
        private static final int USER_ERROR_CLASS_NUM = 194;
        private static final int USER_ERROR_CLASS_TYPE = 1;
 
-       public static final int TYPE = 21;
-
-       /*
-        * flags offsets inside flags field in bits
-        */
        private static final int IN_PLACE_FLAG_OFFSET = 7;
        private static final int NOT_GUILTY_FLAGS_OFFSET = 6;
 
+       private static final int V4_RSVP_LENGTH = 10;
+       private static final int V6_RSVP_LENGTH = 22;
+
        @Override
        public RsvpErrorSpecTlv parseTlv(final byte[] valueBytes) throws PCEPDeserializerException {
-               if (valueBytes == null || valueBytes.length == 0)
+               if (valueBytes == null || valueBytes.length == 0) {
                        throw new IllegalArgumentException("Value bytes array is mandatory. Can't be null or empty.");
+               }
 
-               final int classNum = ByteArray.bytesToInt(ByteArray.subByte(valueBytes, 2, 1));
-               final int classType = ByteArray.bytesToInt(ByteArray.subByte(valueBytes, 3, 1));
+               final int classNum = ByteArray.bytesToInt(ByteArray.subByte(valueBytes, 0, 1));
+               final int classType = ByteArray.bytesToInt(ByteArray.subByte(valueBytes, 1, 1));
 
                ErrorType errorType = null;
-               int byteOffset = 0;
+               final int byteOffset = 2;
 
                if (classNum == RSVP_ERROR_CLASS_NUM) {
-                       final RsvpErrorBuilder builder = new RsvpErrorBuilder();
-                       if (classType == RSVP_IPV4_ERROR_CLASS_TYPE) {
-                               builder.setNode(new IpAddress(Ipv4Util.addressForBytes(ByteArray.subByte(valueBytes, byteOffset, IP4_F_LENGTH))));
-                               byteOffset += IP4_F_LENGTH;
-                       } else if (classType == RSVP_IPV6_ERROR_CLASS_TYPE) {
-                               builder.setNode(new IpAddress(Ipv6Util.addressForBytes(ByteArray.subByte(valueBytes, byteOffset, IP6_F_LENGTH))));
-                               byteOffset += IP6_F_LENGTH;
-                       }
-                       final BitSet flags = ByteArray.bytesToBitSet(ByteArray.subByte(valueBytes, byteOffset, FLAGS_F_LENGTH));
-                       byteOffset += FLAGS_F_LENGTH;
-
-                       final short errorCode = (short) (valueBytes[byteOffset] & 0xFF);
-                       byteOffset += ERROR_CODE_F_LENGTH;
-                       final int errorValue = (ByteArray.bytesToShort(ByteArray.subByte(valueBytes, byteOffset, ERROR_VALUE_F_LENGTH)) & 0xFFFF);
-
-                       errorType = new RsvpBuilder().setRsvpError(
-                                       builder.setFlags(new Flags(flags.get(IN_PLACE_FLAG_OFFSET), flags.get(NOT_GUILTY_FLAGS_OFFSET))).setCode(errorCode).setValue(
-                                                       errorValue).build()).build();
+                       errorType = parseRsvp(classType, ByteArray.cutBytes(valueBytes, byteOffset));
                } else if (classNum == USER_ERROR_CLASS_NUM && classType == USER_ERROR_CLASS_TYPE) {
-                       final UserErrorBuilder error = new UserErrorBuilder();
-                       error.setEnterprise(new EnterpriseNumber(ByteArray.bytesToLong(ByteArray.subByte(valueBytes, byteOffset, ENTERPRISE_F_LENGTH))));
-                       byteOffset += ENTERPRISE_F_LENGTH;
-                       error.setSubOrg(ByteArray.bytesToShort(ByteArray.subByte(valueBytes, byteOffset, SUB_ORG_F_LENGTH)));
-                       byteOffset += SUB_ORG_F_LENGTH;
-                       final int errDescrLength = UnsignedBytes.toInt(valueBytes[byteOffset]);
-                       byteOffset += ERR_DESCR_LENGTH_F_LENGTH;
-                       error.setValue(ByteArray.bytesToInt(ByteArray.subByte(valueBytes, byteOffset, USER_VALUE_F_LENGTH)));
-                       byteOffset += USER_VALUE_F_LENGTH;
-                       error.setDescription(ByteArray.bytesToHRString(ByteArray.subByte(valueBytes, byteOffset, errDescrLength)));
-                       byteOffset += errDescrLength;
-                       if (byteOffset < valueBytes.length) {
-                               // TODO: if we have any subobjects
-                               // error.setSubobjects(new SubobjectsBuilder().build());
-                       }
-                       errorType = new UserBuilder().setUserError(error.build()).build();
+                       errorType = parseUserError(ByteArray.cutBytes(valueBytes, byteOffset));
                }
-
                return new RsvpErrorSpecBuilder().setErrorType(errorType).build();
        }
 
        @Override
        public byte[] serializeTlv(final Tlv tlv) {
-               if (tlv == null)
+               if (tlv == null) {
                        throw new IllegalArgumentException("RSVPErrorSpecTlv is mandatory.");
+               }
                final RsvpErrorSpecTlv rsvp = (RsvpErrorSpecTlv) tlv;
 
-               if (rsvp.getErrorType().getClass().equals(Rsvp.class)) {
+               if (rsvp.getErrorType().getImplementedInterface().equals(Rsvp.class)) {
                        final Rsvp r = (Rsvp) rsvp.getErrorType();
-                       final RsvpError e = r.getRsvpError();
-                       final BitSet flags = new BitSet(FLAGS_F_LENGTH * Byte.SIZE);
-                       flags.set(IN_PLACE_FLAG_OFFSET, e.getFlags().isInPlace());
-                       flags.set(NOT_GUILTY_FLAGS_OFFSET, e.getFlags().isNotGuilty());
-                       final IpAddress node = e.getNode();
-                       if (node.getIpv4Address() != null) {
+                       return serializeRsvp(r.getRsvpError());
+               } else {
+                       final User u = (User) rsvp.getErrorType();
+                       return serializerUserError(u.getUserError());
+               }
+       }
 
-                       }
+       private User parseUserError(final byte[] valueBytes) {
+               final UserErrorBuilder error = new UserErrorBuilder();
+               int byteOffset = 0;
+               error.setEnterprise(new EnterpriseNumber(ByteArray.bytesToLong(ByteArray.subByte(valueBytes, byteOffset, ENTERPRISE_F_LENGTH))));
+               byteOffset += ENTERPRISE_F_LENGTH;
+               error.setSubOrg((short) UnsignedBytes.toInt(valueBytes[byteOffset]));
+               byteOffset += SUB_ORG_F_LENGTH;
+               final int errDescrLength = UnsignedBytes.toInt(valueBytes[byteOffset]);
+               byteOffset += ERR_DESCR_LENGTH_F_LENGTH;
+               error.setValue(ByteArray.bytesToInt(ByteArray.subByte(valueBytes, byteOffset, USER_VALUE_F_LENGTH)));
+               byteOffset += USER_VALUE_F_LENGTH;
+               error.setDescription(ByteArray.bytesToHRString(ByteArray.subByte(valueBytes, byteOffset, errDescrLength)));
+               byteOffset += errDescrLength;
+               // TODO: if we have any subobjects
+               return new UserBuilder().setUserError(error.build()).build();
+       }
 
-               } else {
+       private byte[] serializerUserError(final UserError ue) {
+               final byte[] enterprise = ByteArray.subByte(ByteArray.longToBytes(ue.getEnterprise().getValue()), 4, ENTERPRISE_F_LENGTH);
+               final byte suborg = UnsignedBytes.checkedCast(ue.getSubOrg());
+               final byte[] value = ByteArray.subByte(ByteArray.intToBytes(ue.getValue()), 2, USER_VALUE_F_LENGTH);
+               final byte[] desc = (ue.getDescription() == null) ? new byte[0] : ue.getDescription().getBytes();
+               final byte descLen = UnsignedBytes.checkedCast(desc.length);
+               // TODO: if we have any subobjects
+               final byte[] bytes = new byte[2 + ENTERPRISE_F_LENGTH + SUB_ORG_F_LENGTH + USER_VALUE_F_LENGTH + ERR_DESCR_LENGTH_F_LENGTH
+                               + desc.length];
+               bytes[0] = UnsignedBytes.checkedCast(USER_ERROR_CLASS_NUM);
+               bytes[1] = UnsignedBytes.checkedCast(USER_ERROR_CLASS_TYPE);
+               int offset = 2;
+               ByteArray.copyWhole(enterprise, bytes, offset);
+               offset += ENTERPRISE_F_LENGTH;
+               bytes[offset] = suborg;
+               offset += SUB_ORG_F_LENGTH;
+               bytes[offset] = descLen;
+               offset += ERR_DESCR_LENGTH_F_LENGTH;
+               ByteArray.copyWhole(value, bytes, offset);
+               offset += USER_VALUE_F_LENGTH;
+               ByteArray.copyWhole(desc, bytes, offset);
+               return bytes;
+       }
 
+       private Rsvp parseRsvp(final int classType, final byte[] valueBytes) {
+               int byteOffset = 0;
+               final RsvpErrorBuilder builder = new RsvpErrorBuilder();
+               if (classType == RSVP_IPV4_ERROR_CLASS_TYPE) {
+                       builder.setNode(new IpAddress(Ipv4Util.addressForBytes(ByteArray.subByte(valueBytes, byteOffset, IP4_F_LENGTH))));
+                       byteOffset += IP4_F_LENGTH;
+               } else if (classType == RSVP_IPV6_ERROR_CLASS_TYPE) {
+                       builder.setNode(new IpAddress(Ipv6Util.addressForBytes(ByteArray.subByte(valueBytes, byteOffset, IP6_F_LENGTH))));
+                       byteOffset += IP6_F_LENGTH;
+               }
+               final BitSet flags = ByteArray.bytesToBitSet(ByteArray.subByte(valueBytes, byteOffset, FLAGS_F_LENGTH));
+               byteOffset += FLAGS_F_LENGTH;
+               builder.setFlags(new Flags(flags.get(IN_PLACE_FLAG_OFFSET), flags.get(NOT_GUILTY_FLAGS_OFFSET)));
+               final short errorCode = (short) (valueBytes[byteOffset] & Util.BYTE_MAX_VALUE_BYTES);
+               byteOffset += ERROR_CODE_F_LENGTH;
+               builder.setCode(errorCode);
+               final int errorValue = (ByteArray.bytesToShort(ByteArray.subByte(valueBytes, byteOffset, ERROR_VALUE_F_LENGTH)) & 0xFFFF);
+               builder.setValue(errorValue);
+               return new RsvpBuilder().setRsvpError(builder.build()).build();
+       }
+
+       private byte[] serializeRsvp(final RsvpError rsvp) {
+               final BitSet flags = new BitSet(FLAGS_F_LENGTH * Byte.SIZE);
+               flags.set(IN_PLACE_FLAG_OFFSET, rsvp.getFlags().isInPlace());
+               flags.set(NOT_GUILTY_FLAGS_OFFSET, rsvp.getFlags().isNotGuilty());
+               int offset = 0;
+               final IpAddress node = rsvp.getNode();
+               byte[] bytes;
+               if (node.getIpv4Address() != null) {
+                       bytes = new byte[V4_RSVP_LENGTH];
+                       bytes[0] = RSVP_ERROR_CLASS_NUM;
+                       bytes[1] = RSVP_IPV4_ERROR_CLASS_TYPE;
+                       offset += 2;
+                       ByteArray.copyWhole(Ipv4Util.bytesForAddress(node.getIpv4Address()), bytes, offset);
+                       offset += IP4_F_LENGTH;
+               } else {
+                       bytes = new byte[V6_RSVP_LENGTH];
+                       bytes[0] = RSVP_ERROR_CLASS_NUM;
+                       bytes[1] = RSVP_IPV6_ERROR_CLASS_TYPE;
+                       offset += 2;
+                       ByteArray.copyWhole(Ipv6Util.bytesForAddress(node.getIpv6Address()), bytes, offset);
+                       offset += IP6_F_LENGTH;
                }
-               // TODO: finish
-               return null;
+               bytes[offset] = ByteArray.bitSetToBytes(flags, FLAGS_F_LENGTH)[0];
+               offset += FLAGS_F_LENGTH;
+               bytes[offset] = UnsignedBytes.checkedCast(rsvp.getCode());
+               offset += ERROR_CODE_F_LENGTH;
+               final byte[] value = ByteArray.subByte(ByteArray.intToBytes(rsvp.getValue().intValue()), 2, ERROR_VALUE_F_LENGTH);
+               ByteArray.copyWhole(value, bytes, offset);
+               return bytes;
        }
 
        @Override
index ee967b435288ed9fb14e68409c175d638adec246..9ef75ce1f639f763afafbc34e5dbfa948eb99da9 100644 (file)
@@ -21,10 +21,10 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.typ
  */
 public class ReqMissingTlvParser implements TlvParser, TlvSerializer {
 
-       private static final int REQ_ID_LENGTH = 4;
-
        public static final int TYPE = 3;
 
+       private static final int REQ_ID_LENGTH = 4;
+
        @Override
        public ReqMissingTlv parseTlv(final byte[] buffer) throws PCEPDeserializerException {
                return new ReqMissingBuilder().setRequestId(new RequestId(ByteArray.bytesToLong(ByteArray.subByte(buffer, 0, REQ_ID_LENGTH)))).build();
@@ -32,10 +32,11 @@ public class ReqMissingTlvParser implements TlvParser, TlvSerializer {
 
        @Override
        public byte[] serializeTlv(final Tlv tlv) {
-               if (tlv == null)
+               if (tlv == null) {
                        throw new IllegalArgumentException("ReqMissingTlv is mandatory.");
+               }
                final ReqMissingTlv req = (ReqMissingTlv) tlv;
-               return ByteArray.subByte(ByteArray.longToBytes(req.getRequestId().getValue()), 4, REQ_ID_LENGTH);
+               return ByteArray.subByte(ByteArray.longToBytes(req.getRequestId().getValue()), REQ_ID_LENGTH, REQ_ID_LENGTH);
        }
 
        @Override
index 021b8891f83ccae385949a1514ddfa6bd2df9e86..dc20e2848fca1fb7eee6d623dcb2896af6a59733 100644 (file)
  */
 package org.opendaylight.protocol.pcep.impl;
 
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+
+import java.math.BigInteger;
+import java.util.List;
+
+import org.junit.Test;
+import org.opendaylight.protocol.concepts.Ipv4Util;
+import org.opendaylight.protocol.concepts.Ipv6Util;
+import org.opendaylight.protocol.pcep.PCEPDeserializerException;
+import org.opendaylight.protocol.pcep.impl.tlv.LSPIdentifierTlvParser;
+import org.opendaylight.protocol.pcep.impl.tlv.LspDbVersionTlvParser;
+import org.opendaylight.protocol.pcep.impl.tlv.LspSymbolicNameTlvParser;
+import org.opendaylight.protocol.pcep.impl.tlv.LspUpdateErrorTlvParser;
+import org.opendaylight.protocol.pcep.impl.tlv.NoPathVectorTlvParser;
+import org.opendaylight.protocol.pcep.impl.tlv.OFListTlvParser;
+import org.opendaylight.protocol.pcep.impl.tlv.OrderTlvParser;
+import org.opendaylight.protocol.pcep.impl.tlv.OverloadedDurationTlvParser;
+import org.opendaylight.protocol.pcep.impl.tlv.PCEStatefulCapabilityTlvParser;
+import org.opendaylight.protocol.pcep.impl.tlv.PredundancyGroupTlvParser;
+import org.opendaylight.protocol.pcep.impl.tlv.RSVPErrorSpecTlvParser;
+import org.opendaylight.protocol.pcep.impl.tlv.ReqMissingTlvParser;
+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.types.rev131005.LspDbVersionTlv;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.LspErrorCodeTlv;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.LspIdentifiersTlv;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.NoPathVectorTlv;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.OfId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.OfListTlv;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.OrderTlv;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.OverloadDurationTlv;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.PredundancyGroupIdTlv;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ReqMissingTlv;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.RequestId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.RsvpErrorSpecTlv;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.StatefulCapabilityTlv;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.StatefulCapabilityTlv.Flags;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.SymbolicPathNameTlv;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lsp.identifiers.tlv.address.family.Ipv4Builder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lsp.identifiers.tlv.address.family.Ipv6Builder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lsp.object.tlvs.LspErrorCodeBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lsp.object.tlvs.LspIdentifiersBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lsp.object.tlvs.RsvpErrorSpecBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lsp.object.tlvs.SymblicPathNameBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.notification.object.tlvs.OverloadDurationBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.tlvs.LspDbVersionBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.tlvs.OfListBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.tlvs.PredundancyGroupIdBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.tlvs.StatefulBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcep.error.object.tlvs.ReqMissingBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcrep.message.pcrep.message.replies.result.failure.no.path.tlvs.NoPathVectorBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.rp.object.tlvs.OrderBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.rsvp.error.spec.tlv.error.type.RsvpBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.rsvp.error.spec.tlv.error.type.UserBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.rsvp.error.spec.tlv.error.type.rsvp.RsvpErrorBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.rsvp.error.spec.tlv.error.type.user.UserErrorBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.Ipv4ExtendedTunnelId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.Ipv6ExtendedTunnelId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.LspId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.TunnelId;
+
+import com.google.common.collect.Lists;
 
-/**
- * Tests of PCEPTlvParser
- */
 public class PCEPTlvParserTest {
 
-       // @Test
-       // public void testDeserialization() throws PCEPDeserializerException, IOException {
-       // final byte[] bytesFromFile = ByteArray.fileToBytes("src/test/resources/PackOfTlvs.bin");
-       // final List<PCEPTlv> tlvsToTest = PCEPTlvParser.parseTlv(bytesFromFile);
-       //
-       // assertEquals(17, tlvsToTest.size());
-       // assertEquals(tlvsToTest.get(0), new PCEStatefulCapabilityTlv(false, false, true));
-       // assertEquals(tlvsToTest.get(1), new LSPStateDBVersionTlv(0xFF00FFAAB2F5F2CFL));
-       // assertEquals(tlvsToTest.get(2), new PCEStatefulCapabilityTlv(false, true, true));
-       // assertEquals(tlvsToTest.get(3), new LSPStateDBVersionTlv(0xFFFFFFFFFFFFFFFFL));
-       // assertEquals(tlvsToTest.get(4), new NoPathVectorTlv(true, true, true, false, true, true));
-       // assertEquals(tlvsToTest.get(5), new OverloadedDurationTlv(0x7FFFFFFF));
-       // assertEquals(tlvsToTest.get(6), new LSPSymbolicNameTlv(new LSPSymbolicName(new
-       // String("Med test of symbolic name").getBytes())));
-       // final byte[] errorCode = { (byte) 0x25, (byte) 0x68, (byte) 0x95, (byte) 0x03 };
-       // assertEquals(tlvsToTest.get(7), new LSPUpdateErrorTlv(errorCode));
-       // final byte[] ipv4Address = { (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78 };
-       // final byte[] tunnelId1 = { (byte) 0x12, (byte) 0x34 };
-       // final byte[] extendedTunnelID1 = { (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78 };
-       // final byte[] lspId1 = { (byte) 0xFF, (byte) 0xFF };
-       // assertEquals(tlvsToTest.get(8), new IPv4LSPIdentifiersTlv(new IPv4Address(ipv4Address),
-       // new LSPIdentifier(lspId1), new TunnelIdentifier(tunnelId1), new IPv4ExtendedTunnelIdentifier(new
-       // IPv4Address(extendedTunnelID1))));
-       // final byte[] ipv6Address = { (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 };
-       // final byte[] tunnelId2 = { (byte) 0xFF, (byte) 0xFF };
-       // final byte[] extendedTunnelID2 = { (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78, (byte) 0x12, (byte) 0x34,
-       // (byte) 0x56, (byte) 0x78, (byte) 0x01,
-       // (byte) 0x23, (byte) 0x45, (byte) 0x67, (byte) 0x01, (byte) 0x23, (byte) 0x45, (byte) 0x67 };
-       // final byte[] lspId2 = { (byte) 0x12, (byte) 0x34 };
-       // assertEquals(tlvsToTest.get(9), new IPv6LSPIdentifiersTlv(new IPv6Address(ipv6Address),
-       // new LSPIdentifier(lspId2), new TunnelIdentifier(tunnelId2), new IPv6ExtendedTunnelIdentifier(new
-       // IPv6Address(extendedTunnelID2))));
-       // assertEquals(tlvsToTest.get(10), new RSVPErrorSpecTlv<IPv4Address>(new IPv4Address(ipv4Address), false, true,
-       // 0x92, 0x1602));
-       // assertEquals(tlvsToTest.get(11), new RSVPErrorSpecTlv<IPv6Address>(new IPv6Address(ipv6Address), true, false,
-       // 0xD5, 0xC5D9));
-       // assertEquals(tlvsToTest.get(12), new ReqMissingTlv(0xF7823517L));
-       // final byte[] valueBytes = { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF };
-       // assertEquals(tlvsToTest.get(13), new NodeIdentifierTlv(valueBytes));
-       // assertEquals(tlvsToTest.get(14), new OrderTlv(0xFFFFFFFFL, 0x00000001L));
-       // assertEquals(tlvsToTest.get(15), new OFListTlv(new ArrayList<PCEPOFCodes>() {
-       // private static final long serialVersionUID = 1L;
-       //
-       // {
-       // this.add(PCEPOFCodes.MCC);
-       // this.add(PCEPOFCodes.MCP);
-       // this.add(PCEPOFCodes.MLL);
-       // }
-       // }));
-       // assertEquals(tlvsToTest.get(16), new P2MPCapabilityTlv(2));
-       //
-       // assertArrayEquals(bytesFromFile, PCEPTlvParser.put(tlvsToTest));
-       // }
-       //
-       // @Test
-       // public void testDifferentLengthExceptions() {
-       // final byte[] bytes = { (byte) 0x00 }; // not empty but not enought data
-       // // for parsing subobjects
-       //
-       // try {
-       // LSPIdentifierIPv4TlvParser.parse(bytes);
-       // fail("");
-       // } catch (final PCEPDeserializerException e) {
-       // }
-       //
-       // try {
-       // LSPIdentifierIPv6TlvParser.parse(bytes);
-       // fail("");
-       // } catch (final PCEPDeserializerException e) {
-       // }
-       //
-       // try {
-       // PCEStatefulCapabilityTlvParser.deserializeValueField(bytes);
-       // fail("");
-       // } catch (final PCEPDeserializerException e) {
-       // }
-       //
-       // try {
-       // RSVPErrorSpecTlvParser.parse(bytes);
-       // fail("");
-       // } catch (final PCEPDeserializerException e) {
-       // }
-       //
-       // try {
-       // RSVPErrorSpecIPv6TlvParser.parse(bytes);
-       // fail("");
-       // } catch (final PCEPDeserializerException e) {
-       // }
-       //
-       // try {
-       // OFListTlvParser.parse(bytes);
-       // fail("");
-       // } catch (final PCEPDeserializerException e) {
-       // }
-       // }
-       //
-       // @Test
-       // public void testUnknownInstanceExceptions() {
-       // try {
-       // LSPIdentifierIPv4TlvParser.put(null);
-       // fail("");
-       // } catch (final IllegalArgumentException e) {
-       // }
-       //
-       // try {
-       // LSPIdentifierIPv6TlvParser.put(null);
-       // fail("");
-       // } catch (final IllegalArgumentException e) {
-       // }
-       //
-       // try {
-       // PCEStatefulCapabilityTlvParser.serializeValueField(null);
-       // fail("");
-       // } catch (final IllegalArgumentException e) {
-       // }
-       //
-       // try {
-       // RSVPErrorSpecTlvParser.put(null);
-       // fail("");
-       // } catch (final IllegalArgumentException e) {
-       // }
-       //
-       // try {
-       // RSVPErrorSpecIPv6TlvParser.put(null);
-       // fail("");
-       // } catch (final IllegalArgumentException e) {
-       // }
-       //
-       // try {
-       // OFListTlvParser.put(null);
-       // fail("");
-       // } catch (final IllegalArgumentException e) {
-       // }
-       //
-       // }
-       //
-       // @Test
-       // public void testEmptyExceptions() throws PCEPDeserializerException {
-       // final byte[] bytes = {}; // empty
-       //
-       // try {
-       // LSPIdentifierIPv4TlvParser.parse(bytes);
-       // fail("");
-       // } catch (final IllegalArgumentException e) {
-       // }
-       //
-       // try {
-       // LSPIdentifierIPv6TlvParser.parse(bytes);
-       // fail("");
-       // } catch (final IllegalArgumentException e) {
-       // }
-       //
-       // try {
-       // PCEStatefulCapabilityTlvParser.deserializeValueField(bytes);
-       // fail("");
-       // } catch (final IllegalArgumentException e) {
-       // }
-       //
-       // try {
-       // RSVPErrorSpecTlvParser.parse(bytes);
-       // fail("");
-       // } catch (final IllegalArgumentException e) {
-       // }
-       //
-       // try {
-       // RSVPErrorSpecIPv6TlvParser.parse(bytes);
-       // fail("");
-       // } catch (final IllegalArgumentException e) {
-       // }
-       //
-       // try {
-       // OFListTlvParser.parse(bytes);
-       // fail("");
-       // } catch (final IllegalArgumentException e) {
-       // }
-       // }
+       private static final byte[] statefulBytes = { (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x02 };
+       private static final byte[] DbVersionBytes = { (byte) 0xff, (byte) 0x00, (byte) 0xff, (byte) 0xaa, (byte) 0xb2, (byte) 0xf5,
+                       (byte) 0xf2, (byte) 0xcf };
+       private static final byte[] noPathVectorBytes = { (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0xa7 };
+       private static final byte[] overloadedBytes = { (byte) 0x7f, (byte) 0xff, (byte) 0xff, (byte) 0xff };
+       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[] lspUpdateErrorBytes = { (byte) 0x25, (byte) 0x68, (byte) 0x95, (byte) 0x03 };
+       private static final byte[] lspIdentifiers4Bytes = { (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78, (byte) 0xFF, (byte) 0xFF,
+                       (byte) 0x12, (byte) 0x34, (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78 };
+       private static final byte[] lspIdentifiers6Bytes = { (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) 0x12, (byte) 0x34, (byte) 0xFF, (byte) 0xFF, (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78,
+                       (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78, (byte) 0x01, (byte) 0x23, (byte) 0x45, (byte) 0x67, (byte) 0x01,
+                       (byte) 0x23, (byte) 0x45, (byte) 0x67 };
+       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 };
+       private static final byte[] reqMissingBytes = { (byte) 0xF7, (byte) 0x82, (byte) 0x35, (byte) 0x17 };
+       private static final byte[] orderBytes = { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+                       (byte) 0x01 };
+       private static final byte[] ofListBytes = { (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78 };
+       private static final byte[] predundancyBytes = { (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78 };
+
+       @Test
+       public void testStatefulTlv() throws PCEPDeserializerException {
+               final PCEStatefulCapabilityTlvParser parser = new PCEStatefulCapabilityTlvParser();
+               final StatefulCapabilityTlv tlv = new StatefulBuilder().setFlags(new Flags(true, false, false)).build();
+               assertEquals(tlv, parser.parseTlv(statefulBytes));
+               assertArrayEquals(statefulBytes, parser.serializeTlv(tlv));
+       }
+
+       @Test
+       public void testStateDbVersionTlv() throws PCEPDeserializerException {
+               final LspDbVersionTlvParser parser = new LspDbVersionTlvParser();
+               final LspDbVersionTlv tlv = new LspDbVersionBuilder().setVersion(BigInteger.valueOf(0xFF00FFAAB2F5F2CFL)).build();
+               assertEquals(tlv, parser.parseTlv(DbVersionBytes));
+               assertArrayEquals(DbVersionBytes, parser.serializeTlv(tlv));
+       }
+
+       @Test
+       public void testNoPathVectorTlv() throws PCEPDeserializerException {
+               final NoPathVectorTlvParser parser = new NoPathVectorTlvParser();
+               final NoPathVectorTlv tlv = new NoPathVectorBuilder().setFlags(
+                               new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.NoPathVectorTlv.Flags(false, true, false, true, false, true, true, true)).build();
+               assertEquals(tlv, parser.parseTlv(noPathVectorBytes));
+               assertArrayEquals(noPathVectorBytes, parser.serializeTlv(tlv));
+       }
+
+       @Test
+       public void testOverloadedDurationTlv() throws PCEPDeserializerException {
+               final OverloadedDurationTlvParser parser = new OverloadedDurationTlvParser();
+               final OverloadDurationTlv tlv = new OverloadDurationBuilder().setDuration(0x7FFFFFFFL).build();
+               assertEquals(tlv, parser.parseTlv(overloadedBytes));
+               assertArrayEquals(overloadedBytes, parser.serializeTlv(tlv));
+       }
+
+       @Test
+       public void testSymbolicNameTlv() throws PCEPDeserializerException {
+               final LspSymbolicNameTlvParser parser = new LspSymbolicNameTlvParser();
+               final SymbolicPathNameTlv tlv = new SymblicPathNameBuilder().setPathName(new String("Med test of symbolic name").getBytes()).build();
+               assertEquals(tlv, parser.parseTlv(symbolicNameBytes));
+               assertArrayEquals(symbolicNameBytes, parser.serializeTlv(tlv));
+       }
+
+       @Test
+       public void testLspErrorCodeTlv() throws PCEPDeserializerException {
+               final LspUpdateErrorTlvParser parser = new LspUpdateErrorTlvParser();
+               final LspErrorCodeTlv tlv = new LspErrorCodeBuilder().setErrorCode(627610883L).build();
+               assertEquals(tlv, parser.parseTlv(lspUpdateErrorBytes));
+               assertArrayEquals(lspUpdateErrorBytes, parser.serializeTlv(tlv));
+       }
+
+       @Test
+       public void testLspIdentifiers4Tlv() throws PCEPDeserializerException {
+               final LSPIdentifierTlvParser parser = new LSPIdentifierTlvParser();
+               final Ipv4Builder afi = new Ipv4Builder();
+               afi.setIpv4TunnelSenderAddress(Ipv4Util.addressForBytes(new byte[] { (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78 }));
+               afi.setIpv4ExtendedTunnelId(new Ipv4ExtendedTunnelId(Ipv4Util.addressForBytes(new byte[] { (byte) 0x12, (byte) 0x34, (byte) 0x56,
+                               (byte) 0x78 })));
+               final LspIdentifiersTlv tlv = new LspIdentifiersBuilder().setAddressFamily(afi.build()).setLspId(new LspId(65535L)).setTunnelId(
+                               new TunnelId(4660)).build();
+               assertEquals(tlv, parser.parseTlv(lspIdentifiers4Bytes));
+               assertArrayEquals(lspIdentifiers4Bytes, parser.serializeTlv(tlv));
+       }
+
+       @Test
+       public void testLspIdentifiers6Tlv() throws PCEPDeserializerException {
+               final LSPIdentifierTlvParser parser = new LSPIdentifierTlvParser();
+               final Ipv6Builder afi = new Ipv6Builder();
+               afi.setIpv6TunnelSenderAddress(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 }));
+               afi.setIpv6ExtendedTunnelId(new Ipv6ExtendedTunnelId(Ipv6Util.addressForBytes(new byte[] { (byte) 0x12, (byte) 0x34, (byte) 0x56,
+                               (byte) 0x78, (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78, (byte) 0x01, (byte) 0x23, (byte) 0x45, (byte) 0x67,
+                               (byte) 0x01, (byte) 0x23, (byte) 0x45, (byte) 0x67 })));
+               final LspIdentifiersTlv tlv = new LspIdentifiersBuilder().setAddressFamily(afi.build()).setLspId(new LspId(4660L)).setTunnelId(
+                               new TunnelId(65535)).build();
+               assertEquals(tlv, parser.parseTlv(lspIdentifiers6Bytes));
+               assertArrayEquals(lspIdentifiers6Bytes, 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 RsvpErrorSpecTlv tlv = new RsvpErrorSpecBuilder().setErrorType(new RsvpBuilder().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 RsvpErrorSpecTlv tlv = new RsvpErrorSpecBuilder().setErrorType(new RsvpBuilder().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 RsvpErrorSpecTlv tlv = new RsvpErrorSpecBuilder().setErrorType(new UserBuilder().setUserError(builder.build()).build()).build();
+               assertEquals(tlv, parser.parseTlv(userErrorBytes));
+               assertArrayEquals(userErrorBytes, parser.serializeTlv(tlv));
+       }
+
+       @Test
+       public void testReqMissingTlv() throws PCEPDeserializerException {
+               final ReqMissingTlvParser parser = new ReqMissingTlvParser();
+               final ReqMissingTlv tlv = new ReqMissingBuilder().setRequestId(new RequestId(0xF7823517L)).build();
+               assertEquals(tlv, parser.parseTlv(reqMissingBytes));
+               assertArrayEquals(reqMissingBytes, parser.serializeTlv(tlv));
+       }
+
+       @Test
+       public void testOrderTlv() throws PCEPDeserializerException {
+               final OrderTlvParser parser = new OrderTlvParser();
+               final OrderTlv tlv = new OrderBuilder().setDelete(0xFFFFFFFFL).setSetup(0x00000001L).build();
+               assertEquals(tlv, parser.parseTlv(orderBytes));
+               assertArrayEquals(orderBytes, parser.serializeTlv(tlv));
+       }
+
+       @Test
+       public void testOFListTlv() throws PCEPDeserializerException {
+               final OFListTlvParser parser = new OFListTlvParser();
+               final List<OfId> ids = Lists.newArrayList();
+               ids.add(new OfId(0x1234));
+               ids.add(new OfId(0x5678));
+               final OfListTlv tlv = new OfListBuilder().setCodes(ids).build();
+               assertEquals(tlv, parser.parseTlv(ofListBytes));
+               assertArrayEquals(ofListBytes, parser.serializeTlv(tlv));
+       }
+
+       @Test
+       public void testPredundancyTlv() throws PCEPDeserializerException {
+               final PredundancyGroupTlvParser parser = new PredundancyGroupTlvParser();
+               final PredundancyGroupIdTlv tlv = new PredundancyGroupIdBuilder().setIdentifier(predundancyBytes).build();
+               assertEquals(tlv, parser.parseTlv(predundancyBytes));
+               assertArrayEquals(predundancyBytes, parser.serializeTlv(tlv));
+       }
 }
index ed342330bc2d429289038596dd14b8c9a2e73dc1..e083d2bebe92438d96169450bc6b15cb665544f6 100644 (file)
@@ -11,6 +11,7 @@ import org.opendaylight.protocol.concepts.HandlerRegistry;
 import org.opendaylight.protocol.pcep.spi.EROSubobjectHandlerRegistry;
 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.yangtools.yang.binding.DataContainer;
@@ -21,7 +22,7 @@ public final class SimpleEROSubobjectHandlerRegistry implements EROSubobjectHand
        private final HandlerRegistry<DataContainer, EROSubobjectParser, EROSubobjectSerializer> handlers = new HandlerRegistry<>();
 
        public AutoCloseable registerSubobjectParser(final int subobjectType, final EROSubobjectParser parser) {
-               Preconditions.checkArgument(subobjectType >= 0 && subobjectType <= 65535);
+               Preconditions.checkArgument(subobjectType >= 0 && subobjectType <= Util.UNSIGNED_SHORT_MAX_VALUE);
                return this.handlers.registerParser(subobjectType, parser);
        }
 
@@ -32,7 +33,7 @@ public final class SimpleEROSubobjectHandlerRegistry implements EROSubobjectHand
 
        @Override
        public EROSubobjectParser getSubobjectParser(final int subobjectType) {
-               Preconditions.checkArgument(subobjectType >= 0 && subobjectType <= 65535);
+               Preconditions.checkArgument(subobjectType >= 0 && subobjectType <= Util.UNSIGNED_SHORT_MAX_VALUE);
                return this.handlers.getParser(subobjectType);
        }
 
index 169db72fbfbd2a65869d8b6ab919ad2925bca4b2..e7e5d77cf232df355b73f4097e9b695ff71138b4 100644 (file)
@@ -11,6 +11,7 @@ import org.opendaylight.protocol.concepts.HandlerRegistry;
 import org.opendaylight.protocol.pcep.spi.LabelHandlerRegistry;
 import org.opendaylight.protocol.pcep.spi.LabelParser;
 import org.opendaylight.protocol.pcep.spi.LabelSerializer;
+import org.opendaylight.protocol.util.Util;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.CLabel;
 import org.opendaylight.yangtools.yang.binding.DataContainer;
 
@@ -20,22 +21,22 @@ public class SimpleLabelHandlerRegistry implements LabelHandlerRegistry {
        private final HandlerRegistry<DataContainer, LabelParser, LabelSerializer> handlers = new HandlerRegistry<>();
 
        public AutoCloseable registerLabelParser(final int cType, final LabelParser parser) {
-               Preconditions.checkArgument(cType >= 0 && cType <= 255);
-               return handlers.registerParser(cType, parser);
+               Preconditions.checkArgument(cType >= 0 && cType <= Util.UNSIGNED_BYTE_MAX_VALUE);
+               return this.handlers.registerParser(cType, parser);
        }
 
        public AutoCloseable registerLabelSerializer(final Class<? extends CLabel> labelClass, final LabelSerializer serializer) {
-               return handlers.registerSerializer(labelClass, serializer);
+               return this.handlers.registerSerializer(labelClass, serializer);
        }
 
        @Override
        public LabelParser getLabelParser(final int cType) {
-               Preconditions.checkArgument(cType >= 0 && cType <= 255);
-               return handlers.getParser(cType);
+               Preconditions.checkArgument(cType >= 0 && cType <= Util.UNSIGNED_BYTE_MAX_VALUE);
+               return this.handlers.getParser(cType);
        }
 
        @Override
        public LabelSerializer getLabelSerializer(final CLabel label) {
-               return handlers.getSerializer(label.getImplementedInterface());
+               return this.handlers.getSerializer(label.getImplementedInterface());
        }
 }
index 6c7a07a629597cc9b9b9fb8a4e09123af05a9ce9..74f6bb348a23b3ca82d7fe62c39e66575d7d8b21 100644 (file)
@@ -11,6 +11,7 @@ import org.opendaylight.protocol.concepts.HandlerRegistry;
 import org.opendaylight.protocol.pcep.spi.MessageHandlerRegistry;
 import org.opendaylight.protocol.pcep.spi.MessageParser;
 import org.opendaylight.protocol.pcep.spi.MessageSerializer;
+import org.opendaylight.protocol.util.Util;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Message;
 import org.opendaylight.yangtools.yang.binding.DataContainer;
 
@@ -21,7 +22,7 @@ public final class SimpleMessageHandlerRegistry implements MessageHandlerRegistr
        private final HandlerRegistry<DataContainer, MessageParser, MessageSerializer> handlers = new HandlerRegistry<>();
 
        public AutoCloseable registerMessageParser(final int messageType, final MessageParser parser) {
-               Preconditions.checkArgument(messageType >= 0 && messageType <= 255);
+               Preconditions.checkArgument(messageType >= 0 && messageType <= Util.UNSIGNED_BYTE_MAX_VALUE);
                return this.handlers.registerParser(messageType, parser);
        }
 
@@ -31,7 +32,7 @@ public final class SimpleMessageHandlerRegistry implements MessageHandlerRegistr
 
        @Override
        public MessageParser getMessageParser(final int messageType) {
-               Preconditions.checkArgument(messageType >= 0 && messageType <= 255);
+               Preconditions.checkArgument(messageType >= 0 && messageType <= Util.UNSIGNED_BYTE_MAX_VALUE);
                return this.handlers.getParser(messageType);
        }
 
index 709452bbae49a9c4e2421b50aa341366e5b46d70..7452e375783dc9402778d6222c54a8afd7a9d8e1 100644 (file)
@@ -11,6 +11,7 @@ import org.opendaylight.protocol.concepts.HandlerRegistry;
 import org.opendaylight.protocol.pcep.spi.ObjectHandlerRegistry;
 import org.opendaylight.protocol.pcep.spi.ObjectParser;
 import org.opendaylight.protocol.pcep.spi.ObjectSerializer;
+import org.opendaylight.protocol.util.Util;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object;
 import org.opendaylight.yangtools.yang.binding.DataContainer;
 
@@ -22,29 +23,29 @@ import com.google.common.base.Preconditions;
 public final class SimpleObjectHandlerRegistry implements ObjectHandlerRegistry {
        private final HandlerRegistry<DataContainer, ObjectParser, ObjectSerializer> handlers = new HandlerRegistry<>();
 
-       private static final int createKey(final int objectClass, final int objectType) {
-               Preconditions.checkArgument(objectClass >= 0 && objectClass <= 255);
+       private static int createKey(final int objectClass, final int objectType) {
+               Preconditions.checkArgument(objectClass >= 0 && objectClass <= Util.UNSIGNED_BYTE_MAX_VALUE);
                Preconditions.checkArgument(objectType >= 0 && objectType <= 15);
                return (objectClass << 4) | objectType;
        }
 
        public AutoCloseable registerObjectParser(final int objectClass, final int objectType, final ObjectParser parser) {
-               Preconditions.checkArgument(objectClass >= 0 && objectClass <= 255);
+               Preconditions.checkArgument(objectClass >= 0 && objectClass <= Util.UNSIGNED_BYTE_MAX_VALUE);
                Preconditions.checkArgument(objectType >= 0 && objectType <= 15);
-               return handlers.registerParser(createKey(objectClass, objectType), parser);
+               return this.handlers.registerParser(createKey(objectClass, objectType), parser);
        }
 
        public AutoCloseable registerObjectSerializer(final Class<? extends Object> objClass, final ObjectSerializer serializer) {
-               return handlers.registerSerializer(objClass, serializer);
+               return this.handlers.registerSerializer(objClass, serializer);
        }
 
        @Override
        public ObjectParser getObjectParser(final int objectClass, final int objectType) {
-               return handlers.getParser(createKey(objectClass, objectType));
+               return this.handlers.getParser(createKey(objectClass, objectType));
        }
 
        @Override
        public ObjectSerializer getObjectSerializer(final Object object) {
-               return handlers.getSerializer(object.getImplementedInterface());
+               return this.handlers.getSerializer(object.getImplementedInterface());
        }
 }
index 6981dcb2ef29d9d2328d04e0f695d2159d8dbf72..e96788e87de5b69cfdaaeda20f42c32e4b8a9aff 100644 (file)
@@ -11,6 +11,7 @@ import org.opendaylight.protocol.concepts.HandlerRegistry;
 import org.opendaylight.protocol.pcep.spi.RROSubobjectHandlerRegistry;
 import org.opendaylight.protocol.pcep.spi.RROSubobjectParser;
 import org.opendaylight.protocol.pcep.spi.RROSubobjectSerializer;
+import org.opendaylight.protocol.util.Util;
 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.rsvp.rev130820.CSubobject;
 import org.opendaylight.yangtools.yang.binding.DataContainer;
@@ -21,13 +22,13 @@ public final class SimpleRROSubobjectHandlerRegistry implements RROSubobjectHand
        private final HandlerRegistry<DataContainer, RROSubobjectParser, RROSubobjectSerializer> handlers = new HandlerRegistry<>();
 
        public AutoCloseable registerSubobjectParser(final int subobjectType, final RROSubobjectParser parser) {
-               Preconditions.checkArgument(subobjectType >= 0 && subobjectType <= 65535);
+               Preconditions.checkArgument(subobjectType >= 0 && subobjectType <= Util.UNSIGNED_SHORT_MAX_VALUE);
                return this.handlers.registerParser(subobjectType, parser);
        }
 
        @Override
        public RROSubobjectParser getSubobjectParser(final int subobjectType) {
-               Preconditions.checkArgument(subobjectType >= 0 && subobjectType <= 65535);
+               Preconditions.checkArgument(subobjectType >= 0 && subobjectType <= Util.UNSIGNED_SHORT_MAX_VALUE);
                return this.handlers.getParser(subobjectType);
        }
 
index fd3ad8292cef412f775bad79dbc969c23b0a3873..94f00a97647c4acee1ed1df3a6b0531e15fd7d36 100644 (file)
@@ -11,6 +11,7 @@ import org.opendaylight.protocol.concepts.HandlerRegistry;
 import org.opendaylight.protocol.pcep.spi.TlvHandlerRegistry;
 import org.opendaylight.protocol.pcep.spi.TlvParser;
 import org.opendaylight.protocol.pcep.spi.TlvSerializer;
+import org.opendaylight.protocol.util.Util;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Tlv;
 import org.opendaylight.yangtools.yang.binding.DataContainer;
 
@@ -23,21 +24,21 @@ public final class SimpleTlvHandlerRegistry implements TlvHandlerRegistry {
        private final HandlerRegistry<DataContainer, TlvParser, TlvSerializer> handlers = new HandlerRegistry<>();
 
        public AutoCloseable registerTlvParser(final int tlvType, final TlvParser parser) {
-               Preconditions.checkArgument(tlvType >= 0 && tlvType < 65535);
-               return handlers.registerParser(tlvType, parser);
+               Preconditions.checkArgument(tlvType >= 0 && tlvType < Util.UNSIGNED_SHORT_MAX_VALUE);
+               return this.handlers.registerParser(tlvType, parser);
        }
 
        public AutoCloseable registerTlvSerializer(final Class<? extends Tlv> tlvClass, final TlvSerializer serializer) {
-               return handlers.registerSerializer(tlvClass, serializer);
+               return this.handlers.registerSerializer(tlvClass, serializer);
        }
 
        @Override
        public TlvParser getTlvParser(final int tlvType) {
-               return handlers.getParser(tlvType);
+               return this.handlers.getParser(tlvType);
        }
 
        @Override
        public TlvSerializer getTlvSerializer(final Tlv tlv) {
-               return handlers.getSerializer(tlv.getImplementedInterface());
+               return this.handlers.getSerializer(tlv.getImplementedInterface());
        }
 }
index ebfe100a0ea8b32b2cefc72d9a79221485a4c0bc..030adfcb64d1c8607d40060ffcaa3f3b94209af5 100644 (file)
@@ -11,6 +11,7 @@ import org.opendaylight.protocol.concepts.HandlerRegistry;
 import org.opendaylight.protocol.pcep.spi.XROSubobjectHandlerRegistry;
 import org.opendaylight.protocol.pcep.spi.XROSubobjectParser;
 import org.opendaylight.protocol.pcep.spi.XROSubobjectSerializer;
+import org.opendaylight.protocol.util.Util;
 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.rsvp.rev130820.CSubobject;
 import org.opendaylight.yangtools.yang.binding.DataContainer;
@@ -21,7 +22,7 @@ public final class SimpleXROSubobjectHandlerRegistry implements XROSubobjectHand
        private final HandlerRegistry<DataContainer, XROSubobjectParser, XROSubobjectSerializer> handlers = new HandlerRegistry<>();
 
        public AutoCloseable registerSubobjectParser(final int subobjectType, final XROSubobjectParser parser) {
-               Preconditions.checkArgument(subobjectType >= 0 && subobjectType <= 65535);
+               Preconditions.checkArgument(subobjectType >= 0 && subobjectType <= Util.UNSIGNED_SHORT_MAX_VALUE);
                return this.handlers.registerParser(subobjectType, parser);
        }
 
@@ -32,7 +33,7 @@ public final class SimpleXROSubobjectHandlerRegistry implements XROSubobjectHand
 
        @Override
        public XROSubobjectParser getSubobjectParser(final int subobjectType) {
-               Preconditions.checkArgument(subobjectType >= 0 && subobjectType <= 65535);
+               Preconditions.checkArgument(subobjectType >= 0 && subobjectType <= Util.UNSIGNED_SHORT_MAX_VALUE);
                return this.handlers.getParser(subobjectType);
        }
 
index 9edb26705ac4b0f7f6ee1d033591478734927abc..dbce743996e38f12206f7e6bf6d79f3bed7e00e4 100644 (file)
@@ -18,9 +18,13 @@ import org.opendaylight.protocol.pcep.impl.PCEPDispatcherImpl;
 import org.opendaylight.protocol.pcep.impl.PCEPSessionProposalFactoryImpl;
 import org.opendaylight.protocol.pcep.spi.pojo.PCEPExtensionProviderContextImpl;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.OpenObject;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 public class Main {
 
+       private static final Logger logger = LoggerFactory.getLogger(Main.class);
+
        public static String usage = "DESCRIPTION:\n" + "\tCreates a server with given parameters. As long as it runs, it accepts connections "
                        + "from PCCs.\n" + "USAGE:\n" + "\t-a, --address\n" + "\t\tthe ip address to which is this server bound.\n"
                        + "\t\tFormat: x.x.x.x:y where y is port number.\n\n" +
@@ -58,6 +62,10 @@ public class Main {
 
                        "With no parameters, this help is printed.";
 
+       private Main() {
+
+       }
+
        public static void main(final String[] args) throws Exception {
                if (args.length == 0 || args.length == 1 && args[0].equalsIgnoreCase("--help")) {
                        System.out.println(Main.usage);
@@ -103,12 +111,12 @@ public class Main {
                                        i++;
                                }
                        } else {
-                               System.out.println("WARNING: Unrecognized argument: " + args[i]);
+                               logger.warn("WARNING: Unrecognized argument: {}", args[i]);
                        }
                        i++;
                }
                if (deadTimerValue != 0 && deadTimerValue != keepAliveValue * 4) {
-                       System.out.println("WARNING: The value of DeadTimer should be 4 times the value of KeepAlive.");
+                       logger.warn("WARNING: The value of DeadTimer should be 4 times the value of KeepAlive.");
                }
                if (deadTimerValue == 0) {
                        deadTimerValue = keepAliveValue * 4;
@@ -118,9 +126,7 @@ public class Main {
 
                final OpenObject prefs = spf.getSessionProposal(address, 0);
 
-               final PCEPDispatcherImpl dispatcher = new PCEPDispatcherImpl(
-                               PCEPExtensionProviderContextImpl.getSingletonInstance().getMessageHandlerRegistry(),
-                               new DefaultPCEPSessionNegotiatorFactory(new HashedWheelTimer(), prefs, 5));
+               final PCEPDispatcherImpl dispatcher = new PCEPDispatcherImpl(PCEPExtensionProviderContextImpl.getSingletonInstance().getMessageHandlerRegistry(), new DefaultPCEPSessionNegotiatorFactory(new HashedWheelTimer(), prefs, 5));
 
                dispatcher.createServer(address, new TestingSessionListenerFactory()).get();
        }
index 4e67547eaf4713dab82ecad9ca372b20daf19287..3897ee4d5ea28c53ec00054db5a5fe4385fd0d0e 100644 (file)
@@ -39,17 +39,6 @@ public class SimpleSessionListener implements PCEPSessionListener {
        @Override
        public void onSessionUp(final PCEPSession session) {
                logger.debug("Session up.");
-               // final List<ExplicitRouteSubobject> subs = new ArrayList<ExplicitRouteSubobject>();
-               // subs.add(new EROIPPrefixSubobject<Prefix<?>>(new IPv4Prefix(new IPv4Address(new byte[] { 10, 1, 1, 2 }), 32),
-               // false));
-               // subs.add(new EROIPPrefixSubobject<Prefix<?>>(new IPv4Prefix(new IPv4Address(new byte[] { 2, 2, 2, 2 }), 32),
-               // false));
-               // final CompositeInstantiationObject cpo = new CompositeInstantiationObject(new
-               // PCEPEndPointsObject<IPv4Address>(IPv4.FAMILY.addressForBytes(new byte[] {
-               // 1, 1, 1, 1 }), IPv4.FAMILY.addressForBytes(new byte[] { 2, 2, 2, 2 })), new PCEPLspaObject(0, 0, 0, (short)
-               // 0, (short) 0, false, false, false, false), new PCEPExplicitRouteObject(subs, false), null, null);
-               //
-               // session.sendMessage(new PCCreateMessage(Lists.newArrayList(cpo)));
        }
 
        @Override
index 1e60189650575a281c4d7c1c121a7374764565b1..f08a295dffcb2313bda29a7e665b36c59ba771a3 100644 (file)
@@ -39,14 +39,12 @@ public class TestingSessionListener implements PCEPSessionListener {
        public void onSessionUp(final PCEPSession session) {
                logger.debug("Session up.");
                this.up = true;
-               // this.notifyAll();
        }
 
        @Override
        public void onSessionDown(final PCEPSession session, final Exception e) {
                logger.debug("Session down. Cause : {} or {}", e);
                this.up = false;
-               // this.notifyAll();
        }
 
        @Override
index 6386ffebc44e8c51c1903ed0a9c531088b214c44..cd0f816667331903e12de64937c33b89978df3ed 100644 (file)
@@ -7,10 +7,11 @@
  */
 package org.opendaylight.protocol.util;
 
-
 public class Util {
 
        public static final int UNSIGNED_SHORT_MAX_VALUE = 65535;
 
        public static final int UNSIGNED_BYTE_MAX_VALUE = 255;
+
+       public static final int BYTE_MAX_VALUE_BYTES = 0xFF;
 }