Listen for OpenFlow connections on 6633 and 6653

Also, cleaning up OFController config

Change-Id: I5f1fe159a6c59d3bea99bd89303f2afc4cf269b6
diff --git a/openflow/ctl/src/main/java/org/onosproject/openflow/controller/impl/Controller.java b/openflow/ctl/src/main/java/org/onosproject/openflow/controller/impl/Controller.java
index fd7c35d..3b473b8 100644
--- a/openflow/ctl/src/main/java/org/onosproject/openflow/controller/impl/Controller.java
+++ b/openflow/ctl/src/main/java/org/onosproject/openflow/controller/impl/Controller.java
@@ -16,6 +16,8 @@
 
 package org.onosproject.openflow.controller.impl;
 
+import com.google.common.base.Strings;
+import com.google.common.collect.ImmutableList;
 import org.jboss.netty.bootstrap.ServerBootstrap;
 import org.jboss.netty.channel.ChannelPipelineFactory;
 import org.jboss.netty.channel.group.ChannelGroup;
@@ -40,10 +42,15 @@
 import java.lang.management.ManagementFactory;
 import java.lang.management.RuntimeMXBean;
 import java.net.InetSocketAddress;
+import java.util.Dictionary;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 import java.util.concurrent.Executors;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
 
+import static org.onlab.util.Tools.get;
 import static org.onlab.util.Tools.groupedThreads;
 import static org.onosproject.net.DeviceId.deviceId;
 import static org.onosproject.openflow.controller.Dpid.uri;
@@ -65,8 +72,8 @@
     private ChannelGroup cg;
 
     // Configuration options
-    protected int openFlowPort = 6653;
-    protected int workerThreads = 0;
+    protected List<Integer> openFlowPorts = ImmutableList.of(6633, 6653);
+    protected int workerThreads = 16;
 
     // Start time of the controller
     protected long systemStartTime;
@@ -129,11 +136,13 @@
             ChannelPipelineFactory pfact =
                     new OpenflowPipelineFactory(this, null);
             bootstrap.setPipelineFactory(pfact);
-            InetSocketAddress sa = new InetSocketAddress(openFlowPort);
             cg = new DefaultChannelGroup();
-            cg.add(bootstrap.bind(sa));
+            openFlowPorts.forEach(port -> {
+                InetSocketAddress sa = new InetSocketAddress(port);
+                cg.add(bootstrap.bind(sa));
+                log.info("Listening for switch connections on {}", sa);
+            });
 
-            log.info("Listening for switch connections on {}", sa);
         } catch (Exception e) {
             throw new RuntimeException(e);
         }
@@ -155,19 +164,22 @@
         }
     }
 
-    public void setConfigParams(Map<String, String> configParams) {
-        String ofPort = configParams.get("openflowport");
-        if (ofPort != null) {
-            this.openFlowPort = Integer.parseInt(ofPort);
+    public void setConfigParams(Dictionary<?, ?> properties) {
+        String ports = get(properties, "openflowPorts");
+        if (!Strings.isNullOrEmpty(ports)) {
+            this.openFlowPorts = Stream.of(ports.split(","))
+                                       .map(s -> Integer.parseInt(s))
+                                       .collect(Collectors.toList());
         }
-        log.debug("OpenFlow port set to {}", this.openFlowPort);
+        log.debug("OpenFlow ports set to {}", this.openFlowPorts);
 
-        String threads = configParams.get("workerthreads");
-        this.workerThreads = threads != null ? Integer.parseInt(threads) : 16;
+        String threads = get(properties, "workerThreads");
+        if (!Strings.isNullOrEmpty(threads)) {
+            this.workerThreads = Integer.parseInt(threads);
+        }
         log.debug("Number of worker threads set to {}", this.workerThreads);
     }
 
-
     /**
      * Initialize internal data structures.
      */
diff --git a/openflow/ctl/src/main/java/org/onosproject/openflow/controller/impl/OpenFlowControllerImpl.java b/openflow/ctl/src/main/java/org/onosproject/openflow/controller/impl/OpenFlowControllerImpl.java
index c52f4bb..cff8cdc 100644
--- a/openflow/ctl/src/main/java/org/onosproject/openflow/controller/impl/OpenFlowControllerImpl.java
+++ b/openflow/ctl/src/main/java/org/onosproject/openflow/controller/impl/OpenFlowControllerImpl.java
@@ -15,7 +15,6 @@
  */
 package org.onosproject.openflow.controller.impl;
 
-import com.google.common.base.Strings;
 import com.google.common.collect.ArrayListMultimap;
 import com.google.common.collect.Lists;
 import com.google.common.collect.Multimap;
@@ -67,11 +66,8 @@
 
 import java.util.Collection;
 import java.util.Collections;
-import java.util.Dictionary;
-import java.util.HashMap;
 import java.util.LinkedList;
 import java.util.List;
-import java.util.Map;
 import java.util.Set;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.CopyOnWriteArraySet;
@@ -80,13 +76,12 @@
 import java.util.concurrent.locks.Lock;
 import java.util.concurrent.locks.ReentrantLock;
 
-import static org.onlab.util.Tools.get;
 import static org.onlab.util.Tools.groupedThreads;
 
 @Component(immediate = true)
 @Service
 public class OpenFlowControllerImpl implements OpenFlowController {
-    private static final int DEFAULT_OFPORT = 6653;
+    private static final String DEFAULT_OFPORT = "6633,6653";
     private static final int DEFAULT_WORKER_THREADS = 16;
 
     private static final Logger log =
@@ -102,9 +97,9 @@
     @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
     protected ComponentConfigService cfgService;
 
-    @Property(name = "openflowPort", intValue = DEFAULT_OFPORT,
+    @Property(name = "openflowPort", value = DEFAULT_OFPORT,
             label = "Port number used by OpenFlow protocol; default is 6653")
-    private int openflowPort = DEFAULT_OFPORT;
+    private String openflowPort = DEFAULT_OFPORT;
 
     @Property(name = "workerThreads", intValue = DEFAULT_WORKER_THREADS,
             label = "Number of controller worker threads; default is 16")
@@ -148,8 +143,7 @@
     @Activate
     public void activate(ComponentContext context) {
         cfgService.registerProperties(getClass());
-        Map<String, String> properties = readComponentConfiguration(context);
-        ctrl.setConfigParams(properties);
+        ctrl.setConfigParams(context.getProperties());
         ctrl.start(agent, driverService);
     }
 
@@ -159,33 +153,10 @@
         ctrl.stop();
     }
 
-    /**
-     * Extracts properties from the component configuration context.
-     *
-     * @param context the component context
-     */
-    private Map<String, String> readComponentConfiguration(ComponentContext context) {
-        Dictionary<?, ?> properties = context.getProperties();
-        Map<String, String> outProperties = new HashMap<>();
-
-        String port = get(properties, "openflowPort");
-        if (!Strings.isNullOrEmpty(port)) {
-            outProperties.put("openflowport", port);
-        }
-
-        String thread = get(properties, "workerThreads");
-        if (!Strings.isNullOrEmpty(thread)) {
-            outProperties.put("workerthreads", thread);
-        }
-
-        return outProperties;
-    }
-
     @Modified
     public void modified(ComponentContext context) {
-        Map<String, String> properties = readComponentConfiguration(context);
         ctrl.stop();
-        ctrl.setConfigParams(properties);
+        ctrl.setConfigParams(context.getProperties());
         ctrl.start(agent, driverService);
     }