X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=bgp%2Ftesttool%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fprotocol%2Fbgp%2Ftesttool%2FBGPSpeakerMock.java;h=fd5698cf0a8dad58e25b856b0258d4864e209a72;hb=e6d9fbf96737ba5d69a77ac79127b348d13d6a7a;hp=71cf358585f31751da78f06b09af3e9061ebee71;hpb=750312d7538ab246fef36136ae0374305b825c77;p=bgpcep.git 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 71cf358585..fd5698cf0a 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,72 +7,98 @@ */ package org.opendaylight.protocol.bgp.testtool; -import io.netty.channel.socket.SocketChannel; -import io.netty.util.HashedWheelTimer; +import com.google.common.base.Preconditions; +import io.netty.channel.nio.NioEventLoopGroup; import io.netty.util.concurrent.DefaultPromise; 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 java.util.HashMap; +import java.util.Map; +import org.opendaylight.protocol.bgp.parser.BGPDocumentedException; +import org.opendaylight.protocol.bgp.parser.spi.pojo.ServiceLoaderBGPExtensionProviderContext; +import org.opendaylight.protocol.bgp.rib.impl.BGPDispatcherImpl; import org.opendaylight.protocol.bgp.rib.impl.BGPHandlerFactory; +import org.opendaylight.protocol.bgp.rib.impl.BGPServerSessionNegotiatorFactory; import org.opendaylight.protocol.bgp.rib.impl.BGPSessionImpl; -import org.opendaylight.protocol.bgp.rib.impl.BGPSessionNegotiatorFactory; import org.opendaylight.protocol.bgp.rib.impl.BGPSessionProposalImpl; +import org.opendaylight.protocol.bgp.rib.impl.spi.BGPPeerRegistry; 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; -import org.opendaylight.protocol.framework.SessionNegotiatorFactory; +import org.opendaylight.protocol.bgp.rib.spi.BGPSessionListener; +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.IpAddress; 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 org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.LinkstateAddressFamily; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.LinkstateSubsequentAddressFamily; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.Open; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.AddressFamily; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv4AddressFamily; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.SubsequentAddressFamily; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.UnicastSubsequentAddressFamily; -import com.google.common.base.Preconditions; +public class BGPSpeakerMock { + + private final BGPServerSessionNegotiatorFactory negotiatorFactory; + private final BGPHandlerFactory factory; + private final BGPDispatcherImpl disp; + private final BGPPeerRegistry peerRegistry; + private final Map, Class> tables; + + private BGPSpeakerMock(final BGPServerSessionNegotiatorFactory negotiatorFactory, final BGPHandlerFactory factory, + final DefaultPromise defaultPromise) { + this.disp = new BGPDispatcherImpl(null, new NioEventLoopGroup(), new NioEventLoopGroup()); + this.negotiatorFactory = Preconditions.checkNotNull(negotiatorFactory); + this.factory = Preconditions.checkNotNull(factory); + + + this.peerRegistry = new BGPPeerRegistry() { + @Override + public void addPeer(final IpAddress ip, final BGPSessionListener peer, final BGPSessionPreferences prefs) { + } + + @Override + public void removePeer(final IpAddress ip) { + } + + @Override + public boolean isPeerConfigured(final IpAddress ip) { + return true; + } -public class BGPSpeakerMock, L extends SessionListener> extends AbstractDispatcher { + @Override + public BGPSessionListener getPeer(final IpAddress ip, final Ipv4Address sourceId, final Ipv4Address remoteId, final Open open) throws BGPDocumentedException { + return new SpeakerSessionListener(); + } - private final SessionNegotiatorFactory negotiatorFactory; - private final ProtocolHandlerFactory factory; + @Override + public BGPSessionPreferences getPeerPreferences(final IpAddress ip) { + return new BGPSessionProposalImpl((short) 90, new AsNumber(72L), new Ipv4Address("127.0.0.2"), BGPSpeakerMock.this.tables, new AsNumber(72L)).getProposal(); + } - public BGPSpeakerMock(final SessionNegotiatorFactory negotiatorFactory, final ProtocolHandlerFactory factory, - final DefaultPromise defaultPromise) { - this.negotiatorFactory = Preconditions.checkNotNull(negotiatorFactory); - this.factory = Preconditions.checkNotNull(factory); - } + @Override + public void close() throws Exception { - public void createServer(final InetSocketAddress address, final SessionListenerFactory listenerFactory) { - super.createServer(address, new PipelineInitializer() { + } - @Override - public void initializeChannel(final SocketChannel ch, final Promise promise) { - ch.pipeline().addLast(BGPSpeakerMock.this.factory.getDecoders()); - ch.pipeline().addLast("negotiator", - BGPSpeakerMock.this.negotiatorFactory.getSessionNegotiator(listenerFactory, ch, promise)); - ch.pipeline().addLast(BGPSpeakerMock.this.factory.getEncoders()); - } - }); - } + @Override + public void removePeerSession(final IpAddress ip) { + } + }; - public static void main(final String[] args) throws IOException { + this.tables = new HashMap<>(); + this.tables.put(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class); + this.tables.put(LinkstateAddressFamily.class, LinkstateSubsequentAddressFamily.class); + } - final SessionListenerFactory f = new SessionListenerFactory() { - @Override - public BGPSessionListener getSessionListener() { - return new SpeakerSessionListener(); - } - }; + public void main(final String[] args) { - final BGPSessionPreferences prefs = new BGPSessionProposalImpl((short) 90, 25, new Ipv4Address("127.0.0.2")).getProposal(); + final BGPServerSessionNegotiatorFactory snf = new BGPServerSessionNegotiatorFactory(this.peerRegistry); - final SessionNegotiatorFactory snf = new BGPSessionNegotiatorFactory(new HashedWheelTimer(), prefs); + final BGPSpeakerMock mock = new BGPSpeakerMock(snf, new BGPHandlerFactory(ServiceLoaderBGPExtensionProviderContext.getSingletonInstance().getMessageRegistry()), new DefaultPromise(GlobalEventExecutor.INSTANCE)); - final BGPSpeakerMock mock = new BGPSpeakerMock(snf, new BGPHandlerFactory(new BGPMessageFactoryImpl()), new DefaultPromise(GlobalEventExecutor.INSTANCE)); + mock.createServer(new InetSocketAddress("127.0.0.2", 12345)); + } - mock.createServer(new InetSocketAddress("127.0.0.2", 12345), f); - } + private void createServer(final InetSocketAddress address) { + this.disp.createServer(this.peerRegistry,address); + } }