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 /* parentInterface = parentRefs.getParentInterface();
71 if (parentInterface != null && !parentInterface.equals(ifName)) {
74 if (parentRefs.getDatapathNodeIdentifier() == null) {
77 if(parentInterface == null){
78 LOG.error("parent interface not specified for {}",interfaceOld.getName());
82 DataStoreJobCoordinator coordinator = DataStoreJobCoordinator.getInstance();
83 RendererConfigRemoveWorker configWorker = new RendererConfigRemoveWorker(key, interfaceOld, ifName, parentRefs);
84 coordinator.enqueueJob(ifName, configWorker);
88 protected void update(InstanceIdentifier<Interface> key, Interface interfaceOld, Interface interfaceNew) {
89 LOG.debug("Received Interface Update Event: {}, {}, {}", key, interfaceOld, interfaceNew);
90 String ifNameNew = interfaceNew.getName();
91 String parentInterface = null;
93 /*ParentRefs parentRefs = interfaceNew.getAugmentation(ParentRefs.class);
94 if (parentRefs == null) {
95 LOG.error("parent refs not specified for {}",interfaceNew.getName());
98 if (parentInterface == null) {
99 LOG.error("parent interface not specified for {}",interfaceOld.getName());
103 DataStoreJobCoordinator coordinator = DataStoreJobCoordinator.getInstance();
104 RendererConfigUpdateWorker worker = new RendererConfigUpdateWorker(key, interfaceOld, interfaceNew, ifNameNew);
105 coordinator.enqueueJob(ifNameNew, worker);
109 protected void add(InstanceIdentifier<Interface> key, Interface interfaceNew) {
110 LOG.debug("Received Interface Add Event: {}, {}", key, interfaceNew);
111 String ifName = interfaceNew.getName();
112 String parentInterface = null;
114 ParentRefs parentRefs = interfaceNew.getAugmentation(ParentRefs.class);
115 if (parentRefs == null) {
116 LOG.error("parent refs not specified for {}",interfaceNew.getName());
119 /*if(parentInterface == null){
120 LOG.error("parent interface not specified for {}",interfaceNew.getName());
123 DataStoreJobCoordinator coordinator = DataStoreJobCoordinator.getInstance();
124 RendererConfigAddWorker configWorker = new RendererConfigAddWorker(key, interfaceNew, parentRefs, ifName);
125 coordinator.enqueueJob(ifName, configWorker);
128 private class RendererConfigAddWorker implements Callable<List<ListenableFuture<Void>>> {
129 InstanceIdentifier<Interface> key;
130 Interface interfaceNew;
132 ParentRefs parentRefs;
134 public RendererConfigAddWorker(InstanceIdentifier<Interface> key, Interface interfaceNew,
135 ParentRefs parentRefs, String portName) {
137 this.interfaceNew = interfaceNew;
138 this.portName = portName;
139 this.parentRefs = parentRefs;
143 public List<ListenableFuture<Void>> call() throws Exception {
144 // If another renderer(for eg : CSS) needs to be supported, check can be performed here
145 // to call the respective helpers.
146 return OvsInterfaceConfigAddHelper.addConfiguration(dataBroker, parentRefs, interfaceNew,
147 idManager, alivenessMonitorService, mdsalApiManager);
151 public String toString() {
152 return "RendererConfigAddWorker{" +
154 ", interfaceNew=" + interfaceNew +
155 ", portName='" + portName + '\'' +
163 private class RendererConfigUpdateWorker implements Callable {
164 InstanceIdentifier<Interface> key;
165 Interface interfaceOld;
166 Interface interfaceNew;
169 public RendererConfigUpdateWorker(InstanceIdentifier<Interface> key, Interface interfaceOld,
170 Interface interfaceNew, String portNameNew) {
172 this.interfaceOld = interfaceOld;
173 this.interfaceNew = interfaceNew;
174 this.portNameNew = portNameNew;
178 public List<ListenableFuture<Void>> call() throws Exception {
179 // If another renderer(for eg : CSS) needs to be supported, check can be performed here
180 // to call the respective helpers.
181 return OvsInterfaceConfigUpdateHelper.updateConfiguration(dataBroker, alivenessMonitorService, idManager,
182 mdsalApiManager, interfaceNew, interfaceOld);
186 public String toString() {
187 return "RendererConfigUpdateWorker{" +
189 ", interfaceOld=" + interfaceOld +
190 ", interfaceNew=" + interfaceNew +
191 ", portNameNew='" + portNameNew + '\'' +
199 private class RendererConfigRemoveWorker implements Callable {
200 InstanceIdentifier<Interface> key;
201 Interface interfaceOld;
203 ParentRefs parentRefs;
205 public RendererConfigRemoveWorker(InstanceIdentifier<Interface> key, Interface interfaceOld, String portName,
206 ParentRefs parentRefs) {
208 this.interfaceOld = interfaceOld;
209 this.portName = portName;
210 this.parentRefs = parentRefs;
214 public List<ListenableFuture<Void>> call() throws Exception {
215 // If another renderer(for eg : CSS) needs to be supported, check can be performed here
216 // to call the respective helpers.
217 return OvsInterfaceConfigRemoveHelper.removeConfiguration(dataBroker, alivenessMonitorService,
218 interfaceOld, idManager, mdsalApiManager, parentRefs);
222 public String toString() {
223 return "RendererConfigRemoveWorker{" +
225 ", interfaceOld=" + interfaceOld +
226 ", portName='" + portName + '\'' +