Charles Chan
Committed by Gerrit Code Review

Make OpenFlow port configurable via cfg command

Example:
cfg set org.onosproject.openflow.controller.impl.OpenFlowControllerImpl openflowPort 6633

Change-Id: I2fa4b0db671003d0b357e63df619f1b0dec38e03
...@@ -55,6 +55,10 @@ ...@@ -55,6 +55,10 @@
55 <groupId>org.apache.felix</groupId> 55 <groupId>org.apache.felix</groupId>
56 <artifactId>maven-scr-plugin</artifactId> 56 <artifactId>maven-scr-plugin</artifactId>
57 </plugin> 57 </plugin>
58 + <plugin>
59 + <groupId>org.onosproject</groupId>
60 + <artifactId>onos-maven-plugin</artifactId>
61 + </plugin>
58 </plugins> 62 </plugins>
59 </build> 63 </build>
60 64
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
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;
18 import com.google.common.collect.ArrayListMultimap; 19 import com.google.common.collect.ArrayListMultimap;
19 import com.google.common.collect.Lists; 20 import com.google.common.collect.Lists;
20 import com.google.common.collect.Multimap; 21 import com.google.common.collect.Multimap;
...@@ -22,9 +23,11 @@ import org.apache.felix.scr.annotations.Activate; ...@@ -22,9 +23,11 @@ import org.apache.felix.scr.annotations.Activate;
22 import org.apache.felix.scr.annotations.Component; 23 import org.apache.felix.scr.annotations.Component;
23 import org.apache.felix.scr.annotations.Deactivate; 24 import org.apache.felix.scr.annotations.Deactivate;
24 import org.apache.felix.scr.annotations.Modified; 25 import org.apache.felix.scr.annotations.Modified;
26 +import org.apache.felix.scr.annotations.Property;
25 import org.apache.felix.scr.annotations.Reference; 27 import org.apache.felix.scr.annotations.Reference;
26 import org.apache.felix.scr.annotations.ReferenceCardinality; 28 import org.apache.felix.scr.annotations.ReferenceCardinality;
27 import org.apache.felix.scr.annotations.Service; 29 import org.apache.felix.scr.annotations.Service;
30 +import org.onosproject.cfg.ComponentConfigService;
28 import org.onosproject.net.driver.DefaultDriverProviderService; 31 import org.onosproject.net.driver.DefaultDriverProviderService;
29 import org.onosproject.net.driver.DriverService; 32 import org.onosproject.net.driver.DriverService;
30 import org.onosproject.openflow.controller.DefaultOpenFlowPacketContext; 33 import org.onosproject.openflow.controller.DefaultOpenFlowPacketContext;
...@@ -77,11 +80,14 @@ import java.util.concurrent.Executors; ...@@ -77,11 +80,14 @@ import java.util.concurrent.Executors;
77 import java.util.concurrent.locks.Lock; 80 import java.util.concurrent.locks.Lock;
78 import java.util.concurrent.locks.ReentrantLock; 81 import java.util.concurrent.locks.ReentrantLock;
79 82
83 +import static org.onlab.util.Tools.get;
80 import static org.onlab.util.Tools.groupedThreads; 84 import static org.onlab.util.Tools.groupedThreads;
81 85
82 @Component(immediate = true) 86 @Component(immediate = true)
83 @Service 87 @Service
84 public class OpenFlowControllerImpl implements OpenFlowController { 88 public class OpenFlowControllerImpl implements OpenFlowController {
89 + private static final int DEFAULT_OFPORT = 6633;
90 + private static final int DEFAULT_WORKER_THREADS = 16;
85 91
86 private static final Logger log = 92 private static final Logger log =
87 LoggerFactory.getLogger(OpenFlowControllerImpl.class); 93 LoggerFactory.getLogger(OpenFlowControllerImpl.class);
...@@ -93,6 +99,17 @@ public class OpenFlowControllerImpl implements OpenFlowController { ...@@ -93,6 +99,17 @@ public class OpenFlowControllerImpl implements OpenFlowController {
93 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 99 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
94 protected DefaultDriverProviderService defaultDriverProviderService; 100 protected DefaultDriverProviderService defaultDriverProviderService;
95 101
102 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
103 + protected ComponentConfigService cfgService;
104 +
105 + @Property(name = "openflowPort", intValue = DEFAULT_OFPORT,
106 + label = "Port number used by OpenFlow protocol; default is 6633")
107 + private int openflowPort = DEFAULT_OFPORT;
108 +
109 + @Property(name = "workerThreads", intValue = DEFAULT_WORKER_THREADS,
110 + label = "Number of controller worker threads; default is 16")
111 + private int workerThreads = DEFAULT_WORKER_THREADS;
112 +
96 private final ExecutorService executorMsgs = 113 private final ExecutorService executorMsgs =
97 Executors.newFixedThreadPool(32, groupedThreads("onos/of", "event-stats-%d")); 114 Executors.newFixedThreadPool(32, groupedThreads("onos/of", "event-stats-%d"));
98 115
...@@ -130,6 +147,7 @@ public class OpenFlowControllerImpl implements OpenFlowController { ...@@ -130,6 +147,7 @@ public class OpenFlowControllerImpl implements OpenFlowController {
130 147
131 @Activate 148 @Activate
132 public void activate(ComponentContext context) { 149 public void activate(ComponentContext context) {
150 + cfgService.registerProperties(getClass());
133 Map<String, String> properties = readComponentConfiguration(context); 151 Map<String, String> properties = readComponentConfiguration(context);
134 ctrl.setConfigParams(properties); 152 ctrl.setConfigParams(properties);
135 ctrl.start(agent, driverService); 153 ctrl.start(agent, driverService);
...@@ -137,6 +155,7 @@ public class OpenFlowControllerImpl implements OpenFlowController { ...@@ -137,6 +155,7 @@ public class OpenFlowControllerImpl implements OpenFlowController {
137 155
138 @Deactivate 156 @Deactivate
139 public void deactivate() { 157 public void deactivate() {
158 + cfgService.unregisterProperties(getClass(), false);
140 ctrl.stop(); 159 ctrl.stop();
141 } 160 }
142 161
...@@ -148,22 +167,26 @@ public class OpenFlowControllerImpl implements OpenFlowController { ...@@ -148,22 +167,26 @@ public class OpenFlowControllerImpl implements OpenFlowController {
148 private Map<String, String> readComponentConfiguration(ComponentContext context) { 167 private Map<String, String> readComponentConfiguration(ComponentContext context) {
149 Dictionary<?, ?> properties = context.getProperties(); 168 Dictionary<?, ?> properties = context.getProperties();
150 Map<String, String> outProperties = new HashMap<>(); 169 Map<String, String> outProperties = new HashMap<>();
151 - try { 170 +
152 - String strDpid = (String) properties.get("corsaDpid"); 171 + String port = get(properties, "openflowPort");
153 - if (strDpid != null) { 172 + if (!Strings.isNullOrEmpty(port)) {
154 - outProperties.put("corsaDpid", strDpid); 173 + outProperties.put("openflowport", port);
155 } 174 }
156 - } catch (ClassCastException e) { 175 +
157 - return outProperties; 176 + String thread = get(properties, "workerThreads");
177 + if (!Strings.isNullOrEmpty(thread)) {
178 + outProperties.put("workerthreads", thread);
158 } 179 }
180 +
159 return outProperties; 181 return outProperties;
160 } 182 }
161 183
162 @Modified 184 @Modified
163 public void modified(ComponentContext context) { 185 public void modified(ComponentContext context) {
164 - // Blank @Modified method to catch modifications to the context. 186 + Map<String, String> properties = readComponentConfiguration(context);
165 - // If no @Modified method exists, @Activate is called again 187 + ctrl.stop();
166 - // when the context is modified. 188 + ctrl.setConfigParams(properties);
189 + ctrl.start(agent, driverService);
167 } 190 }
168 191
169 @Override 192 @Override
......