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.ver13; |
| 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.OFGroupCapabilities; |
| 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 OFGroupCapabilitiesSerializerVer13 { |
| 35 | |
| 36 | public final static int SELECT_WEIGHT_VAL = 0x1; |
| 37 | public final static int SELECT_LIVENESS_VAL = 0x2; |
| 38 | public final static int CHAINING_VAL = 0x4; |
| 39 | public final static int CHAINING_CHECKS_VAL = 0x8; |
| 40 | |
| 41 | public static Set<OFGroupCapabilities> readFrom(ChannelBuffer bb) throws OFParseError { |
| 42 | try { |
| 43 | return ofWireValue(bb.readInt()); |
| 44 | } catch (IllegalArgumentException e) { |
| 45 | throw new OFParseError(e); |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | public static void writeTo(ChannelBuffer bb, Set<OFGroupCapabilities> set) { |
| 50 | bb.writeInt(toWireValue(set)); |
| 51 | } |
| 52 | |
| 53 | public static void putTo(Set<OFGroupCapabilities> set, PrimitiveSink sink) { |
| 54 | sink.putInt(toWireValue(set)); |
| 55 | } |
| 56 | |
| 57 | |
| 58 | public static Set<OFGroupCapabilities> ofWireValue(int val) { |
| 59 | EnumSet<OFGroupCapabilities> set = EnumSet.noneOf(OFGroupCapabilities.class); |
| 60 | |
| 61 | if((val & SELECT_WEIGHT_VAL) != 0) |
| 62 | set.add(OFGroupCapabilities.SELECT_WEIGHT); |
| 63 | if((val & SELECT_LIVENESS_VAL) != 0) |
| 64 | set.add(OFGroupCapabilities.SELECT_LIVENESS); |
| 65 | if((val & CHAINING_VAL) != 0) |
| 66 | set.add(OFGroupCapabilities.CHAINING); |
| 67 | if((val & CHAINING_CHECKS_VAL) != 0) |
| 68 | set.add(OFGroupCapabilities.CHAINING_CHECKS); |
| 69 | return Collections.unmodifiableSet(set); |
| 70 | } |
| 71 | |
| 72 | public static int toWireValue(Set<OFGroupCapabilities> set) { |
| 73 | int wireValue = 0; |
| 74 | |
| 75 | for(OFGroupCapabilities e: set) { |
| 76 | switch(e) { |
| 77 | case SELECT_WEIGHT: |
| 78 | wireValue |= SELECT_WEIGHT_VAL; |
| 79 | break; |
| 80 | case SELECT_LIVENESS: |
| 81 | wireValue |= SELECT_LIVENESS_VAL; |
| 82 | break; |
| 83 | case CHAINING: |
| 84 | wireValue |= CHAINING_VAL; |
| 85 | break; |
| 86 | case CHAINING_CHECKS: |
| 87 | wireValue |= CHAINING_CHECKS_VAL; |
| 88 | break; |
| 89 | default: |
| 90 | throw new IllegalArgumentException("Illegal enum value for type OFGroupCapabilities in version 1.3: " + e); |
| 91 | } |
| 92 | } |
| 93 | return wireValue; |
| 94 | } |
| 95 | |
| 96 | } |