blob: b4937baf15875a6f1380698d7aeb8babdf8ac83a [file] [log] [blame]
Yotam Harcholf3f11152013-09-05 16:47:16 -07001package org.projectfloodlight.openflow.protocol.ver10;
2
Rob Vaterlausfeee3712013-09-30 11:24:19 -07003import java.util.EnumSet;
4import java.util.Set;
5
Yotam Harcholf3f11152013-09-05 16:47:16 -07006import org.jboss.netty.buffer.ChannelBuffer;
7import org.projectfloodlight.openflow.exceptions.OFParseError;
Rob Vaterlausfeee3712013-09-30 11:24:19 -07008import org.projectfloodlight.openflow.protocol.OFActionType;
Andreas Wundsam5ea1aca2013-10-07 17:00:24 -07009import org.projectfloodlight.openflow.protocol.match.Match;
10
11import com.google.common.hash.PrimitiveSink;
Yotam Harcholf3f11152013-09-05 16:47:16 -070012
13/**
14 * Collection of helper functions for reading and writing into ChannelBuffers
15 *
16 * @author capveg
17 */
18
19public class ChannelUtilsVer10 {
20 public static Match readOFMatch(final ChannelBuffer bb) throws OFParseError {
21 return OFMatchV1Ver10.READER.readFrom(bb);
22 }
23
Rob Vaterlausfeee3712013-09-30 11:24:19 -070024 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 Wundsam5ea1aca2013-10-07 17:00:24 -070054 public static int supportedActionsToWire(Set<OFActionType> supportedActions) {
Rob Vaterlausfeee3712013-09-30 11:24:19 -070055 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 Wundsam5ea1aca2013-10-07 17:00:24 -070080 return supportedActionsVal;
Rob Vaterlausfeee3712013-09-30 11:24:19 -070081 }
Andreas Wundsam5ea1aca2013-10-07 17:00:24 -070082
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 Harcholf3f11152013-09-05 16:47:16 -070091}