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