blob: b19e2e3d393d8878e9217bda9d68d8d7c1a8b005 [file] [log] [blame]
tom7ef8ff92014-09-17 13:08:06 -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.ver10;
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.OFPortFeatures;
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 OFPortFeaturesSerializerVer10 {
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 = 0x80;
44 public final static int PF_FIBER_VAL = 0x100;
45 public final static int PF_AUTONEG_VAL = 0x200;
46 public final static int PF_PAUSE_VAL = 0x400;
47 public final static int PF_PAUSE_ASYM_VAL = 0x800;
48
49 public static Set<OFPortFeatures> readFrom(ChannelBuffer bb) throws OFParseError {
50 try {
51 return ofWireValue(bb.readInt());
52 } catch (IllegalArgumentException e) {
53 throw new OFParseError(e);
54 }
55 }
56
57 public static void writeTo(ChannelBuffer bb, Set<OFPortFeatures> set) {
58 bb.writeInt(toWireValue(set));
59 }
60
61 public static void putTo(Set<OFPortFeatures> set, PrimitiveSink sink) {
62 sink.putInt(toWireValue(set));
63 }
64
65
66 public static Set<OFPortFeatures> ofWireValue(int val) {
67 EnumSet<OFPortFeatures> set = EnumSet.noneOf(OFPortFeatures.class);
68
69 if((val & PF_10MB_HD_VAL) != 0)
70 set.add(OFPortFeatures.PF_10MB_HD);
71 if((val & PF_10MB_FD_VAL) != 0)
72 set.add(OFPortFeatures.PF_10MB_FD);
73 if((val & PF_100MB_HD_VAL) != 0)
74 set.add(OFPortFeatures.PF_100MB_HD);
75 if((val & PF_100MB_FD_VAL) != 0)
76 set.add(OFPortFeatures.PF_100MB_FD);
77 if((val & PF_1GB_HD_VAL) != 0)
78 set.add(OFPortFeatures.PF_1GB_HD);
79 if((val & PF_1GB_FD_VAL) != 0)
80 set.add(OFPortFeatures.PF_1GB_FD);
81 if((val & PF_10GB_FD_VAL) != 0)
82 set.add(OFPortFeatures.PF_10GB_FD);
83 if((val & PF_COPPER_VAL) != 0)
84 set.add(OFPortFeatures.PF_COPPER);
85 if((val & PF_FIBER_VAL) != 0)
86 set.add(OFPortFeatures.PF_FIBER);
87 if((val & PF_AUTONEG_VAL) != 0)
88 set.add(OFPortFeatures.PF_AUTONEG);
89 if((val & PF_PAUSE_VAL) != 0)
90 set.add(OFPortFeatures.PF_PAUSE);
91 if((val & PF_PAUSE_ASYM_VAL) != 0)
92 set.add(OFPortFeatures.PF_PAUSE_ASYM);
93 return Collections.unmodifiableSet(set);
94 }
95
96 public static int toWireValue(Set<OFPortFeatures> set) {
97 int wireValue = 0;
98
99 for(OFPortFeatures e: set) {
100 switch(e) {
101 case PF_10MB_HD:
102 wireValue |= PF_10MB_HD_VAL;
103 break;
104 case PF_10MB_FD:
105 wireValue |= PF_10MB_FD_VAL;
106 break;
107 case PF_100MB_HD:
108 wireValue |= PF_100MB_HD_VAL;
109 break;
110 case PF_100MB_FD:
111 wireValue |= PF_100MB_FD_VAL;
112 break;
113 case PF_1GB_HD:
114 wireValue |= PF_1GB_HD_VAL;
115 break;
116 case PF_1GB_FD:
117 wireValue |= PF_1GB_FD_VAL;
118 break;
119 case PF_10GB_FD:
120 wireValue |= PF_10GB_FD_VAL;
121 break;
122 case PF_COPPER:
123 wireValue |= PF_COPPER_VAL;
124 break;
125 case PF_FIBER:
126 wireValue |= PF_FIBER_VAL;
127 break;
128 case PF_AUTONEG:
129 wireValue |= PF_AUTONEG_VAL;
130 break;
131 case PF_PAUSE:
132 wireValue |= PF_PAUSE_VAL;
133 break;
134 case PF_PAUSE_ASYM:
135 wireValue |= PF_PAUSE_ASYM_VAL;
136 break;
137 default:
138 throw new IllegalArgumentException("Illegal enum value for type OFPortFeatures in version 1.0: " + e);
139 }
140 }
141 return wireValue;
142 }
143
144}