tom | 0eb04ca | 2014-08-25 14:34:51 -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.OFCapabilities; |
| 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 OFCapabilitiesSerializerVer13 { |
| 35 | |
| 36 | public final static int FLOW_STATS_VAL = 0x1; |
| 37 | public final static int TABLE_STATS_VAL = 0x2; |
| 38 | public final static int PORT_STATS_VAL = 0x4; |
| 39 | public final static int IP_REASM_VAL = 0x20; |
| 40 | public final static int QUEUE_STATS_VAL = 0x40; |
| 41 | public final static int GROUP_STATS_VAL = 0x8; |
| 42 | public final static int PORT_BLOCKED_VAL = 0x100; |
| 43 | |
| 44 | public static Set<OFCapabilities> readFrom(ChannelBuffer bb) throws OFParseError { |
| 45 | try { |
| 46 | return ofWireValue(bb.readInt()); |
| 47 | } catch (IllegalArgumentException e) { |
| 48 | throw new OFParseError(e); |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | public static void writeTo(ChannelBuffer bb, Set<OFCapabilities> set) { |
| 53 | bb.writeInt(toWireValue(set)); |
| 54 | } |
| 55 | |
| 56 | public static void putTo(Set<OFCapabilities> set, PrimitiveSink sink) { |
| 57 | sink.putInt(toWireValue(set)); |
| 58 | } |
| 59 | |
| 60 | |
| 61 | public static Set<OFCapabilities> ofWireValue(int val) { |
| 62 | EnumSet<OFCapabilities> set = EnumSet.noneOf(OFCapabilities.class); |
| 63 | |
| 64 | if((val & FLOW_STATS_VAL) != 0) |
| 65 | set.add(OFCapabilities.FLOW_STATS); |
| 66 | if((val & TABLE_STATS_VAL) != 0) |
| 67 | set.add(OFCapabilities.TABLE_STATS); |
| 68 | if((val & PORT_STATS_VAL) != 0) |
| 69 | set.add(OFCapabilities.PORT_STATS); |
| 70 | if((val & IP_REASM_VAL) != 0) |
| 71 | set.add(OFCapabilities.IP_REASM); |
| 72 | if((val & QUEUE_STATS_VAL) != 0) |
| 73 | set.add(OFCapabilities.QUEUE_STATS); |
| 74 | if((val & GROUP_STATS_VAL) != 0) |
| 75 | set.add(OFCapabilities.GROUP_STATS); |
| 76 | if((val & PORT_BLOCKED_VAL) != 0) |
| 77 | set.add(OFCapabilities.PORT_BLOCKED); |
| 78 | return Collections.unmodifiableSet(set); |
| 79 | } |
| 80 | |
| 81 | public static int toWireValue(Set<OFCapabilities> set) { |
| 82 | int wireValue = 0; |
| 83 | |
| 84 | for(OFCapabilities e: set) { |
| 85 | switch(e) { |
| 86 | case FLOW_STATS: |
| 87 | wireValue |= FLOW_STATS_VAL; |
| 88 | break; |
| 89 | case TABLE_STATS: |
| 90 | wireValue |= TABLE_STATS_VAL; |
| 91 | break; |
| 92 | case PORT_STATS: |
| 93 | wireValue |= PORT_STATS_VAL; |
| 94 | break; |
| 95 | case IP_REASM: |
| 96 | wireValue |= IP_REASM_VAL; |
| 97 | break; |
| 98 | case QUEUE_STATS: |
| 99 | wireValue |= QUEUE_STATS_VAL; |
| 100 | break; |
| 101 | case GROUP_STATS: |
| 102 | wireValue |= GROUP_STATS_VAL; |
| 103 | break; |
| 104 | case PORT_BLOCKED: |
| 105 | wireValue |= PORT_BLOCKED_VAL; |
| 106 | break; |
| 107 | default: |
| 108 | throw new IllegalArgumentException("Illegal enum value for type OFCapabilities in version 1.3: " + e); |
| 109 | } |
| 110 | } |
| 111 | return wireValue; |
| 112 | } |
| 113 | |
| 114 | } |