2 * Copyright (c) 2015 - 2016 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;
42 private static final int MAX_RETRIES = 3;
44 public InterfaceConfigListener(final DataBroker dataBroker, final IdManagerService idManager,
45 final AlivenessMonitorService alivenessMonitorService,
46 final IMdsalApiManager mdsalApiManager) {
47 super(Interface.class, InterfaceConfigListener.class);
48 this.dataBroker = dataBroker;
49 this.idManager = idManager;
50 this.alivenessMonitorService = alivenessMonitorService;
51 this.mdsalApiManager = mdsalApiManager;
55 protected InstanceIdentifier<Interface> getWildCardPath() {
56 return InstanceIdentifier.create(Interfaces.class).child(Interface.class);
60 protected InterfaceConfigListener getDataTreeChangeListener() {
61 return InterfaceConfigListener.this;
65 protected void remove(InstanceIdentifier<Interface> key, Interface interfaceOld) {
66 LOG.debug("Received Interface Remove Event: {}, {}", key, interfaceOld);
67 String ifName = interfaceOld.getName();
68 ParentRefs parentRefs = interfaceOld.getAugmentation(ParentRefs.class);
69 DataStoreJobCoordinator coordinator = DataStoreJobCoordinator.getInstance();
70 RendererConfigRemoveWorker configWorker = new RendererConfigRemoveWorker(key, interfaceOld, ifName, parentRefs);
71 coordinator.enqueueJob(ifName, configWorker, MAX_RETRIES);
75 protected void update(InstanceIdentifier<Interface> key, Interface interfaceOld, Interface interfaceNew) {
76 LOG.debug("Received Interface Update Event: {}, {}, {}", key, interfaceOld, interfaceNew);
77 String ifNameNew = interfaceNew.getName();
78 ParentRefs parentRefs = interfaceNew.getAugmentation(ParentRefs.class);
79 if (parentRefs == null || parentRefs.getDatapathNodeIdentifier() == null && parentRefs.getParentInterface() == null) {
80 LOG.error("parent refs not specified for {}",interfaceNew.getName());
83 DataStoreJobCoordinator coordinator = DataStoreJobCoordinator.getInstance();
84 RendererConfigUpdateWorker worker = new RendererConfigUpdateWorker(key, interfaceOld, interfaceNew, ifNameNew);
85 coordinator.enqueueJob(ifNameNew, worker, MAX_RETRIES);
89 protected void add(InstanceIdentifier<Interface> key, Interface interfaceNew) {
90 LOG.debug("Received Interface Add Event: {}, {}", key, interfaceNew);
91 String ifName = interfaceNew.getName();
92 ParentRefs parentRefs = interfaceNew.getAugmentation(ParentRefs.class);
93 if (parentRefs == null || parentRefs.getDatapathNodeIdentifier() == null && parentRefs.getParentInterface() == null) {
94 LOG.error("parent refs not specified for {}",interfaceNew.getName());
97 DataStoreJobCoordinator coordinator = DataStoreJobCoordinator.getInstance();
98 RendererConfigAddWorker configWorker = new RendererConfigAddWorker(key, interfaceNew, parentRefs, ifName);
99 coordinator.enqueueJob(ifName, configWorker, MAX_RETRIES);
102 private class RendererConfigAddWorker implements Callable<List<ListenableFuture<Void>>> {
103 InstanceIdentifier<Interface> key;
104 Interface interfaceNew;
106 ParentRefs parentRefs;
108 public RendererConfigAddWorker(InstanceIdentifier<Interface> key, Interface interfaceNew,
109 ParentRefs parentRefs, String portName) {
111 this.interfaceNew = interfaceNew;
112 this.portName = portName;
113 this.parentRefs = parentRefs;
117 public List<ListenableFuture<Void>> call() throws Exception {
118 // If another renderer(for eg : CSS) needs to be supported, check can be performed here
119 // to call the respective helpers.
120 return OvsInterfaceConfigAddHelper.addConfiguration(dataBroker, parentRefs, interfaceNew,
121 idManager, alivenessMonitorService, mdsalApiManager);
125 public String toString() {
126 return "RendererConfigAddWorker{" +
128 ", interfaceNew=" + interfaceNew +
129 ", portName='" + portName + '\'' +
137 private class RendererConfigUpdateWorker implements Callable {
138 InstanceIdentifier<Interface> key;
139 Interface interfaceOld;
140 Interface interfaceNew;
143 public RendererConfigUpdateWorker(InstanceIdentifier<Interface> key, Interface interfaceOld,
144 Interface interfaceNew, String portNameNew) {
146 this.interfaceOld = interfaceOld;
147 this.interfaceNew = interfaceNew;
148 this.portNameNew = portNameNew;
152 public List<ListenableFuture<Void>> call() throws Exception {
153 // If another renderer(for eg : CSS) needs to be supported, check can be performed here
154 // to call the respective helpers.
155 return OvsInterfaceConfigUpdateHelper.updateConfiguration(dataBroker, alivenessMonitorService, idManager,
156 mdsalApiManager, interfaceNew, interfaceOld);
160 public String toString() {
161 return "RendererConfigUpdateWorker{" +
163 ", interfaceOld=" + interfaceOld +
164 ", interfaceNew=" + interfaceNew +
165 ", portNameNew='" + portNameNew + '\'' +
173 private class RendererConfigRemoveWorker implements Callable {
174 InstanceIdentifier<Interface> key;
175 Interface interfaceOld;
177 ParentRefs parentRefs;
179 public RendererConfigRemoveWorker(InstanceIdentifier<Interface> key, Interface interfaceOld, String portName,
180 ParentRefs parentRefs) {
182 this.interfaceOld = interfaceOld;
183 this.portName = portName;
184 this.parentRefs = parentRefs;
188 public List<ListenableFuture<Void>> call() throws Exception {
189 // If another renderer(for eg : CSS) needs to be supported, check can be performed here
190 // to call the respective helpers.
191 return OvsInterfaceConfigRemoveHelper.removeConfiguration(dataBroker, alivenessMonitorService,
192 interfaceOld, idManager, mdsalApiManager, parentRefs);
196 public String toString() {
197 return "RendererConfigRemoveWorker{" +
199 ", interfaceOld=" + interfaceOld +
200 ", portName='" + portName + '\'' +