Yotam Harchol | f3f1115 | 2013-09-05 16:47:16 -0700 | [diff] [blame] | 1 | package org.projectfloodlight.openflow.protocol.ver10; |
| 2 | |
Rob Vaterlaus | feee371 | 2013-09-30 11:24:19 -0700 | [diff] [blame] | 3 | import java.util.EnumSet; |
| 4 | import java.util.Set; |
| 5 | |
Yotam Harchol | f3f1115 | 2013-09-05 16:47:16 -0700 | [diff] [blame] | 6 | import org.jboss.netty.buffer.ChannelBuffer; |
| 7 | import org.projectfloodlight.openflow.exceptions.OFParseError; |
Rob Vaterlaus | feee371 | 2013-09-30 11:24:19 -0700 | [diff] [blame] | 8 | import org.projectfloodlight.openflow.protocol.OFActionType; |
Andreas Wundsam | 5ea1aca | 2013-10-07 17:00:24 -0700 | [diff] [blame] | 9 | import org.projectfloodlight.openflow.protocol.match.Match; |
| 10 | |
| 11 | import com.google.common.hash.PrimitiveSink; |
Yotam Harchol | f3f1115 | 2013-09-05 16:47:16 -0700 | [diff] [blame] | 12 | |
| 13 | /** |
| 14 | * Collection of helper functions for reading and writing into ChannelBuffers |
| 15 | * |
| 16 | * @author capveg |
| 17 | */ |
| 18 | |
| 19 | public class ChannelUtilsVer10 { |
| 20 | public static Match readOFMatch(final ChannelBuffer bb) throws OFParseError { |
| 21 | return OFMatchV1Ver10.READER.readFrom(bb); |
| 22 | } |
| 23 | |
Rob Vaterlaus | feee371 | 2013-09-30 11:24:19 -0700 | [diff] [blame] | 24 | public static Set<OFActionType> readSupportedActions(ChannelBuffer bb) { |
| 25 | int actions = bb.readInt(); |
| 26 | EnumSet<OFActionType> supportedActions = EnumSet.noneOf(OFActionType.class); |
| 27 | if ((actions & (1 << OFActionTypeSerializerVer10.OUTPUT_VAL)) != 0) |
| 28 | supportedActions.add(OFActionType.OUTPUT); |
| 29 | if ((actions & (1 << OFActionTypeSerializerVer10.SET_VLAN_VID_VAL)) != 0) |
| 30 | supportedActions.add(OFActionType.SET_VLAN_VID); |
| 31 | if ((actions & (1 << OFActionTypeSerializerVer10.SET_VLAN_PCP_VAL)) != 0) |
| 32 | supportedActions.add(OFActionType.SET_VLAN_PCP); |
| 33 | if ((actions & (1 << OFActionTypeSerializerVer10.STRIP_VLAN_VAL)) != 0) |
| 34 | supportedActions.add(OFActionType.STRIP_VLAN); |
| 35 | if ((actions & (1 << OFActionTypeSerializerVer10.SET_DL_SRC_VAL)) != 0) |
| 36 | supportedActions.add(OFActionType.SET_DL_SRC); |
| 37 | if ((actions & (1 << OFActionTypeSerializerVer10.SET_DL_DST_VAL)) != 0) |
| 38 | supportedActions.add(OFActionType.SET_DL_DST); |
| 39 | if ((actions & (1 << OFActionTypeSerializerVer10.SET_NW_SRC_VAL)) != 0) |
| 40 | supportedActions.add(OFActionType.SET_NW_SRC); |
| 41 | if ((actions & (1 << OFActionTypeSerializerVer10.SET_NW_DST_VAL)) != 0) |
| 42 | supportedActions.add(OFActionType.SET_NW_DST); |
| 43 | if ((actions & (1 << OFActionTypeSerializerVer10.SET_NW_TOS_VAL)) != 0) |
| 44 | supportedActions.add(OFActionType.SET_NW_TOS); |
| 45 | if ((actions & (1 << OFActionTypeSerializerVer10.SET_TP_SRC_VAL)) != 0) |
| 46 | supportedActions.add(OFActionType.SET_TP_SRC); |
| 47 | if ((actions & (1 << OFActionTypeSerializerVer10.SET_TP_DST_VAL)) != 0) |
| 48 | supportedActions.add(OFActionType.SET_TP_DST); |
| 49 | if ((actions & (1 << OFActionTypeSerializerVer10.ENQUEUE_VAL)) != 0) |
| 50 | supportedActions.add(OFActionType.ENQUEUE); |
| 51 | return supportedActions; |
| 52 | } |
| 53 | |
Andreas Wundsam | 5ea1aca | 2013-10-07 17:00:24 -0700 | [diff] [blame] | 54 | public static int supportedActionsToWire(Set<OFActionType> supportedActions) { |
Rob Vaterlaus | feee371 | 2013-09-30 11:24:19 -0700 | [diff] [blame] | 55 | int supportedActionsVal = 0; |
| 56 | if (supportedActions.contains(OFActionType.OUTPUT)) |
| 57 | supportedActionsVal |= (1 << OFActionTypeSerializerVer10.OUTPUT_VAL); |
| 58 | if (supportedActions.contains(OFActionType.SET_VLAN_VID)) |
| 59 | supportedActionsVal |= (1 << OFActionTypeSerializerVer10.SET_VLAN_VID_VAL); |
| 60 | if (supportedActions.contains(OFActionType.SET_VLAN_PCP)) |
| 61 | supportedActionsVal |= (1 << OFActionTypeSerializerVer10.SET_VLAN_PCP_VAL); |
| 62 | if (supportedActions.contains(OFActionType.STRIP_VLAN)) |
| 63 | supportedActionsVal |= (1 << OFActionTypeSerializerVer10.STRIP_VLAN_VAL); |
| 64 | if (supportedActions.contains(OFActionType.SET_DL_SRC)) |
| 65 | supportedActionsVal |= (1 << OFActionTypeSerializerVer10.SET_DL_SRC_VAL); |
| 66 | if (supportedActions.contains(OFActionType.SET_DL_DST)) |
| 67 | supportedActionsVal |= (1 << OFActionTypeSerializerVer10.SET_DL_DST_VAL); |
| 68 | if (supportedActions.contains(OFActionType.SET_NW_SRC)) |
| 69 | supportedActionsVal |= (1 << OFActionTypeSerializerVer10.SET_NW_SRC_VAL); |
| 70 | if (supportedActions.contains(OFActionType.SET_NW_DST)) |
| 71 | supportedActionsVal |= (1 << OFActionTypeSerializerVer10.SET_NW_DST_VAL); |
| 72 | if (supportedActions.contains(OFActionType.SET_NW_TOS)) |
| 73 | supportedActionsVal |= (1 << OFActionTypeSerializerVer10.SET_NW_TOS_VAL); |
| 74 | if (supportedActions.contains(OFActionType.SET_TP_SRC)) |
| 75 | supportedActionsVal |= (1 << OFActionTypeSerializerVer10.SET_TP_SRC_VAL); |
| 76 | if (supportedActions.contains(OFActionType.SET_TP_DST)) |
| 77 | supportedActionsVal |= (1 << OFActionTypeSerializerVer10.SET_TP_DST_VAL); |
| 78 | if (supportedActions.contains(OFActionType.ENQUEUE)) |
| 79 | supportedActionsVal |= (1 << OFActionTypeSerializerVer10.ENQUEUE_VAL); |
Andreas Wundsam | 5ea1aca | 2013-10-07 17:00:24 -0700 | [diff] [blame] | 80 | return supportedActionsVal; |
Rob Vaterlaus | feee371 | 2013-09-30 11:24:19 -0700 | [diff] [blame] | 81 | } |
Andreas Wundsam | 5ea1aca | 2013-10-07 17:00:24 -0700 | [diff] [blame] | 82 | |
| 83 | public static void putSupportedActionsTo(Set<OFActionType> supportedActions, PrimitiveSink sink) { |
| 84 | sink.putInt(supportedActionsToWire(supportedActions)); |
| 85 | } |
| 86 | |
| 87 | public static void writeSupportedActions(ChannelBuffer bb, Set<OFActionType> supportedActions) { |
| 88 | bb.writeInt(supportedActionsToWire(supportedActions)); |
| 89 | } |
| 90 | |
Yotam Harchol | f3f1115 | 2013-09-05 16:47:16 -0700 | [diff] [blame] | 91 | } |