2 * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.openflowjava.protocol.impl.core;
11 import io.netty.channel.ChannelHandlerContext;
12 import io.netty.handler.codec.MessageToMessageDecoder;
14 import java.util.List;
16 import org.opendaylight.openflowjava.protocol.impl.deserialization.DeserializationFactory;
17 import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils;
18 import org.opendaylight.yangtools.yang.binding.DataObject;
19 import org.slf4j.Logger;
20 import org.slf4j.LoggerFactory;
23 * Transforms OpenFlow Protocol messages to POJOs
24 * @author michal.polkorab
26 public class OFDecoder extends MessageToMessageDecoder<VersionMessageWrapper> {
28 private static final Logger LOGGER = LoggerFactory.getLogger(OFDecoder.class);
29 private DeserializationFactory deserializationFactory;
32 * Constructor of class
35 LOGGER.trace("Creating OF 1.3 Decoder");
39 protected void decode(ChannelHandlerContext ctx, VersionMessageWrapper msg,
40 List<Object> out) throws Exception {
41 if (LOGGER.isDebugEnabled()) {
42 LOGGER.debug("VersionMessageWrapper received");
43 LOGGER.debug("<< " + ByteBufUtils.byteBufToHexString(msg.getMessageBuffer()));
45 DataObject dataObject = null;
47 dataObject = deserializationFactory.deserialize(msg.getMessageBuffer(),
49 } catch(Exception e) {
50 LOGGER.error("Message deserialization failed");
51 LOGGER.error(e.getMessage(), e);
54 if (dataObject == null) {
55 LOGGER.warn("Translated POJO is null");
58 msg.getMessageBuffer().release();
63 * @param deserializationFactory
65 public void setDeserializationFactory(DeserializationFactory deserializationFactory) {
66 this.deserializationFactory = deserializationFactory;