= How-To: Extending OpenFlow with Vendor messages = !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. == Overview == The vendor type message has its own header and a fully customizable payload. 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". 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: {{{ <-------OpenFlow header-------><---Vendor message header--><----vendor message payload-----> [OF ver(1)|OFType(1)|length(2)][Vendor ID(2-8)|dataType(4)][user-defined structures(varied)] }}} Where the numbers in the parenthesis denote the field size in Bytes. Vendor messages are identified by !OpenFlow message type (OFType) value of 4. == In openflowj == `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: {{{ public class OFNiciraVendorData implements OFVendorData { public static final int NX_VENDOR_ID = 0x00002320; ... }}} This base class can then be subclassed to implement the various types of this message. 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(): {{{ private void initVendorMessages() { // Configure openflowj to be able to parse the role request/reply vendor messages. // first register the vendor ID OFBasicVendorId niciraVendorId = new OFBasicVendorId( OFNiciraVendorData.NX_VENDOR_ID, 4); OFVendorId.registerVendorId(niciraVendorId); // then each data type OFBasicVendorDataType roleRequestVendorData = new OFBasicVendorDataType( OFRoleRequestVendorData.NXT_ROLE_REQUEST, OFRoleRequestVendorData.getInstantiable()); niciraVendorId.registerVendorDataType(roleRequestVendorData); OFBasicVendorDataType roleReplyVendorData = new OFBasicVendorDataType( OFRoleReplyVendorData.NXT_ROLE_REPLY, OFRoleReplyVendorData.getInstantiable()); niciraVendorId.registerVendorDataType(roleReplyVendorData); } }}} Where NXT_ROLE_REQUEST and NXT_ROLE_REPLY are the request and reply data types. 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. It seems customary to provide a method, getInstantiable(), for this purpose. This belongs in the subclass that defines the actual vendor data payload. The code that does this may look like this: {{{ protected static Instantiable instantiable = new Instantiable() { public OFVendorData instantiate() { return new OFExportsReply(); } }; /** * @return a subclass of Instantiable that instantiates * an instance of OFRoleRequestVendorData. */ public static Instantiable getInstantiable() { return instantiable; } }}} The above sample was modified slightly to fit my vendor message, but was almost taken, word-for-word, from the Nicira vendor messages. 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).