Add SPI registry implementations 32/1732/3
authorRobert Varga <rovarga@cisco.com>
Mon, 7 Oct 2013 18:13:48 +0000 (20:13 +0200)
committerRobert Varga <rovarga@cisco.com>
Mon, 7 Oct 2013 21:16:47 +0000 (23:16 +0200)
Change-Id: I7d7aca44a38d6ad3a1ce778f34c1c7d0f59ffbe9
Signed-off-by: Robert Varga <rovarga@cisco.com>
21 files changed:
bgp/parser-impl/pom.xml
bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/AbstractRegistryImpl.java [new file with mode: 0644]
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/MessageRegistryImpl.java [new file with mode: 0644]
bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/BGPKeepAliveMessageParser.java [new file with mode: 0644]
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/BGPUpdateMessageParser.java
bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/open/CapabilityRegistryImpl.java [new file with mode: 0644]
bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/open/ParameterRegistryImpl.java [new file with mode: 0644]
bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/AttributeRegistryImpl.java [new file with mode: 0644]
bgp/parser-impl/src/test/java/org/opendaylight/protocol/bgp/parser/impl/BGPParserTest.java
bgp/parser-impl/src/test/java/org/opendaylight/protocol/bgp/parser/impl/ComplementaryTest.java
bgp/parser-spi/src/main/java/org/opendaylight/protocol/bgp/parser/spi/AttributeRegistry.java
bgp/parser-spi/src/main/java/org/opendaylight/protocol/bgp/parser/spi/CapabilityRegistry.java
bgp/parser-spi/src/main/java/org/opendaylight/protocol/bgp/parser/spi/MessageParser.java
bgp/parser-spi/src/main/java/org/opendaylight/protocol/bgp/parser/spi/MessageSerializer.java
bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/ParserTest.java
bgp/rib-mock/src/main/java/org/opendaylight/protocol/bgp/rib/mock/BGPMock.java
bgp/testtool/src/main/java/org/opendaylight/protocol/bgp/testtool/Main.java
bgp/testtool/src/test/java/org/opendaylight/protocol/bgp/testtool/BGPSpeakerMock.java

index 17895e43a209971ba6a2f0e6fee30387c42aa0b7..894aea03d6c99bf8d84c418028f7218f6bf8ab02 100644 (file)
                <dependency>
                        <groupId>${project.groupId}</groupId>
                        <artifactId>bgp-parser-api</artifactId>
+            <version>${project.version}</version>
+               </dependency>
+               <dependency>
+                       <groupId>${project.groupId}</groupId>
+                       <artifactId>bgp-parser-spi</artifactId>
             <version>${project.version}</version>
                </dependency>
                <dependency>
diff --git a/bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/AbstractRegistryImpl.java b/bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/AbstractRegistryImpl.java
new file mode 100644 (file)
index 0000000..73a3510
--- /dev/null
@@ -0,0 +1,71 @@
+/*
+ * 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.bgp.parser.impl;
+
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+import javax.annotation.concurrent.ThreadSafe;
+
+import org.opendaylight.protocol.concepts.AbstractRegistration;
+
+import com.google.common.base.Preconditions;
+
+@ThreadSafe
+public abstract class AbstractRegistryImpl<CLASS, PARSER, SERIALIZER> {
+       private final Map<Class<? extends CLASS>, SERIALIZER> serializers = new ConcurrentHashMap<>();
+       private final Map<Integer, PARSER> parsers = new ConcurrentHashMap<>();
+
+       protected AutoCloseable registerParser(final Integer type, final PARSER parser) {
+               synchronized (parsers) {
+                       Preconditions.checkArgument(!parsers.containsKey(type), "Type %s already registered", type);
+                       parsers.put(type, parser);
+
+                       return new AbstractRegistration() {
+                               @Override
+                               protected void removeRegistration() {
+                                       synchronized (parsers) {
+                                               parsers.remove(type);
+                                       }
+                               }
+                       };
+               }
+       }
+
+       protected PARSER getParser(final int messageType) {
+               return parsers.get(messageType);
+       }
+
+       protected AutoCloseable registerSerializer(final Class<? extends CLASS> clazz, final SERIALIZER serializer) {
+               synchronized (serializers) {
+                       Preconditions.checkArgument(!serializers.containsKey(clazz), "Message class %s already registered", clazz);
+                       serializers.put(clazz, serializer);
+
+                       return new AbstractRegistration() {
+                               @Override
+                               protected void removeRegistration() {
+                                       synchronized (serializers) {
+                                               serializers.remove(clazz);
+                                       }
+                               }
+                       };
+               }
+       }
+
+       protected SERIALIZER getSerializer(final CLASS obj) {
+               final Class<?> c = obj.getClass();
+
+               for (Map.Entry<Class<? extends CLASS>, SERIALIZER> e : serializers.entrySet()) {
+                       if (e.getKey().isAssignableFrom(c)) {
+                               return e.getValue();
+                       }
+               }
+
+               return null;
+       }
+}
index 3f34f61df7be8c8f58f451eea720b42bc863b6e3..d59a1db4da9a0374eb8982116cd36c613ead8949 100644 (file)
@@ -13,20 +13,17 @@ import java.util.List;
 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.impl.message.BGPNotificationMessageParser;
-import org.opendaylight.protocol.bgp.parser.impl.message.BGPOpenMessageParser;
-import org.opendaylight.protocol.bgp.parser.impl.message.BGPUpdateMessageParser;
+import org.opendaylight.protocol.bgp.parser.spi.MessageParser;
+import org.opendaylight.protocol.bgp.parser.spi.MessageRegistry;
+import org.opendaylight.protocol.bgp.parser.spi.MessageSerializer;
 import org.opendaylight.protocol.framework.DeserializerException;
 import org.opendaylight.protocol.framework.DocumentedException;
 import org.opendaylight.protocol.util.ByteArray;
-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.Open;
 import org.opendaylight.yangtools.yang.binding.Notification;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import com.google.common.base.Preconditions;
 import com.google.common.collect.Lists;
 import com.google.common.primitives.UnsignedBytes;
 
@@ -34,10 +31,11 @@ import com.google.common.primitives.UnsignedBytes;
  * The byte array
  */
 public final class BGPMessageFactoryImpl implements BGPMessageFactory {
+       public static final BGPMessageFactory INSTANCE = new BGPMessageFactoryImpl(MessageRegistryImpl.INSTANCE);
 
        private final static Logger logger = LoggerFactory.getLogger(BGPMessageFactoryImpl.class);
 
-       final static int LENGTH_FIELD_LENGTH = 2; // bytes
+       public final static int LENGTH_FIELD_LENGTH = 2; // bytes
 
        private final static int TYPE_FIELD_LENGTH = 1; // bytes
 
@@ -45,6 +43,12 @@ public final class BGPMessageFactoryImpl implements BGPMessageFactory {
 
        public final static int COMMON_HEADER_LENGTH = LENGTH_FIELD_LENGTH + TYPE_FIELD_LENGTH + MARKER_LENGTH;
 
+       private final MessageRegistry registry;
+
+       private BGPMessageFactoryImpl(final MessageRegistry registry) {
+               this.registry = Preconditions.checkNotNull(registry);
+       }
+
        /*
         * (non-Javadoc)
         * @see org.opendaylight.protocol.bgp.parser.BGPMessageParser#parse(byte[])
@@ -82,32 +86,13 @@ public final class BGPMessageFactoryImpl implements BGPMessageFactory {
 
                logger.debug("Attempt to parse message from bytes: {}", ByteArray.bytesToHexString(msgBody));
 
-               final Notification msg;
-
-               switch (messageType) {
-               case 1:
-                       msg = BGPOpenMessageParser.parse(msgBody);
-                       logger.debug("Received and parsed Open Message: {}", msg);
-                       break;
-               case 2:
-                       msg = BGPUpdateMessageParser.parse(msgBody, messageLength);
-                       logger.debug("Received and parsed Update Message: {}", msg);
-                       break;
-               case 3:
-                       msg = BGPNotificationMessageParser.parse(msgBody);
-                       logger.debug("Received and parsed Notification Message: {}", msg);
-                       break;
-               case 4:
-                       msg = new KeepaliveBuilder().build();
-                       if (messageLength != COMMON_HEADER_LENGTH) {
-                               throw new BGPDocumentedException("Message length field not within valid range.", BGPError.BAD_MSG_LENGTH, ByteArray.subByte(
-                                               bs, 0, LENGTH_FIELD_LENGTH));
-                       }
-                       break;
-               default:
+               final MessageParser parser = registry.getMessageParser(messageType);
+               if (parser == null) {
                        throw new BGPDocumentedException("Unhandled message type " + messageType, BGPError.BAD_MSG_TYPE, new byte[] { bs[LENGTH_FIELD_LENGTH] });
                }
 
+               final Notification msg = parser.parseMessage(msgBody, messageLength);
+
                return Lists.newArrayList(msg);
        }
 
@@ -119,26 +104,13 @@ public final class BGPMessageFactoryImpl implements BGPMessageFactory {
 
                logger.trace("Serializing {}", msg);
 
-               byte[] msgBody = null;
-               int msgType = 0;
-
-               /*
-                * Update message is not supported
-                */
-               if (msg instanceof Open) {
-                       msgType = 1;
-                       msgBody = BGPOpenMessageParser.put((Open) msg);
-               } else if (msg instanceof Notify) {
-                       msgType = 3;
-                       msgBody = BGPNotificationMessageParser.put((Notify) msg);
-               } else if (msg instanceof Keepalive) {
-                       msgType = 4;
-                       msgBody = new byte[0];
-               } else {
+               final MessageSerializer serializer = registry.getMessageSerializer(msg);
+               if (serializer == null) {
                        throw new IllegalArgumentException("Unknown instance of BGPMessage. Passed " + msg.getClass());
                }
 
-               final byte[] headerBytes = headerToBytes(msgBody.length + COMMON_HEADER_LENGTH, msgType);
+               final byte[] msgBody = serializer.serializeMessage(msg);
+               final byte[] headerBytes = headerToBytes(msgBody.length + COMMON_HEADER_LENGTH, serializer.messageType());
                final byte[] retBytes = new byte[headerBytes.length + msgBody.length];
 
                ByteArray.copyWhole(headerBytes, retBytes, 0);
diff --git a/bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/MessageRegistryImpl.java b/bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/MessageRegistryImpl.java
new file mode 100644 (file)
index 0000000..04ee5a2
--- /dev/null
@@ -0,0 +1,63 @@
+/*
+ * 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.bgp.parser.impl;
+
+import org.opendaylight.protocol.bgp.parser.impl.message.BGPKeepAliveMessageParser;
+import org.opendaylight.protocol.bgp.parser.impl.message.BGPNotificationMessageParser;
+import org.opendaylight.protocol.bgp.parser.impl.message.BGPOpenMessageParser;
+import org.opendaylight.protocol.bgp.parser.impl.message.BGPUpdateMessageParser;
+import org.opendaylight.protocol.bgp.parser.spi.MessageParser;
+import org.opendaylight.protocol.bgp.parser.spi.MessageRegistry;
+import org.opendaylight.protocol.bgp.parser.spi.MessageSerializer;
+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.Notify;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.Open;
+import org.opendaylight.yangtools.yang.binding.Notification;
+
+import com.google.common.base.Preconditions;
+
+public final class MessageRegistryImpl extends AbstractRegistryImpl<Notification, MessageParser, MessageSerializer>
+implements MessageRegistry {
+       public static final MessageRegistry INSTANCE;
+
+       static {
+               final MessageRegistry reg = new MessageRegistryImpl();
+
+               reg.registerMessageParser(1, BGPOpenMessageParser.PARSER);
+               reg.registerMessageSerializer(Open.class, BGPOpenMessageParser.SERIALIZER);
+               reg.registerMessageParser(2, BGPUpdateMessageParser.PARSER);
+               // Serialization of Update message is not supported
+               reg.registerMessageParser(3, BGPNotificationMessageParser.PARSER);
+               reg.registerMessageSerializer(Notify.class, BGPNotificationMessageParser.SERIALIZER);
+               reg.registerMessageParser(4, BGPKeepAliveMessageParser.PARSER);
+               reg.registerMessageSerializer(Keepalive.class, BGPKeepAliveMessageParser.SERIALIZER);
+
+               INSTANCE = reg;
+       }
+
+       @Override
+       public synchronized AutoCloseable registerMessageParser(final int messageType, final MessageParser parser) {
+               Preconditions.checkArgument(messageType >= 0 && messageType <= 255);
+               return super.registerParser(messageType, parser);
+       }
+
+       @Override
+       public MessageParser getMessageParser(final int messageType) {
+               return super.getParser(messageType);
+       }
+
+       @Override
+       public AutoCloseable registerMessageSerializer(final Class<? extends Notification> msgClass, final MessageSerializer serializer) {
+               return super.registerSerializer(msgClass, serializer);
+       }
+
+       @Override
+       public MessageSerializer getMessageSerializer(final Notification message) {
+               return super.getSerializer(message);
+       }
+}
diff --git a/bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/BGPKeepAliveMessageParser.java b/bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/BGPKeepAliveMessageParser.java
new file mode 100644 (file)
index 0000000..a37f1cc
--- /dev/null
@@ -0,0 +1,54 @@
+package org.opendaylight.protocol.bgp.parser.impl.message;
+
+import org.opendaylight.protocol.bgp.parser.BGPDocumentedException;
+import org.opendaylight.protocol.bgp.parser.BGPError;
+import org.opendaylight.protocol.bgp.parser.impl.BGPMessageFactoryImpl;
+import org.opendaylight.protocol.bgp.parser.spi.MessageParser;
+import org.opendaylight.protocol.bgp.parser.spi.MessageSerializer;
+import org.opendaylight.protocol.util.ByteArray;
+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.yangtools.yang.binding.Notification;
+
+import com.google.common.base.Preconditions;
+
+public class BGPKeepAliveMessageParser implements MessageParser, MessageSerializer {
+       private static final Keepalive msg = new KeepaliveBuilder().build();
+       private static final byte[] bytes = new byte[0];
+
+       public static final MessageParser PARSER;
+       public static final MessageSerializer SERIALIZER;
+
+       static {
+               final BGPKeepAliveMessageParser p = new BGPKeepAliveMessageParser();
+               PARSER = p;
+               SERIALIZER = p;
+       }
+
+       private BGPKeepAliveMessageParser() {
+
+       }
+
+       @Override
+       public Keepalive parseMessage(final byte[] bytes, final int messageLength) throws BGPDocumentedException {
+               if (messageLength != BGPMessageFactoryImpl.COMMON_HEADER_LENGTH) {
+                       throw new BGPDocumentedException("Message length field not within valid range.",
+                                       BGPError.BAD_MSG_LENGTH,  ByteArray.subByte(ByteArray.intToBytes(messageLength),
+                                                       4 - BGPMessageFactoryImpl.LENGTH_FIELD_LENGTH,
+                                                       BGPMessageFactoryImpl.LENGTH_FIELD_LENGTH));
+               }
+
+               return msg;
+       }
+
+       @Override
+       public int messageType() {
+               return 4;
+       }
+
+       @Override
+       public byte[] serializeMessage(final Notification message) {
+               Preconditions.checkArgument(message instanceof Keepalive);
+               return bytes;
+       }
+}
index ac72ab21798951b7c1c6223b88d5887b2fc011a8..d4db56ceb9df945de3eae0b2f59916ffa28add44 100644 (file)
@@ -11,9 +11,12 @@ import java.util.Arrays;
 
 import org.opendaylight.protocol.bgp.parser.BGPDocumentedException;
 import org.opendaylight.protocol.bgp.parser.BGPError;
+import org.opendaylight.protocol.bgp.parser.spi.MessageParser;
+import org.opendaylight.protocol.bgp.parser.spi.MessageSerializer;
 import org.opendaylight.protocol.util.ByteArray;
 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.yangtools.yang.binding.Notification;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -22,31 +25,48 @@ import com.google.common.primitives.UnsignedBytes;
 /**
  * Parser for BGPNotification message.
  */
-public final class BGPNotificationMessageParser {
+public final class BGPNotificationMessageParser implements MessageParser, MessageSerializer {
+       public static final MessageParser PARSER;
+       public static final MessageSerializer SERIALIZER;
+
+       static {
+               final BGPNotificationMessageParser p = new BGPNotificationMessageParser();
+               PARSER = p;
+               SERIALIZER = p;
+       }
 
        private static final Logger logger = LoggerFactory.getLogger(BGPNotificationMessageParser.class);
 
        private static final int ERROR_SIZE = 2; // bytes
 
+       private BGPNotificationMessageParser() {
+
+       }
+
        /**
         * Serializes BGP Notification message.
         * 
         * @param msg to be serialized
         * @return BGP Notification message converted to byte array
         */
-       public static byte[] put(final Notify msg) {
-               if (msg == null)
+       @Override
+       public byte[] serializeMessage(final Notification msg) {
+               if (msg == null) {
                        throw new IllegalArgumentException("BGP Notification message cannot be null");
-               logger.trace("Started serializing Notification message: {}", msg);
+               }
+
+               final Notify ntf = (Notify)msg;
+               logger.trace("Started serializing Notification message: {}", ntf);
 
-               final byte[] msgBody = (msg.getData() == null) ? new byte[ERROR_SIZE] : new byte[ERROR_SIZE + msg.getData().length];
+               final byte[] msgBody = (ntf.getData() == null) ? new byte[ERROR_SIZE] : new byte[ERROR_SIZE + ntf.getData().length];
 
-               msgBody[0] = ByteArray.intToBytes(msg.getErrorCode())[Integer.SIZE / Byte.SIZE - 1];
+               msgBody[0] = ByteArray.intToBytes(ntf.getErrorCode())[Integer.SIZE / Byte.SIZE - 1];
 
-               msgBody[1] = ByteArray.intToBytes(msg.getErrorSubcode())[Integer.SIZE / Byte.SIZE - 1];
+               msgBody[1] = ByteArray.intToBytes(ntf.getErrorSubcode())[Integer.SIZE / Byte.SIZE - 1];
 
-               if (msg.getData() != null)
-                       System.arraycopy(msg.getData(), 0, msgBody, ERROR_SIZE, msg.getData().length);
+               if (ntf.getData() != null) {
+                       System.arraycopy(ntf.getData(), 0, msgBody, ERROR_SIZE, ntf.getData().length);
+               }
                logger.trace("Notification message serialized to: {}", Arrays.toString(msgBody));
                return msgBody;
        }
@@ -58,13 +78,16 @@ public final class BGPNotificationMessageParser {
         * @return BGPNotification message
         * @throws BGPDocumentedException
         */
-       public static Notify parse(final byte[] bytes) throws BGPDocumentedException {
-               if (bytes == null || bytes.length == 0)
+       @Override
+       public Notify parseMessage(final byte[] bytes, final int messageLength) throws BGPDocumentedException {
+               if (bytes == null || bytes.length == 0) {
                        throw new IllegalArgumentException("Byte array cannot be null or empty.");
+               }
                logger.trace("Started parsing of notification message: {}", Arrays.toString(bytes));
 
-               if (bytes.length < ERROR_SIZE)
+               if (bytes.length < ERROR_SIZE) {
                        throw new BGPDocumentedException("Notification message too small.", BGPError.BAD_MSG_LENGTH, ByteArray.intToBytes(bytes.length));
+               }
                final int errorCode = UnsignedBytes.toInt(bytes[0]);
                final int errorSubcode = UnsignedBytes.toInt(bytes[1]);
 
@@ -75,8 +98,14 @@ public final class BGPNotificationMessageParser {
                logger.trace("Notification message was parsed: err = {}, data = {}.", BGPError.forValue(errorCode, errorSubcode),
                                Arrays.toString(data));
                final NotifyBuilder builder = new NotifyBuilder().setErrorCode((short) errorCode).setErrorSubcode((short) errorSubcode);
-               if (data != null)
+               if (data != null) {
                        builder.setData(data);
+               }
                return builder.build();
        }
+
+       @Override
+       public int messageType() {
+               return 3;
+       }
 }
index fa2c278784d98e4b290e2df3d8bfc23ee163ce30..e7396fd5aa3735e37be0bc902a96aec304000b9b 100644 (file)
@@ -16,6 +16,8 @@ import org.opendaylight.protocol.bgp.parser.BGPDocumentedException;
 import org.opendaylight.protocol.bgp.parser.BGPError;
 import org.opendaylight.protocol.bgp.parser.BGPParsingException;
 import org.opendaylight.protocol.bgp.parser.impl.message.open.BGPParameterParser;
+import org.opendaylight.protocol.bgp.parser.spi.MessageParser;
+import org.opendaylight.protocol.bgp.parser.spi.MessageSerializer;
 import org.opendaylight.protocol.concepts.Ipv4Util;
 import org.opendaylight.protocol.util.ByteArray;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.AsNumber;
@@ -23,6 +25,7 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.
 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.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.open.BgpParameters;
+import org.opendaylight.yangtools.yang.binding.Notification;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -33,7 +36,15 @@ import com.google.common.primitives.UnsignedBytes;
 /**
  * Parser for BGP Open message.
  */
-public final class BGPOpenMessageParser {
+public final class BGPOpenMessageParser implements MessageParser, MessageSerializer {
+       public static final MessageParser PARSER;
+       public static final MessageSerializer SERIALIZER;
+
+       static {
+               final BGPOpenMessageParser p = new BGPOpenMessageParser();
+               PARSER = p;
+               SERIALIZER = p;
+       }
 
        private static final Logger logger = LoggerFactory.getLogger(BGPOpenMessageParser.class);
 
@@ -57,24 +68,27 @@ public final class BGPOpenMessageParser {
         * @param msg BGP Open message to be serialized.
         * @return BGP Open message converted to byte array
         */
-       public static byte[] put(final Open msg) {
-               if (msg == null)
+       @Override
+       public byte[] serializeMessage(final Notification msg) {
+               if (msg == null) {
                        throw new IllegalArgumentException("BGPOpen message cannot be null");
+               }
                logger.trace("Started serializing open message: {}", msg);
+               final Open open = (Open) msg;
 
                final Map<byte[], Integer> optParams = Maps.newHashMap();
 
                int optParamsLength = 0;
 
-               if (msg.getBgpParameters() != null) {
-                       for (final BgpParameters param : msg.getBgpParameters()) {
+               if (open.getBgpParameters() != null) {
+                       for (final BgpParameters param : open.getBgpParameters()) {
                                final byte[] p = BGPParameterParser.put(param);
                                optParams.put(p, p.length);
                                optParamsLength += p.length;
                        }
                }
 
-               final byte[] msgBody = (msg.getBgpParameters() == null || msg.getBgpParameters().isEmpty()) ? new byte[MIN_MSG_LENGTH]
+               final byte[] msgBody = (open.getBgpParameters() == null || open.getBgpParameters().isEmpty()) ? new byte[MIN_MSG_LENGTH]
                                : new byte[MIN_MSG_LENGTH + optParamsLength];
 
                int offset = 0;
@@ -83,17 +97,18 @@ public final class BGPOpenMessageParser {
                offset += VERSION_SIZE;
 
                // When our AS number does not fit into two bytes, we report it as AS_TRANS
-               int openAS = msg.getMyAsNumber();
-               if (openAS > 65535)
+               int openAS = open.getMyAsNumber();
+               if (openAS > 65535) {
                        openAS = 2345;
+               }
 
                System.arraycopy(ByteArray.longToBytes(openAS), 6, msgBody, offset, AS_SIZE);
                offset += AS_SIZE;
 
-               System.arraycopy(ByteArray.intToBytes(msg.getHoldTimer()), 2, msgBody, offset, HOLD_TIME_SIZE);
+               System.arraycopy(ByteArray.intToBytes(open.getHoldTimer()), 2, msgBody, offset, HOLD_TIME_SIZE);
                offset += HOLD_TIME_SIZE;
 
-               System.arraycopy(Ipv4Util.bytesForAddress(msg.getBgpIdentifier()), 0, msgBody, offset, BGP_ID_SIZE);
+               System.arraycopy(Ipv4Util.bytesForAddress(open.getBgpIdentifier()), 0, msgBody, offset, BGP_ID_SIZE);
                offset += BGP_ID_SIZE;
 
                msgBody[offset] = ByteArray.intToBytes(optParamsLength)[Integer.SIZE / Byte.SIZE - 1];
@@ -116,16 +131,20 @@ public final class BGPOpenMessageParser {
         * @return BGP Open Message
         * @throws BGPDocumentedException if the parsing was unsuccessful
         */
-       public static Open parse(final byte[] bytes) throws BGPDocumentedException {
-               if (bytes == null || bytes.length == 0)
+       @Override
+       public Open parseMessage(final byte[] bytes, final int messageLength) throws BGPDocumentedException {
+               if (bytes == null || bytes.length == 0) {
                        throw new IllegalArgumentException("Byte array cannot be null or empty.");
+               }
                logger.trace("Started parsing of open message: {}", Arrays.toString(bytes));
 
-               if (bytes.length < MIN_MSG_LENGTH)
+               if (bytes.length < MIN_MSG_LENGTH) {
                        throw new BGPDocumentedException("Open message too small.", BGPError.BAD_MSG_LENGTH, ByteArray.intToBytes(bytes.length));
-               if (UnsignedBytes.toInt(bytes[0]) != BGP_VERSION)
+               }
+               if (UnsignedBytes.toInt(bytes[0]) != BGP_VERSION) {
                        throw new BGPDocumentedException("BGP Protocol version " + UnsignedBytes.toInt(bytes[0]) + " not supported.", BGPError.VERSION_NOT_SUPPORTED, ByteArray.subByte(
                                        ByteArray.intToBytes(BGP_VERSION), 2, 2));
+               }
 
                int offset = VERSION_SIZE;
                final AsNumber as = new AsNumber(ByteArray.bytesToLong(ByteArray.subByte(bytes, offset, AS_SIZE)));
@@ -135,8 +154,9 @@ public final class BGPOpenMessageParser {
 
                final short holdTime = ByteArray.bytesToShort(ByteArray.subByte(bytes, offset, HOLD_TIME_SIZE));
                offset += HOLD_TIME_SIZE;
-               if (holdTime == 1 || holdTime == 2)
+               if (holdTime == 1 || holdTime == 2) {
                        throw new BGPDocumentedException("Hold time value not acceptable.", BGPError.HOLD_TIME_NOT_ACC);
+               }
 
                Ipv4Address bgpId = null;
                try {
@@ -160,4 +180,9 @@ public final class BGPOpenMessageParser {
                return new OpenBuilder().setMyAsNumber(as.getValue().intValue()).setHoldTimer((int) holdTime).setBgpIdentifier(bgpId).setBgpParameters(
                                optParams).build();
        }
+
+       @Override
+       public int messageType() {
+               return 1;
+       }
 }
index aa3726d06eda055d05688474c1217b146e43ebe0..529295c69fcbb9b4c9f3a874e840ce3f80d29aea 100644 (file)
@@ -16,6 +16,7 @@ import org.opendaylight.protocol.bgp.parser.BGPError;
 import org.opendaylight.protocol.bgp.parser.BGPParsingException;
 import org.opendaylight.protocol.bgp.parser.impl.BGPMessageFactoryImpl;
 import org.opendaylight.protocol.bgp.parser.impl.message.update.PathAttributeParser;
+import org.opendaylight.protocol.bgp.parser.spi.MessageParser;
 import org.opendaylight.protocol.concepts.Ipv4Util;
 import org.opendaylight.protocol.util.ByteArray;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Prefix;
@@ -33,7 +34,8 @@ import org.slf4j.LoggerFactory;
  * @see <a href="http://tools.ietf.org/html/rfc4271#section-4.3">BGP-4 Update Message Format</a>
  * 
  */
-public class BGPUpdateMessageParser {
+public class BGPUpdateMessageParser implements MessageParser {
+       public static final BGPUpdateMessageParser PARSER = new BGPUpdateMessageParser();
 
        private static Logger logger = LoggerFactory.getLogger(BGPUpdateMessageParser.class);
 
@@ -48,14 +50,14 @@ public class BGPUpdateMessageParser {
        public static final int TOTAL_PATH_ATTR_LENGTH_SIZE = 2;
 
        // Constructors -------------------------------------------------------
-
-       public BGPUpdateMessageParser() {
+       private BGPUpdateMessageParser() {
 
        }
 
        // Getters & setters --------------------------------------------------
 
-       public static Update parse(final byte[] bytes, final int msgLength) throws BGPDocumentedException {
+       @Override
+       public Update parseMessage(final byte[] bytes, final int msgLength) throws BGPDocumentedException {
                if (bytes == null || bytes.length == 0) {
                        throw new IllegalArgumentException("Byte array cannot be null or empty.");
                }
diff --git a/bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/open/CapabilityRegistryImpl.java b/bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/open/CapabilityRegistryImpl.java
new file mode 100644 (file)
index 0000000..88e4ae3
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ * 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.bgp.parser.impl.message.open;
+
+import org.opendaylight.protocol.bgp.parser.impl.AbstractRegistryImpl;
+import org.opendaylight.protocol.bgp.parser.spi.CapabilityParser;
+import org.opendaylight.protocol.bgp.parser.spi.CapabilityRegistry;
+import org.opendaylight.protocol.bgp.parser.spi.CapabilitySerializer;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.open.bgp.parameters.CParameters;
+
+import com.google.common.base.Preconditions;
+
+public final class CapabilityRegistryImpl extends AbstractRegistryImpl<CParameters, CapabilityParser, CapabilitySerializer> implements CapabilityRegistry {
+       public static final CapabilityRegistry INSTANCE;
+
+       static {
+               final CapabilityRegistry reg = new CapabilityRegistryImpl();
+
+               // FIXME: fix registry
+
+               INSTANCE = reg;
+       }
+
+       @Override
+       public AutoCloseable registerCapabilityParser(final int messageType, final CapabilityParser parser) {
+               Preconditions.checkArgument(messageType >= 0 && messageType <= 255);
+               return super.registerParser(messageType, parser);
+       }
+
+       @Override
+       public CapabilityParser getCapabilityParser(final int messageType) {
+               return super.getParser(messageType);
+       }
+
+       @Override
+       public AutoCloseable registerCapabilitySerializer(final Class<? extends CParameters> paramClass, final CapabilitySerializer serializer) {
+               return super.registerSerializer(paramClass, serializer);
+       }
+
+       @Override
+       public CapabilitySerializer getCapabilitySerializer(final CParameters capability) {
+               return super.getSerializer(capability);
+       }
+}
diff --git a/bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/open/ParameterRegistryImpl.java b/bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/open/ParameterRegistryImpl.java
new file mode 100644 (file)
index 0000000..3682548
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ * 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.bgp.parser.impl.message.open;
+
+import org.opendaylight.protocol.bgp.parser.impl.AbstractRegistryImpl;
+import org.opendaylight.protocol.bgp.parser.spi.ParameterParser;
+import org.opendaylight.protocol.bgp.parser.spi.ParameterRegistry;
+import org.opendaylight.protocol.bgp.parser.spi.ParameterSerializer;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.open.BgpParameters;
+
+import com.google.common.base.Preconditions;
+
+public final class ParameterRegistryImpl extends AbstractRegistryImpl<BgpParameters, ParameterParser, ParameterSerializer> implements ParameterRegistry {
+       public static final ParameterRegistry INSTANCE;
+
+       static {
+               final ParameterRegistry reg = new ParameterRegistryImpl();
+
+               // FIXME: fix registry
+
+               INSTANCE = reg;
+       }
+
+       @Override
+       public AutoCloseable registerParameterParser(final int messageType, final ParameterParser parser) {
+               Preconditions.checkArgument(messageType >= 0 && messageType <= 255);
+               return super.registerParser(messageType, parser);
+       }
+
+       @Override
+       public ParameterParser getParameterParser(final int messageType) {
+               return super.getParser(messageType);
+       }
+
+       @Override
+       public AutoCloseable registerParameterSerializer(final Class<? extends BgpParameters> paramClass, final ParameterSerializer serializer) {
+               return super.registerSerializer(paramClass, serializer);
+       }
+
+       @Override
+       public ParameterSerializer getParameterSerializer(final BgpParameters message) {
+               return super.getSerializer(message);
+       }
+}
diff --git a/bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/AttributeRegistryImpl.java b/bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/AttributeRegistryImpl.java
new file mode 100644 (file)
index 0000000..7442c73
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+ * 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.bgp.parser.impl.message.update;
+
+import org.opendaylight.protocol.bgp.parser.impl.AbstractRegistryImpl;
+import org.opendaylight.protocol.bgp.parser.spi.AttributeParser;
+import org.opendaylight.protocol.bgp.parser.spi.AttributeRegistry;
+import org.opendaylight.protocol.bgp.parser.spi.AttributeSerializer;
+import org.opendaylight.yangtools.yang.binding.DataObject;
+
+import com.google.common.base.Preconditions;
+
+public final class AttributeRegistryImpl extends AbstractRegistryImpl<DataObject, AttributeParser, AttributeSerializer>
+implements AttributeRegistry {
+       public static final AttributeRegistry INSTANCE;
+
+       static {
+               final AttributeRegistry reg = new AttributeRegistryImpl();
+
+               // FIXME: fix registry
+
+               INSTANCE = reg;
+       }
+
+       @Override
+       public AutoCloseable registerAttributeParser(final int messageType, final AttributeParser parser) {
+               Preconditions.checkArgument(messageType >= 0 && messageType <= 255);
+               return super.registerParser(messageType, parser);
+       }
+
+       @Override
+       public AttributeParser getAttributeParser(final int messageType) {
+               return super.getParser(messageType);
+       }
+
+       @Override
+       public AutoCloseable registerAttributeSerializer(final Class<? extends DataObject> paramClass, final AttributeSerializer serializer) {
+               return super.registerSerializer(paramClass, serializer);
+       }
+
+       @Override
+       public AttributeSerializer getAttributeSerializer(final DataObject attribute) {
+               return super.getSerializer(attribute);
+       }
+}
index b2b5d38e00a2ea752f2cc673c25ae4e751fcc589..aaf500835d048618bbf796c0f445b6b5e1d69d21 100644 (file)
@@ -22,6 +22,7 @@ import java.util.Set;
 import org.junit.BeforeClass;
 import org.junit.Ignore;
 import org.junit.Test;
+import org.opendaylight.protocol.bgp.parser.BGPMessageFactory;
 import org.opendaylight.protocol.bgp.parser.BgpTableTypeImpl;
 import org.opendaylight.protocol.bgp.parser.impl.message.BGPUpdateMessageParser;
 import org.opendaylight.protocol.concepts.IGPMetric;
@@ -83,6 +84,8 @@ public class BGPParserTest {
 
        private static int MAX_SIZE = 300;
 
+       private final BGPUpdateMessageParser updateParser = BGPUpdateMessageParser.PARSER;
+
        @BeforeClass
        public static void setUp() throws Exception {
 
@@ -160,7 +163,7 @@ public class BGPParserTest {
                final byte[] body = ByteArray.cutBytes(inputBytes.get(0), BGPMessageFactoryImpl.COMMON_HEADER_LENGTH);
                final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(0), BGPMessageFactoryImpl.MARKER_LENGTH,
                                BGPMessageFactoryImpl.LENGTH_FIELD_LENGTH));
-               final Update message = BGPUpdateMessageParser.parse(body, messageLength);
+               final Update message = updateParser.parseMessage(body, messageLength);
 
                // check fields
 
@@ -212,24 +215,24 @@ public class BGPParserTest {
                // final Set<IPv4Prefix> nlri = Sets.newHashSet(pref1, pref2, pref3);
                // assertEquals(nlri, ret.getBgpUpdateMessageBuilder().getNlri());
 
-//             final BaseBGPObjectState state = new BaseBGPObjectState(BgpOrigin.Igp, null);
-//             final NetworkRouteState routeState = new NetworkRouteState(new NetworkObjectState(asPath, comms, Collections.<ExtendedCommunity> emptySet()), nextHop);
+               //              final BaseBGPObjectState state = new BaseBGPObjectState(BgpOrigin.Igp, null);
+               //              final NetworkRouteState routeState = new NetworkRouteState(new NetworkObjectState(asPath, comms, Collections.<ExtendedCommunity> emptySet()), nextHop);
 
                // check API message
 
-//             final Set<BGPObject> addedObjects = Sets.newHashSet();
-//
-//             final BGPRoute route1 = new BGPIPv4RouteImpl(IPv4.FAMILY.prefixForString("172.17.2.0/24"), state, routeState);
-//
-//             addedObjects.add(route1);
-//
-//             final BGPRoute route2 = new BGPIPv4RouteImpl(IPv4.FAMILY.prefixForString("172.17.1.0/24"), state, routeState);
-//
-//             addedObjects.add(route2);
-//
-//             final BGPRoute route3 = new BGPIPv4RouteImpl(IPv4.FAMILY.prefixForString("172.17.0.0/24"), state, routeState);
-//
-//             addedObjects.add(route3);
+               //              final Set<BGPObject> addedObjects = Sets.newHashSet();
+               //
+               //              final BGPRoute route1 = new BGPIPv4RouteImpl(IPv4.FAMILY.prefixForString("172.17.2.0/24"), state, routeState);
+               //
+               //              addedObjects.add(route1);
+               //
+               //              final BGPRoute route2 = new BGPIPv4RouteImpl(IPv4.FAMILY.prefixForString("172.17.1.0/24"), state, routeState);
+               //
+               //              addedObjects.add(route2);
+               //
+               //              final BGPRoute route3 = new BGPIPv4RouteImpl(IPv4.FAMILY.prefixForString("172.17.0.0/24"), state, routeState);
+               //
+               //              addedObjects.add(route3);
        }
 
        /*
@@ -286,7 +289,7 @@ public class BGPParserTest {
                final byte[] body = ByteArray.cutBytes(inputBytes.get(1), BGPMessageFactoryImpl.COMMON_HEADER_LENGTH);
                final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(1), BGPMessageFactoryImpl.MARKER_LENGTH,
                                BGPMessageFactoryImpl.LENGTH_FIELD_LENGTH));
-               final Update message = BGPUpdateMessageParser.parse(body, messageLength);
+               final Update message = updateParser.parseMessage(body, messageLength);
                // check fields
 
                assertNull(message.getWithdrawnRoutes());
@@ -325,24 +328,24 @@ public class BGPParserTest {
                // TypeCode.CLUSTER_LIST, true, false, false, false, clusters);
                // assertEquals(clusterAttr, attrs.get(4));
 
-//             final BaseBGPObjectState state = new BaseBGPObjectState(BgpOrigin.Igp, null);
-//             final NetworkRouteState routeState = new NetworkRouteState(new NetworkObjectState(asPath, Collections.<Community> emptySet(), Collections.<ExtendedCommunity> emptySet()), nextHop);
+               //              final BaseBGPObjectState state = new BaseBGPObjectState(BgpOrigin.Igp, null);
+               //              final NetworkRouteState routeState = new NetworkRouteState(new NetworkObjectState(asPath, Collections.<Community> emptySet(), Collections.<ExtendedCommunity> emptySet()), nextHop);
 
                // check API message
 
-//             final Set<BGPObject> addedObjects = Sets.newHashSet();
-//
-//             final BGPRoute route1 = new BGPIPv6RouteImpl(IPv6.FAMILY.prefixForString("2001:db8:1:2::/64"), state, routeState);
-//
-//             addedObjects.add(route1);
-//
-//             final BGPRoute route2 = new BGPIPv6RouteImpl(IPv6.FAMILY.prefixForString("2001:db8:1:1::/64"), state, routeState);
-//
-//             addedObjects.add(route2);
-//
-//             final BGPRoute route3 = new BGPIPv6RouteImpl(IPv6.FAMILY.prefixForString("2001:db8:1::/64"), state, routeState);
-//
-//             addedObjects.add(route3);
+               //              final Set<BGPObject> addedObjects = Sets.newHashSet();
+               //
+               //              final BGPRoute route1 = new BGPIPv6RouteImpl(IPv6.FAMILY.prefixForString("2001:db8:1:2::/64"), state, routeState);
+               //
+               //              addedObjects.add(route1);
+               //
+               //              final BGPRoute route2 = new BGPIPv6RouteImpl(IPv6.FAMILY.prefixForString("2001:db8:1:1::/64"), state, routeState);
+               //
+               //              addedObjects.add(route2);
+               //
+               //              final BGPRoute route3 = new BGPIPv6RouteImpl(IPv6.FAMILY.prefixForString("2001:db8:1::/64"), state, routeState);
+               //
+               //              addedObjects.add(route3);
        }
 
        /*
@@ -391,8 +394,8 @@ public class BGPParserTest {
                final byte[] body = ByteArray.cutBytes(inputBytes.get(2), BGPMessageFactoryImpl.COMMON_HEADER_LENGTH);
                final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(2), BGPMessageFactoryImpl.MARKER_LENGTH,
                                BGPMessageFactoryImpl.LENGTH_FIELD_LENGTH));
-               final Update message = BGPUpdateMessageParser.parse(body, messageLength);
-               
+               final Update message = updateParser.parseMessage(body, messageLength);
+
                // check fields
                assertNull(message.getWithdrawnRoutes());
 
@@ -437,17 +440,17 @@ public class BGPParserTest {
                //
                // final Set<IPv4Prefix> nlri = Sets.newHashSet(pref1);
                // assertEquals(nlri, ret.getBgpUpdateMessageBuilder().getNlri());
-//
-//             final BaseBGPObjectState state = new BaseBGPObjectState(BgpOrigin.Incomplete, aggregator);
-//             final NetworkRouteState routeState = new NetworkRouteState(new NetworkObjectState(asPath, Collections.<Community> emptySet(), Collections.<ExtendedCommunity> emptySet()), nextHop);
+               //
+               //              final BaseBGPObjectState state = new BaseBGPObjectState(BgpOrigin.Incomplete, aggregator);
+               //              final NetworkRouteState routeState = new NetworkRouteState(new NetworkObjectState(asPath, Collections.<Community> emptySet(), Collections.<ExtendedCommunity> emptySet()), nextHop);
 
                // check API message
 
-//             final Set<BGPObject> addedObjects = Sets.newHashSet();
-//
-//             final BGPRoute route1 = new BGPIPv4RouteImpl(pref1, state, routeState);
-//
-//             addedObjects.add(route1);
+               //              final Set<BGPObject> addedObjects = Sets.newHashSet();
+               //
+               //              final BGPRoute route1 = new BGPIPv4RouteImpl(pref1, state, routeState);
+               //
+               //              addedObjects.add(route1);
        }
 
        /*
@@ -496,7 +499,7 @@ public class BGPParserTest {
                final byte[] body = ByteArray.cutBytes(inputBytes.get(3), BGPMessageFactoryImpl.COMMON_HEADER_LENGTH);
                final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(3), BGPMessageFactoryImpl.MARKER_LENGTH,
                                BGPMessageFactoryImpl.LENGTH_FIELD_LENGTH));
-               final Update message = BGPUpdateMessageParser.parse(body, messageLength);
+               final Update message = updateParser.parseMessage(body, messageLength);
 
                // check fields
 
@@ -539,24 +542,24 @@ public class BGPParserTest {
                // final Set<IPv4Prefix> nlri = Sets.newHashSet(pref1, pref2, pref3);
                // assertEquals(nlri, ret.getBgpUpdateMessageBuilder().getNlri());
 
-//             final BaseBGPObjectState state = new BaseBGPObjectState(BgpOrigin.Egp, null);
-//             final NetworkRouteState routeState = new NetworkRouteState(new NetworkObjectState(Collections.<AsPathSegment> emptyList(), Collections.<Community> emptySet(), comms), nextHop);
+               //              final BaseBGPObjectState state = new BaseBGPObjectState(BgpOrigin.Egp, null);
+               //              final NetworkRouteState routeState = new NetworkRouteState(new NetworkObjectState(Collections.<AsPathSegment> emptyList(), Collections.<Community> emptySet(), comms), nextHop);
 
                // check API message
 
-//             final Set<BGPObject> addedObjects = Sets.newHashSet();
-//
-//             final BGPRoute route1 = new BGPIPv4RouteImpl(IPv4.FAMILY.prefixForString("10.30.3.0/24"), state, routeState);
-//
-//             addedObjects.add(route1);
-//
-//             final BGPRoute route2 = new BGPIPv4RouteImpl(IPv4.FAMILY.prefixForString("10.30.2.0/24"), state, routeState);
-//
-//             addedObjects.add(route2);
-//
-//             final BGPRoute route3 = new BGPIPv4RouteImpl(IPv4.FAMILY.prefixForString("10.30.1.0/24"), state, routeState);
-//
-//             addedObjects.add(route3);
+               //              final Set<BGPObject> addedObjects = Sets.newHashSet();
+               //
+               //              final BGPRoute route1 = new BGPIPv4RouteImpl(IPv4.FAMILY.prefixForString("10.30.3.0/24"), state, routeState);
+               //
+               //              addedObjects.add(route1);
+               //
+               //              final BGPRoute route2 = new BGPIPv4RouteImpl(IPv4.FAMILY.prefixForString("10.30.2.0/24"), state, routeState);
+               //
+               //              addedObjects.add(route2);
+               //
+               //              final BGPRoute route3 = new BGPIPv4RouteImpl(IPv4.FAMILY.prefixForString("10.30.1.0/24"), state, routeState);
+               //
+               //              addedObjects.add(route3);
        }
 
        /*
@@ -576,7 +579,7 @@ public class BGPParserTest {
                final byte[] body = ByteArray.cutBytes(inputBytes.get(4), BGPMessageFactoryImpl.COMMON_HEADER_LENGTH);
                final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(4), BGPMessageFactoryImpl.MARKER_LENGTH,
                                BGPMessageFactoryImpl.LENGTH_FIELD_LENGTH));
-               final Update message = BGPUpdateMessageParser.parse(body, messageLength);
+               final Update message = updateParser.parseMessage(body, messageLength);
 
                // attributes
 
@@ -603,7 +606,7 @@ public class BGPParserTest {
                final byte[] body = ByteArray.cutBytes(inputBytes.get(5), BGPMessageFactoryImpl.COMMON_HEADER_LENGTH);
                final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(5), BGPMessageFactoryImpl.MARKER_LENGTH,
                                BGPMessageFactoryImpl.LENGTH_FIELD_LENGTH));
-               final Update message = BGPUpdateMessageParser.parse(body, messageLength);
+               final Update message = updateParser.parseMessage(body, messageLength);
 
                assertEquals(new UpdateBuilder().build(), message);
        }
@@ -629,13 +632,13 @@ public class BGPParserTest {
                final byte[] body = ByteArray.cutBytes(inputBytes.get(6), BGPMessageFactoryImpl.COMMON_HEADER_LENGTH);
                final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(6), BGPMessageFactoryImpl.MARKER_LENGTH,
                                BGPMessageFactoryImpl.LENGTH_FIELD_LENGTH));
-               final Update message = BGPUpdateMessageParser.parse(body, messageLength);
+               final Update message = updateParser.parseMessage(body, messageLength);
 
                // check fields
-               
+
                Class<? extends AddressFamily> afi = message.getPathAttributes().getAugmentation(PathAttributes1.class).getMpReachNlri().getAfi();
                SubsequentAddressFamily safi = message.getPathAttributes().getAugmentation(PathAttributes1.class).getMpReachNlri().getSafi().newInstance();
-               
+
                assertEquals(Ipv6AddressFamily.class, afi);
                assertEquals(UnicastSubsequentAddressFamily.INSTANCE, safi);
        }
@@ -661,11 +664,11 @@ public class BGPParserTest {
                final byte[] body = ByteArray.cutBytes(inputBytes.get(7), BGPMessageFactoryImpl.COMMON_HEADER_LENGTH);
                final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(7), BGPMessageFactoryImpl.MARKER_LENGTH,
                                BGPMessageFactoryImpl.LENGTH_FIELD_LENGTH));
-               final Update message = BGPUpdateMessageParser.parse(body, messageLength);
+               final Update message = updateParser.parseMessage(body, messageLength);
 
                Class<? extends AddressFamily> afi = message.getPathAttributes().getAugmentation(PathAttributes1.class).getMpReachNlri().getAfi();
                SubsequentAddressFamily safi = message.getPathAttributes().getAugmentation(PathAttributes1.class).getMpReachNlri().getSafi().newInstance();
-               
+
                assertEquals(LinkstateAddressFamily.class, afi);
                assertEquals(LinkstateSubsequentAddressFamily.INSTANCE, safi);
        }
@@ -826,44 +829,44 @@ public class BGPParserTest {
                final byte[] body = ByteArray.cutBytes(inputBytes.get(8), BGPMessageFactoryImpl.COMMON_HEADER_LENGTH);
                final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(8), BGPMessageFactoryImpl.MARKER_LENGTH,
                                BGPMessageFactoryImpl.LENGTH_FIELD_LENGTH));
-               final Update message = BGPUpdateMessageParser.parse(body, messageLength);
+               final Update message = updateParser.parseMessage(body, messageLength);
 
                // check fields
 
                assertNull(message.getWithdrawnRoutes());
 
                // network object state
-//             final NetworkObjectState objState = new NetworkObjectState(Collections.<AsPathSegment> emptyList(), Collections.<Community> emptySet(), Collections.<ExtendedCommunity> emptySet());
-//             final BaseBGPObjectState state = new BaseBGPObjectState(BgpOrigin.Igp, null);
+               //              final NetworkObjectState objState = new NetworkObjectState(Collections.<AsPathSegment> emptyList(), Collections.<Community> emptySet(), Collections.<ExtendedCommunity> emptySet());
+               //              final BaseBGPObjectState state = new BaseBGPObjectState(BgpOrigin.Igp, null);
 
                // network link state
                final DefaultingTypesafeContainer<Metric<?>> container = new DefaultingTypesafeContainer<Metric<?>>();
                container.setDefaultEntry(new IGPMetric(1));
                //final NetworkLinkState linkState = new NetworkLinkState(objState, container, null, LinkProtectionType.UNPROTECTED, null, null, null);
 
-//             final NodeIdentifierFactory f100 = new NodeIdentifierFactory(new AsNumber((long) 100), new DomainIdentifier(new byte[] { 25, 25,
-//                             25, 1 }), new AreaIdentifier(new byte[] { 0, 0, 0, 0 }));
-//
-//             final NodeIdentifier nodeid1 = f100.identifierForRouter(new OSPFv3LANIdentifier(new OSPFRouterIdentifier(new byte[] { 3, 3, 3, 4 }), new OSPFInterfaceIdentifier(new byte[] {
-//                             0x0b, 0x0b, 0x0b, 0x03 })));
-//             final NodeIdentifier nodeid2 = f100.identifierForRouter(new OSPFRouterIdentifier(new byte[] { 3, 3, 3, 4 }));
-//
-//             final NodeIdentifier nodeid3 = f100.identifierForRouter(new OSPFRouterIdentifier(new byte[] { 1, 1, 1, 2 }));
+               //              final NodeIdentifierFactory f100 = new NodeIdentifierFactory(new AsNumber((long) 100), new DomainIdentifier(new byte[] { 25, 25,
+               //                              25, 1 }), new AreaIdentifier(new byte[] { 0, 0, 0, 0 }));
+               //
+               //              final NodeIdentifier nodeid1 = f100.identifierForRouter(new OSPFv3LANIdentifier(new OSPFRouterIdentifier(new byte[] { 3, 3, 3, 4 }), new OSPFInterfaceIdentifier(new byte[] {
+               //                              0x0b, 0x0b, 0x0b, 0x03 })));
+               //              final NodeIdentifier nodeid2 = f100.identifierForRouter(new OSPFRouterIdentifier(new byte[] { 3, 3, 3, 4 }));
+               //
+               //              final NodeIdentifier nodeid3 = f100.identifierForRouter(new OSPFRouterIdentifier(new byte[] { 1, 1, 1, 2 }));
 
                // check API message
 
-//             final LinkIdentifier linkId1 = new LinkIdentifier(null, new LinkAnchor(nodeid1, new IPv4InterfaceIdentifier(IPv4.FAMILY.addressForString("11.11.11.3"))), new LinkAnchor(nodeid2, null));
-//             final LinkIdentifier linkId2 = new LinkIdentifier(null, new LinkAnchor(nodeid1, new IPv4InterfaceIdentifier(IPv4.FAMILY.addressForString("11.11.11.1"))), new LinkAnchor(nodeid3, null));
-//             final LinkIdentifier linkId3 = new LinkIdentifier(null, new LinkAnchor(nodeid3, new IPv4InterfaceIdentifier(IPv4.FAMILY.addressForString("11.11.11.1"))), new LinkAnchor(nodeid1, null));
-//
-//             final BGPLink link1 = new BGPLinkImpl(state, linkId1, linkState);
-//             final BGPLink link2 = new BGPLinkImpl(state, linkId2, linkState);
-//             final BGPLink link3 = new BGPLinkImpl(state, linkId3, linkState);
-//
-//             final BGPUpdateMessage expectedMessage = new BGPUpdateMessageImpl(Sets.newHashSet((BGPObject) link1, (BGPObject) link2,
-//                             (BGPObject) link3), Collections.<Identifier> emptySet());
-//
-//             assertEquals(expectedMessage, message);
+               //              final LinkIdentifier linkId1 = new LinkIdentifier(null, new LinkAnchor(nodeid1, new IPv4InterfaceIdentifier(IPv4.FAMILY.addressForString("11.11.11.3"))), new LinkAnchor(nodeid2, null));
+               //              final LinkIdentifier linkId2 = new LinkIdentifier(null, new LinkAnchor(nodeid1, new IPv4InterfaceIdentifier(IPv4.FAMILY.addressForString("11.11.11.1"))), new LinkAnchor(nodeid3, null));
+               //              final LinkIdentifier linkId3 = new LinkIdentifier(null, new LinkAnchor(nodeid3, new IPv4InterfaceIdentifier(IPv4.FAMILY.addressForString("11.11.11.1"))), new LinkAnchor(nodeid1, null));
+               //
+               //              final BGPLink link1 = new BGPLinkImpl(state, linkId1, linkState);
+               //              final BGPLink link2 = new BGPLinkImpl(state, linkId2, linkState);
+               //              final BGPLink link3 = new BGPLinkImpl(state, linkId3, linkState);
+               //
+               //              final BGPUpdateMessage expectedMessage = new BGPUpdateMessageImpl(Sets.newHashSet((BGPObject) link1, (BGPObject) link2,
+               //                              (BGPObject) link3), Collections.<Identifier> emptySet());
+               //
+               //              assertEquals(expectedMessage, message);
        }
 
        /*
@@ -957,38 +960,38 @@ public class BGPParserTest {
                final byte[] body = ByteArray.cutBytes(inputBytes.get(9), BGPMessageFactoryImpl.COMMON_HEADER_LENGTH);
                final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(9), BGPMessageFactoryImpl.MARKER_LENGTH,
                                BGPMessageFactoryImpl.LENGTH_FIELD_LENGTH));
-               final Update message = BGPUpdateMessageParser.parse(body, messageLength);
+               final Update message = updateParser.parseMessage(body, messageLength);
 
                // check fields
 
                assertNull(message.getWithdrawnRoutes());
 
                // network object state
-//             final NetworkObjectState objState = new NetworkObjectState(Collections.<AsPathSegment> emptyList(), Collections.<Community> emptySet(), Collections.<ExtendedCommunity> emptySet());
-//             final BaseBGPObjectState state = new BaseBGPObjectState(BgpOrigin.Igp, null);
-//             final NetworkNodeState nstate = new NetworkNodeState(objState, Collections.<TopologyIdentifier> emptySet(), Collections.<ISISAreaIdentifier> emptySet(), false, false, false, false, Collections.<RouterIdentifier> emptySet(), null);
+               //              final NetworkObjectState objState = new NetworkObjectState(Collections.<AsPathSegment> emptyList(), Collections.<Community> emptySet(), Collections.<ExtendedCommunity> emptySet());
+               //              final BaseBGPObjectState state = new BaseBGPObjectState(BgpOrigin.Igp, null);
+               //              final NetworkNodeState nstate = new NetworkNodeState(objState, Collections.<TopologyIdentifier> emptySet(), Collections.<ISISAreaIdentifier> emptySet(), false, false, false, false, Collections.<RouterIdentifier> emptySet(), null);
 
                // network link state
 
-//             final NodeIdentifierFactory f100 = new NodeIdentifierFactory(new AsNumber((long) 100), new DomainIdentifier(new byte[] { 25, 25,
-//                             25, 1 }), new AreaIdentifier(new byte[] { 0, 0, 0, 0 }));
-//
-//             final NodeIdentifier nodeid1 = f100.identifierForRouter(new OSPFv3LANIdentifier(new OSPFRouterIdentifier(new byte[] { 3, 3, 3, 4 }), new OSPFInterfaceIdentifier(new byte[] {
-//                             0x0b, 0x0b, 0x0b, 0x03 })));
-//             final NodeIdentifier nodeid2 = f100.identifierForRouter(new OSPFRouterIdentifier(new byte[] { 3, 3, 3, 4 }));
-//
-//             final NodeIdentifier nodeid3 = f100.identifierForRouter(new OSPFRouterIdentifier(new byte[] { 1, 1, 1, 2 }));
+               //              final NodeIdentifierFactory f100 = new NodeIdentifierFactory(new AsNumber((long) 100), new DomainIdentifier(new byte[] { 25, 25,
+               //                              25, 1 }), new AreaIdentifier(new byte[] { 0, 0, 0, 0 }));
+               //
+               //              final NodeIdentifier nodeid1 = f100.identifierForRouter(new OSPFv3LANIdentifier(new OSPFRouterIdentifier(new byte[] { 3, 3, 3, 4 }), new OSPFInterfaceIdentifier(new byte[] {
+               //                              0x0b, 0x0b, 0x0b, 0x03 })));
+               //              final NodeIdentifier nodeid2 = f100.identifierForRouter(new OSPFRouterIdentifier(new byte[] { 3, 3, 3, 4 }));
+               //
+               //              final NodeIdentifier nodeid3 = f100.identifierForRouter(new OSPFRouterIdentifier(new byte[] { 1, 1, 1, 2 }));
 
                // check API message
 
-//             final BGPNode node1 = new BGPNodeImpl(state, nodeid1, nstate);
-//             final BGPNode node2 = new BGPNodeImpl(state, nodeid2, nstate);
-//             final BGPNode node3 = new BGPNodeImpl(state, nodeid3, nstate);
-//
-//             final BGPUpdateMessage expectedMessage = new BGPUpdateMessageImpl(Sets.newHashSet((BGPObject) node1, (BGPObject) node2,
-//                             (BGPObject) node3), Collections.<Identifier> emptySet());
-//
-//             assertEquals(expectedMessage, message);
+               //              final BGPNode node1 = new BGPNodeImpl(state, nodeid1, nstate);
+               //              final BGPNode node2 = new BGPNodeImpl(state, nodeid2, nstate);
+               //              final BGPNode node3 = new BGPNodeImpl(state, nodeid3, nstate);
+               //
+               //              final BGPUpdateMessage expectedMessage = new BGPUpdateMessageImpl(Sets.newHashSet((BGPObject) node1, (BGPObject) node2,
+               //                              (BGPObject) node3), Collections.<Identifier> emptySet());
+               //
+               //              assertEquals(expectedMessage, message);
        }
 
        /*
@@ -1031,7 +1034,7 @@ public class BGPParserTest {
         */
        @Test
        public void testOpenMessage() throws Exception {
-               final BGPMessageFactoryImpl msgFactory = new BGPMessageFactoryImpl();
+               final BGPMessageFactory msgFactory = BGPMessageFactoryImpl.INSTANCE;
                final Open open = (Open) msgFactory.parse(inputBytes.get(13)).get(0);
                final Set<BgpTableType> types = Sets.newHashSet();
                for (final BgpParameters param : open.getBgpParameters()) {
index 46a668d3a83ab62be28896387290455811d52aec..cb15854aaff2f9c56a2de9ab7f80386b195b8c30 100644 (file)
@@ -18,6 +18,7 @@ import java.util.Map;
 
 import org.junit.Test;
 import org.opendaylight.protocol.bgp.parser.BGPDocumentedException;
+import org.opendaylight.protocol.bgp.parser.BGPMessageFactory;
 import org.opendaylight.protocol.bgp.parser.BgpTableTypeImpl;
 import org.opendaylight.protocol.bgp.parser.impl.message.update.CommunitiesParser;
 import org.opendaylight.protocol.framework.DeserializerException;
@@ -56,7 +57,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.type
 import com.google.common.collect.Maps;
 
 public class ComplementaryTest {
-       
+
        @Test
        public void testBGPParameter() {
 
@@ -218,7 +219,7 @@ public class ComplementaryTest {
 
        @Test
        public void testBGPHeaderParser() throws IOException {
-               final BGPMessageFactoryImpl h = new BGPMessageFactoryImpl();
+               final BGPMessageFactory h = BGPMessageFactoryImpl.INSTANCE;
                try {
                        h.parse(new byte[] { (byte) 0, (byte) 0 });
                        fail("Exception should have occured.");
@@ -247,7 +248,7 @@ public class ComplementaryTest {
 
        @Test
        public void testMessageParser() throws IOException {
-               final BGPMessageFactoryImpl parser = new BGPMessageFactoryImpl();
+               final BGPMessageFactory parser = BGPMessageFactoryImpl.INSTANCE;
                String ex = "";
                try {
                        parser.put(null);
index 37b816c5adea5890efc82af6c91bf8cd512a980e..0e36ba2cd733ed306657a70c7ef94e4094f21824 100644 (file)
@@ -14,5 +14,5 @@ public interface AttributeRegistry {
        public AttributeParser getAttributeParser(int attributeType);
 
        public AutoCloseable registerAttributeSerializer(Class<? extends DataObject> attrClass, AttributeSerializer serializer);
-       public AttributeSerializer getAttributeSerializer(DataObject object);
+       public AttributeSerializer getAttributeSerializer(DataObject attribute);
 }
index 55d70dea9d0cafdb28455db10d4fdf1c2cee6dbc..d3c1a20d4d2b45d3b7ad2e62fb76d69f0cbedef5 100644 (file)
@@ -14,5 +14,5 @@ public interface CapabilityRegistry {
        public CapabilityParser getCapabilityParser(int capabilityType);
 
        public AutoCloseable registerCapabilitySerializer(Class<? extends CParameters> capabilityClass, CapabilitySerializer serializer);
-       public CapabilitySerializer getCapabilitySerializer(CParameters object);
+       public CapabilitySerializer getCapabilitySerializer(CParameters capability);
 }
index 13bbeac8c81aeba52a669686c9ac9dcac6139aec..8f3b40f492054400e763d870b3b4248ef973970b 100644 (file)
@@ -11,5 +11,5 @@ import org.opendaylight.protocol.bgp.parser.BGPDocumentedException;
 import org.opendaylight.yangtools.yang.binding.Notification;
 
 public interface MessageParser {
-       public Notification parseMessage(final byte[] bytes) throws BGPDocumentedException;
+       public Notification parseMessage(final byte[] bytes, final int messageLength) throws BGPDocumentedException;
 }
index 3b5cf0f4e750f5cb3e5bae00d4958d461f579b94..9faff156a975648657076a51fb4564011bd8638d 100644 (file)
@@ -10,5 +10,13 @@ package org.opendaylight.protocol.bgp.parser.spi;
 import org.opendaylight.yangtools.yang.binding.Notification;
 
 public interface MessageSerializer {
+       /**
+        * Deprecated method. Needs to be refactored such that we have an abstract
+        * class which will encode the header, too.
+        * 
+        * @return message type to be encoded in the header.
+        */
+       @Deprecated
+       public int messageType();
        public byte[] serializeMessage(final Notification message);
 }
index 84ae10d562f50cd84b88146ce2315b0e64f2d1ef..9a057f210f29d3e48318f258233084b04bd3e80a 100644 (file)
@@ -54,33 +54,33 @@ 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 };
 
-       final ProtocolMessageFactory<Notification> factory = new BGPMessageFactoryImpl();
+       final ProtocolMessageFactory<Notification> factory = BGPMessageFactoryImpl.INSTANCE;
 
        @Test
        public void testHeaderErrors() throws DeserializerException, DocumentedException {
index 3bf4130f61ce200a33f9657b954514cfbeefd197..418df4c3d86b02c44f8519342ff7ef5e747ea175 100644 (file)
@@ -55,7 +55,7 @@ public final class BGPMock implements BGP, Closeable {
 
        private List<Notification> parsePrevious(final List<byte[]> msgs) {
                final List<Notification> messages = Lists.newArrayList();
-               final ProtocolMessageFactory<Notification> parser = new BGPMessageFactoryImpl();
+               final ProtocolMessageFactory<Notification> parser = BGPMessageFactoryImpl.INSTANCE;
                try {
                        for (final byte[] b : msgs) {
 
index b7f051b80b26c0af9c40d809c3f0226354d635e3..be5f26d2c4d2328baa36f947c177c2028e8ca7a8 100644 (file)
@@ -49,7 +49,7 @@ public class Main {
        BGPDispatcherImpl dispatcher;
 
        public Main() throws IOException {
-               this.dispatcher = new BGPDispatcherImpl(new BGPMessageFactoryImpl());
+               this.dispatcher = new BGPDispatcherImpl(BGPMessageFactoryImpl.INSTANCE);
        }
 
        public static void main(final String[] args) throws NumberFormatException, IOException {
index 71cf358585f31751da78f06b09af3e9061ebee71..0f23d26eb0a2e2f926ebe9eb45d3b63e295f5a23 100644 (file)
@@ -71,7 +71,7 @@ public class BGPSpeakerMock<M, S extends ProtocolSession<M>, L extends SessionLi
 
                final SessionNegotiatorFactory<Notification, BGPSessionImpl, BGPSessionListener> snf = new BGPSessionNegotiatorFactory(new HashedWheelTimer(), prefs);
 
-               final BGPSpeakerMock<Notification, BGPSessionImpl, BGPSessionListener> mock = new BGPSpeakerMock<Notification, BGPSessionImpl, BGPSessionListener>(snf, new BGPHandlerFactory(new BGPMessageFactoryImpl()), new DefaultPromise<BGPSessionImpl>(GlobalEventExecutor.INSTANCE));
+               final BGPSpeakerMock<Notification, BGPSessionImpl, BGPSessionListener> mock = new BGPSpeakerMock<Notification, BGPSessionImpl, BGPSessionListener>(snf, new BGPHandlerFactory(BGPMessageFactoryImpl.INSTANCE), new DefaultPromise<BGPSessionImpl>(GlobalEventExecutor.INSTANCE));
 
                mock.createServer(new InetSocketAddress("127.0.0.2", 12345), f);
        }