From: Robert Varga Date: Fri, 22 Nov 2013 06:34:01 +0000 (+0100) Subject: Do not rely on deprecated classes directly X-Git-Tag: jenkins-bgpcep-bulk-release-prepare-only-1~228 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=d1fc5be78cf158b4273abbc9355d0662d86addb6;p=bgpcep.git Do not rely on deprecated classes directly Change-Id: Ifeabc5220952aa6cee16a193875ff5b17d508faa Signed-off-by: Robert Varga --- 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 index 1c25f27768..7406943cca 100644 --- 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 @@ -14,5 +14,6 @@ import org.opendaylight.yangtools.yang.binding.Notification; * Interface to expose BGP specific MessageFactory. */ public interface BGPMessageFactory extends ProtocolMessageFactory { - + @Override + public Notification parse(final byte[] bytes) throws BGPParsingException, BGPDocumentedException; } diff --git a/bgp/parser-api/src/test/java/org/opendaylight/protocol/bgp/parser/APITest.java b/bgp/parser-api/src/test/java/org/opendaylight/protocol/bgp/parser/APITest.java index db2485088c..7fa2d036ad 100644 --- a/bgp/parser-api/src/test/java/org/opendaylight/protocol/bgp/parser/APITest.java +++ b/bgp/parser-api/src/test/java/org/opendaylight/protocol/bgp/parser/APITest.java @@ -11,22 +11,20 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; import org.junit.Test; -import org.opendaylight.protocol.framework.DeserializerException; -import org.opendaylight.protocol.framework.DocumentedException; public class APITest { @Test public void testDocumentedException() { - final DocumentedException de = new BGPDocumentedException("Some message", BGPError.BAD_BGP_ID); + final BGPDocumentedException de = new BGPDocumentedException("Some message", BGPError.BAD_BGP_ID); assertEquals("Some message", de.getMessage()); - assertEquals(BGPError.BAD_BGP_ID, ((BGPDocumentedException) de).getError()); - assertNull(((BGPDocumentedException) de).getData()); + assertEquals(BGPError.BAD_BGP_ID, de.getError()); + assertNull(de.getData()); } @Test public void testParsingException() { - final DeserializerException de = new BGPParsingException("Some message"); + final BGPParsingException de = new BGPParsingException("Some message"); assertEquals("Some message", de.getMessage()); } 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 index 15eca5fe03..1b59155543 100644 --- 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 @@ -7,10 +7,10 @@ */ 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.protocol.framework.DeserializerException; -import org.opendaylight.protocol.framework.DocumentedException; import org.opendaylight.yangtools.yang.binding.Notification; import com.google.common.base.Preconditions; @@ -27,7 +27,7 @@ public final class BGPMessageFactoryImpl implements BGPMessageFactory { * @see org.opendaylight.protocol.bgp.parser.BGPMessageParser#parse(byte[]) */ @Override - public Notification parse(final byte[] bytes) throws DeserializerException, DocumentedException { + public Notification parse(final byte[] bytes) throws BGPParsingException, BGPDocumentedException { return this.registry.parseMessage(bytes); } diff --git a/bgp/parser-impl/src/test/java/org/opendaylight/protocol/bgp/parser/impl/ComplementaryTest.java b/bgp/parser-impl/src/test/java/org/opendaylight/protocol/bgp/parser/impl/ComplementaryTest.java index 3666ab7e8f..32626f43a2 100644 --- a/bgp/parser-impl/src/test/java/org/opendaylight/protocol/bgp/parser/impl/ComplementaryTest.java +++ b/bgp/parser-impl/src/test/java/org/opendaylight/protocol/bgp/parser/impl/ComplementaryTest.java @@ -21,8 +21,6 @@ import org.opendaylight.protocol.bgp.parser.BgpTableTypeImpl; import org.opendaylight.protocol.bgp.parser.impl.message.update.CommunitiesParser; import org.opendaylight.protocol.bgp.parser.spi.MessageRegistry; import org.opendaylight.protocol.bgp.parser.spi.pojo.ServiceLoaderBGPExtensionProviderContext; -import org.opendaylight.protocol.framework.DeserializerException; -import org.opendaylight.protocol.framework.DocumentedException; import org.opendaylight.protocol.util.ByteList; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.AsNumber; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address; @@ -226,10 +224,6 @@ public class ComplementaryTest { fail("Exception should have occured."); } catch (final IllegalArgumentException e) { assertEquals("Too few bytes in passed array. Passed: 2. Expected: >= 19.", e.getMessage()); - } catch (final DeserializerException e) { - fail("Not this exception should have occured:" + e); - } catch (final DocumentedException e) { - fail("Not this exception should have occured:" + e); } } diff --git a/bgp/parser-impl/src/test/java/org/opendaylight/protocol/bgp/parser/impl/ParserTest.java b/bgp/parser-impl/src/test/java/org/opendaylight/protocol/bgp/parser/impl/ParserTest.java index 0ff66fc6d5..f2a379c171 100644 --- a/bgp/parser-impl/src/test/java/org/opendaylight/protocol/bgp/parser/impl/ParserTest.java +++ b/bgp/parser-impl/src/test/java/org/opendaylight/protocol/bgp/parser/impl/ParserTest.java @@ -25,11 +25,9 @@ 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.impl.BGPMessageFactoryImpl; import org.opendaylight.protocol.bgp.parser.spi.pojo.ServiceLoaderBGPExtensionProviderContext; -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.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.LinkstateAddressFamily; @@ -56,31 +54,31 @@ import com.google.common.collect.Maps; public class ParserTest { public static final byte[] openBMsg = new byte[] { (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, - (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, - (byte) 0xff, (byte) 0x00, (byte) 0x1d, (byte) 0x01, (byte) 0x04, (byte) 0x00, (byte) 0x64, (byte) 0x00, (byte) 0xb4, - (byte) 0x14, (byte) 0x14, (byte) 0x14, (byte) 0x14, (byte) 0x00 }; + (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, + (byte) 0xff, (byte) 0x00, (byte) 0x1d, (byte) 0x01, (byte) 0x04, (byte) 0x00, (byte) 0x64, (byte) 0x00, (byte) 0xb4, + (byte) 0x14, (byte) 0x14, (byte) 0x14, (byte) 0x14, (byte) 0x00 }; public static final byte[] keepAliveBMsg = new byte[] { (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, - (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, - (byte) 0xff, (byte) 0x00, (byte) 0x13, (byte) 0x04 }; + (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, + (byte) 0xff, (byte) 0x00, (byte) 0x13, (byte) 0x04 }; public static final byte[] notificationBMsg = new byte[] { (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, - (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, - (byte) 0xff, (byte) 0xff, (byte) 0x00, (byte) 0x17, (byte) 0x03, (byte) 0x02, (byte) 0x04, (byte) 0x04, (byte) 0x09 }; + (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, + (byte) 0xff, (byte) 0xff, (byte) 0x00, (byte) 0x17, (byte) 0x03, (byte) 0x02, (byte) 0x04, (byte) 0x04, (byte) 0x09 }; public static final byte[] openWithCpblt1 = new byte[] { (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, - (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, - (byte) 0xff, (byte) 0x00, (byte) 0x2d, (byte) 0x01, (byte) 0x04, (byte) 0x00, (byte) 0x48, (byte) 0x00, (byte) 0xb4, - (byte) 0xac, (byte) 0x14, (byte) 0xa0, (byte) 0xaa, (byte) 0x10, (byte) 0x02, (byte) 0x06, (byte) 0x01, (byte) 0x04, - (byte) 0x00, (byte) 0x01, (byte) 0x00, (byte) 0x01, (byte) 0x02, (byte) 0x06, (byte) 0x01, (byte) 0x04, (byte) 0x40, - (byte) 0x04, (byte) 0x00, (byte) 0x47 }; + (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, + (byte) 0xff, (byte) 0x00, (byte) 0x2d, (byte) 0x01, (byte) 0x04, (byte) 0x00, (byte) 0x48, (byte) 0x00, (byte) 0xb4, + (byte) 0xac, (byte) 0x14, (byte) 0xa0, (byte) 0xaa, (byte) 0x10, (byte) 0x02, (byte) 0x06, (byte) 0x01, (byte) 0x04, + (byte) 0x00, (byte) 0x01, (byte) 0x00, (byte) 0x01, (byte) 0x02, (byte) 0x06, (byte) 0x01, (byte) 0x04, (byte) 0x40, + (byte) 0x04, (byte) 0x00, (byte) 0x47 }; public static final byte[] openWithCpblt2 = new byte[] { (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, - (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, - (byte) 0xff, (byte) 0x00, (byte) 0x2d, (byte) 0x01, (byte) 0x04, (byte) 0x00, (byte) 0x48, (byte) 0x00, (byte) 0xb4, - (byte) 0xac, (byte) 0x14, (byte) 0xa0, (byte) 0xaa, (byte) 0x10, (byte) 0x02, (byte) 0x06, (byte) 0x01, (byte) 0x04, - (byte) 0x40, (byte) 0x04, (byte) 0x00, (byte) 0x47, (byte) 0x02, (byte) 0x06, (byte) 0x01, (byte) 0x04, (byte) 0x00, - (byte) 0x01, (byte) 0x00, (byte) 0x01 }; + (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, + (byte) 0xff, (byte) 0x00, (byte) 0x2d, (byte) 0x01, (byte) 0x04, (byte) 0x00, (byte) 0x48, (byte) 0x00, (byte) 0xb4, + (byte) 0xac, (byte) 0x14, (byte) 0xa0, (byte) 0xaa, (byte) 0x10, (byte) 0x02, (byte) 0x06, (byte) 0x01, (byte) 0x04, + (byte) 0x40, (byte) 0x04, (byte) 0x00, (byte) 0x47, (byte) 0x02, (byte) 0x06, (byte) 0x01, (byte) 0x04, (byte) 0x00, + (byte) 0x01, (byte) 0x00, (byte) 0x01 }; static BGPMessageFactory factory; @@ -90,7 +88,7 @@ public class ParserTest { } @Test - public void testHeaderErrors() throws DeserializerException, DocumentedException { + public void testHeaderErrors() throws BGPParsingException, BGPDocumentedException { byte[] wrong = 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 }; wrong = ByteArray.cutBytes(wrong, 16); @@ -105,22 +103,22 @@ public class ParserTest { } @Test - public void testBadMsgType() throws DeserializerException { + public void testBadMsgType() throws BGPParsingException { final byte[] bytes = 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) 0x08 }; try { ParserTest.factory.parse(bytes); fail("Exception should have occured."); - } catch (final DocumentedException e) { - assertEquals(BGPError.BAD_MSG_TYPE, ((BGPDocumentedException) e).getError()); + } catch (final BGPDocumentedException e) { + assertEquals(BGPError.BAD_MSG_TYPE, e.getError()); return; } fail(); } @Test - public void testKeepAliveMsg() throws DeserializerException, DocumentedException { + public void testKeepAliveMsg() throws BGPParsingException, BGPDocumentedException { final Notification keepAlive = new KeepaliveBuilder().build(); final byte[] bytes = ParserTest.factory.put(keepAlive); assertArrayEquals(keepAliveBMsg, bytes); @@ -131,7 +129,7 @@ public class ParserTest { } @Test - public void testBadKeepAliveMsg() throws DeserializerException { + public void testBadKeepAliveMsg() throws BGPParsingException { final byte[] bytes = 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) 0x14, (byte) 0x04, (byte) 0x05 }; @@ -139,16 +137,16 @@ public class ParserTest { try { ParserTest.factory.parse(bytes); fail("Exception should have occured."); - } catch (final DocumentedException e) { + } catch (final BGPDocumentedException e) { assertThat(e.getMessage(), containsString("Message length field not within valid range.")); - assertEquals(BGPError.BAD_MSG_LENGTH, ((BGPDocumentedException) e).getError()); + assertEquals(BGPError.BAD_MSG_LENGTH, e.getError()); return; } fail(); } @Test - public void testOpenMessage() throws UnknownHostException, DeserializerException, DocumentedException { + 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); @@ -164,7 +162,7 @@ public class ParserTest { } @Test - public void testBadHoldTimeError() throws DeserializerException { + public void testBadHoldTimeError() throws BGPParsingException { final byte[] bMsg = 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) 0x01, (byte) 0x14, @@ -173,16 +171,16 @@ public class ParserTest { try { ParserTest.factory.parse(bMsg); fail("Exception should have occured."); - } catch (final DocumentedException e) { + } catch (final BGPDocumentedException e) { assertEquals("Hold time value not acceptable.", e.getMessage()); - assertEquals(BGPError.HOLD_TIME_NOT_ACC, ((BGPDocumentedException) e).getError()); + assertEquals(BGPError.HOLD_TIME_NOT_ACC, e.getError()); return; } fail(); } @Test - public void testBadMsgLength() throws DeserializerException { + public void testBadMsgLength() throws BGPParsingException { final byte[] bMsg = 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) 0x1b, (byte) 0x01, (byte) 0x04, (byte) 0x00, (byte) 0x64, (byte) 0x00, (byte) 0xb4, (byte) 0xff, @@ -191,14 +189,14 @@ public class ParserTest { try { ParserTest.factory.parse(bMsg); fail("Exception should have occured."); - } catch (final DocumentedException e) { + } catch (final BGPDocumentedException e) { assertEquals("Open message too small.", e.getMessage()); - assertEquals(BGPError.BAD_MSG_LENGTH, ((BGPDocumentedException) e).getError()); + assertEquals(BGPError.BAD_MSG_LENGTH, e.getError()); } } @Test - public void testBadVersion() throws DeserializerException { + public void testBadVersion() throws BGPParsingException { final byte[] bMsg = 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) 0x08, (byte) 0x00, (byte) 0x64, (byte) 0x00, (byte) 0xb4, (byte) 0x14, @@ -207,16 +205,16 @@ public class ParserTest { try { ParserTest.factory.parse(bMsg); fail("Exception should have occured."); - } catch (final DocumentedException e) { + } catch (final BGPDocumentedException e) { assertEquals("BGP Protocol version 8 not supported.", e.getMessage()); - assertEquals(BGPError.VERSION_NOT_SUPPORTED, ((BGPDocumentedException) e).getError()); + assertEquals(BGPError.VERSION_NOT_SUPPORTED, e.getError()); return; } fail(); } @Test - public void testNotificationMsg() throws DeserializerException, DocumentedException { + 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); @@ -240,7 +238,7 @@ public class ParserTest { } @Test - public void testWrongLength() throws DeserializerException { + public void testWrongLength() throws BGPParsingException { final byte[] bMsg = 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) 0x14, (byte) 0x03, (byte) 0x02 }; @@ -248,16 +246,16 @@ public class ParserTest { try { ParserTest.factory.parse(bMsg); fail("Exception should have occured."); - } catch (final DocumentedException e) { + } catch (final BGPDocumentedException e) { assertEquals("Notification message too small.", e.getMessage()); - assertEquals(BGPError.BAD_MSG_LENGTH, ((BGPDocumentedException) e).getError()); + assertEquals(BGPError.BAD_MSG_LENGTH, e.getError()); return; } fail(); } @Test - public void testUnrecognizedError() throws DeserializerException, DocumentedException { + public void testUnrecognizedError() throws BGPParsingException, BGPDocumentedException { final byte[] bMsg = 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) 0x15, (byte) 0x03, (byte) 0x02, (byte) 0xaa }; diff --git a/bgp/parser-mock/src/main/java/org/opendaylight/protocol/bgp/parser/mock/BGPMessageParserMock.java b/bgp/parser-mock/src/main/java/org/opendaylight/protocol/bgp/parser/mock/BGPMessageParserMock.java index 75e4f8816f..f630f3d3ed 100644 --- a/bgp/parser-mock/src/main/java/org/opendaylight/protocol/bgp/parser/mock/BGPMessageParserMock.java +++ b/bgp/parser-mock/src/main/java/org/opendaylight/protocol/bgp/parser/mock/BGPMessageParserMock.java @@ -9,8 +9,8 @@ package org.opendaylight.protocol.bgp.parser.mock; import java.util.Map; -import org.opendaylight.protocol.framework.DeserializerException; -import org.opendaylight.protocol.framework.DocumentedException; +import org.opendaylight.protocol.bgp.parser.BGPDocumentedException; +import org.opendaylight.protocol.bgp.parser.BGPParsingException; import org.opendaylight.protocol.framework.ProtocolMessageFactory; import org.opendaylight.yangtools.yang.binding.Notification; @@ -30,7 +30,7 @@ public class BGPMessageParserMock implements ProtocolMessageFactory updateMap = Maps.newHashMap(); for (int i = 0; i < this.inputBytes.length; i++) { updateMap.put(this.inputBytes[i], this.messages.get(i)); @@ -104,12 +104,12 @@ public class BGPMessageParserMockTest { /** * Test if method throws IllegalArgumentException after finding no BGPUpdateMessage associated with given byte[] key * - * @throws DocumentedException - * @throws DeserializerException + * @throws BGPDocumentedException + * @throws BGPParsingException * @throws IOException */ @Test(expected = IllegalArgumentException.class) - public void testGetUpdateMessageException() throws DeserializerException, DocumentedException, IOException { + public void testGetUpdateMessageException() throws BGPParsingException, BGPDocumentedException, IOException { final Map updateMap = Maps.newHashMap(); for (int i = 0; i < this.inputBytes.length; i++) { updateMap.put(this.inputBytes[i], this.messages.get(i)); @@ -150,7 +150,7 @@ public class BGPMessageParserMockTest { final List asnums = Lists.newArrayList(new AsSequenceBuilder().setAs(new AsNumber(asn)).build()); final List asPath = Lists.newArrayList(); asPath.add(new SegmentsBuilder().setCSegment(new CAListBuilder().setAsSequence(asnums).build()).build()); - final CNextHop nextHop = (CNextHop) new CIpv6NextHopBuilder().setIpv6NextHop( + final CNextHop nextHop = new CIpv6NextHopBuilder().setIpv6NextHop( new Ipv6NextHopBuilder().setGlobal(new Ipv6Address("2001:db8::1")).setLinkLocal(new Ipv6Address("fe80::c001:bff:fe7e:0")).build()).build(); final Ipv6Prefix pref1 = new Ipv6Prefix("2001:db8:1:2::/64"); @@ -176,7 +176,7 @@ public class BGPMessageParserMockTest { } @Test - public void testGetOpenMessage() throws DeserializerException, DocumentedException, IOException { + public void testGetOpenMessage() throws BGPParsingException, BGPDocumentedException, IOException { final Map openMap = Maps.newHashMap(); final Set type = Sets.newHashSet(); diff --git a/bgp/rib-impl-config/src/main/java/org/opendaylight/controller/config/yang/bgp/rib/impl/BGPMessageFactoryImplModule.java b/bgp/rib-impl-config/src/main/java/org/opendaylight/controller/config/yang/bgp/rib/impl/BGPMessageFactoryImplModule.java index b0608ca96d..dfbd70c2aa 100644 --- a/bgp/rib-impl-config/src/main/java/org/opendaylight/controller/config/yang/bgp/rib/impl/BGPMessageFactoryImplModule.java +++ b/bgp/rib-impl-config/src/main/java/org/opendaylight/controller/config/yang/bgp/rib/impl/BGPMessageFactoryImplModule.java @@ -9,10 +9,10 @@ */ package org.opendaylight.controller.config.yang.bgp.rib.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.impl.BGPMessageFactoryImpl; -import org.opendaylight.protocol.framework.DeserializerException; -import org.opendaylight.protocol.framework.DocumentedException; import org.opendaylight.yangtools.yang.binding.Notification; /** @@ -67,8 +67,7 @@ org.opendaylight.controller.config.yang.bgp.rib.impl.AbstractBGPMessageFactoryIm } @Override - public Notification parse(final byte[] bytes) throws DeserializerException, - DocumentedException { + public Notification parse(final byte[] bytes) throws BGPParsingException, BGPDocumentedException { return inner.parse(bytes); } diff --git a/bgp/rib-mock/src/main/java/org/opendaylight/protocol/bgp/rib/mock/BGPMock.java b/bgp/rib-mock/src/main/java/org/opendaylight/protocol/bgp/rib/mock/BGPMock.java index 22756166b6..77886fd94c 100644 --- a/bgp/rib-mock/src/main/java/org/opendaylight/protocol/bgp/rib/mock/BGPMock.java +++ b/bgp/rib-mock/src/main/java/org/opendaylight/protocol/bgp/rib/mock/BGPMock.java @@ -15,15 +15,15 @@ import java.util.List; import javax.annotation.concurrent.GuardedBy; 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; -import org.opendaylight.protocol.framework.DeserializerException; -import org.opendaylight.protocol.framework.DocumentedException; -import org.opendaylight.protocol.framework.ProtocolMessageFactory; import org.opendaylight.protocol.framework.ReconnectStrategy; import org.opendaylight.protocol.framework.ReconnectStrategyFactory; import org.opendaylight.protocol.util.ByteArray; @@ -43,7 +43,7 @@ import com.google.common.eventbus.EventBus; @ThreadSafe public final class BGPMock implements BGP, Closeable { - private static final Logger logger = LoggerFactory.getLogger(BGPMock.class); + private static final Logger LOG = LoggerFactory.getLogger(BGPMock.class); static final Notification CONNECTION_LOST_MAGIC_MSG = new NotifyBuilder().setErrorCode(BGPError.CEASE.getCode()).build(); @@ -63,7 +63,7 @@ public final class BGPMock implements BGP, Closeable { private List parsePrevious(final MessageRegistry registry, final List msgs) { final List messages = Lists.newArrayList(); - final ProtocolMessageFactory parser = new BGPMessageFactoryImpl(registry); + final BGPMessageFactory parser = new BGPMessageFactoryImpl(registry); try { for (final byte[] b : msgs) { @@ -71,10 +71,8 @@ public final class BGPMock implements BGP, Closeable { messages.add(parser.parse(body)); } - } catch (final DeserializerException e) { - logger.warn(e.getMessage(), e); - } catch (final DocumentedException e) { - logger.warn(e.getMessage(), e); + } catch (final BGPDocumentedException | BGPParsingException e) { + LOG.warn("Failed to parse message {}", e); } return messages; } diff --git a/bgp/testtool/src/test/java/org/opendaylight/protocol/bgp/testtool/BGPSpeakerMock.java b/bgp/testtool/src/test/java/org/opendaylight/protocol/bgp/testtool/BGPSpeakerMock.java index 8264d83318..e2e57f657e 100644 --- a/bgp/testtool/src/test/java/org/opendaylight/protocol/bgp/testtool/BGPSpeakerMock.java +++ b/bgp/testtool/src/test/java/org/opendaylight/protocol/bgp/testtool/BGPSpeakerMock.java @@ -7,13 +7,15 @@ */ package org.opendaylight.protocol.bgp.testtool; -import com.google.common.base.Preconditions; import io.netty.channel.nio.NioEventLoopGroup; import io.netty.channel.socket.SocketChannel; import io.netty.util.HashedWheelTimer; import io.netty.util.concurrent.DefaultPromise; import io.netty.util.concurrent.GlobalEventExecutor; import io.netty.util.concurrent.Promise; + +import java.net.InetSocketAddress; + import org.opendaylight.protocol.bgp.parser.BGPSessionListener; import org.opendaylight.protocol.bgp.parser.impl.BGPMessageFactoryImpl; import org.opendaylight.protocol.bgp.parser.spi.pojo.ServiceLoaderBGPExtensionProviderContext; @@ -23,7 +25,6 @@ import org.opendaylight.protocol.bgp.rib.impl.BGPSessionNegotiatorFactory; import org.opendaylight.protocol.bgp.rib.impl.BGPSessionProposalImpl; import org.opendaylight.protocol.bgp.rib.impl.spi.BGPSessionPreferences; import org.opendaylight.protocol.framework.AbstractDispatcher; -import org.opendaylight.protocol.framework.ProtocolHandlerFactory; import org.opendaylight.protocol.framework.ProtocolSession; import org.opendaylight.protocol.framework.SessionListener; import org.opendaylight.protocol.framework.SessionListenerFactory; @@ -31,14 +32,14 @@ import org.opendaylight.protocol.framework.SessionNegotiatorFactory; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address; import org.opendaylight.yangtools.yang.binding.Notification; -import java.net.InetSocketAddress; +import com.google.common.base.Preconditions; public class BGPSpeakerMock, L extends SessionListener> extends AbstractDispatcher { private final SessionNegotiatorFactory negotiatorFactory; - private final ProtocolHandlerFactory factory; + private final BGPHandlerFactory factory; - public BGPSpeakerMock(final SessionNegotiatorFactory negotiatorFactory, final ProtocolHandlerFactory factory, + public BGPSpeakerMock(final SessionNegotiatorFactory negotiatorFactory, final BGPHandlerFactory factory, final DefaultPromise defaultPromise) { super(new NioEventLoopGroup(), new NioEventLoopGroup()); this.negotiatorFactory = Preconditions.checkNotNull(negotiatorFactory); diff --git a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/PCEPByteToMessageDecoder.java b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/PCEPByteToMessageDecoder.java index 8ba57ad185..995b372425 100644 --- a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/PCEPByteToMessageDecoder.java +++ b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/PCEPByteToMessageDecoder.java @@ -15,7 +15,7 @@ import io.netty.handler.codec.ByteToMessageDecoder; import java.util.ArrayList; import java.util.List; -import org.opendaylight.protocol.framework.DeserializerException; +import org.opendaylight.protocol.pcep.PCEPDeserializerException; import org.opendaylight.protocol.pcep.spi.MessageHandlerRegistry; import org.opendaylight.protocol.util.ByteArray; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Message; @@ -57,7 +57,7 @@ public final class PCEPByteToMessageDecoder extends ByteToMessageDecoder { try { out.add(parse(bytes, errors)); - } catch (DeserializerException e) { + } catch (PCEPDeserializerException e) { LOG.debug("Failed to decode protocol message", e); this.exceptionCaught(ctx, e); } @@ -72,13 +72,13 @@ public final class PCEPByteToMessageDecoder extends ByteToMessageDecoder { } } - private Message parse(final byte[] bytes, final List errors) throws DeserializerException { + private Message parse(final byte[] bytes, final List errors) throws PCEPDeserializerException { final int type = UnsignedBytes.toInt(bytes[1]); final int msgLength = ByteArray.bytesToInt(ByteArray.subByte(bytes, TYPE_SIZE + 1, LENGTH_SIZE)); final byte[] msgBody = ByteArray.cutBytes(bytes, TYPE_SIZE + 1 + LENGTH_SIZE); if (msgBody.length != msgLength - PCEPMessageConstants.COMMON_HEADER_LENGTH) { - throw new DeserializerException("Body size " + msgBody.length + " does not match header size " + throw new PCEPDeserializerException("Body size " + msgBody.length + " does not match header size " + (msgLength - PCEPMessageConstants.COMMON_HEADER_LENGTH)); }