Changes between Version 7 and Version 8 of Internal/OpenFlow/VendorTutorial
- Timestamp:
- Jan 2, 2013, 10:17:34 PM (12 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Internal/OpenFlow/VendorTutorial
v7 v8 4 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 5 6 == 1. Overview: The Vendor Message == 6 == 1. Overview: The Vendor Message == #intro 7 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 8 … … 44 44 * at the beginning of the vendor data 45 45 */ 46 protected int dataType; 46 protected int dataType; (1) 47 47 ... 48 48 }}} 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; 55 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: 49 This class is extended to implement the Request and Reply message types (`OFRoleRequestVendorData` and `OFRoleReplyVendorData`, respectively). Note how at (1) the value of dataType is not set here - this value is set through the base class's constructor, which takes a integer value for the !dataType: 64 50 {{{ 65 51 /** … … 71 57 } 72 58 }}} 59 The values passed to this constructor are declared in each subclass that represents a message type, as we can see here in `OFRoleReplyVendorData`: 60 {{{ 61 /** 62 * The data type value for a role reply 63 */ 64 public static final int NXT_ROLE_REPLY = 11; 65 66 /** 67 * Construct a role reply vendor data with an unspecified role value. 68 */ 69 public OFRoleReplyVendorData() { 70 super(NXT_ROLE_REPLY); 71 } 72 }}} 73 If we trace back, we learn that super() above refers to the constructor of `OFRoleVendorData`, a subclass of `OFNiciraVendorData`. `OFRoleVendorData` takes the value passed to it by `OFRoleReplyVendorData` and passes it to the constructor of its parent class. 74 75 This organization isn't a requirement, but makes code reuse easier. The "nesting" of message classes can be thought of as implementing the message structure in layers - Each subclass implements message components that are encapsulated by components implemented in its parent class. 73 76 74 77 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 78 76 79 === 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 itproperly. Registration is a two step process:80 As expected from the variable structure of vendor messages, a given vendor message must be registered with openflowj before it can handle your messages properly. Registration is a two step process: 78 81 79 82 1. Vendor ID registration … … 105 108 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. 106 109 107 There are severalthings to point out here:110 There are two things to point out here: 108 111 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). 109 112 110 2. As seen above in (2) and (3), the class implementing the vendor data should include a way to provide an instantiator. The instantiator provides `OFBasicVendorDataType` with a format that allows it toavoid making assumptions about the structure of the vendor data. The method ''getInstantiable()'' returns an instantiator for the class.113 2. As seen above in (2) and (3), the class implementing vendor data must provide an instantiator. The instantiator provides `OFBasicVendorDataType` with a format that allows it to safely avoid making assumptions about the structure of the vendor data. The method ''getInstantiable()'' returns an instantiator for the class. 111 114 112 Point 2. indicates that we need a ''getInstantiable()'' (or something of equal function) 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):115 The second point indicates that we need a ''getInstantiable()'' (or something of equal function) in our vendor data class. 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): 113 116 {{{ 114 117 protected static Instantiable<OFVendorData> instantiable = … … 127 130 } 128 131 }}} 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.132 A non-registered Vendor message data payload is interpreted simply as a byte array (an OFByteArrayVendorData object, to be precise), and cannot be cast to your message (sub)class(es) for further handling. Aside from throwing a !ClassCastException if you try, this is inconvenient since you won't be able to invoke the class methods specific to your vendor data class for message-specific processing. 130 133 131 134 === 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 bytesis 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.135 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 in bytes of the vendor data, minus the Vendor ID length, 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. 133 136 134 137 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. … … 139 142 [OpenFlow Header][ 0x00002320 ][ 10|11 ][ 0|1|2 ] 140 143 }}} 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 payloadis one integral value of 4 bytes, used to indicate controller role. The packet structure is reflected in readFrom() and writeTo():144 Where the values within the square brackets separated by pipes are the various decimal values that the fields can take. For this message, what we had dubbed the vendor message payload in section [#intro 1] is one integral value of 4 bytes, used to indicate controller role. The packet structure is reflected in readFrom() and writeTo(): 142 145 {{{ 143 146 public void readFrom(ChannelBuffer data, int length) {