blob: 28e1041cd08c10fc010de482d121ff0cf07d5f1a [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;
Shashikanth VH5dd8dbe2015-11-26 13:22:18 +053026import org.onosproject.bgp.controller.BgpController;
Satish Ke107e662015-09-21 19:00:17 +053027
28/**
29 * Creates a ChannelPipeline for a server-side bgp channel.
30 */
Shashikanth VH5dd8dbe2015-11-26 13:22:18 +053031public class BgpPipelineFactory
Satish Ke107e662015-09-21 19:00:17 +053032 implements ChannelPipelineFactory, ExternalResourceReleasable {
33
34 static final Timer TIMER = new HashedWheelTimer();
35 protected ReadTimeoutHandler readTimeoutHandler;
Shashikanth VH9f8afb42015-11-04 18:00:30 +053036 private boolean isBgpServ;
Shashikanth VH5dd8dbe2015-11-26 13:22:18 +053037 private BgpController bgpController;
Satish Ke107e662015-09-21 19:00:17 +053038
39 /**
40 * Constructor to initialize the values.
41 *
Shashikanth VH9f8afb42015-11-04 18:00:30 +053042 * @param bgpController parent controller
43 * @param isBgpServ if it is a server or remote peer
Satish Ke107e662015-09-21 19:00:17 +053044 */
Shashikanth VH5dd8dbe2015-11-26 13:22:18 +053045 public BgpPipelineFactory(BgpController bgpController, boolean isBgpServ) {
Satish Ke107e662015-09-21 19:00:17 +053046 super();
Shashikanth VH9f8afb42015-11-04 18:00:30 +053047 this.isBgpServ = isBgpServ;
48 this.bgpController = bgpController;
49 /* hold time */
50 this.readTimeoutHandler = new ReadTimeoutHandler(TIMER, bgpController.getConfig().getHoldTime());
Satish Ke107e662015-09-21 19:00:17 +053051 }
52
53 @Override
54 public ChannelPipeline getPipeline() throws Exception {
Shashikanth VH5dd8dbe2015-11-26 13:22:18 +053055 BgpChannelHandler handler = new BgpChannelHandler(bgpController);
Satish Ke107e662015-09-21 19:00:17 +053056
57 ChannelPipeline pipeline = Channels.pipeline();
Shashikanth VH5dd8dbe2015-11-26 13:22:18 +053058 pipeline.addLast("bgpmessagedecoder", new BgpMessageDecoder());
59 pipeline.addLast("bgpmessageencoder", new BgpMessageEncoder());
Satish Ke107e662015-09-21 19:00:17 +053060 pipeline.addLast("holdTime", readTimeoutHandler);
Shashikanth VH9f8afb42015-11-04 18:00:30 +053061 if (isBgpServ) {
62 pipeline.addLast("PassiveHandler", handler);
63 } else {
64 pipeline.addLast("ActiveHandler", handler);
65 }
Satish Ke107e662015-09-21 19:00:17 +053066
67 return pipeline;
68 }
69
70 @Override
71 public void releaseExternalResources() {
72 TIMER.stop();
73 }
74}