X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=pcep%2Ftesttool%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fprotocol%2Fpcep%2Ftesttool%2FPCCMock.java;h=dc2d8bcbd4f24c9f08f5eed5600e54bafe97efa2;hb=4d2a6ddcf804cdcb6451f7edbd7334e7c2119b86;hp=f19f563b5d627c2310a1c7c8319081fe377de89c;hpb=5fbf4f8681909a3ef9dfbf2fa3e9b1a1f0b5b6fc;p=bgpcep.git diff --git a/pcep/testtool/src/test/java/org/opendaylight/protocol/pcep/testtool/PCCMock.java b/pcep/testtool/src/test/java/org/opendaylight/protocol/pcep/testtool/PCCMock.java index f19f563b5d..dc2d8bcbd4 100644 --- a/pcep/testtool/src/test/java/org/opendaylight/protocol/pcep/testtool/PCCMock.java +++ b/pcep/testtool/src/test/java/org/opendaylight/protocol/pcep/testtool/PCCMock.java @@ -7,69 +7,44 @@ */ package org.opendaylight.protocol.pcep.testtool; -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 com.google.common.base.Preconditions; +import com.google.common.net.HostAndPort; import java.net.InetSocketAddress; +import java.util.ArrayList; import java.util.List; - -import org.opendaylight.protocol.framework.AbstractDispatcher; -import org.opendaylight.protocol.framework.NeverReconnectStrategy; -import org.opendaylight.protocol.framework.ProtocolHandlerFactory; -import org.opendaylight.protocol.framework.ProtocolMessage; -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.pcep.PCEPMessage; -import org.opendaylight.protocol.pcep.PCEPSessionListener; -import org.opendaylight.protocol.pcep.PCEPTlv; +import java.util.concurrent.ExecutionException; +import org.opendaylight.protocol.concepts.KeyMapping; +import org.opendaylight.protocol.pcep.PCEPCapability; +import org.opendaylight.protocol.pcep.PCEPSession; +import org.opendaylight.protocol.pcep.PCEPSessionNegotiatorFactory; +import org.opendaylight.protocol.pcep.PCEPSessionProposalFactory; +import org.opendaylight.protocol.pcep.impl.BasePCEPSessionProposalFactory; import org.opendaylight.protocol.pcep.impl.DefaultPCEPSessionNegotiatorFactory; -import org.opendaylight.protocol.pcep.impl.PCEPHandlerFactory; -import org.opendaylight.protocol.pcep.impl.PCEPSessionImpl; -import org.opendaylight.protocol.pcep.object.PCEPOpenObject; -import org.opendaylight.protocol.pcep.tlv.NodeIdentifierTlv; - -import com.google.common.base.Preconditions; -import com.google.common.collect.Lists; - -public class PCCMock, L extends SessionListener> extends - AbstractDispatcher { - - private final SessionNegotiatorFactory negotiatorFactory; - private final ProtocolHandlerFactory factory; - - public PCCMock(final SessionNegotiatorFactory negotiatorFactory, final ProtocolHandlerFactory factory, - final DefaultPromise defaultPromise) { - this.negotiatorFactory = Preconditions.checkNotNull(negotiatorFactory); - this.factory = Preconditions.checkNotNull(factory); - } - - @Override - public void initializeChannel(final SocketChannel ch, final Promise promise, final SessionListenerFactory listenerFactory) { - ch.pipeline().addLast(this.factory.getDecoders()); - ch.pipeline().addLast("negotiator", this.negotiatorFactory.getSessionNegotiator(listenerFactory, ch, promise)); - ch.pipeline().addLast(this.factory.getEncoders()); - } - - public static void main(final String[] args) throws Exception { - final List tlvs = Lists.newArrayList(); - tlvs.add(new NodeIdentifierTlv(new byte[] { (byte) 127, (byte) 2, (byte) 3, (byte) 7 })); - - final SessionNegotiatorFactory snf = new DefaultPCEPSessionNegotiatorFactory(new HashedWheelTimer(), new PCEPOpenObject(30, 120, 0, tlvs), 0); - - final PCCMock pcc = new PCCMock<>(snf, new PCEPHandlerFactory(), new DefaultPromise(GlobalEventExecutor.INSTANCE)); - - pcc.createClient(new InetSocketAddress("127.0.0.3", 12345), new NeverReconnectStrategy(GlobalEventExecutor.INSTANCE, 2000), - new SessionListenerFactory() { - - @Override - public PCEPSessionListener getSessionListener() { - return new SimpleSessionListener(); - } - }).get(); - } +import org.opendaylight.protocol.pcep.pcc.mock.protocol.PCCDispatcherImpl; +import org.opendaylight.protocol.pcep.spi.pojo.ServiceLoaderPCEPExtensionProviderContext; +import org.opendaylight.protocol.util.InetSocketAddressUtil; + +public final class PCCMock { + + private PCCMock() { + throw new UnsupportedOperationException(); + } + + public static void main(final String[] args) throws InterruptedException, ExecutionException { + Preconditions.checkArgument(args.length > 0, "Host and port of server must be provided."); + final List caps = new ArrayList<>(); + final PCEPSessionProposalFactory proposal = new BasePCEPSessionProposalFactory((short) 120, (short) 30, caps); + final PCEPSessionNegotiatorFactory snf + = new DefaultPCEPSessionNegotiatorFactory(proposal, 0); + final HostAndPort serverHostAndPort = HostAndPort.fromString(args[0]); + final InetSocketAddress serverAddr = new InetSocketAddress(serverHostAndPort.getHost(), serverHostAndPort + .getPortOrDefault(12345)); + final InetSocketAddress clientAddr = InetSocketAddressUtil.getRandomLoopbackInetSocketAddress(0); + + try (PCCDispatcherImpl pccDispatcher = new PCCDispatcherImpl(ServiceLoaderPCEPExtensionProviderContext + .getSingletonInstance().getMessageHandlerRegistry())) { + pccDispatcher.createClient(serverAddr, -1, SimpleSessionListener::new, snf, + KeyMapping.getKeyMapping(), clientAddr).get(); + } + } }