blob: 1c5e994dc65d8a218706316fba09c31d99d82cb5 [file] [log] [blame]
Jian Lie4f12162016-09-13 00:09:09 +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 */
Jian Li5e505c62016-12-05 02:44:24 +090016package org.onosproject.lisp.ctl.impl;
Jian Lie4f12162016-09-13 00:09:09 +090017
18import io.netty.buffer.ByteBuf;
19import io.netty.channel.ChannelHandlerContext;
Jian Li6322a362016-10-31 00:57:19 +090020import io.netty.channel.socket.DatagramPacket;
21import io.netty.handler.codec.MessageToMessageDecoder;
Jian Lie4f12162016-09-13 00:09:09 +090022import org.onosproject.lisp.msg.protocols.LispMessage;
23import org.onosproject.lisp.msg.protocols.LispMessageReader;
24import org.onosproject.lisp.msg.protocols.LispMessageReaderFactory;
25
26import java.util.List;
27
28/**
29 * Decode a LISP message from a ByteBuffer, for use in a netty pipeline.
30 */
Jian Li6322a362016-10-31 00:57:19 +090031public class LispMessageDecoder extends MessageToMessageDecoder<DatagramPacket> {
Jian Lie4f12162016-09-13 00:09:09 +090032
33 @Override
Jian Li6322a362016-10-31 00:57:19 +090034 protected void decode(ChannelHandlerContext ctx, DatagramPacket msg,
Jian Lie4f12162016-09-13 00:09:09 +090035 List<Object> list) throws Exception {
Jian Li6322a362016-10-31 00:57:19 +090036 ByteBuf byteBuf = msg.content();
Jian Lie4f12162016-09-13 00:09:09 +090037 LispMessageReader reader = LispMessageReaderFactory.getReader(byteBuf);
38 LispMessage message = (LispMessage) reader.readFrom(byteBuf);
Jian Liafe2d3f2016-11-01 02:49:07 +090039 message.configSender(msg.sender());
Jian Lie4f12162016-09-13 00:09:09 +090040 list.add(message);
41 }
42}