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.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.Interfaces;
20 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.idmanager.rev150403.IdManagerService;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.rev150331.ParentRefs;
23 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
24 import org.slf4j.Logger;
25 import org.slf4j.LoggerFactory;
27 import java.util.List;
28 import java.util.concurrent.Callable;
31 * This class listens for interface creation/removal/update in Configuration DS.
32 * This is used to handle interfaces for base of-ports.
34 public class InterfaceConfigListener extends AsyncDataTreeChangeListenerBase<Interface, InterfaceConfigListener> {
35 private static final Logger LOG = LoggerFactory.getLogger(InterfaceConfigListener.class);
36 private DataBroker dataBroker;
37 private IdManagerService idManager;
39 public InterfaceConfigListener(final DataBroker dataBroker, final IdManagerService idManager) {
40 super(Interface.class, InterfaceConfigListener.class);
41 this.dataBroker = dataBroker;
42 this.idManager = idManager;
46 protected InstanceIdentifier<Interface> getWildCardPath() {
47 return InstanceIdentifier.create(Interfaces.class).child(Interface.class);
51 protected InterfaceConfigListener getDataTreeChangeListener() {
52 return InterfaceConfigListener.this;
56 protected void remove(InstanceIdentifier<Interface> key, Interface interfaceOld) {
57 LOG.debug("Received Interface Remove Event: {}, {}", key, interfaceOld);
58 String ifName = interfaceOld.getName();
59 String parentInterface = null;
61 ParentRefs parentRefs = interfaceOld.getAugmentation(ParentRefs.class);
62 if (parentRefs != null) {
63 parentInterface = parentRefs.getParentInterface();
64 if (parentInterface != null && !parentInterface.equals(ifName)) {
67 if (parentRefs.getDatapathNodeIdentifier() == null) {
72 DataStoreJobCoordinator coordinator = DataStoreJobCoordinator.getInstance();
73 RendererConfigRemoveWorker configWorker = new RendererConfigRemoveWorker(key, interfaceOld, ifName, parentRefs);
74 coordinator.enqueueJob(ifName, configWorker);
78 protected void update(InstanceIdentifier<Interface> key, Interface interfaceOld, Interface interfaceNew) {
79 LOG.debug("Received Interface Update Event: {}, {}, {}", key, interfaceOld, interfaceNew);
80 String ifNameNew = interfaceNew.getName();
81 String parentInterface = null;
83 ParentRefs parentRefs = interfaceNew.getAugmentation(ParentRefs.class);
84 if (parentRefs != null) {
85 parentInterface = parentRefs.getParentInterface();
88 if (parentInterface != null && !parentInterface.equals(ifNameNew)) {
92 DataStoreJobCoordinator coordinator = DataStoreJobCoordinator.getInstance();
93 RendererConfigUpdateWorker worker = new RendererConfigUpdateWorker(key, interfaceOld, interfaceNew, ifNameNew);
94 coordinator.enqueueJob(ifNameNew, worker);
98 protected void add(InstanceIdentifier<Interface> key, Interface interfaceNew) {
99 LOG.debug("Received Interface Add Event: {}, {}", key, interfaceNew);
100 String ifName = interfaceNew.getName();
101 String parentInterface = null;
103 ParentRefs parentRefs = interfaceNew.getAugmentation(ParentRefs.class);
104 if (parentRefs != null) {
105 parentInterface = parentRefs.getParentInterface();
108 if (parentInterface != null && !parentInterface.equals(ifName)) {
112 DataStoreJobCoordinator coordinator = DataStoreJobCoordinator.getInstance();
113 RendererConfigAddWorker configWorker = new RendererConfigAddWorker(key, interfaceNew, parentRefs, ifName);
114 coordinator.enqueueJob(ifName, configWorker);
117 private class RendererConfigAddWorker implements Callable<List<ListenableFuture<Void>>> {
118 InstanceIdentifier<Interface> key;
119 Interface interfaceNew;
121 ParentRefs parentRefs;
123 public RendererConfigAddWorker(InstanceIdentifier<Interface> key, Interface interfaceNew,
124 ParentRefs parentRefs, String portName) {
126 this.interfaceNew = interfaceNew;
127 this.portName = portName;
128 this.parentRefs = parentRefs;
132 public List<ListenableFuture<Void>> call() throws Exception {
133 // If another renderer(for eg : CSS) needs to be supported, check can be performed here
134 // to call the respective helpers.
135 return OvsInterfaceConfigAddHelper.addConfiguration(dataBroker, parentRefs, interfaceNew, idManager);
139 public String toString() {
140 return "RendererConfigAddWorker{" +
142 ", interfaceNew=" + interfaceNew +
143 ", portName='" + portName + '\'' +
151 private class RendererConfigUpdateWorker implements Callable {
152 InstanceIdentifier<Interface> key;
153 Interface interfaceOld;
154 Interface interfaceNew;
157 public RendererConfigUpdateWorker(InstanceIdentifier<Interface> key, Interface interfaceOld,
158 Interface interfaceNew, String portNameNew) {
160 this.interfaceOld = interfaceOld;
161 this.interfaceNew = interfaceNew;
162 this.portNameNew = portNameNew;
166 public List<ListenableFuture<Void>> call() throws Exception {
167 // If another renderer(for eg : CSS) needs to be supported, check can be performed here
168 // to call the respective helpers.
169 return OvsInterfaceConfigUpdateHelper.updateConfiguration(dataBroker, idManager, interfaceNew, interfaceOld);
173 public String toString() {
174 return "RendererConfigUpdateWorker{" +
176 ", interfaceOld=" + interfaceOld +
177 ", interfaceNew=" + interfaceNew +
178 ", portNameNew='" + portNameNew + '\'' +
186 private class RendererConfigRemoveWorker implements Callable {
187 InstanceIdentifier<Interface> key;
188 Interface interfaceOld;
190 ParentRefs parentRefs;
192 public RendererConfigRemoveWorker(InstanceIdentifier<Interface> key, Interface interfaceOld, String portName,
193 ParentRefs parentRefs) {
195 this.interfaceOld = interfaceOld;
196 this.portName = portName;
197 this.parentRefs = parentRefs;
201 public List<ListenableFuture<Void>> call() throws Exception {
202 // If another renderer(for eg : CSS) needs to be supported, check can be performed here
203 // to call the respective helpers.
204 return OvsInterfaceConfigRemoveHelper.removeConfiguration(dataBroker, interfaceOld, idManager, parentRefs);
208 public String toString() {
209 return "RendererConfigRemoveWorker{" +
211 ", interfaceOld=" + interfaceOld +
212 ", portName='" + portName + '\'' +