2 * Copyright 2015 Open Networking Laboratory
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package org.onosproject.bgp.controller.impl;
19 import org.jboss.netty.channel.ChannelPipeline;
20 import org.jboss.netty.channel.ChannelPipelineFactory;
21 import org.jboss.netty.channel.Channels;
22 import org.jboss.netty.handler.timeout.ReadTimeoutHandler;
23 import org.jboss.netty.util.ExternalResourceReleasable;
24 import org.jboss.netty.util.HashedWheelTimer;
25 import org.jboss.netty.util.Timer;
26 import org.onosproject.bgp.controller.BgpController;
29 * Creates a ChannelPipeline for a server-side bgp channel.
31 public class BgpPipelineFactory
32 implements ChannelPipelineFactory, ExternalResourceReleasable {
34 static final Timer TIMER = new HashedWheelTimer();
35 protected ReadTimeoutHandler readTimeoutHandler;
36 private boolean isBgpServ;
37 private BgpController bgpController;
40 * Constructor to initialize the values.
42 * @param bgpController parent controller
43 * @param isBgpServ if it is a server or remote peer
45 public BgpPipelineFactory(BgpController bgpController, boolean isBgpServ) {
47 this.isBgpServ = isBgpServ;
48 this.bgpController = bgpController;
50 this.readTimeoutHandler = new ReadTimeoutHandler(TIMER, bgpController.getConfig().getHoldTime());
54 public ChannelPipeline getPipeline() throws Exception {
55 BgpChannelHandler handler = new BgpChannelHandler(bgpController);
57 ChannelPipeline pipeline = Channels.pipeline();
58 pipeline.addLast("bgpmessagedecoder", new BgpMessageDecoder());
59 pipeline.addLast("bgpmessageencoder", new BgpMessageEncoder());
60 pipeline.addLast("holdTime", readTimeoutHandler);
62 pipeline.addLast("PassiveHandler", handler);
64 pipeline.addLast("ActiveHandler", handler);
71 public void releaseExternalResources() {