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.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.OFFlowModFlags; |
| 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 OFFlowModFlagsSerializerVer11 { |
| 35 | |
| 36 | public final static short SEND_FLOW_REM_VAL = (short) 0x1; |
| 37 | public final static short CHECK_OVERLAP_VAL = (short) 0x2; |
| 38 | |
| 39 | public static Set<OFFlowModFlags> readFrom(ChannelBuffer bb) throws OFParseError { |
| 40 | try { |
| 41 | return ofWireValue(bb.readShort()); |
| 42 | } catch (IllegalArgumentException e) { |
| 43 | throw new OFParseError(e); |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | public static void writeTo(ChannelBuffer bb, Set<OFFlowModFlags> set) { |
| 48 | bb.writeShort(toWireValue(set)); |
| 49 | } |
| 50 | |
| 51 | public static void putTo(Set<OFFlowModFlags> set, PrimitiveSink sink) { |
| 52 | sink.putShort(toWireValue(set)); |
| 53 | } |
| 54 | |
| 55 | |
| 56 | public static Set<OFFlowModFlags> ofWireValue(short val) { |
| 57 | EnumSet<OFFlowModFlags> set = EnumSet.noneOf(OFFlowModFlags.class); |
| 58 | |
| 59 | if((val & SEND_FLOW_REM_VAL) != 0) |
| 60 | set.add(OFFlowModFlags.SEND_FLOW_REM); |
| 61 | if((val & CHECK_OVERLAP_VAL) != 0) |
| 62 | set.add(OFFlowModFlags.CHECK_OVERLAP); |
| 63 | return Collections.unmodifiableSet(set); |
| 64 | } |
| 65 | |
| 66 | public static short toWireValue(Set<OFFlowModFlags> set) { |
| 67 | short wireValue = 0; |
| 68 | |
| 69 | for(OFFlowModFlags e: set) { |
| 70 | switch(e) { |
| 71 | case SEND_FLOW_REM: |
| 72 | wireValue |= SEND_FLOW_REM_VAL; |
| 73 | break; |
| 74 | case CHECK_OVERLAP: |
| 75 | wireValue |= CHECK_OVERLAP_VAL; |
| 76 | break; |
| 77 | default: |
| 78 | throw new IllegalArgumentException("Illegal enum value for type OFFlowModFlags in version 1.1: " + e); |
| 79 | } |
| 80 | } |
| 81 | return wireValue; |
| 82 | } |
| 83 | |
| 84 | } |