blob: 394f783a0663f72c14bb44949eca49b0ef2600bc [file] [log] [blame]
Dhruv Dhody4d8943a2016-02-17 16:36:08 +05301/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2016-present Open Networking Laboratory
Dhruv Dhody4d8943a2016-02-17 16:36:08 +05303 *
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
7 *
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.
15 */
16package org.onosproject.ospf.controller.impl;
17
18import org.jboss.netty.channel.ChannelPipeline;
19import org.jboss.netty.channel.ChannelPipelineFactory;
20import org.jboss.netty.channel.Channels;
21import org.jboss.netty.handler.timeout.ReadTimeoutHandler;
22import org.jboss.netty.util.ExternalResourceReleasable;
23import org.jboss.netty.util.HashedWheelTimer;
24import org.jboss.netty.util.Timer;
25import org.onosproject.ospf.controller.OspfArea;
26import org.onosproject.ospf.controller.OspfInterface;
27
28/**
29 * Creates a ChannelPipeline for a server-side OSPF channel.
30 */
31public class OspfPipelineFactory implements ChannelPipelineFactory, ExternalResourceReleasable {
32
33 private static final Timer TIMER = new HashedWheelTimer();
34 private Controller controller;
35 private ReadTimeoutHandler readTimeoutHandler;
36 private OspfArea ospfArea;
37 private OspfInterface ospfInterface;
38 private int holdTime = 120 * 1000;
39
40 /**
41 * Creates an instance of OSPF pipeline factory.
42 *
43 * @param controller controller instance.
44 * @param ospfArea OSPF area instance.
45 * @param ospfInterface OSPF interface instance.
46 */
47 public OspfPipelineFactory(Controller controller, OspfArea ospfArea, OspfInterface ospfInterface) {
48 super();
49 this.controller = controller;
50 this.ospfArea = ospfArea;
51 this.ospfInterface = ospfInterface;
52 readTimeoutHandler = new ReadTimeoutHandler(TIMER, holdTime);
53 }
54
55 @Override
56 public ChannelPipeline getPipeline() throws Exception {
57 OspfInterfaceChannelHandler interfaceHandler = new OspfInterfaceChannelHandler(
58 controller, ospfArea, ospfInterface);
59
60 ChannelPipeline pipeline = Channels.pipeline();
61 pipeline.addLast("encoder", new OspfMessageEncoder(ospfInterface));
62 pipeline.addLast("decoder", new OspfMessageDecoder());
63 pipeline.addLast("holdTime", readTimeoutHandler);
64 pipeline.addLast("interfacehandler", interfaceHandler);
65
66 return pipeline;
67 }
68
69 @Override
70 public void releaseExternalResources() {
71 TIMER.stop();
72 }
73
74}