我们知道,在Netty架构,一个ServerBootstrap用于生成server端的Channel的时候都须要提供一个ChannelPipelineFactory类型的參数,用于服务于建立连接的Channel,流水线处理来自某个client的请求。所以这里的 OpenflowPipelineFactory
就是Floodlight 为建立连接的openflow交换机创建ChannelPipeline。
1. IdleStateHandler 当Channel上没有运行对应的读写操作一定时间的时候出发一个 IdleStateEvent 事件;
2. ReadTimeoutHandler 读超时处理;
3. HandshakeTimeoutHandler 设置一个定时器检查连接的状态,握手阶段 。
4 . OFChannelHandler 核心,处理全部的业务。
代码例如以下:
public class OpenflowPipelineFactory implements ChannelPipelineFactory
{
protected Controller controller ;
protected ThreadPoolExecutor pipelineExecutor ;
protected Timer timer;
protected IdleStateHandler idleHandler ;
protected ReadTimeoutHandler readTimeoutHandler ;
public OpenflowPipelineFactory(Controller
controller,
ThreadPoolExecutor pipelineExecutor) {
super ();
this .controller =
controller;
this .pipelineExecutor =
pipelineExecutor;
this .timer = new HashedWheelTimer();
this .idleHandler = new IdleStateHandler( timer,
20, 25, 0);
this .readTimeoutHandler = new ReadTimeoutHandler(timer ,
30);
}
@Override
public ChannelPipeline
getPipeline() throws Exception {
OFChannelState state = new OFChannelState();
ChannelPipeline pipeline = Channels. pipeline();
pipeline.addLast( "ofmessagedecoder" , new OFMessageDecoder());
pipeline.addLast( "ofmessageencoder" , new OFMessageEncoder());
pipeline.addLast( "idle" , idleHandler );
pipeline.addLast( "timeout" , readTimeoutHandler );
pipeline.addLast( "handshaketimeout" ,
new HandshakeTimeoutHandler(state, timer ,
15));
if (pipelineExecutor != null)
pipeline.addLast( "pipelineExecutor" ,
new ExecutionHandler(pipelineExecutor ));
//OFChannelHandler 是核心
pipeline.addLast( "handler" , controller .getChannelHandler(state));
return pipeline;
}
}
版权声明:本文博客原创文章,博客,未经同意,不得转载。