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
8 package org.opendaylight.vpnservice.interfacemgr.listeners;
10 import com.google.common.util.concurrent.ListenableFuture;
11 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
12 import org.opendaylight.idmanager.IdManager;
13 import org.opendaylight.vpnservice.datastoreutils.AsyncDataTreeChangeListenerBase;
14 import org.opendaylight.vpnservice.datastoreutils.DataStoreJobCoordinator;
15 import org.opendaylight.vpnservice.interfacemgr.renderer.ovs.confighelpers.OvsVlanMemberConfigAddHelper;
16 import org.opendaylight.vpnservice.interfacemgr.renderer.ovs.confighelpers.OvsVlanMemberConfigRemoveHelper;
17 import org.opendaylight.vpnservice.interfacemgr.renderer.ovs.confighelpers.OvsVlanMemberConfigUpdateHelper;
18 import org.opendaylight.vpnservice.mdsalutil.interfaces.IMdsalApiManager;
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.IfL2vlan;
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;
32 public class VlanMemberConfigListener extends AsyncDataTreeChangeListenerBase<Interface, VlanMemberConfigListener> {
33 private static final Logger LOG = LoggerFactory.getLogger(VlanMemberConfigListener.class);
34 private DataBroker dataBroker;
35 private IdManagerService idManager;
36 private AlivenessMonitorService alivenessMonitorService;
37 private IMdsalApiManager mdsalApiManager;
39 public VlanMemberConfigListener(final DataBroker dataBroker, final IdManagerService idManager,
40 final AlivenessMonitorService alivenessMonitorService,
41 final IMdsalApiManager mdsalApiManager) {
42 super(Interface.class, VlanMemberConfigListener.class);
43 this.dataBroker = dataBroker;
44 this.idManager = idManager;
45 this.alivenessMonitorService = alivenessMonitorService;
46 this.mdsalApiManager = mdsalApiManager;
50 protected InstanceIdentifier<Interface> getWildCardPath() {
51 return InstanceIdentifier.create(Interfaces.class).child(Interface.class);
55 protected void remove(InstanceIdentifier<Interface> key, Interface interfaceOld) {
56 IfL2vlan ifL2vlan = interfaceOld.getAugmentation(IfL2vlan.class);
57 if (ifL2vlan == null) {
61 ParentRefs parentRefs = interfaceOld.getAugmentation(ParentRefs.class);
62 if (parentRefs == null) {
63 LOG.error("Attempt to remove Vlan Trunk-Member {} without a parent interface", interfaceOld);
67 String lowerLayerIf = parentRefs.getParentInterface();
68 if (lowerLayerIf.equals(interfaceOld.getName())) {
69 LOG.error("Attempt to remove Vlan Trunk-Member {} with same parent interface name.", interfaceOld);
73 DataStoreJobCoordinator coordinator = DataStoreJobCoordinator.getInstance();
74 RendererConfigRemoveWorker removeWorker = new RendererConfigRemoveWorker(key, interfaceOld, parentRefs, ifL2vlan);
75 coordinator.enqueueJob(lowerLayerIf, removeWorker);
79 protected void update(InstanceIdentifier<Interface> key, Interface interfaceOld, Interface interfaceNew) {
80 IfL2vlan ifL2vlanNew = interfaceNew.getAugmentation(IfL2vlan.class);
81 if (ifL2vlanNew == null) {
85 ParentRefs parentRefsNew = interfaceNew.getAugmentation(ParentRefs.class);
86 if (parentRefsNew == null) {
87 LOG.error("Configuration Error. Attempt to update Vlan Trunk-Member {} without a " +
88 "parent interface", interfaceNew);
92 String lowerLayerIf = parentRefsNew.getParentInterface();
93 if (lowerLayerIf.equals(interfaceNew.getName())) {
94 LOG.error("Configuration Error. Attempt to update Vlan Trunk-Member {} with same parent " +
95 "interface name.", interfaceNew);
99 DataStoreJobCoordinator coordinator = DataStoreJobCoordinator.getInstance();
100 RendererConfigUpdateWorker updateWorker = new RendererConfigUpdateWorker(key, interfaceNew, interfaceOld,
101 parentRefsNew, ifL2vlanNew);
102 coordinator.enqueueJob(lowerLayerIf, updateWorker);
106 protected void add(InstanceIdentifier<Interface> key, Interface interfaceNew) {
107 IfL2vlan ifL2vlan = interfaceNew.getAugmentation(IfL2vlan.class);
108 if (ifL2vlan == null) {
112 ParentRefs parentRefs = interfaceNew.getAugmentation(ParentRefs.class);
113 if (parentRefs == null) {
117 String lowerLayerIf = parentRefs.getParentInterface();
118 if (lowerLayerIf.equals(interfaceNew.getName())) {
119 LOG.error("Attempt to add Vlan Trunk-Member {} with same parent interface name.", interfaceNew);
123 DataStoreJobCoordinator coordinator = DataStoreJobCoordinator.getInstance();
124 RendererConfigAddWorker configWorker = new RendererConfigAddWorker(key, interfaceNew, parentRefs, ifL2vlan);
125 coordinator.enqueueJob(lowerLayerIf, configWorker);
129 protected VlanMemberConfigListener getDataTreeChangeListener() {
130 return VlanMemberConfigListener.this;
133 private class RendererConfigAddWorker implements Callable<List<ListenableFuture<Void>>> {
134 InstanceIdentifier<Interface> key;
135 Interface interfaceNew;
137 ParentRefs parentRefs;
139 public RendererConfigAddWorker(InstanceIdentifier<Interface> key, Interface interfaceNew,
140 ParentRefs parentRefs, IfL2vlan ifL2vlan) {
142 this.interfaceNew = interfaceNew;
143 this.ifL2vlan = ifL2vlan;
144 this.parentRefs = parentRefs;
148 public List<ListenableFuture<Void>> call() throws Exception {
149 // If another renderer(for eg : CSS) needs to be supported, check can be performed here
150 // to call the respective helpers.
151 return OvsVlanMemberConfigAddHelper.addConfiguration(dataBroker, parentRefs, interfaceNew,
152 ifL2vlan, idManager);
156 private class RendererConfigUpdateWorker implements Callable<List<ListenableFuture<Void>>> {
157 InstanceIdentifier<Interface> key;
158 Interface interfaceNew;
159 Interface interfaceOld;
160 IfL2vlan ifL2vlanNew;
161 ParentRefs parentRefsNew;
163 public RendererConfigUpdateWorker(InstanceIdentifier<Interface> key, Interface interfaceNew,
164 Interface interfaceOld, ParentRefs parentRefsNew, IfL2vlan ifL2vlanNew) {
166 this.interfaceNew = interfaceNew;
167 this.interfaceOld = interfaceOld;
168 this.ifL2vlanNew = ifL2vlanNew;
169 this.parentRefsNew = parentRefsNew;
173 public List<ListenableFuture<Void>> call() throws Exception {
174 // If another renderer(for eg : CSS) needs to be supported, check can be performed here
175 // to call the respective helpers.
176 return OvsVlanMemberConfigUpdateHelper.updateConfiguration(dataBroker, alivenessMonitorService,
177 parentRefsNew, interfaceOld, ifL2vlanNew, interfaceNew, idManager, mdsalApiManager);
181 private class RendererConfigRemoveWorker implements Callable<List<ListenableFuture<Void>>> {
182 InstanceIdentifier<Interface> key;
183 Interface interfaceOld;
185 ParentRefs parentRefs;
187 public RendererConfigRemoveWorker(InstanceIdentifier<Interface> key, Interface interfaceOld,
188 ParentRefs parentRefs, IfL2vlan ifL2vlan) {
190 this.interfaceOld = interfaceOld;
191 this.ifL2vlan = ifL2vlan;
192 this.parentRefs = parentRefs;
196 public List<ListenableFuture<Void>> call() throws Exception {
197 // If another renderer(for eg : CSS) needs to be supported, check can be performed here
198 // to call the respective helpers.
199 return OvsVlanMemberConfigRemoveHelper.removeConfiguration(dataBroker, parentRefs, interfaceOld,
200 ifL2vlan, idManager);