blob: 39f2862de18ea37291fcc2366e7a67fede427863 [file] [log] [blame]
Satish Ke107e662015-09-21 19:00:17 +05301/*
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 */
16package org.onosproject.bgp.controller.impl;
17
18import java.util.LinkedList;
19import java.util.List;
20
21import org.jboss.netty.buffer.ChannelBuffer;
22import org.jboss.netty.channel.Channel;
23import org.jboss.netty.channel.ChannelHandlerContext;
24import org.jboss.netty.handler.codec.frame.FrameDecoder;
25import org.onosproject.bgpio.protocol.BGPMessage;
26import org.onlab.util.HexDump;
27import org.slf4j.Logger;
28import org.slf4j.LoggerFactory;
29
30/**
31 * Decode an bgp message from a Channel, for use in a netty pipeline.
32 */
33public class BGPMessageDecoder extends FrameDecoder {
34
35 protected static final Logger log = LoggerFactory.getLogger(BGPMessageDecoder.class);
36
37 @Override
38 protected Object decode(ChannelHandlerContext ctx, Channel channel, ChannelBuffer buffer) throws Exception {
39
40 List<BGPMessage> msgList = new LinkedList<BGPMessage>();
41
42 log.debug("MESSAGE IS RECEIVED.");
43 if (!channel.isConnected()) {
44 log.info("Channel is not connected.");
45 return null;
46 }
47
48 HexDump.dump(buffer);
49
50 // TODO: decode bgp messages
51 return msgList;
52 }
53}