Changes between Version 5 and Version 6 of Internal/OpenFlow/VendorTutorial
- Timestamp:
- Dec 28, 2012, 5:17:15 AM (12 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Internal/OpenFlow/VendorTutorial
v5 v6 1 1 = How-To: Extending OpenFlow with Vendor messages = 2 !OpenFlow provides a vendor message type as a way to offer third parties a way to customize the protocol without going out of spec. This tutorial attempts to describe the openflowj implementations of the vendor type message and how to use them in Floodlight. We'll mostly use snippets of the Nicira vendor messages, found in org.openflow.vendor.nicira, as examples in this page.2 This tutorial attempts to describe how to use the !OpenFlow vendor message to create custom messages. We first provide an overview of the message structure. We then describe the vendor message implementations found in openflowj, the Java implementations of the !OpenFlow protocol used in Floodlight and !FlowVisor. 3 3 4 == Overview == 4 We'll mostly use snippets of the Nicira vendor messages, found in org.openflow.vendor.nicira of the Floodlight source, as working examples in this page. The Nicira extensions add !OpenFlow role features, introduced in !OpenFlow v1.2, to the v1.0 protocol used in Floodlight. 5 6 == 1. Overview: The Vendor Message == 7 !OpenFlow provides a vendor message type as a way to offer third parties a way to customize the protocol without going out of spec. Although called the "Vendor message", this message type provides a handy way for a developer to implement and test out experimental features without wantonly modifying the protocol. 8 5 9 Vendor messages are identified by !OpenFlow message type (OFType) value of 4. In addition to the standard !OpenFlow header, The vendor type message has its own message header and a fully customizable payload. 6 10 7 A vendor message header contains a vendor ID and a data type. The vendor ID identifies the vendor implementing the custom message, and is typically the OUI of the vendor. The data type is used to indicate any subtypes that this message may have. For example, Nicira's vendor messages use Nicira's OUI (002320) as the vendor ID and come in two types, a Request and Reply, indicated by the data types of "10" and "11".11 A vendor message header contains a vendor ID and a data type. The vendor ID identifies the vendor implementing the custom message, and is typically the organizationally unique identifier (OUI) of the vendor. As an individual, you can randomly pick and use an integral value for this purpose and nothing would balk at this, but this is highly discouraged. The proper conduct for this case is either to use your institution's OUI (if it has one), or to apply for an ID from the Open Networking Foundation (see [https://www.opennetworking.org/wiki/display/PUBLIC/ONF+Registry here] for details). 8 12 9 The rest of the message is the vendor message payload, and can be freely defined. To sum it up, the full !OpenFlow vendor message takes on the following format: 10 {{{ 11 <-------OpenFlow header-------><---Vendor message header--><----Vendor message payload-----> 12 [OF ver(1)|OFType(1)|length(2)][Vendor ID(2-8)|dataType(4)][user-defined structures(varied)] 13 }}} 14 Where the numbers in the parenthesis denote the field size in Bytes. The Vendor message header and payloads, in combination, make up the full payload of the vendor message. 13 The data type is used to indicate any subtypes that this message may have. For example, Nicira's vendor messages use Nicira's OUI (002320) as the vendor ID and comes in two types, a Request and Reply, indicated by the data type values of "10" and "11". 15 14 16 == In openflowj == 17 The base interface and framework needed for defining vendor messages are found in the package org.openflow.protocol.vendor. 15 The rest of the message is the vendor message payload, and can be freely defined. To sum it up, the full !OpenFlow vendor message takes on the following general format: 16 {{{ 17 |<------OpenFlow header------>||<----------------------Vendor Data------------------------>| 18 | ||<-Vendor message header-->||<---Vendor message payload---->| 19 [OF ver(1)|OFType(1)|length(2)][Vendor ID(2-8)|dataType(4)][user-defined structures(varied)] 20 }}} 21 Where the numbers in the parenthesis denote the field size in bytes. The vendor message header and payload in combination make up the full payload of the !OpenFlow message, the vendor data. 18 22 19 `OFVendorData` is the Java interface for the full payload. All vendor type messages must implement `OFVendorData`. The vendor message header is typically defined in the class that implements this interface. As an example, the vendor ID and data type are part of `OFNiciraVendorData`, the base class for all Nicira vendor messages: 23 == 2. In openflowj == #iface 24 In openflowj, the base interface and framework needed for creating vendor messages are found in the package org.openflow.protocol.vendor. Specifically, openflowj provides developers with a way to define custom vendor data classes. 25 26 `OFVendorData` is the Java interface required by any class defining custom vendor data. `OFVendorData` imposes just a few methods on a class implementing it: 27 28 * getLength() : return length of the data 29 * readFrom(!ChannelBuffer data, int length) : Read the vendor data from the specified !ChannelBuffer 30 * writeTo(!ChannelBuffer data) : Write the vendor data to the specified !ChannelBuffer 31 32 These methods are needed for the serialization/deserialization of the message. 33 34 === 2.1 The Vendor Message Header === 35 What we're referring to as the vendor message header is typically a set of variables defined in the class that implements `OFVendorData`. The class in which these variables are declared typically becomes the base class for further message types. 36 37 For example, the vendor ID and data type are part of `OFNiciraVendorData`, the base class for all Nicira vendor messages: 20 38 {{{ 21 39 public class OFNiciraVendorData implements OFVendorData { … … 29 47 ... 30 48 }}} 31 This base class is extended to implement the Request and Reply message types (OFRoleRequestVendorData and OFRoleReplyVendorData, respectively). 49 This class is extended to implement the Request and Reply message types (`OFRoleRequestVendorData` and `OFRoleReplyVendorData`, respectively). Note how the value of dataType is not set here - this value is set with the values declared in each subclass, as we can see here in `OFRoleReplyVendorData`: 50 {{{ 51 /** 52 * The data type value for a role reply 53 */ 54 public static final int NXT_ROLE_REPLY = 11; 32 55 33 The Vendor ID and data type are the only requirements in terms of vendor header content. The rest may be structured as needed, such as various message fields, getters and setters, and !ChannelBuffer manipulators, which we'll discuss in the section on [#serial serialization]. 56 /** 57 * Construct a role reply vendor data with an unspecified role value. 58 */ 59 public OFRoleReplyVendorData() { 60 super(NXT_ROLE_REPLY); 61 } 62 }}} 63 super() refers to `OFRoleVendorData`, a subclass of `OFNiciraVendorData`. Tracing back a step further, we end up in `OFNiciraVendorData` whose constructor sets the value of dataType: 64 {{{ 65 /** 66 * Contruct Nicira vendor data with the specified data type 67 * @param dataType the data type value at the beginning of the vendor data. 68 */ 69 public OFNiciraVendorData(int dataType) { 70 this.dataType = dataType; 71 } 72 }}} 34 73 35 === Message Registration === 36 The Vendor ID and message classes must be registered before it can properly be parsed. This is a two step process: 74 The Vendor ID and data type are the only requirements in terms of vendor header content. Given that the methods required by `OFVendorData` are provided, along with those required for message registration, the message implementation may be structured as needed. The usual additions are various message fields and their getters and setters. 75 76 === 2.2 Message Registration === 77 As expected from the variable structure of vendor messages, a given vendor message must be registered before openflowj can handle it properly. Registration is a two step process: 78 37 79 1. Vendor ID registration 38 80 2. Message type registration 39 81 40 We c n confirm this by taking a look at the method ''initVendorMessages()'' from Floodlight's core controller class `Controller`. We see that (1) the vendor ID is registered first, and (2) followed by each subclass representing a message type:82 We can see this by taking a look at the method ''initVendorMessages()'' from Floodlight's core controller class `Controller`. We see that (1) the vendor ID is registered first, and (2),(3) followed by each class representing a message type: 41 83 {{{ 42 84 // Configure openflowj to be able to parse the role request/reply vendor messages. … … 53 95 niciraVendorId.registerVendorDataType(roleRequestVendorData); 54 96 55 // then the repy97 // then the reply 56 98 OFBasicVendorDataType roleReplyVendorData = (3) 57 99 new OFBasicVendorDataType( … … 61 103 62 104 }}} 63 Where NXT_ROLE_REQUEST and NXT_ROLE_REPLY are the request and reply data type values for the two Nicira vendor message data types.105 Where, as seen earlier, NXT_ROLE_REQUEST and NXT_ROLE_REPLY are the request and reply data type values for the two Nicira vendor message data types. 64 106 65 Several things to point out here:66 *Since vendor IDs may vary in length, we indicate the length in bytes that the vendor ID is when we instantiate the OFBasicVendorId. In (1) we provide the constructor with the value 4 along with the actual Vendor ID, indicating that the Nicira vendor ID is an integer (4 bytes long).107 There are several things to point out here: 108 1. Since vendor IDs may vary in length, we indicate the length in bytes that the vendor ID is when we instantiate the OFBasicVendorId. In (1) we provide the constructor with the value 4 along with the actual Vendor ID, indicating that the Nicira vendor ID is an integer (4 bytes long). 67 109 68 * As seen above in (2) and (3), the class implementing the vendor data should be instantiable, so that it can be registered properly. The method getInstantiable() should be available in your message classes for this purpose. The following snippet was taken from `OFRoleRequestVendorData`, but the structure will pretty much be the same for any vendor data class (e.g. replace OFRoleRequestVendorData below with your class): 110 2. As seen above in (2) and (3), the class implementing the vendor data should include the method ''getInstantiable()''. `OFBasicVendorDataType`, is a container for an instantiator of a `OFVendorData` subclass. By allowing the custom class to provide it a format, `OFBasicVendorDataType` avoids making assumptions about the structure of the message payload. 111 112 2. indicates that we also need a ''getInstantiable()'' in our vendor data. The following snippet was taken from `OFRoleRequestVendorData`, but the structure will pretty much be the same for any vendor data class (e.g. replace OFRoleRequestVendorData below with your class): 69 113 {{{ 70 114 protected static Instantiable<OFVendorData> instantiable = … … 83 127 } 84 128 }}} 85 A non-registered Vendor message data payload is interpreted simply as a byte array (OFByteArrayVendorData to be precise), and cannot be cast to your message (sub)class(es) for further handling. 129 A non-registered Vendor message data payload is interpreted simply as a byte array (OFByteArrayVendorData to be precise), and cannot be cast to your message (sub)class(es) for further handling. Aside from throwing a !ClassCastException, this is inconvenient since you won't be able to invoke the class methods specific to your vendor data class for message-specific processing. 86 130 87 === Message Serialization === #serial88 Each class implementing OFVendorData must have a readFrom(!ChannelBuffer data, int length) and writeTo(!ChannelBuffer data) method for reading and writing the data from/to a !ChannelBuffer. A getLength() method that returns the size of the messages is also required for reading. This value does not count the !OpenFlow header, which is added in by helper methods to produce the full message length. The message length must be correct in order for it to be processed by the !OpenFlow channel pipeline. 131 === 2.3 Message Serialization === #serial 132 As mentioned [#iface earlier], a class implementing OFVendorData must have a readFrom(!ChannelBuffer data, int length) and writeTo(!ChannelBuffer data) method for reading and writing the data from/to a !ChannelBuffer. A getLength() method that returns the size of the vendor data sans the Vendor ID in bytes is also required for properly reading/writing from the !ChannelBuffer. We do not count the !OpenFlow header length since helper methods take it into account along with the Vendor ID length to produce the full message length. 89 133 90 The packet structure is determined by the order in which the various fields are written to the !ChannelBuffer, so readFrom() and writeTo() should read/write the fields in the same order.134 The packet structure is determined by the order in which the various fields are written to the !ChannelBuffer, so readFrom() and writeTo() should read/write the fields to/from the !ChannelBuffer in the same order. 91 135 92 == In Floodlight == 93 Floodlight uses openflowj as its !OpenFlow implementation. Custom vendor messages are usually placed in their own packages, such as org.openflow.vendor.nicira for Nicira messages. Message registration occurs, as mentioned before, in method ''initVendorMessages()'' in `Controller.java`, found in net.floodlightcontroller.core.internal. 136 As an example, we can look at `OFRoleVendorData`, the parent class of the Nicira Request and Reply messages. Since both messages only differ in the values of the ''role'' field, the readFrom(), writeTo(), and getLength() methods for the final packet structure are defined in this class. The message structure looks like this: 137 {{{ 138 |<-Vendor ID->||<-dataType->|<----payload(4)--->| 139 [OpenFlow Header][ 0x00002320 ][ 10|11 ][ 0|1|2 ] 140 }}} 141 Where the values within the square brackets separated by pipes are the various decimal values that the fields can take. What we had dubbed the vendor payload is one integral value of 4 bytes, used to indicate controller role. The packet structure is reflected in readFrom() and writeTo(): 142 {{{ 143 public void readFrom(ChannelBuffer data, int length) { 144 super.readFrom(data, length); 145 role = data.readInt(); 146 } 147 148 public void writeTo(ChannelBuffer data) { 149 super.writeTo(data); 150 data.writeInt(role); 151 } 152 }}} 153 super() points to `OFNiciraVendorData`, which takes care of reading and writing the integral dataType field: 154 {{{ 155 @Override 156 public void readFrom(ChannelBuffer data, int length) { 157 dataType = data.readInt(); 158 } 159 160 @Override 161 public void writeTo(ChannelBuffer data) { 162 data.writeInt(dataType); 163 } 164 }}} 165 166 As for getLength(), the total returned is the length of the two fields (8 bytes). looking at the two classes side-by-side makes this clear. First `OFRoleVendorData`: 167 {{{ 168 @Override 169 public int getLength() { 170 return super.getLength() + 4; 171 } 172 }}} 173 Then `OFNiciraVendorData`: 174 {{{ 175 @Override 176 public int getLength() { 177 return 4; 178 } 179 }}}