2 * Copyright (c) 2014 Pantheon Technologies s.r.o. and others. All rights reserved.
\r
4 * This program and the accompanying materials are made available under the
\r
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
\r
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
\r
9 package org.opendaylight.openflowjava.protocol.impl.core;
\r
11 import io.netty.channel.ChannelHandlerContext;
\r
12 import io.netty.channel.SimpleChannelInboundHandler;
\r
14 import org.opendaylight.openflowjava.protocol.impl.core.connection.MessageConsumer;
\r
15 import org.opendaylight.openflowjava.protocol.impl.deserialization.DeserializationFactory;
\r
16 import org.opendaylight.openflowjava.util.ByteBufUtils;
\r
17 import org.opendaylight.yangtools.yang.binding.DataObject;
\r
18 import org.slf4j.Logger;
\r
19 import org.slf4j.LoggerFactory;
\r
22 * @author michal.polkorab
\r
25 public class OFDatagramPacketDecoder extends SimpleChannelInboundHandler<VersionMessageUdpWrapper>{
\r
27 private static final Logger LOGGER = LoggerFactory.getLogger(OFDatagramPacketDecoder.class);
\r
28 private DeserializationFactory deserializationFactory;
\r
31 public void channelRead0(ChannelHandlerContext ctx, VersionMessageUdpWrapper msg)
\r
33 if (LOGGER.isDebugEnabled()) {
\r
34 LOGGER.debug("UdpVersionMessageWrapper received");
\r
35 LOGGER.debug("<< " + ByteBufUtils.byteBufToHexString(msg.getMessageBuffer()));
\r
37 DataObject dataObject = null;
\r
39 dataObject = deserializationFactory.deserialize(msg.getMessageBuffer(),msg.getVersion());
\r
40 if (dataObject == null) {
\r
41 LOGGER.warn("Translated POJO is null");
\r
43 MessageConsumer consumer = UdpConnectionMap.getMessageConsumer(msg.getAddress());
\r
44 consumer.consume(dataObject);
\r
46 } catch(Exception e) {
\r
47 LOGGER.warn("Message deserialization failed");
\r
48 LOGGER.warn(e.getMessage(), e);
\r
49 // TODO: delegate exception to allow easier deserialization
\r
50 // debugging / deserialization problem awareness
\r
52 msg.getMessageBuffer().release();
\r
57 * @param deserializationFactory
\r
59 public void setDeserializationFactory(DeserializationFactory deserializationFactory) {
\r
60 this.deserializationFactory = deserializationFactory;
\r