Floodlight 中 ChannelPipeline 结构图

我们知道在Netty架构中,当创建一个ServerBootstrap用于生成服务器端的Channel的时候都需要提供一个ChannelPipelineFactory类型的参数,用于服务于建立连接的Channel,流水线处理来自某个客户端的请求。所以这里的 OpenflowPipelineFactory 就是Floodlight 为建立连接的openflow交换机创建ChannelPipeline。


Floodlight 中 ChannelPipeline 结构图_第1张图片

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;
    }
}




你可能感兴趣的:(ChannelPipeline,ServerBootstrap)