Mass replace CRLF->LF
[openflowjava.git] / openflow-protocol-impl / src / main / java / org / opendaylight / openflowjava / protocol / impl / serialization / action / OF13SetFieldActionSerializer.java
index 93539a83bf7da1406c978e473296472053248146..65eefec9de5d1ae19bd5ad014877b10423d7f63c 100644 (file)
@@ -1,63 +1,71 @@
-/*\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
-\r
-package org.opendaylight.openflowjava.protocol.impl.serialization.action;\r
-\r
-import io.netty.buffer.ByteBuf;\r
-\r
-import org.opendaylight.openflowjava.protocol.api.extensibility.EnhancedMessageTypeKey;\r
-import org.opendaylight.openflowjava.protocol.api.extensibility.HeaderSerializer;\r
-import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer;\r
-import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry;\r
-import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistryInjector;\r
-import org.opendaylight.openflowjava.protocol.impl.util.ActionConstants;\r
-import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils;\r
-import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.OxmFieldsAction;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.grouping.Action;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries;\r
-\r
-/**\r
- * @author michal.polkorab\r
- *\r
- */\r
-public class OF13SetFieldActionSerializer implements OFSerializer<Action>,\r
-        HeaderSerializer<Action>, SerializerRegistryInjector {\r
-\r
-    private SerializerRegistry registry;\r
-\r
-    @Override\r
-    public void serialize(Action action, ByteBuf outBuffer) {\r
-        int startIndex = outBuffer.writerIndex();\r
-        outBuffer.writeShort(ActionConstants.SET_FIELD_CODE);\r
-        int lengthIndex = outBuffer.writerIndex();\r
-        outBuffer.writeShort(EncodeConstants.EMPTY_LENGTH);\r
-        OxmFieldsAction oxmField = action.getAugmentation(OxmFieldsAction.class);\r
-        MatchEntries entry = oxmField.getMatchEntries().get(0);\r
-        OFSerializer<MatchEntries> serializer = registry.getSerializer(new EnhancedMessageTypeKey<>(\r
-                EncodeConstants.OF13_VERSION_ID, entry.getOxmClass(), entry.getOxmMatchField()));\r
-        serializer.serialize(entry, outBuffer);\r
-        int paddingRemainder = (outBuffer.writerIndex() - startIndex) % EncodeConstants.PADDING;\r
-        if (paddingRemainder != 0) {\r
-            ByteBufUtils.padBuffer(EncodeConstants.PADDING - paddingRemainder, outBuffer);\r
-        }\r
-        outBuffer.setShort(lengthIndex, outBuffer.writerIndex() - startIndex);\r
-    }\r
-\r
-    @Override\r
-    public void serializeHeader(Action input, ByteBuf outBuffer) {\r
-        outBuffer.writeShort(ActionConstants.SET_FIELD_CODE);\r
-        outBuffer.writeShort(ActionConstants.ACTION_IDS_LENGTH);\r
-    }\r
-\r
-    @Override\r
-    public void injectSerializerRegistry(SerializerRegistry serializerRegistry) {\r
-        registry = serializerRegistry;\r
-    }\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.action;
+
+import io.netty.buffer.ByteBuf;
+
+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.openflowjava.protocol.api.extensibility.SerializerRegistryInjector;
+import org.opendaylight.openflowjava.protocol.api.keys.MatchEntrySerializerKey;
+import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ExperimenterIdMatchEntry;
+import org.opendaylight.openflowjava.protocol.impl.util.ActionConstants;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.OxmFieldsAction;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.grouping.Action;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.ExperimenterClass;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries;
+
+/**
+ * @author michal.polkorab
+ *
+ */
+public class OF13SetFieldActionSerializer implements OFSerializer<Action>,
+        HeaderSerializer<Action>, SerializerRegistryInjector {
+
+    private SerializerRegistry registry;
+
+    @Override
+    public void serialize(Action action, ByteBuf outBuffer) {
+        int startIndex = outBuffer.writerIndex();
+        outBuffer.writeShort(ActionConstants.SET_FIELD_CODE);
+        int lengthIndex = outBuffer.writerIndex();
+        outBuffer.writeShort(EncodeConstants.EMPTY_LENGTH);
+        OxmFieldsAction oxmField = action.getAugmentation(OxmFieldsAction.class);
+        MatchEntries entry = oxmField.getMatchEntries().get(0);
+        MatchEntrySerializerKey<?, ?> key = new MatchEntrySerializerKey<>(
+                EncodeConstants.OF13_VERSION_ID, entry.getOxmClass(), entry.getOxmMatchField());
+        if (entry.getOxmClass().equals(ExperimenterClass.class)) {
+            key.setExperimenterId(entry.getAugmentation(ExperimenterIdMatchEntry.class)
+                    .getExperimenter().getValue());
+        } else {
+            key.setExperimenterId(null);
+        }
+        OFSerializer<MatchEntries> serializer = registry.getSerializer(key);
+        serializer.serialize(entry, outBuffer);
+        int paddingRemainder = (outBuffer.writerIndex() - startIndex) % EncodeConstants.PADDING;
+        if (paddingRemainder != 0) {
+            outBuffer.writeZero(EncodeConstants.PADDING - paddingRemainder);
+        }
+        outBuffer.setShort(lengthIndex, outBuffer.writerIndex() - startIndex);
+    }
+
+    @Override
+    public void serializeHeader(Action input, ByteBuf outBuffer) {
+        outBuffer.writeShort(ActionConstants.SET_FIELD_CODE);
+        outBuffer.writeShort(ActionConstants.ACTION_IDS_LENGTH);
+    }
+
+    @Override
+    public void injectSerializerRegistry(SerializerRegistry serializerRegistry) {
+        registry = serializerRegistry;
+    }
+
+}