blob: d3ef1e7fb6fd49345cb0c6c9ec231192cf9b0e01 [file] [log] [blame]
Thomas Vachuska781d18b2014-10-27 10:31:25 -07001/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
tom7ef8ff92014-09-17 13:08:06 -070019
tom9c94c5b2014-09-17 13:14:42 -070020package org.onlab.onos.openflow.controller.impl;
tom7ef8ff92014-09-17 13:08:06 -070021
22import java.util.concurrent.ThreadPoolExecutor;
23
24import org.jboss.netty.channel.ChannelPipeline;
25import org.jboss.netty.channel.ChannelPipelineFactory;
26import org.jboss.netty.channel.Channels;
27import org.jboss.netty.handler.execution.ExecutionHandler;
28import org.jboss.netty.handler.timeout.IdleStateHandler;
29import org.jboss.netty.handler.timeout.ReadTimeoutHandler;
30import org.jboss.netty.util.ExternalResourceReleasable;
31import org.jboss.netty.util.HashedWheelTimer;
32import org.jboss.netty.util.Timer;
33
34/**
35 * Creates a ChannelPipeline for a server-side openflow channel.
36 */
37public class OpenflowPipelineFactory
38 implements ChannelPipelineFactory, ExternalResourceReleasable {
39
40 protected Controller controller;
41 protected ThreadPoolExecutor pipelineExecutor;
42 protected Timer timer;
43 protected IdleStateHandler idleHandler;
44 protected ReadTimeoutHandler readTimeoutHandler;
45
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 }
55
56 @Override
57 public ChannelPipeline getPipeline() throws Exception {
58 OFChannelHandler handler = new OFChannelHandler(controller);
59
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 // XXX S ONOS: was 15 increased it to fix Issue #296
66 pipeline.addLast("handshaketimeout",
67 new HandshakeTimeoutHandler(handler, timer, 60));
68 if (pipelineExecutor != null) {
69 pipeline.addLast("pipelineExecutor",
70 new ExecutionHandler(pipelineExecutor));
71 }
72 pipeline.addLast("handler", handler);
73 return pipeline;
74 }
75
76 @Override
77 public void releaseExternalResources() {
78 timer.stop();
79 }
80}