Ray Milkey | 7f9e020 | 2015-11-04 17:14:09 -0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Foundation |
Ray Milkey | 7f9e020 | 2015-11-04 17:14:09 -0800 | [diff] [blame] | 3 | * |
| 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 |
| 7 | * |
| 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. |
| 15 | */ |
| 16 | package org.onosproject.openflow; |
| 17 | |
Ray Milkey | 7f9e020 | 2015-11-04 17:14:09 -0800 | [diff] [blame] | 18 | import org.onosproject.net.Device; |
| 19 | import org.onosproject.net.driver.DriverData; |
| 20 | import org.onosproject.net.driver.DriverHandler; |
| 21 | import org.onosproject.openflow.controller.Dpid; |
Yuta HIGUCHI | 6ee6b8c | 2017-05-09 14:44:30 -0700 | [diff] [blame] | 22 | import org.onosproject.openflow.controller.OpenFlowSession; |
Ray Milkey | 7f9e020 | 2015-11-04 17:14:09 -0800 | [diff] [blame] | 23 | import org.onosproject.openflow.controller.RoleState; |
| 24 | import org.onosproject.openflow.controller.driver.OpenFlowAgent; |
| 25 | import org.onosproject.openflow.controller.driver.OpenFlowSwitchDriver; |
| 26 | import org.onosproject.openflow.controller.driver.RoleHandler; |
| 27 | import org.onosproject.openflow.controller.driver.SwitchStateException; |
| 28 | import org.projectfloodlight.openflow.protocol.OFDescStatsReply; |
| 29 | import org.projectfloodlight.openflow.protocol.OFErrorMsg; |
| 30 | import org.projectfloodlight.openflow.protocol.OFFactories; |
| 31 | import org.projectfloodlight.openflow.protocol.OFFactory; |
| 32 | import org.projectfloodlight.openflow.protocol.OFFeaturesReply; |
| 33 | import org.projectfloodlight.openflow.protocol.OFMessage; |
Jordi Ortiz | aa8de49 | 2016-12-01 00:21:36 +0100 | [diff] [blame] | 34 | import org.projectfloodlight.openflow.protocol.OFMeterFeatures; |
Jordi Ortiz | 91477b8 | 2016-11-29 15:22:50 +0100 | [diff] [blame] | 35 | import org.projectfloodlight.openflow.protocol.OFMeterFeaturesStatsReply; |
Ray Milkey | 7f9e020 | 2015-11-04 17:14:09 -0800 | [diff] [blame] | 36 | import org.projectfloodlight.openflow.protocol.OFPortDesc; |
| 37 | import org.projectfloodlight.openflow.protocol.OFPortDescStatsReply; |
| 38 | import org.projectfloodlight.openflow.protocol.OFVersion; |
| 39 | |
Jian Li | a78cdb2 | 2016-04-21 13:03:58 -0700 | [diff] [blame] | 40 | import java.util.List; |
pier | 7f292e7 | 2019-07-16 15:52:50 +0200 | [diff] [blame^] | 41 | import java.util.Set; |
Jian Li | a78cdb2 | 2016-04-21 13:03:58 -0700 | [diff] [blame] | 42 | |
Ray Milkey | 7f9e020 | 2015-11-04 17:14:09 -0800 | [diff] [blame] | 43 | /** |
| 44 | * Testing adapter for the OpenFlow switch driver class. |
| 45 | */ |
| 46 | public class OpenflowSwitchDriverAdapter implements OpenFlowSwitchDriver { |
Ray Milkey | ca20bb5 | 2015-11-10 13:59:16 -0800 | [diff] [blame] | 47 | |
| 48 | RoleState role = RoleState.MASTER; |
pier | 7f292e7 | 2019-07-16 15:52:50 +0200 | [diff] [blame^] | 49 | // state of the connection |
| 50 | private Set<Dpid> connected; |
| 51 | private Dpid myDpid; |
| 52 | private boolean complete; |
| 53 | |
| 54 | public OpenflowSwitchDriverAdapter() { |
| 55 | } |
| 56 | |
| 57 | public OpenflowSwitchDriverAdapter(Set<Dpid> connected, Dpid myDpid, boolean complete) { |
| 58 | this.connected = connected; |
| 59 | this.myDpid = myDpid; |
| 60 | this.complete = complete; |
| 61 | } |
Ray Milkey | ca20bb5 | 2015-11-10 13:59:16 -0800 | [diff] [blame] | 62 | |
Ray Milkey | 7f9e020 | 2015-11-04 17:14:09 -0800 | [diff] [blame] | 63 | @Override |
| 64 | public void setAgent(OpenFlowAgent agent) { |
| 65 | |
| 66 | } |
| 67 | |
| 68 | @Override |
| 69 | public void setRoleHandler(RoleHandler roleHandler) { |
| 70 | |
| 71 | } |
| 72 | |
| 73 | @Override |
| 74 | public void reassertRole() { |
| 75 | |
| 76 | } |
| 77 | |
| 78 | @Override |
| 79 | public boolean handleRoleError(OFErrorMsg error) { |
| 80 | return false; |
| 81 | } |
| 82 | |
| 83 | @Override |
| 84 | public void handleNiciraRole(OFMessage m) throws SwitchStateException { |
| 85 | |
| 86 | } |
| 87 | |
| 88 | @Override |
| 89 | public void handleRole(OFMessage m) throws SwitchStateException { |
| 90 | |
| 91 | } |
| 92 | |
| 93 | @Override |
| 94 | public boolean connectSwitch() { |
pier | 7f292e7 | 2019-07-16 15:52:50 +0200 | [diff] [blame^] | 95 | return !connected.contains(myDpid); |
Ray Milkey | 7f9e020 | 2015-11-04 17:14:09 -0800 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | @Override |
| 99 | public boolean activateMasterSwitch() { |
| 100 | return false; |
| 101 | } |
| 102 | |
| 103 | @Override |
| 104 | public boolean activateEqualSwitch() { |
| 105 | return false; |
| 106 | } |
| 107 | |
| 108 | @Override |
| 109 | public void transitionToEqualSwitch() { |
| 110 | |
| 111 | } |
| 112 | |
| 113 | @Override |
| 114 | public void transitionToMasterSwitch() { |
| 115 | |
| 116 | } |
| 117 | |
| 118 | @Override |
| 119 | public void removeConnectedSwitch() { |
| 120 | |
| 121 | } |
| 122 | |
| 123 | @Override |
| 124 | public void setPortDescReply(OFPortDescStatsReply portDescReply) { |
| 125 | |
| 126 | } |
| 127 | |
| 128 | @Override |
| 129 | public void setPortDescReplies(List<OFPortDescStatsReply> portDescReplies) { |
| 130 | |
| 131 | } |
| 132 | |
| 133 | @Override |
| 134 | public void setFeaturesReply(OFFeaturesReply featuresReply) { |
| 135 | |
| 136 | } |
| 137 | |
| 138 | @Override |
Jordi Ortiz | 91477b8 | 2016-11-29 15:22:50 +0100 | [diff] [blame] | 139 | public void setMeterFeaturesReply(OFMeterFeaturesStatsReply meterFeaturesReply) { |
| 140 | |
| 141 | } |
| 142 | |
| 143 | @Override |
Ray Milkey | 7f9e020 | 2015-11-04 17:14:09 -0800 | [diff] [blame] | 144 | public void setSwitchDescription(OFDescStatsReply desc) { |
| 145 | |
| 146 | } |
| 147 | |
| 148 | @Override |
| 149 | public int getNextTransactionId() { |
| 150 | return 0; |
| 151 | } |
| 152 | |
| 153 | @Override |
| 154 | public void setOFVersion(OFVersion ofV) { |
| 155 | |
| 156 | } |
| 157 | |
| 158 | @Override |
| 159 | public void setTableFull(boolean full) { |
| 160 | |
| 161 | } |
| 162 | |
| 163 | @Override |
Yuta HIGUCHI | 6ee6b8c | 2017-05-09 14:44:30 -0700 | [diff] [blame] | 164 | public void setChannel(OpenFlowSession channel) { |
Ray Milkey | 7f9e020 | 2015-11-04 17:14:09 -0800 | [diff] [blame] | 165 | |
| 166 | } |
| 167 | |
| 168 | @Override |
| 169 | public void setConnected(boolean connected) { |
| 170 | |
| 171 | } |
| 172 | |
| 173 | @Override |
| 174 | public void init(Dpid dpid, OFDescStatsReply desc, OFVersion ofv) { |
| 175 | |
| 176 | } |
| 177 | |
| 178 | @Override |
| 179 | public Boolean supportNxRole() { |
| 180 | return true; |
| 181 | } |
| 182 | |
| 183 | @Override |
| 184 | public void startDriverHandshake() { |
| 185 | |
| 186 | } |
| 187 | |
| 188 | @Override |
| 189 | public boolean isDriverHandshakeComplete() { |
pier | 7f292e7 | 2019-07-16 15:52:50 +0200 | [diff] [blame^] | 190 | return complete; |
Ray Milkey | 7f9e020 | 2015-11-04 17:14:09 -0800 | [diff] [blame] | 191 | } |
| 192 | |
| 193 | @Override |
| 194 | public void processDriverHandshakeMessage(OFMessage m) { |
pier | 7f292e7 | 2019-07-16 15:52:50 +0200 | [diff] [blame^] | 195 | complete = true; |
Ray Milkey | 7f9e020 | 2015-11-04 17:14:09 -0800 | [diff] [blame] | 196 | } |
| 197 | |
| 198 | @Override |
| 199 | public void sendRoleRequest(OFMessage message) { |
| 200 | |
| 201 | } |
| 202 | |
| 203 | @Override |
| 204 | public void sendHandshakeMessage(OFMessage message) { |
| 205 | |
| 206 | } |
| 207 | |
| 208 | @Override |
| 209 | public DriverHandler handler() { |
| 210 | return null; |
| 211 | } |
| 212 | |
| 213 | @Override |
| 214 | public void setHandler(DriverHandler handler) { |
| 215 | |
| 216 | } |
| 217 | |
| 218 | @Override |
| 219 | public DriverData data() { |
| 220 | return null; |
| 221 | } |
| 222 | |
| 223 | @Override |
| 224 | public void setData(DriverData data) { |
| 225 | |
| 226 | } |
| 227 | |
| 228 | @Override |
| 229 | public void sendMsg(OFMessage msg) { |
| 230 | |
| 231 | } |
| 232 | |
| 233 | @Override |
| 234 | public void sendMsg(List<OFMessage> msgs) { |
| 235 | |
| 236 | } |
| 237 | |
| 238 | @Override |
| 239 | public void handleMessage(OFMessage fromSwitch) { |
| 240 | |
| 241 | } |
| 242 | |
| 243 | @Override |
| 244 | public void setRole(RoleState role) { |
Ray Milkey | ca20bb5 | 2015-11-10 13:59:16 -0800 | [diff] [blame] | 245 | this.role = role; |
Ray Milkey | 7f9e020 | 2015-11-04 17:14:09 -0800 | [diff] [blame] | 246 | } |
| 247 | |
| 248 | @Override |
| 249 | public RoleState getRole() { |
Ray Milkey | ca20bb5 | 2015-11-10 13:59:16 -0800 | [diff] [blame] | 250 | return role; |
Ray Milkey | 7f9e020 | 2015-11-04 17:14:09 -0800 | [diff] [blame] | 251 | } |
| 252 | |
| 253 | @Override |
| 254 | public List<OFPortDesc> getPorts() { |
| 255 | return null; |
| 256 | } |
| 257 | |
| 258 | @Override |
Jordi Ortiz | aa8de49 | 2016-12-01 00:21:36 +0100 | [diff] [blame] | 259 | public OFMeterFeatures getMeterFeatures() { |
| 260 | return null; |
| 261 | } |
| 262 | |
| 263 | @Override |
Ray Milkey | 7f9e020 | 2015-11-04 17:14:09 -0800 | [diff] [blame] | 264 | public OFFactory factory() { |
| 265 | // return what-ever triggers requestPending = true |
| 266 | return OFFactories.getFactory(OFVersion.OF_10); |
| 267 | } |
| 268 | |
| 269 | @Override |
| 270 | public String getStringId() { |
| 271 | return "100"; |
| 272 | } |
| 273 | |
| 274 | @Override |
| 275 | public long getId() { |
| 276 | return 0; |
| 277 | } |
| 278 | |
| 279 | @Override |
| 280 | public String manufacturerDescription() { |
| 281 | return null; |
| 282 | } |
| 283 | |
| 284 | @Override |
| 285 | public String datapathDescription() { |
| 286 | return null; |
| 287 | } |
| 288 | |
| 289 | @Override |
| 290 | public String hardwareDescription() { |
| 291 | return null; |
| 292 | } |
| 293 | |
| 294 | @Override |
| 295 | public String softwareDescription() { |
| 296 | return null; |
| 297 | } |
| 298 | |
| 299 | @Override |
| 300 | public String serialNumber() { |
| 301 | return null; |
| 302 | } |
| 303 | |
| 304 | @Override |
| 305 | public boolean isConnected() { |
| 306 | return false; |
| 307 | } |
| 308 | |
| 309 | @Override |
| 310 | public void disconnectSwitch() { |
| 311 | |
| 312 | } |
| 313 | |
| 314 | @Override |
| 315 | public void returnRoleReply(RoleState requested, RoleState response) { |
| 316 | |
| 317 | } |
| 318 | |
| 319 | @Override |
| 320 | public Device.Type deviceType() { |
| 321 | return Device.Type.SWITCH; |
| 322 | } |
| 323 | |
| 324 | @Override |
| 325 | public String channelId() { |
| 326 | return null; |
| 327 | } |
Ray Milkey | 7f9e020 | 2015-11-04 17:14:09 -0800 | [diff] [blame] | 328 | } |