Skip to content
Eder Leão Fernandes edited this page Sep 13, 2018 · 1 revision

Although already present in the software switch base code, the library underwent several modifications in old messages and grew with the addition of OpenFlow 1.3 messages.

Every OpenFlow message represented by the Oflib has a common header. This header struct contains only one member, which is the message type information. Using the same initial struct for every message struct allows the implementation of two general functions that abstract marshaling and unmarshaling. In the code below, the definition of these functions is shown.

int ofl_msg_pack(struct ofl_msg_header *msg, uint32_t xid, uint8_t **buf, size_t *buf_len, struct ofl_exp *exp);
ofl_err ofl_msg_unpack(uint8_t *buf, size_t buf_len, struct ofl_msg_header **msg, uint32_t *xid, struct ofl_exp *exp);

Marshaling, also known as packing, is done by ofl_msg_pack. By passing a pointer to the struct ofl_msg_header for the function, we can check the message type and apply the message respective marshaling function. Unmarshaling, also known as unpacking, is performed by ofl_msg_unpack. In this function, the first bytes of the OpenFlow messages, the buf parameter, reveal their types. With this information the function calls the proper function to convert the message for the Oflib format.

Another Oflib task is the error handling of messages. It checks for bad requests from the controller; for example messages with unknown types and wrong sizes are performed by every unpacking function. In case of error, the function returns the OpenFlow error code for the Datapath, which creates an error message and sends it for the controller, through the Communication Channel.

Addition of new OpenFlow messages in the Oflib should be a trivial task. Firstly, the developer needs to define a C struct, with struct ofl_msg_header as the first member. Then, write a pack and unpack function. Finally, add the new message type for *ofl_msg_pack and *ofl_msg_unpack. The code below illustrates the OpenFlow 1.3 Role Request.

struct ofl_msg_role_request {
	struct ofl_msg_header header; /* Type OFPT_ROLE_REQUEST/OFPT_ROLE_REPLY. */
	uint32_t role;                /* One of OFPCR_ROLE_*. */
	uint64_t generation_id;       /* Master Election Generation Id */
};

static ofl_err
ofl_msg_unpack_role_request(struct ofp_header *src, size_t *len, struct ofl_msg_header **msg)

static int
ofl_msg_pack_role_request(struct ofl_msg_role_request *msg, uint8_t **buf, size_t *buf_len)
};

Additionally, the Oflib also has printing functions. This is helpful for logging and debugging in the software switch.