Thomas Vachuska | 781d18b | 2014-10-27 10:31:25 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2015-present 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 | |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 18 | import org.jboss.netty.channel.Channel; |
alshabib | b452fd7 | 2015-04-22 20:46:20 -0700 | [diff] [blame] | 19 | import org.onosproject.net.driver.HandlerBehaviour; |
| 20 | import org.onosproject.openflow.controller.Dpid; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 21 | import org.onosproject.openflow.controller.OpenFlowSwitch; |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 22 | import org.projectfloodlight.openflow.protocol.OFDescStatsReply; |
| 23 | import org.projectfloodlight.openflow.protocol.OFErrorMsg; |
| 24 | import org.projectfloodlight.openflow.protocol.OFFeaturesReply; |
| 25 | import org.projectfloodlight.openflow.protocol.OFMessage; |
Jordi Ortiz | 91477b8 | 2016-11-29 15:22:50 +0100 | [diff] [blame^] | 26 | import org.projectfloodlight.openflow.protocol.OFMeterFeaturesStatsReply; |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 27 | import org.projectfloodlight.openflow.protocol.OFPortDescStatsReply; |
| 28 | import org.projectfloodlight.openflow.protocol.OFVersion; |
| 29 | |
alshabib | b452fd7 | 2015-04-22 20:46:20 -0700 | [diff] [blame] | 30 | import java.util.List; |
| 31 | |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 32 | /** |
| 33 | * Represents the driver side of an OpenFlow switch. |
| 34 | * This interface should never be exposed to consumers. |
| 35 | * |
| 36 | */ |
alshabib | b452fd7 | 2015-04-22 20:46:20 -0700 | [diff] [blame] | 37 | public interface OpenFlowSwitchDriver extends OpenFlowSwitch, HandlerBehaviour { |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 38 | |
| 39 | /** |
| 40 | * Sets the OpenFlow agent to be used. This method |
| 41 | * can only be called once. |
| 42 | * @param agent the agent to set. |
| 43 | */ |
Sho SHIMIZU | 3310a34 | 2015-05-13 12:14:05 -0700 | [diff] [blame] | 44 | void setAgent(OpenFlowAgent agent); |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 45 | |
| 46 | /** |
| 47 | * Sets the Role handler object. |
| 48 | * This method can only be called once. |
| 49 | * @param roleHandler the roleHandler class |
| 50 | */ |
Sho SHIMIZU | 3310a34 | 2015-05-13 12:14:05 -0700 | [diff] [blame] | 51 | void setRoleHandler(RoleHandler roleHandler); |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 52 | |
| 53 | /** |
| 54 | * Reasserts this controllers role to the switch. |
| 55 | * Useful in cases where the switch no longer agrees |
| 56 | * that this controller has the role it claims. |
| 57 | */ |
Sho SHIMIZU | 3310a34 | 2015-05-13 12:14:05 -0700 | [diff] [blame] | 58 | void reassertRole(); |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 59 | |
| 60 | /** |
| 61 | * Handle the situation where the role request triggers an error. |
| 62 | * @param error the error to handle. |
| 63 | * @return true if handled, false if not. |
| 64 | */ |
Sho SHIMIZU | 3310a34 | 2015-05-13 12:14:05 -0700 | [diff] [blame] | 65 | boolean handleRoleError(OFErrorMsg error); |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 66 | |
| 67 | /** |
| 68 | * If this driver know of Nicira style role messages, these should |
| 69 | * be handled here. |
| 70 | * @param m the role message to handle. |
| 71 | * @throws SwitchStateException if the message received was |
| 72 | * not a nicira role or was malformed. |
| 73 | */ |
Sho SHIMIZU | 3310a34 | 2015-05-13 12:14:05 -0700 | [diff] [blame] | 74 | void handleNiciraRole(OFMessage m) throws SwitchStateException; |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 75 | |
| 76 | /** |
Thomas Vachuska | 4b42077 | 2014-10-30 16:46:17 -0700 | [diff] [blame] | 77 | * Handle OF 1.x (where x > 0) role messages. |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 78 | * @param m the role message to handle |
| 79 | * @throws SwitchStateException if the message received was |
| 80 | * not a nicira role or was malformed. |
| 81 | */ |
Sho SHIMIZU | 3310a34 | 2015-05-13 12:14:05 -0700 | [diff] [blame] | 82 | void handleRole(OFMessage m) throws SwitchStateException; |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 83 | |
| 84 | /** |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 85 | * Announce to the OpenFlow agent that this switch has connected. |
| 86 | * @return true if successful, false if duplicate switch. |
| 87 | */ |
Sho SHIMIZU | 3310a34 | 2015-05-13 12:14:05 -0700 | [diff] [blame] | 88 | boolean connectSwitch(); |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 89 | |
| 90 | /** |
| 91 | * Activate this MASTER switch-controller relationship in the OF agent. |
| 92 | * @return true is successful, false is switch has not |
| 93 | * connected or is unknown to the system. |
| 94 | */ |
Sho SHIMIZU | 3310a34 | 2015-05-13 12:14:05 -0700 | [diff] [blame] | 95 | boolean activateMasterSwitch(); |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 96 | |
| 97 | /** |
| 98 | * Activate this EQUAL switch-controller relationship in the OF agent. |
| 99 | * @return true is successful, false is switch has not |
| 100 | * connected or is unknown to the system. |
| 101 | */ |
Sho SHIMIZU | 3310a34 | 2015-05-13 12:14:05 -0700 | [diff] [blame] | 102 | boolean activateEqualSwitch(); |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 103 | |
| 104 | /** |
| 105 | * Transition this switch-controller relationship to an EQUAL state. |
| 106 | */ |
Sho SHIMIZU | 3310a34 | 2015-05-13 12:14:05 -0700 | [diff] [blame] | 107 | void transitionToEqualSwitch(); |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 108 | |
| 109 | /** |
| 110 | * Transition this switch-controller relationship to an Master state. |
| 111 | */ |
Sho SHIMIZU | 3310a34 | 2015-05-13 12:14:05 -0700 | [diff] [blame] | 112 | void transitionToMasterSwitch(); |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 113 | |
| 114 | /** |
| 115 | * Remove this switch from the openflow agent. |
| 116 | */ |
Sho SHIMIZU | 3310a34 | 2015-05-13 12:14:05 -0700 | [diff] [blame] | 117 | void removeConnectedSwitch(); |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 118 | |
| 119 | /** |
| 120 | * Sets the ports on this switch. |
| 121 | * @param portDescReply the port set and descriptions |
| 122 | */ |
Sho SHIMIZU | 3310a34 | 2015-05-13 12:14:05 -0700 | [diff] [blame] | 123 | void setPortDescReply(OFPortDescStatsReply portDescReply); |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 124 | |
| 125 | /** |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 126 | * Sets the ports on this switch. |
| 127 | * @param portDescReplies list of port set and descriptions |
| 128 | */ |
Sho SHIMIZU | 3310a34 | 2015-05-13 12:14:05 -0700 | [diff] [blame] | 129 | void setPortDescReplies(List<OFPortDescStatsReply> portDescReplies); |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 130 | |
| 131 | /** |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 132 | * Sets the features reply for this switch. |
| 133 | * @param featuresReply the features to set. |
| 134 | */ |
Sho SHIMIZU | 3310a34 | 2015-05-13 12:14:05 -0700 | [diff] [blame] | 135 | void setFeaturesReply(OFFeaturesReply featuresReply); |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 136 | |
| 137 | /** |
Jordi Ortiz | 91477b8 | 2016-11-29 15:22:50 +0100 | [diff] [blame^] | 138 | * Sets the meter features reply for this switch. |
| 139 | * @param meterFeaturesReply the meter features to set. |
| 140 | */ |
| 141 | void setMeterFeaturesReply(OFMeterFeaturesStatsReply meterFeaturesReply); |
| 142 | |
| 143 | /** |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 144 | * Sets the switch description. |
| 145 | * @param desc the descriptions |
| 146 | */ |
Sho SHIMIZU | 3310a34 | 2015-05-13 12:14:05 -0700 | [diff] [blame] | 147 | void setSwitchDescription(OFDescStatsReply desc); |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 148 | |
| 149 | /** |
| 150 | * Gets the next transaction id to use. |
| 151 | * @return the xid |
| 152 | */ |
Sho SHIMIZU | 3310a34 | 2015-05-13 12:14:05 -0700 | [diff] [blame] | 153 | int getNextTransactionId(); |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 154 | |
| 155 | |
| 156 | /** |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 157 | * Sets the OF version for this switch. |
| 158 | * @param ofV the version to set. |
| 159 | */ |
Sho SHIMIZU | 3310a34 | 2015-05-13 12:14:05 -0700 | [diff] [blame] | 160 | void setOFVersion(OFVersion ofV); |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 161 | |
| 162 | /** |
| 163 | * Sets this switch has having a full flowtable. |
| 164 | * @param full true if full, false otherswise. |
| 165 | */ |
Sho SHIMIZU | 3310a34 | 2015-05-13 12:14:05 -0700 | [diff] [blame] | 166 | void setTableFull(boolean full); |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 167 | |
| 168 | /** |
| 169 | * Sets the associated Netty channel for this switch. |
| 170 | * @param channel the Netty channel |
| 171 | */ |
Sho SHIMIZU | 3310a34 | 2015-05-13 12:14:05 -0700 | [diff] [blame] | 172 | void setChannel(Channel channel); |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 173 | |
| 174 | /** |
| 175 | * Sets whether the switch is connected. |
| 176 | * |
| 177 | * @param connected whether the switch is connected |
| 178 | */ |
Sho SHIMIZU | 3310a34 | 2015-05-13 12:14:05 -0700 | [diff] [blame] | 179 | void setConnected(boolean connected); |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 180 | |
| 181 | /** |
alshabib | b452fd7 | 2015-04-22 20:46:20 -0700 | [diff] [blame] | 182 | * Initialises the behaviour. |
| 183 | * @param dpid a dpid |
| 184 | * @param desc a switch description |
| 185 | * @param ofv OpenFlow version |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 186 | */ |
alshabib | b452fd7 | 2015-04-22 20:46:20 -0700 | [diff] [blame] | 187 | void init(Dpid dpid, OFDescStatsReply desc, OFVersion ofv); |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 188 | |
| 189 | /** |
alshabib | b452fd7 | 2015-04-22 20:46:20 -0700 | [diff] [blame] | 190 | * Does this switch support Nicira Role messages. |
| 191 | * @return true if supports, false otherwise. |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 192 | */ |
alshabib | b452fd7 | 2015-04-22 20:46:20 -0700 | [diff] [blame] | 193 | Boolean supportNxRole(); |
| 194 | |
| 195 | |
| 196 | /** |
| 197 | * Starts the driver specific handshake process. |
| 198 | */ |
| 199 | void startDriverHandshake(); |
| 200 | |
| 201 | /** |
| 202 | * Checks whether the driver specific handshake is complete. |
| 203 | * @return true is finished, false if not. |
| 204 | */ |
| 205 | boolean isDriverHandshakeComplete(); |
| 206 | |
| 207 | /** |
| 208 | * Process a message during the driver specific handshake. |
| 209 | * @param m the message to process. |
| 210 | */ |
| 211 | void processDriverHandshakeMessage(OFMessage m); |
| 212 | |
| 213 | /** |
| 214 | * Sends only role request messages. |
| 215 | * |
| 216 | * @param message a role request message. |
| 217 | */ |
| 218 | void sendRoleRequest(OFMessage message); |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 219 | |
alshabib | a2df7b2a | 2015-05-06 13:57:10 -0700 | [diff] [blame] | 220 | /** |
| 221 | * Allows the handshaker behaviour to send messages during the |
| 222 | * handshake phase only. |
| 223 | * |
| 224 | * @param message an OpenFlow message |
| 225 | */ |
| 226 | void sendHandshakeMessage(OFMessage message); |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 227 | } |