blob: c087a436061ad7397ac927714459c5fcbcc201bf [file] [log] [blame]
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -08001/**
Brian O'Connorc67f9fa2014-08-07 18:17:46 -07002* Copyright 2011, Big Switch Networks, Inc.
3* Originally created by David Erickson, Stanford University
4*
5* Licensed under the Apache License, Version 2.0 (the "License"); you may
6* not use this file except in compliance with the License. You may obtain
7* a copy of the License at
8*
9* http://www.apache.org/licenses/LICENSE-2.0
10*
11* Unless required by applicable law or agreed to in writing, software
12* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14* License for the specific language governing permissions and limitations
15* under the License.
16**/
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080017
18package net.floodlightcontroller.core.internal;
19
20import java.util.concurrent.ThreadPoolExecutor;
21
22import org.jboss.netty.channel.ChannelPipeline;
23import org.jboss.netty.channel.ChannelPipelineFactory;
24import org.jboss.netty.channel.Channels;
25import org.jboss.netty.handler.execution.ExecutionHandler;
26import org.jboss.netty.handler.timeout.IdleStateHandler;
27import org.jboss.netty.handler.timeout.ReadTimeoutHandler;
Brian O'Connorc67f9fa2014-08-07 18:17:46 -070028import org.jboss.netty.util.ExternalResourceReleasable;
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080029import org.jboss.netty.util.HashedWheelTimer;
30import org.jboss.netty.util.Timer;
31
32/**
33 * Creates a ChannelPipeline for a server-side openflow channel
34 * @author readams
35 */
Brian O'Connorc67f9fa2014-08-07 18:17:46 -070036public class OpenflowPipelineFactory
37 implements ChannelPipelineFactory, ExternalResourceReleasable {
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080038
Saurav Das85399942014-09-02 16:11:48 -070039 private static final long HANDSHAKE_TIMEOUT_SECS = 10;
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080040 protected Controller controller;
41 protected ThreadPoolExecutor pipelineExecutor;
42 protected Timer timer;
43 protected IdleStateHandler idleHandler;
44 protected ReadTimeoutHandler readTimeoutHandler;
Ray Milkey269ffb92014-04-03 14:43:30 -070045
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080046 public OpenflowPipelineFactory(Controller controller,
47 ThreadPoolExecutor pipelineExecutor) {
48 super();
49 this.controller = controller;
50 this.pipelineExecutor = pipelineExecutor;
51 this.timer = new HashedWheelTimer();
52 this.idleHandler = new IdleStateHandler(timer, 20, 25, 0);
53 this.readTimeoutHandler = new ReadTimeoutHandler(timer, 30);
54 }
Ray Milkey269ffb92014-04-03 14:43:30 -070055
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080056 @Override
57 public ChannelPipeline getPipeline() throws Exception {
Brian O'Connorc67f9fa2014-08-07 18:17:46 -070058 OFChannelHandler handler = new OFChannelHandler(controller);
Ray Milkey269ffb92014-04-03 14:43:30 -070059
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080060 ChannelPipeline pipeline = Channels.pipeline();
61 pipeline.addLast("ofmessagedecoder", new OFMessageDecoder());
62 pipeline.addLast("ofmessageencoder", new OFMessageEncoder());
63 pipeline.addLast("idle", idleHandler);
64 pipeline.addLast("timeout", readTimeoutHandler);
65 pipeline.addLast("handshaketimeout",
Saurav Das85399942014-09-02 16:11:48 -070066 new HandshakeTimeoutHandler(handler, timer, HANDSHAKE_TIMEOUT_SECS));
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080067 if (pipelineExecutor != null)
68 pipeline.addLast("pipelineExecutor",
Brian O'Connorc67f9fa2014-08-07 18:17:46 -070069 new ExecutionHandler(pipelineExecutor));
70 pipeline.addLast("handler", handler);
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080071 return pipeline;
72 }
73
Brian O'Connorc67f9fa2014-08-07 18:17:46 -070074 @Override
75 public void releaseExternalResources() {
76 timer.stop();
77 }
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080078}