blob: c9b87ba839edd586c0f1cf1bd0ee1787c4263b63 [file] [log] [blame]
tom0eb04ca2014-08-25 14:34:51 -07001// 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
10package org.projectfloodlight.openflow.protocol.ver12;
11
12import org.projectfloodlight.openflow.protocol.*;
13import org.projectfloodlight.openflow.protocol.action.*;
14import org.projectfloodlight.openflow.protocol.actionid.*;
15import org.projectfloodlight.openflow.protocol.bsntlv.*;
16import org.projectfloodlight.openflow.protocol.errormsg.*;
17import org.projectfloodlight.openflow.protocol.meterband.*;
18import org.projectfloodlight.openflow.protocol.instruction.*;
19import org.projectfloodlight.openflow.protocol.instructionid.*;
20import org.projectfloodlight.openflow.protocol.match.*;
21import org.projectfloodlight.openflow.protocol.oxm.*;
22import org.projectfloodlight.openflow.protocol.queueprop.*;
23import org.projectfloodlight.openflow.types.*;
24import org.projectfloodlight.openflow.util.*;
25import org.projectfloodlight.openflow.exceptions.*;
26import org.projectfloodlight.openflow.protocol.OFInstructionType;
27import java.util.Set;
28import org.jboss.netty.buffer.ChannelBuffer;
29import com.google.common.hash.PrimitiveSink;
30import java.util.EnumSet;
31import java.util.Collections;
32
33
34public class OFInstructionTypeSerializerVer12 {
35
36 public final static short GOTO_TABLE_VAL = (short) 0x1;
37 public final static short WRITE_METADATA_VAL = (short) 0x2;
38 public final static short WRITE_ACTIONS_VAL = (short) 0x3;
39 public final static short APPLY_ACTIONS_VAL = (short) 0x4;
40 public final static short CLEAR_ACTIONS_VAL = (short) 0x5;
41 public final static short EXPERIMENTER_VAL = (short) 0xffff;
42
43 public static Set<OFInstructionType> readFrom(ChannelBuffer bb) throws OFParseError {
44 try {
45 return ofWireValue(bb.readShort());
46 } catch (IllegalArgumentException e) {
47 throw new OFParseError(e);
48 }
49 }
50
51 public static void writeTo(ChannelBuffer bb, Set<OFInstructionType> set) {
52 bb.writeShort(toWireValue(set));
53 }
54
55 public static void putTo(Set<OFInstructionType> set, PrimitiveSink sink) {
56 sink.putShort(toWireValue(set));
57 }
58
59
60 public static Set<OFInstructionType> ofWireValue(short val) {
61 EnumSet<OFInstructionType> set = EnumSet.noneOf(OFInstructionType.class);
62
63 if((val & GOTO_TABLE_VAL) != 0)
64 set.add(OFInstructionType.GOTO_TABLE);
65 if((val & WRITE_METADATA_VAL) != 0)
66 set.add(OFInstructionType.WRITE_METADATA);
67 if((val & WRITE_ACTIONS_VAL) != 0)
68 set.add(OFInstructionType.WRITE_ACTIONS);
69 if((val & APPLY_ACTIONS_VAL) != 0)
70 set.add(OFInstructionType.APPLY_ACTIONS);
71 if((val & CLEAR_ACTIONS_VAL) != 0)
72 set.add(OFInstructionType.CLEAR_ACTIONS);
73 if((val & EXPERIMENTER_VAL) != 0)
74 set.add(OFInstructionType.EXPERIMENTER);
75 return Collections.unmodifiableSet(set);
76 }
77
78 public static short toWireValue(Set<OFInstructionType> set) {
79 short wireValue = 0;
80
81 for(OFInstructionType e: set) {
82 switch(e) {
83 case GOTO_TABLE:
84 wireValue |= GOTO_TABLE_VAL;
85 break;
86 case WRITE_METADATA:
87 wireValue |= WRITE_METADATA_VAL;
88 break;
89 case WRITE_ACTIONS:
90 wireValue |= WRITE_ACTIONS_VAL;
91 break;
92 case APPLY_ACTIONS:
93 wireValue |= APPLY_ACTIONS_VAL;
94 break;
95 case CLEAR_ACTIONS:
96 wireValue |= CLEAR_ACTIONS_VAL;
97 break;
98 case EXPERIMENTER:
99 wireValue |= EXPERIMENTER_VAL;
100 break;
101 default:
102 throw new IllegalArgumentException("Illegal enum value for type OFInstructionType in version 1.2: " + e);
103 }
104 }
105 return wireValue;
106 }
107
108}