blob: e7c8bf2135b875a74bd14c0ad5393529a3e6e53b [file] [log] [blame]
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -08001/**
2* Copyright 2011, Big Switch Networks, Inc.
3* Originally created by David Erickson & Rob Sherwood, Stanford University
4*
5* Licensed under the Apache License, Version 2.0 (the "License"); you may
6* not use this file except in compliance with the License. You may obtain
7* a copy of the License at
8*
9* http://www.apache.org/licenses/LICENSE-2.0
10*
11* Unless required by applicable law or agreed to in writing, software
12* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14* License for the specific language governing permissions and limitations
15* under the License.
16**/
17
18package org.openflow.vendor.nicira;
19
20import org.jboss.netty.buffer.ChannelBuffer;
21
22/**
23 * Class that represents the vendor data in the role request
24 * extension implemented by Open vSwitch to support high availability.
25 *
26 * @author Rob Vaterlaus (rob.vaterlaus@bigswitch.com)
27 */
28public class OFRoleVendorData extends OFNiciraVendorData {
29
30 /**
31 * Role value indicating that the controller is in the OTHER role.
32 */
33 public static final int NX_ROLE_OTHER = 0;
34
35 /**
36 * Role value indicating that the controller is in the MASTER role.
37 */
38 public static final int NX_ROLE_MASTER = 1;
39
40 /**
41 * Role value indicating that the controller is in the SLAVE role.
42 */
43 public static final int NX_ROLE_SLAVE = 2;
44
45 protected int role;
46
47 /**
48 * Construct an uninitialized OFRoleVendorData
49 */
50 public OFRoleVendorData() {
51 super();
52 }
53
54 /**
55 * Construct an OFRoleVendorData with the specified data type
56 * (i.e. either request or reply) and an unspecified role.
57 * @param dataType
58 */
59 public OFRoleVendorData(int dataType) {
60 super(dataType);
61 }
62
63 /**
64 * Construct an OFRoleVendorData with the specified data type
65 * (i.e. either request or reply) and role (i.e. one of of
66 * master, slave, or other).
67 * @param dataType either role request or role reply data type
68 */
69 public OFRoleVendorData(int dataType, int role) {
70 super(dataType);
71 this.role = role;
72 }
73 /**
74 * @return the role value of the role vendor data
75 */
76 public int getRole() {
77 return role;
78 }
79
80 /**
81 * @param role the role value of the role vendor data
82 */
83 public void setRole(int role) {
84 this.role = role;
85 }
86
87 /**
88 * @return the total length of the role vendor data
89 */
90 @Override
91 public int getLength() {
92 return super.getLength() + 4;
93 }
94
95 /**
96 * Read the role vendor data from the ChannelBuffer
97 * @param data the channel buffer from which we're deserializing
98 * @param length the length to the end of the enclosing message
99 */
100 public void readFrom(ChannelBuffer data, int length) {
101 super.readFrom(data, length);
102 role = data.readInt();
103 }
104
105 /**
106 * Write the role vendor data to the ChannelBuffer
107 * @param data the channel buffer to which we're serializing
108 */
109 public void writeTo(ChannelBuffer data) {
110 super.writeTo(data);
111 data.writeInt(role);
112 }
113}