alshabib
Committed by Gerrit Code Review

WIP: default driver ignition

Change-Id: Ia37de8dcaee2ff2be0908fa12c567acf99ef3a13
...@@ -31,6 +31,8 @@ import org.onosproject.mastership.MastershipService; ...@@ -31,6 +31,8 @@ import org.onosproject.mastership.MastershipService;
31 import org.onosproject.net.Device; 31 import org.onosproject.net.Device;
32 import org.onosproject.net.DeviceId; 32 import org.onosproject.net.DeviceId;
33 import org.onosproject.net.behaviour.Pipeliner; 33 import org.onosproject.net.behaviour.Pipeliner;
34 +import org.onosproject.net.device.DeviceEvent;
35 +import org.onosproject.net.device.DeviceListener;
34 import org.onosproject.net.device.DeviceService; 36 import org.onosproject.net.device.DeviceService;
35 import org.onosproject.net.driver.Driver; 37 import org.onosproject.net.driver.Driver;
36 import org.onosproject.net.driver.DriverHandler; 38 import org.onosproject.net.driver.DriverHandler;
...@@ -73,18 +75,23 @@ public class FlowObjectiveManager implements FlowObjectiveService { ...@@ -73,18 +75,23 @@ public class FlowObjectiveManager implements FlowObjectiveService {
73 75
74 private MastershipListener mastershipListener = new InnerMastershipListener(); 76 private MastershipListener mastershipListener = new InnerMastershipListener();
75 77
78 + private DeviceListener deviceListener = new InnerDeviceListener();
79 +
76 private Map<DeviceId, DriverHandler> driverHandlers = 80 private Map<DeviceId, DriverHandler> driverHandlers =
77 Maps.newConcurrentMap(); 81 Maps.newConcurrentMap();
78 82
79 @Activate 83 @Activate
80 protected void activate() { 84 protected void activate() {
81 mastershipService.addListener(mastershipListener); 85 mastershipService.addListener(mastershipListener);
86 + deviceService.addListener(deviceListener);
87 + deviceService.getDevices().forEach(device -> setupDriver(device.id()));
82 log.info("Started"); 88 log.info("Started");
83 } 89 }
84 90
85 @Deactivate 91 @Deactivate
86 protected void deactivate() { 92 protected void deactivate() {
87 mastershipService.removeListener(mastershipListener); 93 mastershipService.removeListener(mastershipListener);
94 + deviceService.removeListener(deviceListener);
88 log.info("Stopped"); 95 log.info("Stopped");
89 } 96 }
90 97
...@@ -121,43 +128,82 @@ public class FlowObjectiveManager implements FlowObjectiveService { ...@@ -121,43 +128,82 @@ public class FlowObjectiveManager implements FlowObjectiveService {
121 return pipe.next(nextObjectives); 128 return pipe.next(nextObjectives);
122 } 129 }
123 130
131 +
132 +
124 private class InnerMastershipListener implements MastershipListener { 133 private class InnerMastershipListener implements MastershipListener {
125 @Override 134 @Override
126 public void event(MastershipEvent event) { 135 public void event(MastershipEvent event) {
127 switch (event.type()) { 136 switch (event.type()) {
128 137
129 case MASTER_CHANGED: 138 case MASTER_CHANGED:
130 - //TODO: refactor this into a method 139 + setupDriver(event.subject());
131 - if (event.roleInfo().master().equals( 140 +
132 - clusterService.getLocalNode().id())) { 141 + break;
133 - DriverHandler handler = lookupDriver(event.subject()); 142 + case BACKUPS_CHANGED:
134 - if (handler != null) { 143 + break;
135 - Pipeliner pipe = handler.behaviour(Pipeliner.class); 144 + default:
136 - pipe.init(event.subject(), serviceDirectory); 145 + log.warn("Unknown mastership type {}", event.type());
137 - driverHandlers.put(event.subject(), handler);
138 - log.info("Driver {} bound to device {}",
139 - handler.data().type().name(), event.subject());
140 - } else {
141 - log.error("No driver for device {}", event.subject());
142 } 146 }
147 + }
148 +
143 149
144 } 150 }
145 151
152 + private class InnerDeviceListener implements DeviceListener {
153 + @Override
154 + public void event(DeviceEvent event) {
155 + switch (event.type()) {
156 + case DEVICE_ADDED:
157 + case DEVICE_AVAILABILITY_CHANGED:
158 + setupDriver(event.subject().id());
146 break; 159 break;
147 - case BACKUPS_CHANGED: 160 + case DEVICE_UPDATED:
161 + break;
162 + case DEVICE_REMOVED:
163 + break;
164 + case DEVICE_SUSPENDED:
165 + break;
166 + case PORT_ADDED:
167 + break;
168 + case PORT_UPDATED:
169 + break;
170 + case PORT_REMOVED:
148 break; 171 break;
149 default: 172 default:
150 - log.warn("Unknown mastership type {}", event.type()); 173 + log.warn("Unknown event type {}", event.type());
174 + }
151 } 175 }
152 } 176 }
153 177
178 + private void setupDriver(DeviceId deviceId) {
179 + //TODO: Refactor this to make it nicer and use a cache.
180 + if (mastershipService.getMasterFor(
181 + deviceId).equals(clusterService.getLocalNode().id())) {
182 +
183 + DriverHandler handler = lookupDriver(deviceId);
184 + if (handler != null) {
185 + Pipeliner pipe = handler.behaviour(Pipeliner.class);
186 + pipe.init(deviceId, serviceDirectory);
187 + driverHandlers.put(deviceId, handler);
188 + log.info("Driver {} bound to device {}",
189 + handler.data().type().name(), deviceId);
190 + } else {
191 + log.error("No driver for device {}", deviceId);
192 + }
193 + }
194 + }
195 +
196 +
154 private DriverHandler lookupDriver(DeviceId deviceId) { 197 private DriverHandler lookupDriver(DeviceId deviceId) {
155 Device device = deviceService.getDevice(deviceId); 198 Device device = deviceService.getDevice(deviceId);
156 - 199 + if (device == null) {
200 + log.warn("Device is null!");
201 + return null;
202 + }
157 Driver driver = driverService.getDriver(device.manufacturer(), 203 Driver driver = driverService.getDriver(device.manufacturer(),
158 device.hwVersion(), device.swVersion()); 204 device.hwVersion(), device.swVersion());
159 205
160 return driverService.createHandler(driver.name(), deviceId); 206 return driverService.createHandler(driver.name(), deviceId);
161 } 207 }
162 - } 208 +
163 } 209 }
......
...@@ -19,4 +19,8 @@ ...@@ -19,4 +19,8 @@
19 <behaviour api="org.onosproject.net.behaviour.Pipeliner" 19 <behaviour api="org.onosproject.net.behaviour.Pipeliner"
20 impl="org.onosproject.driver.pipeline.DefaultSingleTablePipeline"/> 20 impl="org.onosproject.driver.pipeline.DefaultSingleTablePipeline"/>
21 </driver> 21 </driver>
22 + <driver name="ovs-corsa" manufacturer="Nicira, Inc." hwVersion="Open vSwitch" swVersion="2.3.0">
23 + <behaviour api="org.onosproject.net.behaviour.Pipeliner"
24 + impl="org.onosproject.driver.pipeline.OVSCorsaPipeline"/>
25 + </driver>
22 </drivers> 26 </drivers>
...\ No newline at end of file ...\ No newline at end of file
......