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.OFBsnTcpFlag; |
| 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 OFBsnTcpFlagSerializerVer13 { |
| 35 | |
| 36 | public final static short BSN_TCP_FLAG_FIN_VAL = (short) 0x1; |
| 37 | public final static short BSN_TCP_FLAG_SYN_VAL = (short) 0x2; |
| 38 | public final static short BSN_TCP_FLAG_RST_VAL = (short) 0x4; |
| 39 | public final static short BSN_TCP_FLAG_PSH_VAL = (short) 0x8; |
| 40 | public final static short BSN_TCP_FLAG_ACK_VAL = (short) 0x10; |
| 41 | public final static short BSN_TCP_FLAG_URG_VAL = (short) 0x20; |
| 42 | public final static short BSN_TCP_FLAG_ECE_VAL = (short) 0x40; |
| 43 | public final static short BSN_TCP_FLAG_CWR_VAL = (short) 0x80; |
| 44 | public final static short BSN_TCP_FLAG_NS_VAL = (short) 0x100; |
| 45 | |
| 46 | public static Set<OFBsnTcpFlag> readFrom(ChannelBuffer bb) throws OFParseError { |
| 47 | try { |
| 48 | return ofWireValue(bb.readShort()); |
| 49 | } catch (IllegalArgumentException e) { |
| 50 | throw new OFParseError(e); |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | public static void writeTo(ChannelBuffer bb, Set<OFBsnTcpFlag> set) { |
| 55 | bb.writeShort(toWireValue(set)); |
| 56 | } |
| 57 | |
| 58 | public static void putTo(Set<OFBsnTcpFlag> set, PrimitiveSink sink) { |
| 59 | sink.putShort(toWireValue(set)); |
| 60 | } |
| 61 | |
| 62 | |
| 63 | public static Set<OFBsnTcpFlag> ofWireValue(short val) { |
| 64 | EnumSet<OFBsnTcpFlag> set = EnumSet.noneOf(OFBsnTcpFlag.class); |
| 65 | |
| 66 | if((val & BSN_TCP_FLAG_FIN_VAL) != 0) |
| 67 | set.add(OFBsnTcpFlag.BSN_TCP_FLAG_FIN); |
| 68 | if((val & BSN_TCP_FLAG_SYN_VAL) != 0) |
| 69 | set.add(OFBsnTcpFlag.BSN_TCP_FLAG_SYN); |
| 70 | if((val & BSN_TCP_FLAG_RST_VAL) != 0) |
| 71 | set.add(OFBsnTcpFlag.BSN_TCP_FLAG_RST); |
| 72 | if((val & BSN_TCP_FLAG_PSH_VAL) != 0) |
| 73 | set.add(OFBsnTcpFlag.BSN_TCP_FLAG_PSH); |
| 74 | if((val & BSN_TCP_FLAG_ACK_VAL) != 0) |
| 75 | set.add(OFBsnTcpFlag.BSN_TCP_FLAG_ACK); |
| 76 | if((val & BSN_TCP_FLAG_URG_VAL) != 0) |
| 77 | set.add(OFBsnTcpFlag.BSN_TCP_FLAG_URG); |
| 78 | if((val & BSN_TCP_FLAG_ECE_VAL) != 0) |
| 79 | set.add(OFBsnTcpFlag.BSN_TCP_FLAG_ECE); |
| 80 | if((val & BSN_TCP_FLAG_CWR_VAL) != 0) |
| 81 | set.add(OFBsnTcpFlag.BSN_TCP_FLAG_CWR); |
| 82 | if((val & BSN_TCP_FLAG_NS_VAL) != 0) |
| 83 | set.add(OFBsnTcpFlag.BSN_TCP_FLAG_NS); |
| 84 | return Collections.unmodifiableSet(set); |
| 85 | } |
| 86 | |
| 87 | public static short toWireValue(Set<OFBsnTcpFlag> set) { |
| 88 | short wireValue = 0; |
| 89 | |
| 90 | for(OFBsnTcpFlag e: set) { |
| 91 | switch(e) { |
| 92 | case BSN_TCP_FLAG_FIN: |
| 93 | wireValue |= BSN_TCP_FLAG_FIN_VAL; |
| 94 | break; |
| 95 | case BSN_TCP_FLAG_SYN: |
| 96 | wireValue |= BSN_TCP_FLAG_SYN_VAL; |
| 97 | break; |
| 98 | case BSN_TCP_FLAG_RST: |
| 99 | wireValue |= BSN_TCP_FLAG_RST_VAL; |
| 100 | break; |
| 101 | case BSN_TCP_FLAG_PSH: |
| 102 | wireValue |= BSN_TCP_FLAG_PSH_VAL; |
| 103 | break; |
| 104 | case BSN_TCP_FLAG_ACK: |
| 105 | wireValue |= BSN_TCP_FLAG_ACK_VAL; |
| 106 | break; |
| 107 | case BSN_TCP_FLAG_URG: |
| 108 | wireValue |= BSN_TCP_FLAG_URG_VAL; |
| 109 | break; |
| 110 | case BSN_TCP_FLAG_ECE: |
| 111 | wireValue |= BSN_TCP_FLAG_ECE_VAL; |
| 112 | break; |
| 113 | case BSN_TCP_FLAG_CWR: |
| 114 | wireValue |= BSN_TCP_FLAG_CWR_VAL; |
| 115 | break; |
| 116 | case BSN_TCP_FLAG_NS: |
| 117 | wireValue |= BSN_TCP_FLAG_NS_VAL; |
| 118 | break; |
| 119 | default: |
| 120 | throw new IllegalArgumentException("Illegal enum value for type OFBsnTcpFlag in version 1.3: " + e); |
| 121 | } |
| 122 | } |
| 123 | return wireValue; |
| 124 | } |
| 125 | |
| 126 | } |