Thomas Vachuska | 781d18b | 2014-10-27 10:31:25 -0700 | [diff] [blame] | 1 | /* |
Ray Milkey | 34c9590 | 2015-04-15 09:47:53 -0700 | [diff] [blame] | 2 | * Copyright 2014-2015 Open Networking Laboratory |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -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 |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -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 | */ |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 16 | |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 17 | package org.onosproject.openflow.controller.driver; |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 18 | |
| 19 | import java.io.IOException; |
Ray Milkey | e53f171 | 2015-01-16 09:17:16 -0800 | [diff] [blame] | 20 | import java.net.InetSocketAddress; |
| 21 | import java.net.SocketAddress; |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 22 | import java.util.ArrayList; |
alshabib | b452fd7 | 2015-04-22 20:46:20 -0700 | [diff] [blame] | 23 | import java.util.Collections; |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 24 | import java.util.List; |
Thomas Vachuska | f15511b | 2015-03-24 12:17:57 -0700 | [diff] [blame] | 25 | import java.util.concurrent.RejectedExecutionException; |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 26 | import java.util.concurrent.atomic.AtomicInteger; |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 27 | import java.util.stream.Collectors; |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 28 | |
| 29 | import org.jboss.netty.channel.Channel; |
Ray Milkey | e53f171 | 2015-01-16 09:17:16 -0800 | [diff] [blame] | 30 | import org.onlab.packet.IpAddress; |
alshabib | b452fd7 | 2015-04-22 20:46:20 -0700 | [diff] [blame] | 31 | import org.onosproject.net.driver.AbstractHandlerBehaviour; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 32 | import org.onosproject.openflow.controller.Dpid; |
| 33 | import org.onosproject.openflow.controller.RoleState; |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 34 | import org.projectfloodlight.openflow.protocol.OFDescStatsReply; |
| 35 | import org.projectfloodlight.openflow.protocol.OFErrorMsg; |
| 36 | import org.projectfloodlight.openflow.protocol.OFExperimenter; |
| 37 | import org.projectfloodlight.openflow.protocol.OFFactories; |
| 38 | import org.projectfloodlight.openflow.protocol.OFFactory; |
| 39 | import org.projectfloodlight.openflow.protocol.OFFeaturesReply; |
| 40 | import org.projectfloodlight.openflow.protocol.OFMessage; |
alshabib | b452fd7 | 2015-04-22 20:46:20 -0700 | [diff] [blame] | 41 | import org.projectfloodlight.openflow.protocol.OFNiciraControllerRoleRequest; |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 42 | import org.projectfloodlight.openflow.protocol.OFPortDesc; |
| 43 | import org.projectfloodlight.openflow.protocol.OFPortDescStatsReply; |
Thomas Vachuska | 3927446 | 2014-12-02 13:23:50 -0800 | [diff] [blame] | 44 | import org.projectfloodlight.openflow.protocol.OFPortStatus; |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 45 | import org.projectfloodlight.openflow.protocol.OFRoleReply; |
alshabib | b452fd7 | 2015-04-22 20:46:20 -0700 | [diff] [blame] | 46 | import org.projectfloodlight.openflow.protocol.OFRoleRequest; |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 47 | import org.projectfloodlight.openflow.protocol.OFVersion; |
| 48 | import org.slf4j.Logger; |
| 49 | import org.slf4j.LoggerFactory; |
| 50 | |
| 51 | /** |
| 52 | * An abstract representation of an OpenFlow switch. Can be extended by others |
| 53 | * to serve as a base for their vendor specific representation of a switch. |
| 54 | */ |
alshabib | b452fd7 | 2015-04-22 20:46:20 -0700 | [diff] [blame] | 55 | public abstract class AbstractOpenFlowSwitch extends AbstractHandlerBehaviour |
| 56 | implements OpenFlowSwitchDriver { |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 57 | |
Yuta HIGUCHI | f5416d8 | 2014-10-24 21:17:40 -0700 | [diff] [blame] | 58 | protected final Logger log = LoggerFactory.getLogger(getClass()); |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 59 | |
Thomas Vachuska | f15511b | 2015-03-24 12:17:57 -0700 | [diff] [blame] | 60 | private static final String SHUTDOWN_MSG = "Worker has already been shutdown"; |
| 61 | |
alshabib | b452fd7 | 2015-04-22 20:46:20 -0700 | [diff] [blame] | 62 | private Channel channel; |
Ray Milkey | e53f171 | 2015-01-16 09:17:16 -0800 | [diff] [blame] | 63 | protected String channelId; |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 64 | |
| 65 | private boolean connected; |
| 66 | protected boolean startDriverHandshakeCalled = false; |
alshabib | b452fd7 | 2015-04-22 20:46:20 -0700 | [diff] [blame] | 67 | private Dpid dpid; |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 68 | private OpenFlowAgent agent; |
| 69 | private final AtomicInteger xidCounter = new AtomicInteger(0); |
| 70 | |
| 71 | private OFVersion ofVersion; |
| 72 | |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 73 | protected List<OFPortDescStatsReply> ports = new ArrayList<>(); |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 74 | |
| 75 | protected boolean tableFull; |
| 76 | |
| 77 | private RoleHandler roleMan; |
| 78 | |
| 79 | protected RoleState role; |
| 80 | |
| 81 | protected OFFeaturesReply features; |
| 82 | protected OFDescStatsReply desc; |
| 83 | |
alshabib | b452fd7 | 2015-04-22 20:46:20 -0700 | [diff] [blame] | 84 | @Override |
| 85 | public void init(Dpid dpid, OFDescStatsReply desc, OFVersion ofv) { |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 86 | this.dpid = dpid; |
| 87 | this.desc = desc; |
alshabib | b452fd7 | 2015-04-22 20:46:20 -0700 | [diff] [blame] | 88 | this.ofVersion = ofv; |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | //************************ |
| 92 | // Channel related |
| 93 | //************************ |
| 94 | |
| 95 | @Override |
| 96 | public final void disconnectSwitch() { |
| 97 | this.channel.close(); |
| 98 | } |
| 99 | |
| 100 | @Override |
| 101 | public final void sendMsg(OFMessage m) { |
alshabib | 339a3d9 | 2014-09-26 17:54:32 -0700 | [diff] [blame] | 102 | if (role == RoleState.MASTER) { |
Thomas Vachuska | f15511b | 2015-03-24 12:17:57 -0700 | [diff] [blame] | 103 | try { |
alshabib | b452fd7 | 2015-04-22 20:46:20 -0700 | [diff] [blame] | 104 | channel.write(Collections.singletonList(m)); |
Thomas Vachuska | f15511b | 2015-03-24 12:17:57 -0700 | [diff] [blame] | 105 | } catch (RejectedExecutionException e) { |
Thomas Vachuska | 152f9fd | 2015-04-02 16:28:13 -0700 | [diff] [blame] | 106 | log.warn(e.getMessage()); |
Thomas Vachuska | f15511b | 2015-03-24 12:17:57 -0700 | [diff] [blame] | 107 | if (!e.getMessage().contains(SHUTDOWN_MSG)) { |
| 108 | throw e; |
| 109 | } |
| 110 | } |
alshabib | 339a3d9 | 2014-09-26 17:54:32 -0700 | [diff] [blame] | 111 | } |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 112 | } |
| 113 | |
| 114 | @Override |
| 115 | public final void sendMsg(List<OFMessage> msgs) { |
alshabib | 339a3d9 | 2014-09-26 17:54:32 -0700 | [diff] [blame] | 116 | if (role == RoleState.MASTER) { |
Thomas Vachuska | f15511b | 2015-03-24 12:17:57 -0700 | [diff] [blame] | 117 | try { |
alshabib | b452fd7 | 2015-04-22 20:46:20 -0700 | [diff] [blame] | 118 | channel.write(msgs); |
Thomas Vachuska | f15511b | 2015-03-24 12:17:57 -0700 | [diff] [blame] | 119 | } catch (RejectedExecutionException e) { |
Thomas Vachuska | 152f9fd | 2015-04-02 16:28:13 -0700 | [diff] [blame] | 120 | log.warn(e.getMessage()); |
Thomas Vachuska | f15511b | 2015-03-24 12:17:57 -0700 | [diff] [blame] | 121 | if (!e.getMessage().contains(SHUTDOWN_MSG)) { |
| 122 | throw e; |
| 123 | } |
| 124 | } |
alshabib | 339a3d9 | 2014-09-26 17:54:32 -0700 | [diff] [blame] | 125 | } |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 126 | } |
| 127 | |
| 128 | @Override |
alshabib | b452fd7 | 2015-04-22 20:46:20 -0700 | [diff] [blame] | 129 | public final void sendRoleRequest(OFMessage msg) { |
| 130 | if (msg instanceof OFRoleRequest || |
| 131 | msg instanceof OFNiciraControllerRoleRequest) { |
| 132 | channel.write(Collections.singletonList(msg)); |
| 133 | return; |
| 134 | } |
| 135 | throw new IllegalArgumentException("Someone is trying to send " + |
| 136 | "a non role request message"); |
| 137 | } |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 138 | |
alshabib | a2df7b2a | 2015-05-06 13:57:10 -0700 | [diff] [blame^] | 139 | public final void sendHandshakeMessage(OFMessage message) { |
| 140 | if (!this.isDriverHandshakeComplete()) { |
| 141 | channel.write(Collections.singletonList(message)); |
| 142 | } |
| 143 | } |
| 144 | |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 145 | @Override |
| 146 | public final boolean isConnected() { |
| 147 | return this.connected; |
| 148 | } |
| 149 | |
| 150 | @Override |
| 151 | public final void setConnected(boolean connected) { |
| 152 | this.connected = connected; |
| 153 | }; |
| 154 | |
| 155 | @Override |
| 156 | public final void setChannel(Channel channel) { |
| 157 | this.channel = channel; |
Ray Milkey | e53f171 | 2015-01-16 09:17:16 -0800 | [diff] [blame] | 158 | final SocketAddress address = channel.getRemoteAddress(); |
| 159 | if (address instanceof InetSocketAddress) { |
| 160 | final InetSocketAddress inetAddress = (InetSocketAddress) address; |
| 161 | final IpAddress ipAddress = IpAddress.valueOf(inetAddress.getAddress()); |
Pavlin Radoslavov | 87dd930 | 2015-03-10 13:53:24 -0700 | [diff] [blame] | 162 | if (ipAddress.isIp4()) { |
Ray Milkey | e53f171 | 2015-01-16 09:17:16 -0800 | [diff] [blame] | 163 | channelId = ipAddress.toString() + ':' + inetAddress.getPort(); |
| 164 | } else { |
| 165 | channelId = '[' + ipAddress.toString() + "]:" + inetAddress.getPort(); |
| 166 | } |
| 167 | } |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 168 | }; |
| 169 | |
Ray Milkey | e53f171 | 2015-01-16 09:17:16 -0800 | [diff] [blame] | 170 | @Override |
| 171 | public String channelId() { |
| 172 | return channelId; |
| 173 | } |
| 174 | |
| 175 | |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 176 | //************************ |
| 177 | // Switch features related |
| 178 | //************************ |
| 179 | |
| 180 | @Override |
| 181 | public final long getId() { |
| 182 | return this.dpid.value(); |
| 183 | }; |
| 184 | |
| 185 | @Override |
| 186 | public final String getStringId() { |
| 187 | return this.dpid.toString(); |
| 188 | } |
| 189 | |
| 190 | @Override |
| 191 | public final void setOFVersion(OFVersion ofV) { |
| 192 | this.ofVersion = ofV; |
| 193 | } |
| 194 | |
| 195 | @Override |
| 196 | public void setTableFull(boolean full) { |
| 197 | this.tableFull = full; |
| 198 | } |
| 199 | |
| 200 | @Override |
| 201 | public void setFeaturesReply(OFFeaturesReply featuresReply) { |
| 202 | this.features = featuresReply; |
| 203 | } |
| 204 | |
| 205 | @Override |
| 206 | public abstract Boolean supportNxRole(); |
| 207 | |
| 208 | //************************ |
| 209 | // Message handling |
| 210 | //************************ |
| 211 | /** |
| 212 | * Handle the message coming from the dataplane. |
| 213 | * |
| 214 | * @param m the actual message |
| 215 | */ |
| 216 | @Override |
| 217 | public final void handleMessage(OFMessage m) { |
Thomas Vachuska | 3927446 | 2014-12-02 13:23:50 -0800 | [diff] [blame] | 218 | if (this.role == RoleState.MASTER || m instanceof OFPortStatus) { |
alshabib | 339a3d9 | 2014-09-26 17:54:32 -0700 | [diff] [blame] | 219 | this.agent.processMessage(dpid, m); |
| 220 | } |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 221 | } |
| 222 | |
| 223 | @Override |
| 224 | public RoleState getRole() { |
| 225 | return role; |
| 226 | }; |
| 227 | |
| 228 | @Override |
| 229 | public final boolean connectSwitch() { |
| 230 | return this.agent.addConnectedSwitch(dpid, this); |
| 231 | } |
| 232 | |
| 233 | @Override |
| 234 | public final boolean activateMasterSwitch() { |
| 235 | return this.agent.addActivatedMasterSwitch(dpid, this); |
| 236 | } |
| 237 | |
| 238 | @Override |
| 239 | public final boolean activateEqualSwitch() { |
| 240 | return this.agent.addActivatedEqualSwitch(dpid, this); |
| 241 | } |
| 242 | |
| 243 | @Override |
| 244 | public final void transitionToEqualSwitch() { |
| 245 | this.agent.transitionToEqualSwitch(dpid); |
| 246 | } |
| 247 | |
| 248 | @Override |
| 249 | public final void transitionToMasterSwitch() { |
| 250 | this.agent.transitionToMasterSwitch(dpid); |
| 251 | } |
| 252 | |
| 253 | @Override |
| 254 | public final void removeConnectedSwitch() { |
| 255 | this.agent.removeConnectedSwitch(dpid); |
| 256 | } |
| 257 | |
| 258 | @Override |
| 259 | public OFFactory factory() { |
| 260 | return OFFactories.getFactory(ofVersion); |
| 261 | } |
| 262 | |
| 263 | @Override |
| 264 | public void setPortDescReply(OFPortDescStatsReply portDescReply) { |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 265 | this.ports.add(portDescReply); |
| 266 | } |
| 267 | |
| 268 | @Override |
| 269 | public void setPortDescReplies(List<OFPortDescStatsReply> portDescReplies) { |
| 270 | this.ports.addAll(portDescReplies); |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 271 | } |
| 272 | |
| 273 | @Override |
Ayaka Koshibe | 3ef2b0d | 2014-10-31 13:58:27 -0700 | [diff] [blame] | 274 | public void returnRoleReply(RoleState requested, RoleState response) { |
| 275 | this.agent.returnRoleReply(dpid, requested, response); |
Ayaka Koshibe | ab91cc4 | 2014-09-25 10:20:52 -0700 | [diff] [blame] | 276 | } |
| 277 | |
| 278 | @Override |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 279 | public abstract void startDriverHandshake(); |
| 280 | |
| 281 | @Override |
| 282 | public abstract boolean isDriverHandshakeComplete(); |
| 283 | |
| 284 | @Override |
| 285 | public abstract void processDriverHandshakeMessage(OFMessage m); |
| 286 | |
alshabib | 339a3d9 | 2014-09-26 17:54:32 -0700 | [diff] [blame] | 287 | |
| 288 | // Role Handling |
| 289 | |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 290 | @Override |
| 291 | public void setRole(RoleState role) { |
| 292 | try { |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 293 | if (this.roleMan.sendRoleRequest(role, RoleRecvStatus.MATCHED_SET_ROLE)) { |
alshabib | 339a3d9 | 2014-09-26 17:54:32 -0700 | [diff] [blame] | 294 | log.info("Sending role {} to switch {}", role, getStringId()); |
| 295 | if (role == RoleState.SLAVE || role == RoleState.EQUAL) { |
| 296 | this.role = role; |
| 297 | } |
alshabib | 7814e9f | 2014-09-30 11:52:12 -0700 | [diff] [blame] | 298 | } else { |
| 299 | this.role = role; |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 300 | } |
| 301 | } catch (IOException e) { |
| 302 | log.error("Unable to write to switch {}.", this.dpid); |
| 303 | } |
| 304 | } |
| 305 | |
alshabib | 339a3d9 | 2014-09-26 17:54:32 -0700 | [diff] [blame] | 306 | @Override |
| 307 | public void reassertRole() { |
| 308 | if (this.getRole() == RoleState.MASTER) { |
| 309 | log.warn("Received permission error from switch {} while " + |
| 310 | "being master. Reasserting master role.", |
| 311 | this.getStringId()); |
| 312 | this.setRole(RoleState.MASTER); |
| 313 | } |
| 314 | } |
| 315 | |
| 316 | |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 317 | |
| 318 | @Override |
| 319 | public void handleRole(OFMessage m) throws SwitchStateException { |
| 320 | RoleReplyInfo rri = roleMan.extractOFRoleReply((OFRoleReply) m); |
| 321 | RoleRecvStatus rrs = roleMan.deliverRoleReply(rri); |
| 322 | if (rrs == RoleRecvStatus.MATCHED_SET_ROLE) { |
| 323 | if (rri.getRole() == RoleState.MASTER) { |
alshabib | 339a3d9 | 2014-09-26 17:54:32 -0700 | [diff] [blame] | 324 | this.role = rri.getRole(); |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 325 | this.transitionToMasterSwitch(); |
| 326 | } else if (rri.getRole() == RoleState.EQUAL || |
alshabib | 339a3d9 | 2014-09-26 17:54:32 -0700 | [diff] [blame] | 327 | rri.getRole() == RoleState.SLAVE) { |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 328 | this.transitionToEqualSwitch(); |
| 329 | } |
alshabib | 339a3d9 | 2014-09-26 17:54:32 -0700 | [diff] [blame] | 330 | } else { |
alshabib | 4785eec | 2014-12-04 16:45:45 -0800 | [diff] [blame] | 331 | log.warn("Failed to set role for {}", this.getStringId()); |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 332 | } |
| 333 | } |
| 334 | |
| 335 | @Override |
| 336 | public void handleNiciraRole(OFMessage m) throws SwitchStateException { |
| 337 | RoleState r = this.roleMan.extractNiciraRoleReply((OFExperimenter) m); |
| 338 | if (r == null) { |
| 339 | // The message wasn't really a Nicira role reply. We just |
| 340 | // dispatch it to the OFMessage listeners in this case. |
| 341 | this.handleMessage(m); |
alshabib | dfc7afb | 2014-10-21 20:13:27 -0700 | [diff] [blame] | 342 | return; |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 343 | } |
| 344 | |
| 345 | RoleRecvStatus rrs = this.roleMan.deliverRoleReply( |
| 346 | new RoleReplyInfo(r, null, m.getXid())); |
| 347 | if (rrs == RoleRecvStatus.MATCHED_SET_ROLE) { |
| 348 | if (r == RoleState.MASTER) { |
alshabib | 339a3d9 | 2014-09-26 17:54:32 -0700 | [diff] [blame] | 349 | this.role = r; |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 350 | this.transitionToMasterSwitch(); |
| 351 | } else if (r == RoleState.EQUAL || |
| 352 | r == RoleState.SLAVE) { |
| 353 | this.transitionToEqualSwitch(); |
| 354 | } |
alshabib | 339a3d9 | 2014-09-26 17:54:32 -0700 | [diff] [blame] | 355 | } else { |
alshabib | dfc7afb | 2014-10-21 20:13:27 -0700 | [diff] [blame] | 356 | this.disconnectSwitch(); |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 357 | } |
| 358 | } |
| 359 | |
| 360 | @Override |
| 361 | public boolean handleRoleError(OFErrorMsg error) { |
| 362 | try { |
| 363 | return RoleRecvStatus.OTHER_EXPECTATION != this.roleMan.deliverError(error); |
| 364 | } catch (SwitchStateException e) { |
| 365 | this.disconnectSwitch(); |
| 366 | } |
| 367 | return true; |
| 368 | } |
| 369 | |
alshabib | 339a3d9 | 2014-09-26 17:54:32 -0700 | [diff] [blame] | 370 | |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 371 | |
| 372 | @Override |
| 373 | public final void setAgent(OpenFlowAgent ag) { |
| 374 | if (this.agent == null) { |
| 375 | this.agent = ag; |
| 376 | } |
| 377 | } |
| 378 | |
| 379 | @Override |
| 380 | public final void setRoleHandler(RoleHandler roleHandler) { |
| 381 | if (this.roleMan == null) { |
| 382 | this.roleMan = roleHandler; |
| 383 | } |
| 384 | } |
| 385 | |
| 386 | @Override |
| 387 | public void setSwitchDescription(OFDescStatsReply d) { |
| 388 | this.desc = d; |
| 389 | } |
| 390 | |
| 391 | @Override |
| 392 | public int getNextTransactionId() { |
| 393 | return this.xidCounter.getAndIncrement(); |
| 394 | } |
| 395 | |
| 396 | @Override |
| 397 | public List<OFPortDesc> getPorts() { |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 398 | return this.ports.stream() |
| 399 | .flatMap((portReply) -> (portReply.getEntries().stream())) |
| 400 | .collect(Collectors.toList()); |
| 401 | //return Collections.unmodifiableList(ports.getEntries()); |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 402 | } |
| 403 | |
| 404 | @Override |
Ray Milkey | d3edd03 | 2015-01-16 11:38:58 -0800 | [diff] [blame] | 405 | public String manufacturerDescription() { |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 406 | return this.desc.getMfrDesc(); |
| 407 | } |
| 408 | |
| 409 | |
| 410 | @Override |
| 411 | public String datapathDescription() { |
| 412 | return this.desc.getDpDesc(); |
| 413 | } |
| 414 | |
| 415 | |
| 416 | @Override |
| 417 | public String hardwareDescription() { |
| 418 | return this.desc.getHwDesc(); |
| 419 | } |
| 420 | |
| 421 | @Override |
| 422 | public String softwareDescription() { |
| 423 | return this.desc.getSwDesc(); |
| 424 | } |
| 425 | |
| 426 | @Override |
| 427 | public String serialNumber() { |
| 428 | return this.desc.getSerialNum(); |
| 429 | } |
| 430 | |
alshabib | b452fd7 | 2015-04-22 20:46:20 -0700 | [diff] [blame] | 431 | |
Praseed Balakrishnan | a22eadf | 2014-10-20 14:21:45 -0700 | [diff] [blame] | 432 | @Override |
| 433 | public boolean isOptical() { |
| 434 | return false; |
| 435 | } |
| 436 | |
alshabib | 9af7007 | 2015-02-09 14:34:16 -0800 | [diff] [blame] | 437 | |
alshabib | b452fd7 | 2015-04-22 20:46:20 -0700 | [diff] [blame] | 438 | @Override |
| 439 | public String toString() { |
| 440 | return this.getClass().getName() + " [" + ((channel != null) |
| 441 | ? channel.getRemoteAddress() : "?") |
| 442 | + " DPID[" + ((getStringId() != null) ? getStringId() : "?") + "]]"; |
| 443 | } |
| 444 | |
| 445 | |
alshabib | 9af7007 | 2015-02-09 14:34:16 -0800 | [diff] [blame] | 446 | |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 447 | } |