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;
(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
(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());
(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());
@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);
}
(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."));
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());
(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());
(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());
(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());
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()));
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()));
(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());
(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());
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));