Changes between Version 2 and Version 3 of Internal/OpenFlow/VendorTutorial
- Timestamp:
- Dec 22, 2012, 5:08:17 AM (12 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Internal/OpenFlow/VendorTutorial
v2 v3 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 how to create custom vendor messages using openflowj (the Java OpenFlow implementation) and to use them in Floodlight.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 how to create custom vendor messages using openflowj (the Java !OpenFlow implementation) and to use them in Floodlight. 3 3 4 4 == Overview == 5 The vendor type message has its own header and a fully customizable payload.5 The vendor type message has its own message header and a fully customizable payload. 6 6 7 A vendor message must specify a vendor ID and a data type in its header. The vendor ID is a unique ID, typically the OUI, of the vendor implementing the custom message. 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".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". 8 8 9 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: … … 15 15 16 16 == In openflowj == 17 `OFVendorData` is the interface for the generic vendor message payload. All vendor type message payloads must implement `OFVendorData`. The vendor ID is also typically defined in the implementing class, as we see here in `OFNiciraVendorData`, the base class for all Nicira vendor messages:17 `OFVendorData`, located in package org.openflow.protocol.vendor, is the interface for the generic vendor message payload. All vendor type message payloads must implement `OFVendorData`. The vendor ID is also typically defined in the implementing class, as we see here in `OFNiciraVendorData`, the base class for all Nicira vendor messages: 18 18 {{{ 19 19 public class OFNiciraVendorData implements OFVendorData { … … 24 24 This base class can then be subclassed to implement the various types of this message. 25 25 26 The Vendor ID and !VendorData must be registered before it can properly be parsed by your controller. Floodlight's core controller class, `Controller`, registers each vendor message and its subtypes during startup by calling initVendorMessages():26 The Vendor ID and message classes must be registered before it can properly be parsed. This is a two step process. Using the method initVendorMessages() from Floodlight's core controller class `Controller`, we see that the vendor ID is registered first: 27 27 {{{ 28 private void initVendorMessages() { 29 // Configure openflowj to be able to parse the role request/reply vendor messages. 30 // first register the vendor ID 28 // Configure openflowj to be able to parse the role request/reply vendor messages. 29 // first register the vendor ID 31 30 OFBasicVendorId niciraVendorId = new OFBasicVendorId( 32 31 OFNiciraVendorData.NX_VENDOR_ID, 4); 33 32 OFVendorId.registerVendorId(niciraVendorId); 34 // then each data type 33 }}} 34 Vendor IDs may vary in length - we indicate that the Nicira vendor ID is an Integer (4B) when we instantiate the !OFBasicVendorId, Next is the registration of each subclass representing a message type: 35 {{{ 36 // then each data type, starting with reqest 35 37 OFBasicVendorDataType roleRequestVendorData = 36 38 new OFBasicVendorDataType( … … 38 40 OFRoleRequestVendorData.getInstantiable()); 39 41 niciraVendorId.registerVendorDataType(roleRequestVendorData); 42 43 //then the repy 40 44 OFBasicVendorDataType roleReplyVendorData = 41 45 new OFBasicVendorDataType( … … 43 47 OFRoleReplyVendorData.getInstantiable()); 44 48 niciraVendorId.registerVendorDataType(roleReplyVendorData); 45 }46 49 }}} 47 Where NXT_ROLE_REQUEST and NXT_ROLE_REPLY are the request and reply data type s.50 Where NXT_ROLE_REQUEST and NXT_ROLE_REPLY are the request and reply data type values for the two Nicira vendor message types. 48 51 49 As seen above in the instantiation of the OFBasicVendorDataType, 50 the class implementing the vendor data should be instantiable, so that 51 it can be registered properly by the controller. It seems customary to 52 provide a method, getInstantiable(), for this purpose. This belongs in 53 the subclass that defines the actual vendor data payload. The code that 54 does this may look like this: 52 As seen above in the instantiation of the OFBasicVendorDataType, the class implementing the vendor data should be instantiable, so that it can be registered properly by the controller. The method getInstantiable() should be available in your message class for this purpose, and look like this: 55 53 {{{ 56 54 protected static Instantiable<OFVendorData> instantiable = 57 55 new Instantiable<OFVendorData>() { 58 56 public OFVendorData instantiate() { 59 return new OF ExportsReply();57 return new OFRoleRequestVendorData(); 60 58 } 61 59 }; … … 69 67 } 70 68 }}} 71 The above sample was modified slightly to fit my vendor message, but 72 was almost taken, word-for-word, from the Nicira vendor messages. 69 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. 73 70 74 A non-registered Vendor message data payload is interpreted simply as a byte array (OFByteArrayVendorData to be precise), and is not easily processed e.g. the methods in your VendorData classes would not be applicable as you would not be able to cast the byte array to your message (sub)class(es). 75 71 Each class implementing OFVendorData has 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 messaes is also required for reading. This value does not count the !OpenFlow header, which is added in by helper methods to produce the total message length. The message length must be correct in order for it to be processed by the !OpenFlow channel pipeline.