alshabib

adding Access device events and a listener

Change-Id: I0e9b4dae4231e7057443e7ed52723e29e06747cc
...@@ -17,12 +17,16 @@ ...@@ -17,12 +17,16 @@
17 package org.onosproject.olt; 17 package org.onosproject.olt;
18 18
19 import org.onlab.packet.VlanId; 19 import org.onlab.packet.VlanId;
20 +import org.onosproject.event.ListenerService;
20 import org.onosproject.net.ConnectPoint; 21 import org.onosproject.net.ConnectPoint;
22 +import org.onosproject.olt.api.AccessDeviceEvent;
23 +import org.onosproject.olt.api.AccessDeviceListener;
21 24
22 /** 25 /**
23 * Service for interacting with an access device (OLT). 26 * Service for interacting with an access device (OLT).
24 */ 27 */
25 -public interface AccessDeviceService { 28 +public interface AccessDeviceService
29 + extends ListenerService<AccessDeviceEvent, AccessDeviceListener> {
26 30
27 /** 31 /**
28 * Provisions connectivity for a subscriber on an access device. 32 * Provisions connectivity for a subscriber on an access device.
...@@ -38,4 +42,5 @@ public interface AccessDeviceService { ...@@ -38,4 +42,5 @@ public interface AccessDeviceService {
38 * @param port subscriber's connection point 42 * @param port subscriber's connection point
39 */ 43 */
40 void removeSubscriber(ConnectPoint port); 44 void removeSubscriber(ConnectPoint port);
45 +
41 } 46 }
......
...@@ -28,9 +28,9 @@ import org.onlab.packet.VlanId; ...@@ -28,9 +28,9 @@ import org.onlab.packet.VlanId;
28 import org.onlab.util.Tools; 28 import org.onlab.util.Tools;
29 import org.onosproject.core.ApplicationId; 29 import org.onosproject.core.ApplicationId;
30 import org.onosproject.core.CoreService; 30 import org.onosproject.core.CoreService;
31 +import org.onosproject.event.AbstractListenerManager;
31 import org.onosproject.net.ConnectPoint; 32 import org.onosproject.net.ConnectPoint;
32 import org.onosproject.net.DeviceId; 33 import org.onosproject.net.DeviceId;
33 -import org.onosproject.net.Port;
34 import org.onosproject.net.PortNumber; 34 import org.onosproject.net.PortNumber;
35 import org.onosproject.net.config.ConfigFactory; 35 import org.onosproject.net.config.ConfigFactory;
36 import org.onosproject.net.config.NetworkConfigEvent; 36 import org.onosproject.net.config.NetworkConfigEvent;
...@@ -47,6 +47,8 @@ import org.onosproject.net.flow.TrafficTreatment; ...@@ -47,6 +47,8 @@ import org.onosproject.net.flow.TrafficTreatment;
47 import org.onosproject.net.flowobjective.DefaultForwardingObjective; 47 import org.onosproject.net.flowobjective.DefaultForwardingObjective;
48 import org.onosproject.net.flowobjective.FlowObjectiveService; 48 import org.onosproject.net.flowobjective.FlowObjectiveService;
49 import org.onosproject.net.flowobjective.ForwardingObjective; 49 import org.onosproject.net.flowobjective.ForwardingObjective;
50 +import org.onosproject.olt.api.AccessDeviceEvent;
51 +import org.onosproject.olt.api.AccessDeviceListener;
50 import org.osgi.service.component.ComponentContext; 52 import org.osgi.service.component.ComponentContext;
51 import org.slf4j.Logger; 53 import org.slf4j.Logger;
52 54
...@@ -62,7 +64,9 @@ import static org.slf4j.LoggerFactory.getLogger; ...@@ -62,7 +64,9 @@ import static org.slf4j.LoggerFactory.getLogger;
62 */ 64 */
63 @Service 65 @Service
64 @Component(immediate = true) 66 @Component(immediate = true)
65 -public class Olt implements AccessDeviceService { 67 +public class Olt
68 + extends AbstractListenerManager<AccessDeviceEvent, AccessDeviceListener>
69 + implements AccessDeviceService {
66 private final Logger log = getLogger(getClass()); 70 private final Logger log = getLogger(getClass());
67 71
68 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 72 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
...@@ -98,7 +102,7 @@ public class Olt implements AccessDeviceService { ...@@ -98,7 +102,7 @@ public class Olt implements AccessDeviceService {
98 label = "The OLT's uplink port number") 102 label = "The OLT's uplink port number")
99 private int gfastUplink = GFAST_UPLINK_PORT; 103 private int gfastUplink = GFAST_UPLINK_PORT;
100 104
101 - //TODO: replace this with an annotation lookup 105 + //TODO: replace this information with info comming for net cfg service.
102 @Property(name = "oltDevice", value = OLT_DEVICE, 106 @Property(name = "oltDevice", value = OLT_DEVICE,
103 label = "The OLT device id") 107 label = "The OLT device id")
104 private String oltDevice = OLT_DEVICE; 108 private String oltDevice = OLT_DEVICE;
...@@ -127,6 +131,8 @@ public class Olt implements AccessDeviceService { ...@@ -127,6 +131,8 @@ public class Olt implements AccessDeviceService {
127 public void activate() { 131 public void activate() {
128 appId = coreService.registerApplication("org.onosproject.olt"); 132 appId = coreService.registerApplication("org.onosproject.olt");
129 133
134 + eventDispatcher.addSink(AccessDeviceEvent.class, listenerRegistry);
135 +
130 networkConfig.registerConfigFactory(configFactory); 136 networkConfig.registerConfigFactory(configFactory);
131 networkConfig.addListener(configListener); 137 networkConfig.addListener(configListener);
132 138
...@@ -140,31 +146,6 @@ public class Olt implements AccessDeviceService { ...@@ -140,31 +146,6 @@ public class Olt implements AccessDeviceService {
140 } 146 }
141 ); 147 );
142 148
143 - /*deviceService.addListener(deviceListener);
144 -
145 - deviceService.getPorts(DeviceId.deviceId(oltDevice)).stream().forEach(
146 - port -> {
147 - if (!port.number().isLogical() && port.isEnabled()) {
148 - short vlanId = fetchVlanId(port.number());
149 - if (vlanId > 0) {
150 - provisionVlanOnPort(oltDevice, uplinkPort, port.number(), (short) 7);
151 - provisionVlanOnPort(oltDevice, uplinkPort, port.number(), vlanId);
152 - }
153 - }
154 - }
155 - );*/
156 -
157 -
158 - deviceService.getPorts(DeviceId.deviceId(gfastDevice)).stream()
159 - .filter(port -> !port.number().isLogical())
160 - .filter(Port::isEnabled)
161 - .forEach(port -> {
162 - short vlanId = (short) (fetchVlanId(port.number()) + OFFSET);
163 - if (vlanId > 0) {
164 - provisionVlanOnPort(gfastDevice, gfastUplink, port.number(), vlanId);
165 - }
166 - }
167 - );
168 log.info("Started with Application ID {}", appId.id()); 149 log.info("Started with Application ID {}", appId.id());
169 } 150 }
170 151
...@@ -312,17 +293,28 @@ public class Olt implements AccessDeviceService { ...@@ -312,17 +293,28 @@ public class Olt implements AccessDeviceService {
312 @Override 293 @Override
313 public void event(DeviceEvent event) { 294 public void event(DeviceEvent event) {
314 DeviceId devId = DeviceId.deviceId(oltDevice); 295 DeviceId devId = DeviceId.deviceId(oltDevice);
296 + if (!devId.equals(event.subject().id())) {
297 + return;
298 + }
315 switch (event.type()) { 299 switch (event.type()) {
316 case PORT_ADDED: 300 case PORT_ADDED:
317 case PORT_UPDATED: 301 case PORT_UPDATED:
318 - if (devId.equals(event.subject().id()) && event.port().isEnabled()) { 302 + if (event.port().isEnabled()) {
319 short vlanId = fetchVlanId(event.port().number()); 303 short vlanId = fetchVlanId(event.port().number());
320 provisionVlanOnPort(gfastDevice, uplinkPort, event.port().number(), vlanId); 304 provisionVlanOnPort(gfastDevice, uplinkPort, event.port().number(), vlanId);
321 } 305 }
322 break; 306 break;
323 case DEVICE_ADDED: 307 case DEVICE_ADDED:
324 - case DEVICE_UPDATED: 308 + post(new AccessDeviceEvent(
309 + AccessDeviceEvent.Type.DEVICE_CONNECTED, devId,
310 + null, null));
311 + break;
325 case DEVICE_REMOVED: 312 case DEVICE_REMOVED:
313 + post(new AccessDeviceEvent(
314 + AccessDeviceEvent.Type.DEVICE_DISCONNECTED, devId,
315 + null, null));
316 + break;
317 + case DEVICE_UPDATED:
326 case DEVICE_SUSPENDED: 318 case DEVICE_SUSPENDED:
327 case DEVICE_AVAILABILITY_CHANGED: 319 case DEVICE_AVAILABILITY_CHANGED:
328 case PORT_REMOVED: 320 case PORT_REMOVED:
......
1 +package org.onosproject.olt.api;
2 +
3 +import org.onlab.packet.VlanId;
4 +import org.onosproject.event.AbstractEvent;
5 +import org.onosproject.net.DeviceId;
6 +
7 +import java.util.Optional;
8 +
9 +/**
10 + * Describes an access device event.
11 + */
12 +public class AccessDeviceEvent extends AbstractEvent<AccessDeviceEvent.Type, DeviceId> {
13 +
14 + private final Optional<VlanId> sVlan;
15 + private final Optional<VlanId> cVlan;
16 +
17 + public enum Type {
18 + /**
19 + * A subscriber was registered and provisioned.
20 + */
21 + SUBSCRIBER_REGISTERED,
22 +
23 + /**
24 + * A subscriber was unregistered and deprovisioned.
25 + */
26 + SUBSCRIBER_UNREGISTERED,
27 +
28 + /**
29 + * An access device connected.
30 + */
31 + DEVICE_CONNECTED,
32 +
33 + /**
34 + * An access device disconnected.
35 + */
36 + DEVICE_DISCONNECTED
37 +
38 + }
39 +
40 + /**
41 + *
42 + * Creates an event of a given type and for the specified device,
43 + * along with the cVlanId and sVlanId. The vlan fields may not be provisioned
44 + * if the event is related to the access device (dis)connection.
45 + *
46 + * @param type the event type
47 + * @param deviceId the device id
48 + * @param sVlanId the service vlan
49 + * @param cVlanId the customer vlan
50 + */
51 + public AccessDeviceEvent(Type type, DeviceId deviceId,
52 + VlanId sVlanId,
53 + VlanId cVlanId) {
54 + super(type, deviceId);
55 + this.sVlan = Optional.ofNullable(sVlanId);
56 + this.cVlan = Optional.ofNullable(cVlanId);
57 + }
58 +
59 + /**
60 + *
61 + * Creates an event of a given type and for the specified device, and timestamp
62 + * along with the cVlanId and sVlanId. The vlan fields may not be provisioned
63 + * if the event is related to the access device (dis)connection.
64 + *
65 + * @param type the event type
66 + * @param deviceId the device id
67 + * @param time a timestamp
68 + * @param sVlanId the service vlan
69 + * @param cVlanId the customer vlan
70 + */
71 + protected AccessDeviceEvent(Type type, DeviceId deviceId, long time,
72 + VlanId sVlanId,
73 + VlanId cVlanId) {
74 + super(type, deviceId, time);
75 + this.sVlan = Optional.ofNullable(sVlanId);
76 + this.cVlan = Optional.ofNullable(cVlanId);
77 +
78 + }
79 +
80 + public Optional<VlanId> sVlanId() {
81 + return sVlan;
82 + }
83 +
84 + public Optional<VlanId> cVlanId() {
85 + return cVlan;
86 + }
87 +
88 +}
1 +package org.onosproject.olt.api;
2 +
3 +import org.onosproject.event.EventListener;
4 +
5 +/**
6 + * Entity capable of receiving access device related events.
7 + */
8 +public interface AccessDeviceListener extends EventListener<AccessDeviceEvent> {
9 +}
1 +/*
2 + * Copyright 2016 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +
17 +/**
18 + * OLT event api.
19 + */
20 +package org.onosproject.olt.api;