alshabib | 86ac11c | 2014-08-14 16:14:41 -0700 | [diff] [blame^] | 1 | // Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior University |
| 2 | // Copyright (c) 2011, 2012 Open Networking Foundation |
| 3 | // Copyright (c) 2012, 2013 Big Switch Networks, Inc. |
| 4 | // This library was generated by the LoxiGen Compiler. |
| 5 | // See the file LICENSE.txt which should have been included in the source distribution |
| 6 | |
| 7 | // Automatically generated by LOXI from template const_set_serializer.java |
| 8 | // Do not modify |
| 9 | |
| 10 | package org.projectfloodlight.openflow.protocol.ver10; |
| 11 | |
| 12 | import org.projectfloodlight.openflow.protocol.*; |
| 13 | import org.projectfloodlight.openflow.protocol.action.*; |
| 14 | import org.projectfloodlight.openflow.protocol.actionid.*; |
| 15 | import org.projectfloodlight.openflow.protocol.bsntlv.*; |
| 16 | import org.projectfloodlight.openflow.protocol.errormsg.*; |
| 17 | import org.projectfloodlight.openflow.protocol.meterband.*; |
| 18 | import org.projectfloodlight.openflow.protocol.instruction.*; |
| 19 | import org.projectfloodlight.openflow.protocol.instructionid.*; |
| 20 | import org.projectfloodlight.openflow.protocol.match.*; |
| 21 | import org.projectfloodlight.openflow.protocol.oxm.*; |
| 22 | import org.projectfloodlight.openflow.protocol.queueprop.*; |
| 23 | import org.projectfloodlight.openflow.types.*; |
| 24 | import org.projectfloodlight.openflow.util.*; |
| 25 | import org.projectfloodlight.openflow.exceptions.*; |
| 26 | import org.projectfloodlight.openflow.protocol.OFFlowWildcards; |
| 27 | import java.util.Set; |
| 28 | import org.jboss.netty.buffer.ChannelBuffer; |
| 29 | import com.google.common.hash.PrimitiveSink; |
| 30 | import java.util.EnumSet; |
| 31 | import java.util.Collections; |
| 32 | |
| 33 | |
| 34 | public class OFFlowWildcardsSerializerVer10 { |
| 35 | |
| 36 | public final static int IN_PORT_VAL = 0x1; |
| 37 | public final static int DL_VLAN_VAL = 0x2; |
| 38 | public final static int DL_SRC_VAL = 0x4; |
| 39 | public final static int DL_DST_VAL = 0x8; |
| 40 | public final static int DL_TYPE_VAL = 0x10; |
| 41 | public final static int NW_PROTO_VAL = 0x20; |
| 42 | public final static int TP_SRC_VAL = 0x40; |
| 43 | public final static int TP_DST_VAL = 0x80; |
| 44 | public final static int NW_SRC_ALL_VAL = 0x2000; |
| 45 | public final static int NW_SRC_MASK_VAL = 0x3f00; |
| 46 | public final static int NW_DST_ALL_VAL = 0x80000; |
| 47 | public final static int NW_DST_MASK_VAL = 0xfc000; |
| 48 | public final static int DL_VLAN_PCP_VAL = 0x100000; |
| 49 | public final static int NW_TOS_VAL = 0x200000; |
| 50 | public final static int ALL_VAL = 0x3fffff; |
| 51 | |
| 52 | public static Set<OFFlowWildcards> readFrom(ChannelBuffer bb) throws OFParseError { |
| 53 | try { |
| 54 | return ofWireValue(bb.readInt()); |
| 55 | } catch (IllegalArgumentException e) { |
| 56 | throw new OFParseError(e); |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | public static void writeTo(ChannelBuffer bb, Set<OFFlowWildcards> set) { |
| 61 | bb.writeInt(toWireValue(set)); |
| 62 | } |
| 63 | |
| 64 | public static void putTo(Set<OFFlowWildcards> set, PrimitiveSink sink) { |
| 65 | sink.putInt(toWireValue(set)); |
| 66 | } |
| 67 | |
| 68 | |
| 69 | public static Set<OFFlowWildcards> ofWireValue(int val) { |
| 70 | EnumSet<OFFlowWildcards> set = EnumSet.noneOf(OFFlowWildcards.class); |
| 71 | |
| 72 | if((val & IN_PORT_VAL) != 0) |
| 73 | set.add(OFFlowWildcards.IN_PORT); |
| 74 | if((val & DL_VLAN_VAL) != 0) |
| 75 | set.add(OFFlowWildcards.DL_VLAN); |
| 76 | if((val & DL_SRC_VAL) != 0) |
| 77 | set.add(OFFlowWildcards.DL_SRC); |
| 78 | if((val & DL_DST_VAL) != 0) |
| 79 | set.add(OFFlowWildcards.DL_DST); |
| 80 | if((val & DL_TYPE_VAL) != 0) |
| 81 | set.add(OFFlowWildcards.DL_TYPE); |
| 82 | if((val & NW_PROTO_VAL) != 0) |
| 83 | set.add(OFFlowWildcards.NW_PROTO); |
| 84 | if((val & TP_SRC_VAL) != 0) |
| 85 | set.add(OFFlowWildcards.TP_SRC); |
| 86 | if((val & TP_DST_VAL) != 0) |
| 87 | set.add(OFFlowWildcards.TP_DST); |
| 88 | if((val & NW_SRC_ALL_VAL) != 0) |
| 89 | set.add(OFFlowWildcards.NW_SRC_ALL); |
| 90 | if((val & NW_SRC_MASK_VAL) != 0) |
| 91 | set.add(OFFlowWildcards.NW_SRC_MASK); |
| 92 | if((val & NW_DST_ALL_VAL) != 0) |
| 93 | set.add(OFFlowWildcards.NW_DST_ALL); |
| 94 | if((val & NW_DST_MASK_VAL) != 0) |
| 95 | set.add(OFFlowWildcards.NW_DST_MASK); |
| 96 | if((val & DL_VLAN_PCP_VAL) != 0) |
| 97 | set.add(OFFlowWildcards.DL_VLAN_PCP); |
| 98 | if((val & NW_TOS_VAL) != 0) |
| 99 | set.add(OFFlowWildcards.NW_TOS); |
| 100 | if((val & ALL_VAL) != 0) |
| 101 | set.add(OFFlowWildcards.ALL); |
| 102 | return Collections.unmodifiableSet(set); |
| 103 | } |
| 104 | |
| 105 | public static int toWireValue(Set<OFFlowWildcards> set) { |
| 106 | int wireValue = 0; |
| 107 | |
| 108 | for(OFFlowWildcards e: set) { |
| 109 | switch(e) { |
| 110 | case IN_PORT: |
| 111 | wireValue |= IN_PORT_VAL; |
| 112 | break; |
| 113 | case DL_VLAN: |
| 114 | wireValue |= DL_VLAN_VAL; |
| 115 | break; |
| 116 | case DL_SRC: |
| 117 | wireValue |= DL_SRC_VAL; |
| 118 | break; |
| 119 | case DL_DST: |
| 120 | wireValue |= DL_DST_VAL; |
| 121 | break; |
| 122 | case DL_TYPE: |
| 123 | wireValue |= DL_TYPE_VAL; |
| 124 | break; |
| 125 | case NW_PROTO: |
| 126 | wireValue |= NW_PROTO_VAL; |
| 127 | break; |
| 128 | case TP_SRC: |
| 129 | wireValue |= TP_SRC_VAL; |
| 130 | break; |
| 131 | case TP_DST: |
| 132 | wireValue |= TP_DST_VAL; |
| 133 | break; |
| 134 | case NW_SRC_ALL: |
| 135 | wireValue |= NW_SRC_ALL_VAL; |
| 136 | break; |
| 137 | case NW_SRC_MASK: |
| 138 | wireValue |= NW_SRC_MASK_VAL; |
| 139 | break; |
| 140 | case NW_DST_ALL: |
| 141 | wireValue |= NW_DST_ALL_VAL; |
| 142 | break; |
| 143 | case NW_DST_MASK: |
| 144 | wireValue |= NW_DST_MASK_VAL; |
| 145 | break; |
| 146 | case DL_VLAN_PCP: |
| 147 | wireValue |= DL_VLAN_PCP_VAL; |
| 148 | break; |
| 149 | case NW_TOS: |
| 150 | wireValue |= NW_TOS_VAL; |
| 151 | break; |
| 152 | case ALL: |
| 153 | wireValue |= ALL_VAL; |
| 154 | break; |
| 155 | default: |
| 156 | throw new IllegalArgumentException("Illegal enum value for type OFFlowWildcards in version 1.0: " + e); |
| 157 | } |
| 158 | } |
| 159 | return wireValue; |
| 160 | } |
| 161 | |
| 162 | } |