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
9 package org.opendaylight.ovsdb.hwvtepsouthbound;
11 import org.opendaylight.ovsdb.lib.notation.UUID;
12 import org.opendaylight.ovsdb.schema.hardwarevtep.LogicalSwitch;
13 import org.opendaylight.ovsdb.schema.hardwarevtep.PhysicalLocator;
14 import org.opendaylight.ovsdb.schema.hardwarevtep.PhysicalSwitch;
15 import org.opendaylight.yangtools.yang.binding.Identifiable;
16 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
17 import org.slf4j.Logger;
18 import org.slf4j.LoggerFactory;
20 import java.util.HashMap;
22 import java.util.concurrent.ConcurrentHashMap;
25 * HwvtepDeviceInfo is used to store some of the table entries received
26 * in updates from a Hwvtep device. There will be one instance of this per
27 * Hwvtep device connected. Table entries are stored in a map keyed by
28 * uuids of respective rows.
30 * Purpose of this class is to provide data present in tables which
31 * were updated in a previous transaction and are not available in
32 * current updatedRows. This allows us to handle updates for Tables
33 * which reference other tables and need information in those tables
34 * to add data to Operational data store.
36 * e.g. Mac-entries in data store use logical-switch-ref as one of the
37 * keys. Mac-entry updates from switch rarely contain Logical_Switch
38 * table entries. To add mac-entries we need table entries from
39 * Logical_Switch table which were created in an earlier update.
42 public class HwvtepDeviceInfo {
44 private static final Logger LOG = LoggerFactory.getLogger(HwvtepDeviceInfo.class);
46 public enum DeviceDataStatus {
52 public static class DeviceData {
53 private final InstanceIdentifier key;
54 private final UUID uuid;
55 private final Object data;
56 private final DeviceDataStatus status;
58 public DeviceData(InstanceIdentifier key, UUID uuid, Object data, DeviceDataStatus status) {
65 public Object getData() {
69 public DeviceDataStatus getStatus() {
73 public UUID getUuid() {
79 private Map<UUID, LogicalSwitch> logicalSwitches = null;
80 private Map<UUID, PhysicalSwitch> physicalSwitches = null;
81 private Map<UUID, PhysicalLocator> physicalLocators = null;
82 private Map<UUID, UUID> mapTunnelToPhysicalSwitch = null;
84 private HwvtepConnectionInstance connectionInstance;
86 private Map<Class<? extends Identifiable>, Map<InstanceIdentifier, DeviceData>> configKeyVsData = new ConcurrentHashMap<>();
87 private Map<Class<? extends Identifiable>, Map<InstanceIdentifier, DeviceData>> opKeyVsData = new ConcurrentHashMap<>();
88 private Map<Class<? extends Identifiable>, Map<UUID, Object>> uuidVsData = new ConcurrentHashMap<>();
90 public HwvtepDeviceInfo(HwvtepConnectionInstance hwvtepConnectionInstance) {
91 this.connectionInstance = hwvtepConnectionInstance;
92 this.logicalSwitches = new HashMap<>();
93 this.physicalSwitches = new HashMap<>();
94 this.physicalLocators = new HashMap<>();
95 this.mapTunnelToPhysicalSwitch = new HashMap<>();
98 public void putLogicalSwitch(UUID uuid, LogicalSwitch lSwitch) {
99 logicalSwitches.put(uuid, lSwitch);
102 public LogicalSwitch getLogicalSwitch(UUID uuid) {
103 return logicalSwitches.get(uuid);
106 public LogicalSwitch removeLogicalSwitch(UUID uuid) {
107 return logicalSwitches.remove(uuid);
110 public Map<UUID, LogicalSwitch> getLogicalSwitches() {
111 return logicalSwitches;
114 public void putPhysicalSwitch(UUID uuid, PhysicalSwitch pSwitch) {
115 physicalSwitches.put(uuid, pSwitch);
118 public PhysicalSwitch getPhysicalSwitch(UUID uuid) {
119 return physicalSwitches.get(uuid);
122 public PhysicalSwitch removePhysicalSwitch(UUID uuid) {
123 return physicalSwitches.remove(uuid);
126 public Map<UUID, PhysicalSwitch> getPhysicalSwitches() {
127 return physicalSwitches;
130 public void putPhysicalLocator(UUID uuid, PhysicalLocator pLocator) {
131 physicalLocators.put(uuid, pLocator);
134 public PhysicalLocator getPhysicalLocator(UUID uuid) {
135 return physicalLocators.get(uuid);
138 public PhysicalLocator removePhysicalLocator(UUID uuid) {
139 return physicalLocators.remove(uuid);
142 public Map<UUID, PhysicalLocator> getPhysicalLocators() {
143 return physicalLocators;
146 public void putPhysicalSwitchForTunnel(UUID uuid, UUID psUUID) {
147 mapTunnelToPhysicalSwitch.put(uuid, psUUID);
150 public PhysicalSwitch getPhysicalSwitchForTunnel(UUID uuid) {
151 return physicalSwitches.get(mapTunnelToPhysicalSwitch.get(uuid));
154 public void removePhysicalSwitchForTunnel(UUID uuid) {
155 mapTunnelToPhysicalSwitch.remove(uuid);
158 public Map<UUID, UUID> getPhysicalSwitchesForTunnels() {
159 return mapTunnelToPhysicalSwitch;
162 public boolean isKeyInTransit(Class<? extends Identifiable> cls, InstanceIdentifier key) {
163 DeviceData deviceData = HwvtepSouthboundUtil.getData(opKeyVsData, cls, key);
164 return deviceData != null && DeviceDataStatus.IN_TRANSIT == deviceData.status;
167 public boolean isConfigDataAvailable(Class<? extends Identifiable> cls, InstanceIdentifier key) {
168 return HwvtepSouthboundUtil.getData(configKeyVsData, cls, key) != null;
171 public void updateConfigData(Class<? extends Identifiable> cls, InstanceIdentifier key, Object data) {
172 HwvtepSouthboundUtil.updateData(configKeyVsData, cls, key,
173 new DeviceData(key, null, data, DeviceDataStatus.AVAILABLE));
176 public void clearConfigData(Class<? extends Identifiable> cls, InstanceIdentifier key) {
177 HwvtepSouthboundUtil.clearData(configKeyVsData, cls, key);
180 public void markKeyAsInTransit(Class<? extends Identifiable> cls, InstanceIdentifier key) {
181 HwvtepSouthboundUtil.updateData(opKeyVsData, cls, key,
182 new DeviceData(key, null, null, DeviceDataStatus.IN_TRANSIT));
185 public void updateDeviceOpData(Class<? extends Identifiable> cls, InstanceIdentifier key, UUID uuid, Object data) {
186 HwvtepSouthboundUtil.updateData(opKeyVsData, cls, key,
187 new DeviceData(key, uuid, data, DeviceDataStatus.AVAILABLE));
188 HwvtepSouthboundUtil.updateData(uuidVsData, cls, uuid, data);
191 public void clearDeviceOpData(Class<? extends Identifiable> cls, InstanceIdentifier key) {
192 DeviceData deviceData = HwvtepSouthboundUtil.getData(opKeyVsData, cls, key);
193 if (deviceData != null && deviceData.uuid != null) {
194 HwvtepSouthboundUtil.clearData(uuidVsData, cls, deviceData.uuid);
196 HwvtepSouthboundUtil.clearData(opKeyVsData, cls, key);
199 public Object getDeviceOpData(Class<? extends Identifiable> cls, UUID uuid) {
200 return HwvtepSouthboundUtil.getData(uuidVsData, cls, uuid);
203 public DeviceData getDeviceOpData(Class<? extends Identifiable> cls, InstanceIdentifier key) {
204 return HwvtepSouthboundUtil.getData(opKeyVsData, cls, key);
207 public UUID getUUID(Class<? extends Identifiable> cls, InstanceIdentifier key) {
208 DeviceData data = HwvtepSouthboundUtil.getData(opKeyVsData, cls, key);