blob: b2ca50771acba960b19267809a113b7ef5e2a267 [file] [log] [blame]
Satish Ke107e662015-09-21 19:00:17 +05301/*
2 * Copyright 2015 Open Networking Laboratory
3 *
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 */
16
17package org.onosproject.bgp.controller.impl;
18
19import org.jboss.netty.channel.ChannelPipeline;
20import org.jboss.netty.channel.ChannelPipelineFactory;
21import org.jboss.netty.channel.Channels;
22import org.jboss.netty.handler.timeout.ReadTimeoutHandler;
23import org.jboss.netty.util.ExternalResourceReleasable;
24import org.jboss.netty.util.HashedWheelTimer;
25import org.jboss.netty.util.Timer;
26
27/**
28 * Creates a ChannelPipeline for a server-side bgp channel.
29 */
30public class BGPPipelineFactory
31 implements ChannelPipelineFactory, ExternalResourceReleasable {
32
33 static final Timer TIMER = new HashedWheelTimer();
34 protected ReadTimeoutHandler readTimeoutHandler;
35 BGPControllerImpl bgpCtrlImpl;
36
37 /**
38 * Constructor to initialize the values.
39 *
40 * @param ctrlImpl parent ctrlImpl
41 * @param isServBgp if it is a server or not
42 */
43 public BGPPipelineFactory(BGPControllerImpl ctrlImpl, boolean isServBgp) {
44 super();
45 bgpCtrlImpl = ctrlImpl;
46 /* hold time*/
47 readTimeoutHandler = new ReadTimeoutHandler(TIMER, bgpCtrlImpl.getConfig().getHoldTime());
48 }
49
50 @Override
51 public ChannelPipeline getPipeline() throws Exception {
52 BGPChannelHandler handler = new BGPChannelHandler(bgpCtrlImpl);
53
54 ChannelPipeline pipeline = Channels.pipeline();
55 pipeline.addLast("bgpmessagedecoder", new BGPMessageDecoder());
56 pipeline.addLast("bgpmessageencoder", new BGPMessageEncoder());
57 pipeline.addLast("holdTime", readTimeoutHandler);
58 pipeline.addLast("PassiveHandler", handler);
59
60 return pipeline;
61 }
62
63 @Override
64 public void releaseExternalResources() {
65 TIMER.stop();
66 }
67}