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.alivenessmonitor.rev150629.AlivenessMonitorService;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.idmanager.rev150403.IdManagerService;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.rev150331.ParentRefs;
24 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
28 import java.util.List;
29 import java.util.concurrent.Callable;
32 * This class listens for interface creation/removal/update in Configuration DS.
33 * This is used to handle interfaces for base of-ports.
35 public class InterfaceConfigListener extends AsyncDataTreeChangeListenerBase<Interface, InterfaceConfigListener> {
36 private static final Logger LOG = LoggerFactory.getLogger(InterfaceConfigListener.class);
37 private DataBroker dataBroker;
38 private IdManagerService idManager;
39 private AlivenessMonitorService alivenessMonitorService;
41 public InterfaceConfigListener(final DataBroker dataBroker, final IdManagerService idManager, final AlivenessMonitorService alivenessMonitorService) {
42 super(Interface.class, InterfaceConfigListener.class);
43 this.dataBroker = dataBroker;
44 this.idManager = idManager;
45 this.alivenessMonitorService = alivenessMonitorService;
49 protected InstanceIdentifier<Interface> getWildCardPath() {
50 return InstanceIdentifier.create(Interfaces.class).child(Interface.class);
54 protected InterfaceConfigListener getDataTreeChangeListener() {
55 return InterfaceConfigListener.this;
59 protected void remove(InstanceIdentifier<Interface> key, Interface interfaceOld) {
60 LOG.debug("Received Interface Remove Event: {}, {}", key, interfaceOld);
61 String ifName = interfaceOld.getName();
62 String parentInterface = null;
64 ParentRefs parentRefs = interfaceOld.getAugmentation(ParentRefs.class);
65 if (parentRefs != null) {
66 parentInterface = parentRefs.getParentInterface();
67 if (parentInterface != null && !parentInterface.equals(ifName)) {
70 if (parentRefs.getDatapathNodeIdentifier() == null) {
75 DataStoreJobCoordinator coordinator = DataStoreJobCoordinator.getInstance();
76 RendererConfigRemoveWorker configWorker = new RendererConfigRemoveWorker(key, interfaceOld, ifName, parentRefs);
77 coordinator.enqueueJob(ifName, configWorker);
81 protected void update(InstanceIdentifier<Interface> key, Interface interfaceOld, Interface interfaceNew) {
82 LOG.debug("Received Interface Update Event: {}, {}, {}", key, interfaceOld, interfaceNew);
83 String ifNameNew = interfaceNew.getName();
84 String parentInterface = null;
86 ParentRefs parentRefs = interfaceNew.getAugmentation(ParentRefs.class);
87 if (parentRefs != null) {
88 parentInterface = parentRefs.getParentInterface();
91 if (parentInterface != null && !parentInterface.equals(ifNameNew)) {
95 DataStoreJobCoordinator coordinator = DataStoreJobCoordinator.getInstance();
96 RendererConfigUpdateWorker worker = new RendererConfigUpdateWorker(key, interfaceOld, interfaceNew, ifNameNew);
97 coordinator.enqueueJob(ifNameNew, worker);
101 protected void add(InstanceIdentifier<Interface> key, Interface interfaceNew) {
102 LOG.debug("Received Interface Add Event: {}, {}", key, interfaceNew);
103 String ifName = interfaceNew.getName();
104 String parentInterface = null;
106 ParentRefs parentRefs = interfaceNew.getAugmentation(ParentRefs.class);
107 if (parentRefs != null) {
108 parentInterface = parentRefs.getParentInterface();
111 if (parentInterface != null && !parentInterface.equals(ifName)) {
115 DataStoreJobCoordinator coordinator = DataStoreJobCoordinator.getInstance();
116 RendererConfigAddWorker configWorker = new RendererConfigAddWorker(key, interfaceNew, parentRefs, ifName);
117 coordinator.enqueueJob(ifName, configWorker);
120 private class RendererConfigAddWorker implements Callable<List<ListenableFuture<Void>>> {
121 InstanceIdentifier<Interface> key;
122 Interface interfaceNew;
124 ParentRefs parentRefs;
126 public RendererConfigAddWorker(InstanceIdentifier<Interface> key, Interface interfaceNew,
127 ParentRefs parentRefs, String portName) {
129 this.interfaceNew = interfaceNew;
130 this.portName = portName;
131 this.parentRefs = parentRefs;
135 public List<ListenableFuture<Void>> call() throws Exception {
136 // If another renderer(for eg : CSS) needs to be supported, check can be performed here
137 // to call the respective helpers.
138 return OvsInterfaceConfigAddHelper.addConfiguration(dataBroker, parentRefs, interfaceNew,
143 public String toString() {
144 return "RendererConfigAddWorker{" +
146 ", interfaceNew=" + interfaceNew +
147 ", portName='" + portName + '\'' +
155 private class RendererConfigUpdateWorker implements Callable {
156 InstanceIdentifier<Interface> key;
157 Interface interfaceOld;
158 Interface interfaceNew;
161 public RendererConfigUpdateWorker(InstanceIdentifier<Interface> key, Interface interfaceOld,
162 Interface interfaceNew, String portNameNew) {
164 this.interfaceOld = interfaceOld;
165 this.interfaceNew = interfaceNew;
166 this.portNameNew = portNameNew;
170 public List<ListenableFuture<Void>> call() throws Exception {
171 // If another renderer(for eg : CSS) needs to be supported, check can be performed here
172 // to call the respective helpers.
173 return OvsInterfaceConfigUpdateHelper.updateConfiguration(dataBroker, alivenessMonitorService, idManager,
174 interfaceNew, interfaceOld);
178 public String toString() {
179 return "RendererConfigUpdateWorker{" +
181 ", interfaceOld=" + interfaceOld +
182 ", interfaceNew=" + interfaceNew +
183 ", portNameNew='" + portNameNew + '\'' +
191 private class RendererConfigRemoveWorker implements Callable {
192 InstanceIdentifier<Interface> key;
193 Interface interfaceOld;
195 ParentRefs parentRefs;
197 public RendererConfigRemoveWorker(InstanceIdentifier<Interface> key, Interface interfaceOld, String portName,
198 ParentRefs parentRefs) {
200 this.interfaceOld = interfaceOld;
201 this.portName = portName;
202 this.parentRefs = parentRefs;
206 public List<ListenableFuture<Void>> call() throws Exception {
207 // If another renderer(for eg : CSS) needs to be supported, check can be performed here
208 // to call the respective helpers.
209 return OvsInterfaceConfigRemoveHelper.removeConfiguration(dataBroker, alivenessMonitorService,
210 interfaceOld, idManager, parentRefs);
214 public String toString() {
215 return "RendererConfigRemoveWorker{" +
217 ", interfaceOld=" + interfaceOld +
218 ", portName='" + portName + '\'' +