blob: e93b0c9416bfa614cdbd1f8d8f7bb731221a30d4 [file] [log] [blame]
Hyunsun Moon90163ba2016-10-12 13:35:14 -07001/*
2 * Copyright 2017-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.ofagent.impl;
17
18import io.netty.channel.ChannelInitializer;
19import io.netty.channel.socket.SocketChannel;
Daniel Parkbe6b6732016-11-11 15:52:19 +090020import io.netty.handler.timeout.ReadTimeoutHandler;
Hyunsun Moon90163ba2016-10-12 13:35:14 -070021import org.onosproject.ofagent.api.OFSwitch;
22
23/**
24 * Implementation of OpenFlow channel initializer.
25 */
26public final class OFChannelInitializer extends ChannelInitializer<SocketChannel> {
27
28 private final OFSwitch ofSwitch;
Daniel Parkbe6b6732016-11-11 15:52:19 +090029 private static final int READ_TIMEOUT = 30;
Hyunsun Moon90163ba2016-10-12 13:35:14 -070030
31 /**
32 * Default constructor.
33 *
34 * @param ofSwitch openflow switch that owns this channel
35 */
36 public OFChannelInitializer(OFSwitch ofSwitch) {
37 this.ofSwitch = ofSwitch;
38 }
39
40 @Override
41 protected void initChannel(SocketChannel ch) throws Exception {
42
Daniel Parkbe6b6732016-11-11 15:52:19 +090043 ch.pipeline().addLast(new OFMessageDecoder())
44 .addLast(new OFMessageEncoder())
45 .addLast(new ReadTimeoutHandler(READ_TIMEOUT))
46 .addLast(new OFChannelHandler(ofSwitch));
Hyunsun Moon90163ba2016-10-12 13:35:14 -070047 }
48}