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.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.OFIpv6ExthdrFlags; |
| 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 OFIpv6ExthdrFlagsSerializerVer13 { |
| 35 | |
| 36 | public final static short NONEXT_VAL = (short) 0x1; |
| 37 | public final static short ESP_VAL = (short) 0x2; |
| 38 | public final static short AUTH_VAL = (short) 0x4; |
| 39 | public final static short DEST_VAL = (short) 0x8; |
| 40 | public final static short FRAG_VAL = (short) 0x10; |
| 41 | public final static short ROUTER_VAL = (short) 0x20; |
| 42 | public final static short HOP_VAL = (short) 0x40; |
| 43 | public final static short UNREP_VAL = (short) 0x80; |
| 44 | public final static short UNSEQ_VAL = (short) 0x100; |
| 45 | |
| 46 | public static Set<OFIpv6ExthdrFlags> 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<OFIpv6ExthdrFlags> set) { |
| 55 | bb.writeShort(toWireValue(set)); |
| 56 | } |
| 57 | |
| 58 | public static void putTo(Set<OFIpv6ExthdrFlags> set, PrimitiveSink sink) { |
| 59 | sink.putShort(toWireValue(set)); |
| 60 | } |
| 61 | |
| 62 | |
| 63 | public static Set<OFIpv6ExthdrFlags> ofWireValue(short val) { |
| 64 | EnumSet<OFIpv6ExthdrFlags> set = EnumSet.noneOf(OFIpv6ExthdrFlags.class); |
| 65 | |
| 66 | if((val & NONEXT_VAL) != 0) |
| 67 | set.add(OFIpv6ExthdrFlags.NONEXT); |
| 68 | if((val & ESP_VAL) != 0) |
| 69 | set.add(OFIpv6ExthdrFlags.ESP); |
| 70 | if((val & AUTH_VAL) != 0) |
| 71 | set.add(OFIpv6ExthdrFlags.AUTH); |
| 72 | if((val & DEST_VAL) != 0) |
| 73 | set.add(OFIpv6ExthdrFlags.DEST); |
| 74 | if((val & FRAG_VAL) != 0) |
| 75 | set.add(OFIpv6ExthdrFlags.FRAG); |
| 76 | if((val & ROUTER_VAL) != 0) |
| 77 | set.add(OFIpv6ExthdrFlags.ROUTER); |
| 78 | if((val & HOP_VAL) != 0) |
| 79 | set.add(OFIpv6ExthdrFlags.HOP); |
| 80 | if((val & UNREP_VAL) != 0) |
| 81 | set.add(OFIpv6ExthdrFlags.UNREP); |
| 82 | if((val & UNSEQ_VAL) != 0) |
| 83 | set.add(OFIpv6ExthdrFlags.UNSEQ); |
| 84 | return Collections.unmodifiableSet(set); |
| 85 | } |
| 86 | |
| 87 | public static short toWireValue(Set<OFIpv6ExthdrFlags> set) { |
| 88 | short wireValue = 0; |
| 89 | |
| 90 | for(OFIpv6ExthdrFlags e: set) { |
| 91 | switch(e) { |
| 92 | case NONEXT: |
| 93 | wireValue |= NONEXT_VAL; |
| 94 | break; |
| 95 | case ESP: |
| 96 | wireValue |= ESP_VAL; |
| 97 | break; |
| 98 | case AUTH: |
| 99 | wireValue |= AUTH_VAL; |
| 100 | break; |
| 101 | case DEST: |
| 102 | wireValue |= DEST_VAL; |
| 103 | break; |
| 104 | case FRAG: |
| 105 | wireValue |= FRAG_VAL; |
| 106 | break; |
| 107 | case ROUTER: |
| 108 | wireValue |= ROUTER_VAL; |
| 109 | break; |
| 110 | case HOP: |
| 111 | wireValue |= HOP_VAL; |
| 112 | break; |
| 113 | case UNREP: |
| 114 | wireValue |= UNREP_VAL; |
| 115 | break; |
| 116 | case UNSEQ: |
| 117 | wireValue |= UNSEQ_VAL; |
| 118 | break; |
| 119 | default: |
| 120 | throw new IllegalArgumentException("Illegal enum value for type OFIpv6ExthdrFlags in version 1.3: " + e); |
| 121 | } |
| 122 | } |
| 123 | return wireValue; |
| 124 | } |
| 125 | |
| 126 | } |