2 * Copyright (c) 2015 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.vpnservice.interfacemgr.listeners;
11 import com.google.common.util.concurrent.ListenableFuture;
12 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
13 import org.opendaylight.idmanager.IdManager;
14 import org.opendaylight.vpnservice.datastoreutils.AsyncDataTreeChangeListenerBase;
15 import org.opendaylight.vpnservice.datastoreutils.DataStoreJobCoordinator;
16 import org.opendaylight.vpnservice.interfacemgr.renderer.ovs.confighelpers.OvsInterfaceConfigAddHelper;
17 import org.opendaylight.vpnservice.interfacemgr.renderer.ovs.confighelpers.OvsInterfaceConfigRemoveHelper;
18 import org.opendaylight.vpnservice.interfacemgr.renderer.ovs.confighelpers.OvsInterfaceConfigUpdateHelper;
19 import org.opendaylight.vpnservice.mdsalutil.interfaces.IMdsalApiManager;
20 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.Interfaces;
21 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.alivenessmonitor.rev150629.AlivenessMonitorService;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.idmanager.rev150403.IdManagerService;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.rev150331.ParentRefs;
25 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
26 import org.slf4j.Logger;
27 import org.slf4j.LoggerFactory;
29 import java.util.List;
30 import java.util.concurrent.Callable;
33 * This class listens for interface creation/removal/update in Configuration DS.
34 * This is used to handle interfaces for base of-ports.
36 public class InterfaceConfigListener extends AsyncDataTreeChangeListenerBase<Interface, InterfaceConfigListener> {
37 private static final Logger LOG = LoggerFactory.getLogger(InterfaceConfigListener.class);
38 private DataBroker dataBroker;
39 private IdManagerService idManager;
40 private AlivenessMonitorService alivenessMonitorService;
41 private IMdsalApiManager mdsalApiManager;
43 public InterfaceConfigListener(final DataBroker dataBroker, final IdManagerService idManager,
44 final AlivenessMonitorService alivenessMonitorService,
45 final IMdsalApiManager mdsalApiManager) {
46 super(Interface.class, InterfaceConfigListener.class);
47 this.dataBroker = dataBroker;
48 this.idManager = idManager;
49 this.alivenessMonitorService = alivenessMonitorService;
50 this.mdsalApiManager = mdsalApiManager;
54 protected InstanceIdentifier<Interface> getWildCardPath() {
55 return InstanceIdentifier.create(Interfaces.class).child(Interface.class);
59 protected InterfaceConfigListener getDataTreeChangeListener() {
60 return InterfaceConfigListener.this;
64 protected void remove(InstanceIdentifier<Interface> key, Interface interfaceOld) {
65 LOG.debug("Received Interface Remove Event: {}, {}", key, interfaceOld);
66 String ifName = interfaceOld.getName();
67 String parentInterface = null;
69 ParentRefs parentRefs = interfaceOld.getAugmentation(ParentRefs.class);
70 if (parentRefs != null) {
71 parentInterface = parentRefs.getParentInterface();
72 if (parentInterface != null && !parentInterface.equals(ifName)) {
75 if (parentRefs.getDatapathNodeIdentifier() == null) {
80 DataStoreJobCoordinator coordinator = DataStoreJobCoordinator.getInstance();
81 RendererConfigRemoveWorker configWorker = new RendererConfigRemoveWorker(key, interfaceOld, ifName, parentRefs);
82 coordinator.enqueueJob(ifName, configWorker);
86 protected void update(InstanceIdentifier<Interface> key, Interface interfaceOld, Interface interfaceNew) {
87 LOG.debug("Received Interface Update Event: {}, {}, {}", key, interfaceOld, interfaceNew);
88 String ifNameNew = interfaceNew.getName();
89 String parentInterface = null;
91 ParentRefs parentRefs = interfaceNew.getAugmentation(ParentRefs.class);
92 if (parentRefs != null) {
93 parentInterface = parentRefs.getParentInterface();
96 if (parentInterface != null && !parentInterface.equals(ifNameNew)) {
100 DataStoreJobCoordinator coordinator = DataStoreJobCoordinator.getInstance();
101 RendererConfigUpdateWorker worker = new RendererConfigUpdateWorker(key, interfaceOld, interfaceNew, ifNameNew);
102 coordinator.enqueueJob(ifNameNew, worker);
106 protected void add(InstanceIdentifier<Interface> key, Interface interfaceNew) {
107 LOG.debug("Received Interface Add Event: {}, {}", key, interfaceNew);
108 String ifName = interfaceNew.getName();
109 String parentInterface = null;
111 ParentRefs parentRefs = interfaceNew.getAugmentation(ParentRefs.class);
112 if (parentRefs != null) {
113 parentInterface = parentRefs.getParentInterface();
116 if (parentInterface != null && !parentInterface.equals(ifName)) {
120 DataStoreJobCoordinator coordinator = DataStoreJobCoordinator.getInstance();
121 RendererConfigAddWorker configWorker = new RendererConfigAddWorker(key, interfaceNew, parentRefs, ifName);
122 coordinator.enqueueJob(ifName, configWorker);
125 private class RendererConfigAddWorker implements Callable<List<ListenableFuture<Void>>> {
126 InstanceIdentifier<Interface> key;
127 Interface interfaceNew;
129 ParentRefs parentRefs;
131 public RendererConfigAddWorker(InstanceIdentifier<Interface> key, Interface interfaceNew,
132 ParentRefs parentRefs, String portName) {
134 this.interfaceNew = interfaceNew;
135 this.portName = portName;
136 this.parentRefs = parentRefs;
140 public List<ListenableFuture<Void>> call() throws Exception {
141 // If another renderer(for eg : CSS) needs to be supported, check can be performed here
142 // to call the respective helpers.
143 return OvsInterfaceConfigAddHelper.addConfiguration(dataBroker, parentRefs, interfaceNew,
148 public String toString() {
149 return "RendererConfigAddWorker{" +
151 ", interfaceNew=" + interfaceNew +
152 ", portName='" + portName + '\'' +
160 private class RendererConfigUpdateWorker implements Callable {
161 InstanceIdentifier<Interface> key;
162 Interface interfaceOld;
163 Interface interfaceNew;
166 public RendererConfigUpdateWorker(InstanceIdentifier<Interface> key, Interface interfaceOld,
167 Interface interfaceNew, String portNameNew) {
169 this.interfaceOld = interfaceOld;
170 this.interfaceNew = interfaceNew;
171 this.portNameNew = portNameNew;
175 public List<ListenableFuture<Void>> call() throws Exception {
176 // If another renderer(for eg : CSS) needs to be supported, check can be performed here
177 // to call the respective helpers.
178 return OvsInterfaceConfigUpdateHelper.updateConfiguration(dataBroker, alivenessMonitorService, idManager,
179 mdsalApiManager, interfaceNew, interfaceOld);
183 public String toString() {
184 return "RendererConfigUpdateWorker{" +
186 ", interfaceOld=" + interfaceOld +
187 ", interfaceNew=" + interfaceNew +
188 ", portNameNew='" + portNameNew + '\'' +
196 private class RendererConfigRemoveWorker implements Callable {
197 InstanceIdentifier<Interface> key;
198 Interface interfaceOld;
200 ParentRefs parentRefs;
202 public RendererConfigRemoveWorker(InstanceIdentifier<Interface> key, Interface interfaceOld, String portName,
203 ParentRefs parentRefs) {
205 this.interfaceOld = interfaceOld;
206 this.portName = portName;
207 this.parentRefs = parentRefs;
211 public List<ListenableFuture<Void>> call() throws Exception {
212 // If another renderer(for eg : CSS) needs to be supported, check can be performed here
213 // to call the respective helpers.
214 return OvsInterfaceConfigRemoveHelper.removeConfiguration(dataBroker, alivenessMonitorService,
215 interfaceOld, idManager, mdsalApiManager, parentRefs);
219 public String toString() {
220 return "RendererConfigRemoveWorker{" +
222 ", interfaceOld=" + interfaceOld +
223 ", portName='" + portName + '\'' +