Thomas Vachuska | 781d18b | 2014-10-27 10:31:25 -0700 | [diff] [blame] | 1 | /* |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame^] | 2 | * Copyright 2014 Open Networking Laboratory |
Thomas Vachuska | 781d18b | 2014-10-27 10:31:25 -0700 | [diff] [blame] | 3 | * |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame^] | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
Thomas Vachuska | 781d18b | 2014-10-27 10:31:25 -0700 | [diff] [blame] | 7 | * |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame^] | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
Thomas Vachuska | 781d18b | 2014-10-27 10:31:25 -0700 | [diff] [blame] | 15 | */ |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 16 | |
tom | 9c94c5b | 2014-09-17 13:14:42 -0700 | [diff] [blame] | 17 | package org.onlab.onos.openflow.controller.impl; |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 18 | |
| 19 | import java.util.concurrent.ThreadPoolExecutor; |
| 20 | |
| 21 | import org.jboss.netty.channel.ChannelPipeline; |
| 22 | import org.jboss.netty.channel.ChannelPipelineFactory; |
| 23 | import org.jboss.netty.channel.Channels; |
| 24 | import org.jboss.netty.handler.execution.ExecutionHandler; |
| 25 | import org.jboss.netty.handler.timeout.IdleStateHandler; |
| 26 | import org.jboss.netty.handler.timeout.ReadTimeoutHandler; |
| 27 | import org.jboss.netty.util.ExternalResourceReleasable; |
| 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. |
| 33 | */ |
| 34 | public class OpenflowPipelineFactory |
| 35 | implements ChannelPipelineFactory, ExternalResourceReleasable { |
| 36 | |
| 37 | protected Controller controller; |
| 38 | protected ThreadPoolExecutor pipelineExecutor; |
| 39 | protected Timer timer; |
| 40 | protected IdleStateHandler idleHandler; |
| 41 | protected ReadTimeoutHandler readTimeoutHandler; |
| 42 | |
| 43 | public OpenflowPipelineFactory(Controller controller, |
| 44 | ThreadPoolExecutor pipelineExecutor) { |
| 45 | super(); |
| 46 | this.controller = controller; |
| 47 | this.pipelineExecutor = pipelineExecutor; |
| 48 | this.timer = new HashedWheelTimer(); |
| 49 | this.idleHandler = new IdleStateHandler(timer, 20, 25, 0); |
| 50 | this.readTimeoutHandler = new ReadTimeoutHandler(timer, 30); |
| 51 | } |
| 52 | |
| 53 | @Override |
| 54 | public ChannelPipeline getPipeline() throws Exception { |
| 55 | OFChannelHandler handler = new OFChannelHandler(controller); |
| 56 | |
| 57 | ChannelPipeline pipeline = Channels.pipeline(); |
| 58 | pipeline.addLast("ofmessagedecoder", new OFMessageDecoder()); |
| 59 | pipeline.addLast("ofmessageencoder", new OFMessageEncoder()); |
| 60 | pipeline.addLast("idle", idleHandler); |
| 61 | pipeline.addLast("timeout", readTimeoutHandler); |
| 62 | // XXX S ONOS: was 15 increased it to fix Issue #296 |
| 63 | pipeline.addLast("handshaketimeout", |
| 64 | new HandshakeTimeoutHandler(handler, timer, 60)); |
| 65 | if (pipelineExecutor != null) { |
| 66 | pipeline.addLast("pipelineExecutor", |
| 67 | new ExecutionHandler(pipelineExecutor)); |
| 68 | } |
| 69 | pipeline.addLast("handler", handler); |
| 70 | return pipeline; |
| 71 | } |
| 72 | |
| 73 | @Override |
| 74 | public void releaseExternalResources() { |
| 75 | timer.stop(); |
| 76 | } |
| 77 | } |