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