Listen for OpenFlow connections on 6633 and 6653
Also, cleaning up OFController config Change-Id: I5f1fe159a6c59d3bea99bd89303f2afc4cf269b6
Showing
2 changed files
with
30 additions
and
47 deletions
| ... | @@ -16,6 +16,8 @@ | ... | @@ -16,6 +16,8 @@ |
| 16 | 16 | ||
| 17 | package org.onosproject.openflow.controller.impl; | 17 | package org.onosproject.openflow.controller.impl; |
| 18 | 18 | ||
| 19 | +import com.google.common.base.Strings; | ||
| 20 | +import com.google.common.collect.ImmutableList; | ||
| 19 | import org.jboss.netty.bootstrap.ServerBootstrap; | 21 | import org.jboss.netty.bootstrap.ServerBootstrap; |
| 20 | import org.jboss.netty.channel.ChannelPipelineFactory; | 22 | import org.jboss.netty.channel.ChannelPipelineFactory; |
| 21 | import org.jboss.netty.channel.group.ChannelGroup; | 23 | import org.jboss.netty.channel.group.ChannelGroup; |
| ... | @@ -40,10 +42,15 @@ import org.slf4j.LoggerFactory; | ... | @@ -40,10 +42,15 @@ import org.slf4j.LoggerFactory; |
| 40 | import java.lang.management.ManagementFactory; | 42 | import java.lang.management.ManagementFactory; |
| 41 | import java.lang.management.RuntimeMXBean; | 43 | import java.lang.management.RuntimeMXBean; |
| 42 | import java.net.InetSocketAddress; | 44 | import java.net.InetSocketAddress; |
| 45 | +import java.util.Dictionary; | ||
| 43 | import java.util.HashMap; | 46 | import java.util.HashMap; |
| 47 | +import java.util.List; | ||
| 44 | import java.util.Map; | 48 | import java.util.Map; |
| 45 | import java.util.concurrent.Executors; | 49 | import java.util.concurrent.Executors; |
| 50 | +import java.util.stream.Collectors; | ||
| 51 | +import java.util.stream.Stream; | ||
| 46 | 52 | ||
| 53 | +import static org.onlab.util.Tools.get; | ||
| 47 | import static org.onlab.util.Tools.groupedThreads; | 54 | import static org.onlab.util.Tools.groupedThreads; |
| 48 | import static org.onosproject.net.DeviceId.deviceId; | 55 | import static org.onosproject.net.DeviceId.deviceId; |
| 49 | import static org.onosproject.openflow.controller.Dpid.uri; | 56 | import static org.onosproject.openflow.controller.Dpid.uri; |
| ... | @@ -65,8 +72,8 @@ public class Controller { | ... | @@ -65,8 +72,8 @@ public class Controller { |
| 65 | private ChannelGroup cg; | 72 | private ChannelGroup cg; |
| 66 | 73 | ||
| 67 | // Configuration options | 74 | // Configuration options |
| 68 | - protected int openFlowPort = 6653; | 75 | + protected List<Integer> openFlowPorts = ImmutableList.of(6633, 6653); |
| 69 | - protected int workerThreads = 0; | 76 | + protected int workerThreads = 16; |
| 70 | 77 | ||
| 71 | // Start time of the controller | 78 | // Start time of the controller |
| 72 | protected long systemStartTime; | 79 | protected long systemStartTime; |
| ... | @@ -129,11 +136,13 @@ public class Controller { | ... | @@ -129,11 +136,13 @@ public class Controller { |
| 129 | ChannelPipelineFactory pfact = | 136 | ChannelPipelineFactory pfact = |
| 130 | new OpenflowPipelineFactory(this, null); | 137 | new OpenflowPipelineFactory(this, null); |
| 131 | bootstrap.setPipelineFactory(pfact); | 138 | bootstrap.setPipelineFactory(pfact); |
| 132 | - InetSocketAddress sa = new InetSocketAddress(openFlowPort); | ||
| 133 | cg = new DefaultChannelGroup(); | 139 | cg = new DefaultChannelGroup(); |
| 134 | - cg.add(bootstrap.bind(sa)); | 140 | + openFlowPorts.forEach(port -> { |
| 141 | + InetSocketAddress sa = new InetSocketAddress(port); | ||
| 142 | + cg.add(bootstrap.bind(sa)); | ||
| 143 | + log.info("Listening for switch connections on {}", sa); | ||
| 144 | + }); | ||
| 135 | 145 | ||
| 136 | - log.info("Listening for switch connections on {}", sa); | ||
| 137 | } catch (Exception e) { | 146 | } catch (Exception e) { |
| 138 | throw new RuntimeException(e); | 147 | throw new RuntimeException(e); |
| 139 | } | 148 | } |
| ... | @@ -155,19 +164,22 @@ public class Controller { | ... | @@ -155,19 +164,22 @@ public class Controller { |
| 155 | } | 164 | } |
| 156 | } | 165 | } |
| 157 | 166 | ||
| 158 | - public void setConfigParams(Map<String, String> configParams) { | 167 | + public void setConfigParams(Dictionary<?, ?> properties) { |
| 159 | - String ofPort = configParams.get("openflowport"); | 168 | + String ports = get(properties, "openflowPorts"); |
| 160 | - if (ofPort != null) { | 169 | + if (!Strings.isNullOrEmpty(ports)) { |
| 161 | - this.openFlowPort = Integer.parseInt(ofPort); | 170 | + this.openFlowPorts = Stream.of(ports.split(",")) |
| 171 | + .map(s -> Integer.parseInt(s)) | ||
| 172 | + .collect(Collectors.toList()); | ||
| 162 | } | 173 | } |
| 163 | - log.debug("OpenFlow port set to {}", this.openFlowPort); | 174 | + log.debug("OpenFlow ports set to {}", this.openFlowPorts); |
| 164 | 175 | ||
| 165 | - String threads = configParams.get("workerthreads"); | 176 | + String threads = get(properties, "workerThreads"); |
| 166 | - this.workerThreads = threads != null ? Integer.parseInt(threads) : 16; | 177 | + if (!Strings.isNullOrEmpty(threads)) { |
| 178 | + this.workerThreads = Integer.parseInt(threads); | ||
| 179 | + } | ||
| 167 | log.debug("Number of worker threads set to {}", this.workerThreads); | 180 | log.debug("Number of worker threads set to {}", this.workerThreads); |
| 168 | } | 181 | } |
| 169 | 182 | ||
| 170 | - | ||
| 171 | /** | 183 | /** |
| 172 | * Initialize internal data structures. | 184 | * Initialize internal data structures. |
| 173 | */ | 185 | */ | ... | ... |
| ... | @@ -15,7 +15,6 @@ | ... | @@ -15,7 +15,6 @@ |
| 15 | */ | 15 | */ |
| 16 | package org.onosproject.openflow.controller.impl; | 16 | package org.onosproject.openflow.controller.impl; |
| 17 | 17 | ||
| 18 | -import com.google.common.base.Strings; | ||
| 19 | import com.google.common.collect.ArrayListMultimap; | 18 | import com.google.common.collect.ArrayListMultimap; |
| 20 | import com.google.common.collect.Lists; | 19 | import com.google.common.collect.Lists; |
| 21 | import com.google.common.collect.Multimap; | 20 | import com.google.common.collect.Multimap; |
| ... | @@ -67,11 +66,8 @@ import org.slf4j.LoggerFactory; | ... | @@ -67,11 +66,8 @@ import org.slf4j.LoggerFactory; |
| 67 | 66 | ||
| 68 | import java.util.Collection; | 67 | import java.util.Collection; |
| 69 | import java.util.Collections; | 68 | import java.util.Collections; |
| 70 | -import java.util.Dictionary; | ||
| 71 | -import java.util.HashMap; | ||
| 72 | import java.util.LinkedList; | 69 | import java.util.LinkedList; |
| 73 | import java.util.List; | 70 | import java.util.List; |
| 74 | -import java.util.Map; | ||
| 75 | import java.util.Set; | 71 | import java.util.Set; |
| 76 | import java.util.concurrent.ConcurrentHashMap; | 72 | import java.util.concurrent.ConcurrentHashMap; |
| 77 | import java.util.concurrent.CopyOnWriteArraySet; | 73 | import java.util.concurrent.CopyOnWriteArraySet; |
| ... | @@ -80,13 +76,12 @@ import java.util.concurrent.Executors; | ... | @@ -80,13 +76,12 @@ import java.util.concurrent.Executors; |
| 80 | import java.util.concurrent.locks.Lock; | 76 | import java.util.concurrent.locks.Lock; |
| 81 | import java.util.concurrent.locks.ReentrantLock; | 77 | import java.util.concurrent.locks.ReentrantLock; |
| 82 | 78 | ||
| 83 | -import static org.onlab.util.Tools.get; | ||
| 84 | import static org.onlab.util.Tools.groupedThreads; | 79 | import static org.onlab.util.Tools.groupedThreads; |
| 85 | 80 | ||
| 86 | @Component(immediate = true) | 81 | @Component(immediate = true) |
| 87 | @Service | 82 | @Service |
| 88 | public class OpenFlowControllerImpl implements OpenFlowController { | 83 | public class OpenFlowControllerImpl implements OpenFlowController { |
| 89 | - private static final int DEFAULT_OFPORT = 6653; | 84 | + private static final String DEFAULT_OFPORT = "6633,6653"; |
| 90 | private static final int DEFAULT_WORKER_THREADS = 16; | 85 | private static final int DEFAULT_WORKER_THREADS = 16; |
| 91 | 86 | ||
| 92 | private static final Logger log = | 87 | private static final Logger log = |
| ... | @@ -102,9 +97,9 @@ public class OpenFlowControllerImpl implements OpenFlowController { | ... | @@ -102,9 +97,9 @@ public class OpenFlowControllerImpl implements OpenFlowController { |
| 102 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 97 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 103 | protected ComponentConfigService cfgService; | 98 | protected ComponentConfigService cfgService; |
| 104 | 99 | ||
| 105 | - @Property(name = "openflowPort", intValue = DEFAULT_OFPORT, | 100 | + @Property(name = "openflowPort", value = DEFAULT_OFPORT, |
| 106 | label = "Port number used by OpenFlow protocol; default is 6653") | 101 | label = "Port number used by OpenFlow protocol; default is 6653") |
| 107 | - private int openflowPort = DEFAULT_OFPORT; | 102 | + private String openflowPort = DEFAULT_OFPORT; |
| 108 | 103 | ||
| 109 | @Property(name = "workerThreads", intValue = DEFAULT_WORKER_THREADS, | 104 | @Property(name = "workerThreads", intValue = DEFAULT_WORKER_THREADS, |
| 110 | label = "Number of controller worker threads; default is 16") | 105 | label = "Number of controller worker threads; default is 16") |
| ... | @@ -148,8 +143,7 @@ public class OpenFlowControllerImpl implements OpenFlowController { | ... | @@ -148,8 +143,7 @@ public class OpenFlowControllerImpl implements OpenFlowController { |
| 148 | @Activate | 143 | @Activate |
| 149 | public void activate(ComponentContext context) { | 144 | public void activate(ComponentContext context) { |
| 150 | cfgService.registerProperties(getClass()); | 145 | cfgService.registerProperties(getClass()); |
| 151 | - Map<String, String> properties = readComponentConfiguration(context); | 146 | + ctrl.setConfigParams(context.getProperties()); |
| 152 | - ctrl.setConfigParams(properties); | ||
| 153 | ctrl.start(agent, driverService); | 147 | ctrl.start(agent, driverService); |
| 154 | } | 148 | } |
| 155 | 149 | ||
| ... | @@ -159,33 +153,10 @@ public class OpenFlowControllerImpl implements OpenFlowController { | ... | @@ -159,33 +153,10 @@ public class OpenFlowControllerImpl implements OpenFlowController { |
| 159 | ctrl.stop(); | 153 | ctrl.stop(); |
| 160 | } | 154 | } |
| 161 | 155 | ||
| 162 | - /** | ||
| 163 | - * Extracts properties from the component configuration context. | ||
| 164 | - * | ||
| 165 | - * @param context the component context | ||
| 166 | - */ | ||
| 167 | - private Map<String, String> readComponentConfiguration(ComponentContext context) { | ||
| 168 | - Dictionary<?, ?> properties = context.getProperties(); | ||
| 169 | - Map<String, String> outProperties = new HashMap<>(); | ||
| 170 | - | ||
| 171 | - String port = get(properties, "openflowPort"); | ||
| 172 | - if (!Strings.isNullOrEmpty(port)) { | ||
| 173 | - outProperties.put("openflowport", port); | ||
| 174 | - } | ||
| 175 | - | ||
| 176 | - String thread = get(properties, "workerThreads"); | ||
| 177 | - if (!Strings.isNullOrEmpty(thread)) { | ||
| 178 | - outProperties.put("workerthreads", thread); | ||
| 179 | - } | ||
| 180 | - | ||
| 181 | - return outProperties; | ||
| 182 | - } | ||
| 183 | - | ||
| 184 | @Modified | 156 | @Modified |
| 185 | public void modified(ComponentContext context) { | 157 | public void modified(ComponentContext context) { |
| 186 | - Map<String, String> properties = readComponentConfiguration(context); | ||
| 187 | ctrl.stop(); | 158 | ctrl.stop(); |
| 188 | - ctrl.setConfigParams(properties); | 159 | + ctrl.setConfigParams(context.getProperties()); |
| 189 | ctrl.start(agent, driverService); | 160 | ctrl.start(agent, driverService); |
| 190 | } | 161 | } |
| 191 | 162 | ... | ... |
-
Please register or login to post a comment