Dhruv Dhody | 4d8943a | 2016-02-17 16:36:08 +0530 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame^] | 2 | * Copyright 2016-present Open Networking Laboratory |
Dhruv Dhody | 4d8943a | 2016-02-17 16:36:08 +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 | package org.onosproject.ospf.controller.impl; |
| 17 | |
| 18 | import org.jboss.netty.channel.ChannelPipeline; |
| 19 | import org.jboss.netty.channel.ChannelPipelineFactory; |
| 20 | import org.jboss.netty.channel.Channels; |
| 21 | import org.jboss.netty.handler.timeout.ReadTimeoutHandler; |
| 22 | import org.jboss.netty.util.ExternalResourceReleasable; |
| 23 | import org.jboss.netty.util.HashedWheelTimer; |
| 24 | import org.jboss.netty.util.Timer; |
| 25 | import org.onosproject.ospf.controller.OspfArea; |
| 26 | import org.onosproject.ospf.controller.OspfInterface; |
| 27 | |
| 28 | /** |
| 29 | * Creates a ChannelPipeline for a server-side OSPF channel. |
| 30 | */ |
| 31 | public 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 | } |