f32b87a8ce350422de75f5567e939acc9e66b3e8
[onosfw.git] /
1 /*
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
17 package org.onosproject.pcep.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.IdleStateHandler;
23 import org.jboss.netty.handler.timeout.ReadTimeoutHandler;
24 import org.jboss.netty.util.ExternalResourceReleasable;
25 import org.jboss.netty.util.HashedWheelTimer;
26 import org.jboss.netty.util.Timer;
27
28 /**
29  * Creates a ChannelPipeline for a server-side pcep channel.
30  */
31 public class PcepPipelineFactory
32     implements ChannelPipelineFactory, ExternalResourceReleasable {
33
34     protected Controller controller;
35     static final Timer TIMER = new HashedWheelTimer();
36     protected IdleStateHandler idleHandler;
37     protected ReadTimeoutHandler readTimeoutHandler;
38     static final int DEFAULT_KEEP_ALIVE_TIME = 30;
39     static final int DEFAULT_DEAD_TIME = 120;
40     static final int DEFAULT_WAIT_TIME = 60;
41
42     public PcepPipelineFactory(Controller controller) {
43         super();
44         this.controller = controller;
45         this.idleHandler = new IdleStateHandler(TIMER, DEFAULT_DEAD_TIME, DEFAULT_KEEP_ALIVE_TIME, 0);
46         this.readTimeoutHandler = new ReadTimeoutHandler(TIMER, DEFAULT_WAIT_TIME);
47     }
48
49     @Override
50     public ChannelPipeline getPipeline() throws Exception {
51         PcepChannelHandler handler = new PcepChannelHandler(controller);
52
53         ChannelPipeline pipeline = Channels.pipeline();
54         pipeline.addLast("pcepmessagedecoder", new PcepMessageDecoder());
55         pipeline.addLast("pcepmessageencoder", new PcepMessageEncoder());
56         pipeline.addLast("idle", idleHandler);
57         pipeline.addLast("waittimeout", readTimeoutHandler);
58         pipeline.addLast("handler", handler);
59         return pipeline;
60     }
61
62     @Override
63     public void releaseExternalResources() {
64         TIMER.stop();
65     }
66 }