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.ver11; |
| 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.OFConfigFlags; |
| 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 OFConfigFlagsSerializerVer11 { |
| 35 | |
| 36 | public final static short FRAG_NORMAL_VAL = (short) 0x0; |
| 37 | public final static short FRAG_DROP_VAL = (short) 0x1; |
| 38 | public final static short FRAG_REASM_VAL = (short) 0x2; |
| 39 | public final static short FRAG_MASK_VAL = (short) 0x3; |
| 40 | public final static short INVALID_TTL_TO_CONTROLLER_VAL = (short) 0x4; |
| 41 | |
| 42 | public static Set<OFConfigFlags> readFrom(ChannelBuffer bb) throws OFParseError { |
| 43 | try { |
| 44 | return ofWireValue(bb.readShort()); |
| 45 | } catch (IllegalArgumentException e) { |
| 46 | throw new OFParseError(e); |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | public static void writeTo(ChannelBuffer bb, Set<OFConfigFlags> set) { |
| 51 | bb.writeShort(toWireValue(set)); |
| 52 | } |
| 53 | |
| 54 | public static void putTo(Set<OFConfigFlags> set, PrimitiveSink sink) { |
| 55 | sink.putShort(toWireValue(set)); |
| 56 | } |
| 57 | |
| 58 | |
| 59 | public static Set<OFConfigFlags> ofWireValue(short val) { |
| 60 | EnumSet<OFConfigFlags> set = EnumSet.noneOf(OFConfigFlags.class); |
| 61 | |
| 62 | if((val & FRAG_MASK_VAL) == FRAG_NORMAL_VAL) |
| 63 | set.add(OFConfigFlags.FRAG_NORMAL); |
| 64 | else if((val & FRAG_MASK_VAL) == FRAG_DROP_VAL) |
| 65 | set.add(OFConfigFlags.FRAG_DROP); |
| 66 | else if((val & FRAG_MASK_VAL) == FRAG_REASM_VAL) |
| 67 | set.add(OFConfigFlags.FRAG_REASM); |
| 68 | if((val & INVALID_TTL_TO_CONTROLLER_VAL) != 0) |
| 69 | set.add(OFConfigFlags.INVALID_TTL_TO_CONTROLLER); |
| 70 | return Collections.unmodifiableSet(set); |
| 71 | } |
| 72 | |
| 73 | public static short toWireValue(Set<OFConfigFlags> set) { |
| 74 | short wireValue = 0; |
| 75 | |
| 76 | for(OFConfigFlags e: set) { |
| 77 | switch(e) { |
| 78 | case FRAG_NORMAL: |
| 79 | wireValue |= FRAG_NORMAL_VAL; |
| 80 | break; |
| 81 | case FRAG_DROP: |
| 82 | wireValue |= FRAG_DROP_VAL; |
| 83 | break; |
| 84 | case FRAG_REASM: |
| 85 | wireValue |= FRAG_REASM_VAL; |
| 86 | break; |
| 87 | case INVALID_TTL_TO_CONTROLLER: |
| 88 | wireValue |= INVALID_TTL_TO_CONTROLLER_VAL; |
| 89 | break; |
| 90 | default: |
| 91 | throw new IllegalArgumentException("Illegal enum value for type OFConfigFlags in version 1.1: " + e); |
| 92 | } |
| 93 | } |
| 94 | return wireValue; |
| 95 | } |
| 96 | |
| 97 | } |