-/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */\r
-package org.opendaylight.openflowjava.protocol.impl.core;\r
-\r
-import io.netty.channel.ChannelHandlerContext;\r
-import io.netty.handler.codec.MessageToMessageDecoder;\r
-\r
-import java.util.List;\r
-\r
-import org.opendaylight.openflowjava.protocol.impl.deserialization.DeserializationFactory;\r
-import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils;\r
-import org.opendaylight.yangtools.yang.binding.DataObject;\r
-import org.slf4j.Logger;\r
-import org.slf4j.LoggerFactory;\r
-\r
-/**\r
- * Transforms OpenFlow Protocol messages to POJOs\r
- * @author michal.polkorab\r
- */\r
-public class OFDecoder extends MessageToMessageDecoder<VersionMessageWrapper> {\r
-\r
- private static final Logger LOGGER = LoggerFactory.getLogger(OFDecoder.class);\r
-\r
- /**\r
- * Constructor of class\r
- */\r
- public OFDecoder() {\r
- LOGGER.debug("Creating OF 1.3 Decoder");\r
- }\r
-\r
- @Override\r
- protected void decode(ChannelHandlerContext ctx, VersionMessageWrapper msg,\r
- List<Object> out) throws Exception {\r
- if (LOGGER.isDebugEnabled()) {\r
- LOGGER.debug("VersionMessageWrapper received");\r
- LOGGER.debug("buffer size: " + msg.getMessageBuffer().readableBytes());\r
- LOGGER.debug("<< " + ByteBufUtils.byteBufToHexString(msg.getMessageBuffer()));\r
- }\r
- DataObject dataObject = null;\r
- try {\r
- dataObject = DeserializationFactory.bufferToMessage(msg.getMessageBuffer(),\r
- msg.getVersion());\r
- } catch(Exception e) {\r
- LOGGER.error("Message deserialization failed");\r
- LOGGER.error(e.getMessage(), e);\r
- return;\r
- }\r
- if (dataObject == null) {\r
- LOGGER.warn("Translated POJO is null");\r
- return;\r
- }\r
- msg.getMessageBuffer().release();\r
- out.add(dataObject);\r
- }\r
-}\r
+/*
+ * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.openflowjava.protocol.impl.core;
+
+import io.netty.channel.ChannelHandlerContext;
+import io.netty.handler.codec.MessageToMessageDecoder;
+
+import java.util.List;
+
+import org.opendaylight.openflowjava.protocol.impl.deserialization.DeserializationFactory;
+import org.opendaylight.openflowjava.statistics.CounterEventTypes;
+import org.opendaylight.openflowjava.statistics.StatisticsCounters;
+import org.opendaylight.openflowjava.util.ByteBufUtils;
+import org.opendaylight.yangtools.yang.binding.DataObject;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Transforms OpenFlow Protocol messages to POJOs
+ * @author michal.polkorab
+ */
+public class OFDecoder extends MessageToMessageDecoder<VersionMessageWrapper> {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(OFDecoder.class);
+ private final StatisticsCounters statisticsCounter;
+
+ // TODO: make this final?
+ private DeserializationFactory deserializationFactory;
+
+ /**
+ * Constructor of class
+ */
+ public OFDecoder() {
+ LOGGER.trace("Creating OF 1.3 Decoder");
+ // TODO: pass as argument
+ statisticsCounter = StatisticsCounters.getInstance();
+ }
+
+ @Override
+ protected void decode(ChannelHandlerContext ctx, VersionMessageWrapper msg,
+ List<Object> out) throws Exception {
+ statisticsCounter.incrementCounter(CounterEventTypes.US_RECEIVED_IN_OFJAVA);
+ if (LOGGER.isDebugEnabled()) {
+ LOGGER.debug("VersionMessageWrapper received");
+ LOGGER.debug("<< {}", ByteBufUtils.byteBufToHexString(msg.getMessageBuffer()));
+ }
+
+ try {
+ final DataObject dataObject = deserializationFactory.deserialize(msg.getMessageBuffer(),
+ msg.getVersion());
+ if (dataObject == null) {
+ LOGGER.warn("Translated POJO is null");
+ statisticsCounter.incrementCounter(CounterEventTypes.US_DECODE_FAIL);
+ } else {
+ out.add(dataObject);
+ statisticsCounter.incrementCounter(CounterEventTypes.US_DECODE_SUCCESS);
+ }
+ } catch (Exception e) {
+ LOGGER.warn("Message deserialization failed", e);
+ statisticsCounter.incrementCounter(CounterEventTypes.US_DECODE_FAIL);
+ } finally {
+ msg.getMessageBuffer().release();
+ }
+ }
+
+ /**
+ * @param deserializationFactory
+ */
+ public void setDeserializationFactory(DeserializationFactory deserializationFactory) {
+ this.deserializationFactory = deserializationFactory;
+ }
+
+}