Satish K | e107e66 | 2015-09-21 19:00:17 +0530 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Laboratory |
Satish K | e107e66 | 2015-09-21 19:00:17 +0530 | [diff] [blame] | 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 | |
| 17 | package org.onosproject.bgp.controller.impl; |
| 18 | |
| 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; |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 26 | import org.onosproject.bgp.controller.BgpController; |
Satish K | e107e66 | 2015-09-21 19:00:17 +0530 | [diff] [blame] | 27 | |
| 28 | /** |
| 29 | * Creates a ChannelPipeline for a server-side bgp channel. |
| 30 | */ |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 31 | public class BgpPipelineFactory |
Satish K | e107e66 | 2015-09-21 19:00:17 +0530 | [diff] [blame] | 32 | implements ChannelPipelineFactory, ExternalResourceReleasable { |
| 33 | |
| 34 | static final Timer TIMER = new HashedWheelTimer(); |
| 35 | protected ReadTimeoutHandler readTimeoutHandler; |
Shashikanth VH | 9f8afb4 | 2015-11-04 18:00:30 +0530 | [diff] [blame] | 36 | private boolean isBgpServ; |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 37 | private BgpController bgpController; |
Satish K | e107e66 | 2015-09-21 19:00:17 +0530 | [diff] [blame] | 38 | |
| 39 | /** |
| 40 | * Constructor to initialize the values. |
| 41 | * |
Shashikanth VH | 9f8afb4 | 2015-11-04 18:00:30 +0530 | [diff] [blame] | 42 | * @param bgpController parent controller |
| 43 | * @param isBgpServ if it is a server or remote peer |
Satish K | e107e66 | 2015-09-21 19:00:17 +0530 | [diff] [blame] | 44 | */ |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 45 | public BgpPipelineFactory(BgpController bgpController, boolean isBgpServ) { |
Satish K | e107e66 | 2015-09-21 19:00:17 +0530 | [diff] [blame] | 46 | super(); |
Shashikanth VH | 9f8afb4 | 2015-11-04 18:00:30 +0530 | [diff] [blame] | 47 | this.isBgpServ = isBgpServ; |
| 48 | this.bgpController = bgpController; |
| 49 | /* hold time */ |
| 50 | this.readTimeoutHandler = new ReadTimeoutHandler(TIMER, bgpController.getConfig().getHoldTime()); |
Satish K | e107e66 | 2015-09-21 19:00:17 +0530 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | @Override |
| 54 | public ChannelPipeline getPipeline() throws Exception { |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 55 | BgpChannelHandler handler = new BgpChannelHandler(bgpController); |
Satish K | e107e66 | 2015-09-21 19:00:17 +0530 | [diff] [blame] | 56 | |
| 57 | ChannelPipeline pipeline = Channels.pipeline(); |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 58 | pipeline.addLast("bgpmessagedecoder", new BgpMessageDecoder()); |
| 59 | pipeline.addLast("bgpmessageencoder", new BgpMessageEncoder()); |
Satish K | e107e66 | 2015-09-21 19:00:17 +0530 | [diff] [blame] | 60 | pipeline.addLast("holdTime", readTimeoutHandler); |
Shashikanth VH | 9f8afb4 | 2015-11-04 18:00:30 +0530 | [diff] [blame] | 61 | if (isBgpServ) { |
| 62 | pipeline.addLast("PassiveHandler", handler); |
| 63 | } else { |
| 64 | pipeline.addLast("ActiveHandler", handler); |
| 65 | } |
Satish K | e107e66 | 2015-09-21 19:00:17 +0530 | [diff] [blame] | 66 | |
| 67 | return pipeline; |
| 68 | } |
| 69 | |
| 70 | @Override |
| 71 | public void releaseExternalResources() { |
| 72 | TIMER.stop(); |
| 73 | } |
| 74 | } |