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.impl; |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 18 | |
Brian O'Connor | ff27850 | 2015-09-22 14:49:52 -0700 | [diff] [blame] | 19 | import com.google.common.base.Strings; |
| 20 | import com.google.common.collect.ImmutableList; |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 21 | import org.jboss.netty.bootstrap.ServerBootstrap; |
| 22 | import org.jboss.netty.channel.ChannelPipelineFactory; |
| 23 | import org.jboss.netty.channel.group.ChannelGroup; |
| 24 | import org.jboss.netty.channel.group.DefaultChannelGroup; |
| 25 | import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory; |
alshabib | 5162a9d | 2015-12-07 17:49:37 -0800 | [diff] [blame] | 26 | |
Jonathan Hart | a0d1249 | 2015-07-16 12:03:41 -0700 | [diff] [blame] | 27 | import org.onlab.util.ItemNotFoundException; |
| 28 | import org.onosproject.net.DeviceId; |
alshabib | b452fd7 | 2015-04-22 20:46:20 -0700 | [diff] [blame] | 29 | import org.onosproject.net.driver.DefaultDriverData; |
| 30 | import org.onosproject.net.driver.DefaultDriverHandler; |
| 31 | import org.onosproject.net.driver.Driver; |
| 32 | import org.onosproject.net.driver.DriverService; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 33 | import org.onosproject.openflow.controller.Dpid; |
| 34 | import org.onosproject.openflow.controller.driver.OpenFlowAgent; |
| 35 | import org.onosproject.openflow.controller.driver.OpenFlowSwitchDriver; |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 36 | import org.projectfloodlight.openflow.protocol.OFDescStatsReply; |
| 37 | import org.projectfloodlight.openflow.protocol.OFFactories; |
| 38 | import org.projectfloodlight.openflow.protocol.OFFactory; |
| 39 | import org.projectfloodlight.openflow.protocol.OFVersion; |
| 40 | import org.slf4j.Logger; |
| 41 | import org.slf4j.LoggerFactory; |
| 42 | |
alshabib | 9b6c19c | 2015-09-26 12:19:27 -0700 | [diff] [blame] | 43 | import javax.net.ssl.KeyManagerFactory; |
| 44 | import javax.net.ssl.SSLContext; |
alshabib | 9b6c19c | 2015-09-26 12:19:27 -0700 | [diff] [blame] | 45 | import javax.net.ssl.TrustManagerFactory; |
| 46 | import java.io.FileInputStream; |
Thomas Vachuska | 6f94ded | 2015-02-21 14:02:38 -0800 | [diff] [blame] | 47 | import java.lang.management.ManagementFactory; |
| 48 | import java.lang.management.RuntimeMXBean; |
| 49 | import java.net.InetSocketAddress; |
alshabib | 9b6c19c | 2015-09-26 12:19:27 -0700 | [diff] [blame] | 50 | import java.security.KeyStore; |
Brian O'Connor | ff27850 | 2015-09-22 14:49:52 -0700 | [diff] [blame] | 51 | import java.util.Dictionary; |
Thomas Vachuska | 6f94ded | 2015-02-21 14:02:38 -0800 | [diff] [blame] | 52 | import java.util.HashMap; |
Brian O'Connor | ff27850 | 2015-09-22 14:49:52 -0700 | [diff] [blame] | 53 | import java.util.List; |
Thomas Vachuska | 6f94ded | 2015-02-21 14:02:38 -0800 | [diff] [blame] | 54 | import java.util.Map; |
| 55 | import java.util.concurrent.Executors; |
Brian O'Connor | ff27850 | 2015-09-22 14:49:52 -0700 | [diff] [blame] | 56 | import java.util.stream.Collectors; |
| 57 | import java.util.stream.Stream; |
Thomas Vachuska | 6f94ded | 2015-02-21 14:02:38 -0800 | [diff] [blame] | 58 | |
Brian O'Connor | ff27850 | 2015-09-22 14:49:52 -0700 | [diff] [blame] | 59 | import static org.onlab.util.Tools.get; |
Thomas Vachuska | 6f94ded | 2015-02-21 14:02:38 -0800 | [diff] [blame] | 60 | import static org.onlab.util.Tools.groupedThreads; |
Thomas Vachuska | 80b0a80 | 2015-07-17 08:43:30 -0700 | [diff] [blame] | 61 | import static org.onosproject.net.DeviceId.deviceId; |
| 62 | import static org.onosproject.openflow.controller.Dpid.uri; |
Thomas Vachuska | 6f94ded | 2015-02-21 14:02:38 -0800 | [diff] [blame] | 63 | |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 64 | |
| 65 | /** |
| 66 | * The main controller class. Handles all setup and network listeners |
| 67 | * - Distributed ownership control of switch through IControllerRegistryService |
| 68 | */ |
| 69 | public class Controller { |
| 70 | |
| 71 | protected static final Logger log = LoggerFactory.getLogger(Controller.class); |
alshabib | 9eab22f | 2014-10-20 17:17:31 -0700 | [diff] [blame] | 72 | |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 73 | protected static final OFFactory FACTORY13 = OFFactories.getFactory(OFVersion.OF_13); |
| 74 | protected static final OFFactory FACTORY10 = OFFactories.getFactory(OFVersion.OF_10); |
alshabib | 9b6c19c | 2015-09-26 12:19:27 -0700 | [diff] [blame] | 75 | private static final boolean TLS_DISABLED = false; |
| 76 | private static final short MIN_KS_LENGTH = 6; |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 77 | |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 78 | protected HashMap<String, String> controllerNodeIPsCache; |
| 79 | |
| 80 | private ChannelGroup cg; |
| 81 | |
| 82 | // Configuration options |
Brian O'Connor | ff27850 | 2015-09-22 14:49:52 -0700 | [diff] [blame] | 83 | protected List<Integer> openFlowPorts = ImmutableList.of(6633, 6653); |
| 84 | protected int workerThreads = 16; |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 85 | |
| 86 | // Start time of the controller |
| 87 | protected long systemStartTime; |
| 88 | |
| 89 | private OpenFlowAgent agent; |
| 90 | |
| 91 | private NioServerSocketChannelFactory execFactory; |
| 92 | |
alshabib | 9b6c19c | 2015-09-26 12:19:27 -0700 | [diff] [blame] | 93 | protected String ksLocation; |
| 94 | protected String tsLocation; |
| 95 | protected char[] ksPwd; |
| 96 | protected char[] tsPwd; |
alshabib | 5162a9d | 2015-12-07 17:49:37 -0800 | [diff] [blame] | 97 | protected SSLContext sslContext; |
alshabib | 9b6c19c | 2015-09-26 12:19:27 -0700 | [diff] [blame] | 98 | |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 99 | // Perf. related configuration |
| 100 | protected static final int SEND_BUFFER_SIZE = 4 * 1024 * 1024; |
alshabib | b452fd7 | 2015-04-22 20:46:20 -0700 | [diff] [blame] | 101 | private DriverService driverService; |
Jonathan Hart | b35540a | 2015-11-17 09:30:56 -0800 | [diff] [blame] | 102 | private boolean enableOfTls = TLS_DISABLED; |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 103 | |
| 104 | // *************** |
| 105 | // Getters/Setters |
| 106 | // *************** |
| 107 | |
| 108 | public OFFactory getOFMessageFactory10() { |
| 109 | return FACTORY10; |
| 110 | } |
| 111 | |
| 112 | |
| 113 | public OFFactory getOFMessageFactory13() { |
| 114 | return FACTORY13; |
| 115 | } |
| 116 | |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 117 | // ************** |
| 118 | // Initialization |
| 119 | // ************** |
| 120 | |
| 121 | /** |
| 122 | * Tell controller that we're ready to accept switches loop. |
| 123 | */ |
| 124 | public void run() { |
| 125 | |
| 126 | try { |
| 127 | final ServerBootstrap bootstrap = createServerBootStrap(); |
| 128 | |
| 129 | bootstrap.setOption("reuseAddr", true); |
| 130 | bootstrap.setOption("child.keepAlive", true); |
| 131 | bootstrap.setOption("child.tcpNoDelay", true); |
| 132 | bootstrap.setOption("child.sendBufferSize", Controller.SEND_BUFFER_SIZE); |
| 133 | |
| 134 | ChannelPipelineFactory pfact = |
alshabib | 5162a9d | 2015-12-07 17:49:37 -0800 | [diff] [blame] | 135 | new OpenflowPipelineFactory(this, null, sslContext); |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 136 | bootstrap.setPipelineFactory(pfact); |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 137 | cg = new DefaultChannelGroup(); |
Brian O'Connor | ff27850 | 2015-09-22 14:49:52 -0700 | [diff] [blame] | 138 | openFlowPorts.forEach(port -> { |
| 139 | InetSocketAddress sa = new InetSocketAddress(port); |
| 140 | cg.add(bootstrap.bind(sa)); |
| 141 | log.info("Listening for switch connections on {}", sa); |
| 142 | }); |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 143 | |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 144 | } catch (Exception e) { |
| 145 | throw new RuntimeException(e); |
| 146 | } |
| 147 | |
| 148 | } |
| 149 | |
| 150 | private ServerBootstrap createServerBootStrap() { |
| 151 | |
| 152 | if (workerThreads == 0) { |
Thomas Vachuska | 6f94ded | 2015-02-21 14:02:38 -0800 | [diff] [blame] | 153 | execFactory = new NioServerSocketChannelFactory( |
| 154 | Executors.newCachedThreadPool(groupedThreads("onos/of", "boss-%d")), |
| 155 | Executors.newCachedThreadPool(groupedThreads("onos/of", "worker-%d"))); |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 156 | return new ServerBootstrap(execFactory); |
| 157 | } else { |
| 158 | execFactory = new NioServerSocketChannelFactory( |
Thomas Vachuska | 6f94ded | 2015-02-21 14:02:38 -0800 | [diff] [blame] | 159 | Executors.newCachedThreadPool(groupedThreads("onos/of", "boss-%d")), |
| 160 | Executors.newCachedThreadPool(groupedThreads("onos/of", "worker-%d")), workerThreads); |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 161 | return new ServerBootstrap(execFactory); |
| 162 | } |
| 163 | } |
| 164 | |
Brian O'Connor | ff27850 | 2015-09-22 14:49:52 -0700 | [diff] [blame] | 165 | public void setConfigParams(Dictionary<?, ?> properties) { |
| 166 | String ports = get(properties, "openflowPorts"); |
| 167 | if (!Strings.isNullOrEmpty(ports)) { |
| 168 | this.openFlowPorts = Stream.of(ports.split(",")) |
| 169 | .map(s -> Integer.parseInt(s)) |
| 170 | .collect(Collectors.toList()); |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 171 | } |
Brian O'Connor | ff27850 | 2015-09-22 14:49:52 -0700 | [diff] [blame] | 172 | log.debug("OpenFlow ports set to {}", this.openFlowPorts); |
Charles Chan | 45624b8 | 2015-08-24 00:29:20 +0800 | [diff] [blame] | 173 | |
Brian O'Connor | ff27850 | 2015-09-22 14:49:52 -0700 | [diff] [blame] | 174 | String threads = get(properties, "workerThreads"); |
| 175 | if (!Strings.isNullOrEmpty(threads)) { |
| 176 | this.workerThreads = Integer.parseInt(threads); |
| 177 | } |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 178 | log.debug("Number of worker threads set to {}", this.workerThreads); |
| 179 | } |
| 180 | |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 181 | /** |
| 182 | * Initialize internal data structures. |
| 183 | */ |
Jonathan Hart | bbd91d4 | 2015-02-27 11:18:04 -0800 | [diff] [blame] | 184 | public void init() { |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 185 | // These data structures are initialized here because other |
| 186 | // module's startUp() might be called before ours |
Jonathan Hart | bbd91d4 | 2015-02-27 11:18:04 -0800 | [diff] [blame] | 187 | this.controllerNodeIPsCache = new HashMap<>(); |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 188 | |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 189 | this.systemStartTime = System.currentTimeMillis(); |
alshabib | 9b6c19c | 2015-09-26 12:19:27 -0700 | [diff] [blame] | 190 | |
| 191 | try { |
Jonathan Hart | b35540a | 2015-11-17 09:30:56 -0800 | [diff] [blame] | 192 | getTlsParameters(); |
| 193 | if (enableOfTls) { |
| 194 | initSsl(); |
alshabib | 9b6c19c | 2015-09-26 12:19:27 -0700 | [diff] [blame] | 195 | } |
| 196 | } catch (Exception ex) { |
| 197 | log.error("SSL init failed: {}", ex.getMessage()); |
| 198 | } |
| 199 | |
| 200 | } |
| 201 | |
Jonathan Hart | b35540a | 2015-11-17 09:30:56 -0800 | [diff] [blame] | 202 | private void getTlsParameters() { |
alshabib | 9b6c19c | 2015-09-26 12:19:27 -0700 | [diff] [blame] | 203 | String tempString = System.getProperty("enableOFTLS"); |
Jonathan Hart | b35540a | 2015-11-17 09:30:56 -0800 | [diff] [blame] | 204 | enableOfTls = Strings.isNullOrEmpty(tempString) ? TLS_DISABLED : Boolean.parseBoolean(tempString); |
| 205 | log.info("OpenFlow Security is {}", enableOfTls ? "enabled" : "disabled"); |
| 206 | if (enableOfTls) { |
alshabib | 9b6c19c | 2015-09-26 12:19:27 -0700 | [diff] [blame] | 207 | ksLocation = System.getProperty("javax.net.ssl.keyStore"); |
| 208 | if (Strings.isNullOrEmpty(ksLocation)) { |
Jonathan Hart | b35540a | 2015-11-17 09:30:56 -0800 | [diff] [blame] | 209 | enableOfTls = TLS_DISABLED; |
alshabib | 9b6c19c | 2015-09-26 12:19:27 -0700 | [diff] [blame] | 210 | return; |
| 211 | } |
| 212 | tsLocation = System.getProperty("javax.net.ssl.trustStore"); |
| 213 | if (Strings.isNullOrEmpty(tsLocation)) { |
Jonathan Hart | b35540a | 2015-11-17 09:30:56 -0800 | [diff] [blame] | 214 | enableOfTls = TLS_DISABLED; |
alshabib | 9b6c19c | 2015-09-26 12:19:27 -0700 | [diff] [blame] | 215 | return; |
| 216 | } |
| 217 | ksPwd = System.getProperty("javax.net.ssl.keyStorePassword").toCharArray(); |
| 218 | if (MIN_KS_LENGTH > ksPwd.length) { |
Jonathan Hart | b35540a | 2015-11-17 09:30:56 -0800 | [diff] [blame] | 219 | enableOfTls = TLS_DISABLED; |
alshabib | 9b6c19c | 2015-09-26 12:19:27 -0700 | [diff] [blame] | 220 | return; |
| 221 | } |
| 222 | tsPwd = System.getProperty("javax.net.ssl.trustStorePassword").toCharArray(); |
| 223 | if (MIN_KS_LENGTH > tsPwd.length) { |
Jonathan Hart | b35540a | 2015-11-17 09:30:56 -0800 | [diff] [blame] | 224 | enableOfTls = TLS_DISABLED; |
alshabib | 9b6c19c | 2015-09-26 12:19:27 -0700 | [diff] [blame] | 225 | return; |
| 226 | } |
| 227 | } |
| 228 | } |
| 229 | |
Jonathan Hart | b35540a | 2015-11-17 09:30:56 -0800 | [diff] [blame] | 230 | private void initSsl() throws Exception { |
alshabib | 9b6c19c | 2015-09-26 12:19:27 -0700 | [diff] [blame] | 231 | |
| 232 | TrustManagerFactory tmFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm()); |
| 233 | KeyStore ts = KeyStore.getInstance("JKS"); |
| 234 | ts.load(new FileInputStream(tsLocation), tsPwd); |
| 235 | tmFactory.init(ts); |
| 236 | |
| 237 | KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm()); |
| 238 | KeyStore ks = KeyStore.getInstance("JKS"); |
| 239 | ks.load(new FileInputStream(ksLocation), ksPwd); |
| 240 | kmf.init(ks, ksPwd); |
| 241 | |
alshabib | 5162a9d | 2015-12-07 17:49:37 -0800 | [diff] [blame] | 242 | sslContext = SSLContext.getInstance("TLS"); |
| 243 | sslContext.init(kmf.getKeyManagers(), tmFactory.getTrustManagers(), null); |
alshabib | 9b6c19c | 2015-09-26 12:19:27 -0700 | [diff] [blame] | 244 | |
alshabib | 9b6c19c | 2015-09-26 12:19:27 -0700 | [diff] [blame] | 245 | |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 246 | } |
| 247 | |
| 248 | // ************** |
| 249 | // Utility methods |
| 250 | // ************** |
| 251 | |
| 252 | public Map<String, Long> getMemory() { |
Jonathan Hart | bbd91d4 | 2015-02-27 11:18:04 -0800 | [diff] [blame] | 253 | Map<String, Long> m = new HashMap<>(); |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 254 | Runtime runtime = Runtime.getRuntime(); |
| 255 | m.put("total", runtime.totalMemory()); |
| 256 | m.put("free", runtime.freeMemory()); |
| 257 | return m; |
| 258 | } |
| 259 | |
| 260 | |
Ray Milkey | dc0ff19 | 2015-11-04 13:49:52 -0800 | [diff] [blame] | 261 | public Long getSystemUptime() { |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 262 | RuntimeMXBean rb = ManagementFactory.getRuntimeMXBean(); |
| 263 | return rb.getUptime(); |
| 264 | } |
| 265 | |
Ray Milkey | dc0ff19 | 2015-11-04 13:49:52 -0800 | [diff] [blame] | 266 | public long getSystemStartTime() { |
| 267 | return (this.systemStartTime); |
| 268 | } |
| 269 | |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 270 | /** |
| 271 | * Forward to the driver-manager to get an IOFSwitch instance. |
Thomas Vachuska | 6f94ded | 2015-02-21 14:02:38 -0800 | [diff] [blame] | 272 | * |
Yuta HIGUCHI | 5c94727 | 2014-11-03 21:39:21 -0800 | [diff] [blame] | 273 | * @param dpid data path id |
| 274 | * @param desc switch description |
Thomas Vachuska | 6f94ded | 2015-02-21 14:02:38 -0800 | [diff] [blame] | 275 | * @param ofv OpenFlow version |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 276 | * @return switch instance |
| 277 | */ |
| 278 | protected OpenFlowSwitchDriver getOFSwitchInstance(long dpid, |
alshabib | b452fd7 | 2015-04-22 20:46:20 -0700 | [diff] [blame] | 279 | OFDescStatsReply desc, |
| 280 | OFVersion ofv) { |
Jonathan Hart | a0d1249 | 2015-07-16 12:03:41 -0700 | [diff] [blame] | 281 | Dpid dpidObj = new Dpid(dpid); |
| 282 | |
| 283 | Driver driver; |
| 284 | try { |
Sho SHIMIZU | bc82ebb | 2015-08-25 10:15:21 -0700 | [diff] [blame] | 285 | driver = driverService.getDriver(DeviceId.deviceId(Dpid.uri(dpidObj))); |
Jonathan Hart | a0d1249 | 2015-07-16 12:03:41 -0700 | [diff] [blame] | 286 | } catch (ItemNotFoundException e) { |
| 287 | driver = driverService.getDriver(desc.getMfrDesc(), desc.getHwDesc(), desc.getSwDesc()); |
| 288 | } |
alshabib | b452fd7 | 2015-04-22 20:46:20 -0700 | [diff] [blame] | 289 | |
Thomas Vachuska | 3358af2 | 2015-05-19 18:40:34 -0700 | [diff] [blame] | 290 | if (driver != null && driver.hasBehaviour(OpenFlowSwitchDriver.class)) { |
Thomas Vachuska | 80b0a80 | 2015-07-17 08:43:30 -0700 | [diff] [blame] | 291 | Dpid did = new Dpid(dpid); |
| 292 | DefaultDriverHandler handler = |
| 293 | new DefaultDriverHandler(new DefaultDriverData(driver, deviceId(uri(did)))); |
| 294 | OpenFlowSwitchDriver ofSwitchDriver = |
| 295 | driver.createBehaviour(handler, OpenFlowSwitchDriver.class); |
| 296 | ofSwitchDriver.init(did, desc, ofv); |
alshabib | b452fd7 | 2015-04-22 20:46:20 -0700 | [diff] [blame] | 297 | ofSwitchDriver.setAgent(agent); |
| 298 | ofSwitchDriver.setRoleHandler(new RoleManager(ofSwitchDriver)); |
Saurav Das | 100e3b8 | 2015-04-30 11:12:10 -0700 | [diff] [blame] | 299 | log.info("OpenFlow handshaker found for device {}: {}", dpid, ofSwitchDriver); |
alshabib | b452fd7 | 2015-04-22 20:46:20 -0700 | [diff] [blame] | 300 | return ofSwitchDriver; |
| 301 | } |
| 302 | log.error("No OpenFlow driver for {} : {}", dpid, desc); |
| 303 | return null; |
| 304 | |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 305 | } |
| 306 | |
alshabib | b452fd7 | 2015-04-22 20:46:20 -0700 | [diff] [blame] | 307 | public void start(OpenFlowAgent ag, DriverService driverService) { |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 308 | log.info("Starting OpenFlow IO"); |
| 309 | this.agent = ag; |
alshabib | b452fd7 | 2015-04-22 20:46:20 -0700 | [diff] [blame] | 310 | this.driverService = driverService; |
Jonathan Hart | bbd91d4 | 2015-02-27 11:18:04 -0800 | [diff] [blame] | 311 | this.init(); |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 312 | this.run(); |
| 313 | } |
| 314 | |
| 315 | |
| 316 | public void stop() { |
| 317 | log.info("Stopping OpenFlow IO"); |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 318 | cg.close(); |
Thomas Vachuska | 1c681d7 | 2015-05-18 14:58:53 -0700 | [diff] [blame] | 319 | execFactory.shutdown(); |
tom | 7ef8ff9 | 2014-09-17 13:08:06 -0700 | [diff] [blame] | 320 | } |
| 321 | |
| 322 | } |