Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 1 | /** |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -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; |
| 28 | import org.jboss.netty.util.HashedWheelTimer; |
| 29 | import org.jboss.netty.util.Timer; |
| 30 | |
| 31 | /** |
| 32 | * Creates a ChannelPipeline for a server-side openflow channel |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame^] | 33 | * |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 34 | * @author readams |
| 35 | */ |
| 36 | public class OpenflowPipelineFactory implements ChannelPipelineFactory { |
| 37 | |
| 38 | protected Controller controller; |
| 39 | protected ThreadPoolExecutor pipelineExecutor; |
| 40 | protected Timer timer; |
| 41 | protected IdleStateHandler idleHandler; |
| 42 | protected ReadTimeoutHandler readTimeoutHandler; |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame^] | 43 | |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 44 | public OpenflowPipelineFactory(Controller controller, |
| 45 | ThreadPoolExecutor pipelineExecutor) { |
| 46 | super(); |
| 47 | this.controller = controller; |
| 48 | this.pipelineExecutor = pipelineExecutor; |
| 49 | this.timer = new HashedWheelTimer(); |
| 50 | this.idleHandler = new IdleStateHandler(timer, 20, 25, 0); |
| 51 | this.readTimeoutHandler = new ReadTimeoutHandler(timer, 30); |
| 52 | } |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame^] | 53 | |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 54 | @Override |
| 55 | public ChannelPipeline getPipeline() throws Exception { |
| 56 | OFChannelState state = new OFChannelState(); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame^] | 57 | |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 58 | ChannelPipeline pipeline = Channels.pipeline(); |
| 59 | pipeline.addLast("ofmessagedecoder", new OFMessageDecoder()); |
| 60 | pipeline.addLast("ofmessageencoder", new OFMessageEncoder()); |
| 61 | pipeline.addLast("idle", idleHandler); |
| 62 | pipeline.addLast("timeout", readTimeoutHandler); |
| 63 | pipeline.addLast("handshaketimeout", |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame^] | 64 | new HandshakeTimeoutHandler(state, timer, 60)); // ONOS: was 15 increased it to fix Issue #296 |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 65 | if (pipelineExecutor != null) |
| 66 | pipeline.addLast("pipelineExecutor", |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame^] | 67 | new ExecutionHandler(pipelineExecutor)); |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 68 | pipeline.addLast("handler", controller.getChannelHandler(state)); |
| 69 | return pipeline; |
| 70 | } |
| 71 | |
| 72 | } |