blob: 48b7191ea0aa2d6e6f7771fc47192d4c2ed19f58 [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.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.OFPortState;
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 OFPortStateSerializerVer10 {
35
36 public final static int LINK_DOWN_VAL = 0x1;
37 public final static int STP_LISTEN_VAL = 0x0;
38 public final static int STP_LEARN_VAL = 0x100;
39 public final static int STP_FORWARD_VAL = 0x200;
40 public final static int STP_BLOCK_VAL = 0x300;
41 public final static int STP_MASK_VAL = 0x300;
42
43 public static Set<OFPortState> readFrom(ChannelBuffer bb) throws OFParseError {
44 try {
45 return ofWireValue(bb.readInt());
46 } catch (IllegalArgumentException e) {
47 throw new OFParseError(e);
48 }
49 }
50
51 public static void writeTo(ChannelBuffer bb, Set<OFPortState> set) {
52 bb.writeInt(toWireValue(set));
53 }
54
55 public static void putTo(Set<OFPortState> set, PrimitiveSink sink) {
56 sink.putInt(toWireValue(set));
57 }
58
59
60 public static Set<OFPortState> ofWireValue(int val) {
61 EnumSet<OFPortState> set = EnumSet.noneOf(OFPortState.class);
62
63 if((val & LINK_DOWN_VAL) != 0)
64 set.add(OFPortState.LINK_DOWN);
65 if((val & STP_MASK_VAL) == STP_LISTEN_VAL)
66 set.add(OFPortState.STP_LISTEN);
67 else if((val & STP_MASK_VAL) == STP_LEARN_VAL)
68 set.add(OFPortState.STP_LEARN);
69 else if((val & STP_MASK_VAL) == STP_FORWARD_VAL)
70 set.add(OFPortState.STP_FORWARD);
71 else if((val & STP_MASK_VAL) == STP_BLOCK_VAL)
72 set.add(OFPortState.STP_BLOCK);
73 return Collections.unmodifiableSet(set);
74 }
75
76 public static int toWireValue(Set<OFPortState> set) {
77 int wireValue = 0;
78
79 for(OFPortState e: set) {
80 switch(e) {
81 case LINK_DOWN:
82 wireValue |= LINK_DOWN_VAL;
83 break;
84 case STP_LISTEN:
85 wireValue |= STP_LISTEN_VAL;
86 break;
87 case STP_LEARN:
88 wireValue |= STP_LEARN_VAL;
89 break;
90 case STP_FORWARD:
91 wireValue |= STP_FORWARD_VAL;
92 break;
93 case STP_BLOCK:
94 wireValue |= STP_BLOCK_VAL;
95 break;
96 default:
97 throw new IllegalArgumentException("Illegal enum value for type OFPortState in version 1.0: " + e);
98 }
99 }
100 return wireValue;
101 }
102
103}