341463230b96296bb0f42440ef05204808841123
[openflowplugin.git] / openflow_netty / src / main / java / org / opendaylight / controller / protocol_plugin / openflow / core / internal / OpenflowPipelineFactory.java
1 package org.opendaylight.controller.protocol_plugin.openflow.core.internal;
2
3 import java.util.concurrent.ThreadPoolExecutor;
4
5 import org.jboss.netty.channel.ChannelPipeline;
6 import org.jboss.netty.channel.ChannelPipelineFactory;
7 import org.jboss.netty.channel.Channels;
8 import org.jboss.netty.handler.execution.ExecutionHandler;
9 import org.jboss.netty.handler.timeout.IdleStateHandler;
10 import org.jboss.netty.handler.timeout.ReadTimeoutHandler;
11 import org.jboss.netty.util.HashedWheelTimer;
12 import org.jboss.netty.util.Timer;
13
14 /**
15  * Creates a ChannelPipeline for a server-side openflow channel
16  * @author readams
17  */
18 public class OpenflowPipelineFactory implements ChannelPipelineFactory {
19
20     private static final int READ_TIMEOUT = 30;
21     private static final int READER_IDLE_TIMEOUT = 20;
22     private static final int WRITER_IDLE_TIMEOUT = 25;
23     private static final int ALL_IDLE_TIMEOUT = 0;
24
25     protected EnhancedController controller;
26     protected ThreadPoolExecutor pipelineExecutor;
27     protected Timer timer;
28     protected IdleStateHandler idleHandler;
29     protected ReadTimeoutHandler readTimeoutHandler;
30
31     public OpenflowPipelineFactory(EnhancedController controller,
32                                    ThreadPoolExecutor pipelineExecutor) {
33         super();
34         this.controller = controller;
35         this.pipelineExecutor = pipelineExecutor;
36         this.timer = new HashedWheelTimer();
37         this.idleHandler = new IdleStateHandler(timer, READER_IDLE_TIMEOUT, WRITER_IDLE_TIMEOUT, ALL_IDLE_TIMEOUT);
38         this.readTimeoutHandler = new ReadTimeoutHandler(timer, READ_TIMEOUT);
39     }
40
41     @Override
42     public ChannelPipeline getPipeline() throws Exception {
43         //OFChannelState state = new OFChannelState();
44
45
46         ChannelPipeline pipeline = Channels.pipeline();
47
48         /*
49         if (pipelineExecutor != null)
50             pipeline.addLast("pipelineExecutor",
51                              new ExecutionHandler(pipelineExecutor));*/
52         pipeline.addLast("ofmessagedecoder", new OFMessageDecoder());
53         pipeline.addLast("ofmessageencoder", new OFMessageEncoder());
54         pipeline.addLast("idle", idleHandler);
55         //pipeline.addLast("timeout", readTimeoutHandler);
56         //pipeline.addLast("handshaketimeout",
57         //                 new HandshakeTimeoutHandler(state, timer, 15));
58
59         /*
60         if (pipelineExecutor != null)
61             pipeline.addLast("pipelineExecutor",
62                              new ExecutionHandler(pipelineExecutor));*/
63         pipeline.addLast("handler", controller.getChannelHandler());
64         return pipeline;
65     }
66 }