import io.netty.buffer.ByteBuf;
import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
-import org.opendaylight.openflowjava.protocol.api.util.OxmMatchConstants;
import org.opendaylight.openflowjava.protocol.impl.serialization.match.AbstractOxmMatchEntrySerializer;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev150225.oxm.container.match.entry.value.ExperimenterIdCase;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry;
}
/**
- * @return Experimenter match entry ID
+ * Returns the Experimenter match entry ID.
*/
protected abstract long getExperimenterId();
}
}
/**
- * @return Experimenter match entry ID
+ * Returns the Experimenter match entry ID.
*/
@Override
protected long getExperimenterId() {
}
/**
- * @return numeric representation of oxm_field
+ * Returns the numeric representation of oxm_field.
*/
@Override
protected int getOxmFieldCode() {
}
/**
- * @return numeric representation of oxm_class
+ * Returns the numeric representation of oxm_class.
*/
@Override
protected int getOxmClassCode() {
}
/**
- * @return match entry value length (without mask length)
+ * Returns the match entry value length (without mask length).
*/
@Override
protected int getValueLength() {
package org.opendaylight.openflowjava.protocol.impl.util;
/**
+ * Base class for a CodeKeyMaker.
+ *
* @author michal.polkorab
*/
public abstract class AbstractCodeKeyMaker implements CodeKeyMaker {
- private short version;
+ private final short version;
/**
+ * Constractor.
+ *
* @param version openflow wire version
*/
public AbstractCodeKeyMaker(short version) {
}
/**
- * @return the version
+ * Returns the version.
*/
public short getVersion() {
return version;
}
-
}
/**
+ * Base class for a TypeKeyMaker.
+ *
* @author michal.polkorab
* @param <T> type the key maker is based on
*/
public abstract class AbstractTypeKeyMaker<T> implements TypeKeyMaker<T> {
- private short version;
+ private final short version;
/**
+ * Constructor.
+ *
* @param version openflow wire version
*/
public AbstractTypeKeyMaker(short version) {
}
/**
- * @return the version
+ * Returns the version.
*/
public short getVersion() {
return version;
}
-
}
package org.opendaylight.openflowjava.protocol.impl.util;
/**
- * @author michal.polkorab
+ * Action constants.
*
+ * @author michal.polkorab
*/
-public final class ActionConstants {
-
- /** Openflow v1.0 and v1.3 OFPAT_OUTPUT code */
- public static final byte OUTPUT_CODE = 0;
- /** Openflow v1.0 OFPAT_SET_VLAN_VID code */
- public static final byte SET_VLAN_VID_CODE = 1;
- /** Openflow v1.0 OFPAT_SET_VLAN_PCP code */
- public static final byte SET_VLAN_PCP_CODE = 2;
- /** Openflow v1.0 OFPAT_STRIP_VLAN code */
- public static final byte STRIP_VLAN_CODE = 3;
- /** Openflow v1.0 OFPAT_SET_DL_SRC code */
- public static final byte SET_DL_SRC_CODE = 4;
- /** Openflow v1.0 OFPAT_SET_DL_DST code */
- public static final byte SET_DL_DST_CODE = 5;
- /** Openflow v1.0 OFPAT_SET_NW_SRC code */
- public static final byte SET_NW_SRC_CODE = 6;
- /** Openflow v1.0 OFPAT_SET_NW_DST code */
- public static final byte SET_NW_DST_CODE = 7;
- /** Openflow v1.0 OFPAT_SET_NW_TOS code */
- public static final byte SET_NW_TOS_CODE = 8;
- /** Openflow v1.0 OFPAT_SET_TP_SRC code */
- public static final byte SET_TP_SRC_CODE = 9;
- /** Openflow v1.0 OFPAT_SET_TP_DST code */
- public static final byte SET_TP_DST_CODE = 10;
- /** Openflow v1.0 OFPAT_ENQUEUE code */
- public static final byte ENQUEUE_CODE = 11;
- /** Openflow v1.3 OFPAT_COPY_TTL_OUT code */
- public static final byte COPY_TTL_OUT_CODE = 11;
- /** Openflow v1.3 OFPAT_COPY_TTL_IN code */
- public static final byte COPY_TTL_IN_CODE = 12;
- /** Openflow v1.3 OFPAT_SET_MPLS_TTL code */
- public static final byte SET_MPLS_TTL_CODE = 15;
- /** Openflow v1.3 OFPAT_DEC_MPLS_TTL code */
- public static final byte DEC_MPLS_TTL_CODE = 16;
- /** Openflow v1.3 OFPAT_PUSH_VLAN code */
- public static final byte PUSH_VLAN_CODE = 17;
- /** Openflow v1.3 OFPAT_POP_VLAN code */
- public static final byte POP_VLAN_CODE = 18;
- /** Openflow v1.3 OFPAT_PUSH_MPLS code */
- public static final byte PUSH_MPLS_CODE = 19;
- /** Openflow v1.3 OFPAT_POP_MPLS code */
- public static final byte POP_MPLS_CODE = 20;
- /** Openflow v1.3 OFPAT_SET_QUEUE code */
- public static final byte SET_QUEUE_CODE = 21;
- /** Openflow v1.3 OFPAT_GROUP code */
- public static final byte GROUP_CODE = 22;
- /** Openflow v1.3 OFPAT_SET_NW_TTL code */
- public static final byte SET_NW_TTL_CODE = 23;
- /** Openflow v1.3 OFPAT_DEC_NW_TTL code */
- public static final byte DEC_NW_TTL_CODE = 24;
- /** Openflow v1.3 OFPAT_SET_FIELD code */
- public static final int SET_FIELD_CODE = 25;
- /** Openflow v1.3 OFPAT_PUSH_PBB code */
- public static final byte PUSH_PBB_CODE = 26;
- /** Openflow v1.3 OFPAT_POP_PBB code */
- public static final byte POP_PBB_CODE = 27;
-
- /** Padding in OFPAT_OUTPUT (OF v1.3) */
- public static final byte OUTPUT_PADDING = 6;
- /** Padding in OFPAT_SET_VLAN_VID (OF v1.3) */
- public static final byte PADDING_IN_SET_VLAN_VID_ACTION = 2;
- /** Padding in OFPAT_SET_VLAN_PCP (OF v1.3) */
- public static final byte PADDING_IN_SET_VLAN_PCP_ACTION = 3;
- /** Padding in OFPAT_SET_NW_TOS (OF v1.3) */
- public static final byte PADDING_IN_SET_NW_TOS_ACTION = 3;
- /** Padding in OFPAT_ENQUEUE (OF v1.3) */
- public static final int PADDING_IN_ENQUEUE_ACTION = 6;
- /** Padding in OFPAT_SET_MPLS_TTL (OF v1.3) */
- public static final byte SET_MPLS_TTL_PADDING = 3;
- /** Padding in OFPAT_SET_NW_TTL (OF v1.3) */
- public static final byte SET_NW_TTL_PADDING = 3;
- /** Padding in OFPAT_SET_DL_SRC and OFPAT_SET_DL_DST (OF v1.3) */
- public static final byte PADDING_IN_DL_ADDRESS_ACTION = 6;
- /** Padding in OFPAT_SET_TP_SRC and OFPAT_SET_TP_DST (OF v1.3) */
- public static final byte PADDING_IN_TP_PORT_ACTION = 2;
- /** Padding in action header (OF v1.3) */
- public static final byte PADDING_IN_ACTION_HEADER = 4;
+public interface ActionConstants {
+
+ /** Openflow v1.0 and v1.3 OFPAT_OUTPUT code. */
+ byte OUTPUT_CODE = 0;
+
+ /** Openflow v1.0 OFPAT_SET_VLAN_VID code. */
+ byte SET_VLAN_VID_CODE = 1;
+
+ /** Openflow v1.0 OFPAT_SET_VLAN_PCP code. */
+ byte SET_VLAN_PCP_CODE = 2;
+
+ /** Openflow v1.0 OFPAT_STRIP_VLAN code. */
+ byte STRIP_VLAN_CODE = 3;
+
+ /** Openflow v1.0 OFPAT_SET_DL_SRC code. */
+ byte SET_DL_SRC_CODE = 4;
+
+ /** Openflow v1.0 OFPAT_SET_DL_DST code. */
+ byte SET_DL_DST_CODE = 5;
+
+ /** Openflow v1.0 OFPAT_SET_NW_SRC code. */
+ byte SET_NW_SRC_CODE = 6;
+
+ /** Openflow v1.0 OFPAT_SET_NW_DST code. */
+ byte SET_NW_DST_CODE = 7;
+
+ /** Openflow v1.0 OFPAT_SET_NW_TOS code. */
+ byte SET_NW_TOS_CODE = 8;
+
+ /** Openflow v1.0 OFPAT_SET_TP_SRC code. */
+ byte SET_TP_SRC_CODE = 9;
+
+ /** Openflow v1.0 OFPAT_SET_TP_DST code. */
+ byte SET_TP_DST_CODE = 10;
+
+ /** Openflow v1.0 OFPAT_ENQUEUE code. */
+ byte ENQUEUE_CODE = 11;
+
+ /** Openflow v1.3 OFPAT_COPY_TTL_OUT code. */
+ byte COPY_TTL_OUT_CODE = 11;
+
+ /** Openflow v1.3 OFPAT_COPY_TTL_IN code. */
+ byte COPY_TTL_IN_CODE = 12;
+
+ /** Openflow v1.3 OFPAT_SET_MPLS_TTL code. */
+ byte SET_MPLS_TTL_CODE = 15;
+
+ /** Openflow v1.3 OFPAT_DEC_MPLS_TTL code. */
+ byte DEC_MPLS_TTL_CODE = 16;
+
+ /** Openflow v1.3 OFPAT_PUSH_VLAN code. */
+ byte PUSH_VLAN_CODE = 17;
+
+ /** Openflow v1.3 OFPAT_POP_VLAN code. */
+ byte POP_VLAN_CODE = 18;
+
+ /** Openflow v1.3 OFPAT_PUSH_MPLS code. */
+ byte PUSH_MPLS_CODE = 19;
+
+ /** Openflow v1.3 OFPAT_POP_MPLS code. */
+ byte POP_MPLS_CODE = 20;
+
+ /** Openflow v1.3 OFPAT_SET_QUEUE code. */
+ byte SET_QUEUE_CODE = 21;
+
+ /** Openflow v1.3 OFPAT_GROUP code. */
+ byte GROUP_CODE = 22;
+
+ /** Openflow v1.3 OFPAT_SET_NW_TTL code. */
+ byte SET_NW_TTL_CODE = 23;
+
+ /** Openflow v1.3 OFPAT_DEC_NW_TTL code. */
+ byte DEC_NW_TTL_CODE = 24;
+
+ /** Openflow v1.3 OFPAT_SET_FIELD code. */
+ int SET_FIELD_CODE = 25;
+
+ /** Openflow v1.3 OFPAT_PUSH_PBB code. */
+ byte PUSH_PBB_CODE = 26;
+
+ /** Openflow v1.3 OFPAT_POP_PBB code. */
+ byte POP_PBB_CODE = 27;
+
+ /** Padding in OFPAT_OUTPUT (OF v1.3). */
+ byte OUTPUT_PADDING = 6;
+
+ /** Padding in OFPAT_SET_VLAN_VID (OF v1.3). */
+ byte PADDING_IN_SET_VLAN_VID_ACTION = 2;
+
+ /** Padding in OFPAT_SET_VLAN_PCP (OF v1.3). */
+ byte PADDING_IN_SET_VLAN_PCP_ACTION = 3;
+
+ /** Padding in OFPAT_SET_NW_TOS (OF v1.3). */
+ byte PADDING_IN_SET_NW_TOS_ACTION = 3;
+
+ /** Padding in OFPAT_ENQUEUE (OF v1.3). */
+ int PADDING_IN_ENQUEUE_ACTION = 6;
+
+ /** Padding in OFPAT_SET_MPLS_TTL (OF v1.3). */
+ byte SET_MPLS_TTL_PADDING = 3;
+
+ /** Padding in OFPAT_SET_NW_TTL (OF v1.3). */
+ byte SET_NW_TTL_PADDING = 3;
+
+ /** Padding in OFPAT_SET_DL_SRC and OFPAT_SET_DL_DST (OF v1.3). */
+ byte PADDING_IN_DL_ADDRESS_ACTION = 6;
+
+ /** Padding in OFPAT_SET_TP_SRC and OFPAT_SET_TP_DST (OF v1.3). */
+ byte PADDING_IN_TP_PORT_ACTION = 2;
+
+ /** Padding in action header (OF v1.3). */
+ byte PADDING_IN_ACTION_HEADER = 4;
+
/** Padding in OFPAT_PUSH_VLAN, OFPAT_PUSH_MPLS, OFPAT_POP_MPLS
- * and OFPAT_PUSH_PBB (OF v1.3) */
- public static final byte ETHERTYPE_ACTION_PADDING = 2;
+ * and OFPAT_PUSH_PBB (OF v1.3). */
+ byte ETHERTYPE_ACTION_PADDING = 2;
+
+ /** Most common action length. */
+ byte GENERAL_ACTION_LENGTH = 8;
- /** Most common action length */
- public static final byte GENERAL_ACTION_LENGTH = 8;
/** Action larger than GENERAL_ACTION_LENGTH - currently
- * only 16 bytes long actions for both OF v1.0 and v1.3*/
- public static final byte LARGER_ACTION_LENGTH = 16;
- /** Action header size */
- public static final byte ACTION_IDS_LENGTH = 4;
-
- private ActionConstants() {
- throw new UnsupportedOperationException("Utility class shouldn't be instantiated");
- }
+ * only 16 bytes long actions for both OF v1.0 and v1.3. */
+ byte LARGER_ACTION_LENGTH = 16;
+
+ /** Action header size. */
+ byte ACTION_IDS_LENGTH = 4;
}
import org.opendaylight.openflowjava.protocol.api.keys.ActionDeserializerKey;
/**
- * @author michal.polkorab
+ * Helper for registering deserializers.
*
+ * @author michal.polkorab
*/
public class ActionDeserializerRegistryHelper {
- private short version;
- private DeserializerRegistry registry;
+ private final short version;
+ private final DeserializerRegistry registry;
/**
+ * Constructor.
+ *
* @param version wire protocol version
* @param deserializerRegistry registry to be filled with message deserializers
*/
}
/**
+ * Registers a deserializer.
+ *
* @param code code / value to distinguish between deserializers
* @param deserializer deserializer instance
*/
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.ActionChoice;
/**
+ * Helper for registering serializers.
+ *
* @author michal.polkorab
*/
public class ActionSerializerRegistryHelper {
- private short version;
- private SerializerRegistry serializerRegistry;
+ private final short version;
+ private final SerializerRegistry serializerRegistry;
/**
+ * Constructor.
+ *
* @param version Openflow wire version
- * @param serializerRegistry
+ * @param serializerRegistry registry to be filled with message serializers
*/
public ActionSerializerRegistryHelper(short version, SerializerRegistry serializerRegistry) {
this.version = version;
}
/**
- * Registers given serializer
- * @param actionType
- * @param serializer
+ * Registers given serializer.
+ *
+ * @param actionType action type
+ * @param serializer serializer instance
*/
public <T extends ActionChoice> void registerSerializer(Class<T> actionType,
OFGeneralSerializer serializer) {
package org.opendaylight.openflowjava.protocol.impl.util;
-import org.opendaylight.openflowjava.protocol.api.keys.MessageCodeKey;
-
import io.netty.buffer.ByteBuf;
+import org.opendaylight.openflowjava.protocol.api.keys.MessageCodeKey;
/**
+ * Interface for making code keys.
+ *
* @author michal.polkorab
*/
public interface CodeKeyMaker {
/**
+ * Makes a code key.
+ *
* @param input buffer that will be the needed data gathered from
* @return key for deserializer lookup
*/
- abstract MessageCodeKey make(ByteBuf input);
-
+ MessageCodeKey make(ByteBuf input);
}
package org.opendaylight.openflowjava.protocol.impl.util;
import io.netty.buffer.ByteBuf;
-
import org.opendaylight.openflowjava.protocol.api.keys.ActionDeserializerKey;
import org.opendaylight.openflowjava.protocol.api.keys.ExperimenterActionDeserializerKey;
import org.opendaylight.openflowjava.protocol.api.keys.ExperimenterInstructionDeserializerKey;
import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
/**
- * @author michal.polkorab
+ * Factory for creating CodeKeyMaker instances.
*
+ * @author michal.polkorab
*/
-public abstract class CodeKeyMakerFactory {
+public final class CodeKeyMakerFactory {
private CodeKeyMakerFactory() {
//not called
}
- /**
- * @param version
- * @return
- */
+
public static CodeKeyMaker createMatchEntriesKeyMaker(short version) {
return new AbstractCodeKeyMaker(version) {
@Override
};
}
- /**
- * @param version
- * @return
- */
public static CodeKeyMaker createActionsKeyMaker(short version) {
return new AbstractCodeKeyMaker(version) {
@Override
};
}
- /**
- * @param version
- * @return
- */
public static CodeKeyMaker createInstructionsKeyMaker(short version) {
return new AbstractCodeKeyMaker(version) {
@Override
import org.opendaylight.openflowjava.protocol.api.extensibility.OFGeneralSerializer;
import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry;
import org.opendaylight.openflowjava.protocol.api.keys.MessageTypeKey;
-import org.opendaylight.openflowjava.util.ExperimenterSerializerKeyFactory;
/**
* Helper class for serializer registration.
+ *
* @author michal.polkorab
*/
public class CommonMessageRegistryHelper {
- private short version;
- private SerializerRegistry serializerRegistry;
+ private final short version;
+ private final SerializerRegistry serializerRegistry;
/**
+ * Constructor.
+ *
* @param version wire protocol version
* @param serializerRegistry registry to be filled with message serializers
*/
public void registerSerializer(Class<?> msgType, OFGeneralSerializer serializer) {
serializerRegistry.registerSerializer(new MessageTypeKey<>(version, msgType), serializer);
}
-
}
package org.opendaylight.openflowjava.protocol.impl.util;
/**
- * @author michal.polkorab
+ * Instruction constants.
*
+ * @author michal.polkorab
*/
-public final class InstructionConstants {
-
- /** Openflow v1.3 OFPIT_GOTO_TABLE code */
- public static final byte GOTO_TABLE_TYPE = 1;
- /** Openflow v1.3 OFPIT_WRITE_METADATA code */
- public static final byte WRITE_METADATA_TYPE = 2;
- /** Openflow v1.3 OFPIT_WRITE_ACTIONS code */
- public static final byte WRITE_ACTIONS_TYPE = 3;
- /** Openflow v1.3 OFPIT_APPLY_ACTIONS code */
- public static final byte APPLY_ACTIONS_TYPE = 4;
- /** Openflow v1.3 OFPIT_CLEAR_ACTIONS code */
- public static final byte CLEAR_ACTIONS_TYPE = 5;
- /** Openflow v1.3 OFPIT_METER code */
- public static final byte METER_TYPE = 6;
-
- /** PADDING in OFPIT_GOTO_TABLE */
- public static final byte PADDING_IN_GOTO_TABLE = 3;
- /** PADDING in OFPIT_WRITE_METADATA */
- public static final byte PADDING_IN_WRITE_METADATA = 4;
- /** PADDING in OFPIT_WRITE_ACTIONS, OFPIT_APPLY_ACTIONS
- * and OFPIT_CLEAR_ACTIONS */
- public static final byte PADDING_IN_ACTIONS_INSTRUCTION = 4;
-
- /** Openflow v1.3 header length (padded) */
- public static final byte STANDARD_INSTRUCTION_LENGTH = 8;
- /** Openflow v1.3 OFPIT_WRITE_METADATA length */
- public static final byte WRITE_METADATA_LENGTH = 24;
- /** Openflow v1.3 header length (only type and length fields) */
- public static final byte INSTRUCTION_IDS_LENGTH = 4;
-
- private InstructionConstants() {
- throw new UnsupportedOperationException("Utility class shouldn't be instantiated");
- }
+public interface InstructionConstants {
+
+ /** Openflow v1.3 OFPIT_GOTO_TABLE code. */
+ byte GOTO_TABLE_TYPE = 1;
+
+ /** Openflow v1.3 OFPIT_WRITE_METADATA code. */
+ byte WRITE_METADATA_TYPE = 2;
+
+ /** Openflow v1.3 OFPIT_WRITE_ACTIONS code. */
+ byte WRITE_ACTIONS_TYPE = 3;
+
+ /** Openflow v1.3 OFPIT_APPLY_ACTIONS code. */
+ byte APPLY_ACTIONS_TYPE = 4;
+
+ /** Openflow v1.3 OFPIT_CLEAR_ACTIONS code. */
+ byte CLEAR_ACTIONS_TYPE = 5;
+
+ /** Openflow v1.3 OFPIT_METER code. */
+ byte METER_TYPE = 6;
+
+ /** PADDING in OFPIT_GOTO_TABLE. */
+ byte PADDING_IN_GOTO_TABLE = 3;
+
+ /** PADDING in OFPIT_WRITE_METADATA. */
+ byte PADDING_IN_WRITE_METADATA = 4;
+
+ /** PADDING in OFPIT_WRITE_ACTIONS, OFPIT_APPLY_ACTIONS and OFPIT_CLEAR_ACTIONS. */
+ byte PADDING_IN_ACTIONS_INSTRUCTION = 4;
+
+ /** Openflow v1.3 header length (padded). */
+ byte STANDARD_INSTRUCTION_LENGTH = 8;
+
+ /** Openflow v1.3 OFPIT_WRITE_METADATA length. */
+ byte WRITE_METADATA_LENGTH = 24;
+
+ /** Openflow v1.3 header length (only type and length fields). */
+ byte INSTRUCTION_IDS_LENGTH = 4;
}
import org.opendaylight.openflowjava.protocol.api.keys.InstructionDeserializerKey;
/**
- * @author michal.polkorab
+ * Helper class for registering instruction deserializers.
*
+ * @author michal.polkorab
*/
public class InstructionDeserializerRegistryHelper {
- private short version;
- private DeserializerRegistry registry;
+ private final short version;
+ private final DeserializerRegistry registry;
/**
+ * Constructor.
+ *
* @param version wire protocol version
* @param deserializerRegistry registry to be filled with message deserializers
*/
}
/**
+ * Registers a deserializer.
+ *
* @param code code / value to distinguish between deserializers
* @param deserializer deserializer instance
*/
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instruction.grouping.InstructionChoice;
/**
+ * Helper class for registering instruction serializers.
+ *
* @author michal.polkorab
*/
public class InstructionSerializerRegistryHelper {
- private short version;
- private SerializerRegistry serializerRegistry;
+ private final short version;
+ private final SerializerRegistry serializerRegistry;
/**
+ * Constructor.
+ *
* @param version Openflow wire version
- * @param serializerRegistry
+ * @param serializerRegistry registry to be filled with message serializers
*/
public InstructionSerializerRegistryHelper(short version, SerializerRegistry serializerRegistry) {
this.version = version;
}
/**
- * Registers given serializer
- * @param instructionType
- * @param serializer
+ * Registers given serializer.
+ *
+ * @param instructionType instruction type
+ * @param serializer serializer instance
*/
public <T extends InstructionChoice> void registerSerializer(Class<T> instructionType,
OFGeneralSerializer serializer) {
serializerRegistry.registerSerializer(new InstructionSerializerKey<>(version,
instructionType, null), serializer);
}
-}
\ No newline at end of file
+}
package org.opendaylight.openflowjava.protocol.impl.util;
import io.netty.buffer.ByteBuf;
-
import java.util.ArrayList;
import java.util.List;
-
import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistry;
import org.opendaylight.openflowjava.protocol.api.extensibility.HeaderDeserializer;
import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer;
import org.slf4j.LoggerFactory;
/**
- * @author michal.polkorab
+ * Deserializes list.
*
+ * @author michal.polkorab
*/
public final class ListDeserializer {
private static final Logger LOG = LoggerFactory.getLogger(ListDeserializer.class);
}
/**
- * Deserializes items into list
+ * Deserializes items into list.
+ *
* @param version openflow wire version
* @param length length of list in ByteBuf (bytes)
* @param input input buffer
if (input.readableBytes() > 0) {
items = new ArrayList<>();
int startIndex = input.readerIndex();
- while ((input.readerIndex() - startIndex) < length){
+ while (input.readerIndex() - startIndex < length) {
OFDeserializer<E> deserializer = registry.getDeserializer(keyMaker.make(input));
E item = deserializer.deserialize(input);
items.add(item);
}
/**
- * Deserializes headers of items into list (used in MultipartReplyMessage - Table features)
+ * Deserializes headers of items into list (used in MultipartReplyMessage - Table features).
+ *
* @param version openflow wire version
* @param length length of list in ByteBuf (bytes)
* @param input input buffer
items = new ArrayList<>();
int startIndex = input.readerIndex();
boolean exceptionLogged = false;
- while ((input.readerIndex() - startIndex) < length){
+ while (input.readerIndex() - startIndex < length) {
HeaderDeserializer<E> deserializer;
MessageCodeKey key = keyMaker.make(input);
try {
// are not yet (2nd February 2016) fully supported by existing OF Plugin.
// TODO - simplify to correctly report exception during deserialization
if (!exceptionLogged) {
- LOG.warn("Problem during reading table feature property. Skipping unknown feature property: {}." +
- "If more information is needed, set org.opendaylight.openflowjava do DEBUG log level.",
- key, e.getMessage());
+ LOG.warn("Problem during reading table feature property. Skipping unknown feature property: {}."
+ + "If more information is needed, set org.opendaylight.openflowjava do DEBUG log level.",
+ key, e.getMessage());
if (LOG.isDebugEnabled()) {
LOG.debug("Detailed exception: {}", e);
LOG.debug("This exception is logged only once for each multipart reply (table features) to "
- + "prevent log flooding. There might be more of table features related exceptions.");
+ + "prevent log flooding. There might be more of table features related exceptions.");
}
exceptionLogged = true;
}
package org.opendaylight.openflowjava.protocol.impl.util;
import io.netty.buffer.ByteBuf;
-
import java.util.List;
-
import org.opendaylight.openflowjava.protocol.api.extensibility.HeaderSerializer;
import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer;
import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry;
import org.opendaylight.yangtools.yang.binding.DataObject;
/**
- * Serializes list items and their headers
+ * Serializes list items and their headers.
+ *
* @author michal.polkorab
*/
-public abstract class ListSerializer {
+public final class ListSerializer {
private ListSerializer() {
//not called
}
/**
- * Serializes item list
+ * Serializes item list.
+ *
* @param list list of items to be serialized
* @param keyMaker creates key for registry lookup
* @param registry stores serializers
}
/**
- * Serializes headers of items in list
+ * Serializes headers of items in list.
+ *
* @param list list of items to be serialized
* @param keyMaker creates key for registry lookup
* @param registry stores serializers
}
}
}
-
}
package org.opendaylight.openflowjava.protocol.impl.util;
import io.netty.buffer.ByteBuf;
-
import java.util.List;
-
import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistry;
import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistryInjector;
import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.grouping.MatchBuilder;
/**
- * Deserializes ofp_match (OpenFlow v1.3) and its oxm_fields structures
+ * Deserializes ofp_match (OpenFlow v1.3) and its oxm_fields structures.
+ *
* @author timotej.kubas
* @author michal.polkorab
*/
int type = input.readUnsignedShort();
int length = input.readUnsignedShort();
switch (type) {
- case 0:
- builder.setType(StandardMatchType.class);
- break;
- case 1:
- builder.setType(OxmMatchType.class);
- break;
- default:
- break;
+ case 0:
+ builder.setType(StandardMatchType.class);
+ break;
+ case 1:
+ builder.setType(OxmMatchType.class);
+ break;
+ default:
+ break;
}
CodeKeyMaker keyMaker = CodeKeyMakerFactory
.createMatchEntriesKeyMaker(EncodeConstants.OF13_VERSION_ID);
import org.opendaylight.openflowjava.protocol.api.util.OxmMatchConstants;
/**
- * @author michal.polkorab
+ * Helper class for registering match entry deserializers.
*
+ * @author michal.polkorab
*/
public class MatchEntryDeserializerRegistryHelper {
- private short version;
- private DeserializerRegistry registry;
- private int oxmClass;
+ private final short version;
+ private final DeserializerRegistry registry;
+ private final int oxmClass;
/**
+ * Constructor.
+ *
* @param version wire protocol version
- * @param oxmClass oxm_class that will be used for match entry deserializer
- * registration
+ * @param oxmClass oxm_class that will be used for match entry deserializer registration
* @param deserializerRegistry registry to be filled with message deserializers
*/
public MatchEntryDeserializerRegistryHelper(short version, int oxmClass,
}
/**
- * Registers match entry deserializer under provided oxmfield ()
+ * Registers match entry deserializer under provided oxmfield.
+ *
* @param oxmField oxm_field value/code
* @param deserializer deserializer instance
*/
key.setExperimenterId(expId);
registry.registerDeserializer(key, deserializer);
}
-}
\ No newline at end of file
+}
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.OxmClassBase;
/**
+ * Helper class for registering match entry serializers.
+ *
* @author michal.polkorab
* @param <C> OXM class
*/
public class MatchEntrySerializerRegistryHelper<C extends OxmClassBase> {
- private short version;
- private Class<C> generalClass;
- private SerializerRegistry serializerRegistry;
+ private final short version;
+ private final Class<C> generalClass;
+ private final SerializerRegistry serializerRegistry;
/**
+ * Constructor.
+ *
* @param version Openflow wire version
- * @param generalClass
- * @param serializerRegistry
+ * @param generalClass class that will be used for match entry serializer registration
+ * @param serializerRegistry registry to be filled with message serializers
*/
public MatchEntrySerializerRegistryHelper(short version, Class<C> generalClass,
SerializerRegistry serializerRegistry) {
}
/**
- * Registers given serializer
- * @param specificClass
- * @param serializer
+ * Registers the given serializer.
+ *
+ * @param specificClass the MatchField class
+ * @param serializer the serializer instance
*/
public <F extends MatchField> void registerSerializer(
Class<F> specificClass, OFGeneralSerializer serializer) {
}
/**
- * Registers ExperimenterClass type match serializer
- * @param specificClass
- * @param serializer
+ * Registers ExperimenterClass type match serializer.
+ *
+ * @param specificClass the MatchField class
+ * @param serializer the serializer instance
*/
public <F extends MatchField> void registerExperimenterSerializer(
Class<F> specificClass, long expId, OFGeneralSerializer serializer) {
- MatchEntrySerializerKey<?, ?> key = new MatchEntrySerializerKey<>(version, ExperimenterClass.class, specificClass);
+ MatchEntrySerializerKey<?, ?> key = new MatchEntrySerializerKey<>(
+ version, ExperimenterClass.class, specificClass);
key.setExperimenterId(expId);
serializerRegistry.registerSerializer(key, serializer);
}
-
}
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.v10.grouping.MatchV10Builder;
/**
- * Deserializes ofp_match (OpenFlow v1.0) structure
+ * Deserializes ofp_match (OpenFlow v1.0) structure.
+ *
* @author michal.polkorab
*/
public class OF10MatchDeserializer implements OFDeserializer<MatchV10> {
private static final byte PADDING_IN_MATCH_2 = 2;
private static final byte NW_SRC_BITS = 6;
private static final byte NW_SRC_SHIFT = 8;
- private static final int NW_SRC_MASK = ((1 << NW_SRC_BITS) - 1) << NW_SRC_SHIFT;
+ private static final int NW_SRC_MASK = (1 << NW_SRC_BITS) - 1 << NW_SRC_SHIFT;
private static final byte NW_DST_BITS = 6;
private static final byte NW_DST_SHIFT = 14;
- private static final int NW_DST_MASK = ((1 << NW_DST_BITS) - 1) << NW_DST_SHIFT;
+ private static final int NW_DST_MASK = (1 << NW_DST_BITS) - 1 << NW_DST_SHIFT;
@Override
public MatchV10 deserialize(final ByteBuf input) {
}
/**
- * Decodes FlowWildcards
+ * Decodes FlowWildcards.
+ *
* @param input input ByteBuf
* @return decoded FlowWildcardsV10
*/
public static FlowWildcardsV10 createWildcards(final long input) {
- boolean inPort = (input & (1 << 0)) != 0;
- boolean dlVLAN = (input & (1 << 1)) != 0;
- boolean dlSrc = (input & (1 << 2)) != 0;
- boolean dlDst = (input & (1 << 3)) != 0;
- boolean dLType = (input & (1 << 4)) != 0;
- boolean nwProto = (input & (1 << 5)) != 0;
- boolean tpSrc = (input & (1 << 6)) != 0;
- boolean tpDst = (input & (1 << 7)) != 0;
- boolean dlVLANpcp = (input & (1 << 20)) != 0;
- boolean nwTos = (input & (1 << 21)) != 0;
- return new FlowWildcardsV10(dlDst, dlSrc, dLType, dlVLAN,
+ boolean inPort = (input & 1 << 0) != 0;
+ boolean dlVLAN = (input & 1 << 1) != 0;
+ boolean dlSrc = (input & 1 << 2) != 0;
+ boolean dlDst = (input & 1 << 3) != 0;
+ boolean dlType = (input & 1 << 4) != 0;
+ boolean nwProto = (input & 1 << 5) != 0;
+ boolean tpSrc = (input & 1 << 6) != 0;
+ boolean tpDst = (input & 1 << 7) != 0;
+ boolean dlVLANpcp = (input & 1 << 20) != 0;
+ boolean nwTos = (input & 1 << 21) != 0;
+ return new FlowWildcardsV10(dlDst, dlSrc, dlType, dlVLAN,
dlVLANpcp, inPort, nwProto, nwTos, tpDst, tpSrc);
}
/**
- * Decodes NwSrcMask from FlowWildcards (represented as uint32)
+ * Decodes NwSrcMask from FlowWildcards (represented as uint32).
+ *
* @param input binary FlowWildcards
* @return decoded NwSrcMask
*/
}
/**
- * Decodes NwDstMask from FlowWildcards (represented as uint32)
+ * Decodes NwDstMask from FlowWildcards (represented as uint32).
+ *
* @param input binary FlowWildcards
* @return decoded NwDstMask
*/
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.v10.grouping.MatchV10;
/**
- * Serializes ofp_match (OpenFlow v1.0) structure
+ * Serializes ofp_match (OpenFlow v1.0) structure.
+ *
* @author michal.polkorab
*/
public class OF10MatchSerializer implements OFSerializer<MatchV10> {
private static final byte NW_DST_SHIFT = 14;
/**
- * Serializes ofp_match (OpenFlow v1.0)
+ * Serializes ofp_match (OpenFlow v1.0).
+ *
* @param outBuffer output ByteBuf
* @param match match to be serialized
*/
bitmask |= ByteBufUtils.fillBitMask(20,
wildcards.isDLVLANPCP(),
wildcards.isNWTOS());
- bitmask |= ((32 - srcMask) << NW_SRC_SHIFT);
- bitmask |= ((32 - dstMask) << NW_DST_SHIFT);
+ bitmask |= 32 - srcMask << NW_SRC_SHIFT;
+ bitmask |= 32 - dstMask << NW_DST_SHIFT;
return bitmask;
}
-
}
package org.opendaylight.openflowjava.protocol.impl.util;
import io.netty.buffer.ByteBuf;
-
import java.util.List;
-
import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer;
import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry;
import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistryInjector;
import org.slf4j.LoggerFactory;
/**
- * Serializes ofp_match (OpenFlow v1.3)
+ * Serializes ofp_match (OpenFlow v1.3).
+ *
* @author michal.polkorab
* @author timotej.kubas
*/
LOG.debug("Match is null");
return;
}
- int matchStartIndex = outBuffer.writerIndex();
+ final int matchStartIndex = outBuffer.writerIndex();
serializeType(match, outBuffer);
int matchLengthIndex = outBuffer.writerIndex();
outBuffer.writeShort(EncodeConstants.EMPTY_LENGTH);
}
/**
- * Serializes MatchEntries
+ * Serializes MatchEntries.
+ *
* @param matchEntries list of match entries (oxm_fields)
* @param out output ByteBuf
*/
public void injectSerializerRegistry(SerializerRegistry serializerRegistry) {
this.registry = serializerRegistry;
}
-
}
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortStateV10;
/**
- * Used for common structures translation / conversion
+ * Used for common structures translation / conversion.
*
* @author michal.polkorab
*/
}
/**
- * Creates PortState (OF v1.0) from input
+ * Creates PortState (OF v1.0) from input.
+ *
* @param input value read from buffer
* @return port state
*/
- public static PortStateV10 createPortState(long input){
- final Boolean psLinkDown = ((input) & (1<<0)) != 0;
- final Boolean psBlocked = ((input) & (1<<1)) != 0;
- final Boolean psLive = ((input) & (1<<2)) != 0;
- final Boolean psStpListen = ((input) & (1<<8)) == 0;
- final Boolean psStpLearn = ((input) & (1<<8)) != 0;
- final Boolean psStpForward = ((input) & (1<<9)) != 0; // equals 2 << 8
- final Boolean psStpBlock = (((input) & (1<<9)) != 0) && (((input) & (1<<8)) != 0); // equals 3 << 8
- final Boolean psStpMask = ((input) & (1<<10)) != 0; // equals 4 << 8
- return new PortStateV10(psBlocked, psLinkDown, psLive, psStpBlock, psStpForward, psStpLearn, psStpListen, psStpMask);
+ public static PortStateV10 createPortState(long input) {
+ final Boolean psLinkDown = (input & 1 << 0) != 0;
+ final Boolean psBlocked = (input & 1 << 1) != 0;
+ final Boolean psLive = (input & 1 << 2) != 0;
+ final Boolean psStpListen = (input & 1 << 8) == 0;
+ final Boolean psStpLearn = (input & 1 << 8) != 0;
+ // equals 2 << 8
+ final Boolean psStpForward = (input & 1 << 9) != 0;
+ // equals 3 << 8
+ final Boolean psStpBlock = (input & 1 << 9) != 0 && (input & 1 << 8) != 0;
+ // equals 4 << 8
+ final Boolean psStpMask = (input & 1 << 10) != 0;
+ return new PortStateV10(psBlocked, psLinkDown, psLive, psStpBlock, psStpForward, psStpLearn, psStpListen,
+ psStpMask);
}
/**
- * Creates PortConfig (OF v1.0) from input
+ * Creates PortConfig (OF v1.0) from input.
+ *
* @param input value read from buffer
* @return port state
*/
- public static PortConfigV10 createPortConfig(long input){
- final Boolean pcPortDown = ((input) & (1<<0)) != 0;
- final Boolean pcNoStp = ((input) & (1<<1)) != 0;
- final Boolean pcNoRecv = ((input) & (1<<2)) != 0;
- final Boolean pcNoRecvStp = ((input) & (1<<3)) != 0;
- final Boolean pcNoFlood = ((input) & (1<<4)) != 0;
- final Boolean pcNoFwd = ((input) & (1<<5)) != 0;
- final Boolean pcNoPacketIn = ((input) & (1<<6)) != 0;
+ public static PortConfigV10 createPortConfig(long input) {
+ final Boolean pcPortDown = (input & 1 << 0) != 0;
+ final Boolean pcNoStp = (input & 1 << 1) != 0;
+ final Boolean pcNoRecv = (input & 1 << 2) != 0;
+ final Boolean pcNoRecvStp = (input & 1 << 3) != 0;
+ final Boolean pcNoFlood = (input & 1 << 4) != 0;
+ final Boolean pcNoFwd = (input & 1 << 5) != 0;
+ final Boolean pcNoPacketIn = (input & 1 << 6) != 0;
return new PortConfigV10(pcNoFlood, pcNoFwd, pcNoPacketIn, pcNoRecv, pcNoRecvStp, pcNoStp, pcPortDown);
}
/**
- * Creates PortFeatures (OF v1.0) from input
+ * Creates PortFeatures (OF v1.0) from input.
+ *
* @param input value read from buffer
* @return port state
*/
- public static PortFeaturesV10 createPortFeatures(long input){
- final Boolean pf10mbHd = ((input) & (1<<0)) != 0;
- final Boolean pf10mbFd = ((input) & (1<<1)) != 0;
- final Boolean pf100mbHd = ((input) & (1<<2)) != 0;
- final Boolean pf100mbFd = ((input) & (1<<3)) != 0;
- final Boolean pf1gbHd = ((input) & (1<<4)) != 0;
- final Boolean pf1gbFd = ((input) & (1<<5)) != 0;
- final Boolean pf10gbFd = ((input) & (1<<6)) != 0;
- final Boolean pfCopper = ((input) & (1<<7)) != 0;
- final Boolean pfFiber = ((input) & (1<<8)) != 0;
- final Boolean pfAutoneg = ((input) & (1<<9)) != 0;
- final Boolean pfPause = ((input) & (1<<10)) != 0;
- final Boolean pfPauseAsym = ((input) & (1<<11)) != 0;
+ public static PortFeaturesV10 createPortFeatures(long input) {
+ final Boolean pf10mbHd = (input & 1 << 0) != 0;
+ final Boolean pf10mbFd = (input & 1 << 1) != 0;
+ final Boolean pf100mbHd = (input & 1 << 2) != 0;
+ final Boolean pf100mbFd = (input & 1 << 3) != 0;
+ final Boolean pf1gbHd = (input & 1 << 4) != 0;
+ final Boolean pf1gbFd = (input & 1 << 5) != 0;
+ final Boolean pf10gbFd = (input & 1 << 6) != 0;
+ final Boolean pfCopper = (input & 1 << 7) != 0;
+ final Boolean pfFiber = (input & 1 << 8) != 0;
+ final Boolean pfAutoneg = (input & 1 << 9) != 0;
+ final Boolean pfPause = (input & 1 << 10) != 0;
+ final Boolean pfPauseAsym = (input & 1 << 11) != 0;
return new PortFeaturesV10(pf100mbFd, pf100mbHd, pf10gbFd, pf10mbFd, pf10mbHd,
pf1gbFd, pf1gbHd, pfAutoneg, pfCopper, pfFiber, pfPause, pfPauseAsym);
}
-}
\ No newline at end of file
+}
/**
* Helper class for deserializer registration.
+ *
* @author michal.polkorab
*/
public class SimpleDeserializerRegistryHelper {
- private short version;
- private DeserializerRegistry registry;
+ private final short version;
+ private final DeserializerRegistry registry;
/**
+ * Constructor.
+ *
* @param version wire protocol version
* @param deserializerRegistry registry to be filled with message deserializers
*/
((VersionAssignableFactory) deserializer).assignVersion(version);
}
}
-
}
import org.opendaylight.openflowjava.protocol.api.keys.MessageTypeKey;
/**
+ * Interface for a type key maker.
+ *
* @author michal.polkorab
- * @param <T>
+ * @param <T> type the key maker is based on
*/
public interface TypeKeyMaker<T> {
/**
- * @param entry
- * @return key that will be used for serializer lookup in
- * the serializer registry
+ * Makes a MessageTypeKey.
+ *
+ * @param entry the entry for which to create the key
+ * @return key that will be used for serializer lookup in the serializer registry
*/
- abstract MessageTypeKey<?> make(T entry);
-
+ MessageTypeKey<?> make(T entry);
}
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry;
/**
- * Creates KeyMakers
+ * Creates KeyMakers.
+ *
* @author michal.polkorab
*/
-public abstract class TypeKeyMakerFactory {
+public final class TypeKeyMakerFactory {
private TypeKeyMakerFactory() {
//not called
}
/**
- * @param version openflow wire version that shall be used
- * in lookup key
+ * Creates a key maker for MatchEntry instances.
+ *
+ * @param version openflow wire version that shall be used in lookup key
* @return lookup key
*/
public static TypeKeyMaker<MatchEntry> createMatchEntriesKeyMaker(short version) {
}
/**
- * @param version openflow wire version that shall be used
- * in lookup key
+ * Creates a key maker for Action instances.
+ *
+ * @param version openflow wire version that shall be used in lookup key
* @return lookup key
*/
public static TypeKeyMaker<Action> createActionKeyMaker(short version) {
}
/**
- * @param version openflow wire version that shall be used
- * in lookup key
+ * Creates a key maker for Instruction instances.
+ *
+ * @param version openflow wire version that shall be used in lookup key
* @return lookup key
*/
public static TypeKeyMaker<Instruction> createInstructionKeyMaker(short version) {
import org.opendaylight.openflowjava.protocol.api.keys.TypeToClassKey;
/**
- * @author michal.polkorab
+ * Helper for initializing type to class mappings.
*
+ * @author michal.polkorab
*/
public class TypeToClassInitHelper {
- private short version;
- private Map<TypeToClassKey, Class<?>> messageClassMap;
+ private final short version;
+ private final Map<TypeToClassKey, Class<?>> messageClassMap;
/**
- * Constructor
+ * Constructor.
+ *
* @param version protocol wire version
* @param messageClassMap map which stores type to class mapping
*/
}
/**
- * Registers Class int the type to class mapping
+ * Registers Class int the type to class mapping.
+ *
* @param type code value for message type / class
* @param clazz class corresponding to the code
*/
private Short version;
/**
- * @param version OpenFlow protocol version
+ * Assigns the version.
+ *
+ * @param newVersion OpenFlow protocol version
*/
- public void assignVersion(@Nonnull final Short version) {
+ public void assignVersion(@Nonnull final Short newVersion) {
if (this.version == null) {
- this.version = version;
+ this.version = newVersion;
} else {
throw new IllegalStateException("Version already assigned: " + this.version);
}
}
/**
- * @return OpenFlow protocol version
+ * Returns the OpenFlow protocol version.
*/
protected Short getVersion() {
return this.version;
}
-}
\ No newline at end of file
+}
package org.opendaylight.openflowjava.statistics;
import java.util.concurrent.atomic.AtomicLong;
+
/**
- * Counts statistics
+ * Counts statistics.
*
* @author madamjak
*/
public class Counter {
- private AtomicLong counterValue;
- private AtomicLong counterLastReadValue;
+ private final AtomicLong counterValue;
+ private final AtomicLong counterLastReadValue;
/**
- * Default constructor
+ * Default constructor.
*/
public Counter() {
counterValue = new AtomicLong(0L);
}
/**
- * Increment current counter value
+ * Increment current counter value.
*/
- public void incrementCounter(){
+ public void incrementCounter() {
counterValue.incrementAndGet();
}
}
/**
- * get current value of counter and rewrite CounterLastReadValue by current value
+ * Gets current value of counter and rewrite CounterLastReadValue by current value.
+ *
* @return the current value of counter
*/
public long getCounterValue() {
}
/**
- * get current counter value
+ * Gets current counter value.
+ *
* @param modifyLastReadValue
* true - CounterLastReadValue will be rewritten by current CounterValue
* false - no change CounterLastReadValue
* @return the current value of counter
*/
public long getCounterValue(boolean modifyLastReadValue) {
- if(modifyLastReadValue){
+ if (modifyLastReadValue) {
counterLastReadValue.set(counterValue.get());
}
return counterValue.get();
}
/**
- * set current counter value and CounterLastReadValue to 0 (zero)
+ * Sets current counter value and CounterLastReadValue to 0 (zero).
*/
- public void reset(){
- counterValue.set(0l);
- counterLastReadValue.set(0l);
+ public void reset() {
+ counterValue.set(0L);
+ counterLastReadValue.set(0L);
}
/**
- * @return last and current count for specified statistic
+ * Returns the last and current count for specified statistic.
*/
public String getStat() {
long cntPrevVal = getCounterLastReadValue();
long cntCurValue = getCounterValue();
- return String.format("+%d | %d",cntCurValue-cntPrevVal,cntCurValue);
+ return String.format("+%d | %d",cntCurValue - cntPrevVal,cntCurValue);
}
}
package org.opendaylight.openflowjava.statistics;
/**
- * Enumeration of events to be counted with StatisticsCounters
- * @author madamjak
+ * Enumeration of events to be counted with StatisticsCounters.
*
+ * @author madamjak
*/
public enum CounterEventTypes {
/**
- * enter message to OFJ and pass to downstream
+ * enter message to OFJ and pass to downstream.
*/
DS_ENTERED_OFJAVA,
+
/**
- * flow-mod is entered
+ * flow-mod is entered.
*/
DS_FLOW_MODS_ENTERED,
+
/**
- * encode message successfully
+ * encode message successfully.
*/
DS_ENCODE_SUCCESS,
+
/**
- * fail encode message
+ * fail encode message.
*/
DS_ENCODE_FAIL,
+
/**
- * flow-mod encoded and sent to downstream
+ * flow-mod encoded and sent to downstream.
*/
DS_FLOW_MODS_SENT,
+
/**
- * packetIn message got dropped -filtering is active
+ * packetIn message got dropped -filtering is active.
*/
US_DROPPED_PACKET_IN,
+
/**
- * receive message and pass to upstream
+ * receive message and pass to upstream.
*/
US_RECEIVED_IN_OFJAVA,
+
/**
- * decode message successfully
+ * decode message successfully.
*/
US_DECODE_SUCCESS,
+
/**
- * fail decode message
+ * fail decode message.
*/
US_DECODE_FAIL,
+
/**
- * pass message to consumer (end of upstream)
+ * pass message to consumer (end of upstream).
*/
US_MESSAGE_PASS;
-}
\ No newline at end of file
+}
import org.slf4j.LoggerFactory;
/**
- * Singleton class to hold and process counters
- * @author madamjak
+ * Singleton class to hold and process counters.
*
+ * @author madamjak
*/
public final class StatisticsCounters implements StatisticsHandler {
/**
- * Default delay between two writings into log (milliseconds)
+ * Default delay between two writings into log (milliseconds).
*/
public static final int DEFAULT_LOG_REPORT_PERIOD = 10000;
+
/**
- * Minimal delay between two writings into log (milliseconds)
+ * Minimal delay between two writings into log (milliseconds).
*/
public static final int MINIMAL_LOG_REPORT_PERIOD = 500;
+
private static StatisticsCounters instanceHolder;
private static final Logger LOG = LoggerFactory.getLogger(StatisticsCounters.class);
private Timer logReporter;
private int logReportPeriod;
private boolean runLogReport;
- private Map<CounterEventTypes, Counter> countersMap;
+ private final Map<CounterEventTypes, Counter> countersMap;
private boolean runCounting;
// array to hold enabled counter types
- private CounterEventTypes[] enabledCounters = {
- CounterEventTypes.DS_ENCODE_FAIL,
- CounterEventTypes.DS_ENCODE_SUCCESS,
- CounterEventTypes.DS_ENTERED_OFJAVA,
- CounterEventTypes.DS_FLOW_MODS_ENTERED,
- CounterEventTypes.DS_FLOW_MODS_SENT,
- CounterEventTypes.US_DROPPED_PACKET_IN,
- CounterEventTypes.US_DECODE_FAIL,
- CounterEventTypes.US_DECODE_SUCCESS,
- CounterEventTypes.US_MESSAGE_PASS,
- CounterEventTypes.US_RECEIVED_IN_OFJAVA};
-
- /**
- * Get instance of statistics counters, first created object does not start counting and log reporting
+ private final CounterEventTypes[] enabledCounters = { CounterEventTypes.DS_ENCODE_FAIL,
+ CounterEventTypes.DS_ENCODE_SUCCESS, CounterEventTypes.DS_ENTERED_OFJAVA,
+ CounterEventTypes.DS_FLOW_MODS_ENTERED, CounterEventTypes.DS_FLOW_MODS_SENT,
+ CounterEventTypes.US_DROPPED_PACKET_IN, CounterEventTypes.US_DECODE_FAIL,
+ CounterEventTypes.US_DECODE_SUCCESS, CounterEventTypes.US_MESSAGE_PASS,
+ CounterEventTypes.US_RECEIVED_IN_OFJAVA };
+
+ /**
+ * Get instance of statistics counters, first created object does not start counting and log reporting.
+ *
* @return an instance
*/
public static synchronized StatisticsCounters getInstance() {
private StatisticsCounters() {
countersMap = new ConcurrentHashMap<>();
- for(CounterEventTypes cet : enabledCounters){
+ for (CounterEventTypes cet : enabledCounters) {
countersMap.put(cet, new Counter());
}
runCounting = false;
}
/**
- * Start counting (counters are set to 0 before counting starts)
+ * Start counting (counters are set to 0 before counting starts).
+ *
* @param reportToLogs - true = statistic counters will periodically log
* @param logReportDelay - delay between two logs (in milliseconds)
*/
- public void startCounting(boolean reportToLogs, int logReportDelay){
+ public void startCounting(boolean reportToLogs, int logReportDelay) {
if (runCounting) {
return;
}
resetCounters();
LOG.debug("Counting started...");
- if(reportToLogs){
+ if (reportToLogs) {
startLogReport(logReportDelay);
}
runCounting = true;
}
/**
- * Stop counting, values in counters are untouched, log reporter is stopped
+ * Stop counting, values in counters are untouched, log reporter is stopped.
*/
- public void stopCounting(){
+ public void stopCounting() {
runCounting = false;
LOG.debug("Stop counting...");
stopLogReport();
}
/**
- * Give an information if counting is running
+ * Give an information if counting is running.
+ *
* @return true, if counting is running, otherwise false
*/
- public boolean isRunCounting(){
+ public boolean isRunCounting() {
return runCounting;
}
/**
- * Prints statistics with given delay between logs
+ * Prints statistics with given delay between logs.
+ *
* @param logReportDelay - delay between two logs (in milliseconds)
* @exception IllegalArgumentException if logReportDelay is less than 0
*/
- public void startLogReport(int logReportDelay){
- if(runLogReport){
+ public void startLogReport(int logReportDelay) {
+ if (runLogReport) {
return;
}
- if(logReportDelay <= 0){
+ if (logReportDelay <= 0) {
throw new IllegalArgumentException("logReportDelay has to be greater than 0");
}
- if(logReportDelay < MINIMAL_LOG_REPORT_PERIOD){
+ if (logReportDelay < MINIMAL_LOG_REPORT_PERIOD) {
this.logReportPeriod = MINIMAL_LOG_REPORT_PERIOD;
} else {
this.logReportPeriod = logReportDelay;
}
/**
- * Stops logging, counting continues
+ * Stops logging, counting continues.
*/
- public void stopLogReport(){
- if(runLogReport){
- if(logReporter != null){
+ public void stopLogReport() {
+ if (runLogReport) {
+ if (logReporter != null) {
logReporter.cancel();
LOG.debug("Statistics log reporter has been canceled");
}
* Give an information if log reporter is running (statistics are write into logs).
* @return true if log reporter writes statistics into log, otherwise false
*/
- public boolean isRunLogReport(){
+ public boolean isRunLogReport() {
return runLogReport;
}
/**
- * @return the current delay between two writings into logs
+ * Returns the current delay between two writings into logs.
*/
public int getLogReportPeriod() {
return logReportPeriod;
}
/**
- * @return the enabled counters
+ * Returns the enabled counters.
*/
protected CounterEventTypes[] getEnabledCounters() {
return enabledCounters;
}
+
/**
- * @return the countersMap
+ * Returns the countersMap.
*/
protected Map<CounterEventTypes, Counter> getCountersMap() {
return countersMap;
}
/**
- * Give an information if is given counter is enabled
- * @param counterEventKey
+ * Determines if the given counter is enabled.
+ *
+ * @param counterEventKey the counter key
* @return true if counter has been Enabled, otherwise false
*/
- public boolean isCounterEnabled(CounterEventTypes counterEventKey){
+ public boolean isCounterEnabled(CounterEventTypes counterEventKey) {
if (counterEventKey == null) {
return false;
}
}
/**
- * Get counter by CounterEventType
+ * Get counter by CounterEventType.
+ *
* @param counterEventKey key to identify counter (can not be null)
* @return Counter object or null if counter has not been enabled
* @throws IllegalArgumentException if counterEventKey is null
}
/**
- * Increment value of given counter
+ * Increment value of given counter.
+ *
* @param counterEventKey key to identify counter
*/
public void incrementCounter(CounterEventTypes counterEventKey) {
- if(runCounting){
- if (isCounterEnabled(counterEventKey)){
+ if (runCounting) {
+ if (isCounterEnabled(counterEventKey)) {
countersMap.get(counterEventKey).incrementCounter();
}
}
@Override
public void resetCounters() {
- for(CounterEventTypes cet : enabledCounters){
+ for (CounterEventTypes cet : enabledCounters) {
countersMap.get(cet).reset();
}
LOG.debug("StaticsCounters has been reset");
@Override
public String printStatistics() {
StringBuilder strBuilder = new StringBuilder();
- for(CounterEventTypes cet : getEnabledCounters()){
+ for (CounterEventTypes cet : getEnabledCounters()) {
strBuilder.append(cet.name() + ": " + getCountersMap().get(cet).getStat() + "\n");
}
return strBuilder.toString();
}
/**
- * internal class to process logReporter
- * @author madamjak
+ * internal class to process logReporter.
*
+ * @author madamjak
*/
private static class LogReporterTask extends TimerTask {
- private static final Logger LOG = LoggerFactory.getLogger(LogReporterTask.class);
+ private final StatisticsCounters sc;
- private StatisticsCounters sc;
- public LogReporterTask(StatisticsCounters sc) {
+ LogReporterTask(StatisticsCounters sc) {
this.sc = sc;
}
@Override
public void run() {
- for(CounterEventTypes cet : sc.getEnabledCounters()){
+ for (CounterEventTypes cet : sc.getEnabledCounters()) {
LOG.debug("{}: {}", cet.name(), sc.getCountersMap().get(cet).getStat());
}
}