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 | |
| 139 | @Override |
| 140 | public final boolean isConnected() { |
| 141 | return this.connected; |
| 142 | } |
| 143 | |
| 144 | @Override |
| 145 | public final void setConnected(boolean connected) { |
| 146 | this.connected = connected; |
| 147 | }; |
| 148 | |
| 149 | @Override |
| 150 | public final void setChannel(Channel channel) { |
| 151 | this.channel = channel; |
Ray Milkey | e53f171 | 2015-01-16 09:17:16 -0800 | [diff] [blame] | 152 | final SocketAddress address = channel.getRemoteAddress(); |
| 153 | if (address instanceof InetSocketAddress) { |
| 154 | final InetSocketAddress inetAddress = (InetSocketAddress) address; |
| 155 | final IpAddress ipAddress = IpAddress.valueOf(inetAddress.getAddress()); |
Pavlin Radoslavov | 87dd930 | 2015-03-10 13:53:24 -0700 | [diff] [blame] | 156 | if (ipAddress.isIp4()) { |
Ray Milkey | e53f171 | 2015-01-16 09:17:16 -0800 | [diff] [blame] | 157 | channelId = ipAddress.toString() + ':' + inetAddress.getPort(); |
| 158 | } else { |
| 159 | channelId = '[' + ipAddress.toString() + "]:" + inetAddress.getPort(); |
| 160 | } |
| 161 | } |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 162 | }; |
| 163 | |
Ray Milkey | e53f171 | 2015-01-16 09:17:16 -0800 | [diff] [blame] | 164 | @Override |
| 165 | public String channelId() { |
| 166 | return channelId; |
| 167 | } |
| 168 | |
| 169 | |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 170 | //************************ |
| 171 | // Switch features related |
| 172 | //************************ |
| 173 | |
| 174 | @Override |
| 175 | public final long getId() { |
| 176 | return this.dpid.value(); |
| 177 | }; |
| 178 | |
| 179 | @Override |
| 180 | public final String getStringId() { |
| 181 | return this.dpid.toString(); |
| 182 | } |
| 183 | |
| 184 | @Override |
| 185 | public final void setOFVersion(OFVersion ofV) { |
| 186 | this.ofVersion = ofV; |
| 187 | } |
| 188 | |
| 189 | @Override |
| 190 | public void setTableFull(boolean full) { |
| 191 | this.tableFull = full; |
| 192 | } |
| 193 | |
| 194 | @Override |
| 195 | public void setFeaturesReply(OFFeaturesReply featuresReply) { |
| 196 | this.features = featuresReply; |
| 197 | } |
| 198 | |
| 199 | @Override |
| 200 | public abstract Boolean supportNxRole(); |
| 201 | |
| 202 | //************************ |
| 203 | // Message handling |
| 204 | //************************ |
| 205 | /** |
| 206 | * Handle the message coming from the dataplane. |
| 207 | * |
| 208 | * @param m the actual message |
| 209 | */ |
| 210 | @Override |
| 211 | public final void handleMessage(OFMessage m) { |
Thomas Vachuska | 3927446 | 2014-12-02 13:23:50 -0800 | [diff] [blame] | 212 | if (this.role == RoleState.MASTER || m instanceof OFPortStatus) { |
alshabib | 339a3d9 | 2014-09-26 17:54:32 -0700 | [diff] [blame] | 213 | this.agent.processMessage(dpid, m); |
| 214 | } |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 215 | } |
| 216 | |
| 217 | @Override |
| 218 | public RoleState getRole() { |
| 219 | return role; |
| 220 | }; |
| 221 | |
| 222 | @Override |
| 223 | public final boolean connectSwitch() { |
| 224 | return this.agent.addConnectedSwitch(dpid, this); |
| 225 | } |
| 226 | |
| 227 | @Override |
| 228 | public final boolean activateMasterSwitch() { |
| 229 | return this.agent.addActivatedMasterSwitch(dpid, this); |
| 230 | } |
| 231 | |
| 232 | @Override |
| 233 | public final boolean activateEqualSwitch() { |
| 234 | return this.agent.addActivatedEqualSwitch(dpid, this); |
| 235 | } |
| 236 | |
| 237 | @Override |
| 238 | public final void transitionToEqualSwitch() { |
| 239 | this.agent.transitionToEqualSwitch(dpid); |
| 240 | } |
| 241 | |
| 242 | @Override |
| 243 | public final void transitionToMasterSwitch() { |
| 244 | this.agent.transitionToMasterSwitch(dpid); |
| 245 | } |
| 246 | |
| 247 | @Override |
| 248 | public final void removeConnectedSwitch() { |
| 249 | this.agent.removeConnectedSwitch(dpid); |
| 250 | } |
| 251 | |
| 252 | @Override |
| 253 | public OFFactory factory() { |
| 254 | return OFFactories.getFactory(ofVersion); |
| 255 | } |
| 256 | |
| 257 | @Override |
| 258 | public void setPortDescReply(OFPortDescStatsReply portDescReply) { |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 259 | this.ports.add(portDescReply); |
| 260 | } |
| 261 | |
| 262 | @Override |
| 263 | public void setPortDescReplies(List<OFPortDescStatsReply> portDescReplies) { |
| 264 | this.ports.addAll(portDescReplies); |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 265 | } |
| 266 | |
| 267 | @Override |
Ayaka Koshibe | 3ef2b0d | 2014-10-31 13:58:27 -0700 | [diff] [blame] | 268 | public void returnRoleReply(RoleState requested, RoleState response) { |
| 269 | this.agent.returnRoleReply(dpid, requested, response); |
Ayaka Koshibe | ab91cc4 | 2014-09-25 10:20:52 -0700 | [diff] [blame] | 270 | } |
| 271 | |
| 272 | @Override |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 273 | public abstract void startDriverHandshake(); |
| 274 | |
| 275 | @Override |
| 276 | public abstract boolean isDriverHandshakeComplete(); |
| 277 | |
| 278 | @Override |
| 279 | public abstract void processDriverHandshakeMessage(OFMessage m); |
| 280 | |
alshabib | 339a3d9 | 2014-09-26 17:54:32 -0700 | [diff] [blame] | 281 | |
| 282 | // Role Handling |
| 283 | |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 284 | @Override |
| 285 | public void setRole(RoleState role) { |
| 286 | try { |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 287 | if (this.roleMan.sendRoleRequest(role, RoleRecvStatus.MATCHED_SET_ROLE)) { |
alshabib | 339a3d9 | 2014-09-26 17:54:32 -0700 | [diff] [blame] | 288 | log.info("Sending role {} to switch {}", role, getStringId()); |
| 289 | if (role == RoleState.SLAVE || role == RoleState.EQUAL) { |
| 290 | this.role = role; |
| 291 | } |
alshabib | 7814e9f | 2014-09-30 11:52:12 -0700 | [diff] [blame] | 292 | } else { |
| 293 | this.role = role; |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 294 | } |
| 295 | } catch (IOException e) { |
| 296 | log.error("Unable to write to switch {}.", this.dpid); |
| 297 | } |
| 298 | } |
| 299 | |
alshabib | 339a3d9 | 2014-09-26 17:54:32 -0700 | [diff] [blame] | 300 | @Override |
| 301 | public void reassertRole() { |
| 302 | if (this.getRole() == RoleState.MASTER) { |
| 303 | log.warn("Received permission error from switch {} while " + |
| 304 | "being master. Reasserting master role.", |
| 305 | this.getStringId()); |
| 306 | this.setRole(RoleState.MASTER); |
| 307 | } |
| 308 | } |
| 309 | |
| 310 | |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 311 | |
| 312 | @Override |
| 313 | public void handleRole(OFMessage m) throws SwitchStateException { |
| 314 | RoleReplyInfo rri = roleMan.extractOFRoleReply((OFRoleReply) m); |
| 315 | RoleRecvStatus rrs = roleMan.deliverRoleReply(rri); |
| 316 | if (rrs == RoleRecvStatus.MATCHED_SET_ROLE) { |
| 317 | if (rri.getRole() == RoleState.MASTER) { |
alshabib | 339a3d9 | 2014-09-26 17:54:32 -0700 | [diff] [blame] | 318 | this.role = rri.getRole(); |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 319 | this.transitionToMasterSwitch(); |
| 320 | } else if (rri.getRole() == RoleState.EQUAL || |
alshabib | 339a3d9 | 2014-09-26 17:54:32 -0700 | [diff] [blame] | 321 | rri.getRole() == RoleState.SLAVE) { |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 322 | this.transitionToEqualSwitch(); |
| 323 | } |
alshabib | 339a3d9 | 2014-09-26 17:54:32 -0700 | [diff] [blame] | 324 | } else { |
alshabib | 4785eec | 2014-12-04 16:45:45 -0800 | [diff] [blame] | 325 | log.warn("Failed to set role for {}", this.getStringId()); |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 326 | } |
| 327 | } |
| 328 | |
| 329 | @Override |
| 330 | public void handleNiciraRole(OFMessage m) throws SwitchStateException { |
| 331 | RoleState r = this.roleMan.extractNiciraRoleReply((OFExperimenter) m); |
| 332 | if (r == null) { |
| 333 | // The message wasn't really a Nicira role reply. We just |
| 334 | // dispatch it to the OFMessage listeners in this case. |
| 335 | this.handleMessage(m); |
alshabib | dfc7afb | 2014-10-21 20:13:27 -0700 | [diff] [blame] | 336 | return; |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 337 | } |
| 338 | |
| 339 | RoleRecvStatus rrs = this.roleMan.deliverRoleReply( |
| 340 | new RoleReplyInfo(r, null, m.getXid())); |
| 341 | if (rrs == RoleRecvStatus.MATCHED_SET_ROLE) { |
| 342 | if (r == RoleState.MASTER) { |
alshabib | 339a3d9 | 2014-09-26 17:54:32 -0700 | [diff] [blame] | 343 | this.role = r; |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 344 | this.transitionToMasterSwitch(); |
| 345 | } else if (r == RoleState.EQUAL || |
| 346 | r == RoleState.SLAVE) { |
| 347 | this.transitionToEqualSwitch(); |
| 348 | } |
alshabib | 339a3d9 | 2014-09-26 17:54:32 -0700 | [diff] [blame] | 349 | } else { |
alshabib | dfc7afb | 2014-10-21 20:13:27 -0700 | [diff] [blame] | 350 | this.disconnectSwitch(); |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 351 | } |
| 352 | } |
| 353 | |
| 354 | @Override |
| 355 | public boolean handleRoleError(OFErrorMsg error) { |
| 356 | try { |
| 357 | return RoleRecvStatus.OTHER_EXPECTATION != this.roleMan.deliverError(error); |
| 358 | } catch (SwitchStateException e) { |
| 359 | this.disconnectSwitch(); |
| 360 | } |
| 361 | return true; |
| 362 | } |
| 363 | |
alshabib | 339a3d9 | 2014-09-26 17:54:32 -0700 | [diff] [blame] | 364 | |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 365 | |
| 366 | @Override |
| 367 | public final void setAgent(OpenFlowAgent ag) { |
| 368 | if (this.agent == null) { |
| 369 | this.agent = ag; |
| 370 | } |
| 371 | } |
| 372 | |
| 373 | @Override |
| 374 | public final void setRoleHandler(RoleHandler roleHandler) { |
| 375 | if (this.roleMan == null) { |
| 376 | this.roleMan = roleHandler; |
| 377 | } |
| 378 | } |
| 379 | |
| 380 | @Override |
| 381 | public void setSwitchDescription(OFDescStatsReply d) { |
| 382 | this.desc = d; |
| 383 | } |
| 384 | |
| 385 | @Override |
| 386 | public int getNextTransactionId() { |
| 387 | return this.xidCounter.getAndIncrement(); |
| 388 | } |
| 389 | |
| 390 | @Override |
| 391 | public List<OFPortDesc> getPorts() { |
Srikanth Vavilapalli | f5b234a | 2015-04-21 13:04:13 -0700 | [diff] [blame] | 392 | return this.ports.stream() |
| 393 | .flatMap((portReply) -> (portReply.getEntries().stream())) |
| 394 | .collect(Collectors.toList()); |
| 395 | //return Collections.unmodifiableList(ports.getEntries()); |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 396 | } |
| 397 | |
| 398 | @Override |
Ray Milkey | d3edd03 | 2015-01-16 11:38:58 -0800 | [diff] [blame] | 399 | public String manufacturerDescription() { |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 400 | return this.desc.getMfrDesc(); |
| 401 | } |
| 402 | |
| 403 | |
| 404 | @Override |
| 405 | public String datapathDescription() { |
| 406 | return this.desc.getDpDesc(); |
| 407 | } |
| 408 | |
| 409 | |
| 410 | @Override |
| 411 | public String hardwareDescription() { |
| 412 | return this.desc.getHwDesc(); |
| 413 | } |
| 414 | |
| 415 | @Override |
| 416 | public String softwareDescription() { |
| 417 | return this.desc.getSwDesc(); |
| 418 | } |
| 419 | |
| 420 | @Override |
| 421 | public String serialNumber() { |
| 422 | return this.desc.getSerialNum(); |
| 423 | } |
| 424 | |
alshabib | b452fd7 | 2015-04-22 20:46:20 -0700 | [diff] [blame^] | 425 | |
Praseed Balakrishnan | a22eadf | 2014-10-20 14:21:45 -0700 | [diff] [blame] | 426 | @Override |
| 427 | public boolean isOptical() { |
| 428 | return false; |
| 429 | } |
| 430 | |
alshabib | 9af7007 | 2015-02-09 14:34:16 -0800 | [diff] [blame] | 431 | |
alshabib | b452fd7 | 2015-04-22 20:46:20 -0700 | [diff] [blame^] | 432 | @Override |
| 433 | public String toString() { |
| 434 | return this.getClass().getName() + " [" + ((channel != null) |
| 435 | ? channel.getRemoteAddress() : "?") |
| 436 | + " DPID[" + ((getStringId() != null) ? getStringId() : "?") + "]]"; |
| 437 | } |
| 438 | |
| 439 | |
alshabib | 9af7007 | 2015-02-09 14:34:16 -0800 | [diff] [blame] | 440 | |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 441 | } |