BUG-49 : more tests & warnings fixed. 74/2074/1
authorDana Kutenicsova <dkutenic@cisco.com>
Tue, 22 Oct 2013 13:40:13 +0000 (15:40 +0200)
committerDana Kutenicsova <dkutenic@cisco.com>
Tue, 22 Oct 2013 13:40:13 +0000 (15:40 +0200)
Change-Id: I09221ee9b4ad91c4882b38a5917cb42a75f25098
Signed-off-by: Dana Kutenicsova <dkutenic@cisco.com>
13 files changed:
bgp/parser-api/src/test/java/org/opendaylight/protocol/bgp/parser/APITest.java
bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/BGPMessageFactoryImpl.java
bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/BGPKeepAliveMessageParser.java
bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/BGPNotificationMessageParser.java
bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/BGPOpenMessageParser.java
bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/open/As4CapabilityHandler.java
bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/open/MultiProtocolCapabilityHandler.java
bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/AsPathSegmentParser.java
bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/ClusterIdAttributeParser.java
bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/CommunitiesParser.java
bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/OriginatorIdAttributeParser.java
bgp/parser-impl/src/test/java/org/opendaylight/protocol/bgp/parser/impl/ParserTest.java [moved from bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/ParserTest.java with 81% similarity]
util/src/main/java/org/opendaylight/protocol/util/Util.java [new file with mode: 0644]

index 6cd82982b1550d4f36b56991e3d2ea714618761a..db2485088c83a36cb3fdb7823bf32478b54b56bc 100644 (file)
@@ -8,20 +8,11 @@
 package org.opendaylight.protocol.bgp.parser;
 
 import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotSame;
 import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
 
 import org.junit.Test;
+import org.opendaylight.protocol.framework.DeserializerException;
 import org.opendaylight.protocol.framework.DocumentedException;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.Keepalive;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.KeepaliveBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.Notify;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.NotifyBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.Open;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.OpenBuilder;
-import org.opendaylight.yangtools.yang.binding.Notification;
-
 
 public class APITest {
 
@@ -34,32 +25,18 @@ public class APITest {
        }
 
        @Test
-       public void testBGPKeepAliveMessage() {
-               final Notification msg = new KeepaliveBuilder().build();
-               assertTrue(msg instanceof Keepalive);
-       }
-
-       @Test
-       public void testBGPNotificationMessage() {
-               final Notify msg = new NotifyBuilder().setErrorCode(BGPError.AS_PATH_MALFORMED.getCode()).setErrorSubcode(
-                               BGPError.AS_PATH_MALFORMED.getSubcode()).build();
-               assertTrue(msg instanceof Notify);
-               assertEquals(BGPError.AS_PATH_MALFORMED.getCode(), msg.getErrorCode().shortValue());
-               assertEquals(BGPError.AS_PATH_MALFORMED.getSubcode(), msg.getErrorSubcode().shortValue());
-               assertNull(msg.getData());
+       public void testParsingException() {
+               final DeserializerException de = new BGPParsingException("Some message");
+               assertEquals("Some message", de.getMessage());
        }
 
        @Test
-       public void testBGPOpenMessage() {
-               final Notification msg = new OpenBuilder().setMyAsNumber(58).setHoldTimer(5).build();
-               assertNull(((Open) msg).getBgpParameters());
+       public void testBGPError() {
+               assertEquals(BGPError.BAD_MSG_TYPE, BGPError.forValue(1, 3));
        }
 
        @Test
-       public void testToString() {
-               final Notification o = new OpenBuilder().setMyAsNumber(58).setHoldTimer(5).build();
-               final Notification n = new NotifyBuilder().setErrorCode(BGPError.AS_PATH_MALFORMED.getCode()).setErrorSubcode(
-                               BGPError.AS_PATH_MALFORMED.getSubcode()).build();
-               assertNotSame(o.toString(), n.toString());
+       public void testTerminationReason() {
+               assertEquals(BGPError.BAD_PEER_AS.toString(), new BGPTerminationReason(BGPError.BAD_PEER_AS).getErrorMessage());
        }
 }
index a67f014e11b26198e6b16ed5a298bbadc95d4273..15eca5fe03a9e6bcdf877464407d13ef5716851d 100644 (file)
@@ -27,12 +27,12 @@ public final class BGPMessageFactoryImpl implements BGPMessageFactory {
         * @see org.opendaylight.protocol.bgp.parser.BGPMessageParser#parse(byte[])
         */
        @Override
-       public final Notification parse(final byte[] bytes) throws DeserializerException, DocumentedException {
+       public Notification parse(final byte[] bytes) throws DeserializerException, DocumentedException {
                return this.registry.parseMessage(bytes);
        }
 
        @Override
-       public final byte[] put(final Notification msg) {
+       public byte[] put(final Notification msg) {
                return this.registry.serializeMessage(msg);
        }
 }
index efc9adc4da4248e4c4aca07a5b688b313e0c4930..dd3c9fbb3ef670793037888f56a4df370cc386b3 100644 (file)
@@ -13,21 +13,20 @@ import com.google.common.base.Preconditions;
 public class BGPKeepAliveMessageParser implements MessageParser, MessageSerializer {
        public static final int TYPE = 4;
 
-       private static final Keepalive msg = new KeepaliveBuilder().build();
-       private static final byte[] bytes = MessageUtil.formatMessage(TYPE, new byte[0]);
+       private final Keepalive msg = new KeepaliveBuilder().build();
+       private final byte[] bytes = MessageUtil.formatMessage(TYPE, new byte[0]);
 
        @Override
        public Keepalive parseMessageBody(final byte[] body, final int messageLength) throws BGPDocumentedException {
                if (body.length != 0) {
-                       throw  BGPDocumentedException.badMessageLength("Message length field not within valid range.", messageLength);
+                       throw BGPDocumentedException.badMessageLength("Message length field not within valid range.", messageLength);
                }
-
-               return msg;
+               return this.msg;
        }
 
        @Override
        public byte[] serializeMessage(final Notification message) {
                Preconditions.checkArgument(message instanceof Keepalive);
-               return bytes;
+               return this.bytes;
        }
 }
index 123c4e060241a94ebec33dfdf5f63043dd3578b8..54b92d3e9fe2d4f13acb3e65292709ba5ba36d43 100644 (file)
@@ -31,7 +31,7 @@ public final class BGPNotificationMessageParser implements MessageParser, Messag
 
        private static final Logger logger = LoggerFactory.getLogger(BGPNotificationMessageParser.class);
 
-       private static final int ERROR_SIZE = 2; // bytes
+       private static final int ERROR_SIZE = 2;
 
        /**
         * Serializes BGP Notification message.
@@ -45,7 +45,7 @@ public final class BGPNotificationMessageParser implements MessageParser, Messag
                        throw new IllegalArgumentException("BGP Notification message cannot be null");
                }
 
-               final Notify ntf = (Notify)msg;
+               final Notify ntf = (Notify) msg;
                logger.trace("Started serializing Notification message: {}", ntf);
 
                final byte[] msgBody = (ntf.getData() == null) ? new byte[ERROR_SIZE] : new byte[ERROR_SIZE + ntf.getData().length];
index a335b6dcf0aa0aede17bc69fae1db24c1b719265..3eced158a9eb78eed255223cec4701c22d7326a0 100644 (file)
@@ -21,6 +21,7 @@ import org.opendaylight.protocol.bgp.parser.spi.MessageUtil;
 import org.opendaylight.protocol.bgp.parser.spi.ParameterRegistry;
 import org.opendaylight.protocol.concepts.Ipv4Util;
 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.AsNumber;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.Open;
@@ -53,6 +54,8 @@ public final class BGPOpenMessageParser implements MessageParser, MessageSeriali
 
        private static final int BGP_VERSION = 4;
 
+       private static final int AS_TRANS = 2345;
+
        private final ParameterRegistry reg;
 
        public BGPOpenMessageParser(final ParameterRegistry reg) {
@@ -79,7 +82,7 @@ public final class BGPOpenMessageParser implements MessageParser, MessageSeriali
 
                if (open.getBgpParameters() != null) {
                        for (final BgpParameters param : open.getBgpParameters()) {
-                               final byte[] p = reg.serializeParameter(param);
+                               final byte[] p = this.reg.serializeParameter(param);
                                if (p != null) {
                                        optParams.put(p, p.length);
                                        optParamsLength += p.length;
@@ -96,8 +99,8 @@ public final class BGPOpenMessageParser implements MessageParser, MessageSeriali
 
                // When our AS number does not fit into two bytes, we report it as AS_TRANS
                int openAS = open.getMyAsNumber();
-               if (openAS > 65535) {
-                       openAS = 2345;
+               if (openAS > Util.UNSIGNED_SHORT_MAX_VALUE) {
+                       openAS = AS_TRANS;
                }
 
                System.arraycopy(ByteArray.longToBytes(openAS), 6, msgBody, offset, AS_SIZE);
@@ -162,13 +165,13 @@ public final class BGPOpenMessageParser implements MessageParser, MessageSeriali
                try {
                        bgpId = Ipv4Util.addressForBytes(ByteArray.subByte(body, offset, BGP_ID_SIZE));
                } catch (final IllegalArgumentException e) {
-                       throw new BGPDocumentedException("BGP Identifier is not a valid IPv4 Address", BGPError.BAD_BGP_ID);
+                       throw new BGPDocumentedException("BGP Identifier is not a valid IPv4 Address", BGPError.BAD_BGP_ID, e);
                }
                offset += BGP_ID_SIZE;
 
                final int optLength = UnsignedBytes.toInt(body[offset]);
 
-               List<BgpParameters> optParams = Lists.newArrayList();
+               final List<BgpParameters> optParams = Lists.newArrayList();
                if (optLength > 0) {
                        fillParams(ByteArray.subByte(body, MIN_MSG_LENGTH, optLength), optParams);
                }
@@ -197,7 +200,7 @@ public final class BGPOpenMessageParser implements MessageParser, MessageSeriali
 
                        final BgpParameters param;
                        try {
-                               param = reg.parseParameter(paramType, paramBody);
+                               param = this.reg.parseParameter(paramType, paramBody);
                        } catch (final BGPParsingException e) {
                                throw new BGPDocumentedException("Optional parameter not parsed", BGPError.UNSPECIFIC_OPEN_ERROR, e);
                        }
index 9b9d431ccc05a0bc5be771d8b20264943a86df83..f976affd6f74135f1dfe89af4cde528c043deded 100644 (file)
@@ -22,11 +22,12 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.mess
 public final class As4CapabilityHandler implements CapabilityParser, CapabilitySerializer {
        public static final int CODE = 65;
 
+       private static final int AS4_LENGTH = 4;
+
        @Override
        public CParameters parseCapability(final byte[] bytes) throws BGPDocumentedException, BGPParsingException {
                return new CAs4BytesBuilder().setAs4BytesCapability(
                                new As4BytesCapabilityBuilder().setAsNumber(new AsNumber(ByteArray.bytesToLong(bytes))).build()).build();
-
        }
 
        @Override
@@ -35,6 +36,7 @@ public final class As4CapabilityHandler implements CapabilityParser, CapabilityS
        }
 
        private static byte[] putAS4BytesParameterValue(final CAs4Bytes param) {
-               return ByteArray.subByte(ByteArray.longToBytes(param.getAs4BytesCapability().getAsNumber().getValue()), 4, 4);
+               return ByteArray.subByte(ByteArray.longToBytes(param.getAs4BytesCapability().getAsNumber().getValue()), Long.SIZE / Byte.SIZE
+                               - AS4_LENGTH, AS4_LENGTH);
        }
 }
\ No newline at end of file
index 8d218d3afad737f1e26d6ba1bd172113103f60ae..8016ce4b68a85b6e4a81c5af8c2537faf58cc160 100644 (file)
@@ -28,8 +28,8 @@ import com.google.common.primitives.UnsignedBytes;
 public final class MultiProtocolCapabilityHandler implements CapabilityParser, CapabilitySerializer {
        public static final int CODE = 1;
 
-       private static final int AFI_SIZE = 2; // bytes
-       private static final int SAFI_SIZE = 1; // bytes
+       private static final int AFI_SIZE = 2;
+       private static final int SAFI_SIZE = 1;
 
        private final AddressFamilyRegistry afiReg;
        private final SubsequentAddressFamilyRegistry safiReg;
@@ -42,13 +42,13 @@ public final class MultiProtocolCapabilityHandler implements CapabilityParser, C
        @Override
        public CMultiprotocol parseCapability(final byte[] bytes) throws BGPDocumentedException, BGPParsingException {
                final int afiVal = ByteArray.bytesToInt(ByteArray.subByte(bytes, 0, AFI_SIZE));
-               final Class<? extends AddressFamily> afi = afiReg.classForFamily(afiVal);
+               final Class<? extends AddressFamily> afi = this.afiReg.classForFamily(afiVal);
                if (afi == null) {
                        throw new BGPParsingException("Address Family Identifier: '" + afiVal + "' not supported.");
                }
 
                final int safiVal = ByteArray.bytesToInt(ByteArray.subByte(bytes, AFI_SIZE + 1, SAFI_SIZE));
-               final Class<? extends SubsequentAddressFamily> safi = safiReg.classForFamily(safiVal);
+               final Class<? extends SubsequentAddressFamily> safi = this.safiReg.classForFamily(safiVal);
                if (safi == null) {
                        throw new BGPParsingException("Subsequent Address Family Identifier: '" + safiVal + "' not supported.");
                }
@@ -62,18 +62,16 @@ public final class MultiProtocolCapabilityHandler implements CapabilityParser, C
                final CMultiprotocol mp = (CMultiprotocol) capability;
 
                final Class<? extends AddressFamily> afi = mp.getMultiprotocolCapability().getAfi();
-               final Integer afival = afiReg.numberForClass(afi);
+               final Integer afival = this.afiReg.numberForClass(afi);
                Preconditions.checkArgument(afival != null, "Unhandled address family " + afi);
 
                final Class<? extends SubsequentAddressFamily> safi = mp.getMultiprotocolCapability().getSafi();
-               final Integer safival = safiReg.numberForClass(safi);
+               final Integer safival = this.safiReg.numberForClass(safi);
                Preconditions.checkArgument(safival != null, "Unhandled subsequent address family " + safi);
 
-               return CapabilityUtil.formatCapability(CODE, new byte[] {
-                               UnsignedBytes.checkedCast(afival / 256),
-                               UnsignedBytes.checkedCast(afival % 256),
-                               0,
-                               UnsignedBytes.checkedCast(safival)
-               });
+               return CapabilityUtil.formatCapability(
+                               CODE,
+                               new byte[] { UnsignedBytes.checkedCast(afival / 256), UnsignedBytes.checkedCast(afival % 256), 0,
+                                               UnsignedBytes.checkedCast(safival) });
        }
 }
\ No newline at end of file
index bfdc12950fc735d167858c3ab3110645513dbc8f..9bd7009c014b95a8e13f17acd7d04b43fb809683 100644 (file)
@@ -25,11 +25,11 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.type
  */
 public final class AsPathSegmentParser {
 
-       public static final int TYPE_LENGTH = 1; // bytes
+       public static final int TYPE_LENGTH = 1;
 
-       public static final int LENGTH_SIZE = 1; // bytes
+       public static final int LENGTH_SIZE = 1;
 
-       public static final int AS_NUMBER_LENGTH = 4; // bytes
+       public static final int AS_NUMBER_LENGTH = 4;
 
        /**
         * Possible types of AS Path segments.
index 0e568b19d11f471fba382a9b8cce8e0481e625aa..df13f75767f08d44682b2668fc57f41dba33d21a 100644 (file)
@@ -19,13 +19,15 @@ import com.google.common.collect.Lists;
 public final class ClusterIdAttributeParser implements AttributeParser {
        public static final int TYPE = 10;
 
+       private static final int CLUSTER_LENGTH = 4;
+
        @Override
        public void parseAttribute(final byte[] bytes, final PathAttributesBuilder builder) {
                final List<ClusterIdentifier> list = Lists.newArrayList();
                int i = 0;
                while (i < bytes.length) {
-                       list.add(new ClusterIdentifier(ByteArray.subByte(bytes, i, 4)));
-                       i += 4;
+                       list.add(new ClusterIdentifier(ByteArray.subByte(bytes, i, CLUSTER_LENGTH)));
+                       i += CLUSTER_LENGTH;
                }
 
                builder.setClusterId(list);
index 26a97a7ae069e3619d8ead661952a60b59cc923a..5be864ec09395d567df73440124a3c3c810214e5 100644 (file)
@@ -36,15 +36,15 @@ import com.google.common.primitives.UnsignedBytes;
  */
 public final class CommunitiesParser {
 
-       public static final int EXTENDED_COMMUNITY_LENGTH = 8; // bytes
+       public static final int EXTENDED_COMMUNITY_LENGTH = 8;
 
-       public static final int COMMUNITY_LENGTH = 4; // bytes
+       public static final int COMMUNITY_LENGTH = 4;
 
-       private static final int TYPE_LENGTH = 2; // bytes
+       private static final int TYPE_LENGTH = 2;
 
-       private static final int AS_NUMBER_LENGTH = 2; // bytes
+       private static final int AS_NUMBER_LENGTH = 2;
 
-       private static final int AS_LOCAL_ADMIN_LENGTH = 4; // bytes
+       private static final int AS_LOCAL_ADMIN_LENGTH = 4;
 
        private CommunitiesParser() {
 
@@ -103,7 +103,7 @@ public final class CommunitiesParser {
                                                                new AsNumber(ByteArray.bytesToLong(ByteArray.subByte(value, 0, AS_NUMBER_LENGTH)))).setLocalAdministrator(
                                                                ByteArray.subByte(value, AS_NUMBER_LENGTH, AS_LOCAL_ADMIN_LENGTH)).build()).build();
                        }
-               case 40: // 01000000
+               case 40:
                        return new CAsSpecificExtendedCommunityBuilder().setAsSpecificExtendedCommunity(
                                        new AsSpecificExtendedCommunityBuilder().setTransitive(true).setGlobalAdministrator(
                                                        new AsNumber(ByteArray.bytesToLong(ByteArray.subByte(value, 0, AS_NUMBER_LENGTH)))).setLocalAdministrator(
@@ -139,14 +139,14 @@ public final class CommunitiesParser {
                                                                Ipv4Util.addressForBytes(ByteArray.subByte(value, 0, 4))).setLocalAdministrator(
                                                                ByteArray.subByte(value, 4, 2)).build()).build();
                        }
-               case 41: // 01000001
+               case 41:
                        return new CInet4SpecificExtendedCommunityBuilder().setInet4SpecificExtendedCommunity(
                                        new Inet4SpecificExtendedCommunityBuilder().setTransitive(true).setGlobalAdministrator(
                                                        Ipv4Util.addressForBytes(ByteArray.subByte(value, 0, 4))).setLocalAdministrator(ByteArray.subByte(value, 4, 2)).build()).build();
                case 3:
                        return new COpaqueExtendedCommunityBuilder().setOpaqueExtendedCommunity(
                                        new OpaqueExtendedCommunityBuilder().setTransitive(false).setValue(value).build()).build();
-               case 43: // 01000011
+               case 43:
                        return new COpaqueExtendedCommunityBuilder().setOpaqueExtendedCommunity(
                                        new OpaqueExtendedCommunityBuilder().setTransitive(true).setValue(value).build()).build();
                default:
index d031ce6aa44cf8029b5a52015281e45e6d9d73df..8e2191ee7960f4cbc62d1adc393c1533677e9348 100644 (file)
@@ -13,12 +13,14 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.mess
 public final class OriginatorIdAttributeParser implements AttributeParser {
        public static final int TYPE = 9;
 
+       private static final int ORIGINATOR_LENGTH = 4;
+
        @Override
        public void parseAttribute(final byte[] bytes, final PathAttributesBuilder builder) {
-               if (bytes.length != 4) {
-                       throw new IllegalArgumentException("Length of byte array for ORIGINATOR_ID should be 4, but is " + bytes.length);
+               if (bytes.length != ORIGINATOR_LENGTH) {
+                       throw new IllegalArgumentException("Length of byte array for ORIGINATOR_ID should be " + ORIGINATOR_LENGTH + ", but is "
+                                       + bytes.length);
                }
-
                builder.setOriginatorId(bytes);
        }
 }
\ No newline at end of file
similarity index 81%
rename from bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/ParserTest.java
rename to bgp/parser-impl/src/test/java/org/opendaylight/protocol/bgp/parser/impl/ParserTest.java
index 6308f7893557e2e874cd8ed2a1ff477a8d9462b2..0ff66fc6d5a08f75103bca5b21925de22b2f04ef 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.bgp.rib.impl;
+package org.opendaylight.protocol.bgp.parser.impl;
 
 import static org.junit.Assert.assertArrayEquals;
 import static org.junit.Assert.assertEquals;
@@ -24,8 +24,9 @@ import org.junit.BeforeClass;
 import org.junit.Test;
 import org.opendaylight.protocol.bgp.parser.BGPDocumentedException;
 import org.opendaylight.protocol.bgp.parser.BGPError;
+import org.opendaylight.protocol.bgp.parser.BGPMessageFactory;
 import org.opendaylight.protocol.bgp.parser.BgpTableTypeImpl;
-import org.opendaylight.protocol.bgp.parser.spi.MessageRegistry;
+import org.opendaylight.protocol.bgp.parser.impl.BGPMessageFactoryImpl;
 import org.opendaylight.protocol.bgp.parser.spi.pojo.ServiceLoaderBGPExtensionProviderContext;
 import org.opendaylight.protocol.framework.DeserializerException;
 import org.opendaylight.protocol.framework.DocumentedException;
@@ -55,37 +56,37 @@ import com.google.common.collect.Maps;
 public class ParserTest {
 
        public static final byte[] openBMsg = new byte[] { (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
-               (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
-               (byte) 0xff, (byte) 0x00, (byte) 0x1d, (byte) 0x01, (byte) 0x04, (byte) 0x00, (byte) 0x64, (byte) 0x00, (byte) 0xb4,
-               (byte) 0x14, (byte) 0x14, (byte) 0x14, (byte) 0x14, (byte) 0x00 };
+                       (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
+                       (byte) 0xff, (byte) 0x00, (byte) 0x1d, (byte) 0x01, (byte) 0x04, (byte) 0x00, (byte) 0x64, (byte) 0x00, (byte) 0xb4,
+                       (byte) 0x14, (byte) 0x14, (byte) 0x14, (byte) 0x14, (byte) 0x00 };
 
        public static final byte[] keepAliveBMsg = new byte[] { (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
-               (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
-               (byte) 0xff, (byte) 0x00, (byte) 0x13, (byte) 0x04 };
+                       (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
+                       (byte) 0xff, (byte) 0x00, (byte) 0x13, (byte) 0x04 };
 
        public static final byte[] notificationBMsg = new byte[] { (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
-               (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
-               (byte) 0xff, (byte) 0xff, (byte) 0x00, (byte) 0x17, (byte) 0x03, (byte) 0x02, (byte) 0x04, (byte) 0x04, (byte) 0x09 };
+                       (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
+                       (byte) 0xff, (byte) 0xff, (byte) 0x00, (byte) 0x17, (byte) 0x03, (byte) 0x02, (byte) 0x04, (byte) 0x04, (byte) 0x09 };
 
        public static final byte[] openWithCpblt1 = new byte[] { (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
-               (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
-               (byte) 0xff, (byte) 0x00, (byte) 0x2d, (byte) 0x01, (byte) 0x04, (byte) 0x00, (byte) 0x48, (byte) 0x00, (byte) 0xb4,
-               (byte) 0xac, (byte) 0x14, (byte) 0xa0, (byte) 0xaa, (byte) 0x10, (byte) 0x02, (byte) 0x06, (byte) 0x01, (byte) 0x04,
-               (byte) 0x00, (byte) 0x01, (byte) 0x00, (byte) 0x01, (byte) 0x02, (byte) 0x06, (byte) 0x01, (byte) 0x04, (byte) 0x40,
-               (byte) 0x04, (byte) 0x00, (byte) 0x47 };
+                       (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
+                       (byte) 0xff, (byte) 0x00, (byte) 0x2d, (byte) 0x01, (byte) 0x04, (byte) 0x00, (byte) 0x48, (byte) 0x00, (byte) 0xb4,
+                       (byte) 0xac, (byte) 0x14, (byte) 0xa0, (byte) 0xaa, (byte) 0x10, (byte) 0x02, (byte) 0x06, (byte) 0x01, (byte) 0x04,
+                       (byte) 0x00, (byte) 0x01, (byte) 0x00, (byte) 0x01, (byte) 0x02, (byte) 0x06, (byte) 0x01, (byte) 0x04, (byte) 0x40,
+                       (byte) 0x04, (byte) 0x00, (byte) 0x47 };
 
        public static final byte[] openWithCpblt2 = new byte[] { (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
-               (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
-               (byte) 0xff, (byte) 0x00, (byte) 0x2d, (byte) 0x01, (byte) 0x04, (byte) 0x00, (byte) 0x48, (byte) 0x00, (byte) 0xb4,
-               (byte) 0xac, (byte) 0x14, (byte) 0xa0, (byte) 0xaa, (byte) 0x10, (byte) 0x02, (byte) 0x06, (byte) 0x01, (byte) 0x04,
-               (byte) 0x40, (byte) 0x04, (byte) 0x00, (byte) 0x47, (byte) 0x02, (byte) 0x06, (byte) 0x01, (byte) 0x04, (byte) 0x00,
-               (byte) 0x01, (byte) 0x00, (byte) 0x01 };
+                       (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
+                       (byte) 0xff, (byte) 0x00, (byte) 0x2d, (byte) 0x01, (byte) 0x04, (byte) 0x00, (byte) 0x48, (byte) 0x00, (byte) 0xb4,
+                       (byte) 0xac, (byte) 0x14, (byte) 0xa0, (byte) 0xaa, (byte) 0x10, (byte) 0x02, (byte) 0x06, (byte) 0x01, (byte) 0x04,
+                       (byte) 0x40, (byte) 0x04, (byte) 0x00, (byte) 0x47, (byte) 0x02, (byte) 0x06, (byte) 0x01, (byte) 0x04, (byte) 0x00,
+                       (byte) 0x01, (byte) 0x00, (byte) 0x01 };
 
-       static MessageRegistry factory;
+       static BGPMessageFactory factory;
 
        @BeforeClass
        public static void setupClass() throws Exception {
-               factory = ServiceLoaderBGPExtensionProviderContext.createConsumerContext().getMessageRegistry();
+               factory = new BGPMessageFactoryImpl(ServiceLoaderBGPExtensionProviderContext.createConsumerContext().getMessageRegistry());
        }
 
        @Test
@@ -94,7 +95,7 @@ public class ParserTest {
                                (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0x00 };
                wrong = ByteArray.cutBytes(wrong, 16);
                try {
-                       ParserTest.factory.parseMessage(wrong);
+                       ParserTest.factory.parse(wrong);
                        fail("Exception should have occcured.");
                } catch (final IllegalArgumentException e) {
                        assertEquals("Too few bytes in passed array. Passed: " + wrong.length + ". Expected: >= 19.", e.getMessage());
@@ -109,7 +110,7 @@ public class ParserTest {
                                (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
                                (byte) 0x00, (byte) 0x13, (byte) 0x08 };
                try {
-                       ParserTest.factory.parseMessage(bytes);
+                       ParserTest.factory.parse(bytes);
                        fail("Exception should have occured.");
                } catch (final DocumentedException e) {
                        assertEquals(BGPError.BAD_MSG_TYPE, ((BGPDocumentedException) e).getError());
@@ -121,10 +122,10 @@ public class ParserTest {
        @Test
        public void testKeepAliveMsg() throws DeserializerException, DocumentedException {
                final Notification keepAlive = new KeepaliveBuilder().build();
-               final byte[] bytes = ParserTest.factory.serializeMessage(keepAlive);
+               final byte[] bytes = ParserTest.factory.put(keepAlive);
                assertArrayEquals(keepAliveBMsg, bytes);
 
-               final Notification m = ParserTest.factory.parseMessage(bytes);
+               final Notification m = ParserTest.factory.parse(bytes);
 
                assertTrue(m instanceof Keepalive);
        }
@@ -136,7 +137,7 @@ public class ParserTest {
                                (byte) 0x00, (byte) 0x14, (byte) 0x04, (byte) 0x05 };
 
                try {
-                       ParserTest.factory.parseMessage(bytes);
+                       ParserTest.factory.parse(bytes);
                        fail("Exception should have occured.");
                } catch (final DocumentedException e) {
                        assertThat(e.getMessage(), containsString("Message length field not within valid range."));
@@ -150,10 +151,10 @@ public class ParserTest {
        public void testOpenMessage() throws UnknownHostException, DeserializerException, DocumentedException {
                final Notification open = new OpenBuilder().setMyAsNumber(100).setHoldTimer(180).setBgpIdentifier(new Ipv4Address("20.20.20.20")).setVersion(
                                new ProtocolVersion((short) 4)).build();
-               final byte[] bytes = ParserTest.factory.serializeMessage(open);
+               final byte[] bytes = ParserTest.factory.put(open);
                assertArrayEquals(openBMsg, bytes);
 
-               final Notification m = ParserTest.factory.parseMessage(bytes);
+               final Notification m = ParserTest.factory.parse(bytes);
 
                assertTrue(m instanceof Open);
                assertEquals(100, ((Open) m).getMyAsNumber().intValue());
@@ -170,7 +171,7 @@ public class ParserTest {
                                (byte) 0x14, (byte) 0x14, (byte) 0x14, (byte) 0x00 };
 
                try {
-                       ParserTest.factory.parseMessage(bMsg);
+                       ParserTest.factory.parse(bMsg);
                        fail("Exception should have occured.");
                } catch (final DocumentedException e) {
                        assertEquals("Hold time value not acceptable.", e.getMessage());
@@ -188,7 +189,7 @@ public class ParserTest {
                                (byte) 0xff, (byte) 0xff };
 
                try {
-                       ParserTest.factory.parseMessage(bMsg);
+                       ParserTest.factory.parse(bMsg);
                        fail("Exception should have occured.");
                } catch (final DocumentedException e) {
                        assertEquals("Open message too small.", e.getMessage());
@@ -204,7 +205,7 @@ public class ParserTest {
                                (byte) 0x14, (byte) 0x14, (byte) 0x14, (byte) 0x00 };
 
                try {
-                       ParserTest.factory.parseMessage(bMsg);
+                       ParserTest.factory.parse(bMsg);
                        fail("Exception should have occured.");
                } catch (final DocumentedException e) {
                        assertEquals("BGP Protocol version 8 not supported.", e.getMessage());
@@ -218,10 +219,10 @@ public class ParserTest {
        public void testNotificationMsg() throws DeserializerException, DocumentedException {
                Notification notMsg = new NotifyBuilder().setErrorCode(BGPError.OPT_PARAM_NOT_SUPPORTED.getCode()).setErrorSubcode(
                                BGPError.OPT_PARAM_NOT_SUPPORTED.getSubcode()).setData(new byte[] { 4, 9 }).build();
-               byte[] bytes = ParserTest.factory.serializeMessage(notMsg);
+               byte[] bytes = ParserTest.factory.put(notMsg);
                assertArrayEquals(notificationBMsg, bytes);
 
-               Notification m = ParserTest.factory.parseMessage(bytes);
+               Notification m = ParserTest.factory.parse(bytes);
 
                assertTrue(m instanceof Notify);
                assertEquals(BGPError.OPT_PARAM_NOT_SUPPORTED, BGPError.forValue(((Notify) m).getErrorCode(), ((Notify) m).getErrorSubcode()));
@@ -229,9 +230,9 @@ public class ParserTest {
 
                notMsg = new NotifyBuilder().setErrorCode(BGPError.CONNECTION_NOT_SYNC.getCode()).setErrorSubcode(
                                BGPError.CONNECTION_NOT_SYNC.getSubcode()).build();
-               bytes = ParserTest.factory.serializeMessage(notMsg);
+               bytes = ParserTest.factory.put(notMsg);
 
-               m = ParserTest.factory.parseMessage(bytes);
+               m = ParserTest.factory.parse(bytes);
 
                assertTrue(m instanceof Notify);
                assertEquals(BGPError.CONNECTION_NOT_SYNC, BGPError.forValue(((Notify) m).getErrorCode(), ((Notify) m).getErrorSubcode()));
@@ -245,7 +246,7 @@ public class ParserTest {
                                (byte) 0x00, (byte) 0x14, (byte) 0x03, (byte) 0x02 };
 
                try {
-                       ParserTest.factory.parseMessage(bMsg);
+                       ParserTest.factory.parse(bMsg);
                        fail("Exception should have occured.");
                } catch (final DocumentedException e) {
                        assertEquals("Notification message too small.", e.getMessage());
@@ -262,7 +263,7 @@ public class ParserTest {
                                (byte) 0x00, (byte) 0x15, (byte) 0x03, (byte) 0x02, (byte) 0xaa };
 
                try {
-                       ParserTest.factory.parseMessage(bMsg);
+                       ParserTest.factory.parse(bMsg);
                        fail("Exception should have occured.");
                } catch (final IllegalArgumentException e) {
                        assertEquals("BGP Error code 2 and subcode 170 not recognized.", e.getMessage());
@@ -293,7 +294,7 @@ public class ParserTest {
                final Open open = new OpenBuilder().setMyAsNumber(72).setHoldTimer(180).setBgpIdentifier(new Ipv4Address("172.20.160.170")).setVersion(
                                new ProtocolVersion((short) 4)).setBgpParameters(tlvs).build();
 
-               final byte[] result = ParserTest.factory.serializeMessage(open);
+               final byte[] result = ParserTest.factory.put(open);
 
                // the capabilities can be swapped.
                assertTrue(Arrays.equals(openWithCpblt1, result) || Arrays.equals(openWithCpblt2, result));
diff --git a/util/src/main/java/org/opendaylight/protocol/util/Util.java b/util/src/main/java/org/opendaylight/protocol/util/Util.java
new file mode 100644 (file)
index 0000000..b3a002b
--- /dev/null
@@ -0,0 +1,14 @@
+/*
+ * 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.util;
+
+public class Util {
+
+       public static final int UNSIGNED_SHORT_MAX_VALUE = 65535;
+
+}