Thomas Vachuska | 781d18b | 2014-10-27 10:31:25 -0700 | [diff] [blame] | 1 | /* |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 2 | * Copyright 2014 Open Networking Laboratory |
Thomas Vachuska | 781d18b | 2014-10-27 10:31:25 -0700 | [diff] [blame] | 3 | * |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
Thomas Vachuska | 781d18b | 2014-10-27 10:31:25 -0700 | [diff] [blame] | 7 | * |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
Thomas Vachuska | 781d18b | 2014-10-27 10:31:25 -0700 | [diff] [blame] | 15 | */ |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame^] | 16 | package org.onosproject.openflow.controller.driver; |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 17 | |
| 18 | import java.io.IOException; |
| 19 | |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame^] | 20 | import org.onosproject.openflow.controller.RoleState; |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 21 | import org.projectfloodlight.openflow.protocol.OFErrorMsg; |
| 22 | import org.projectfloodlight.openflow.protocol.OFExperimenter; |
| 23 | import org.projectfloodlight.openflow.protocol.OFRoleReply; |
| 24 | |
| 25 | /** |
| 26 | * Role handling. |
| 27 | * |
| 28 | */ |
| 29 | public interface RoleHandler { |
| 30 | |
| 31 | /** |
| 32 | * Extract the role from an OFVendor message. |
| 33 | * |
| 34 | * Extract the role from an OFVendor message if the message is a |
| 35 | * Nicira role reply. Otherwise return null. |
| 36 | * |
| 37 | * @param experimenterMsg The vendor message to parse. |
| 38 | * @return The role in the message if the message is a Nicira role |
| 39 | * reply, null otherwise. |
| 40 | * @throws SwitchStateException If the message is a Nicira role reply |
| 41 | * but the numeric role value is unknown. |
| 42 | */ |
| 43 | public RoleState extractNiciraRoleReply(OFExperimenter experimenterMsg) |
| 44 | throws SwitchStateException; |
| 45 | |
| 46 | /** |
| 47 | * Send a role request with the given role to the switch and update |
| 48 | * the pending request and timestamp. |
| 49 | * Sends an OFPT_ROLE_REQUEST to an OF1.3 switch, OR |
| 50 | * Sends an NX_ROLE_REQUEST to an OF1.0 switch if configured to support it |
| 51 | * in the IOFSwitch driver. If not supported, this method sends nothing |
| 52 | * and returns 'false'. The caller should take appropriate action. |
| 53 | * |
| 54 | * One other optimization we do here is that for OF1.0 switches with |
| 55 | * Nicira role message support, we force the Role.EQUAL to become |
| 56 | * Role.SLAVE, as there is no defined behavior for the Nicira role OTHER. |
| 57 | * We cannot expect it to behave like SLAVE. We don't have this problem with |
| 58 | * OF1.3 switches, because Role.EQUAL is well defined and we can simulate |
| 59 | * SLAVE behavior by using ASYNC messages. |
| 60 | * |
Yuta HIGUCHI | 5c94727 | 2014-11-03 21:39:21 -0800 | [diff] [blame] | 61 | * @param role role to request |
| 62 | * @param exp expectation |
| 63 | * @throws IOException when I/O exception of some sort has occurred |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 64 | * @return false if and only if the switch does not support role-request |
| 65 | * messages, according to the switch driver; true otherwise. |
| 66 | */ |
| 67 | public boolean sendRoleRequest(RoleState role, RoleRecvStatus exp) |
| 68 | throws IOException; |
| 69 | |
| 70 | /** |
| 71 | * Extract the role information from an OF1.3 Role Reply Message. |
| 72 | * @param rrmsg role reply message |
| 73 | * @return RoleReplyInfo object |
Yuta HIGUCHI | 5c94727 | 2014-11-03 21:39:21 -0800 | [diff] [blame] | 74 | * @throws SwitchStateException If unknown role encountered |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 75 | */ |
| 76 | public RoleReplyInfo extractOFRoleReply(OFRoleReply rrmsg) |
| 77 | throws SwitchStateException; |
| 78 | |
| 79 | /** |
| 80 | * Deliver a received role reply. |
| 81 | * |
| 82 | * Check if a request is pending and if the received reply matches the |
| 83 | * the expected pending reply (we check both role and xid) we set |
| 84 | * the role for the switch/channel. |
| 85 | * |
| 86 | * If a request is pending but doesn't match the reply we ignore it, and |
| 87 | * return |
| 88 | * |
| 89 | * If no request is pending we disconnect with a SwitchStateException |
| 90 | * |
| 91 | * @param rri information about role-reply in format that |
| 92 | * controller can understand. |
Yuta HIGUCHI | 5c94727 | 2014-11-03 21:39:21 -0800 | [diff] [blame] | 93 | * @return result comparing expected and received reply |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 94 | * @throws SwitchStateException if no request is pending |
| 95 | */ |
| 96 | public RoleRecvStatus deliverRoleReply(RoleReplyInfo rri) |
| 97 | throws SwitchStateException; |
| 98 | |
| 99 | |
| 100 | /** |
| 101 | * Called if we receive an error message. If the xid matches the |
| 102 | * pending request we handle it otherwise we ignore it. |
| 103 | * |
| 104 | * Note: since we only keep the last pending request we might get |
| 105 | * error messages for earlier role requests that we won't be able |
| 106 | * to handle |
Yuta HIGUCHI | 5c94727 | 2014-11-03 21:39:21 -0800 | [diff] [blame] | 107 | * @param error error message |
| 108 | * @return result comparing expected and received reply |
| 109 | * @throws SwitchStateException if switch did not support requested role |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 110 | */ |
| 111 | public RoleRecvStatus deliverError(OFErrorMsg error) |
| 112 | throws SwitchStateException; |
| 113 | |
| 114 | } |