-/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */\r
-package org.opendaylight.openflowjava.protocol.impl.util;\r
-\r
-import io.netty.buffer.ByteBuf;\r
-\r
-import java.util.List;\r
-\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.DlAddressAction;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ExperimenterAction;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.IpAddressAction;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MaxLengthAction;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.NwTosAction;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortAction;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.QueueIdAction;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.VlanPcpAction;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.VlanVidAction;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.Enqueue;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.Experimenter;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.Output;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetDlDst;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetDlSrc;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetNwDst;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetNwSrc;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetNwTos;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetTpDst;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetTpSrc;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetVlanPcp;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetVlanVid;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.StripVlan;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.ActionsList;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.actions.list.Action;\r
-\r
-/**\r
- * Serializes ofp_action (OpenFlow v1.0) structures\r
- * @author michal.polkorab\r
- */\r
-public abstract class OF10ActionsSerializer {\r
- \r
- private static final byte OUTPUT_CODE = 0;\r
- private static final byte SET_VLAN_VID_CODE = 1;\r
- private static final byte SET_VLAN_PCP_CODE = 2;\r
- private static final byte STRIP_VLAN_CODE = 3;\r
- private static final byte SET_DL_SRC_CODE = 4;\r
- private static final byte SET_DL_DST_CODE = 5;\r
- private static final byte SET_NW_SRC_CODE = 6;\r
- private static final byte SET_NW_DST_CODE = 7;\r
- private static final byte SET_NW_TOS_CODE = 8;\r
- private static final byte SET_TP_SRC_CODE = 9;\r
- private static final byte SET_TP_DST_CODE = 10;\r
- private static final byte ENQUEUE_CODE = 11;\r
- private static final int EXPERIMENTER_CODE = 65535; // 0xFFFF\r
- private static final byte GENERIC_ACTION_LENGTH = 8;\r
- private static final byte PADDING_IN_GENERIC_ACTION = 4;\r
- private static final byte OUTPUT_LENGTH = 8;\r
- private static final byte SET_VLAN_VID_LENGTH = 8;\r
- private static final byte PADDING_IN_SET_VLAN_VID_ACTION = 2;\r
- private static final byte SET_VLAN_PCP_LENGTH = 8;\r
- private static final byte PADDING_IN_SET_VLAN_PCP_ACTION = 3;\r
- private static final byte DL_ADDRESS_ACTION_LENGTH = 16;\r
- private static final byte PADDING_IN_DL_ADDRESS_ACTION = 6;\r
- private static final byte SET_NW_TOS_LENGTH = 8;\r
- private static final byte PADDING_IN_SET_NW_TOS_ACTION = 3;\r
- private static final byte IP_ADDRESS_ACTION_LENGTH = 8;\r
- private static final byte TP_PORT_ACTION_LENGTH = 8;\r
- private static final byte PADDING_IN_TP_PORT_ACTION = 2;\r
- private static final byte ENQUEUE_LENGTH = 16;\r
- private static final byte PADDING_IN_ENQUEUE_ACTION = 6;\r
- private static final byte EXPERIMENTER_LENGTH = 8;\r
-\r
- \r
- /**\r
- * Encodes ofp_action (OpenFlow v1.0) structures\r
- * @param out output ByteBuf that actions will be written into\r
- * @param actionsList actions to be encoded\r
- */\r
- public static void encodeActionsV10(ByteBuf out, List<ActionsList> actionsList) {\r
- if (actionsList == null) {\r
- return;\r
- }\r
- for (ActionsList list : actionsList) {\r
- Action action = list.getAction();\r
- if (action.getType().equals(Output.class)) {\r
- encodeOutputAction(action, out);\r
- } else if (action.getType().equals(SetVlanVid.class)) {\r
- encodeSetVlanVidAction(action, out);\r
- } else if (action.getType().equals(SetVlanPcp.class)) {\r
- encodeSetVlanPcpAction(action, out);\r
- } else if (action.getType().equals(StripVlan.class)) {\r
- encodeGenericAction(STRIP_VLAN_CODE, out);\r
- } else if (action.getType().equals(SetDlSrc.class)) {\r
- encodeDlAddressAction(action, out, SET_DL_SRC_CODE);\r
- } else if (action.getType().equals(SetDlDst.class)) {\r
- encodeDlAddressAction(action, out, SET_DL_DST_CODE);\r
- } else if (action.getType().equals(SetNwSrc.class)) {\r
- encodeIpAddressAction(action, out, SET_NW_SRC_CODE);\r
- } else if (action.getType().equals(SetNwDst.class)) {\r
- encodeIpAddressAction(action, out, SET_NW_DST_CODE);\r
- } else if (action.getType().equals(SetNwTos.class)) {\r
- encodeNwTosAction(action, out);\r
- } else if (action.getType().equals(SetTpSrc.class)) {\r
- encodeTpPortAction(action, out, SET_TP_SRC_CODE);\r
- } else if (action.getType().equals(SetTpDst.class)) {\r
- encodeTpPortAction(action, out, SET_TP_DST_CODE);\r
- } else if (action.getType().equals(Enqueue.class)) {\r
- encodeEnqueueAction(action, out);\r
- } else if (action.getType().equals(Experimenter.class)) {\r
- encodeExperimenterAction(action, out);\r
- }\r
- }\r
- }\r
- \r
- private static void encodeGenericAction(byte code, ByteBuf out) {\r
- out.writeShort(code);\r
- out.writeShort(GENERIC_ACTION_LENGTH);\r
- ByteBufUtils.padBuffer(PADDING_IN_GENERIC_ACTION, out);\r
- }\r
- \r
- private static void encodeOutputAction(Action action, ByteBuf out) {\r
- out.writeShort(OUTPUT_CODE);\r
- out.writeShort(OUTPUT_LENGTH);\r
- PortAction port = action.getAugmentation(PortAction.class);\r
- out.writeShort(port.getPort().getValue().intValue());\r
- MaxLengthAction maxlength = action.getAugmentation(MaxLengthAction.class);\r
- out.writeShort(maxlength.getMaxLength());\r
- }\r
- \r
- private static void encodeSetVlanVidAction(Action action, ByteBuf out) {\r
- out.writeShort(SET_VLAN_VID_CODE);\r
- out.writeShort(SET_VLAN_VID_LENGTH);\r
- out.writeShort(action.getAugmentation(VlanVidAction.class).getVlanVid());\r
- ByteBufUtils.padBuffer(PADDING_IN_SET_VLAN_VID_ACTION, out);\r
- }\r
- \r
- private static void encodeSetVlanPcpAction(Action action, ByteBuf out) {\r
- out.writeShort(SET_VLAN_PCP_CODE);\r
- out.writeShort(SET_VLAN_PCP_LENGTH);\r
- out.writeByte(action.getAugmentation(VlanPcpAction.class).getVlanPcp());\r
- ByteBufUtils.padBuffer(PADDING_IN_SET_VLAN_PCP_ACTION, out);\r
- }\r
- \r
- private static void encodeDlAddressAction(Action action, ByteBuf out, byte code) {\r
- out.writeShort(code);\r
- out.writeShort(DL_ADDRESS_ACTION_LENGTH);\r
- out.writeBytes(action.getAugmentation(DlAddressAction.class)\r
- .getDlAddress().getValue().getBytes());\r
- ByteBufUtils.padBuffer(PADDING_IN_DL_ADDRESS_ACTION, out);\r
- }\r
- \r
- private static void encodeNwTosAction(Action action, ByteBuf out) {\r
- out.writeShort(SET_NW_TOS_CODE);\r
- out.writeShort(SET_NW_TOS_LENGTH);\r
- out.writeByte(action.getAugmentation(NwTosAction.class).getNwTos());\r
- ByteBufUtils.padBuffer(PADDING_IN_SET_NW_TOS_ACTION, out);\r
- }\r
- \r
- private static void encodeIpAddressAction(Action action, ByteBuf out, byte code) {\r
- out.writeShort(code);\r
- out.writeShort(IP_ADDRESS_ACTION_LENGTH);\r
- String[] addressGroups = action.\r
- getAugmentation(IpAddressAction.class).getIpAddress().getValue().split("\\.");\r
- for (int i = 0; i < addressGroups.length; i++) {\r
- out.writeByte(Integer.parseInt(addressGroups[i]));\r
- }\r
- }\r
- \r
- private static void encodeTpPortAction(Action action, ByteBuf out, byte code) {\r
- out.writeShort(code);\r
- out.writeShort(TP_PORT_ACTION_LENGTH);\r
- PortAction port = action.getAugmentation(PortAction.class);\r
- out.writeShort(port.getPort().getValue().intValue());\r
- ByteBufUtils.padBuffer(PADDING_IN_TP_PORT_ACTION, out);\r
- }\r
- \r
- private static void encodeEnqueueAction(Action action, ByteBuf out) {\r
- out.writeShort(ENQUEUE_CODE);\r
- out.writeShort(ENQUEUE_LENGTH);\r
- PortAction port = action.getAugmentation(PortAction.class);\r
- out.writeShort(port.getPort().getValue().intValue());\r
- ByteBufUtils.padBuffer(PADDING_IN_ENQUEUE_ACTION, out);\r
- QueueIdAction queueId = action.getAugmentation(QueueIdAction.class);\r
- out.writeShort(queueId.getQueueId().intValue());\r
- }\r
- \r
- private static void encodeExperimenterAction(Action action, ByteBuf outBuffer) {\r
- outBuffer.writeShort(EXPERIMENTER_CODE);\r
- outBuffer.writeShort(EXPERIMENTER_LENGTH);\r
- ExperimenterAction experimenter = action.getAugmentation(ExperimenterAction.class);\r
- outBuffer.writeInt(experimenter.getExperimenter().intValue());\r
- }\r
- \r
- /**\r
- * Computes length of actions\r
- * @param actionsList\r
- * @return length of actions (OpenFlow v1.0)\r
- */\r
- public static int computeActionsLength(List<ActionsList> actionsList) {\r
- int length = 0;\r
- if (actionsList != null) {\r
- for (ActionsList list : actionsList) {\r
- Action action = list.getAction();\r
- if (action.getType().equals(Output.class)) {\r
- length += 8;\r
- } else if (action.getType().equals(SetVlanVid.class)) {\r
- length += 8;\r
- } else if (action.getType().equals(SetVlanPcp.class)) {\r
- length += 8;\r
- } else if (action.getType().equals(StripVlan.class)) {\r
- length += 8;\r
- } else if (action.getType().equals(SetDlSrc.class)) {\r
- length += 16;\r
- } else if (action.getType().equals(SetDlDst.class)) {\r
- length += 16;\r
- } else if (action.getType().equals(SetNwSrc.class)) {\r
- length += 8;\r
- } else if (action.getType().equals(SetNwDst.class)) {\r
- length += 8;\r
- } else if (action.getType().equals(SetNwTos.class)) {\r
- length += 8;\r
- } else if (action.getType().equals(SetTpSrc.class)) {\r
- length += 8;\r
- } else if (action.getType().equals(SetTpDst.class)) {\r
- length += 8;\r
- } else if (action.getType().equals(Enqueue.class)) {\r
- length += 16;\r
- } else if (action.getType().equals(Experimenter.class)) {\r
- length += 8;\r
- }\r
- }\r
- }\r
- return length;\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.util;
+
+import io.netty.buffer.ByteBuf;
+
+import java.util.List;
+
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.DlAddressAction;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ExperimenterAction;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.IpAddressAction;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MaxLengthAction;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.NwTosAction;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortAction;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.QueueIdAction;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.VlanPcpAction;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.VlanVidAction;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.Enqueue;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.Experimenter;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.Output;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetDlDst;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetDlSrc;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetNwDst;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetNwSrc;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetNwTos;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetTpDst;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetTpSrc;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetVlanPcp;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetVlanVid;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.StripVlan;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.ActionsList;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.actions.list.Action;
+
+/**
+ * Serializes ofp_action (OpenFlow v1.0) structures
+ * @author michal.polkorab
+ */
+public abstract class OF10ActionsSerializer {
+
+ private static final byte OUTPUT_CODE = 0;
+ private static final byte SET_VLAN_VID_CODE = 1;
+ private static final byte SET_VLAN_PCP_CODE = 2;
+ private static final byte STRIP_VLAN_CODE = 3;
+ private static final byte SET_DL_SRC_CODE = 4;
+ private static final byte SET_DL_DST_CODE = 5;
+ private static final byte SET_NW_SRC_CODE = 6;
+ private static final byte SET_NW_DST_CODE = 7;
+ private static final byte SET_NW_TOS_CODE = 8;
+ private static final byte SET_TP_SRC_CODE = 9;
+ private static final byte SET_TP_DST_CODE = 10;
+ private static final byte ENQUEUE_CODE = 11;
+ private static final int EXPERIMENTER_CODE = 65535; // 0xFFFF
+ private static final byte GENERIC_ACTION_LENGTH = 8;
+ private static final byte PADDING_IN_GENERIC_ACTION = 4;
+ private static final byte OUTPUT_LENGTH = 8;
+ private static final byte SET_VLAN_VID_LENGTH = 8;
+ private static final byte PADDING_IN_SET_VLAN_VID_ACTION = 2;
+ private static final byte SET_VLAN_PCP_LENGTH = 8;
+ private static final byte PADDING_IN_SET_VLAN_PCP_ACTION = 3;
+ private static final byte DL_ADDRESS_ACTION_LENGTH = 16;
+ private static final byte PADDING_IN_DL_ADDRESS_ACTION = 6;
+ private static final byte SET_NW_TOS_LENGTH = 8;
+ private static final byte PADDING_IN_SET_NW_TOS_ACTION = 3;
+ private static final byte IP_ADDRESS_ACTION_LENGTH = 8;
+ private static final byte TP_PORT_ACTION_LENGTH = 8;
+ private static final byte PADDING_IN_TP_PORT_ACTION = 2;
+ private static final byte ENQUEUE_LENGTH = 16;
+ private static final byte PADDING_IN_ENQUEUE_ACTION = 6;
+ private static final byte EXPERIMENTER_LENGTH = 8;
+
+
+ /**
+ * Encodes ofp_action (OpenFlow v1.0) structures
+ * @param out output ByteBuf that actions will be written into
+ * @param actionsList actions to be encoded
+ */
+ public static void encodeActionsV10(ByteBuf out, List<ActionsList> actionsList) {
+ if (actionsList == null) {
+ return;
+ }
+ for (ActionsList list : actionsList) {
+ Action action = list.getAction();
+ if (action.getType().equals(Output.class)) {
+ encodeOutputAction(action, out);
+ } else if (action.getType().equals(SetVlanVid.class)) {
+ encodeSetVlanVidAction(action, out);
+ } else if (action.getType().equals(SetVlanPcp.class)) {
+ encodeSetVlanPcpAction(action, out);
+ } else if (action.getType().equals(StripVlan.class)) {
+ encodeGenericAction(STRIP_VLAN_CODE, out);
+ } else if (action.getType().equals(SetDlSrc.class)) {
+ encodeDlAddressAction(action, out, SET_DL_SRC_CODE);
+ } else if (action.getType().equals(SetDlDst.class)) {
+ encodeDlAddressAction(action, out, SET_DL_DST_CODE);
+ } else if (action.getType().equals(SetNwSrc.class)) {
+ encodeIpAddressAction(action, out, SET_NW_SRC_CODE);
+ } else if (action.getType().equals(SetNwDst.class)) {
+ encodeIpAddressAction(action, out, SET_NW_DST_CODE);
+ } else if (action.getType().equals(SetNwTos.class)) {
+ encodeNwTosAction(action, out);
+ } else if (action.getType().equals(SetTpSrc.class)) {
+ encodeTpPortAction(action, out, SET_TP_SRC_CODE);
+ } else if (action.getType().equals(SetTpDst.class)) {
+ encodeTpPortAction(action, out, SET_TP_DST_CODE);
+ } else if (action.getType().equals(Enqueue.class)) {
+ encodeEnqueueAction(action, out);
+ } else if (action.getType().equals(Experimenter.class)) {
+ encodeExperimenterAction(action, out);
+ }
+ }
+ }
+
+ private static void encodeGenericAction(byte code, ByteBuf out) {
+ out.writeShort(code);
+ out.writeShort(GENERIC_ACTION_LENGTH);
+ ByteBufUtils.padBuffer(PADDING_IN_GENERIC_ACTION, out);
+ }
+
+ private static void encodeOutputAction(Action action, ByteBuf out) {
+ out.writeShort(OUTPUT_CODE);
+ out.writeShort(OUTPUT_LENGTH);
+ PortAction port = action.getAugmentation(PortAction.class);
+ out.writeShort(port.getPort().getValue().intValue());
+ MaxLengthAction maxlength = action.getAugmentation(MaxLengthAction.class);
+ out.writeShort(maxlength.getMaxLength());
+ }
+
+ private static void encodeSetVlanVidAction(Action action, ByteBuf out) {
+ out.writeShort(SET_VLAN_VID_CODE);
+ out.writeShort(SET_VLAN_VID_LENGTH);
+ out.writeShort(action.getAugmentation(VlanVidAction.class).getVlanVid());
+ ByteBufUtils.padBuffer(PADDING_IN_SET_VLAN_VID_ACTION, out);
+ }
+
+ private static void encodeSetVlanPcpAction(Action action, ByteBuf out) {
+ out.writeShort(SET_VLAN_PCP_CODE);
+ out.writeShort(SET_VLAN_PCP_LENGTH);
+ out.writeByte(action.getAugmentation(VlanPcpAction.class).getVlanPcp());
+ ByteBufUtils.padBuffer(PADDING_IN_SET_VLAN_PCP_ACTION, out);
+ }
+
+ private static void encodeDlAddressAction(Action action, ByteBuf out, byte code) {
+ out.writeShort(code);
+ out.writeShort(DL_ADDRESS_ACTION_LENGTH);
+ out.writeBytes(action.getAugmentation(DlAddressAction.class)
+ .getDlAddress().getValue().getBytes());
+ ByteBufUtils.padBuffer(PADDING_IN_DL_ADDRESS_ACTION, out);
+ }
+
+ private static void encodeNwTosAction(Action action, ByteBuf out) {
+ out.writeShort(SET_NW_TOS_CODE);
+ out.writeShort(SET_NW_TOS_LENGTH);
+ out.writeByte(action.getAugmentation(NwTosAction.class).getNwTos());
+ ByteBufUtils.padBuffer(PADDING_IN_SET_NW_TOS_ACTION, out);
+ }
+
+ private static void encodeIpAddressAction(Action action, ByteBuf out, byte code) {
+ out.writeShort(code);
+ out.writeShort(IP_ADDRESS_ACTION_LENGTH);
+ String[] addressGroups = action.
+ getAugmentation(IpAddressAction.class).getIpAddress().getValue().split("\\.");
+ for (int i = 0; i < addressGroups.length; i++) {
+ out.writeByte(Integer.parseInt(addressGroups[i]));
+ }
+ }
+
+ private static void encodeTpPortAction(Action action, ByteBuf out, byte code) {
+ out.writeShort(code);
+ out.writeShort(TP_PORT_ACTION_LENGTH);
+ PortAction port = action.getAugmentation(PortAction.class);
+ out.writeShort(port.getPort().getValue().intValue());
+ ByteBufUtils.padBuffer(PADDING_IN_TP_PORT_ACTION, out);
+ }
+
+ private static void encodeEnqueueAction(Action action, ByteBuf out) {
+ out.writeShort(ENQUEUE_CODE);
+ out.writeShort(ENQUEUE_LENGTH);
+ PortAction port = action.getAugmentation(PortAction.class);
+ out.writeShort(port.getPort().getValue().intValue());
+ ByteBufUtils.padBuffer(PADDING_IN_ENQUEUE_ACTION, out);
+ QueueIdAction queueId = action.getAugmentation(QueueIdAction.class);
+ out.writeShort(queueId.getQueueId().intValue());
+ }
+
+ private static void encodeExperimenterAction(Action action, ByteBuf outBuffer) {
+ outBuffer.writeShort(EXPERIMENTER_CODE);
+ outBuffer.writeShort(EXPERIMENTER_LENGTH);
+ ExperimenterAction experimenter = action.getAugmentation(ExperimenterAction.class);
+ outBuffer.writeInt(experimenter.getExperimenter().intValue());
+ }
+
+ /**
+ * Computes length of actions
+ * @param actionsList
+ * @return length of actions (OpenFlow v1.0)
+ */
+ public static int computeActionsLength(List<ActionsList> actionsList) {
+ int length = 0;
+ if (actionsList != null) {
+ for (ActionsList list : actionsList) {
+ Action action = list.getAction();
+ if (action.getType().equals(Output.class)) {
+ length += 8;
+ } else if (action.getType().equals(SetVlanVid.class)) {
+ length += 8;
+ } else if (action.getType().equals(SetVlanPcp.class)) {
+ length += 8;
+ } else if (action.getType().equals(StripVlan.class)) {
+ length += 8;
+ } else if (action.getType().equals(SetDlSrc.class)) {
+ length += 16;
+ } else if (action.getType().equals(SetDlDst.class)) {
+ length += 16;
+ } else if (action.getType().equals(SetNwSrc.class)) {
+ length += 8;
+ } else if (action.getType().equals(SetNwDst.class)) {
+ length += 8;
+ } else if (action.getType().equals(SetNwTos.class)) {
+ length += 8;
+ } else if (action.getType().equals(SetTpSrc.class)) {
+ length += 8;
+ } else if (action.getType().equals(SetTpDst.class)) {
+ length += 8;
+ } else if (action.getType().equals(Enqueue.class)) {
+ length += 16;
+ } else if (action.getType().equals(Experimenter.class)) {
+ length += 8;
+ }
+ }
+ }
+ return length;
+ }
+
+}