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.interfacemgr.rev150331.ParentRefs;
22 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
26 import java.util.List;
27 import java.util.concurrent.Callable;
30 * This class listens for interface creation/removal/update in Configuration DS.
31 * This is used to handle interfaces for base of-ports.
33 public class InterfaceConfigListener extends AsyncDataTreeChangeListenerBase<Interface, InterfaceConfigListener> {
34 private static final Logger LOG = LoggerFactory.getLogger(InterfaceConfigListener.class);
35 private DataBroker dataBroker;
36 private IdManager idManager;
38 public InterfaceConfigListener(final DataBroker dataBroker, final IdManager idManager) {
39 super(Interface.class, InterfaceConfigListener.class);
40 this.dataBroker = dataBroker;
41 this.idManager = idManager;
45 protected InstanceIdentifier<Interface> getWildCardPath() {
46 return InstanceIdentifier.create(Interfaces.class).child(Interface.class);
50 protected InterfaceConfigListener getDataTreeChangeListener() {
51 return InterfaceConfigListener.this;
55 protected void remove(InstanceIdentifier<Interface> key, Interface interfaceOld) {
56 LOG.debug("Received Interface Remove Event: {}, {}", key, interfaceOld);
57 String ifName = interfaceOld.getName();
58 String parentInterface = null;
60 ParentRefs parentRefs = interfaceOld.getAugmentation(ParentRefs.class);
61 if (parentRefs != null) {
62 parentInterface = parentRefs.getParentInterface();
63 if (parentInterface != null && !parentInterface.equals(ifName)) {
66 if (parentRefs.getDatapathNodeIdentifier() == null) {
71 DataStoreJobCoordinator coordinator = DataStoreJobCoordinator.getInstance();
72 RendererConfigRemoveWorker configWorker = new RendererConfigRemoveWorker(key, interfaceOld, ifName, parentRefs);
73 coordinator.enqueueJob(ifName, configWorker);
77 protected void update(InstanceIdentifier<Interface> key, Interface interfaceOld, Interface interfaceNew) {
78 LOG.debug("Received Interface Update Event: {}, {}, {}", key, interfaceOld, interfaceNew);
79 String ifNameNew = interfaceNew.getName();
80 String parentInterface = null;
82 ParentRefs parentRefs = interfaceNew.getAugmentation(ParentRefs.class);
83 if (parentRefs != null) {
84 parentInterface = parentRefs.getParentInterface();
87 if (parentInterface != null && !parentInterface.equals(ifNameNew)) {
91 DataStoreJobCoordinator coordinator = DataStoreJobCoordinator.getInstance();
92 RendererConfigUpdateWorker worker = new RendererConfigUpdateWorker(key, interfaceOld, interfaceNew, ifNameNew);
93 coordinator.enqueueJob(ifNameNew, worker);
97 protected void add(InstanceIdentifier<Interface> key, Interface interfaceNew) {
98 LOG.debug("Received Interface Add Event: {}, {}", key, interfaceNew);
99 String ifName = interfaceNew.getName();
100 String parentInterface = null;
102 ParentRefs parentRefs = interfaceNew.getAugmentation(ParentRefs.class);
103 if (parentRefs != null) {
104 parentInterface = parentRefs.getParentInterface();
107 if (parentInterface != null && !parentInterface.equals(ifName)) {
111 DataStoreJobCoordinator coordinator = DataStoreJobCoordinator.getInstance();
112 RendererConfigAddWorker configWorker = new RendererConfigAddWorker(key, interfaceNew, parentRefs, ifName);
113 coordinator.enqueueJob(ifName, configWorker);
116 private class RendererConfigAddWorker implements Callable<List<ListenableFuture<Void>>> {
117 InstanceIdentifier<Interface> key;
118 Interface interfaceNew;
120 ParentRefs parentRefs;
122 public RendererConfigAddWorker(InstanceIdentifier<Interface> key, Interface interfaceNew,
123 ParentRefs parentRefs, String portName) {
125 this.interfaceNew = interfaceNew;
126 this.portName = portName;
127 this.parentRefs = parentRefs;
131 public List<ListenableFuture<Void>> call() throws Exception {
132 // If another renderer(for eg : CSS) needs to be supported, check can be performed here
133 // to call the respective helpers.
134 return OvsInterfaceConfigAddHelper.addConfiguration(dataBroker, parentRefs, interfaceNew, idManager);
138 public String toString() {
139 return "RendererConfigAddWorker{" +
141 ", interfaceNew=" + interfaceNew +
142 ", portName='" + portName + '\'' +
150 private class RendererConfigUpdateWorker implements Callable {
151 InstanceIdentifier<Interface> key;
152 Interface interfaceOld;
153 Interface interfaceNew;
156 public RendererConfigUpdateWorker(InstanceIdentifier<Interface> key, Interface interfaceOld,
157 Interface interfaceNew, String portNameNew) {
159 this.interfaceOld = interfaceOld;
160 this.interfaceNew = interfaceNew;
161 this.portNameNew = portNameNew;
165 public List<ListenableFuture<Void>> call() throws Exception {
166 // If another renderer(for eg : CSS) needs to be supported, check can be performed here
167 // to call the respective helpers.
168 return OvsInterfaceConfigUpdateHelper.updateConfiguration(dataBroker, idManager, interfaceNew, interfaceOld);
172 public String toString() {
173 return "RendererConfigUpdateWorker{" +
175 ", interfaceOld=" + interfaceOld +
176 ", interfaceNew=" + interfaceNew +
177 ", portNameNew='" + portNameNew + '\'' +
185 private class RendererConfigRemoveWorker implements Callable {
186 InstanceIdentifier<Interface> key;
187 Interface interfaceOld;
189 ParentRefs parentRefs;
191 public RendererConfigRemoveWorker(InstanceIdentifier<Interface> key, Interface interfaceOld, String portName,
192 ParentRefs parentRefs) {
194 this.interfaceOld = interfaceOld;
195 this.portName = portName;
196 this.parentRefs = parentRefs;
200 public List<ListenableFuture<Void>> call() throws Exception {
201 // If another renderer(for eg : CSS) needs to be supported, check can be performed here
202 // to call the respective helpers.
203 return OvsInterfaceConfigRemoveHelper.removeConfiguration(dataBroker, interfaceOld, idManager, parentRefs);
207 public String toString() {
208 return "RendererConfigRemoveWorker{" +
210 ", interfaceOld=" + interfaceOld +
211 ", portName='" + portName + '\'' +