Jian Li | e4f1216 | 2016-09-13 00:09:09 +0900 | [diff] [blame] | 1 | /* |
| 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 Li | 5e505c6 | 2016-12-05 02:44:24 +0900 | [diff] [blame] | 16 | package org.onosproject.lisp.ctl.impl; |
Jian Li | e4f1216 | 2016-09-13 00:09:09 +0900 | [diff] [blame] | 17 | |
| 18 | import io.netty.buffer.ByteBuf; |
| 19 | import io.netty.channel.ChannelHandlerContext; |
Jian Li | 6322a36 | 2016-10-31 00:57:19 +0900 | [diff] [blame] | 20 | import io.netty.channel.socket.DatagramPacket; |
| 21 | import io.netty.handler.codec.MessageToMessageDecoder; |
Jian Li | e4f1216 | 2016-09-13 00:09:09 +0900 | [diff] [blame] | 22 | import org.onosproject.lisp.msg.protocols.LispMessage; |
| 23 | import org.onosproject.lisp.msg.protocols.LispMessageReader; |
| 24 | import org.onosproject.lisp.msg.protocols.LispMessageReaderFactory; |
| 25 | |
| 26 | import java.util.List; |
| 27 | |
| 28 | /** |
| 29 | * Decode a LISP message from a ByteBuffer, for use in a netty pipeline. |
| 30 | */ |
Jian Li | 6322a36 | 2016-10-31 00:57:19 +0900 | [diff] [blame] | 31 | public class LispMessageDecoder extends MessageToMessageDecoder<DatagramPacket> { |
Jian Li | e4f1216 | 2016-09-13 00:09:09 +0900 | [diff] [blame] | 32 | |
| 33 | @Override |
Jian Li | 6322a36 | 2016-10-31 00:57:19 +0900 | [diff] [blame] | 34 | protected void decode(ChannelHandlerContext ctx, DatagramPacket msg, |
Jian Li | e4f1216 | 2016-09-13 00:09:09 +0900 | [diff] [blame] | 35 | List<Object> list) throws Exception { |
Jian Li | 6322a36 | 2016-10-31 00:57:19 +0900 | [diff] [blame] | 36 | ByteBuf byteBuf = msg.content(); |
Jian Li | e4f1216 | 2016-09-13 00:09:09 +0900 | [diff] [blame] | 37 | LispMessageReader reader = LispMessageReaderFactory.getReader(byteBuf); |
| 38 | LispMessage message = (LispMessage) reader.readFrom(byteBuf); |
Jian Li | afe2d3f | 2016-11-01 02:49:07 +0900 | [diff] [blame] | 39 | message.configSender(msg.sender()); |
Jian Li | e4f1216 | 2016-09-13 00:09:09 +0900 | [diff] [blame] | 40 | list.add(message); |
| 41 | } |
| 42 | } |