tom | 9c94c5b | 2014-09-17 13:14:42 -0700 | [diff] [blame] | 1 | package org.onlab.onos.openflow.controller.driver; |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 2 | |
| 3 | import java.io.IOException; |
| 4 | |
tom | 9c94c5b | 2014-09-17 13:14:42 -0700 | [diff] [blame] | 5 | import org.onlab.onos.openflow.controller.RoleState; |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 6 | import org.projectfloodlight.openflow.protocol.OFErrorMsg; |
| 7 | import org.projectfloodlight.openflow.protocol.OFExperimenter; |
| 8 | import org.projectfloodlight.openflow.protocol.OFRoleReply; |
| 9 | |
| 10 | /** |
| 11 | * Role handling. |
| 12 | * |
| 13 | */ |
| 14 | public interface RoleHandler { |
| 15 | |
| 16 | /** |
| 17 | * Extract the role from an OFVendor message. |
| 18 | * |
| 19 | * Extract the role from an OFVendor message if the message is a |
| 20 | * Nicira role reply. Otherwise return null. |
| 21 | * |
| 22 | * @param experimenterMsg The vendor message to parse. |
| 23 | * @return The role in the message if the message is a Nicira role |
| 24 | * reply, null otherwise. |
| 25 | * @throws SwitchStateException If the message is a Nicira role reply |
| 26 | * but the numeric role value is unknown. |
| 27 | */ |
| 28 | public RoleState extractNiciraRoleReply(OFExperimenter experimenterMsg) |
| 29 | throws SwitchStateException; |
| 30 | |
| 31 | /** |
| 32 | * Send a role request with the given role to the switch and update |
| 33 | * the pending request and timestamp. |
| 34 | * Sends an OFPT_ROLE_REQUEST to an OF1.3 switch, OR |
| 35 | * Sends an NX_ROLE_REQUEST to an OF1.0 switch if configured to support it |
| 36 | * in the IOFSwitch driver. If not supported, this method sends nothing |
| 37 | * and returns 'false'. The caller should take appropriate action. |
| 38 | * |
| 39 | * One other optimization we do here is that for OF1.0 switches with |
| 40 | * Nicira role message support, we force the Role.EQUAL to become |
| 41 | * Role.SLAVE, as there is no defined behavior for the Nicira role OTHER. |
| 42 | * We cannot expect it to behave like SLAVE. We don't have this problem with |
| 43 | * OF1.3 switches, because Role.EQUAL is well defined and we can simulate |
| 44 | * SLAVE behavior by using ASYNC messages. |
| 45 | * |
| 46 | * @param role |
| 47 | * @throws IOException |
| 48 | * @return false if and only if the switch does not support role-request |
| 49 | * messages, according to the switch driver; true otherwise. |
| 50 | */ |
| 51 | public boolean sendRoleRequest(RoleState role, RoleRecvStatus exp) |
| 52 | throws IOException; |
| 53 | |
| 54 | /** |
| 55 | * Extract the role information from an OF1.3 Role Reply Message. |
| 56 | * @param rrmsg role reply message |
| 57 | * @return RoleReplyInfo object |
| 58 | * @throws SwitchStateException |
| 59 | */ |
| 60 | public RoleReplyInfo extractOFRoleReply(OFRoleReply rrmsg) |
| 61 | throws SwitchStateException; |
| 62 | |
| 63 | /** |
| 64 | * Deliver a received role reply. |
| 65 | * |
| 66 | * Check if a request is pending and if the received reply matches the |
| 67 | * the expected pending reply (we check both role and xid) we set |
| 68 | * the role for the switch/channel. |
| 69 | * |
| 70 | * If a request is pending but doesn't match the reply we ignore it, and |
| 71 | * return |
| 72 | * |
| 73 | * If no request is pending we disconnect with a SwitchStateException |
| 74 | * |
| 75 | * @param rri information about role-reply in format that |
| 76 | * controller can understand. |
| 77 | * @throws SwitchStateException if no request is pending |
| 78 | */ |
| 79 | public RoleRecvStatus deliverRoleReply(RoleReplyInfo rri) |
| 80 | throws SwitchStateException; |
| 81 | |
| 82 | |
| 83 | /** |
| 84 | * Called if we receive an error message. If the xid matches the |
| 85 | * pending request we handle it otherwise we ignore it. |
| 86 | * |
| 87 | * Note: since we only keep the last pending request we might get |
| 88 | * error messages for earlier role requests that we won't be able |
| 89 | * to handle |
| 90 | */ |
| 91 | public RoleRecvStatus deliverError(OFErrorMsg error) |
| 92 | throws SwitchStateException; |
| 93 | |
| 94 | } |