/** * Bootstraps netty, the server that handles all openflow connections */ public void bootstrapNetty() { try { final ServerBootstrap bootstrap = createServerBootStrap(); bootstrap.setOption("reuseAddr", true); bootstrap.setOption("child.keepAlive", true); bootstrap.setOption("child.tcpNoDelay", true); bootstrap.setOption("child.sendBufferSize", Controller.SEND_BUFFER_SIZE); ChannelPipelineFactory pfact = useSsl ? new OpenflowPipelineFactory(this, floodlightProvider.getTimer(), this, debugCounterService, keyStore, keyStorePassword) : new OpenflowPipelineFactory(this, floodlightProvider.getTimer(), this, debugCounterService); bootstrap.setPipelineFactory(pfact); InetSocketAddress sa = new InetSocketAddress(floodlightProvider.getOFPort()); final ChannelGroup cg = new DefaultChannelGroup(); cg.add(bootstrap.bind(sa)); log.info("Listening for switch connections on {}", sa); } catch (Exception e) { throw new RuntimeException(e); } }
/** * Bootstraps netty, the server that handles all openflow connections */ public void bootstrapNetty() { try { final ServerBootstrap bootstrap = createServerBootStrap(); bootstrap.setOption("reuseAddr", true); bootstrap.setOption("child.keepAlive", true); bootstrap.setOption("child.tcpNoDelay", true); bootstrap.setOption("child.sendBufferSize", Controller.SEND_BUFFER_SIZE); ChannelPipelineFactory pfact = useSsl ? new OpenflowPipelineFactory(this, floodlightProvider.getTimer(), this, debugCounterService, ofBitmaps, defaultFactory, keyStore, keyStorePassword) : new OpenflowPipelineFactory(this, floodlightProvider.getTimer(), this, debugCounterService, ofBitmaps, defaultFactory); bootstrap.setPipelineFactory(pfact); InetSocketAddress sa = new InetSocketAddress(floodlightProvider.getOFPort()); final ChannelGroup cg = new DefaultChannelGroup(); cg.add(bootstrap.bind(sa)); log.info("Listening for switch connections on {}", sa); } catch (Exception e) { throw new RuntimeException(e); } }
/** * Bootstraps netty, the server that handles all openflow connections * 启动netty,处理所有OF连接 */ public void bootstrapNetty() { try { final ServerBootstrap bootstrap = createServerBootStrap(); bootstrap.setOption("reuseAddr", true); bootstrap.setOption("child.keepAlive", true); bootstrap.setOption("child.tcpNoDelay", true); bootstrap.setOption("child.sendBufferSize", Controller.SEND_BUFFER_SIZE); ChannelPipelineFactory pfact = useSsl ? new OpenflowPipelineFactory(this, floodlightProvider.getTimer(), this, debugCounterService, keyStore, keyStorePassword) : new OpenflowPipelineFactory(this, floodlightProvider.getTimer(), this, debugCounterService); bootstrap.setPipelineFactory(pfact); InetSocketAddress sa = new InetSocketAddress(floodlightProvider.getOFPort()); final ChannelGroup cg = new DefaultChannelGroup(); cg.add(bootstrap.bind(sa)); log.info("Listening for switch connections on {}", sa); } catch (Exception e) { throw new RuntimeException(e); } }
/** * Bootstraps netty, the server that handles all openflow connections */ public void bootstrapNetty() { try { final ServerBootstrap bootstrap = createServerBootStrap(); bootstrap.setOption("reuseAddr", true); bootstrap.setOption("child.keepAlive", true); bootstrap.setOption("child.tcpNoDelay", true); bootstrap.setOption("child.sendBufferSize", Controller.SEND_BUFFER_SIZE); ChannelPipelineFactory pfact = new OpenflowPipelineFactory(this, floodlightProvider.getTimer(), this, debugCounterService); bootstrap.setPipelineFactory(pfact); InetSocketAddress sa = new InetSocketAddress(floodlightProvider.getOFPort()); final ChannelGroup cg = new DefaultChannelGroup(); cg.add(bootstrap.bind(sa)); log.info("Listening for switch connections on {}", sa); } catch (Exception e) { throw new RuntimeException(e); } }
@Test public void withoutPacketTest() throws Exception { ChannelGroup channelGroup = new DefaultChannelGroup(); HealthCheckManager healthCheckManager = new HealthCheckManager(timer, 3000, channelGroup); healthCheckManager.start(1000); Channel mockChannel = createMockChannel(HealthCheckState.WAIT); channelGroup.add(mockChannel); try { verify(mockChannel, timeout(5000).atLeastOnce()).close(); } finally { healthCheckManager.stop(); } }
protected HttpTunnelServerChannel(ChannelFactory factory, ChannelPipeline pipeline, ChannelSink sink, ServerSocketChannelFactory inboundFactory, ChannelGroup realConnections) { super(factory, pipeline, sink); tunnelIdPrefix = Long.toHexString(random.nextLong()); tunnels = new ConcurrentHashMap<String, HttpTunnelAcceptedChannel>(); config = new HttpTunnelServerChannelConfig(); realChannel = inboundFactory.newChannel(this.createRealPipeline(realConnections)); config.setRealChannel(realChannel); opened = new AtomicBoolean(true); bindState = new AtomicReference<BindState>(BindState.UNBOUND); realConnections.add(realChannel); Channels.fireChannelOpen(this); }
RpcProgramPortmap(ChannelGroup allChannels) { this.allChannels = allChannels; PortmapMapping m = new PortmapMapping(PROGRAM, VERSION, PortmapMapping.TRANSPORT_TCP, RpcProgram.RPCB_PORT); PortmapMapping m1 = new PortmapMapping(PROGRAM, VERSION, PortmapMapping.TRANSPORT_UDP, RpcProgram.RPCB_PORT); map.put(PortmapMapping.key(m), m); map.put(PortmapMapping.key(m1), m1); }
public NettyIkasoaFactory(NettyServerConfig nettyServerConfig, ChannelGroup channelGroup) { this.nettyServerConfig = nettyServerConfig; if (channelGroup == null) this.channelGroup = new DefaultChannelGroup(); else this.channelGroup = channelGroup; }
public NettyServerUpstreamHandler(LoggerFactory loggerFactory, ChannelHandler channelHandler, ChannelGroup channelGroup) { this.logger = loggerFactory.create(this); this.ioErrorLogger = loggerFactory.create(this.getClass().getSimpleName() + ".IOError"); this.channelHandler = channelHandler; this.allChannels = channelGroup; }
@Inject public NettyServerTransport(final ThriftServerDef def, final NettyServerConfig nettyServerConfig, final ChannelGroup allChannels, final boolean local) { this.def = def; this.nettyServerConfig = nettyServerConfig; this.requestedPort = def.getServerPort(); this.allChannels = allChannels; this.local = local; // connectionLimiter must be instantiated exactly once (and thus outside // the pipeline factory) final ConnectionLimiter connectionLimiter = new ConnectionLimiter(def.getMaxConnections()); this.channelStatistics = new ChannelStatistics(allChannels); this.pipelineFactory = new ChannelPipelineFactory() { @Override public ChannelPipeline getPipeline() throws Exception { ChannelPipeline cp = Channels.pipeline(); TProtocolFactory inputProtocolFactory = def.getDuplexProtocolFactory().getInputProtocolFactory(); NiftySecurityHandlers securityHandlers = def.getSecurityFactory().getSecurityHandlers(def, nettyServerConfig); cp.addLast("connectionContext", new ConnectionContextHandler()); cp.addLast("connectionLimiter", connectionLimiter); cp.addLast(ChannelStatistics.NAME, channelStatistics); cp.addLast("encryptionHandler", securityHandlers.getEncryptionHandler()); cp.addLast("frameCodec", def.getThriftFrameCodecFactory().create(def.getMaxFrameSize(), inputProtocolFactory)); if (def.getClientIdleTimeout() != null) { // Add handlers to detect idle client connections and // disconnect them cp.addLast("idleTimeoutHandler", new IdleStateHandler(nettyServerConfig.getTimer(), def.getClientIdleTimeout().toMillis(), NO_WRITER_IDLE_TIMEOUT, NO_ALL_IDLE_TIMEOUT, TimeUnit.MILLISECONDS)); cp.addLast("idleDisconnectHandler", new IdleDisconnectHandler()); } cp.addLast("authHandler", securityHandlers.getAuthenticationHandler()); cp.addLast("dispatcher", new NiftyDispatcher(def, nettyServerConfig.getTimer())); cp.addLast("exceptionLogger", new NiftyExceptionLogger()); return cp; } }; }
public ClientChannelPipeline( final OpenVirteXController openVirteXController, final ChannelGroup cg, final ThreadPoolExecutor pipelineExecutor, final ClientBootstrap bootstrap, final OVXSwitch sw) { super(); this.ctrl = openVirteXController; this.pipelineExecutor = pipelineExecutor; this.timer = PhysicalNetwork.getTimer(); this.idleHandler = new IdleStateHandler(this.timer, 20, 25, 0); this.readTimeoutHandler = new ReadTimeoutHandler(this.timer, 30); this.bootstrap = bootstrap; this.sw = sw; this.cg = cg; }
public ReconnectHandler(final OVXSwitch sw, final ClientBootstrap bootstrap, final Timer timer, final int maxBackOff, final ChannelGroup cg) { super(); this.sw = sw; this.bootstrap = bootstrap; this.timer = timer; this.maxBackOff = maxBackOff; this.cg = cg; }
public ChannelPoolLifecycle(SocketAddress address, ClientBootstrap bootstrap, long getTimeout, ScheduledExecutorService executor, ChannelGroup channelGroup) { _remoteAddress = address; _rateLimiter = new RateLimiter(0, getTimeout / 2, Math.max(10, getTimeout / 32), executor); _bootstrap = bootstrap; _channelGroup = channelGroup; }
public HealthCheckManager(Timer timer, long waitTimeMillis, ChannelGroup channelGroup) { Assert.requireNonNull(timer, "timer must not be null"); Assert.isTrue(waitTimeMillis > 0, "waitTimeMillis is must greater than 0"); Assert.requireNonNull(channelGroup, "channelGroup must not be null"); this.timer = timer; this.waitTimeMillis = waitTimeMillis; this.channelGroup = channelGroup; }
@Test public void legacyPingPacketTest() throws Exception { ChannelGroup channelGroup = new DefaultChannelGroup(); HealthCheckManager healthCheckManager = new HealthCheckManager(timer, 3000, channelGroup); healthCheckManager.start(1000); Channel mockChannel = createMockChannel(HealthCheckState.RECEIVED_LEGACY); channelGroup.add(mockChannel); try { verify(mockChannel, timeout(3000).atLeastOnce()).write(PingPacket.PING_PACKET); } finally { healthCheckManager.stop(); } }
@Test public void pingPacketTest() throws Exception { ChannelGroup channelGroup = new DefaultChannelGroup(); HealthCheckManager healthCheckManager = new HealthCheckManager(timer, 3000, channelGroup); healthCheckManager.start(1000); Channel mockChannel = createMockChannel(HealthCheckState.RECEIVED); channelGroup.add(mockChannel); try { verify(mockChannel, timeout(3000).atLeastOnce()).write(PingSimplePacket.PING_PACKET); } finally { healthCheckManager.stop(); } }
@Override protected ChannelPipelineFactory createPipelineFactory(ChannelGroup group) { return new AbstractExecutorAwareChannelPipelineFactory(getTimeout(), connectionLimit, connPerIP, group, enabledCipherSuites, getExecutionHandler()) { @Override protected SSLContext getSSLContext() { if (encryption == null) { return null; } else { return encryption.getContext(); } } @Override protected boolean isSSLSocket() { return encryption != null && !encryption.isStartTLS(); } @Override protected ChannelUpstreamHandler createHandler() { return AbstractConfigurableAsyncServer.this.createCoreHandler(); } @Override protected ConnectionCountHandler getConnectionCountHandler() { return AbstractConfigurableAsyncServer.this.getConnectionCountHandler(); } }; }
private ChannelGroup getChannelGroupWithDefault( String path ) { ChannelGroup group = subscribers.get( path ); if ( group == null ) { group = subscribers.putIfAbsent( path, new DefaultChannelGroup() ); } return group; }
public void removeSubscription( String path, Channel channel ) { ChannelGroup group = subscribers.get( path ); synchronized ( group ) { group.remove( channel ); if ( group.isEmpty() ) { subscribers.remove( path, group ); } } }
private ChannelPipeline createRealPipeline(ChannelGroup realConnections) { final ChannelPipelineFactory realPipelineFactory = new HttpTunnelAcceptedChannelPipelineFactory(this); final ChannelPipeline pipeline; try { pipeline = realPipelineFactory.getPipeline(); } catch (Exception e) { throw new ChannelPipelineException("Failed to initialize a pipeline.", e); } pipeline.addFirst(HttpTunnelServerChannelHandler.NAME, new HttpTunnelServerChannelHandler(this, realPipelineFactory, realConnections)); return pipeline; }
public NettyRpcServerHandler(ChannelGroup channelGroups) { this.channelGroups = channelGroups; }
private void initHttpBootstrap(int myport) { logger.info("initHttpBootstrap..........."); final ServerConfig serverConfig = new ServerConfig(myport); final ChannelGroup channelGroup = new DefaultChannelGroup(getClass().getName()); bootstrap = new ServerBootstrap(new NioServerSocketChannelFactory( //建议用ThreadPoolExecutor代替 Executors.newCachedThreadPool(), Executors.newCachedThreadPool(), serverConfig.getThreadCnt())); //设置常见参数 bootstrap.setOption("tcpNoDelay","true");//禁用nagle算法 bootstrap.setOption("reuseAddress", "true"); bootstrap.setOption("SO_RCVBUF",1024*128); bootstrap.setOption("SO_SNDBUF",1024*128); timer = new HashedWheelTimer(); bootstrap.setPipelineFactory(new ChannelPipelineFactory() { public ChannelPipeline getPipeline() throws Exception { ChannelPipeline pipeline = Channels.pipeline(); int readTimeout = serverConfig.getReadTimeout(); if (readTimeout > 0) { pipeline.addLast("timeout", new ReadTimeoutHandler(timer, readTimeout, TimeUnit.MILLISECONDS)); } pipeline.addLast("decoder", new RpcRequestDecode()); pipeline.addLast("encoder", new RpcResponseEncode()); pipeline.addLast("handler", new NettyRpcServerHandler(channelGroup)); return pipeline; } }); int port = serverConfig.getPort(); if (!checkPortConfig(port)) { throw new IllegalStateException("port: " + port + " already in use!"); } Channel channel = bootstrap.bind(new InetSocketAddress(port)); channelGroup.add(channel); logger.info("voyage server started"); waitForShutdownCommand(); ChannelGroupFuture future = channelGroup.close(); future.awaitUninterruptibly(); bootstrap.releaseExternalResources(); timer.stop(); timer = null; logger.info("voyage server stoped"); }
public ChannelGroup getChannelGroup() { return allChannels; }
public RequestHandlerV2(ChannelGroup group) { this.group = group; }
public HttpServerPipelineFactory(ChannelGroup group) { this.group = group; }
public ChannelGroup getChannelGroup() { return channelGroup; }
public void setChannelGroup(ChannelGroup channelGroup) { this.channelGroup = channelGroup; }
public NaviTCPHandler(ChannelGroup channelGroup) { // super(timer, channelIdleSecond, channelIdleSecond, channelIdleSecond); this.channelGroup = channelGroup; // session计数 SessionIdCounter.getInstance().incAndGet(); }
public NaviNettyHttpHandler(ChannelGroup channelGroup) { super(channelGroup); listeners = new ArrayList<>(); }
public AbstractNaviNettyHttpHandler(ChannelGroup channelGroup) { super(channelGroup); }