blob: b4937baf15875a6f1380698d7aeb8babdf8ac83a [file] [log] [blame]
tom0eb04ca2014-08-25 14:34:51 -07001package org.projectfloodlight.openflow.protocol.ver10;
2
3import java.util.EnumSet;
4import java.util.Set;
5
6import org.jboss.netty.buffer.ChannelBuffer;
7import org.projectfloodlight.openflow.exceptions.OFParseError;
8import org.projectfloodlight.openflow.protocol.OFActionType;
9import org.projectfloodlight.openflow.protocol.match.Match;
10
11import com.google.common.hash.PrimitiveSink;
12
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
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
54 public static int supportedActionsToWire(Set<OFActionType> supportedActions) {
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);
80 return supportedActionsVal;
81 }
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
91}