BUG-50 : added tests for simple PCEP objects. 71/2271/1
authorDana Kutenicsova <dkutenic@cisco.com>
Wed, 30 Oct 2013 10:42:16 +0000 (11:42 +0100)
committerDana Kutenicsova <dkutenic@cisco.com>
Wed, 30 Oct 2013 10:42:16 +0000 (11:42 +0100)
Change-Id: Ibfe66f1d3549eb575c9c4cf3f9770a73005626ab
Signed-off-by: Dana Kutenicsova <dkutenic@cisco.com>
43 files changed:
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/PCEPMessageFactory.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/PCEPMessageHeader.java [deleted file]
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/AbstractObjectWithTlvsParser.java [moved from pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/message/AbstractObjectWithTlvsParser.java with 98% similarity]
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPBandwidthObjectParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPClassTypeObjectParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPCloseObjectParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPEndPointsObjectParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPErrorObjectParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPGlobalConstraintsObjectParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPLoadBalancingObjectParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPLspObjectParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPLspaObjectParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPMetricObjectParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPNoPathObjectParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPNotificationObjectParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPObjectiveFunctionObjectParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPOpenObjectParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPPathKeyObjectParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPRequestParameterObjectParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPSrpObjectParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/PCEPSvecObjectParser.java
pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/PCEPObjectParserTest.java
pcep/impl/src/test/resources/LSPStateDBVersionTlv1.bin [deleted file]
pcep/impl/src/test/resources/LSPStateDBVersionTlv2.bin [deleted file]
pcep/impl/src/test/resources/LSPStateDBVersionTlvInvalid1.bin [deleted file]
pcep/impl/src/test/resources/NoPathObject1WithTLV.bin [deleted file]
pcep/impl/src/test/resources/NoPathObject2WithoutTLV.bin [deleted file]
pcep/impl/src/test/resources/PCEPBandwidthObject1LowerBounds.bin
pcep/impl/src/test/resources/PCEPBandwidthObject2UpperBounds.bin
pcep/impl/src/test/resources/PCEPEndPointsObject1IPv4.bin
pcep/impl/src/test/resources/PCEPEndPointsObject2IPv6.bin
pcep/impl/src/test/resources/PCEPKeepAliveMessage1.bin [deleted file]
pcep/impl/src/test/resources/PCEPLoadBalancingObject1.bin
pcep/impl/src/test/resources/PCEPMetricObject1LowerBounds.bin
pcep/impl/src/test/resources/PCEPMetricObject2UpperBounds.bin
pcep/impl/src/test/resources/PCEPSvecObject1_10ReqIDs.bin
pcep/impl/src/test/resources/PCEPSvecObject2.bin
pcep/impl/src/test/resources/PCEStatefulCapabilityTlv1.bin [deleted file]
pcep/impl/src/test/resources/PCEStatefulCapabilityTlv2.bin [deleted file]
pcep/impl/src/test/resources/PCEStatefulCapabilityTlvInvalid1.bin [deleted file]
pcep/impl/src/test/resources/PackOfSubobjects.bin [deleted file]
pcep/impl/src/test/resources/PackOfTlvs.bin [deleted file]
pcep/impl/src/test/resources/PackOfXROSubobjects.bin [deleted file]

index 1bc18098700dd544dcfed15f98e7f9deb9e4cdaf..883e4563b8e4286e39d8a8531df4efbd8830d146 100644 (file)
@@ -121,7 +121,7 @@ public final class PCEPMessageFactory implements ProtocolMessageFactory<Message>
                final byte[] retBytes = new byte[headerBytes.length + msgBody.length];
 
                ByteArray.copyWhole(headerBytes, retBytes, 0);
-               ByteArray.copyWhole(msgBody, retBytes, PCEPMessageHeader.COMMON_HEADER_LENGTH);
+               ByteArray.copyWhole(msgBody, retBytes, COMMON_HEADER_LENGTH);
 
                return retBytes;
        }
diff --git a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/PCEPMessageHeader.java b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/PCEPMessageHeader.java
deleted file mode 100644 (file)
index 5589ea9..0000000
+++ /dev/null
@@ -1,128 +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;
-
-import java.util.Arrays;
-
-import org.opendaylight.protocol.util.ByteArray;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import com.google.common.primitives.UnsignedBytes;
-
-/**
- * Header parser for {@link org.opendaylight.protocol.pcep.PCEPMessage PCEPMessage}
- */
-public final class PCEPMessageHeader {
-
-       public static final Logger logger = LoggerFactory.getLogger(PCEPMessageHeader.class);
-
-       /*
-        * lengths of fields in bytes
-        */
-       private static final int VER_FLAGS_MF_LENGTH = 1;
-       private static final int TYPE_F_LENGTH = 1;
-       private static final int LENGTH_F_LENGTH = 2;
-
-       /*
-        * lengths of subfields inside multi-field in bits
-        */
-       private static final int VERSION_SF_LENGTH = 3;
-
-       /*
-        * offsets of field in bytes
-        */
-       private static final int VER_FLAGS_MF_OFFSET = 0;
-       private static final int TYPE_F_OFFSET = VER_FLAGS_MF_LENGTH + VER_FLAGS_MF_OFFSET;
-       private static final int LENGTH_F_OFFSET = TYPE_F_LENGTH + TYPE_F_OFFSET;
-
-       /*
-        * offsets of subfields inside multi-filed in bits
-        */
-
-       private static final int VERSION_SF_OFFSET = 0;
-
-       /*
-        * COMMON HEADER LENGTH
-        */
-       public static final int COMMON_HEADER_LENGTH = VER_FLAGS_MF_LENGTH + TYPE_F_LENGTH + LENGTH_F_LENGTH;
-
-       private final int type;
-       private final int length;
-       private final int version;
-
-       public PCEPMessageHeader(final int type, final int length, final int version) {
-               this.type = type;
-               this.length = length;
-               this.version = version;
-       }
-
-       public static PCEPMessageHeader fromBytes(final byte[] bytes) {
-               if (bytes == null) {
-                       throw new IllegalArgumentException("Array of bytes is mandatory");
-               }
-
-               logger.trace("Attempt to parse message header: {}", ByteArray.bytesToHexString(bytes));
-
-               if (bytes.length < COMMON_HEADER_LENGTH) {
-                       throw new IllegalArgumentException("Too few bytes in passed array. Passed: " + bytes.length + "; Expected: >= " + COMMON_HEADER_LENGTH + ".");
-               }
-
-               final int type = UnsignedBytes.toInt(bytes[TYPE_F_OFFSET]);
-
-               final int length = ByteArray.bytesToInt(Arrays.copyOfRange(bytes,
-                               LENGTH_F_OFFSET, LENGTH_F_OFFSET + LENGTH_F_LENGTH));
-
-               final int version = ByteArray.copyBitsRange(bytes[VER_FLAGS_MF_OFFSET], VERSION_SF_OFFSET, VERSION_SF_LENGTH);
-
-               final PCEPMessageHeader ret = new PCEPMessageHeader(type, length, version);
-
-               logger.trace("Message header was parsed. {}", ret);
-               return ret;
-       }
-
-       public byte[] toBytes() {
-               final byte[] retBytes = new byte[COMMON_HEADER_LENGTH];
-
-               // msgVer_Flag
-               retBytes[VER_FLAGS_MF_OFFSET] = (byte) (this.version << (Byte.SIZE - VERSION_SF_LENGTH));
-
-               // msgType
-               retBytes[TYPE_F_OFFSET] = (byte) this.type;
-
-               // msgLength
-               System.arraycopy(ByteArray.intToBytes(this.length), Integer.SIZE / Byte.SIZE - LENGTH_F_LENGTH, retBytes, LENGTH_F_OFFSET, LENGTH_F_LENGTH);
-
-               return retBytes;
-       }
-
-       public int getLength() {
-               return this.length;
-       }
-
-       public int getVersion() {
-               return this.version;
-       }
-
-       public int getType() {
-               return this.type;
-       }
-
-       @Override
-       public String toString() {
-               final StringBuilder builder = new StringBuilder();
-               builder.append("PCEPMessageHeader [type=");
-               builder.append(this.type);
-               builder.append(", length=");
-               builder.append(this.length);
-               builder.append(", version=");
-               builder.append(this.version);
-               builder.append("]");
-               return builder.toString();
-       }
-}
similarity index 98%
rename from pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/message/AbstractObjectWithTlvsParser.java
rename to pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/AbstractObjectWithTlvsParser.java
index 625841d33126fc525d0bfaf1c0885c9f3e918646..3436024c0a91306af5d3f2992fe88d2d62d4654a 100644 (file)
@@ -5,7 +5,7 @@
  * 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.message;
+package org.opendaylight.protocol.pcep.impl.object;
 
 import org.opendaylight.protocol.pcep.PCEPDeserializerException;
 import org.opendaylight.protocol.pcep.spi.ObjectParser;
index dee802b16391f7a949563707f022a9a926140c27..bce6864b38a802c2e81405d3f6f5ecc12c15dea2 100644 (file)
@@ -9,7 +9,6 @@ package org.opendaylight.protocol.pcep.impl.object;
 
 import org.opendaylight.protocol.pcep.PCEPDeserializerException;
 import org.opendaylight.protocol.pcep.PCEPDocumentedException;
-import org.opendaylight.protocol.pcep.impl.message.AbstractObjectWithTlvsParser;
 import org.opendaylight.protocol.pcep.spi.TlvHandlerRegistry;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ieee754.rev130819.Float32;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.BandwidthObject;
@@ -39,7 +38,7 @@ public class PCEPBandwidthObjectParser extends AbstractObjectWithTlvsParser<Band
 
        @Override
        public BandwidthObject parseObject(final ObjectHeader header, final byte[] bytes) throws PCEPDeserializerException,
-       PCEPDocumentedException {
+                       PCEPDocumentedException {
                if (bytes == null || bytes.length == 0) {
                        throw new IllegalArgumentException("Array of bytes is mandatory. Can't be null or empty.");
                }
@@ -47,14 +46,10 @@ public class PCEPBandwidthObjectParser extends AbstractObjectWithTlvsParser<Band
                        throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + bytes.length + "; Expected: "
                                        + BANDWIDTH_F_LENGTH + ".");
                }
-
                final BandwidthBuilder builder = new BandwidthBuilder();
-
                builder.setIgnore(header.isIgnore());
                builder.setProcessingRule(header.isProcessingRule());
-
                builder.setBandwidth(new Float32(bytes));
-
                return builder.build();
        }
 
@@ -68,7 +63,6 @@ public class PCEPBandwidthObjectParser extends AbstractObjectWithTlvsParser<Band
                if (!(object instanceof BandwidthObject)) {
                        throw new IllegalArgumentException("Wrong instance of PCEPObject. Passed " + object.getClass() + ". Needed BandwidthObject.");
                }
-
                return ((BandwidthObject) object).getBandwidth().getValue();
        }
 
index c8f88cbf33224591eff6a7e24bed637d62246088..3ec9ede227212a4a4f1865cde9309f15116a2a83 100644 (file)
@@ -10,7 +10,6 @@ package org.opendaylight.protocol.pcep.impl.object;
 import org.opendaylight.protocol.pcep.PCEPDeserializerException;
 import org.opendaylight.protocol.pcep.PCEPDocumentedException;
 import org.opendaylight.protocol.pcep.PCEPErrors;
-import org.opendaylight.protocol.pcep.impl.message.AbstractObjectWithTlvsParser;
 import org.opendaylight.protocol.pcep.spi.TlvHandlerRegistry;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ClassType;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ClasstypeObject;
index f02047d064c4e1c0dac80f43516157da3b423372..af2ca7ff66bf1d48d265380a2f2d3f0a1e426b78 100644 (file)
@@ -10,7 +10,6 @@ package org.opendaylight.protocol.pcep.impl.object;
 import org.opendaylight.protocol.pcep.PCEPDeserializerException;
 import org.opendaylight.protocol.pcep.PCEPDocumentedException;
 import org.opendaylight.protocol.pcep.impl.Util;
-import org.opendaylight.protocol.pcep.impl.message.AbstractObjectWithTlvsParser;
 import org.opendaylight.protocol.pcep.spi.TlvHandlerRegistry;
 import org.opendaylight.protocol.util.ByteArray;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.CloseObject;
index 72a957fc7d51e55869bae5d3a14c534a9e9b19a7..d2808e2838c23bbbaf101a648a4d1ccbce775096 100644 (file)
@@ -12,7 +12,6 @@ import org.opendaylight.protocol.concepts.Ipv6Util;
 import org.opendaylight.protocol.pcep.PCEPDeserializerException;
 import org.opendaylight.protocol.pcep.PCEPDocumentedException;
 import org.opendaylight.protocol.pcep.PCEPErrors;
-import org.opendaylight.protocol.pcep.impl.message.AbstractObjectWithTlvsParser;
 import org.opendaylight.protocol.pcep.spi.TlvHandlerRegistry;
 import org.opendaylight.protocol.util.ByteArray;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.EndpointsObject;
@@ -32,27 +31,25 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.typ
 public class PCEPEndPointsObjectParser extends AbstractObjectWithTlvsParser<EndpointsBuilder> {
 
        public static final int CLASS = 4;
-
        public static final int TYPE = 1;
 
+       public static final int CLASS_6 = 4;
+       public static final int TYPE_6 = 2;
+
        /*
         * fields lengths and offsets for IPv4 in bytes
         */
-       public static final int SRC4_F_LENGTH = 4;
-       public static final int DEST4_F_LENGTH = 4;
+       private static final int SRC4_F_LENGTH = 4;
+       private static final int DEST4_F_LENGTH = 4;
 
-       public static final int SRC4_F_OFFSET = 0;
-       public static final int DEST4_F_OFFSET = SRC4_F_OFFSET + SRC4_F_LENGTH;
-
-       public static final int CLASS_6 = 4;
-
-       public static final int TYPE_6 = 2;
+       private static final int SRC4_F_OFFSET = 0;
+       private static final int DEST4_F_OFFSET = SRC4_F_OFFSET + SRC4_F_LENGTH;
 
-       public static final int SRC6_F_LENGTH = 16;
-       public static final int DEST6_F_LENGTH = 16;
+       private static final int SRC6_F_LENGTH = 16;
+       private static final int DEST6_F_LENGTH = 16;
 
-       public static final int SRC6_F_OFFSET = 0;
-       public static final int DEST6_F_OFFSET = SRC6_F_OFFSET + SRC6_F_LENGTH;
+       private static final int SRC6_F_OFFSET = 0;
+       private static final int DEST6_F_OFFSET = SRC6_F_OFFSET + SRC6_F_LENGTH;
 
        public PCEPEndPointsObjectParser(final TlvHandlerRegistry tlvReg) {
                super(tlvReg);
@@ -60,7 +57,7 @@ public class PCEPEndPointsObjectParser extends AbstractObjectWithTlvsParser<Endp
 
        @Override
        public EndpointsObject parseObject(final ObjectHeader header, final byte[] bytes) throws PCEPDeserializerException,
-       PCEPDocumentedException {
+                       PCEPDocumentedException {
                if (bytes == null) {
                        throw new IllegalArgumentException("Array of bytes is mandatory");
                }
index a2700cae8a3162b5214e024b3b6b0dc0b6a8955e..05e9b4f0a9ed582d655645220506788d1901bfa2 100644 (file)
@@ -10,7 +10,6 @@ package org.opendaylight.protocol.pcep.impl.object;
 import org.opendaylight.protocol.pcep.PCEPDeserializerException;
 import org.opendaylight.protocol.pcep.PCEPDocumentedException;
 import org.opendaylight.protocol.pcep.impl.Util;
-import org.opendaylight.protocol.pcep.impl.message.AbstractObjectWithTlvsParser;
 import org.opendaylight.protocol.pcep.spi.TlvHandlerRegistry;
 import org.opendaylight.protocol.util.ByteArray;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object;
index add8e19bfe02739226a28c7e22eb67f7bab781c6..726ebf79682e27c34eabceaccc829ecfb518685e 100644 (file)
@@ -9,7 +9,6 @@ package org.opendaylight.protocol.pcep.impl.object;
 
 import org.opendaylight.protocol.pcep.PCEPDeserializerException;
 import org.opendaylight.protocol.pcep.PCEPDocumentedException;
-import org.opendaylight.protocol.pcep.impl.message.AbstractObjectWithTlvsParser;
 import org.opendaylight.protocol.pcep.spi.TlvHandlerRegistry;
 import org.opendaylight.protocol.util.ByteArray;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.GcObject;
index 8eb1d4035b3b7b38a3d68b9fd5c634d887f2d014..fd649e826fb3af50bc78481038df4c0759ab27c9 100644 (file)
@@ -9,7 +9,6 @@ package org.opendaylight.protocol.pcep.impl.object;
 
 import org.opendaylight.protocol.pcep.PCEPDeserializerException;
 import org.opendaylight.protocol.pcep.PCEPDocumentedException;
-import org.opendaylight.protocol.pcep.impl.message.AbstractObjectWithTlvsParser;
 import org.opendaylight.protocol.pcep.spi.TlvHandlerRegistry;
 import org.opendaylight.protocol.util.ByteArray;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ieee754.rev130819.Float32;
@@ -19,8 +18,10 @@ 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.Tlv;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcreq.message.pcreq.message.requests.segment.computation.p2p.LoadBalancingBuilder;
 
+import com.google.common.primitives.UnsignedBytes;
+
 /**
- * Parser for {@link org.opendaylight.protocol.pcep.object.PCEPLoadBalancingObject PCEPLoadBalancingObject}
+ * Parser for {@link LoadBalancingObject}
  */
 public class PCEPLoadBalancingObjectParser extends AbstractObjectWithTlvsParser<LoadBalancingBuilder> {
 
@@ -28,15 +29,15 @@ public class PCEPLoadBalancingObjectParser extends AbstractObjectWithTlvsParser<
 
        public static final int TYPE = 1;
 
-       public static final int FLAGS_F_LENGTH = 1;
-       public static final int MAX_LSP_F_LENGTH = 1;
-       public static final int MIN_BAND_F_LENGTH = 4;
+       private static final int FLAGS_F_LENGTH = 1;
+       private static final int MAX_LSP_F_LENGTH = 1;
+       private static final int MIN_BAND_F_LENGTH = 4;
 
-       public static final int FLAGS_F_OFFSET = 2;
-       public static final int MAX_LSP_F_OFFSET = FLAGS_F_OFFSET + FLAGS_F_LENGTH;
-       public static final int MIN_BAND_F_OFFSET = MAX_LSP_F_OFFSET + MAX_LSP_F_LENGTH;
+       private static final int FLAGS_F_OFFSET = 2;
+       private static final int MAX_LSP_F_OFFSET = FLAGS_F_OFFSET + FLAGS_F_LENGTH;
+       private static final int MIN_BAND_F_OFFSET = MAX_LSP_F_OFFSET + MAX_LSP_F_LENGTH;
 
-       public static final int SIZE = MIN_BAND_F_OFFSET + MIN_BAND_F_LENGTH;
+       private static final int SIZE = MIN_BAND_F_OFFSET + MIN_BAND_F_LENGTH;
 
        public PCEPLoadBalancingObjectParser(final TlvHandlerRegistry tlvReg) {
                super(tlvReg);
@@ -44,23 +45,18 @@ public class PCEPLoadBalancingObjectParser extends AbstractObjectWithTlvsParser<
 
        @Override
        public LoadBalancingObject parseObject(final ObjectHeader header, final byte[] bytes) throws PCEPDeserializerException,
-       PCEPDocumentedException {
+                       PCEPDocumentedException {
                if (bytes == null || bytes.length == 0) {
                        throw new IllegalArgumentException("Byte array is mandatory. Can't be null or empty.");
                }
-
                if (bytes.length != SIZE) {
                        throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + bytes.length + "; Expected: " + SIZE + ".");
                }
-
                final LoadBalancingBuilder builder = new LoadBalancingBuilder();
-
                builder.setIgnore(header.isIgnore());
                builder.setProcessingRule(header.isProcessingRule());
-
-               builder.setMaxLsp((short) (bytes[MAX_LSP_F_OFFSET] & 0xFF));
+               builder.setMaxLsp((short) UnsignedBytes.toInt(bytes[MAX_LSP_F_OFFSET]));
                builder.setMinBandwidth(new Float32(ByteArray.subByte(bytes, MIN_BAND_F_OFFSET, MIN_BAND_F_LENGTH)));
-
                return builder.build();
        }
 
@@ -75,14 +71,10 @@ public class PCEPLoadBalancingObjectParser extends AbstractObjectWithTlvsParser<
                        throw new IllegalArgumentException("Wrong instance of PCEPObject. Passed " + object.getClass()
                                        + ". Needed LoadBalancingObject.");
                }
-
                final LoadBalancingObject specObj = (LoadBalancingObject) object;
-
                final byte[] retBytes = new byte[SIZE];
-
-               retBytes[MAX_LSP_F_OFFSET] = ByteArray.shortToBytes(specObj.getMaxLsp())[1];
+               retBytes[MAX_LSP_F_OFFSET] = UnsignedBytes.checkedCast(specObj.getMaxLsp());
                ByteArray.copyWhole(specObj.getMinBandwidth().getValue(), retBytes, MIN_BAND_F_OFFSET);
-
                return retBytes;
        }
 
index 9b8461010700b77e3f5abfeac1590f11e7372f65..c29d5a6fa3bc5f7acf0f7a833f2f4c24fb77b855 100644 (file)
@@ -11,7 +11,6 @@ import java.util.BitSet;
 
 import org.opendaylight.protocol.pcep.PCEPDeserializerException;
 import org.opendaylight.protocol.pcep.PCEPDocumentedException;
-import org.opendaylight.protocol.pcep.impl.message.AbstractObjectWithTlvsParser;
 import org.opendaylight.protocol.pcep.spi.TlvHandlerRegistry;
 import org.opendaylight.protocol.util.ByteArray;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.LspObject;
index 6745c01f29a8162c212d9d0430f4e0a3864b3c2d..66d9383f2452e9bb6241601c2e674e04836ae3d7 100644 (file)
@@ -11,7 +11,6 @@ import java.util.BitSet;
 
 import org.opendaylight.protocol.pcep.PCEPDeserializerException;
 import org.opendaylight.protocol.pcep.PCEPDocumentedException;
-import org.opendaylight.protocol.pcep.impl.message.AbstractObjectWithTlvsParser;
 import org.opendaylight.protocol.pcep.spi.TlvHandlerRegistry;
 import org.opendaylight.protocol.util.ByteArray;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.LspaObject;
index bef8f5710eda1e0090dab906f813629490250e5b..5b5319e09be58ecca08287ae07e7c9a072490b2c 100644 (file)
@@ -11,7 +11,6 @@ import java.util.BitSet;
 
 import org.opendaylight.protocol.pcep.PCEPDeserializerException;
 import org.opendaylight.protocol.pcep.PCEPDocumentedException;
-import org.opendaylight.protocol.pcep.impl.message.AbstractObjectWithTlvsParser;
 import org.opendaylight.protocol.pcep.spi.TlvHandlerRegistry;
 import org.opendaylight.protocol.util.ByteArray;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ieee754.rev130819.Float32;
@@ -22,8 +21,10 @@ 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.pcreq.message.pcreq.message.svec.Metric;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcreq.message.pcreq.message.svec.MetricBuilder;
 
+import com.google.common.primitives.UnsignedBytes;
+
 /**
- * Parser for {@link org.opendaylight.protocol.pcep.object.PCEPMetricObject PCEPMetricObject}
+ * Parser for {@link MetricObject}
  */
 public class PCEPMetricObjectParser extends AbstractObjectWithTlvsParser<MetricBuilder> {
 
@@ -41,9 +42,9 @@ public class PCEPMetricObjectParser extends AbstractObjectWithTlvsParser<MetricB
        /*
         * offsets of fields in bytes
         */
-       public static final int FLAGS_F_OFFSET = 2;
-       public static final int TYPE_F_OFFSET = FLAGS_F_OFFSET + FLAGS_F_LENGTH;
-       public static final int METRIC_VALUE_F_OFFSET = TYPE_F_OFFSET + TYPE_F_LENGTH;
+       private static final int FLAGS_F_OFFSET = 2;
+       private static final int TYPE_F_OFFSET = FLAGS_F_OFFSET + FLAGS_F_LENGTH;
+       private static final int METRIC_VALUE_F_OFFSET = TYPE_F_OFFSET + TYPE_F_LENGTH;
 
        /*
         * flags offsets inside flags field in bits
@@ -51,7 +52,7 @@ public class PCEPMetricObjectParser extends AbstractObjectWithTlvsParser<MetricB
        private static final int C_FLAG_OFFSET = 6;
        private static final int B_FLAG_OFFSET = 7;
 
-       public static final int SIZE = METRIC_VALUE_F_OFFSET + METRIC_VALUE_F_LENGTH;
+       private static final int SIZE = METRIC_VALUE_F_OFFSET + METRIC_VALUE_F_LENGTH;
 
        public PCEPMetricObjectParser(final TlvHandlerRegistry tlvReg) {
                super(tlvReg);
@@ -59,7 +60,7 @@ public class PCEPMetricObjectParser extends AbstractObjectWithTlvsParser<MetricB
 
        @Override
        public MetricObject parseObject(final ObjectHeader header, final byte[] bytes) throws PCEPDeserializerException,
-       PCEPDocumentedException {
+                       PCEPDocumentedException {
                if (bytes == null || bytes.length == 0) {
                        throw new IllegalArgumentException("Array of bytes is mandatory. Can't be null or empty.");
                }
@@ -68,17 +69,13 @@ public class PCEPMetricObjectParser extends AbstractObjectWithTlvsParser<MetricB
                }
                final byte[] flagBytes = { bytes[FLAGS_F_OFFSET] };
                final BitSet flags = ByteArray.bytesToBitSet(flagBytes);
-
                final MetricBuilder builder = new MetricBuilder();
-
                builder.setIgnore(header.isIgnore());
                builder.setProcessingRule(header.isProcessingRule());
-
                builder.setBound(flags.get(B_FLAG_OFFSET));
                builder.setComputed(flags.get(C_FLAG_OFFSET));
-               builder.setMetricType((short) (bytes[TYPE_F_OFFSET] & 0xFF));
+               builder.setMetricType((short) UnsignedBytes.toInt(bytes[TYPE_F_OFFSET]));
                builder.setValue(new Float32(ByteArray.subByte(bytes, METRIC_VALUE_F_OFFSET, METRIC_VALUE_F_LENGTH)));
-
                return builder.build();
        }
 
@@ -92,18 +89,14 @@ public class PCEPMetricObjectParser extends AbstractObjectWithTlvsParser<MetricB
                if (!(object instanceof MetricObject)) {
                        throw new IllegalArgumentException("Wrong instance of PCEPObject. Passed " + object.getClass() + ". Needed MetricObject.");
                }
-
                final MetricObject mObj = (MetricObject) object;
-
                final byte[] retBytes = new byte[SIZE];
                final BitSet flags = new BitSet(FLAGS_F_LENGTH * Byte.SIZE);
                flags.set(C_FLAG_OFFSET, ((Metric) mObj).isComputed());
                flags.set(B_FLAG_OFFSET, mObj.isBound());
-
                ByteArray.copyWhole(ByteArray.bitSetToBytes(flags, FLAGS_F_LENGTH), retBytes, FLAGS_F_OFFSET);
-
+               retBytes[TYPE_F_OFFSET] = UnsignedBytes.checkedCast(mObj.getMetricType());
                System.arraycopy(mObj.getValue().getValue(), 0, retBytes, METRIC_VALUE_F_OFFSET, METRIC_VALUE_F_LENGTH);
-
                return retBytes;
        }
 
index 19355b75e57e60ab817210da253792b8266f0e9f..8907138ed6504bdfabaf8caf5714f921fa4a053b 100644 (file)
@@ -12,7 +12,6 @@ import java.util.BitSet;
 import org.opendaylight.protocol.pcep.PCEPDeserializerException;
 import org.opendaylight.protocol.pcep.PCEPDocumentedException;
 import org.opendaylight.protocol.pcep.impl.Util;
-import org.opendaylight.protocol.pcep.impl.message.AbstractObjectWithTlvsParser;
 import org.opendaylight.protocol.pcep.spi.TlvHandlerRegistry;
 import org.opendaylight.protocol.util.ByteArray;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcrep.message.pcrep.message.replies.result.failure.NoPath;
index 4168ca0017edeaf91a634d33d4a950affd327b17..57b7352885a2b45beef9168eedf92cd861662300 100644 (file)
@@ -10,7 +10,6 @@ package org.opendaylight.protocol.pcep.impl.object;
 import org.opendaylight.protocol.pcep.PCEPDeserializerException;
 import org.opendaylight.protocol.pcep.PCEPDocumentedException;
 import org.opendaylight.protocol.pcep.impl.Util;
-import org.opendaylight.protocol.pcep.impl.message.AbstractObjectWithTlvsParser;
 import org.opendaylight.protocol.pcep.spi.TlvHandlerRegistry;
 import org.opendaylight.protocol.util.ByteArray;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.NotificationObject;
index 9654b0691bb5de635b3ffe724eeb40893a0fd4f4..e4330429e72b916f71a0831a5ab1056de6bf9f6b 100644 (file)
@@ -9,7 +9,6 @@ package org.opendaylight.protocol.pcep.impl.object;
 
 import org.opendaylight.protocol.pcep.PCEPDeserializerException;
 import org.opendaylight.protocol.pcep.PCEPDocumentedException;
-import org.opendaylight.protocol.pcep.impl.message.AbstractObjectWithTlvsParser;
 import org.opendaylight.protocol.pcep.spi.TlvHandlerRegistry;
 import org.opendaylight.protocol.util.ByteArray;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object;
index 29444baa4fbad0e1f103a83c579d0477b6c43cd7..609c50ac5588a29b3f2f3cfca1255fbd6b653622 100644 (file)
@@ -12,7 +12,6 @@ import org.opendaylight.protocol.pcep.PCEPDeserializerException;
 import org.opendaylight.protocol.pcep.PCEPDocumentedException;
 import org.opendaylight.protocol.pcep.PCEPErrors;
 import org.opendaylight.protocol.pcep.impl.Util;
-import org.opendaylight.protocol.pcep.impl.message.AbstractObjectWithTlvsParser;
 import org.opendaylight.protocol.pcep.spi.TlvHandlerRegistry;
 import org.opendaylight.protocol.util.ByteArray;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.LspDbVersionTlv;
index 570f054cfea6ba9c9363660e47924a7630821c85..f535303104b85ce6d51d4b98a658000bf7aad321 100644 (file)
@@ -9,7 +9,6 @@ package org.opendaylight.protocol.pcep.impl.object;
 
 import org.opendaylight.protocol.pcep.PCEPDeserializerException;
 import org.opendaylight.protocol.pcep.PCEPDocumentedException;
-import org.opendaylight.protocol.pcep.impl.message.AbstractObjectWithTlvsParser;
 import org.opendaylight.protocol.pcep.spi.TlvHandlerRegistry;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ObjectHeader;
index 3e174c3caf397b859375f0e4bd7277932e419c87..344ae406e6e8328cac04de3d44f66160260f088a 100644 (file)
@@ -14,7 +14,6 @@ import java.util.BitSet;
 import org.opendaylight.protocol.pcep.PCEPDeserializerException;
 import org.opendaylight.protocol.pcep.PCEPDocumentedException;
 import org.opendaylight.protocol.pcep.impl.Util;
-import org.opendaylight.protocol.pcep.impl.message.AbstractObjectWithTlvsParser;
 import org.opendaylight.protocol.pcep.spi.TlvHandlerRegistry;
 import org.opendaylight.protocol.util.ByteArray;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object;
index 1daac5fb191273730c96d08658d92835e4dc9da0..ac56d211a1c222135679e124d077f079893cfebc 100644 (file)
@@ -9,7 +9,6 @@ package org.opendaylight.protocol.pcep.impl.object;
 
 import org.opendaylight.protocol.pcep.PCEPDeserializerException;
 import org.opendaylight.protocol.pcep.PCEPDocumentedException;
-import org.opendaylight.protocol.pcep.impl.message.AbstractObjectWithTlvsParser;
 import org.opendaylight.protocol.pcep.spi.TlvHandlerRegistry;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ObjectHeader;
index c3f6b142761d30b2856a3af69e274c82ec7bb79b..d7f45f39e03419566c8b6d153fc7e2fa7b417f3f 100644 (file)
@@ -12,7 +12,6 @@ import java.util.List;
 
 import org.opendaylight.protocol.pcep.PCEPDeserializerException;
 import org.opendaylight.protocol.pcep.PCEPDocumentedException;
-import org.opendaylight.protocol.pcep.impl.message.AbstractObjectWithTlvsParser;
 import org.opendaylight.protocol.pcep.spi.TlvHandlerRegistry;
 import org.opendaylight.protocol.util.ByteArray;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object;
@@ -36,26 +35,26 @@ public class PCEPSvecObjectParser extends AbstractObjectWithTlvsParser<SvecBuild
        /*
         * field lengths in bytes
         */
-       public static final int FLAGS_F_LENGTH = 3;
-       public static final int REQ_LIST_ITEM_LENGTH = 4;
+       private static final int FLAGS_F_LENGTH = 3;
+       private static final int REQ_LIST_ITEM_LENGTH = 4;
 
        /*
         * fields offsets in bytes
         */
-       public static final int FLAGS_F_OFFSET = 1; // aded reserved field of size 1
-       public static final int REQ_ID_LIST_OFFSET = FLAGS_F_OFFSET + FLAGS_F_LENGTH;
+       private static final int FLAGS_F_OFFSET = 1;
+       private static final int REQ_ID_LIST_OFFSET = FLAGS_F_OFFSET + FLAGS_F_LENGTH;
 
        /*
         * flags offsets inside flags field in bits
         */
-       public static final int S_FLAG_OFFSET = 21;
-       public static final int N_FLAG_OFFSET = 22;
-       public static final int L_FLAG_OFFSET = 23;
+       private static final int S_FLAG_OFFSET = 21;
+       private static final int N_FLAG_OFFSET = 22;
+       private static final int L_FLAG_OFFSET = 23;
 
        /*
         * min size in bytes
         */
-       public static final int MIN_SIZE = FLAGS_F_LENGTH + FLAGS_F_OFFSET;
+       private static final int MIN_SIZE = FLAGS_F_LENGTH + FLAGS_F_OFFSET;
 
        public PCEPSvecObjectParser(final TlvHandlerRegistry tlvReg) {
                super(tlvReg);
@@ -66,23 +65,19 @@ public class PCEPSvecObjectParser extends AbstractObjectWithTlvsParser<SvecBuild
                if (bytes == null || bytes.length == 0) {
                        throw new IllegalArgumentException("Array of bytes is mandatory. Can't be null or empty.");
                }
-
                if (bytes.length < MIN_SIZE) {
                        throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + bytes.length + "; Expected: >=" + MIN_SIZE
                                        + ".");
                }
-
                final BitSet flags = ByteArray.bytesToBitSet(ByteArray.subByte(bytes, FLAGS_F_OFFSET, FLAGS_F_LENGTH));
                final List<RequestId> requestIDs = Lists.newArrayList();
 
                for (int i = REQ_ID_LIST_OFFSET; i < bytes.length; i += REQ_LIST_ITEM_LENGTH) {
                        requestIDs.add(new RequestId(ByteArray.bytesToLong(ByteArray.subByte(bytes, i, REQ_LIST_ITEM_LENGTH))));
                }
-
                if (requestIDs.isEmpty()) {
                        throw new PCEPDeserializerException("Empty Svec Object - no request ids.");
                }
-
                final SvecBuilder builder = new SvecBuilder();
 
                builder.setIgnore(header.isIgnore());
@@ -120,9 +115,7 @@ public class PCEPSvecObjectParser extends AbstractObjectWithTlvsParser<SvecBuild
                        System.arraycopy(ByteArray.longToBytes(requestIDs.get(i).getValue()), 4, retBytes, REQ_LIST_ITEM_LENGTH * i
                                        + REQ_ID_LIST_OFFSET, REQ_LIST_ITEM_LENGTH);
                }
-
                assert !(requestIDs.isEmpty()) : "Empty Svec Object - no request ids.";
-
                return retBytes;
        }
 
index d36eb106557b44ebf891a8b23b58c72bc85c5791..f3db4f9bf12890d2c3ae16bd5412ec17680d2868 100644 (file)
@@ -7,8 +7,41 @@
  */
 package org.opendaylight.protocol.pcep.impl;
 
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
 
-/**
+import java.io.IOException;
+import java.util.List;
+
+import org.junit.Before;
+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.PCEPDocumentedException;
+import org.opendaylight.protocol.pcep.impl.object.PCEPBandwidthObjectParser;
+import org.opendaylight.protocol.pcep.impl.object.PCEPEndPointsObjectParser;
+import org.opendaylight.protocol.pcep.impl.object.PCEPLoadBalancingObjectParser;
+import org.opendaylight.protocol.pcep.impl.object.PCEPMetricObjectParser;
+import org.opendaylight.protocol.pcep.impl.object.PCEPSvecObjectParser;
+import org.opendaylight.protocol.pcep.spi.ObjectHeaderImpl;
+import org.opendaylight.protocol.pcep.spi.TlvHandlerRegistry;
+import org.opendaylight.protocol.pcep.spi.pojo.PCEPExtensionProviderContextImpl;
+import org.opendaylight.protocol.util.ByteArray;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ieee754.rev130819.Float32;
+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.endpoints.object.address.family.Ipv4Builder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.endpoints.object.address.family.Ipv6Builder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcinitiate.message.pcinitiate.message.requests.EndpointsBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcreq.message.pcreq.message.SvecBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcreq.message.pcreq.message.requests.segment.computation.p2p.LoadBalancingBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcreq.message.pcreq.message.requests.segment.computation.p2p.reported.route.BandwidthBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcreq.message.pcreq.message.svec.MetricBuilder;
+
+import com.google.common.collect.Lists;
+import com.google.common.primitives.UnsignedBytes;
+
+/*
  * Used resources<br/>
  * <br/>
  * PCEPOpenObject3.bin<br/>
@@ -322,26 +355,19 @@ package org.opendaylight.protocol.pcep.impl;
  */
 public class PCEPObjectParserTest {
 
-       // @Mock
-       // private HandlerRegistry registry;
-       //
+       private TlvHandlerRegistry tlvRegistry;
+
+       @Before
+       public void setUp() throws Exception {
+               this.tlvRegistry = PCEPExtensionProviderContextImpl.create().getTlvHandlerRegistry();
+       }
+
        // IPv4Address ipv4addr = new IPv4Address(new byte[] { (byte) 192, (byte) 168, 1, 8 });
        //
        // IPv6Address ipv6addr = new IPv6Address(new byte[] { (byte) 192, (byte) 168, 2, 1, (byte) 192, (byte) 168, 2, 1,
        // (byte) 192, (byte) 168,
        // 2, 1, (byte) 192, (byte) 168, 2, 1 });
        //
-       // @SuppressWarnings("unchecked")
-       // private static <T extends PCEPObject> void serDeserTest(final String srcFile, final T specObject) throws
-       // IOException,
-       // PCEPDeserializerException, PCEPDocumentedException {
-       // final byte[] bytesFromFile = ByteArray.fileToBytes(srcFile);
-       // final T deserSpecObj = (T) PCEPObjectFactory.parseObjects(bytesFromFile).get(0);
-       // final byte[] serSpecObj = PCEPObjectFactory.put(Arrays.asList((PCEPObject) specObject));
-       //
-       // assertEquals(specObject, deserSpecObj);
-       // assertArrayEquals(bytesFromFile, serSpecObj);
-       // }
        //
        // /**
        // * Standard serialization test<br/>
@@ -384,15 +410,21 @@ public class PCEPObjectParserTest {
        // // serDeserTest("src/test/resources/PCEPCloseObject1.bin", new PCEPCloseObject(Reason.TOO_MANY_UNKNOWN_MSG));
        // // }
        //
-       // @Test
-       // @Ignore
-       // // FIXME BUG-89
-       // public void testLoadBalancingObjSerDeser() throws IOException, PCEPDeserializerException, PCEPDocumentedException
-       // {
-       // serDeserTest("src/test/resources/PCEPLoadBalancingObject1.bin", new PCEPLoadBalancingObject(0xF1, new
-       // Bandwidth(new byte[] {
-       // (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF }), true));
-       // }
+       @Test
+       public void testLoadBalancingObject() throws IOException, PCEPDeserializerException, PCEPDocumentedException {
+               final PCEPLoadBalancingObjectParser parser = new PCEPLoadBalancingObjectParser(this.tlvRegistry);
+               final byte[] result = ByteArray.fileToBytes("src/test/resources/PCEPLoadBalancingObject1.bin");
+
+               final LoadBalancingBuilder builder = new LoadBalancingBuilder();
+               builder.setProcessingRule(true);
+               builder.setIgnore(false);
+               builder.setMaxLsp((short) UnsignedBytes.toInt((byte) 0xf1));
+               builder.setMinBandwidth(new Float32(new byte[] { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF }));
+
+               assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, false), result));
+               assertArrayEquals(result, parser.serializeObject(builder.build()));
+       }
+
        //
        // @Test
        // public void testLspObjectSerDeser() throws IOException, PCEPDeserializerException, PCEPDocumentedException {
@@ -467,65 +499,66 @@ public class PCEPObjectParserTest {
        // assertArrayEquals(bytesFromFile, bytesActual);
        // }
        //
-       // /**
-       // * Test for upper/lower bounds (Serialization/Deserialization)<br/>
-       // * Used resources:<br/>
-       // * - PCEPBandwidthObject2UpperBounds.bin<br/>
-       // * - PCEPBandwidthObject1LowerBounds.bin<br/>
-       // *
-       // * @throws IOException
-       // * @throws PCEPDeserializerException
-       // * @throws PCEPDocumentedException
-       // */
-       // @Test
-       // @Ignore
-       // // FIXME BUG-89
-       // public void testBandwidthObjectBounds() throws IOException, PCEPDeserializerException, PCEPDocumentedException {
-       // serDeserTest("src/test/resources/PCEPBandwidthObject1LowerBounds.bin",
-       // new PCEPRequestedPathBandwidthObject(new Bandwidth(new byte[] { 0, 0, 0, 0 }), true, true));
-       // }
-       //
-       // /**
-       // * Test for upper/lower bounds of IPv4 EndPoints (Serialization/Deserialization)<br/>
-       // * Used resources:<br/>
-       // * - PCEPEndPointsObject1IPv4.bin<br/>
-       // *
-       // * @throws IOException
-       // * @throws PCEPDeserializerException
-       // * @throws PCEPDocumentedException
-       // */
-       // @Test
-       // public void testEndPointsObjectSerDeserIPv4() throws IOException, PCEPDeserializerException,
-       // PCEPDocumentedException {
-       // final byte[] srcIPBytes = { (byte) 0xA2, (byte) 0xF5, (byte) 0x11, (byte) 0x0E };
-       // final byte[] destIPBytes = { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF };
-       // serDeserTest("src/test/resources/PCEPEndPointsObject1IPv4.bin",
-       // new PCEPEndPointsObject<IPv4Address>(new IPv4Address(srcIPBytes), new IPv4Address(destIPBytes)));
-       // }
-       //
-       // /**
-       // * Test for upper/lower bounds of IPv6 EndPoints (Serialization/Deserialization)<br/>
-       // * Used resources:<br/>
-       // * - PCEPEndPointsObject2IPv6.bin<br/>
-       // *
-       // * @throws IOException
-       // * @throws PCEPDeserializerException
-       // * @throws PCEPDocumentedException
-       // */
-       // @Test
-       // public void testEndPointsObjectSerDeserIPv6() throws IOException, PCEPDeserializerException,
-       // PCEPDocumentedException {
-       // final byte[] destIPBytes = { (byte) 0x00, (byte) 0x02, (byte) 0x5D, (byte) 0xD2, (byte) 0xFF, (byte) 0xEC, (byte)
-       // 0xA1,
-       // (byte) 0xB6, (byte) 0x58, (byte) 0x1E, (byte) 0x9F, (byte) 0x50, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte)
-       // 0x00, };
-       // final byte[] srcIPBytes = { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte)
-       // 0xFF, (byte) 0xFF,
-       // (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF };
-       //
-       // serDeserTest("src/test/resources/PCEPEndPointsObject2IPv6.bin",
-       // new PCEPEndPointsObject<IPv6Address>(new IPv6Address(srcIPBytes), new IPv6Address(destIPBytes)));
-       // }
+
+       @Test
+       public void testBandwidthObject() throws IOException, PCEPDeserializerException, PCEPDocumentedException {
+               final PCEPBandwidthObjectParser parser = new PCEPBandwidthObjectParser(this.tlvRegistry);
+               byte[] result = ByteArray.fileToBytes("src/test/resources/PCEPBandwidthObject1LowerBounds.bin");
+
+               final BandwidthBuilder builder = new BandwidthBuilder();
+               builder.setProcessingRule(true);
+               builder.setIgnore(true);
+               builder.setBandwidth(new Float32(result));
+
+               assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result));
+               assertArrayEquals(result, parser.serializeObject(builder.build()));
+
+               result = ByteArray.fileToBytes("src/test/resources/PCEPBandwidthObject2UpperBounds.bin");
+
+               builder.setBandwidth(new Float32(result));
+
+               assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result));
+               assertArrayEquals(result, parser.serializeObject(builder.build()));
+       }
+
+       @Test
+       public void testEndPointsObjectIPv4() throws IOException, PCEPDeserializerException, PCEPDocumentedException {
+               final byte[] srcIPBytes = { (byte) 0xA2, (byte) 0xF5, (byte) 0x11, (byte) 0x0E };
+               final byte[] destIPBytes = { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF };
+
+               final PCEPEndPointsObjectParser parser = new PCEPEndPointsObjectParser(this.tlvRegistry);
+               final byte[] result = ByteArray.fileToBytes("src/test/resources/PCEPEndPointsObject1IPv4.bin");
+
+               final EndpointsBuilder builder = new EndpointsBuilder();
+               builder.setProcessingRule(true);
+               builder.setIgnore(false);
+               builder.setAddressFamily(new Ipv4Builder().setSourceIpv4Address(Ipv4Util.addressForBytes(srcIPBytes)).setDestinationIpv4Address(
+                               Ipv4Util.addressForBytes(destIPBytes)).build());
+
+               assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, false), result));
+               assertArrayEquals(result, parser.serializeObject(builder.build()));
+       }
+
+       @Test
+       public void testEndPointsObjectSerDeserIPv6() throws IOException, PCEPDeserializerException, PCEPDocumentedException {
+               final byte[] destIPBytes = { (byte) 0x00, (byte) 0x02, (byte) 0x5D, (byte) 0xD2, (byte) 0xFF, (byte) 0xEC, (byte) 0xA1,
+                               (byte) 0xB6, (byte) 0x58, (byte) 0x1E, (byte) 0x9F, (byte) 0x50, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, };
+               final byte[] srcIPBytes = { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
+                               (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF };
+
+               final PCEPEndPointsObjectParser parser = new PCEPEndPointsObjectParser(this.tlvRegistry);
+               final byte[] result = ByteArray.fileToBytes("src/test/resources/PCEPEndPointsObject2IPv6.bin");
+
+               final EndpointsBuilder builder = new EndpointsBuilder();
+               builder.setProcessingRule(true);
+               builder.setIgnore(false);
+               builder.setAddressFamily(new Ipv6Builder().setSourceIpv6Address(Ipv6Util.addressForBytes(srcIPBytes)).setDestinationIpv6Address(
+                               Ipv6Util.addressForBytes(destIPBytes)).build());
+
+               assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, false), result));
+               assertArrayEquals(result, parser.serializeObject(builder.build()));
+       }
+
        //
        // /**
        // * Test of Serialization/Deserialization of PCEPErrorObjectParser.<br/>
@@ -582,25 +615,34 @@ public class PCEPObjectParserTest {
        // new PCEPLspaObject(0x20A1FEE3L, 0x1A025CC7L, 0x2BB66532L, (short) 0x03, (short) 0x02, false, true, true, true));
        // }
        //
-       // @Test
-       // public void testMetricObjectSerDeserBounds() throws IOException, PCEPDeserializerException,
-       // PCEPDocumentedException {
-       // final byte[] bytesFromFileUB = ByteArray.fileToBytes("src/test/resources/PCEPMetricObject2UpperBounds.bin");
-       // final byte[] bytesFromFileLB = ByteArray.fileToBytes("src/test/resources/PCEPMetricObject1LowerBounds.bin");
-       //
-       // final PCEPMetricObject metricObjectLB = (PCEPMetricObject)
-       // PCEPObjectFactory.parseObjects(bytesFromFileLB).get(0);
-       // final PCEPMetricObject metricObjectUB = (PCEPMetricObject)
-       // PCEPObjectFactory.parseObjects(bytesFromFileUB).get(0);
-       //
-       // assertEquals(new PCEPMetricObject(false, false, new IGPMetric(0), true, true), metricObjectLB);
-       // assertEquals(new PCEPMetricObject(false, true, new TEMetric(4026531840L), true, true), metricObjectUB);
-       //
-       // final byte[] bytesActualLB = PCEPObjectFactory.put(Arrays.asList((PCEPObject) metricObjectLB));
-       // final byte[] bytesActualUB = PCEPObjectFactory.put(Arrays.asList((PCEPObject) metricObjectUB));
-       // assertArrayEquals(bytesFromFileLB, bytesActualLB);
-       // assertArrayEquals(bytesFromFileUB, bytesActualUB);
-       // }
+
+       @Test
+       public void testMetricObject() throws IOException, PCEPDeserializerException, PCEPDocumentedException {
+               final PCEPMetricObjectParser parser = new PCEPMetricObjectParser(this.tlvRegistry);
+               byte[] result = ByteArray.fileToBytes("src/test/resources/PCEPMetricObject1LowerBounds.bin");
+
+               final MetricBuilder builder = new MetricBuilder();
+               builder.setProcessingRule(true);
+               builder.setIgnore(true);
+               builder.setComputed(false);
+               builder.setBound(false);
+               builder.setMetricType((short) 1);
+               builder.setValue(new Float32(new byte[] { 0, 0, 0, 0 }));
+
+               assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result));
+               assertArrayEquals(result, parser.serializeObject(builder.build()));
+
+               result = ByteArray.fileToBytes("src/test/resources/PCEPMetricObject2UpperBounds.bin");
+
+               builder.setComputed(true);
+               builder.setBound(false);
+               builder.setMetricType((short) 2);
+               builder.setValue(new Float32(new byte[] { (byte) 0x4f, (byte) 0x70, (byte) 0x00, (byte) 0x00 }));
+
+               assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result));
+               assertArrayEquals(result, parser.serializeObject(builder.build()));
+       }
+
        //
        // /**
        // * Standard deserialization test + specific test without tlv<br/>
@@ -736,50 +778,47 @@ public class PCEPObjectParserTest {
        // // }, false, false));
        // }
        //
-       // /**
-       // * Test for upper/lower bounds of PCEPSvecObject (Serialization/Deserialization)<br/>
-       // * Used resources:<br/>
-       // * - PCEPSvecObject1_10ReqIDs.bin<br/>
-       // *
-       // * @throws IOException
-       // * @throws PCEPDeserializerException
-       // * @throws PCEPDocumentedException
-       // */
-       // @Test
-       // public void testSvecObjectSerDeser() throws IOException, PCEPDeserializerException, PCEPDocumentedException {
-       // final List<Long> requestIDs = new ArrayList<Long>(10);
-       // requestIDs.add(0xFFFFFFFFL);
-       // requestIDs.add(0x00000000L);
-       // requestIDs.add(0x01234567L);
-       // requestIDs.add(0x89ABCDEFL);
-       // requestIDs.add(0xFEDCBA98L);
-       // requestIDs.add(0x76543210L);
-       // requestIDs.add(0x15825266L);
-       // requestIDs.add(0x48120BBEL);
-       // requestIDs.add(0x25FB7E52L);
-       // requestIDs.add(0xB2F2546BL);
-       //
-       // serDeserTest("src/test/resources/PCEPSvecObject1_10ReqIDs.bin",
-       // new PCEPSvecObject(true, false, true, false, true, requestIDs, true));
-       // }
-       //
-       // /**
-       // * Test for lowest bounds of PCEPSvecObject (Serialization/Deserialization)<br/>
-       // * Used resources:<br/>
-       // * - PCEPSvecObject2.bin<br/>
-       // *
-       // * @throws IOException
-       // * @throws PCEPDeserializerException
-       // * @throws PCEPDocumentedException
-       // */
-       // @Test
-       // public void testSvecObjectSerDeserNoReqIDs() throws IOException, PCEPDeserializerException,
-       // PCEPDocumentedException {
-       // final List<Long> requestIDs = new ArrayList<Long>();
-       // requestIDs.add(0xFFL);
-       // serDeserTest("src/test/resources/PCEPSvecObject2.bin", new PCEPSvecObject(false, false, false, false, false,
-       // requestIDs, false));
-       // }
+
+       @Test
+       public void testSvecObject() throws IOException, PCEPDeserializerException, PCEPDocumentedException {
+               final PCEPSvecObjectParser parser = new PCEPSvecObjectParser(this.tlvRegistry);
+               byte[] result = ByteArray.fileToBytes("src/test/resources/PCEPSvecObject2.bin");
+
+               final SvecBuilder builder = new SvecBuilder();
+               builder.setProcessingRule(false);
+               builder.setIgnore(false);
+               builder.setLinkDiverse(false);
+               builder.setNodeDiverse(false);
+               builder.setSrlgDiverse(false);
+               builder.setRequestsIds(Lists.newArrayList(new RequestId(0xFFL)));
+
+               assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(false, false), result));
+               assertArrayEquals(result, parser.serializeObject(builder.build()));
+
+               result = ByteArray.fileToBytes("src/test/resources/PCEPSvecObject1_10ReqIDs.bin");
+
+               builder.setProcessingRule(true);
+               builder.setLinkDiverse(true);
+               builder.setSrlgDiverse(true);
+
+               final List<RequestId> requestIDs = Lists.newArrayList();
+               requestIDs.add(new RequestId(0xFFFFFFFFL));
+               requestIDs.add(new RequestId(0x00000000L));
+               requestIDs.add(new RequestId(0x01234567L));
+               requestIDs.add(new RequestId(0x89ABCDEFL));
+               requestIDs.add(new RequestId(0xFEDCBA98L));
+               requestIDs.add(new RequestId(0x76543210L));
+               requestIDs.add(new RequestId(0x15825266L));
+               requestIDs.add(new RequestId(0x48120BBEL));
+               requestIDs.add(new RequestId(0x25FB7E52L));
+               requestIDs.add(new RequestId(0xB2F2546BL));
+
+               builder.setRequestsIds(requestIDs);
+
+               assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, false), result));
+               assertArrayEquals(result, parser.serializeObject(builder.build()));
+       }
+
        //
        // @Test
        // public void testClassTypeObject() throws PCEPDeserializerException, PCEPDocumentedException {
diff --git a/pcep/impl/src/test/resources/LSPStateDBVersionTlv1.bin b/pcep/impl/src/test/resources/LSPStateDBVersionTlv1.bin
deleted file mode 100644 (file)
index 636c636..0000000
Binary files a/pcep/impl/src/test/resources/LSPStateDBVersionTlv1.bin and /dev/null differ
diff --git a/pcep/impl/src/test/resources/LSPStateDBVersionTlv2.bin b/pcep/impl/src/test/resources/LSPStateDBVersionTlv2.bin
deleted file mode 100644 (file)
index cbd64c6..0000000
Binary files a/pcep/impl/src/test/resources/LSPStateDBVersionTlv2.bin and /dev/null differ
diff --git a/pcep/impl/src/test/resources/LSPStateDBVersionTlvInvalid1.bin b/pcep/impl/src/test/resources/LSPStateDBVersionTlvInvalid1.bin
deleted file mode 100644 (file)
index 43c2cfe..0000000
Binary files a/pcep/impl/src/test/resources/LSPStateDBVersionTlvInvalid1.bin and /dev/null differ
diff --git a/pcep/impl/src/test/resources/NoPathObject1WithTLV.bin b/pcep/impl/src/test/resources/NoPathObject1WithTLV.bin
deleted file mode 100644 (file)
index 58ca456..0000000
Binary files a/pcep/impl/src/test/resources/NoPathObject1WithTLV.bin and /dev/null differ
diff --git a/pcep/impl/src/test/resources/NoPathObject2WithoutTLV.bin b/pcep/impl/src/test/resources/NoPathObject2WithoutTLV.bin
deleted file mode 100644 (file)
index 6f89865..0000000
Binary files a/pcep/impl/src/test/resources/NoPathObject2WithoutTLV.bin and /dev/null differ
index e6a25a7df6bac76d14f0b8eb04ec42e92a0689bc..593f4708db84ac8fd0f5cc47c634f38c013fe9e4 100644 (file)
Binary files a/pcep/impl/src/test/resources/PCEPBandwidthObject1LowerBounds.bin and b/pcep/impl/src/test/resources/PCEPBandwidthObject1LowerBounds.bin differ
index 3ebf1ec6dd0ecd622669ff6825ca356465d6cbaf..7bde8641b93c7c55f7365596085b0ce811d0b6c8 100644 (file)
Binary files a/pcep/impl/src/test/resources/PCEPBandwidthObject2UpperBounds.bin and b/pcep/impl/src/test/resources/PCEPBandwidthObject2UpperBounds.bin differ
index addad73ab0ada5b949e04c33512845212d41af94..7a693eab89653098d1d7d5ede44d510c9ccdb67f 100644 (file)
Binary files a/pcep/impl/src/test/resources/PCEPEndPointsObject1IPv4.bin and b/pcep/impl/src/test/resources/PCEPEndPointsObject1IPv4.bin differ
index 9470b7cfa7080a0ef8d36b928c1bde3fc4837ab5..4f41aa403a819924ab2307ba8b567a07dcbace51 100644 (file)
Binary files a/pcep/impl/src/test/resources/PCEPEndPointsObject2IPv6.bin and b/pcep/impl/src/test/resources/PCEPEndPointsObject2IPv6.bin differ
diff --git a/pcep/impl/src/test/resources/PCEPKeepAliveMessage1.bin b/pcep/impl/src/test/resources/PCEPKeepAliveMessage1.bin
deleted file mode 100644 (file)
index dd6707b..0000000
Binary files a/pcep/impl/src/test/resources/PCEPKeepAliveMessage1.bin and /dev/null differ
index 7070f4b587282755f86e0cfa9b4326f5a3defe51..357cfbf279ac888dfda8e381a525330484ba456b 100644 (file)
Binary files a/pcep/impl/src/test/resources/PCEPLoadBalancingObject1.bin and b/pcep/impl/src/test/resources/PCEPLoadBalancingObject1.bin differ
index bb6c3a766f7e85a0c2a7b90548825752586f6839..46426b1617fe258a6500bfba3eb6daea70933b74 100644 (file)
Binary files a/pcep/impl/src/test/resources/PCEPMetricObject1LowerBounds.bin and b/pcep/impl/src/test/resources/PCEPMetricObject1LowerBounds.bin differ
index 4b80f385591b40a8b1a8270c0c79262869a2f54b..49eee514f7f37d55224e45fac18a78c7ebe5fdea 100644 (file)
Binary files a/pcep/impl/src/test/resources/PCEPMetricObject2UpperBounds.bin and b/pcep/impl/src/test/resources/PCEPMetricObject2UpperBounds.bin differ
index 7e75b794f27475379597092dfe77804da20d8c1c..012710f6ac768414697d32b6b7ccbba175f7675c 100644 (file)
Binary files a/pcep/impl/src/test/resources/PCEPSvecObject1_10ReqIDs.bin and b/pcep/impl/src/test/resources/PCEPSvecObject1_10ReqIDs.bin differ
index 7f21270f24cb5f2395893b3e75949053f6dac87c..b59255eabed35cfb91819f1a7e31ef2cfbbe519a 100644 (file)
Binary files a/pcep/impl/src/test/resources/PCEPSvecObject2.bin and b/pcep/impl/src/test/resources/PCEPSvecObject2.bin differ
diff --git a/pcep/impl/src/test/resources/PCEStatefulCapabilityTlv1.bin b/pcep/impl/src/test/resources/PCEStatefulCapabilityTlv1.bin
deleted file mode 100644 (file)
index 34bcb8e..0000000
Binary files a/pcep/impl/src/test/resources/PCEStatefulCapabilityTlv1.bin and /dev/null differ
diff --git a/pcep/impl/src/test/resources/PCEStatefulCapabilityTlv2.bin b/pcep/impl/src/test/resources/PCEStatefulCapabilityTlv2.bin
deleted file mode 100644 (file)
index c23ed7a..0000000
Binary files a/pcep/impl/src/test/resources/PCEStatefulCapabilityTlv2.bin and /dev/null differ
diff --git a/pcep/impl/src/test/resources/PCEStatefulCapabilityTlvInvalid1.bin b/pcep/impl/src/test/resources/PCEStatefulCapabilityTlvInvalid1.bin
deleted file mode 100644 (file)
index ba8e160..0000000
Binary files a/pcep/impl/src/test/resources/PCEStatefulCapabilityTlvInvalid1.bin and /dev/null differ
diff --git a/pcep/impl/src/test/resources/PackOfSubobjects.bin b/pcep/impl/src/test/resources/PackOfSubobjects.bin
deleted file mode 100644 (file)
index 22e5562..0000000
Binary files a/pcep/impl/src/test/resources/PackOfSubobjects.bin and /dev/null differ
diff --git a/pcep/impl/src/test/resources/PackOfTlvs.bin b/pcep/impl/src/test/resources/PackOfTlvs.bin
deleted file mode 100644 (file)
index 98e8383..0000000
Binary files a/pcep/impl/src/test/resources/PackOfTlvs.bin and /dev/null differ
diff --git a/pcep/impl/src/test/resources/PackOfXROSubobjects.bin b/pcep/impl/src/test/resources/PackOfXROSubobjects.bin
deleted file mode 100644 (file)
index 8e555d0..0000000
Binary files a/pcep/impl/src/test/resources/PackOfXROSubobjects.bin and /dev/null differ