Mahesh Poojary S
Committed by Mahesh Poojary Huawei

[ONOS-3117] Listen service function events in VtnRscManager

Change-Id: I7a7392999765d3c44806311e43e93ee40118adbf
...@@ -15,13 +15,14 @@ ...@@ -15,13 +15,14 @@
15 */ 15 */
16 package org.onosproject.vtnrsc.portchain; 16 package org.onosproject.vtnrsc.portchain;
17 17
18 +import org.onosproject.event.ListenerService;
18 import org.onosproject.vtnrsc.PortChain; 19 import org.onosproject.vtnrsc.PortChain;
19 import org.onosproject.vtnrsc.PortChainId; 20 import org.onosproject.vtnrsc.PortChainId;
20 21
21 /** 22 /**
22 * Service for interacting with the inventory of port chains. 23 * Service for interacting with the inventory of port chains.
23 */ 24 */
24 -public interface PortChainService { 25 +public interface PortChainService extends ListenerService<PortChainEvent, PortChainListener> {
25 26
26 /** 27 /**
27 * Returns if the port chain is existed. 28 * Returns if the port chain is existed.
......
...@@ -18,32 +18,20 @@ package org.onosproject.vtnrsc.service; ...@@ -18,32 +18,20 @@ package org.onosproject.vtnrsc.service;
18 import java.util.Iterator; 18 import java.util.Iterator;
19 19
20 import org.onlab.packet.MacAddress; 20 import org.onlab.packet.MacAddress;
21 +import org.onosproject.event.ListenerService;
21 import org.onosproject.net.Device; 22 import org.onosproject.net.Device;
22 import org.onosproject.net.DeviceId; 23 import org.onosproject.net.DeviceId;
23 import org.onosproject.net.HostId; 24 import org.onosproject.net.HostId;
24 import org.onosproject.vtnrsc.SegmentationId; 25 import org.onosproject.vtnrsc.SegmentationId;
25 import org.onosproject.vtnrsc.TenantId; 26 import org.onosproject.vtnrsc.TenantId;
26 import org.onosproject.vtnrsc.VirtualPortId; 27 import org.onosproject.vtnrsc.VirtualPortId;
28 +import org.onosproject.vtnrsc.event.VtnRscEvent;
27 import org.onosproject.vtnrsc.event.VtnRscListener; 29 import org.onosproject.vtnrsc.event.VtnRscListener;
28 30
29 /** 31 /**
30 * Service for interacting with the inventory of Vtn resource. 32 * Service for interacting with the inventory of Vtn resource.
31 */ 33 */
32 -public interface VtnRscService { 34 +public interface VtnRscService extends ListenerService<VtnRscEvent, VtnRscListener> {
33 - /**
34 - * Adds the specified listener.
35 - *
36 - * @param listener VtnRsc listener
37 - */
38 - void addListener(VtnRscListener listener);
39 -
40 - /**
41 - * Removes the specified listener.
42 - *
43 - * @param listener VtnRsc listener
44 - */
45 - void removeListener(VtnRscListener listener);
46 -
47 /** 35 /**
48 * Returns the SegmentationId of tenant. 36 * Returns the SegmentationId of tenant.
49 * 37 *
......
...@@ -32,6 +32,7 @@ import org.onlab.packet.IpAddress; ...@@ -32,6 +32,7 @@ import org.onlab.packet.IpAddress;
32 import org.onlab.packet.MacAddress; 32 import org.onlab.packet.MacAddress;
33 import org.onlab.util.KryoNamespace; 33 import org.onlab.util.KryoNamespace;
34 import org.onosproject.core.CoreService; 34 import org.onosproject.core.CoreService;
35 +import org.onosproject.event.AbstractListenerManager;
35 import org.onosproject.net.Device; 36 import org.onosproject.net.Device;
36 import org.onosproject.net.DeviceId; 37 import org.onosproject.net.DeviceId;
37 import org.onosproject.net.Host; 38 import org.onosproject.net.Host;
...@@ -54,6 +55,11 @@ import org.onosproject.vtnrsc.SubnetId; ...@@ -54,6 +55,11 @@ import org.onosproject.vtnrsc.SubnetId;
54 import org.onosproject.vtnrsc.TenantId; 55 import org.onosproject.vtnrsc.TenantId;
55 import org.onosproject.vtnrsc.VirtualPort; 56 import org.onosproject.vtnrsc.VirtualPort;
56 import org.onosproject.vtnrsc.VirtualPortId; 57 import org.onosproject.vtnrsc.VirtualPortId;
58 +import org.onosproject.vtnrsc.PortPair;
59 +import org.onosproject.vtnrsc.PortPairId;
60 +import org.onosproject.vtnrsc.PortPairGroup;
61 +import org.onosproject.vtnrsc.FlowClassifier;
62 +import org.onosproject.vtnrsc.PortChain;
57 import org.onosproject.vtnrsc.event.VtnRscEvent; 63 import org.onosproject.vtnrsc.event.VtnRscEvent;
58 import org.onosproject.vtnrsc.event.VtnRscEventFeedback; 64 import org.onosproject.vtnrsc.event.VtnRscEventFeedback;
59 import org.onosproject.vtnrsc.event.VtnRscListener; 65 import org.onosproject.vtnrsc.event.VtnRscListener;
...@@ -70,16 +76,27 @@ import org.onosproject.vtnrsc.service.VtnRscService; ...@@ -70,16 +76,27 @@ import org.onosproject.vtnrsc.service.VtnRscService;
70 import org.onosproject.vtnrsc.subnet.SubnetService; 76 import org.onosproject.vtnrsc.subnet.SubnetService;
71 import org.onosproject.vtnrsc.tenantnetwork.TenantNetworkService; 77 import org.onosproject.vtnrsc.tenantnetwork.TenantNetworkService;
72 import org.onosproject.vtnrsc.virtualport.VirtualPortService; 78 import org.onosproject.vtnrsc.virtualport.VirtualPortService;
79 +import org.onosproject.vtnrsc.portpair.PortPairEvent;
80 +import org.onosproject.vtnrsc.portpair.PortPairListener;
81 +import org.onosproject.vtnrsc.portpair.PortPairService;
82 +import org.onosproject.vtnrsc.portpairgroup.PortPairGroupEvent;
83 +import org.onosproject.vtnrsc.portpairgroup.PortPairGroupListener;
84 +import org.onosproject.vtnrsc.portpairgroup.PortPairGroupService;
85 +import org.onosproject.vtnrsc.flowclassifier.FlowClassifierEvent;
86 +import org.onosproject.vtnrsc.flowclassifier.FlowClassifierListener;
87 +import org.onosproject.vtnrsc.flowclassifier.FlowClassifierService;
88 +import org.onosproject.vtnrsc.portchain.PortChainEvent;
89 +import org.onosproject.vtnrsc.portchain.PortChainListener;
90 +import org.onosproject.vtnrsc.portchain.PortChainService;
73 import org.slf4j.Logger; 91 import org.slf4j.Logger;
74 92
75 -import com.google.common.collect.Sets;
76 -
77 /** 93 /**
78 * Provides implementation of the VtnRsc service. 94 * Provides implementation of the VtnRsc service.
79 */ 95 */
80 @Component(immediate = true) 96 @Component(immediate = true)
81 @Service 97 @Service
82 -public class VtnRscManager implements VtnRscService { 98 +public class VtnRscManager extends AbstractListenerManager<VtnRscEvent, VtnRscListener>
99 + implements VtnRscService {
83 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 100 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
84 protected CoreService coreService; 101 protected CoreService coreService;
85 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 102 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
...@@ -88,11 +105,14 @@ public class VtnRscManager implements VtnRscService { ...@@ -88,11 +105,14 @@ public class VtnRscManager implements VtnRscService {
88 protected LogicalClockService clockService; 105 protected LogicalClockService clockService;
89 106
90 private final Logger log = getLogger(getClass()); 107 private final Logger log = getLogger(getClass());
91 - private final Set<VtnRscListener> listeners = Sets.newCopyOnWriteArraySet();
92 private HostListener hostListener = new InnerHostListener(); 108 private HostListener hostListener = new InnerHostListener();
93 private FloatingIpListener floatingIpListener = new InnerFloatingIpListener(); 109 private FloatingIpListener floatingIpListener = new InnerFloatingIpListener();
94 private RouterListener routerListener = new InnerRouterListener(); 110 private RouterListener routerListener = new InnerRouterListener();
95 private RouterInterfaceListener routerInterfaceListener = new InnerRouterInterfaceListener(); 111 private RouterInterfaceListener routerInterfaceListener = new InnerRouterInterfaceListener();
112 + private PortPairListener portPairListener = new InnerPortPairListener();
113 + private PortPairGroupListener portPairGroupListener = new InnerPortPairGroupListener();
114 + private FlowClassifierListener flowClassifierListener = new InnerFlowClassifierListener();
115 + private PortChainListener portChainListener = new InnerPortChainListener();
96 116
97 private EventuallyConsistentMap<TenantId, SegmentationId> l3vniMap; 117 private EventuallyConsistentMap<TenantId, SegmentationId> l3vniMap;
98 private EventuallyConsistentMap<TenantId, Set<DeviceId>> classifierOvsMap; 118 private EventuallyConsistentMap<TenantId, Set<DeviceId>> classifierOvsMap;
...@@ -125,6 +145,14 @@ public class VtnRscManager implements VtnRscService { ...@@ -125,6 +145,14 @@ public class VtnRscManager implements VtnRscService {
125 protected TenantNetworkService tenantNetworkService; 145 protected TenantNetworkService tenantNetworkService;
126 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 146 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
127 protected DeviceService deviceService; 147 protected DeviceService deviceService;
148 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
149 + protected PortPairService portPairService;
150 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
151 + protected PortPairGroupService portPairGroupService;
152 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
153 + protected FlowClassifierService flowClassifierService;
154 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
155 + protected PortChainService portChainService;
128 156
129 @Activate 157 @Activate
130 public void activate() { 158 public void activate() {
...@@ -132,6 +160,10 @@ public class VtnRscManager implements VtnRscService { ...@@ -132,6 +160,10 @@ public class VtnRscManager implements VtnRscService {
132 floatingIpService.addListener(floatingIpListener); 160 floatingIpService.addListener(floatingIpListener);
133 routerService.addListener(routerListener); 161 routerService.addListener(routerListener);
134 routerInterfaceService.addListener(routerInterfaceListener); 162 routerInterfaceService.addListener(routerInterfaceListener);
163 + portPairService.addListener(portPairListener);
164 + portPairGroupService.addListener(portPairGroupListener);
165 + flowClassifierService.addListener(flowClassifierListener);
166 + portChainService.addListener(portChainListener);
135 167
136 KryoNamespace.Builder serializer = KryoNamespace.newBuilder() 168 KryoNamespace.Builder serializer = KryoNamespace.newBuilder()
137 .register(KryoNamespaces.API) 169 .register(KryoNamespaces.API)
...@@ -161,26 +193,18 @@ public class VtnRscManager implements VtnRscService { ...@@ -161,26 +193,18 @@ public class VtnRscManager implements VtnRscService {
161 floatingIpService.removeListener(floatingIpListener); 193 floatingIpService.removeListener(floatingIpListener);
162 routerService.removeListener(routerListener); 194 routerService.removeListener(routerListener);
163 routerInterfaceService.removeListener(routerInterfaceListener); 195 routerInterfaceService.removeListener(routerInterfaceListener);
196 + portPairService.removeListener(portPairListener);
197 + portPairGroupService.removeListener(portPairGroupListener);
198 + flowClassifierService.removeListener(flowClassifierListener);
199 + portChainService.removeListener(portChainListener);
200 +
164 l3vniMap.destroy(); 201 l3vniMap.destroy();
165 classifierOvsMap.destroy(); 202 classifierOvsMap.destroy();
166 sffOvsMap.destroy(); 203 sffOvsMap.destroy();
167 - listeners.clear();
168 log.info("Stopped"); 204 log.info("Stopped");
169 } 205 }
170 206
171 @Override 207 @Override
172 - public void addListener(VtnRscListener listener) {
173 - checkNotNull(listener, LISTENER_NOT_NULL);
174 - listeners.add(listener);
175 - }
176 -
177 - @Override
178 - public void removeListener(VtnRscListener listener) {
179 - checkNotNull(listener, LISTENER_NOT_NULL);
180 - listeners.add(listener);
181 - }
182 -
183 - @Override
184 public SegmentationId getL3vni(TenantId tenantId) { 208 public SegmentationId getL3vni(TenantId tenantId) {
185 checkNotNull(tenantId, "tenantId cannot be null"); 209 checkNotNull(tenantId, "tenantId cannot be null");
186 SegmentationId l3vni = l3vniMap.get(tenantId); 210 SegmentationId l3vni = l3vniMap.get(tenantId);
...@@ -282,6 +306,93 @@ public class VtnRscManager implements VtnRscService { ...@@ -282,6 +306,93 @@ public class VtnRscManager implements VtnRscService {
282 } 306 }
283 } 307 }
284 308
309 + private class InnerPortPairListener implements PortPairListener {
310 +
311 + @Override
312 + public void event(PortPairEvent event) {
313 + checkNotNull(event, EVENT_NOT_NULL);
314 + PortPair portPair = event.subject();
315 + if (PortPairEvent.Type.PORT_PAIR_PUT == event.type()) {
316 + notifyListeners(new VtnRscEvent(VtnRscEvent.Type.PORT_PAIR_PUT,
317 + new VtnRscEventFeedback(portPair)));
318 + } else if (PortPairEvent.Type.PORT_PAIR_DELETE == event.type()) {
319 + notifyListeners(new VtnRscEvent(
320 + VtnRscEvent.Type.PORT_PAIR_DELETE,
321 + new VtnRscEventFeedback(portPair)));
322 + } else if (PortPairEvent.Type.PORT_PAIR_UPDATE == event.type()) {
323 + notifyListeners(new VtnRscEvent(
324 + VtnRscEvent.Type.PORT_PAIR_UPDATE,
325 + new VtnRscEventFeedback(portPair)));
326 + }
327 + }
328 + }
329 +
330 + private class InnerPortPairGroupListener implements PortPairGroupListener {
331 +
332 + @Override
333 + public void event(PortPairGroupEvent event) {
334 + checkNotNull(event, EVENT_NOT_NULL);
335 + PortPairGroup portPairGroup = event.subject();
336 + if (PortPairGroupEvent.Type.PORT_PAIR_GROUP_PUT == event.type()) {
337 + notifyListeners(new VtnRscEvent(
338 + VtnRscEvent.Type.PORT_PAIR_GROUP_PUT,
339 + new VtnRscEventFeedback(portPairGroup)));
340 + } else if (PortPairGroupEvent.Type.PORT_PAIR_GROUP_DELETE == event.type()) {
341 + notifyListeners(new VtnRscEvent(
342 + VtnRscEvent.Type.PORT_PAIR_GROUP_DELETE,
343 + new VtnRscEventFeedback(portPairGroup)));
344 + } else if (PortPairGroupEvent.Type.PORT_PAIR_GROUP_UPDATE == event.type()) {
345 + notifyListeners(new VtnRscEvent(
346 + VtnRscEvent.Type.PORT_PAIR_GROUP_UPDATE,
347 + new VtnRscEventFeedback(portPairGroup)));
348 + }
349 + }
350 + }
351 +
352 + private class InnerFlowClassifierListener implements FlowClassifierListener {
353 +
354 + @Override
355 + public void event(FlowClassifierEvent event) {
356 + checkNotNull(event, EVENT_NOT_NULL);
357 + FlowClassifier flowClassifier = event.subject();
358 + if (FlowClassifierEvent.Type.FLOW_CLASSIFIER_PUT == event.type()) {
359 + notifyListeners(new VtnRscEvent(
360 + VtnRscEvent.Type.FLOW_CLASSIFIER_PUT,
361 + new VtnRscEventFeedback(flowClassifier)));
362 + } else if (FlowClassifierEvent.Type.FLOW_CLASSIFIER_DELETE == event.type()) {
363 + notifyListeners(new VtnRscEvent(
364 + VtnRscEvent.Type.FLOW_CLASSIFIER_DELETE,
365 + new VtnRscEventFeedback(flowClassifier)));
366 + } else if (FlowClassifierEvent.Type.FLOW_CLASSIFIER_UPDATE == event.type()) {
367 + notifyListeners(new VtnRscEvent(
368 + VtnRscEvent.Type.FLOW_CLASSIFIER_UPDATE,
369 + new VtnRscEventFeedback(flowClassifier)));
370 + }
371 + }
372 + }
373 +
374 + private class InnerPortChainListener implements PortChainListener {
375 +
376 + @Override
377 + public void event(PortChainEvent event) {
378 + checkNotNull(event, EVENT_NOT_NULL);
379 + PortChain portChain = event.subject();
380 + if (PortChainEvent.Type.PORT_CHAIN_PUT == event.type()) {
381 + notifyListeners(new VtnRscEvent(
382 + VtnRscEvent.Type.PORT_CHAIN_PUT,
383 + new VtnRscEventFeedback(portChain)));
384 + } else if (PortChainEvent.Type.PORT_CHAIN_DELETE == event.type()) {
385 + notifyListeners(new VtnRscEvent(
386 + VtnRscEvent.Type.PORT_CHAIN_DELETE,
387 + new VtnRscEventFeedback(portChain)));
388 + } else if (PortChainEvent.Type.PORT_CHAIN_UPDATE == event.type()) {
389 + notifyListeners(new VtnRscEvent(
390 + VtnRscEvent.Type.PORT_CHAIN_UPDATE,
391 + new VtnRscEventFeedback(portChain)));
392 + }
393 + }
394 + }
395 +
285 @Override 396 @Override
286 public Iterator<Device> getClassifierOfTenant(TenantId tenantId) { 397 public Iterator<Device> getClassifierOfTenant(TenantId tenantId) {
287 checkNotNull(tenantId, TENANTID_NOT_NULL); 398 checkNotNull(tenantId, TENANTID_NOT_NULL);
...@@ -333,8 +444,7 @@ public class VtnRscManager implements VtnRscService { ...@@ -333,8 +444,7 @@ public class VtnRscManager implements VtnRscService {
333 444
334 @Override 445 @Override
335 public boolean isServiceFunction(VirtualPortId portId) { 446 public boolean isServiceFunction(VirtualPortId portId) {
336 - // TODO Auto-generated method stub 447 + return portPairService.exists(PortPairId.of(portId.portId()));
337 - return false;
338 } 448 }
339 449
340 @Override 450 @Override
...@@ -467,6 +577,6 @@ public class VtnRscManager implements VtnRscService { ...@@ -467,6 +577,6 @@ public class VtnRscManager implements VtnRscService {
467 */ 577 */
468 private void notifyListeners(VtnRscEvent event) { 578 private void notifyListeners(VtnRscEvent event) {
469 checkNotNull(event, EVENT_NOT_NULL); 579 checkNotNull(event, EVENT_NOT_NULL);
470 - listeners.forEach(listener -> listener.event(event)); 580 + post(event);
471 } 581 }
472 } 582 }
......