BGPMessageFactory has been superseded by MessageRegistry 19/3019/1
authorRobert Varga <rovarga@cisco.com>
Fri, 22 Nov 2013 16:59:40 +0000 (17:59 +0100)
committerRobert Varga <rovarga@cisco.com>
Fri, 22 Nov 2013 16:59:40 +0000 (17:59 +0100)
Change-Id: I565797a1c0048f02466ed5362ffc3280b23b57f6
Signed-off-by: Robert Varga <rovarga@cisco.com>
bgp/parser-api/src/main/java/org/opendaylight/protocol/bgp/parser/BGPMessageFactory.java [deleted file]
bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/BGPMessageFactoryImpl.java [deleted file]
bgp/parser-impl/src/test/java/org/opendaylight/protocol/bgp/parser/impl/ParserTest.java
bgp/parser-mock/src/main/java/org/opendaylight/protocol/bgp/parser/mock/BGPMessageParserMock.java
bgp/parser-mock/src/test/java/org/opendaylight/protocol/bgp/parser/mock/BGPMessageParserMockTest.java
bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/BGPImplTest.java
bgp/rib-mock/src/main/java/org/opendaylight/protocol/bgp/rib/mock/BGPMock.java

diff --git a/bgp/parser-api/src/main/java/org/opendaylight/protocol/bgp/parser/BGPMessageFactory.java b/bgp/parser-api/src/main/java/org/opendaylight/protocol/bgp/parser/BGPMessageFactory.java
deleted file mode 100644 (file)
index 7ae7a02..0000000
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.protocol.bgp.parser;
-
-import org.opendaylight.yangtools.yang.binding.Notification;
-
-/**
- * Interface to expose BGP specific MessageFactory.
- */
-public interface BGPMessageFactory {
-       public Notification parse(final byte[] bytes) throws BGPParsingException, BGPDocumentedException;
-
-       /**
-        * Serializes protocol specific message to byte array.
-        * 
-        * @param msg message to be serialized.
-        * @return byte array resulting message
-        */
-       public byte[] put(final Notification msg);
-}
diff --git a/bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/BGPMessageFactoryImpl.java b/bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/BGPMessageFactoryImpl.java
deleted file mode 100644 (file)
index 1b59155..0000000
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.protocol.bgp.parser.impl;
-
-import org.opendaylight.protocol.bgp.parser.BGPDocumentedException;
-import org.opendaylight.protocol.bgp.parser.BGPMessageFactory;
-import org.opendaylight.protocol.bgp.parser.BGPParsingException;
-import org.opendaylight.protocol.bgp.parser.spi.MessageRegistry;
-import org.opendaylight.yangtools.yang.binding.Notification;
-
-import com.google.common.base.Preconditions;
-
-public final class BGPMessageFactoryImpl implements BGPMessageFactory {
-       private final MessageRegistry registry;
-
-       public BGPMessageFactoryImpl(final MessageRegistry registry) {
-               this.registry = Preconditions.checkNotNull(registry);
-       }
-
-       /*
-        * (non-Javadoc)
-        * @see org.opendaylight.protocol.bgp.parser.BGPMessageParser#parse(byte[])
-        */
-       @Override
-       public Notification parse(final byte[] bytes) throws BGPParsingException, BGPDocumentedException {
-               return this.registry.parseMessage(bytes);
-       }
-
-       @Override
-       public byte[] put(final Notification msg) {
-               return this.registry.serializeMessage(msg);
-       }
-}
index f2a379c1717c61955721be81ae8fa4b89d2cc4e3..37a38fd46cfca1156575c3e981a04ba1ad921569 100644 (file)
@@ -24,9 +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.BGPParsingException;
 import org.opendaylight.protocol.bgp.parser.BgpTableTypeImpl;
+import org.opendaylight.protocol.bgp.parser.spi.MessageRegistry;
 import org.opendaylight.protocol.bgp.parser.spi.pojo.ServiceLoaderBGPExtensionProviderContext;
 import org.opendaylight.protocol.util.ByteArray;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
@@ -80,11 +80,11 @@ public class ParserTest {
                (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 BGPMessageFactory factory;
+       static MessageRegistry reg;
 
        @BeforeClass
        public static void setupClass() throws Exception {
-               factory = new BGPMessageFactoryImpl(ServiceLoaderBGPExtensionProviderContext.createConsumerContext().getMessageRegistry());
+               reg = ServiceLoaderBGPExtensionProviderContext.createConsumerContext().getMessageRegistry();
        }
 
        @Test
@@ -93,7 +93,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.parse(wrong);
+                       ParserTest.reg.parseMessage(wrong);
                        fail("Exception should have occcured.");
                } catch (final IllegalArgumentException e) {
                        assertEquals("Too few bytes in passed array. Passed: " + wrong.length + ". Expected: >= 19.", e.getMessage());
@@ -108,7 +108,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.parse(bytes);
+                       ParserTest.reg.parseMessage(bytes);
                        fail("Exception should have occured.");
                } catch (final BGPDocumentedException e) {
                        assertEquals(BGPError.BAD_MSG_TYPE, e.getError());
@@ -120,10 +120,10 @@ public class ParserTest {
        @Test
        public void testKeepAliveMsg() throws BGPParsingException, BGPDocumentedException {
                final Notification keepAlive = new KeepaliveBuilder().build();
-               final byte[] bytes = ParserTest.factory.put(keepAlive);
+               final byte[] bytes = ParserTest.reg.serializeMessage(keepAlive);
                assertArrayEquals(keepAliveBMsg, bytes);
 
-               final Notification m = ParserTest.factory.parse(bytes);
+               final Notification m = ParserTest.reg.parseMessage(bytes);
 
                assertTrue(m instanceof Keepalive);
        }
@@ -135,7 +135,7 @@ public class ParserTest {
                                (byte) 0x00, (byte) 0x14, (byte) 0x04, (byte) 0x05 };
 
                try {
-                       ParserTest.factory.parse(bytes);
+                       ParserTest.reg.parseMessage(bytes);
                        fail("Exception should have occured.");
                } catch (final BGPDocumentedException e) {
                        assertThat(e.getMessage(), containsString("Message length field not within valid range."));
@@ -149,10 +149,10 @@ public class ParserTest {
        public void testOpenMessage() throws UnknownHostException, BGPParsingException, BGPDocumentedException {
                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.put(open);
+               final byte[] bytes = ParserTest.reg.serializeMessage(open);
                assertArrayEquals(openBMsg, bytes);
 
-               final Notification m = ParserTest.factory.parse(bytes);
+               final Notification m = ParserTest.reg.parseMessage(bytes);
 
                assertTrue(m instanceof Open);
                assertEquals(100, ((Open) m).getMyAsNumber().intValue());
@@ -169,7 +169,7 @@ public class ParserTest {
                                (byte) 0x14, (byte) 0x14, (byte) 0x14, (byte) 0x00 };
 
                try {
-                       ParserTest.factory.parse(bMsg);
+                       ParserTest.reg.parseMessage(bMsg);
                        fail("Exception should have occured.");
                } catch (final BGPDocumentedException e) {
                        assertEquals("Hold time value not acceptable.", e.getMessage());
@@ -187,7 +187,7 @@ public class ParserTest {
                                (byte) 0xff, (byte) 0xff };
 
                try {
-                       ParserTest.factory.parse(bMsg);
+                       ParserTest.reg.parseMessage(bMsg);
                        fail("Exception should have occured.");
                } catch (final BGPDocumentedException e) {
                        assertEquals("Open message too small.", e.getMessage());
@@ -203,7 +203,7 @@ public class ParserTest {
                                (byte) 0x14, (byte) 0x14, (byte) 0x14, (byte) 0x00 };
 
                try {
-                       ParserTest.factory.parse(bMsg);
+                       ParserTest.reg.parseMessage(bMsg);
                        fail("Exception should have occured.");
                } catch (final BGPDocumentedException e) {
                        assertEquals("BGP Protocol version 8 not supported.", e.getMessage());
@@ -217,10 +217,10 @@ public class ParserTest {
        public void testNotificationMsg() throws BGPParsingException, BGPDocumentedException {
                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.put(notMsg);
+               byte[] bytes = ParserTest.reg.serializeMessage(notMsg);
                assertArrayEquals(notificationBMsg, bytes);
 
-               Notification m = ParserTest.factory.parse(bytes);
+               Notification m = ParserTest.reg.parseMessage(bytes);
 
                assertTrue(m instanceof Notify);
                assertEquals(BGPError.OPT_PARAM_NOT_SUPPORTED, BGPError.forValue(((Notify) m).getErrorCode(), ((Notify) m).getErrorSubcode()));
@@ -228,9 +228,9 @@ public class ParserTest {
 
                notMsg = new NotifyBuilder().setErrorCode(BGPError.CONNECTION_NOT_SYNC.getCode()).setErrorSubcode(
                                BGPError.CONNECTION_NOT_SYNC.getSubcode()).build();
-               bytes = ParserTest.factory.put(notMsg);
+               bytes = ParserTest.reg.serializeMessage(notMsg);
 
-               m = ParserTest.factory.parse(bytes);
+               m = ParserTest.reg.parseMessage(bytes);
 
                assertTrue(m instanceof Notify);
                assertEquals(BGPError.CONNECTION_NOT_SYNC, BGPError.forValue(((Notify) m).getErrorCode(), ((Notify) m).getErrorSubcode()));
@@ -244,7 +244,7 @@ public class ParserTest {
                                (byte) 0x00, (byte) 0x14, (byte) 0x03, (byte) 0x02 };
 
                try {
-                       ParserTest.factory.parse(bMsg);
+                       ParserTest.reg.parseMessage(bMsg);
                        fail("Exception should have occured.");
                } catch (final BGPDocumentedException e) {
                        assertEquals("Notification message too small.", e.getMessage());
@@ -261,7 +261,7 @@ public class ParserTest {
                                (byte) 0x00, (byte) 0x15, (byte) 0x03, (byte) 0x02, (byte) 0xaa };
 
                try {
-                       ParserTest.factory.parse(bMsg);
+                       ParserTest.reg.parseMessage(bMsg);
                        fail("Exception should have occured.");
                } catch (final IllegalArgumentException e) {
                        assertEquals("BGP Error code 2 and subcode 170 not recognized.", e.getMessage());
@@ -292,7 +292,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.put(open);
+               final byte[] result = ParserTest.reg.serializeMessage(open);
 
                // the capabilities can be swapped.
                assertTrue(Arrays.equals(openWithCpblt1, result) || Arrays.equals(openWithCpblt2, result));
index 0583da09b3e2bac2e86066b5a93bf9f00289a2e0..7957496f134168865155f4967014e975f586b424 100644 (file)
@@ -10,8 +10,8 @@ package org.opendaylight.protocol.bgp.parser.mock;
 import java.util.Map;
 
 import org.opendaylight.protocol.bgp.parser.BGPDocumentedException;
-import org.opendaylight.protocol.bgp.parser.BGPMessageFactory;
 import org.opendaylight.protocol.bgp.parser.BGPParsingException;
+import org.opendaylight.protocol.bgp.parser.spi.MessageRegistry;
 import org.opendaylight.yangtools.yang.binding.Notification;
 
 /**
@@ -19,7 +19,7 @@ import org.opendaylight.yangtools.yang.binding.Notification;
  * each used in one of the methods. It looks up the key provided to the method and returns whatever value is stored in
  * the map.
  */
-public class BGPMessageParserMock implements BGPMessageFactory {
+public class BGPMessageParserMock implements MessageRegistry {
        private final Map<byte[], Notification> messages;
 
        /**
@@ -30,7 +30,7 @@ public class BGPMessageParserMock implements BGPMessageFactory {
        }
 
        @Override
-       public Notification parse(final byte[] bytes) throws BGPParsingException, BGPDocumentedException {
+       public Notification parseMessage(final byte[] bytes) throws BGPParsingException, BGPDocumentedException {
                final Notification ret = this.messages.get(bytes);
                if (ret == null) {
                        throw new IllegalArgumentException("Undefined message encountered");
@@ -39,7 +39,7 @@ public class BGPMessageParserMock implements BGPMessageFactory {
        }
 
        @Override
-       public byte[] put(final Notification msg) {
+       public byte[] serializeMessage(final Notification msg) {
                // nothing
                return null;
        }
index f84a78964fb0ae34e29262c71e7558ea9695cf6e..0a49a1c7cc0c73188ed38ee6f95401a68c2344e1 100644 (file)
@@ -96,9 +96,9 @@ public class BGPMessageParserMockTest {
                final BGPMessageParserMock mockParser = new BGPMessageParserMock(updateMap);
 
                for (int i = 0; i < this.inputBytes.length; i++) {
-                       assertEquals(this.messages.get(i), mockParser.parse(this.inputBytes[i]));
+                       assertEquals(this.messages.get(i), mockParser.parseMessage(this.inputBytes[i]));
                }
-               assertNotSame(this.messages.get(3), mockParser.parse(this.inputBytes[8]));
+               assertNotSame(this.messages.get(3), mockParser.parseMessage(this.inputBytes[8]));
        }
 
        /**
@@ -116,7 +116,7 @@ public class BGPMessageParserMockTest {
                }
 
                final BGPMessageParserMock mockParser = new BGPMessageParserMock(updateMap);
-               mockParser.parse(new byte[] { 7, 4, 6 });
+               mockParser.parseMessage(new byte[] { 7, 4, 6 });
        }
 
        /**
@@ -197,7 +197,7 @@ public class BGPMessageParserMockTest {
                final BGPMessageParserMock mockParser = new BGPMessageParserMock(openMap);
 
                final Set<BgpTableType> result = Sets.newHashSet();
-               for (final BgpParameters p : ((Open) mockParser.parse(input)).getBgpParameters()) {
+               for (final BgpParameters p : ((Open) mockParser.parseMessage(input)).getBgpParameters()) {
                        final CParameters cp = p.getCParameters();
                        final BgpTableType t = new BgpTableTypeImpl(((CMultiprotocol) cp).getMultiprotocolCapability().getAfi(), ((CMultiprotocol) cp).getMultiprotocolCapability().getSafi());
                        result.add(t);
index 22376d8ab3ab3b22b0b06a2e41ac144cc853645b..fdec3ad4b59be8f59ef50ec23b9ccb5d2d4c6aac 100644 (file)
@@ -22,7 +22,6 @@ import org.junit.Before;
 import org.junit.Test;
 import org.mockito.Mock;
 import org.mockito.MockitoAnnotations;
-import org.opendaylight.protocol.bgp.parser.BGPMessageFactory;
 import org.opendaylight.protocol.bgp.parser.BGPSessionListener;
 import org.opendaylight.protocol.bgp.rib.impl.spi.BGPDispatcher;
 import org.opendaylight.protocol.bgp.rib.impl.spi.BGPSessionPreferences;
@@ -41,9 +40,6 @@ public class BGPImplTest {
        @Mock
        private BGPSessionProposal prop;
 
-       @Mock
-       private BGPMessageFactory parser;
-
        @Mock
        private Future<Void> future;
 
@@ -52,8 +48,6 @@ public class BGPImplTest {
        @Before
        public void setUp() throws Exception {
                MockitoAnnotations.initMocks(this);
-               doReturn("").when(this.parser).toString();
-
                doReturn(this.future).when(this.disp).createReconnectingClient(any(InetSocketAddress.class), any(BGPSessionPreferences.class),
                                any(BGPSessionListener.class), any(ReconnectStrategyFactory.class), any(ReconnectStrategy.class));
        }
index 77886fd94c719c8fee6d0a3c6218a843e31cef10..e90838ee4a3fa590f1e51a695bf1b8293e247ee6 100644 (file)
@@ -17,10 +17,8 @@ import javax.annotation.concurrent.ThreadSafe;
 
 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.BGPParsingException;
 import org.opendaylight.protocol.bgp.parser.BGPSessionListener;
-import org.opendaylight.protocol.bgp.parser.impl.BGPMessageFactoryImpl;
 import org.opendaylight.protocol.bgp.parser.spi.MessageRegistry;
 import org.opendaylight.protocol.bgp.rib.impl.BGP;
 import org.opendaylight.protocol.concepts.ListenerRegistration;
@@ -63,13 +61,12 @@ public final class BGPMock implements BGP, Closeable {
 
        private List<Notification> parsePrevious(final MessageRegistry registry, final List<byte[]> msgs) {
                final List<Notification> messages = Lists.newArrayList();
-               final BGPMessageFactory parser = new BGPMessageFactoryImpl(registry);
                try {
                        for (final byte[] b : msgs) {
 
                                final byte[] body = ByteArray.cutBytes(b, 1);
 
-                               messages.add(parser.parse(body));
+                               messages.add(registry.parseMessage(body));
                        }
                } catch (final BGPDocumentedException | BGPParsingException e) {
                        LOG.warn("Failed to parse message {}", e);