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.OFFlowWildcards; |
| 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 OFFlowWildcardsSerializerVer11 { |
| 35 | |
| 36 | public final static int IN_PORT_VAL = 0x1; |
| 37 | public final static int DL_VLAN_VAL = 0x2; |
| 38 | public final static int DL_TYPE_VAL = 0x8; |
| 39 | public final static int NW_PROTO_VAL = 0x20; |
| 40 | public final static int TP_SRC_VAL = 0x40; |
| 41 | public final static int TP_DST_VAL = 0x80; |
| 42 | public final static int DL_VLAN_PCP_VAL = 0x4; |
| 43 | public final static int NW_TOS_VAL = 0x10; |
| 44 | public final static int ALL_VAL = 0x3ff; |
| 45 | public final static int MPLS_LABEL_VAL = 0x100; |
| 46 | public final static int MPLS_TC_VAL = 0x200; |
| 47 | |
| 48 | public static Set<OFFlowWildcards> readFrom(ChannelBuffer bb) throws OFParseError { |
| 49 | try { |
| 50 | return ofWireValue(bb.readInt()); |
| 51 | } catch (IllegalArgumentException e) { |
| 52 | throw new OFParseError(e); |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | public static void writeTo(ChannelBuffer bb, Set<OFFlowWildcards> set) { |
| 57 | bb.writeInt(toWireValue(set)); |
| 58 | } |
| 59 | |
| 60 | public static void putTo(Set<OFFlowWildcards> set, PrimitiveSink sink) { |
| 61 | sink.putInt(toWireValue(set)); |
| 62 | } |
| 63 | |
| 64 | |
| 65 | public static Set<OFFlowWildcards> ofWireValue(int val) { |
| 66 | EnumSet<OFFlowWildcards> set = EnumSet.noneOf(OFFlowWildcards.class); |
| 67 | |
| 68 | if((val & IN_PORT_VAL) != 0) |
| 69 | set.add(OFFlowWildcards.IN_PORT); |
| 70 | if((val & DL_VLAN_VAL) != 0) |
| 71 | set.add(OFFlowWildcards.DL_VLAN); |
| 72 | if((val & DL_TYPE_VAL) != 0) |
| 73 | set.add(OFFlowWildcards.DL_TYPE); |
| 74 | if((val & NW_PROTO_VAL) != 0) |
| 75 | set.add(OFFlowWildcards.NW_PROTO); |
| 76 | if((val & TP_SRC_VAL) != 0) |
| 77 | set.add(OFFlowWildcards.TP_SRC); |
| 78 | if((val & TP_DST_VAL) != 0) |
| 79 | set.add(OFFlowWildcards.TP_DST); |
| 80 | if((val & DL_VLAN_PCP_VAL) != 0) |
| 81 | set.add(OFFlowWildcards.DL_VLAN_PCP); |
| 82 | if((val & NW_TOS_VAL) != 0) |
| 83 | set.add(OFFlowWildcards.NW_TOS); |
| 84 | if((val & ALL_VAL) != 0) |
| 85 | set.add(OFFlowWildcards.ALL); |
| 86 | if((val & MPLS_LABEL_VAL) != 0) |
| 87 | set.add(OFFlowWildcards.MPLS_LABEL); |
| 88 | if((val & MPLS_TC_VAL) != 0) |
| 89 | set.add(OFFlowWildcards.MPLS_TC); |
| 90 | return Collections.unmodifiableSet(set); |
| 91 | } |
| 92 | |
| 93 | public static int toWireValue(Set<OFFlowWildcards> set) { |
| 94 | int wireValue = 0; |
| 95 | |
| 96 | for(OFFlowWildcards e: set) { |
| 97 | switch(e) { |
| 98 | case IN_PORT: |
| 99 | wireValue |= IN_PORT_VAL; |
| 100 | break; |
| 101 | case DL_VLAN: |
| 102 | wireValue |= DL_VLAN_VAL; |
| 103 | break; |
| 104 | case DL_TYPE: |
| 105 | wireValue |= DL_TYPE_VAL; |
| 106 | break; |
| 107 | case NW_PROTO: |
| 108 | wireValue |= NW_PROTO_VAL; |
| 109 | break; |
| 110 | case TP_SRC: |
| 111 | wireValue |= TP_SRC_VAL; |
| 112 | break; |
| 113 | case TP_DST: |
| 114 | wireValue |= TP_DST_VAL; |
| 115 | break; |
| 116 | case DL_VLAN_PCP: |
| 117 | wireValue |= DL_VLAN_PCP_VAL; |
| 118 | break; |
| 119 | case NW_TOS: |
| 120 | wireValue |= NW_TOS_VAL; |
| 121 | break; |
| 122 | case ALL: |
| 123 | wireValue |= ALL_VAL; |
| 124 | break; |
| 125 | case MPLS_LABEL: |
| 126 | wireValue |= MPLS_LABEL_VAL; |
| 127 | break; |
| 128 | case MPLS_TC: |
| 129 | wireValue |= MPLS_TC_VAL; |
| 130 | break; |
| 131 | default: |
| 132 | throw new IllegalArgumentException("Illegal enum value for type OFFlowWildcards in version 1.1: " + e); |
| 133 | } |
| 134 | } |
| 135 | return wireValue; |
| 136 | } |
| 137 | |
| 138 | } |