Book Image

OpenFlow Cookbook

Book Image

OpenFlow Cookbook

Overview of this book

Table of Contents (17 chapters)
16
Index

Setting the role of the communication channel towards a controller

Role-request messages are sent from the controller to set the role of its OpenFlow channel, or query that role. The controller's role in the switch is constantly changed as a result of a request from the controller. The switch cannot change the role of a controller channel on its own.

Tip

The controller may send the role request message to communicate its channel role at any time and the switch must remember the role of each controller connection

Refer to the Setting the role of a controller's communication channel recipe in Chapter 1, OpenFlow Channel Connection Establishment (Part 2) for more information on when and why the controller sends the role request message to the switch.

How to do it...

The message format used by the controller to send OFPT_ROLE_REQUEST messages is defined in the Setting the role of a controller's communication channel recipe in Chapter 1, OpenFlow Channel Connection Establishment (Part 2). The switch should use the same message format for sending the reply message back to the controller.

If the role requested from the controller is master or slave, then the switch must validate the generation_id to check for stale messages. This is required because, if the stale messages are processed by the switch, then there is a possibility of one or more controllers and the switch might be out of sync with respect to the role.

Once the switch receives a role request message, it must return an OFPT_ROLE_REPLY message, if there is no error encountered while processing this role request message. The structure of this reply message is exactly same as the OFPT_ROLE_REQUEST message.

The field role should be set with the current role of the controller.

The field generation_id should be set to the current generation_id (the generation_id associated with the last successful role request). If the current generation_id was never set, the generation_id in the reply must be set to the maximum field value (the unsigned equivalent of -1).

If the validation of generation_id fails, the switch must discard the role request message and return an error message with type OFPET_ROLE_REQUEST_FAILED and the code as OFPRRFC_STALE.

The procedure to handle a role request message from the controller is as follows:

handle_role_request_message (struct ofp_role_request role_request) {
  struct ofp_role_request role_reply;
  /* pseudo-code to validate the generation_id. Here the
   * generation_is_defined and cached_generation_id are global
   * variables */
  if (generation_is_defined && (int64_t)
     (role_request.generation_id - cached_generation_id) < 0)
  {
     send_error_message(OFPET_ROLE_REQUEST_FAILED, OFPRRFC_STALE);
  }
  else
  {
     cached_generation_id = role_request.generation_id;
     generation_is_defined = true;
    /* Here connection is the connection data structure which is
   * maintained by the switch */
     connection.role = role_request.role;
     role_reply.role = role_request.role;
     role_reply.generation_id = cached_generation_id;
     send_openflow_message (connection, role_reply);
  }
}

The procedure to send error messages is explained in the Setting the role of a controller's communication channel recipe in Chapter 1, OpenFlow Channel Connection Establishment (Part 2).

There's more…

If the requested role is OFPCR_ROLE_MASTER, then the switch should change the role of the existing master controller to OFPCR_ROLE_EQUAL.

If the requested role is OFPCR_ROLE_SLAVE and after successfully setting the role of this communication channel as a slave in the switch, the switch:

  • Should not send asynchronous messages.
  • Should not execute the controller-switch command. For example OFPT_PACKET_OUT, OFPT_FLOW_MOD, OFPT_GROUP_MOD, OFPT_PORT_MOD, OFPT_TABLE_MOD requests, and OFPMP_TABLE_FEATURES multipart requests with a non-empty body must be rejected.
  • If it receives any controller-switch command then the switch must send the OFPT_ERROR message of the type field and code as OFPET_BAD_REQUEST and OFPBRC_IS_SLAVE respectively. The procedure to send error messages is explained in the recipe, Setting the role of a controller's communication channel recipe in Chapter 1, OpenFlow Channel Connection Establishment (Part 2).

See also

  • For more information about sending the role request message from the controller, refer to the Setting the role of a controller's communication channel recipe in Chapter 1, OpenFlow Channel Connection Establishment (Part 2)