2 * Copyright (c) 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
8 package org.opendaylight.vpnservice.itm.listeners;
10 import com.google.common.base.Optional;
11 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
12 import org.opendaylight.controller.md.sal.binding.api.DataChangeListener;
13 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
14 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker.DataChangeScope;
15 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
16 import org.opendaylight.vpnservice.datastoreutils.AsyncDataTreeChangeListenerBase;
17 import org.opendaylight.vpnservice.datastoreutils.DataStoreJobCoordinator;
18 import org.opendaylight.vpnservice.interfacemgr.interfaces.IInterfaceManager;
19 import org.opendaylight.vpnservice.itm.confighelpers.HwVtep;
20 import org.opendaylight.vpnservice.itm.confighelpers.ItmMonitorIntervalWorker;
21 import org.opendaylight.vpnservice.itm.confighelpers.ItmMonitorToggleWorker;
22 import org.opendaylight.vpnservice.itm.confighelpers.ItmTepAddWorker;
23 import org.opendaylight.vpnservice.itm.globals.ITMConstants;
24 import org.opendaylight.vpnservice.itm.impl.ItmUtils;
25 import org.opendaylight.vpnservice.mdsalutil.AbstractDataChangeListener;
26 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface;
27 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceBuilder;
28 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceKey;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.rev150331.IfTunnel;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.rev150331.IfTunnelBuilder;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.config.rev151102.TunnelMonitorEnabled;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.config.rev151102.TunnelMonitorInterval;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.ExternalTunnelList;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.TunnelList;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.external.tunnel.list.ExternalTunnel;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.tunnel.list.InternalTunnel;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.rev150701.TransportZones;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.rev150701.transport.zones.TransportZone;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.rev150701.transport.zones.transport.zone.Subnets;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.rev150701.transport.zones.transport.zone.subnets.DeviceVteps;
41 import org.opendaylight.yangtools.concepts.ListenerRegistration;
42 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
43 import org.slf4j.Logger;
44 import org.slf4j.LoggerFactory;
46 import java.util.ArrayList;
47 import java.util.List;
49 public class TunnelMonitorIntervalListener extends AsyncDataTreeChangeListenerBase<TunnelMonitorInterval, TunnelMonitorIntervalListener>
50 implements AutoCloseable {
51 private static final Logger LOG = LoggerFactory.getLogger(TunnelMonitorIntervalListener.class);
52 private ListenerRegistration<DataChangeListener> monitorIntervalListenerRegistration;
53 private final DataBroker broker;
55 public TunnelMonitorIntervalListener(DataBroker db) {
56 super(TunnelMonitorInterval.class, TunnelMonitorIntervalListener.class);
60 @Override protected InstanceIdentifier<TunnelMonitorInterval> getWildCardPath() {
61 return InstanceIdentifier.create(TunnelMonitorInterval.class);
65 protected void remove(InstanceIdentifier<TunnelMonitorInterval> key, TunnelMonitorInterval dataObjectModification) {
66 LOG.debug("remove TunnelMonitorIntervalListener called with {}",dataObjectModification.getInterval());
67 List<HwVtep> hwVteps = new ArrayList<HwVtep>();
68 Boolean hwVtepsExist = false;
69 DataStoreJobCoordinator coordinator = DataStoreJobCoordinator.getInstance();
70 InstanceIdentifier<TransportZones> path = InstanceIdentifier.builder(TransportZones.class).build();
71 Optional<TransportZones> tZonesOptional = ItmUtils.read(LogicalDatastoreType.CONFIGURATION, path, broker);
72 if (tZonesOptional.isPresent()) {
73 TransportZones tZones = tZonesOptional.get();
74 for (TransportZone tzone : tZones.getTransportZone()) {
75 /* hwVtepsExist = false;
76 hwVteps = new ArrayList<HwVtep>();
77 if (tzone.getSubnets() != null && !tzone.getSubnets().isEmpty()) {
78 for (Subnets sub : tzone.getSubnets()) {
79 if (sub.getDeviceVteps() != null && !sub.getDeviceVteps().isEmpty()) {
81 LOG.debug("Remove:Calling TunnelMonitorIntervalWorker with tzone = {} and hwtepExist",tzone.getZoneName());
82 for (DeviceVteps deviceVtep : sub.getDeviceVteps()) {
83 HwVtep hwVtep = ItmUtils.createHwVtepObject(deviceVtep.getTopologyId(), deviceVtep.getNodeId(),
84 deviceVtep.getIpAddress(), sub.getPrefix(), sub.getGatewayIp(), sub.getVlanId(),
85 tzone.getTunnelType(), tzone);
91 //if you remove configuration, the last configured interval is only set i.e no change
92 LOG.debug("Remove:Calling TunnelMonitorIntervalWorker with tzone = {} and {}",tzone.getZoneName(),dataObjectModification.getInterval());
93 ItmMonitorIntervalWorker toggleWorker = new ItmMonitorIntervalWorker(hwVteps, tzone.getZoneName(),
94 dataObjectModification.getInterval(), broker, hwVtepsExist);
95 coordinator.enqueueJob(tzone.getZoneName(), toggleWorker);
100 @Override protected void update(InstanceIdentifier<TunnelMonitorInterval> key,
101 TunnelMonitorInterval dataObjectModificationBefore,
102 TunnelMonitorInterval dataObjectModificationAfter) {
103 LOG.debug("update TunnelMonitorIntervalListener called with {}",dataObjectModificationAfter.getInterval());
104 List<HwVtep> hwVteps = new ArrayList<HwVtep>();
105 Boolean hwVtepsExist = false;
106 DataStoreJobCoordinator coordinator = DataStoreJobCoordinator.getInstance();
107 InstanceIdentifier<TransportZones> path = InstanceIdentifier.builder(TransportZones.class).build();
108 Optional<TransportZones> tZonesOptional = ItmUtils.read(LogicalDatastoreType.CONFIGURATION, path, broker);
109 if (tZonesOptional.isPresent()) {
110 TransportZones tZones = tZonesOptional.get();
111 for (TransportZone tzone : tZones.getTransportZone()) {
112 /*hwVtepsExist = false;
113 hwVteps = new ArrayList<HwVtep>();
114 if (tzone.getSubnets() != null && !tzone.getSubnets().isEmpty()) {
115 for (Subnets sub : tzone.getSubnets()) {
116 if (sub.getDeviceVteps() != null && !sub.getDeviceVteps().isEmpty()) {
117 hwVtepsExist = true;//gets set to true only if this particular tzone has
118 LOG.debug("Update:Calling TunnelMonitorIntervalWorker with tzone = {} and hwtepExist",tzone.getZoneName());
119 for (DeviceVteps deviceVtep : sub.getDeviceVteps()) {
120 HwVtep hwVtep = ItmUtils.createHwVtepObject(deviceVtep.getTopologyId(), deviceVtep.getNodeId(),
121 deviceVtep.getIpAddress(), sub.getPrefix(), sub.getGatewayIp(), sub.getVlanId(),
122 tzone.getTunnelType(), tzone);
128 LOG.debug("Update:Calling TunnelMonitorIntervalWorker with tzone = {} and {}",tzone.getZoneName(),dataObjectModificationAfter.getInterval());
129 ItmMonitorIntervalWorker intervalWorker = new ItmMonitorIntervalWorker(hwVteps, tzone.getZoneName(),
130 dataObjectModificationAfter.getInterval(), broker, hwVtepsExist);
131 coordinator.enqueueJob(tzone.getZoneName(), intervalWorker);
137 protected void add(InstanceIdentifier<TunnelMonitorInterval> key, TunnelMonitorInterval dataObjectModification) {
138 LOG.debug("Add TunnelMonitorIntervalListener called with {}",dataObjectModification.getInterval());
139 List<HwVtep> hwVteps = new ArrayList<HwVtep>();
140 Boolean hwVtepsExist = false;
141 DataStoreJobCoordinator coordinator = DataStoreJobCoordinator.getInstance();
142 InstanceIdentifier<TransportZones> path = InstanceIdentifier.builder(TransportZones.class).build();
143 Optional<TransportZones> tZonesOptional = ItmUtils.read(LogicalDatastoreType.CONFIGURATION, path, broker);
144 if (tZonesOptional.isPresent()) {
145 TransportZones tZones = tZonesOptional.get();
146 for (TransportZone tzone : tZones.getTransportZone()) {
147 /*hwVtepsExist = false;
148 hwVteps = new ArrayList<HwVtep>();
149 if (tzone.getSubnets() != null && !tzone.getSubnets().isEmpty()) {
150 for (Subnets sub : tzone.getSubnets()) {
151 if (sub.getDeviceVteps() != null && !sub.getDeviceVteps().isEmpty()) {
153 LOG.debug("Add:Calling TunnelMonitorIntervalWorker with tzone = {} and hwtepExist",tzone.getZoneName());
154 for (DeviceVteps deviceVtep : sub.getDeviceVteps()) {
155 HwVtep hwVtep = ItmUtils.createHwVtepObject(deviceVtep.getTopologyId(), deviceVtep.getNodeId(),
156 deviceVtep.getIpAddress(), sub.getPrefix(), sub.getGatewayIp(), sub.getVlanId(),
157 tzone.getTunnelType(), tzone);
163 LOG.debug("Add:Calling TunnelMonitorIntervalWorker with tzone = {} and {}",tzone.getZoneName(),dataObjectModification.getInterval());
164 ItmMonitorIntervalWorker intervalWorker = new ItmMonitorIntervalWorker(hwVteps, tzone.getZoneName(),
165 dataObjectModification.getInterval(), broker, hwVtepsExist);
166 //conversion to milliseconds done while writing to i/f-mgr config DS
167 coordinator.enqueueJob(tzone.getZoneName(), intervalWorker);
172 @Override protected TunnelMonitorIntervalListener getDataTreeChangeListener() {
173 return TunnelMonitorIntervalListener.this;