blob: c7ba105c229b7dd05fe90da53552a5b47c0980f4 [file] [log] [blame]
Thomas Vachuska781d18b2014-10-27 10:31:25 -07001/*
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07002 * Copyright 2014 Open Networking Laboratory
Thomas Vachuska781d18b2014-10-27 10:31:25 -07003 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07004 * 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 Vachuska781d18b2014-10-27 10:31:25 -07007 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07008 * 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 Vachuska781d18b2014-10-27 10:31:25 -070015 */
tom7ef8ff92014-09-17 13:08:06 -070016
Brian O'Connorabafb502014-12-02 22:26:20 -080017package org.onosproject.openflow.controller.impl;
tom7ef8ff92014-09-17 13:08:06 -070018
19import java.util.concurrent.ThreadPoolExecutor;
20
21import org.jboss.netty.channel.ChannelPipeline;
22import org.jboss.netty.channel.ChannelPipelineFactory;
23import org.jboss.netty.channel.Channels;
24import org.jboss.netty.handler.execution.ExecutionHandler;
25import org.jboss.netty.handler.timeout.IdleStateHandler;
26import org.jboss.netty.handler.timeout.ReadTimeoutHandler;
27import org.jboss.netty.util.ExternalResourceReleasable;
28import org.jboss.netty.util.HashedWheelTimer;
29import org.jboss.netty.util.Timer;
30
31/**
32 * Creates a ChannelPipeline for a server-side openflow channel.
33 */
34public 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}