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.OFPortFeatures; |
| 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 OFPortFeaturesSerializerVer13 { |
| 35 | |
| 36 | public final static int PF_10MB_HD_VAL = 0x1; |
| 37 | public final static int PF_10MB_FD_VAL = 0x2; |
| 38 | public final static int PF_100MB_HD_VAL = 0x4; |
| 39 | public final static int PF_100MB_FD_VAL = 0x8; |
| 40 | public final static int PF_1GB_HD_VAL = 0x10; |
| 41 | public final static int PF_1GB_FD_VAL = 0x20; |
| 42 | public final static int PF_10GB_FD_VAL = 0x40; |
| 43 | public final static int PF_COPPER_VAL = 0x800; |
| 44 | public final static int PF_FIBER_VAL = 0x1000; |
| 45 | public final static int PF_AUTONEG_VAL = 0x2000; |
| 46 | public final static int PF_PAUSE_VAL = 0x4000; |
| 47 | public final static int PF_PAUSE_ASYM_VAL = 0x8000; |
| 48 | public final static int PF_40GB_FD_VAL = 0x80; |
| 49 | public final static int PF_100GB_FD_VAL = 0x100; |
| 50 | public final static int PF_1TB_FD_VAL = 0x200; |
| 51 | public final static int PF_OTHER_VAL = 0x400; |
| 52 | |
| 53 | public static Set<OFPortFeatures> readFrom(ChannelBuffer bb) throws OFParseError { |
| 54 | try { |
| 55 | return ofWireValue(bb.readInt()); |
| 56 | } catch (IllegalArgumentException e) { |
| 57 | throw new OFParseError(e); |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | public static void writeTo(ChannelBuffer bb, Set<OFPortFeatures> set) { |
| 62 | bb.writeInt(toWireValue(set)); |
| 63 | } |
| 64 | |
| 65 | public static void putTo(Set<OFPortFeatures> set, PrimitiveSink sink) { |
| 66 | sink.putInt(toWireValue(set)); |
| 67 | } |
| 68 | |
| 69 | |
| 70 | public static Set<OFPortFeatures> ofWireValue(int val) { |
| 71 | EnumSet<OFPortFeatures> set = EnumSet.noneOf(OFPortFeatures.class); |
| 72 | |
| 73 | if((val & PF_10MB_HD_VAL) != 0) |
| 74 | set.add(OFPortFeatures.PF_10MB_HD); |
| 75 | if((val & PF_10MB_FD_VAL) != 0) |
| 76 | set.add(OFPortFeatures.PF_10MB_FD); |
| 77 | if((val & PF_100MB_HD_VAL) != 0) |
| 78 | set.add(OFPortFeatures.PF_100MB_HD); |
| 79 | if((val & PF_100MB_FD_VAL) != 0) |
| 80 | set.add(OFPortFeatures.PF_100MB_FD); |
| 81 | if((val & PF_1GB_HD_VAL) != 0) |
| 82 | set.add(OFPortFeatures.PF_1GB_HD); |
| 83 | if((val & PF_1GB_FD_VAL) != 0) |
| 84 | set.add(OFPortFeatures.PF_1GB_FD); |
| 85 | if((val & PF_10GB_FD_VAL) != 0) |
| 86 | set.add(OFPortFeatures.PF_10GB_FD); |
| 87 | if((val & PF_COPPER_VAL) != 0) |
| 88 | set.add(OFPortFeatures.PF_COPPER); |
| 89 | if((val & PF_FIBER_VAL) != 0) |
| 90 | set.add(OFPortFeatures.PF_FIBER); |
| 91 | if((val & PF_AUTONEG_VAL) != 0) |
| 92 | set.add(OFPortFeatures.PF_AUTONEG); |
| 93 | if((val & PF_PAUSE_VAL) != 0) |
| 94 | set.add(OFPortFeatures.PF_PAUSE); |
| 95 | if((val & PF_PAUSE_ASYM_VAL) != 0) |
| 96 | set.add(OFPortFeatures.PF_PAUSE_ASYM); |
| 97 | if((val & PF_40GB_FD_VAL) != 0) |
| 98 | set.add(OFPortFeatures.PF_40GB_FD); |
| 99 | if((val & PF_100GB_FD_VAL) != 0) |
| 100 | set.add(OFPortFeatures.PF_100GB_FD); |
| 101 | if((val & PF_1TB_FD_VAL) != 0) |
| 102 | set.add(OFPortFeatures.PF_1TB_FD); |
| 103 | if((val & PF_OTHER_VAL) != 0) |
| 104 | set.add(OFPortFeatures.PF_OTHER); |
| 105 | return Collections.unmodifiableSet(set); |
| 106 | } |
| 107 | |
| 108 | public static int toWireValue(Set<OFPortFeatures> set) { |
| 109 | int wireValue = 0; |
| 110 | |
| 111 | for(OFPortFeatures e: set) { |
| 112 | switch(e) { |
| 113 | case PF_10MB_HD: |
| 114 | wireValue |= PF_10MB_HD_VAL; |
| 115 | break; |
| 116 | case PF_10MB_FD: |
| 117 | wireValue |= PF_10MB_FD_VAL; |
| 118 | break; |
| 119 | case PF_100MB_HD: |
| 120 | wireValue |= PF_100MB_HD_VAL; |
| 121 | break; |
| 122 | case PF_100MB_FD: |
| 123 | wireValue |= PF_100MB_FD_VAL; |
| 124 | break; |
| 125 | case PF_1GB_HD: |
| 126 | wireValue |= PF_1GB_HD_VAL; |
| 127 | break; |
| 128 | case PF_1GB_FD: |
| 129 | wireValue |= PF_1GB_FD_VAL; |
| 130 | break; |
| 131 | case PF_10GB_FD: |
| 132 | wireValue |= PF_10GB_FD_VAL; |
| 133 | break; |
| 134 | case PF_COPPER: |
| 135 | wireValue |= PF_COPPER_VAL; |
| 136 | break; |
| 137 | case PF_FIBER: |
| 138 | wireValue |= PF_FIBER_VAL; |
| 139 | break; |
| 140 | case PF_AUTONEG: |
| 141 | wireValue |= PF_AUTONEG_VAL; |
| 142 | break; |
| 143 | case PF_PAUSE: |
| 144 | wireValue |= PF_PAUSE_VAL; |
| 145 | break; |
| 146 | case PF_PAUSE_ASYM: |
| 147 | wireValue |= PF_PAUSE_ASYM_VAL; |
| 148 | break; |
| 149 | case PF_40GB_FD: |
| 150 | wireValue |= PF_40GB_FD_VAL; |
| 151 | break; |
| 152 | case PF_100GB_FD: |
| 153 | wireValue |= PF_100GB_FD_VAL; |
| 154 | break; |
| 155 | case PF_1TB_FD: |
| 156 | wireValue |= PF_1TB_FD_VAL; |
| 157 | break; |
| 158 | case PF_OTHER: |
| 159 | wireValue |= PF_OTHER_VAL; |
| 160 | break; |
| 161 | default: |
| 162 | throw new IllegalArgumentException("Illegal enum value for type OFPortFeatures in version 1.3: " + e); |
| 163 | } |
| 164 | } |
| 165 | return wireValue; |
| 166 | } |
| 167 | |
| 168 | } |