blob: ed7c0c87906d33ddf0e5df4da9bc45d0f7fd4c8f [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;
Yotam Harcholf3f11152013-09-05 16:47:16 -07009import org.projectfloodlight.openflow.protocol.OFBsnVportQInQ;
Andreas Wundsam5ea1aca2013-10-07 17:00:24 -070010import org.projectfloodlight.openflow.protocol.match.Match;
11
12import com.google.common.hash.PrimitiveSink;
Yotam Harcholf3f11152013-09-05 16:47:16 -070013
14/**
15 * Collection of helper functions for reading and writing into ChannelBuffers
16 *
17 * @author capveg
18 */
19
20public 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 Vaterlausfeee3712013-09-30 11:24:19 -070036 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 Wundsam5ea1aca2013-10-07 17:00:24 -070066 public static int supportedActionsToWire(Set<OFActionType> supportedActions) {
Rob Vaterlausfeee3712013-09-30 11:24:19 -070067 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 Wundsam5ea1aca2013-10-07 17:00:24 -070092 return supportedActionsVal;
Rob Vaterlausfeee3712013-09-30 11:24:19 -070093 }
Andreas Wundsam5ea1aca2013-10-07 17:00:24 -070094
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 Harcholf3f11152013-09-05 16:47:16 -0700103}