-/*\r
- * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved.\r
- *\r
- * This program and the accompanying materials are made available under the\r
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
- * and is available at http://www.eclipse.org/legal/epl-v10.html\r
- */\r
-package org.opendaylight.openflowjava.protocol.impl.serialization.match;\r
-\r
-import io.netty.buffer.ByteBuf;\r
-\r
-import org.opendaylight.openflowjava.protocol.api.extensibility.HeaderSerializer;\r
-import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MaskMatchEntry;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries;\r
-\r
-/**\r
- * Parent for all match entry serializers\r
- * @author michal.polkorab\r
- */\r
-public abstract class AbstractOxmMatchEntrySerializer\r
- implements OFSerializer<MatchEntries>, HeaderSerializer<MatchEntries>{\r
-\r
- @Override\r
- public void serialize(MatchEntries entry, ByteBuf outBuffer) {\r
- serializeHeader(entry, outBuffer);\r
- }\r
-\r
- @Override\r
- public void serializeHeader(MatchEntries entry, ByteBuf outBuffer) {\r
- outBuffer.writeShort(getOxmClassCode());\r
- writeOxmFieldAndLength(outBuffer, getOxmFieldCode(), entry.isHasMask(),\r
- getValueLength());\r
- }\r
-\r
- protected static void writeMask(MatchEntries entry, ByteBuf out, int length) {\r
- if (entry.isHasMask()) {\r
- byte[] mask = entry.getAugmentation(MaskMatchEntry.class).getMask();\r
- if (mask != null && mask.length != length) {\r
- throw new IllegalArgumentException("incorrect length of mask: "+\r
- mask.length + ", expected: " + length);\r
- }\r
- out.writeBytes(mask);\r
- }\r
- }\r
-\r
- protected static void writeOxmFieldAndLength(ByteBuf out, int fieldValue, boolean hasMask, int lengthArg) {\r
- int fieldAndMask = fieldValue << 1;\r
- int length = lengthArg;\r
- if (hasMask) {\r
- fieldAndMask |= 1;\r
- length *= 2;\r
- }\r
- out.writeByte(fieldAndMask);\r
- out.writeByte(length);\r
- }\r
-\r
- /**\r
- * @return numeric representation of oxm_field\r
- */\r
- protected abstract int getOxmFieldCode();\r
-\r
- /**\r
- * @return numeric representation of oxm_class\r
- */\r
- protected abstract int getOxmClassCode();\r
-\r
- /**\r
- * @return match entry value length (without mask length)\r
- */\r
- protected abstract int getValueLength();\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.serialization.match;
+
+import io.netty.buffer.ByteBuf;
+
+import org.opendaylight.openflowjava.protocol.api.extensibility.HeaderSerializer;
+import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MaskMatchEntry;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries;
+
+/**
+ * Parent for all match entry serializers
+ * @author michal.polkorab
+ */
+public abstract class AbstractOxmMatchEntrySerializer
+ implements OFSerializer<MatchEntries>, HeaderSerializer<MatchEntries>{
+
+ @Override
+ public void serialize(MatchEntries entry, ByteBuf outBuffer) {
+ serializeHeader(entry, outBuffer);
+ }
+
+ @Override
+ public void serializeHeader(MatchEntries entry, ByteBuf outBuffer) {
+ outBuffer.writeShort(getOxmClassCode());
+ writeOxmFieldAndLength(outBuffer, getOxmFieldCode(), entry.isHasMask(),
+ getValueLength());
+ }
+
+ protected static void writeMask(MatchEntries entry, ByteBuf out, int length) {
+ if (entry.isHasMask()) {
+ byte[] mask = entry.getAugmentation(MaskMatchEntry.class).getMask();
+ if (mask != null && mask.length != length) {
+ throw new IllegalArgumentException("incorrect length of mask: "+
+ mask.length + ", expected: " + length);
+ }
+ out.writeBytes(mask);
+ }
+ }
+
+ protected static void writeOxmFieldAndLength(ByteBuf out, int fieldValue, boolean hasMask, int lengthArg) {
+ int fieldAndMask = fieldValue << 1;
+ int length = lengthArg;
+ if (hasMask) {
+ fieldAndMask |= 1;
+ length *= 2;
+ }
+ out.writeByte(fieldAndMask);
+ out.writeByte(length);
+ }
+
+ /**
+ * @return numeric representation of oxm_field
+ */
+ protected abstract int getOxmFieldCode();
+
+ /**
+ * @return numeric representation of oxm_class
+ */
+ protected abstract int getOxmClassCode();
+
+ /**
+ * @return match entry value length (without mask length)
+ */
+ protected abstract int getValueLength();
+
+}