Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 1 | /** |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 2 | * 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 Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 17 | |
| 18 | package net.floodlightcontroller.core.internal; |
| 19 | |
| 20 | import java.util.concurrent.ThreadPoolExecutor; |
| 21 | |
| 22 | import org.jboss.netty.channel.ChannelPipeline; |
| 23 | import org.jboss.netty.channel.ChannelPipelineFactory; |
| 24 | import org.jboss.netty.channel.Channels; |
| 25 | import org.jboss.netty.handler.execution.ExecutionHandler; |
| 26 | import org.jboss.netty.handler.timeout.IdleStateHandler; |
| 27 | import org.jboss.netty.handler.timeout.ReadTimeoutHandler; |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 28 | import org.jboss.netty.util.ExternalResourceReleasable; |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 29 | import org.jboss.netty.util.HashedWheelTimer; |
| 30 | import org.jboss.netty.util.Timer; |
| 31 | |
| 32 | /** |
| 33 | * Creates a ChannelPipeline for a server-side openflow channel |
| 34 | * @author readams |
| 35 | */ |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 36 | public class OpenflowPipelineFactory |
| 37 | implements ChannelPipelineFactory, ExternalResourceReleasable { |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 38 | |
Saurav Das | 8539994 | 2014-09-02 16:11:48 -0700 | [diff] [blame] | 39 | private static final long HANDSHAKE_TIMEOUT_SECS = 10; |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 40 | protected Controller controller; |
| 41 | protected ThreadPoolExecutor pipelineExecutor; |
| 42 | protected Timer timer; |
| 43 | protected IdleStateHandler idleHandler; |
| 44 | protected ReadTimeoutHandler readTimeoutHandler; |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 45 | |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 46 | 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 Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 55 | |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 56 | @Override |
| 57 | public ChannelPipeline getPipeline() throws Exception { |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 58 | OFChannelHandler handler = new OFChannelHandler(controller); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 59 | |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 60 | 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 Das | 8539994 | 2014-09-02 16:11:48 -0700 | [diff] [blame] | 66 | new HandshakeTimeoutHandler(handler, timer, HANDSHAKE_TIMEOUT_SECS)); |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 67 | if (pipelineExecutor != null) |
| 68 | pipeline.addLast("pipelineExecutor", |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 69 | new ExecutionHandler(pipelineExecutor)); |
| 70 | pipeline.addLast("handler", handler); |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 71 | return pipeline; |
| 72 | } |
| 73 | |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 74 | @Override |
| 75 | public void releaseExternalResources() { |
| 76 | timer.stop(); |
| 77 | } |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 78 | } |