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.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.Interfaces;
19 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.alivenessmonitor.rev150629.AlivenessMonitorService;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.idmanager.rev150403.IdManagerService;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.rev150331.IfL2vlan;
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;
31 public class VlanMemberConfigListener extends AsyncDataTreeChangeListenerBase<Interface, VlanMemberConfigListener> {
32 private static final Logger LOG = LoggerFactory.getLogger(VlanMemberConfigListener.class);
33 private DataBroker dataBroker;
34 private IdManagerService idManager;
35 private AlivenessMonitorService alivenessMonitorService;
37 public VlanMemberConfigListener(final DataBroker dataBroker, final IdManagerService idManager,
38 final AlivenessMonitorService alivenessMonitorService) {
39 super(Interface.class, VlanMemberConfigListener.class);
40 this.dataBroker = dataBroker;
41 this.idManager = idManager;
42 this.alivenessMonitorService = alivenessMonitorService;
46 protected InstanceIdentifier<Interface> getWildCardPath() {
47 return InstanceIdentifier.create(Interfaces.class).child(Interface.class);
51 protected void remove(InstanceIdentifier<Interface> key, Interface interfaceOld) {
52 IfL2vlan ifL2vlan = interfaceOld.getAugmentation(IfL2vlan.class);
53 if (ifL2vlan == null) {
57 if (ifL2vlan.getL2vlanMode() != IfL2vlan.L2vlanMode.TrunkMember) {
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) {
84 if (ifL2vlanNew.getL2vlanMode() != IfL2vlan.L2vlanMode.TrunkMember) {
85 LOG.error("Configuration Error. Attempt to modify Vlan Mode of interface: {} " +
86 "to interface: {}", interfaceOld, interfaceNew);
90 ParentRefs parentRefsNew = interfaceNew.getAugmentation(ParentRefs.class);
91 if (parentRefsNew == null) {
92 LOG.error("Configuration Error. Attempt to update Vlan Trunk-Member {} without a " +
93 "parent interface", interfaceNew);
97 String lowerLayerIf = parentRefsNew.getParentInterface();
98 if (lowerLayerIf.equals(interfaceNew.getName())) {
99 LOG.error("Configuration Error. Attempt to update Vlan Trunk-Member {} with same parent " +
100 "interface name.", interfaceNew);
104 DataStoreJobCoordinator coordinator = DataStoreJobCoordinator.getInstance();
105 RendererConfigUpdateWorker updateWorker = new RendererConfigUpdateWorker(key, interfaceNew, interfaceOld,
106 parentRefsNew, ifL2vlanNew);
107 coordinator.enqueueJob(lowerLayerIf, updateWorker);
111 protected void add(InstanceIdentifier<Interface> key, Interface interfaceNew) {
112 IfL2vlan ifL2vlan = interfaceNew.getAugmentation(IfL2vlan.class);
113 if (ifL2vlan == null) {
117 if (ifL2vlan.getL2vlanMode() != IfL2vlan.L2vlanMode.TrunkMember) {
121 ParentRefs parentRefs = interfaceNew.getAugmentation(ParentRefs.class);
122 if (parentRefs == null) {
123 LOG.error("Attempt to add Vlan Trunk-Member {} without a parent interface", interfaceNew);
127 String lowerLayerIf = parentRefs.getParentInterface();
128 if (lowerLayerIf.equals(interfaceNew.getName())) {
129 LOG.error("Attempt to add Vlan Trunk-Member {} with same parent interface name.", interfaceNew);
133 DataStoreJobCoordinator coordinator = DataStoreJobCoordinator.getInstance();
134 RendererConfigAddWorker configWorker = new RendererConfigAddWorker(key, interfaceNew, parentRefs, ifL2vlan);
135 coordinator.enqueueJob(lowerLayerIf, configWorker);
139 protected VlanMemberConfigListener getDataTreeChangeListener() {
140 return VlanMemberConfigListener.this;
143 private class RendererConfigAddWorker implements Callable<List<ListenableFuture<Void>>> {
144 InstanceIdentifier<Interface> key;
145 Interface interfaceNew;
147 ParentRefs parentRefs;
149 public RendererConfigAddWorker(InstanceIdentifier<Interface> key, Interface interfaceNew,
150 ParentRefs parentRefs, IfL2vlan ifL2vlan) {
152 this.interfaceNew = interfaceNew;
153 this.ifL2vlan = ifL2vlan;
154 this.parentRefs = parentRefs;
158 public List<ListenableFuture<Void>> call() throws Exception {
159 // If another renderer(for eg : CSS) needs to be supported, check can be performed here
160 // to call the respective helpers.
161 return OvsVlanMemberConfigAddHelper.addConfiguration(dataBroker, parentRefs, interfaceNew,
162 ifL2vlan, idManager);
166 private class RendererConfigUpdateWorker implements Callable<List<ListenableFuture<Void>>> {
167 InstanceIdentifier<Interface> key;
168 Interface interfaceNew;
169 Interface interfaceOld;
170 IfL2vlan ifL2vlanNew;
171 ParentRefs parentRefsNew;
173 public RendererConfigUpdateWorker(InstanceIdentifier<Interface> key, Interface interfaceNew,
174 Interface interfaceOld, ParentRefs parentRefsNew, IfL2vlan ifL2vlanNew) {
176 this.interfaceNew = interfaceNew;
177 this.interfaceOld = interfaceOld;
178 this.ifL2vlanNew = ifL2vlanNew;
179 this.parentRefsNew = parentRefsNew;
183 public List<ListenableFuture<Void>> call() throws Exception {
184 // If another renderer(for eg : CSS) needs to be supported, check can be performed here
185 // to call the respective helpers.
186 return OvsVlanMemberConfigUpdateHelper.updateConfiguration(dataBroker, alivenessMonitorService,
187 parentRefsNew, interfaceOld, ifL2vlanNew, interfaceNew, idManager);
191 private class RendererConfigRemoveWorker implements Callable<List<ListenableFuture<Void>>> {
192 InstanceIdentifier<Interface> key;
193 Interface interfaceOld;
195 ParentRefs parentRefs;
197 public RendererConfigRemoveWorker(InstanceIdentifier<Interface> key, Interface interfaceOld,
198 ParentRefs parentRefs, IfL2vlan ifL2vlan) {
200 this.interfaceOld = interfaceOld;
201 this.ifL2vlan = ifL2vlan;
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 OvsVlanMemberConfigRemoveHelper.removeConfiguration(dataBroker, parentRefs, interfaceOld,
210 ifL2vlan, idManager);