import org.opendaylight.protocol.bgp.parser.impl.message.BGPUpdateMessageParser;
import org.opendaylight.protocol.bgp.parser.spi.MessageRegistry;
import org.opendaylight.protocol.bgp.parser.spi.MessageUtil;
-import org.opendaylight.protocol.bgp.parser.spi.pojo.BGPExtensionProviderContextImpl;
+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.AsNumber;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
@BeforeClass
public static void setUp() throws Exception {
- updateParser = new BGPUpdateMessageParser(BGPExtensionProviderContextImpl.getSingletonInstance().getAttributeRegistry());
+ updateParser = new BGPUpdateMessageParser(ServiceLoaderBGPExtensionProviderContext.createConsumerContext().getAttributeRegistry());
for (int i = 1; i <= COUNTER; i++) {
final String name = "/up" + i + ".bin";
*/
@Test
public void testOpenMessage() throws Exception {
- final MessageRegistry msgReg = BGPExtensionProviderContextImpl.getSingletonInstance().getMessageRegistry();
+ final MessageRegistry msgReg = ServiceLoaderBGPExtensionProviderContext.createConsumerContext().getMessageRegistry();
final Open open = (Open) msgReg.parseMessage(inputBytes.get(13));
final Set<BgpTableType> types = Sets.newHashSet();
for (final BgpParameters param : open.getBgpParameters()) {
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.fail;
-import java.io.IOException;
import java.util.Map;
import org.junit.Test;
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.BGPExtensionProviderContextImpl;
+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;
}
@Test
- public void testBGPHeaderParser() throws IOException {
- final MessageRegistry msgReg = BGPExtensionProviderContextImpl.getSingletonInstance().getMessageRegistry();
+ public void testBGPHeaderParser() throws Exception {
+ final MessageRegistry msgReg = ServiceLoaderBGPExtensionProviderContext.createConsumerContext().getMessageRegistry();
try {
msgReg.parseMessage(new byte[] { (byte) 0, (byte) 0 });
fail("Exception should have occured.");
}
@Test
- public void testMessageParser() throws IOException {
- final MessageRegistry msgReg = BGPExtensionProviderContextImpl.getSingletonInstance().getMessageRegistry();
+ public void testMessageParser() throws Exception {
+ final MessageRegistry msgReg = ServiceLoaderBGPExtensionProviderContext.createConsumerContext().getMessageRegistry();
String ex = "";
try {
msgReg.serializeMessage(null);
import org.junit.Test;
import org.opendaylight.protocol.bgp.parser.BGPDocumentedException;
import org.opendaylight.protocol.bgp.parser.BGPParsingException;
-import org.opendaylight.protocol.bgp.parser.spi.pojo.BGPExtensionProviderContextImpl;
+import org.opendaylight.protocol.bgp.parser.spi.pojo.ServiceLoaderBGPExtensionProviderContext;
/*
* To test incorrect values.
*/
public class PathAttributeParserTest {
@Test
- public void testOriginParser() {
+ public void testOriginParser() throws Exception {
try {
- BGPExtensionProviderContextImpl.getSingletonInstance().getAttributeRegistry().parseAttributes(new byte[] { 0x40, 0x01, 0x01, 0x04 });
+ ServiceLoaderBGPExtensionProviderContext.createConsumerContext().getAttributeRegistry().parseAttributes(new byte[] { 0x40, 0x01, 0x01, 0x04 });
fail("This needs to fail.");
} catch (final BGPDocumentedException e) {
assertEquals("Unknown Origin type.", e.getMessage());
import org.opendaylight.protocol.bgp.parser.spi.NlriRegistry;
import org.opendaylight.protocol.bgp.parser.spi.ParameterRegistry;
import org.opendaylight.protocol.bgp.parser.spi.SubsequentAddressFamilyRegistry;
+import org.opendaylight.protocol.bgp.parser.spi.pojo.SimpleBGPExtensionProviderContext;
import org.opendaylight.protocol.concepts.AbstractRegistration;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceRegistration;
import com.google.common.base.Preconditions;
class OSGiBGPExtensionConsumerContext implements BGPExtensionConsumerContext {
+ protected final SimpleBGPExtensionProviderContext providerContext = new SimpleBGPExtensionProviderContext();
protected final BundleContext bundleContext;
OSGiBGPExtensionConsumerContext(final BundleContext context) {
this.bundleContext = Preconditions.checkNotNull(context);
}
- protected <T> AutoCloseable register(final Class<T> clazz, final T object) {
+ protected final <T> AutoCloseable register(final Class<T> clazz, final T object) {
final ServiceRegistration<T> reg = bundleContext.registerService(clazz, object, null);
return new AbstractRegistration() {
};
}
- public BundleContext getBundleContext() {
+ public final BundleContext getBundleContext() {
return bundleContext;
}
@Override
- public AddressFamilyRegistry getAddressFamilyRegistry() {
- // TODO Auto-generated method stub
- return null;
+ public final AddressFamilyRegistry getAddressFamilyRegistry() {
+ return providerContext.getAddressFamilyRegistry();
}
@Override
- public AttributeRegistry getAttributeRegistry() {
- // TODO Auto-generated method stub
- return null;
+ public final AttributeRegistry getAttributeRegistry() {
+ return providerContext.getAttributeRegistry();
}
@Override
- public CapabilityRegistry getCapabilityRegistry() {
- // TODO Auto-generated method stub
- return null;
+ public final CapabilityRegistry getCapabilityRegistry() {
+ return providerContext.getCapabilityRegistry();
}
@Override
- public MessageRegistry getMessageRegistry() {
- // TODO Auto-generated method stub
- return null;
+ public final MessageRegistry getMessageRegistry() {
+ return providerContext.getMessageRegistry();
}
@Override
- public NlriRegistry getNlriRegistry() {
- // TODO Auto-generated method stub
- return null;
+ public final NlriRegistry getNlriRegistry() {
+ return providerContext.getNlriRegistry();
}
@Override
- public ParameterRegistry getParameterRegistry() {
- // TODO Auto-generated method stub
- return null;
+ public final ParameterRegistry getParameterRegistry() {
+ return providerContext.getParameterRegistry();
}
@Override
- public SubsequentAddressFamilyRegistry getSubsequentAddressFamilyRegistry() {
- // TODO Auto-generated method stub
- return null;
+ public final SubsequentAddressFamilyRegistry getSubsequentAddressFamilyRegistry() {
+ return providerContext.getSubsequentAddressFamilyRegistry();
}
-
}
--- /dev/null
+/*
+ * 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.spi.pojo;
+
+import java.util.ServiceLoader;
+
+import org.opendaylight.protocol.bgp.parser.spi.BGPExtensionConsumerContext;
+import org.opendaylight.protocol.bgp.parser.spi.BGPExtensionProviderActivator;
+import org.opendaylight.protocol.bgp.parser.spi.BGPExtensionProviderContext;
+
+public final class ServiceLoaderBGPExtensionProviderContext {
+ private ServiceLoaderBGPExtensionProviderContext() {
+
+ }
+
+ public static BGPExtensionConsumerContext createConsumerContext() throws Exception {
+ final BGPExtensionProviderContext ctx = new SimpleBGPExtensionProviderContext();
+
+ final ServiceLoader<BGPExtensionProviderActivator> loader = ServiceLoader.load(BGPExtensionProviderActivator.class);
+ for (BGPExtensionProviderActivator a : loader) {
+ a.start(ctx);
+ }
+
+ return ctx;
+ }
+}
--- /dev/null
+/*
+ * 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.spi.pojo;
+
+import org.opendaylight.protocol.bgp.parser.spi.AddressFamilyRegistry;
+import org.opendaylight.protocol.bgp.parser.spi.AttributeRegistry;
+import org.opendaylight.protocol.bgp.parser.spi.BGPExtensionConsumerContext;
+import org.opendaylight.protocol.bgp.parser.spi.CapabilityRegistry;
+import org.opendaylight.protocol.bgp.parser.spi.MessageRegistry;
+import org.opendaylight.protocol.bgp.parser.spi.NlriRegistry;
+import org.opendaylight.protocol.bgp.parser.spi.ParameterRegistry;
+import org.opendaylight.protocol.bgp.parser.spi.SubsequentAddressFamilyRegistry;
+
+class SimpleBGPExtensionConsumerContext implements BGPExtensionConsumerContext {
+ protected final SimpleAddressFamilyRegistry afiReg = new SimpleAddressFamilyRegistry();
+ protected final SimpleAttributeRegistry attrReg = new SimpleAttributeRegistry();
+ protected final SimpleCapabilityRegistry capReg = new SimpleCapabilityRegistry();
+ protected final SimpleMessageRegistry msgReg = new SimpleMessageRegistry();
+ protected final SimpleSubsequentAddressFamilyRegistry safiReg = new SimpleSubsequentAddressFamilyRegistry();
+ protected final SimpleParameterRegistry paramReg = new SimpleParameterRegistry();
+ protected final SimpleNlriRegistry nlriReg = new SimpleNlriRegistry(afiReg, safiReg);
+
+ @Override
+ public final AddressFamilyRegistry getAddressFamilyRegistry() {
+ return afiReg;
+ }
+
+ @Override
+ public final AttributeRegistry getAttributeRegistry() {
+ return attrReg;
+ }
+
+ @Override
+ public final CapabilityRegistry getCapabilityRegistry() {
+ return capReg;
+ }
+
+ @Override
+ public final MessageRegistry getMessageRegistry() {
+ return msgReg;
+ }
+
+ @Override
+ public final NlriRegistry getNlriRegistry() {
+ return nlriReg;
+ }
+
+ @Override
+ public final ParameterRegistry getParameterRegistry() {
+ return paramReg;
+ }
+
+ @Override
+ public final SubsequentAddressFamilyRegistry getSubsequentAddressFamilyRegistry() {
+ return safiReg;
+ }
+}
*/
package org.opendaylight.protocol.bgp.parser.spi.pojo;
-import java.util.ServiceLoader;
-
-import org.opendaylight.protocol.bgp.parser.spi.AddressFamilyRegistry;
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.protocol.bgp.parser.spi.BGPExtensionConsumerContext;
-import org.opendaylight.protocol.bgp.parser.spi.BGPExtensionProviderActivator;
import org.opendaylight.protocol.bgp.parser.spi.BGPExtensionProviderContext;
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.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.bgp.parser.spi.NlriParser;
-import org.opendaylight.protocol.bgp.parser.spi.NlriRegistry;
import org.opendaylight.protocol.bgp.parser.spi.NlriSerializer;
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.protocol.bgp.parser.spi.SubsequentAddressFamilyRegistry;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.open.BgpParameters;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.open.bgp.parameters.CParameters;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.AddressFamily;
import org.opendaylight.yangtools.yang.binding.DataObject;
import org.opendaylight.yangtools.yang.binding.Notification;
-public final class BGPExtensionProviderContextImpl implements BGPExtensionProviderContext {
- private static final class Holder {
- private static final BGPExtensionConsumerContext INSTANCE;
-
- static {
- try {
- INSTANCE = BGPExtensionProviderContextImpl.create();
- } catch (Exception e) {
- throw new ExceptionInInitializerError(e);
- }
- }
- }
-
- private final SimpleAddressFamilyRegistry afiReg = new SimpleAddressFamilyRegistry();
- private final SimpleAttributeRegistry attrReg = new SimpleAttributeRegistry();
- private final SimpleCapabilityRegistry capReg = new SimpleCapabilityRegistry();
- private final SimpleMessageRegistry msgReg = new SimpleMessageRegistry();
- private final SimpleSubsequentAddressFamilyRegistry safiReg = new SimpleSubsequentAddressFamilyRegistry();
- private final SimpleParameterRegistry paramReg = new SimpleParameterRegistry();
- private final SimpleNlriRegistry nlriReg = new SimpleNlriRegistry(afiReg, safiReg);
-
- private BGPExtensionProviderContextImpl() {
-
- }
-
- public static BGPExtensionConsumerContext getSingletonInstance() {
- return Holder.INSTANCE;
- }
-
- public static BGPExtensionConsumerContext create() throws Exception {
- final BGPExtensionProviderContextImpl ctx = new BGPExtensionProviderContextImpl();
-
- final ServiceLoader<BGPExtensionProviderActivator> loader = ServiceLoader.load(BGPExtensionProviderActivator.class);
- for (BGPExtensionProviderActivator a : loader) {
- a.start(ctx);
- }
-
- return ctx;
- }
-
- @Override
- public AddressFamilyRegistry getAddressFamilyRegistry() {
- return afiReg;
- }
-
+public final class SimpleBGPExtensionProviderContext extends SimpleBGPExtensionConsumerContext implements BGPExtensionProviderContext {
@Override
public AutoCloseable registerAddressFamily(final Class<? extends AddressFamily> clazz, final int number) {
return afiReg.registerAddressFamily(clazz, number);
}
- @Override
- public AttributeRegistry getAttributeRegistry() {
- return attrReg;
- }
-
@Override
public AutoCloseable registerAttributeParser(final int attributeType, final AttributeParser parser) {
return attrReg.registerAttributeParser(attributeType, parser);
return attrReg.registerAttributeSerializer(attributeClass, serializer);
}
- @Override
- public CapabilityRegistry getCapabilityRegistry() {
- return capReg;
- }
-
@Override
public AutoCloseable registerCapabilityParser(final int capabilityType, final CapabilityParser parser) {
return capReg.registerCapabilityParser(capabilityType, parser);
return capReg.registerCapabilitySerializer(capabilityClass, serializer);
}
- @Override
- public MessageRegistry getMessageRegistry() {
- return msgReg;
- }
-
@Override
public AutoCloseable registerMessageParser(final int messageType, final MessageParser parser) {
return msgReg.registerMessageParser(messageType, parser);
return msgReg.registerMessageSerializer(messageClass, serializer);
}
- @Override
- public NlriRegistry getNlriRegistry() {
- return nlriReg;
- }
-
@Override
public AutoCloseable registerNlriParser(final Class<? extends AddressFamily> afi, final Class<? extends SubsequentAddressFamily> safi,
final NlriParser parser) {
throw new UnsupportedOperationException("NLRI serialization not implemented");
}
- @Override
- public ParameterRegistry getParameterRegistry() {
- return paramReg;
- }
-
@Override
public AutoCloseable registerParameterParser(final int parameterType, final ParameterParser parser) {
return paramReg.registerParameterParser(parameterType, parser);
return paramReg.registerParameterSerializer(paramClass, serializer);
}
- @Override
- public SubsequentAddressFamilyRegistry getSubsequentAddressFamilyRegistry() {
- return safiReg;
- }
-
@Override
public AutoCloseable registerSubsequentAddressFamily(final Class<? extends SubsequentAddressFamily> clazz, final int number) {
return safiReg.registerSubsequentAddressFamily(clazz, number);
import java.util.List;
import java.util.Map;
+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.BgpTableTypeImpl;
import org.opendaylight.protocol.bgp.parser.spi.MessageRegistry;
-import org.opendaylight.protocol.bgp.parser.spi.pojo.BGPExtensionProviderContextImpl;
+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;
(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 MessageRegistry factory =
- BGPExtensionProviderContextImpl.getSingletonInstance().getMessageRegistry();
+ static MessageRegistry factory;
+
+ @BeforeClass
+ public static void setupClass() throws Exception {
+ factory = ServiceLoaderBGPExtensionProviderContext.createConsumerContext().getMessageRegistry();
+ }
@Test
public void testHeaderErrors() throws DeserializerException, DocumentedException {
(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0x00 };
wrong = ByteArray.cutBytes(wrong, 16);
try {
- this.factory.parseMessage(wrong);
+ ParserTest.factory.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 {
- this.factory.parseMessage(bytes);
+ ParserTest.factory.parseMessage(bytes);
fail("Exception should have occured.");
} catch (final DocumentedException e) {
assertEquals(BGPError.BAD_MSG_TYPE, ((BGPDocumentedException) e).getError());
@Test
public void testKeepAliveMsg() throws DeserializerException, DocumentedException {
final Notification keepAlive = new KeepaliveBuilder().build();
- final byte[] bytes = this.factory.serializeMessage(keepAlive);
+ final byte[] bytes = ParserTest.factory.serializeMessage(keepAlive);
assertArrayEquals(keepAliveBMsg, bytes);
- final Notification m = this.factory.parseMessage(bytes);
+ final Notification m = ParserTest.factory.parseMessage(bytes);
assertTrue(m instanceof Keepalive);
}
(byte) 0x00, (byte) 0x14, (byte) 0x04, (byte) 0x05 };
try {
- this.factory.parseMessage(bytes);
+ ParserTest.factory.parseMessage(bytes);
fail("Exception should have occured.");
} catch (final DocumentedException e) {
assertThat(e.getMessage(), containsString("Message length field not within valid range."));
public void testOpenMessage() throws UnknownHostException, DeserializerException, DocumentedException {
final Notification open = new OpenBuilder().setMyAsNumber(100).setHoldTimer(180).setBgpIdentifier(new Ipv4Address("20.20.20.20")).setVersion(
new ProtocolVersion((short) 4)).build();
- final byte[] bytes = this.factory.serializeMessage(open);
+ final byte[] bytes = ParserTest.factory.serializeMessage(open);
assertArrayEquals(openBMsg, bytes);
- final Notification m = this.factory.parseMessage(bytes);
+ final Notification m = ParserTest.factory.parseMessage(bytes);
assertTrue(m instanceof Open);
assertEquals(100, ((Open) m).getMyAsNumber().intValue());
(byte) 0x14, (byte) 0x14, (byte) 0x14, (byte) 0x00 };
try {
- this.factory.parseMessage(bMsg);
+ ParserTest.factory.parseMessage(bMsg);
fail("Exception should have occured.");
} catch (final DocumentedException e) {
assertEquals("Hold time value not acceptable.", e.getMessage());
(byte) 0xff, (byte) 0xff };
try {
- this.factory.parseMessage(bMsg);
+ ParserTest.factory.parseMessage(bMsg);
fail("Exception should have occured.");
} catch (final DocumentedException e) {
assertEquals("Open message too small.", e.getMessage());
(byte) 0x14, (byte) 0x14, (byte) 0x14, (byte) 0x00 };
try {
- this.factory.parseMessage(bMsg);
+ ParserTest.factory.parseMessage(bMsg);
fail("Exception should have occured.");
} catch (final DocumentedException e) {
assertEquals("BGP Protocol version 8 not supported.", e.getMessage());
public void testNotificationMsg() throws DeserializerException, DocumentedException {
Notification notMsg = new NotifyBuilder().setErrorCode(BGPError.OPT_PARAM_NOT_SUPPORTED.getCode()).setErrorSubcode(
BGPError.OPT_PARAM_NOT_SUPPORTED.getSubcode()).setData(new byte[] { 4, 9 }).build();
- byte[] bytes = this.factory.serializeMessage(notMsg);
+ byte[] bytes = ParserTest.factory.serializeMessage(notMsg);
assertArrayEquals(notificationBMsg, bytes);
- Notification m = this.factory.parseMessage(bytes);
+ Notification m = ParserTest.factory.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 = this.factory.serializeMessage(notMsg);
+ bytes = ParserTest.factory.serializeMessage(notMsg);
- m = this.factory.parseMessage(bytes);
+ m = ParserTest.factory.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 {
- this.factory.parseMessage(bMsg);
+ ParserTest.factory.parseMessage(bMsg);
fail("Exception should have occured.");
} catch (final DocumentedException e) {
assertEquals("Notification message too small.", e.getMessage());
(byte) 0x00, (byte) 0x15, (byte) 0x03, (byte) 0x02, (byte) 0xaa };
try {
- this.factory.parseMessage(bMsg);
+ ParserTest.factory.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 = this.factory.serializeMessage(open);
+ final byte[] result = ParserTest.factory.serializeMessage(open);
// the capabilities can be swapped.
assertTrue(Arrays.equals(openWithCpblt1, result) || Arrays.equals(openWithCpblt2, result));
import io.netty.util.concurrent.GlobalEventExecutor;
-import java.io.IOException;
import java.net.InetAddress;
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.BGPExtensionProviderContextImpl;
+import org.opendaylight.protocol.bgp.parser.spi.pojo.ServiceLoaderBGPExtensionProviderContext;
import org.opendaylight.protocol.bgp.rib.impl.BGPDispatcherImpl;
import org.opendaylight.protocol.bgp.rib.impl.BGPSessionProposalImpl;
import org.opendaylight.protocol.bgp.rib.impl.spi.BGPSessionPreferences;
BGPDispatcherImpl dispatcher;
- public Main() throws IOException {
- this.dispatcher = new BGPDispatcherImpl(new BGPMessageFactoryImpl(BGPExtensionProviderContextImpl.getSingletonInstance().getMessageRegistry()));
+ public Main() throws Exception {
+ this.dispatcher = new BGPDispatcherImpl(new BGPMessageFactoryImpl(
+ ServiceLoaderBGPExtensionProviderContext.createConsumerContext().getMessageRegistry()));
}
- public static void main(final String[] args) throws NumberFormatException, IOException {
+ public static void main(final String[] args) throws Exception {
if (args.length == 0 || args.length == 1 && args[0].equalsIgnoreCase("--help")) {
System.out.println(Main.usage);
return;
import io.netty.util.concurrent.GlobalEventExecutor;
import io.netty.util.concurrent.Promise;
-import java.io.IOException;
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.BGPExtensionProviderContextImpl;
+import org.opendaylight.protocol.bgp.parser.spi.pojo.ServiceLoaderBGPExtensionProviderContext;
import org.opendaylight.protocol.bgp.rib.impl.BGPHandlerFactory;
import org.opendaylight.protocol.bgp.rib.impl.BGPSessionImpl;
import org.opendaylight.protocol.bgp.rib.impl.BGPSessionNegotiatorFactory;
});
}
- public static void main(final String[] args) throws IOException {
+ public static void main(final String[] args) throws Exception {
final SessionListenerFactory<BGPSessionListener> f = new SessionListenerFactory<BGPSessionListener>() {
@Override
final SessionNegotiatorFactory<Notification, BGPSessionImpl, BGPSessionListener> snf = new BGPSessionNegotiatorFactory(new HashedWheelTimer(), prefs);
final BGPSpeakerMock<Notification, BGPSessionImpl, BGPSessionListener> mock = new BGPSpeakerMock<>(snf,
- new BGPHandlerFactory(new BGPMessageFactoryImpl(BGPExtensionProviderContextImpl.getSingletonInstance().getMessageRegistry())),
+ new BGPHandlerFactory(new BGPMessageFactoryImpl(ServiceLoaderBGPExtensionProviderContext.createConsumerContext().getMessageRegistry())),
new DefaultPromise<BGPSessionImpl>(GlobalEventExecutor.INSTANCE));
mock.createServer(new InetSocketAddress("127.0.0.2", 12345), f);
return parsers.get(type);
}
- public AutoCloseable registerSerializer(final Class<? extends CLASS> clazz, final SERIALIZER serializer) {
+ public AbstractRegistration registerSerializer(final Class<? extends CLASS> clazz, final SERIALIZER serializer) {
return serializers.register(clazz, serializer);
}