blob: 5715f17890759170b502631d1108a7782f55d345 [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.ver13;
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 OFInstructionTypeSerializerVer13 {
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 public final static short METER_VAL = (short) 0x6;
43
44 public static Set<OFInstructionType> readFrom(ChannelBuffer bb) throws OFParseError {
45 try {
46 return ofWireValue(bb.readShort());
47 } catch (IllegalArgumentException e) {
48 throw new OFParseError(e);
49 }
50 }
51
52 public static void writeTo(ChannelBuffer bb, Set<OFInstructionType> set) {
53 bb.writeShort(toWireValue(set));
54 }
55
56 public static void putTo(Set<OFInstructionType> set, PrimitiveSink sink) {
57 sink.putShort(toWireValue(set));
58 }
59
60
61 public static Set<OFInstructionType> ofWireValue(short val) {
62 EnumSet<OFInstructionType> set = EnumSet.noneOf(OFInstructionType.class);
63
64 if((val & GOTO_TABLE_VAL) != 0)
65 set.add(OFInstructionType.GOTO_TABLE);
66 if((val & WRITE_METADATA_VAL) != 0)
67 set.add(OFInstructionType.WRITE_METADATA);
68 if((val & WRITE_ACTIONS_VAL) != 0)
69 set.add(OFInstructionType.WRITE_ACTIONS);
70 if((val & APPLY_ACTIONS_VAL) != 0)
71 set.add(OFInstructionType.APPLY_ACTIONS);
72 if((val & CLEAR_ACTIONS_VAL) != 0)
73 set.add(OFInstructionType.CLEAR_ACTIONS);
74 if((val & EXPERIMENTER_VAL) != 0)
75 set.add(OFInstructionType.EXPERIMENTER);
76 if((val & METER_VAL) != 0)
77 set.add(OFInstructionType.METER);
78 return Collections.unmodifiableSet(set);
79 }
80
81 public static short toWireValue(Set<OFInstructionType> set) {
82 short wireValue = 0;
83
84 for(OFInstructionType e: set) {
85 switch(e) {
86 case GOTO_TABLE:
87 wireValue |= GOTO_TABLE_VAL;
88 break;
89 case WRITE_METADATA:
90 wireValue |= WRITE_METADATA_VAL;
91 break;
92 case WRITE_ACTIONS:
93 wireValue |= WRITE_ACTIONS_VAL;
94 break;
95 case APPLY_ACTIONS:
96 wireValue |= APPLY_ACTIONS_VAL;
97 break;
98 case CLEAR_ACTIONS:
99 wireValue |= CLEAR_ACTIONS_VAL;
100 break;
101 case EXPERIMENTER:
102 wireValue |= EXPERIMENTER_VAL;
103 break;
104 case METER:
105 wireValue |= METER_VAL;
106 break;
107 default:
108 throw new IllegalArgumentException("Illegal enum value for type OFInstructionType in version 1.3: " + e);
109 }
110 }
111 return wireValue;
112 }
113
114}