Add configuration setting to allow one switch to use the Corsa driver.
Change-Id: I6b17098e6d7c31a2d19ccbb0b5a56bd3b5b1e33a
Showing
4 changed files
with
67 additions
and
15 deletions
... | @@ -48,6 +48,10 @@ | ... | @@ -48,6 +48,10 @@ |
48 | <groupId>org.apache.felix</groupId> | 48 | <groupId>org.apache.felix</groupId> |
49 | <artifactId>org.apache.felix.scr.annotations</artifactId> | 49 | <artifactId>org.apache.felix.scr.annotations</artifactId> |
50 | </dependency> | 50 | </dependency> |
51 | + <dependency> | ||
52 | + <groupId>org.osgi</groupId> | ||
53 | + <artifactId>org.osgi.compendium</artifactId> | ||
54 | + </dependency> | ||
51 | </dependencies> | 55 | </dependencies> |
52 | 56 | ||
53 | <build> | 57 | <build> | ... | ... |
... | @@ -89,7 +89,7 @@ public class Controller { | ... | @@ -89,7 +89,7 @@ public class Controller { |
89 | // We return a copy of the mapping so we can guarantee that | 89 | // We return a copy of the mapping so we can guarantee that |
90 | // the mapping return is the same as one that will be (or was) | 90 | // the mapping return is the same as one that will be (or was) |
91 | // dispatched to IHAListeners | 91 | // dispatched to IHAListeners |
92 | - HashMap<String, String> retval = new HashMap<String, String>(); | 92 | + HashMap<String, String> retval = new HashMap<>(); |
93 | synchronized (controllerNodeIPsCache) { | 93 | synchronized (controllerNodeIPsCache) { |
94 | retval.putAll(controllerNodeIPsCache); | 94 | retval.putAll(controllerNodeIPsCache); |
95 | } | 95 | } |
... | @@ -152,6 +152,15 @@ public class Controller { | ... | @@ -152,6 +152,15 @@ public class Controller { |
152 | if (ofPort != null) { | 152 | if (ofPort != null) { |
153 | this.openFlowPort = Integer.parseInt(ofPort); | 153 | this.openFlowPort = Integer.parseInt(ofPort); |
154 | } | 154 | } |
155 | + String corsaDpid = configParams.get("corsaDpid"); | ||
156 | + if (corsaDpid != null) { | ||
157 | + try { | ||
158 | + DriverManager.setCorsaDpid(new Dpid(corsaDpid)); | ||
159 | + log.info("Corsa DPID set to {}", corsaDpid); | ||
160 | + } catch (NumberFormatException e) { | ||
161 | + log.warn("Malformed Corsa DPID string", e); | ||
162 | + } | ||
163 | + } | ||
155 | log.debug("OpenFlow port set to {}", this.openFlowPort); | 164 | log.debug("OpenFlow port set to {}", this.openFlowPort); |
156 | String threads = configParams.get("workerthreads"); | 165 | String threads = configParams.get("workerthreads"); |
157 | this.workerThreads = threads != null ? Integer.parseInt(threads) : 16; | 166 | this.workerThreads = threads != null ? Integer.parseInt(threads) : 16; |
... | @@ -161,18 +170,13 @@ public class Controller { | ... | @@ -161,18 +170,13 @@ public class Controller { |
161 | 170 | ||
162 | /** | 171 | /** |
163 | * Initialize internal data structures. | 172 | * Initialize internal data structures. |
164 | - * | ||
165 | - * @param configParams configuration parameters | ||
166 | */ | 173 | */ |
167 | - public void init(Map<String, String> configParams) { | 174 | + public void init() { |
168 | // These data structures are initialized here because other | 175 | // These data structures are initialized here because other |
169 | // module's startUp() might be called before ours | 176 | // module's startUp() might be called before ours |
170 | - this.controllerNodeIPsCache = new HashMap<String, String>(); | 177 | + this.controllerNodeIPsCache = new HashMap<>(); |
171 | 178 | ||
172 | - setConfigParams(configParams); | ||
173 | this.systemStartTime = System.currentTimeMillis(); | 179 | this.systemStartTime = System.currentTimeMillis(); |
174 | - | ||
175 | - | ||
176 | } | 180 | } |
177 | 181 | ||
178 | // ************** | 182 | // ************** |
... | @@ -180,7 +184,7 @@ public class Controller { | ... | @@ -180,7 +184,7 @@ public class Controller { |
180 | // ************** | 184 | // ************** |
181 | 185 | ||
182 | public Map<String, Long> getMemory() { | 186 | public Map<String, Long> getMemory() { |
183 | - Map<String, Long> m = new HashMap<String, Long>(); | 187 | + Map<String, Long> m = new HashMap<>(); |
184 | Runtime runtime = Runtime.getRuntime(); | 188 | Runtime runtime = Runtime.getRuntime(); |
185 | m.put("total", runtime.totalMemory()); | 189 | m.put("total", runtime.totalMemory()); |
186 | m.put("free", runtime.freeMemory()); | 190 | m.put("free", runtime.freeMemory()); |
... | @@ -213,7 +217,7 @@ public class Controller { | ... | @@ -213,7 +217,7 @@ public class Controller { |
213 | public void start(OpenFlowAgent ag) { | 217 | public void start(OpenFlowAgent ag) { |
214 | log.info("Starting OpenFlow IO"); | 218 | log.info("Starting OpenFlow IO"); |
215 | this.agent = ag; | 219 | this.agent = ag; |
216 | - this.init(new HashMap<String, String>()); | 220 | + this.init(); |
217 | this.run(); | 221 | this.run(); |
218 | } | 222 | } |
219 | 223 | ... | ... |
... | @@ -22,6 +22,7 @@ import com.google.common.collect.Sets; | ... | @@ -22,6 +22,7 @@ import com.google.common.collect.Sets; |
22 | import org.apache.felix.scr.annotations.Activate; | 22 | import org.apache.felix.scr.annotations.Activate; |
23 | import org.apache.felix.scr.annotations.Component; | 23 | import org.apache.felix.scr.annotations.Component; |
24 | import org.apache.felix.scr.annotations.Deactivate; | 24 | import org.apache.felix.scr.annotations.Deactivate; |
25 | +import org.apache.felix.scr.annotations.Modified; | ||
25 | import org.apache.felix.scr.annotations.Service; | 26 | import org.apache.felix.scr.annotations.Service; |
26 | import org.onosproject.openflow.controller.DefaultOpenFlowPacketContext; | 27 | import org.onosproject.openflow.controller.DefaultOpenFlowPacketContext; |
27 | import org.onosproject.openflow.controller.Dpid; | 28 | import org.onosproject.openflow.controller.Dpid; |
... | @@ -33,6 +34,7 @@ import org.onosproject.openflow.controller.OpenFlowSwitchListener; | ... | @@ -33,6 +34,7 @@ import org.onosproject.openflow.controller.OpenFlowSwitchListener; |
33 | import org.onosproject.openflow.controller.PacketListener; | 34 | import org.onosproject.openflow.controller.PacketListener; |
34 | import org.onosproject.openflow.controller.RoleState; | 35 | import org.onosproject.openflow.controller.RoleState; |
35 | import org.onosproject.openflow.controller.driver.OpenFlowAgent; | 36 | import org.onosproject.openflow.controller.driver.OpenFlowAgent; |
37 | +import org.osgi.service.component.ComponentContext; | ||
36 | import org.projectfloodlight.openflow.protocol.OFCircuitPortStatus; | 38 | import org.projectfloodlight.openflow.protocol.OFCircuitPortStatus; |
37 | import org.projectfloodlight.openflow.protocol.OFExperimenter; | 39 | import org.projectfloodlight.openflow.protocol.OFExperimenter; |
38 | import org.projectfloodlight.openflow.protocol.OFFactories; | 40 | import org.projectfloodlight.openflow.protocol.OFFactories; |
... | @@ -52,7 +54,10 @@ import org.slf4j.Logger; | ... | @@ -52,7 +54,10 @@ import org.slf4j.Logger; |
52 | import org.slf4j.LoggerFactory; | 54 | import org.slf4j.LoggerFactory; |
53 | 55 | ||
54 | import java.util.Collection; | 56 | import java.util.Collection; |
57 | +import java.util.Dictionary; | ||
58 | +import java.util.HashMap; | ||
55 | import java.util.HashSet; | 59 | import java.util.HashSet; |
60 | +import java.util.Map; | ||
56 | import java.util.Set; | 61 | import java.util.Set; |
57 | import java.util.concurrent.ConcurrentHashMap; | 62 | import java.util.concurrent.ConcurrentHashMap; |
58 | import java.util.concurrent.ExecutorService; | 63 | import java.util.concurrent.ExecutorService; |
... | @@ -102,7 +107,9 @@ public class OpenFlowControllerImpl implements OpenFlowController { | ... | @@ -102,7 +107,9 @@ public class OpenFlowControllerImpl implements OpenFlowController { |
102 | private final Controller ctrl = new Controller(); | 107 | private final Controller ctrl = new Controller(); |
103 | 108 | ||
104 | @Activate | 109 | @Activate |
105 | - public void activate() { | 110 | + public void activate(ComponentContext context) { |
111 | + Map<String, String> properties = readComponentConfiguration(context); | ||
112 | + ctrl.setConfigParams(properties); | ||
106 | ctrl.start(agent); | 113 | ctrl.start(agent); |
107 | } | 114 | } |
108 | 115 | ||
... | @@ -111,6 +118,32 @@ public class OpenFlowControllerImpl implements OpenFlowController { | ... | @@ -111,6 +118,32 @@ public class OpenFlowControllerImpl implements OpenFlowController { |
111 | ctrl.stop(); | 118 | ctrl.stop(); |
112 | } | 119 | } |
113 | 120 | ||
121 | + /** | ||
122 | + * Extracts properties from the component configuration context. | ||
123 | + * | ||
124 | + * @param context the component context | ||
125 | + */ | ||
126 | + private Map<String, String> readComponentConfiguration(ComponentContext context) { | ||
127 | + Dictionary<?, ?> properties = context.getProperties(); | ||
128 | + Map<String, String> outProperties = new HashMap<>(); | ||
129 | + try { | ||
130 | + String strDpid = (String) properties.get("corsaDpid"); | ||
131 | + if (strDpid != null) { | ||
132 | + outProperties.put("corsaDpid", strDpid); | ||
133 | + } | ||
134 | + } catch (ClassCastException e) { | ||
135 | + return outProperties; | ||
136 | + } | ||
137 | + return outProperties; | ||
138 | + } | ||
139 | + | ||
140 | + @Modified | ||
141 | + public void modified(ComponentContext context) { | ||
142 | + // Blank @Modified method to catch modifications to the context. | ||
143 | + // If no @Modified method exists, @Activate is called again | ||
144 | + // when the context is modified. | ||
145 | + } | ||
146 | + | ||
114 | @Override | 147 | @Override |
115 | public Iterable<OpenFlowSwitch> getSwitches() { | 148 | public Iterable<OpenFlowSwitch> getSwitches() { |
116 | return connectedSwitches.values(); | 149 | return connectedSwitches.values(); | ... | ... |
... | @@ -16,9 +16,6 @@ | ... | @@ -16,9 +16,6 @@ |
16 | package org.onosproject.openflow.drivers; | 16 | package org.onosproject.openflow.drivers; |
17 | 17 | ||
18 | 18 | ||
19 | -import java.util.Collections; | ||
20 | -import java.util.List; | ||
21 | - | ||
22 | import org.onosproject.openflow.controller.Dpid; | 19 | import org.onosproject.openflow.controller.Dpid; |
23 | import org.onosproject.openflow.controller.RoleState; | 20 | import org.onosproject.openflow.controller.RoleState; |
24 | import org.onosproject.openflow.controller.driver.AbstractOpenFlowSwitch; | 21 | import org.onosproject.openflow.controller.driver.AbstractOpenFlowSwitch; |
... | @@ -33,6 +30,9 @@ import org.projectfloodlight.openflow.types.TableId; | ... | @@ -33,6 +30,9 @@ import org.projectfloodlight.openflow.types.TableId; |
33 | import org.slf4j.Logger; | 30 | import org.slf4j.Logger; |
34 | import org.slf4j.LoggerFactory; | 31 | import org.slf4j.LoggerFactory; |
35 | 32 | ||
33 | +import java.util.Collections; | ||
34 | +import java.util.List; | ||
35 | + | ||
36 | /** | 36 | /** |
37 | * A simple implementation of a driver manager that differentiates between | 37 | * A simple implementation of a driver manager that differentiates between |
38 | * connected switches using the OF Description Statistics Reply message. | 38 | * connected switches using the OF Description Statistics Reply message. |
... | @@ -43,6 +43,8 @@ public final class DriverManager implements OpenFlowSwitchDriverFactory { | ... | @@ -43,6 +43,8 @@ public final class DriverManager implements OpenFlowSwitchDriverFactory { |
43 | 43 | ||
44 | private static final int LOWEST_PRIORITY = 0; | 44 | private static final int LOWEST_PRIORITY = 0; |
45 | 45 | ||
46 | + private static Dpid corsaDpid = new Dpid(); | ||
47 | + | ||
46 | /** | 48 | /** |
47 | * Return an IOFSwitch object based on switch's manufacturer description | 49 | * Return an IOFSwitch object based on switch's manufacturer description |
48 | * from OFDescStatsReply. | 50 | * from OFDescStatsReply. |
... | @@ -56,6 +58,11 @@ public final class DriverManager implements OpenFlowSwitchDriverFactory { | ... | @@ -56,6 +58,11 @@ public final class DriverManager implements OpenFlowSwitchDriverFactory { |
56 | OFDescStatsReply desc, OFVersion ofv) { | 58 | OFDescStatsReply desc, OFVersion ofv) { |
57 | String vendor = desc.getMfrDesc(); | 59 | String vendor = desc.getMfrDesc(); |
58 | String hw = desc.getHwDesc(); | 60 | String hw = desc.getHwDesc(); |
61 | + | ||
62 | + if (dpid.equals(corsaDpid)) { | ||
63 | + return new OFCorsaSwitchDriver(dpid, desc); | ||
64 | + } | ||
65 | + | ||
59 | if (vendor.startsWith("Stanford University, Ericsson Research and CPqD Research") | 66 | if (vendor.startsWith("Stanford University, Ericsson Research and CPqD Research") |
60 | && | 67 | && |
61 | hw.startsWith("OpenFlow 1.3 Reference Userspace Switch")) { | 68 | hw.startsWith("OpenFlow 1.3 Reference Userspace Switch")) { |
... | @@ -83,7 +90,7 @@ public final class DriverManager implements OpenFlowSwitchDriverFactory { | ... | @@ -83,7 +90,7 @@ public final class DriverManager implements OpenFlowSwitchDriverFactory { |
83 | } | 90 | } |
84 | 91 | ||
85 | log.warn("DriverManager could not identify switch desc: {}. " | 92 | log.warn("DriverManager could not identify switch desc: {}. " |
86 | - + "Assigning AbstractOpenFlowSwich", desc); | 93 | + + "Assigning AbstractOpenFlowSwich", desc); |
87 | return new AbstractOpenFlowSwitch(dpid, desc) { | 94 | return new AbstractOpenFlowSwitch(dpid, desc) { |
88 | 95 | ||
89 | @Override | 96 | @Override |
... | @@ -157,4 +164,8 @@ public final class DriverManager implements OpenFlowSwitchDriverFactory { | ... | @@ -157,4 +164,8 @@ public final class DriverManager implements OpenFlowSwitchDriverFactory { |
157 | return new DriverManager().getOFSwitchImpl(dpid, desc, ofv); | 164 | return new DriverManager().getOFSwitchImpl(dpid, desc, ofv); |
158 | } | 165 | } |
159 | 166 | ||
167 | + public static void setCorsaDpid(Dpid dpid) { | ||
168 | + corsaDpid = dpid; | ||
169 | + } | ||
170 | + | ||
160 | } | 171 | } | ... | ... |
-
Please register or login to post a comment