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;
13 import java.util.List;
14 import org.opendaylight.openflowjava.protocol.impl.deserialization.DeserializationFactory;
15 import org.opendaylight.openflowjava.statistics.CounterEventTypes;
16 import org.opendaylight.openflowjava.statistics.StatisticsCounters;
17 import org.opendaylight.openflowjava.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 LOG = LoggerFactory.getLogger(OFDecoder.class);
29 private final StatisticsCounters statisticsCounter;
31 // TODO: make this final?
32 private DeserializationFactory deserializationFactory;
35 LOG.trace("Creating OFDecoder");
36 // TODO: pass as argument
37 statisticsCounter = StatisticsCounters.getInstance();
41 protected void decode(ChannelHandlerContext ctx, VersionMessageWrapper msg, List<Object> out) throws Exception {
42 statisticsCounter.incrementCounter(CounterEventTypes.US_RECEIVED_IN_OFJAVA);
43 if (LOG.isDebugEnabled()) {
44 LOG.debug("VersionMessageWrapper received");
45 LOG.debug("<< {}", ByteBufUtils.byteBufToHexString(msg.getMessageBuffer()));
49 final DataObject dataObject = deserializationFactory.deserialize(msg.getMessageBuffer(),
51 if (dataObject == null) {
52 LOG.warn("Translated POJO is null");
53 statisticsCounter.incrementCounter(CounterEventTypes.US_DECODE_FAIL);
56 statisticsCounter.incrementCounter(CounterEventTypes.US_DECODE_SUCCESS);
58 } catch (Exception e) {
59 LOG.warn("Message deserialization failed", e);
60 statisticsCounter.incrementCounter(CounterEventTypes.US_DECODE_FAIL);
62 msg.getMessageBuffer().release();
67 * @param deserializationFactory
69 public void setDeserializationFactory(DeserializationFactory deserializationFactory) {
70 this.deserializationFactory = deserializationFactory;