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