Yotam Harchol | d7b8420 | 2013-07-26 16:08:10 -0700 | [diff] [blame] | 1 | package org.openflow.types; |
| 2 | |
| 3 | import org.jboss.netty.buffer.ChannelBuffer; |
| 4 | import org.openflow.exceptions.OFParseError; |
| 5 | |
Yotam Harchol | 5c9d6f4 | 2013-08-01 11:09:20 -0700 | [diff] [blame] | 6 | public enum IpDscp implements OFValueType<IpDscp> { |
Yotam Harchol | d7b8420 | 2013-07-26 16:08:10 -0700 | [diff] [blame] | 7 | DSCP_0((byte)0), |
| 8 | DSCP_1((byte)1), |
| 9 | DSCP_2((byte)2), |
| 10 | DSCP_3((byte)3), |
| 11 | DSCP_4((byte)4), |
| 12 | DSCP_5((byte)5), |
| 13 | DSCP_6((byte)6), |
| 14 | DSCP_7((byte)7), |
| 15 | DSCP_8((byte)8), |
| 16 | DSCP_9((byte)9), |
| 17 | DSCP_10((byte)10), |
| 18 | DSCP_11((byte)11), |
| 19 | DSCP_12((byte)12), |
| 20 | DSCP_13((byte)13), |
| 21 | DSCP_14((byte)14), |
| 22 | DSCP_15((byte)15), |
| 23 | DSCP_16((byte)16), |
| 24 | DSCP_17((byte)17), |
| 25 | DSCP_18((byte)18), |
| 26 | DSCP_19((byte)19), |
| 27 | DSCP_20((byte)20), |
| 28 | DSCP_21((byte)21), |
| 29 | DSCP_22((byte)22), |
| 30 | DSCP_23((byte)23), |
| 31 | DSCP_24((byte)24), |
| 32 | DSCP_25((byte)25), |
| 33 | DSCP_26((byte)26), |
| 34 | DSCP_27((byte)27), |
| 35 | DSCP_28((byte)28), |
| 36 | DSCP_29((byte)29), |
| 37 | DSCP_30((byte)30), |
| 38 | DSCP_31((byte)31), |
| 39 | DSCP_32((byte)32), |
| 40 | DSCP_33((byte)33), |
| 41 | DSCP_34((byte)34), |
| 42 | DSCP_35((byte)35), |
| 43 | DSCP_36((byte)36), |
| 44 | DSCP_37((byte)37), |
| 45 | DSCP_38((byte)38), |
| 46 | DSCP_39((byte)39), |
| 47 | DSCP_40((byte)40), |
| 48 | DSCP_41((byte)41), |
| 49 | DSCP_42((byte)42), |
| 50 | DSCP_43((byte)43), |
| 51 | DSCP_44((byte)44), |
| 52 | DSCP_45((byte)45), |
| 53 | DSCP_46((byte)46), |
| 54 | DSCP_47((byte)47), |
| 55 | DSCP_48((byte)48), |
| 56 | DSCP_49((byte)49), |
| 57 | DSCP_50((byte)50), |
| 58 | DSCP_51((byte)51), |
| 59 | DSCP_52((byte)52), |
| 60 | DSCP_53((byte)53), |
| 61 | DSCP_54((byte)54), |
| 62 | DSCP_55((byte)55), |
| 63 | DSCP_56((byte)56), |
| 64 | DSCP_57((byte)57), |
| 65 | DSCP_58((byte)58), |
| 66 | DSCP_59((byte)59), |
| 67 | DSCP_60((byte)60), |
| 68 | DSCP_61((byte)61), |
| 69 | DSCP_62((byte)62), |
Yotam Harchol | c281360 | 2013-08-20 12:14:22 -0700 | [diff] [blame] | 70 | DSCP_63((byte)63), |
Yotam Harchol | ff8f85e | 2013-08-21 10:02:23 -0700 | [diff] [blame^] | 71 | DSCP_NO_MASK((byte)0xFF); |
Yotam Harchol | d7b8420 | 2013-07-26 16:08:10 -0700 | [diff] [blame] | 72 | |
| 73 | static final int LENGTH = 1; |
| 74 | |
Yotam Harchol | ff8f85e | 2013-08-21 10:02:23 -0700 | [diff] [blame^] | 75 | public static final IpDscp NO_MASK = DSCP_NO_MASK; |
| 76 | public static final IpDscp FULL_MASK = DSCP_0; |
Yotam Harchol | c281360 | 2013-08-20 12:14:22 -0700 | [diff] [blame] | 77 | |
Yotam Harchol | d7b8420 | 2013-07-26 16:08:10 -0700 | [diff] [blame] | 78 | private final byte dscp; |
| 79 | |
| 80 | private IpDscp(byte dscp) { |
| 81 | this.dscp = dscp; |
| 82 | } |
| 83 | |
| 84 | public static IpDscp of(byte dscp) { |
| 85 | switch (dscp) { |
| 86 | case 0: |
| 87 | return DSCP_0; |
| 88 | case 1: |
| 89 | return DSCP_1; |
| 90 | case 2: |
| 91 | return DSCP_2; |
| 92 | case 3: |
| 93 | return DSCP_3; |
| 94 | case 4: |
| 95 | return DSCP_4; |
| 96 | case 5: |
| 97 | return DSCP_5; |
| 98 | case 6: |
| 99 | return DSCP_6; |
| 100 | case 7: |
| 101 | return DSCP_7; |
| 102 | case 8: |
| 103 | return DSCP_8; |
| 104 | case 9: |
| 105 | return DSCP_9; |
| 106 | case 10: |
| 107 | return DSCP_10; |
| 108 | case 11: |
| 109 | return DSCP_11; |
| 110 | case 12: |
| 111 | return DSCP_12; |
| 112 | case 13: |
| 113 | return DSCP_13; |
| 114 | case 14: |
| 115 | return DSCP_14; |
| 116 | case 15: |
| 117 | return DSCP_15; |
| 118 | case 16: |
| 119 | return DSCP_16; |
| 120 | case 17: |
| 121 | return DSCP_17; |
| 122 | case 18: |
| 123 | return DSCP_18; |
| 124 | case 19: |
| 125 | return DSCP_19; |
| 126 | case 20: |
| 127 | return DSCP_20; |
| 128 | case 21: |
| 129 | return DSCP_21; |
| 130 | case 22: |
| 131 | return DSCP_22; |
| 132 | case 23: |
| 133 | return DSCP_23; |
| 134 | case 24: |
| 135 | return DSCP_24; |
| 136 | case 25: |
| 137 | return DSCP_25; |
| 138 | case 26: |
| 139 | return DSCP_26; |
| 140 | case 27: |
| 141 | return DSCP_27; |
| 142 | case 28: |
| 143 | return DSCP_28; |
| 144 | case 29: |
| 145 | return DSCP_29; |
| 146 | case 30: |
| 147 | return DSCP_30; |
| 148 | case 31: |
| 149 | return DSCP_31; |
| 150 | case 32: |
| 151 | return DSCP_32; |
| 152 | case 33: |
| 153 | return DSCP_33; |
| 154 | case 34: |
| 155 | return DSCP_34; |
| 156 | case 35: |
| 157 | return DSCP_35; |
| 158 | case 36: |
| 159 | return DSCP_36; |
| 160 | case 37: |
| 161 | return DSCP_37; |
| 162 | case 38: |
| 163 | return DSCP_38; |
| 164 | case 39: |
| 165 | return DSCP_39; |
| 166 | case 40: |
| 167 | return DSCP_40; |
| 168 | case 41: |
| 169 | return DSCP_41; |
| 170 | case 42: |
| 171 | return DSCP_42; |
| 172 | case 43: |
| 173 | return DSCP_43; |
| 174 | case 44: |
| 175 | return DSCP_44; |
| 176 | case 45: |
| 177 | return DSCP_45; |
| 178 | case 46: |
| 179 | return DSCP_46; |
| 180 | case 47: |
| 181 | return DSCP_47; |
| 182 | case 48: |
| 183 | return DSCP_48; |
| 184 | case 49: |
| 185 | return DSCP_49; |
| 186 | case 50: |
| 187 | return DSCP_50; |
| 188 | case 51: |
| 189 | return DSCP_51; |
| 190 | case 52: |
| 191 | return DSCP_52; |
| 192 | case 53: |
| 193 | return DSCP_53; |
| 194 | case 54: |
| 195 | return DSCP_54; |
| 196 | case 55: |
| 197 | return DSCP_55; |
| 198 | case 56: |
| 199 | return DSCP_56; |
| 200 | case 57: |
| 201 | return DSCP_57; |
| 202 | case 58: |
| 203 | return DSCP_58; |
| 204 | case 59: |
| 205 | return DSCP_59; |
| 206 | case 60: |
| 207 | return DSCP_60; |
| 208 | case 61: |
| 209 | return DSCP_61; |
| 210 | case 62: |
| 211 | return DSCP_62; |
| 212 | case 63: |
| 213 | return DSCP_63; |
| 214 | default: |
| 215 | throw new IllegalArgumentException("Illegal IPv4 DSCP value: " + dscp); |
| 216 | } |
| 217 | } |
| 218 | |
| 219 | @Override |
| 220 | public int getLength() { |
| 221 | return LENGTH; |
| 222 | } |
| 223 | |
| 224 | @Override |
| 225 | public String toString() { |
| 226 | return Integer.toHexString(dscp); |
| 227 | } |
| 228 | |
| 229 | public void writeByte(ChannelBuffer c) { |
| 230 | c.writeByte(this.dscp); |
| 231 | } |
| 232 | |
| 233 | public static IpDscp readByte(ChannelBuffer c) throws OFParseError { |
| 234 | return IpDscp.of((byte)(c.readUnsignedByte())); |
| 235 | } |
| 236 | |
Yotam Harchol | 5c9d6f4 | 2013-08-01 11:09:20 -0700 | [diff] [blame] | 237 | @Override |
| 238 | public IpDscp applyMask(IpDscp mask) { |
| 239 | return IpDscp.of((byte)(this.dscp & mask.dscp)); |
| 240 | } |
| 241 | |
| 242 | public byte getDscpValue() { |
| 243 | return dscp; |
| 244 | } |
Yotam Harchol | d7b8420 | 2013-07-26 16:08:10 -0700 | [diff] [blame] | 245 | } |