Committed by
Gerrit Code Review
method to annotate a device during driver init
Change-Id: I446a7444edcb98347694b8b568e65fa3614880a3
Showing
1 changed file
with
77 additions
and
3 deletions
... | @@ -16,10 +16,19 @@ | ... | @@ -16,10 +16,19 @@ |
16 | package org.onosproject.driver.pipeline; | 16 | package org.onosproject.driver.pipeline; |
17 | 17 | ||
18 | import org.onlab.osgi.ServiceDirectory; | 18 | import org.onlab.osgi.ServiceDirectory; |
19 | +import org.onosproject.net.DefaultAnnotations; | ||
20 | +import org.onosproject.net.Device; | ||
19 | import org.onosproject.net.DeviceId; | 21 | import org.onosproject.net.DeviceId; |
22 | +import org.onosproject.net.MastershipRole; | ||
20 | import org.onosproject.net.PortNumber; | 23 | import org.onosproject.net.PortNumber; |
21 | import org.onosproject.net.behaviour.Pipeliner; | 24 | import org.onosproject.net.behaviour.Pipeliner; |
22 | import org.onosproject.net.behaviour.PipelinerContext; | 25 | import org.onosproject.net.behaviour.PipelinerContext; |
26 | +import org.onosproject.net.device.DefaultDeviceDescription; | ||
27 | +import org.onosproject.net.device.DeviceDescription; | ||
28 | +import org.onosproject.net.device.DeviceProvider; | ||
29 | +import org.onosproject.net.device.DeviceProviderRegistry; | ||
30 | +import org.onosproject.net.device.DeviceProviderService; | ||
31 | +import org.onosproject.net.device.DeviceService; | ||
23 | import org.onosproject.net.driver.AbstractHandlerBehaviour; | 32 | import org.onosproject.net.driver.AbstractHandlerBehaviour; |
24 | import org.onosproject.net.flow.DefaultFlowRule; | 33 | import org.onosproject.net.flow.DefaultFlowRule; |
25 | import org.onosproject.net.flow.DefaultTrafficTreatment; | 34 | import org.onosproject.net.flow.DefaultTrafficTreatment; |
... | @@ -34,8 +43,11 @@ import org.onosproject.net.flowobjective.FilteringObjective; | ... | @@ -34,8 +43,11 @@ import org.onosproject.net.flowobjective.FilteringObjective; |
34 | import org.onosproject.net.flowobjective.ForwardingObjective; | 43 | import org.onosproject.net.flowobjective.ForwardingObjective; |
35 | import org.onosproject.net.flowobjective.NextObjective; | 44 | import org.onosproject.net.flowobjective.NextObjective; |
36 | import org.onosproject.net.flowobjective.ObjectiveError; | 45 | import org.onosproject.net.flowobjective.ObjectiveError; |
46 | +import org.onosproject.net.provider.AbstractProvider; | ||
47 | +import org.onosproject.net.provider.ProviderId; | ||
37 | import org.slf4j.Logger; | 48 | import org.slf4j.Logger; |
38 | 49 | ||
50 | +import static com.google.common.base.Preconditions.checkNotNull; | ||
39 | import static org.slf4j.LoggerFactory.getLogger; | 51 | import static org.slf4j.LoggerFactory.getLogger; |
40 | 52 | ||
41 | /** | 53 | /** |
... | @@ -45,21 +57,35 @@ public class OLTPipeline extends AbstractHandlerBehaviour implements Pipeliner { | ... | @@ -45,21 +57,35 @@ public class OLTPipeline extends AbstractHandlerBehaviour implements Pipeliner { |
45 | 57 | ||
46 | private final Logger log = getLogger(getClass()); | 58 | private final Logger log = getLogger(getClass()); |
47 | 59 | ||
60 | + static final ProviderId PID = new ProviderId("olt", "org.onosproject.olt", true); | ||
61 | + | ||
62 | + static final String DEVICE = "isAccess"; | ||
63 | + static final String OLT = "true"; | ||
64 | + | ||
48 | private ServiceDirectory serviceDirectory; | 65 | private ServiceDirectory serviceDirectory; |
49 | private FlowRuleService flowRuleService; | 66 | private FlowRuleService flowRuleService; |
50 | private DeviceId deviceId; | 67 | private DeviceId deviceId; |
51 | 68 | ||
69 | + private DeviceProvider provider = new AnnotationProvider(); | ||
70 | + | ||
52 | 71 | ||
53 | @Override | 72 | @Override |
54 | public void init(DeviceId deviceId, PipelinerContext context) { | 73 | public void init(DeviceId deviceId, PipelinerContext context) { |
55 | this.serviceDirectory = context.directory(); | 74 | this.serviceDirectory = context.directory(); |
56 | this.deviceId = deviceId; | 75 | this.deviceId = deviceId; |
57 | - | 76 | + DeviceProviderRegistry registry = |
77 | + serviceDirectory.get(DeviceProviderRegistry.class); | ||
58 | flowRuleService = serviceDirectory.get(FlowRuleService.class); | 78 | flowRuleService = serviceDirectory.get(FlowRuleService.class); |
59 | 79 | ||
60 | - } | 80 | + try { |
61 | - | 81 | + DeviceProviderService providerService = registry.register(provider); |
82 | + providerService.deviceConnected(deviceId, | ||
83 | + description(deviceId, DEVICE, OLT)); | ||
84 | + } finally { | ||
85 | + registry.unregister(provider); | ||
86 | + } | ||
62 | 87 | ||
88 | + } | ||
63 | 89 | ||
64 | @Override | 90 | @Override |
65 | public void filter(FilteringObjective filter) { | 91 | public void filter(FilteringObjective filter) { |
... | @@ -147,4 +173,52 @@ public class OLTPipeline extends AbstractHandlerBehaviour implements Pipeliner { | ... | @@ -147,4 +173,52 @@ public class OLTPipeline extends AbstractHandlerBehaviour implements Pipeliner { |
147 | throw new UnsupportedOperationException("Single table does not next hop."); | 173 | throw new UnsupportedOperationException("Single table does not next hop."); |
148 | } | 174 | } |
149 | 175 | ||
176 | + /** | ||
177 | + * Build a device description. | ||
178 | + * @param deviceId a deviceId | ||
179 | + * @param key the key of the annotation | ||
180 | + * @param value the value for the annotation | ||
181 | + * @return a device description | ||
182 | + */ | ||
183 | + private DeviceDescription description(DeviceId deviceId, String key, String value) { | ||
184 | + DeviceService deviceService = serviceDirectory.get(DeviceService.class); | ||
185 | + Device device = deviceService.getDevice(deviceId); | ||
186 | + | ||
187 | + checkNotNull(device, "Device not found in device service."); | ||
188 | + | ||
189 | + DefaultAnnotations.Builder builder = DefaultAnnotations.builder(); | ||
190 | + if (value != null) { | ||
191 | + builder.set(key, value); | ||
192 | + } else { | ||
193 | + builder.remove(key); | ||
194 | + } | ||
195 | + return new DefaultDeviceDescription(device.id().uri(), device.type(), | ||
196 | + device.manufacturer(), device.hwVersion(), | ||
197 | + device.swVersion(), device.serialNumber(), | ||
198 | + device.chassisId(), builder.build()); | ||
199 | + } | ||
200 | + | ||
201 | + /** | ||
202 | + * Simple ancillary provider used to annotate device. | ||
203 | + */ | ||
204 | + private static final class AnnotationProvider | ||
205 | + extends AbstractProvider implements DeviceProvider { | ||
206 | + private AnnotationProvider() { | ||
207 | + super(PID); | ||
208 | + } | ||
209 | + | ||
210 | + @Override | ||
211 | + public void triggerProbe(DeviceId deviceId) { | ||
212 | + } | ||
213 | + | ||
214 | + @Override | ||
215 | + public void roleChanged(DeviceId deviceId, MastershipRole newRole) { | ||
216 | + } | ||
217 | + | ||
218 | + @Override | ||
219 | + public boolean isReachable(DeviceId deviceId) { | ||
220 | + return false; | ||
221 | + } | ||
222 | + } | ||
223 | + | ||
150 | } | 224 | } | ... | ... |
-
Please register or login to post a comment