blob: 3f2f23f874fa0f7b76feb0603b1630fc44e97889 [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;
8import org.projectfloodlight.openflow.protocol.match.Match;
9import org.projectfloodlight.openflow.protocol.ver10.OFMatchV1Ver10;
Rob Vaterlausfeee3712013-09-30 11:24:19 -070010import org.projectfloodlight.openflow.protocol.OFActionType;
Yotam Harcholf3f11152013-09-05 16:47:16 -070011import org.projectfloodlight.openflow.protocol.OFBsnVportQInQ;
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 // TODO these need to be figured out / removed
25 public static OFBsnVportQInQ readOFBsnVportQInQ(ChannelBuffer bb) {
26 throw new UnsupportedOperationException("not implemented");
27 }
28
29 public static void writeOFBsnVportQInQ(ChannelBuffer bb,
30 OFBsnVportQInQ vport) {
31 throw new UnsupportedOperationException("not implemented");
32
33 }
34
Rob Vaterlausfeee3712013-09-30 11:24:19 -070035 public static Set<OFActionType> readSupportedActions(ChannelBuffer bb) {
36 int actions = bb.readInt();
37 EnumSet<OFActionType> supportedActions = EnumSet.noneOf(OFActionType.class);
38 if ((actions & (1 << OFActionTypeSerializerVer10.OUTPUT_VAL)) != 0)
39 supportedActions.add(OFActionType.OUTPUT);
40 if ((actions & (1 << OFActionTypeSerializerVer10.SET_VLAN_VID_VAL)) != 0)
41 supportedActions.add(OFActionType.SET_VLAN_VID);
42 if ((actions & (1 << OFActionTypeSerializerVer10.SET_VLAN_PCP_VAL)) != 0)
43 supportedActions.add(OFActionType.SET_VLAN_PCP);
44 if ((actions & (1 << OFActionTypeSerializerVer10.STRIP_VLAN_VAL)) != 0)
45 supportedActions.add(OFActionType.STRIP_VLAN);
46 if ((actions & (1 << OFActionTypeSerializerVer10.SET_DL_SRC_VAL)) != 0)
47 supportedActions.add(OFActionType.SET_DL_SRC);
48 if ((actions & (1 << OFActionTypeSerializerVer10.SET_DL_DST_VAL)) != 0)
49 supportedActions.add(OFActionType.SET_DL_DST);
50 if ((actions & (1 << OFActionTypeSerializerVer10.SET_NW_SRC_VAL)) != 0)
51 supportedActions.add(OFActionType.SET_NW_SRC);
52 if ((actions & (1 << OFActionTypeSerializerVer10.SET_NW_DST_VAL)) != 0)
53 supportedActions.add(OFActionType.SET_NW_DST);
54 if ((actions & (1 << OFActionTypeSerializerVer10.SET_NW_TOS_VAL)) != 0)
55 supportedActions.add(OFActionType.SET_NW_TOS);
56 if ((actions & (1 << OFActionTypeSerializerVer10.SET_TP_SRC_VAL)) != 0)
57 supportedActions.add(OFActionType.SET_TP_SRC);
58 if ((actions & (1 << OFActionTypeSerializerVer10.SET_TP_DST_VAL)) != 0)
59 supportedActions.add(OFActionType.SET_TP_DST);
60 if ((actions & (1 << OFActionTypeSerializerVer10.ENQUEUE_VAL)) != 0)
61 supportedActions.add(OFActionType.ENQUEUE);
62 return supportedActions;
63 }
64
65 public static void writeSupportedActions(ChannelBuffer bb,
66 Set<OFActionType> supportedActions) {
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);
92 bb.writeInt(supportedActionsVal);
93 }
Yotam Harcholf3f11152013-09-05 16:47:16 -070094}