blob: e0b7ab64d049f527fa7aeb0e5d510950df1a7ef9 [file] [log] [blame]
Jian Li451cea32016-10-04 15:27:50 +09001/*
2 * Copyright 2016-present 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 */
16package org.onosproject.lisp.ctl;
17
18import io.netty.channel.Channel;
19import io.netty.channel.ChannelInitializer;
20import io.netty.channel.ChannelPipeline;
21import io.netty.handler.timeout.IdleStateHandler;
22import io.netty.handler.timeout.ReadTimeoutHandler;
23import org.slf4j.Logger;
24import org.slf4j.LoggerFactory;
25
26/**
27 * Creates a ChannelInitializer for a server-side LISP channel.
28 */
29public final class LispChannelInitializer extends ChannelInitializer<Channel> {
30
31 private final Logger log = LoggerFactory.getLogger(getClass());
32
33 private IdleStateHandler idleHandler;
34 private ReadTimeoutHandler readTimeoutHandler;
35
36 private static final int READER_IDLE_TIME_SECOND = 20;
37 private static final int WRITER_IDLE_TIME_SECOND = 25;
38 private static final int ALL_IDLE_TIME_SECOND = 0;
39 private static final int READ_TIMEOUT_SECOND = 30;
40
41 @Override
42 protected void initChannel(Channel channel) throws Exception {
43 ChannelPipeline pipeline = channel.pipeline();
44
45 LispChannelHandler handler = new LispChannelHandler();
46
47 idleHandler = new IdleStateHandler(READER_IDLE_TIME_SECOND,
48 WRITER_IDLE_TIME_SECOND, ALL_IDLE_TIME_SECOND);
49 readTimeoutHandler = new ReadTimeoutHandler(READ_TIMEOUT_SECOND);
50
51 pipeline.addLast("lispmessagedecoder", new LispMessageDecoder());
52 pipeline.addLast("lispmessageencoder", new LispMessageEncoder());
53 pipeline.addLast("idle", idleHandler);
54 pipeline.addLast("readTimeout", readTimeoutHandler);
55 pipeline.addLast("handler", handler);
56 }
57}