import javax.annotation.Nonnull;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
import org.opendaylight.controller.md.sal.common.api.clustering.CandidateAlreadyRegisteredException;
import org.opendaylight.controller.md.sal.common.api.clustering.Entity;
import org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipCandidateRegistration;
import org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipListenerRegistration;
import org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipService;
import org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipState;
+import org.opendaylight.ovsdb.hwvtepsouthbound.transactions.md.HwvtepGlobalRemoveCommand;
+import org.opendaylight.ovsdb.hwvtepsouthbound.transactions.md.PhysicalSwitchRemoveCommand;
import org.opendaylight.ovsdb.hwvtepsouthbound.transactions.md.TransactionInvoker;
import org.opendaylight.ovsdb.lib.OvsdbClient;
import org.opendaylight.ovsdb.lib.OvsdbConnectionListener;
import org.slf4j.LoggerFactory;
import com.google.common.base.Optional;
+import com.google.common.base.Preconditions;
public class HwvtepConnectionManager implements OvsdbConnectionListener, AutoCloseable{
- private Map<ConnectionInfo, HwvtepConnectionInstance> clients = new ConcurrentHashMap<>();
+ private Map<ConnectionInfo, HwvtepConnectionInstance> clients =
+ new ConcurrentHashMap<ConnectionInfo,HwvtepConnectionInstance>();
private static final Logger LOG = LoggerFactory.getLogger(HwvtepConnectionManager.class);
private static final String ENTITY_TYPE = "hwvtep";
private DataBroker db;
private TransactionInvoker txInvoker;
- private Map<ConnectionInfo,InstanceIdentifier<Node>> instanceIdentifiers = new ConcurrentHashMap<>();
- private Map<Entity, HwvtepConnectionInstance> entityConnectionMap = new ConcurrentHashMap<>();
+ private Map<ConnectionInfo,InstanceIdentifier<Node>> instanceIdentifiers =
+ new ConcurrentHashMap<ConnectionInfo,InstanceIdentifier<Node>>();
+ private Map<Entity, HwvtepConnectionInstance> entityConnectionMap =
+ new ConcurrentHashMap<>();
private EntityOwnershipService entityOwnershipService;
private HwvtepDeviceEntityOwnershipListener hwvtepDeviceEntityOwnershipListener;
ConnectionInfo key = HwvtepSouthboundMapper.createConnectionInfo(client);
HwvtepConnectionInstance hwvtepConnectionInstance = getConnectionInstance(key);
if (hwvtepConnectionInstance != null) {
- //TODO: txInvoker.invoke(new HwvtepNodeRemoveCommand(hwvtepConnectionInstance, null, null));
+ //TODO: remove all the hwvtep nodes
+ txInvoker.invoke(new HwvtepGlobalRemoveCommand(hwvtepConnectionInstance, null, null));
removeConnectionInstance(key);
// Unregister Cluster Ownership for ConnectionInfo
putInstanceIdentifier(hwvtepGlobal.getConnectionInfo(), iid.firstIdentifierOf(Node.class));
HwvtepConnectionInstance hwvtepConnectionInstance = connectedButCallBacksNotRegistered(client);
hwvtepConnectionInstance.setHwvtepGlobalAugmentation(hwvtepGlobal);
+ hwvtepConnectionInstance.setInstanceIdentifier(iid.firstIdentifierOf(Node.class));
// Register Cluster Ownership for ConnectionInfo
registerEntityForOwnership(hwvtepConnectionInstance);
return hwvtepConnectionInstance;
}
- /* TODO:
- public OvsdbClient connect(InstanceIdentifier<Node> iid, OvsdbNodeAugmentation ovsdbNode)
- throws UnknownHostException {
- }
-
- public void disconnect(OvsdbNodeAugmentation ovsdbNode) throws UnknownHostException {
- OvsdbConnectionInstance client = getConnectionInstance(ovsdbNode.getConnectionInfo());
-
- }
-
- */
-
private void putConnectionInstance(ConnectionInfo key,HwvtepConnectionInstance instance) {
ConnectionInfo connectionInfo = HwvtepSouthboundMapper.suppressLocalIpPort(key);
clients.put(connectionInfo, instance);
ConnectionInfo connectionInfo = HwvtepSouthboundMapper.suppressLocalIpPort(key);
return clients.get(connectionInfo);
}
+ public HwvtepConnectionInstance getConnectionInstance(Node node) {
+ Preconditions.checkNotNull(node);
+ HwvtepGlobalAugmentation hwvtepGlobal = node.getAugmentation(HwvtepGlobalAugmentation.class);
+ if (hwvtepGlobal != null) {
+ return getConnectionInstance(hwvtepGlobal.getConnectionInfo());
+ } //TODO: We could get it from Managers also.
+ else {
+ LOG.warn("This is not a node that gives any hint how to find its OVSDB Manager: {}",node);
+ return null;
+ }
+ }
private void removeConnectionInstance(ConnectionInfo key) {
ConnectionInfo connectionInfo = HwvtepSouthboundMapper.suppressLocalIpPort(key);
public InstanceIdentifier<Node> getInstanceIdentifier(ConnectionInfo key) {
ConnectionInfo connectionInfo = HwvtepSouthboundMapper.suppressLocalIpPort(key);
- return instanceIdentifiers.get(connectionInfo);
+ InstanceIdentifier<Node> iid = instanceIdentifiers.get(connectionInfo);
+ return iid;
}
private void removeInstanceIdentifier(ConnectionInfo key) {
if (dbSchema != null) {
GenericTableSchema hwvtepSchema = TyperUtils.getTableSchema(dbSchema, Global.class);
- List<String> hwvtepTableColumn = new ArrayList<>();
+ List<String> hwvtepTableColumn = new ArrayList<String>();
hwvtepTableColumn.addAll(hwvtepSchema.getColumns());
Select<GenericTableSchema> selectOperation = op.select(hwvtepSchema);
- selectOperation.setColumns(hwvtepTableColumn);
+ selectOperation.setColumns(hwvtepTableColumn);;
- List<Operation> operations = new ArrayList<>();
+ ArrayList<Operation> operations = new ArrayList<Operation>();
operations.add(selectOperation);
operations.add(op.comment("Fetching hardware_vtep table rows"));
+ List<OperationResult> results = null;
try {
- List<OperationResult> results = connectionInstance.transact(dbSchema, operations).get();
+ results = connectionInstance.transact(dbSchema, operations).get();
if (results != null ) {
OperationResult selectResult = results.get(0);
globalRow = TyperUtils.getTypedRowWrapper(
//TODO: Is Global the right one?
Global hwvtepGlobalRow = getHwvtepGlobalTableEntry(hwvtepConnectionInstance);
iid = HwvtepSouthboundMapper.getInstanceIdentifier(hwvtepGlobalRow);
+ /* Let's set the iid now */
+ hwvtepConnectionInstance.setInstanceIdentifier(iid);
LOG.info("InstanceIdentifier {} generated for device "
+ "connection {}",iid, hwvtepConnectionInstance.getConnectionInfo());
}
private void cleanEntityOperationalData(Entity entity) {
- //TODO: remove entity from Operational DataStore
- LOG.error("cleanEntityOperationalData(): Code incomplete");
+ InstanceIdentifier<Node> nodeIid = (InstanceIdentifier<Node>) HwvtepSouthboundUtil
+ .getInstanceIdentifierCodec().bindingDeserializer(entity.getId());
+
+ final ReadWriteTransaction transaction = db.newReadWriteTransaction();
+ Optional<Node> node = HwvtepSouthboundUtil.readNode(transaction, nodeIid);
+ if (node.isPresent()) {
+ HwvtepSouthboundUtil.deleteNode(transaction, nodeIid);
+ }
}
private HwvtepConnectionInstance getConnectionInstanceFromEntity(Entity entity) {
import java.net.UnknownHostException;
import java.util.Collection;
-
+import java.util.HashMap;
+import java.util.Map;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.controller.md.sal.binding.api.DataObjectModification;
import org.opendaylight.controller.md.sal.binding.api.DataObjectModification.ModificationType;
private void registerListener(final DataBroker db) {
final DataTreeIdentifier<Node> treeId =
- new DataTreeIdentifier<>(LogicalDatastoreType.CONFIGURATION, getWildcardPath());
+ new DataTreeIdentifier<Node>(LogicalDatastoreType.CONFIGURATION, getWildcardPath());
try {
LOG.trace("Registering on path: {}", treeId);
registration = db.registerDataTreeChangeListener(treeId, HwvtepDataChangeListener.this);
* Update data for each connection
* Requires Command patterns. TBD.
*/
-
+ connectionInstancesFromChanges(changes);
+ /*for (Entry<InstanceIdentifier<Node>, HwvtepConnectionInstance> connectionInstanceEntry :
+ connectionInstancesFromChanges(changes).entrySet()) {
+
+ }*/
}
private void disconnect(Collection<DataTreeModification<Node>> changes) {
}
private InstanceIdentifier<Node> getWildcardPath() {
- return InstanceIdentifier
+ InstanceIdentifier<Node> path = InstanceIdentifier
.create(NetworkTopology.class)
.child(Topology.class, new TopologyKey(HwvtepSouthboundConstants.HWVTEP_TOPOLOGY_ID))
.child(Node.class);
+ return path;
+ }
+
+ public Map<InstanceIdentifier<Node>, HwvtepConnectionInstance> connectionInstancesFromChanges(
+ Collection<DataTreeModification<Node>> changes) {
+ Map<InstanceIdentifier<Node>, HwvtepConnectionInstance> result =
+ new HashMap<InstanceIdentifier<Node>, HwvtepConnectionInstance>();
+ for (DataTreeModification<Node> change : changes) {
+ final InstanceIdentifier<Node> key = change.getRootPath().getRootIdentifier();
+ final DataObjectModification<Node> mod = change.getRootNode();
+ Node created = getCreated(mod);
+ Node updated = getUpdated(mod);
+ Node original = getOriginal(mod);
+ Node deleted = getRemoved(mod);
+
+ if((original != null) && (deleted == null)) {
+ result.put(key, getConnectionInstance(original));
+ }
+ if(created != null) {
+ result.put(key, getConnectionInstance(created));
+ } else if(updated != null) {
+ result.put(key, getConnectionInstance(updated));
+ }
+ }
+ LOG.trace("Connection Instance Map: {}", result);
+ return result;
}
+
+ private HwvtepConnectionInstance getConnectionInstance(Node node) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+
}
import org.opendaylight.ovsdb.lib.OvsdbClient;
import org.opendaylight.ovsdb.schema.hardwarevtep.Global;
+import org.opendaylight.ovsdb.schema.hardwarevtep.PhysicalSwitch;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Address;
}
public static InstanceIdentifier<Node> createInstanceIdentifier(NodeId nodeId) {
- return InstanceIdentifier
+ InstanceIdentifier<Node> nodePath = InstanceIdentifier
.create(NetworkTopology.class)
.child(Topology.class, new TopologyKey(HwvtepSouthboundConstants.HWVTEP_TOPOLOGY_ID))
.child(Node.class,new NodeKey(nodeId));
+ return nodePath;
}
public static InstanceIdentifier<Node> createInstanceIdentifier (OvsdbClient client) {
public static InstanceIdentifier<Node> getInstanceIdentifier(Global global) {
InstanceIdentifier<Node> iid = null;
- if (global.getManagersColumn() != null
- && global.getManagersColumn().getData() != null) {
- String iidString = global.getManagersColumn().getData().iterator().next().toString();
- iid = (InstanceIdentifier<Node>) HwvtepSouthboundUtil.deserializeInstanceIdentifier(iidString);
- } else {
- String nodeString = HwvtepSouthboundConstants.HWVTEP_URI_PREFIX + "://" +
- HwvtepSouthboundConstants.UUID + "/" + global.getUuid().toString();
+ String nodeString = HwvtepSouthboundConstants.HWVTEP_URI_PREFIX + "://" +
+ HwvtepSouthboundConstants.UUID + "/" + global.getUuid().toString();
NodeId nodeId = new NodeId(new Uri(nodeString));
NodeKey nodeKey = new NodeKey(nodeId);
TopologyKey topoKey = new TopologyKey(HwvtepSouthboundConstants.HWVTEP_TOPOLOGY_ID);
.child(Topology.class, topoKey)
.child(Node.class,nodeKey)
.build();
- }
+ return iid;
+ }
+
+ public static InstanceIdentifier<Node> createInstanceIdentifier(HwvtepConnectionInstance client,
+ PhysicalSwitch pSwitch) {
+ InstanceIdentifier<Node> iid = null;
+ String nodeString = client.getNodeKey().getNodeId().getValue() + "/physicalswitch/" + pSwitch.getName();
+ NodeId nodeId = new NodeId(new Uri(nodeString));
+ NodeKey nodeKey = new NodeKey(nodeId);
+ iid =InstanceIdentifier.builder(NetworkTopology.class)
+ .child(Topology.class, new TopologyKey(HwvtepSouthboundConstants.HWVTEP_TOPOLOGY_ID))
+ .child(Node.class, nodeKey).build();
return iid;
}
}
/*
- * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
+ * Copyright (c) 2015 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
+
package org.opendaylight.ovsdb.hwvtepsouthbound;
+import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
+import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.opendaylight.yangtools.yang.data.impl.codec.DeserializationException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import com.google.common.base.Optional;
+import com.google.common.util.concurrent.CheckedFuture;
+
public class HwvtepSouthboundUtil {
private static final Logger LOG = LoggerFactory.getLogger(HwvtepSouthboundUtil.class);
return result;
}
+ public static <D extends org.opendaylight.yangtools.yang.binding.DataObject> Optional<D> readNode(
+ ReadWriteTransaction transaction, final InstanceIdentifier<D> connectionIid) {
+ Optional<D> node = Optional.absent();
+ try {
+ node = transaction.read(LogicalDatastoreType.OPERATIONAL, connectionIid).checkedGet();
+ } catch (final ReadFailedException e) {
+ LOG.warn("Read Operational/DS for Node failed! {}", connectionIid, e);
+ }
+ return node;
+ }
+ public static <D extends org.opendaylight.yangtools.yang.binding.DataObject> boolean deleteNode(
+ ReadWriteTransaction transaction, final InstanceIdentifier<D> connectionIid) {
+ boolean result = false;
+ transaction.delete(LogicalDatastoreType.OPERATIONAL, connectionIid);
+ CheckedFuture<Void, TransactionCommitFailedException> future = transaction.submit();
+ try {
+ future.checkedGet();
+ result = true;
+ } catch (TransactionCommitFailedException e) {
+ LOG.warn("Failed to delete {} ", connectionIid, e);
+ }
+ return result;
+ }
}
--- /dev/null
+/*
+ * Copyright (c) 2015 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.ovsdb.hwvtepsouthbound.transactions.md;
+
+import org.opendaylight.ovsdb.hwvtepsouthbound.HwvtepConnectionInstance;
+import org.opendaylight.ovsdb.lib.message.TableUpdates;
+import org.opendaylight.ovsdb.lib.schema.DatabaseSchema;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.ConnectionInfo;
+
+public abstract class AbstractTransactionCommand implements TransactionCommand{
+
+ private TableUpdates updates;
+ private DatabaseSchema dbSchema;
+ private HwvtepConnectionInstance key;
+
+ public TableUpdates getUpdates() {
+ return updates;
+ }
+
+ public DatabaseSchema getDbSchema() {
+ return dbSchema;
+ }
+
+ public ConnectionInfo getConnectionInfo() {
+ return key.getMDConnectionInfo();
+ }
+
+ public HwvtepConnectionInstance getOvsdbConnectionInstance() {
+ return key;
+ }
+
+ protected AbstractTransactionCommand() {
+ // NO OP
+ }
+
+ public AbstractTransactionCommand(HwvtepConnectionInstance key,TableUpdates updates, DatabaseSchema dbSchema) {
+ this.updates = updates;
+ this.dbSchema = dbSchema;
+ this.key = key;
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2015 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.ovsdb.hwvtepsouthbound.transactions.md;
+
+import java.util.Map;
+import java.util.Map.Entry;
+
+import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.ovsdb.hwvtepsouthbound.HwvtepConnectionInstance;
+import org.opendaylight.ovsdb.hwvtepsouthbound.HwvtepSouthboundMapper;
+import org.opendaylight.ovsdb.lib.message.TableUpdates;
+import org.opendaylight.ovsdb.lib.notation.UUID;
+import org.opendaylight.ovsdb.lib.schema.DatabaseSchema;
+import org.opendaylight.ovsdb.lib.schema.typed.TyperUtils;
+import org.opendaylight.ovsdb.schema.hardwarevtep.Global;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepGlobalAugmentation;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepGlobalAugmentationBuilder;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeBuilder;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeKey;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class GlobalUpdateCommand extends AbstractTransactionCommand {
+
+ private static final Logger LOG = LoggerFactory.getLogger(GlobalUpdateCommand.class);
+ private Map<UUID, Global> updatedHwvtepRows =
+ TyperUtils.extractRowsUpdated(Global.class, getUpdates(),getDbSchema());
+ private Map<UUID, Global> oldHwvtepRows =
+ TyperUtils.extractRowsUpdated(Global.class, getUpdates(),getDbSchema());
+
+ public GlobalUpdateCommand(HwvtepConnectionInstance key, TableUpdates updates,
+ DatabaseSchema dbSchema) {
+ super(key, updates, dbSchema);
+ }
+
+ @Override
+ public void execute(ReadWriteTransaction transaction) {
+ for (Entry<UUID, Global> entry : updatedHwvtepRows.entrySet()) {
+ Global hwvtepGlobal = entry.getValue();
+ Global oldEntry = oldHwvtepRows.get(entry.getKey());
+ final InstanceIdentifier<Node> nodePath = getInstanceIdentifier(hwvtepGlobal);
+ LOG.trace("Processing hardware_vtep update for nodePath: {}", nodePath);
+
+ HwvtepGlobalAugmentationBuilder hwvtepGlobalBuilder = new HwvtepGlobalAugmentationBuilder();
+ hwvtepGlobalBuilder.setConnectionInfo(getConnectionInfo());
+ NodeBuilder nodeBuilder = new NodeBuilder();
+ nodeBuilder.setNodeId(getNodeId(hwvtepGlobal));
+ nodeBuilder.addAugmentation(HwvtepGlobalAugmentation.class, hwvtepGlobalBuilder.build());
+ transaction.merge(LogicalDatastoreType.OPERATIONAL, nodePath, nodeBuilder.build());
+ }
+ }
+
+ private InstanceIdentifier<Node> getInstanceIdentifier(Global hwvtep) {
+ InstanceIdentifier<Node> iid = getOvsdbConnectionInstance().getInstanceIdentifier();
+ if(iid == null) {
+ LOG.warn("InstanceIdentifier was null when it shouldn't be");
+ /* This can be case for switch initiated connection */
+ iid = HwvtepSouthboundMapper.getInstanceIdentifier(hwvtep);
+ getOvsdbConnectionInstance().setInstanceIdentifier(iid);
+ }
+ return getOvsdbConnectionInstance().getInstanceIdentifier();
+ }
+
+ private NodeId getNodeId(Global hwvtep) {
+ NodeKey nodeKey = getInstanceIdentifier(hwvtep).firstKeyOf(Node.class, NodeKey.class);
+ return nodeKey.getNodeId();
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2015 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.ovsdb.hwvtepsouthbound.transactions.md;
+
+import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
+import org.opendaylight.ovsdb.hwvtepsouthbound.HwvtepConnectionInstance;
+import org.opendaylight.ovsdb.lib.message.TableUpdates;
+import org.opendaylight.ovsdb.lib.schema.DatabaseSchema;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepGlobalAugmentation;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.Managers;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.Switches;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.Optional;
+import com.google.common.util.concurrent.CheckedFuture;
+
+public class HwvtepGlobalRemoveCommand extends AbstractTransactionCommand {
+ private static final Logger LOG = LoggerFactory.getLogger(HwvtepGlobalRemoveCommand.class);
+ private static final long ONE_CONNECTED_MANAGER = 1;
+ private static final long ONE_ACTIVE_CONNECTION_IN_PASSIVE_MODE = 1;
+
+ public HwvtepGlobalRemoveCommand(HwvtepConnectionInstance key,TableUpdates updates,DatabaseSchema dbSchema) {
+ super(key,updates,dbSchema);
+ }
+
+ @Override
+ public void execute(ReadWriteTransaction transaction) {
+ CheckedFuture<Optional<Node>, ReadFailedException> hwvtepGlobalFuture = transaction.read(
+ LogicalDatastoreType.OPERATIONAL, getOvsdbConnectionInstance().getInstanceIdentifier());
+ Optional<Node> hwvtepGlobalOptional;
+ try {
+ hwvtepGlobalOptional = hwvtepGlobalFuture.get();
+ if (hwvtepGlobalOptional.isPresent()) {
+ Node hwvtepNode = hwvtepGlobalOptional.get();
+ HwvtepGlobalAugmentation hgAugmentation = hwvtepNode.getAugmentation(HwvtepGlobalAugmentation.class);
+ if (checkIfOnlyConnectedManager(hgAugmentation)) {
+ if (hgAugmentation != null) {
+ if (hgAugmentation.getSwitches() != null) {
+ for (Switches hwSwitch : hgAugmentation.getSwitches()) {
+ LOG.debug("Deleting hwvtep switch {}", hwSwitch);
+ transaction.delete(
+ LogicalDatastoreType.OPERATIONAL, hwSwitch.getSwitchRef().getValue());
+ }
+ } else {
+ LOG.debug("{} had no switches", hwvtepNode.getNodeId().getValue());
+ }
+ } else {
+ LOG.warn("{} had no HwvtepGlobalAugmentation", hwvtepNode.getNodeId().getValue());
+ }
+ transaction.delete(LogicalDatastoreType.OPERATIONAL,
+ getOvsdbConnectionInstance().getInstanceIdentifier());
+ } else {
+ LOG.debug("Other southbound plugin instances in cluster are connected to the device,"
+ + " not deleting OvsdbNode form data store.");
+ }
+ }
+ } catch (Exception e) {
+ LOG.warn("Failure to delete ovsdbNode {}",e);
+ }
+ }
+
+ private boolean checkIfOnlyConnectedManager(HwvtepGlobalAugmentation hgAugmentation) {
+ Managers onlyConnectedManager = null;
+ if (hgAugmentation != null) {
+ int connectedManager = 0;
+ if (hgAugmentation.getManagers() != null) {
+ for (Managers manager : hgAugmentation.getManagers()) {
+ if (manager.isIsConnected()) {
+ connectedManager++;
+ if (connectedManager > ONE_CONNECTED_MANAGER) {
+ return false;
+ }
+ onlyConnectedManager = manager;
+ }
+ }
+ }
+ if (connectedManager == 0) {
+ return true;
+ }
+ }
+ /*When switch is listening in passive mode, this number represent number of active connection to the device
+ This is to handle the controller initiated connection scenario, where all the controller will connect, but
+ switch will have only one manager.
+ */
+ /* CLUSTERING-TODO-ITEM: For hwvtep we don't have getNumberOfConnections()
+ * FIXME: Add it to yang?
+ if (onlyConnectedManager.getNumberOfConnections() > ONE_ACTIVE_CONNECTION_IN_PASSIVE_MODE) {
+ return false;
+ }*/
+ return true;
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2015 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.ovsdb.hwvtepsouthbound.transactions.md;
+
+import java.util.Map;
+import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
+import org.opendaylight.ovsdb.hwvtepsouthbound.HwvtepConnectionInstance;
+import org.opendaylight.ovsdb.lib.message.TableUpdates;
+import org.opendaylight.ovsdb.lib.notation.UUID;
+import org.opendaylight.ovsdb.lib.schema.DatabaseSchema;
+import org.opendaylight.ovsdb.lib.schema.typed.TyperUtils;
+import org.opendaylight.ovsdb.schema.hardwarevtep.Manager;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class HwvtepManagerUpdateCommand extends AbstractTransactionCommand {
+
+ private static final Logger LOG = LoggerFactory.getLogger(HwvtepManagerUpdateCommand.class);
+ private Map<UUID, Manager> updatedMgrRows;
+ private Map<UUID, Manager> oldMgrRows;
+
+ public HwvtepManagerUpdateCommand(HwvtepConnectionInstance key, TableUpdates updates,
+ DatabaseSchema dbSchema) {
+ super(key, updates, dbSchema);
+ updatedMgrRows = TyperUtils.extractRowsUpdated(Manager.class, getUpdates(),getDbSchema());
+ oldMgrRows = TyperUtils.extractRowsOld(Manager.class, getUpdates(),getDbSchema());
+ }
+
+ @Override
+ public void execute(ReadWriteTransaction transaction) {
+ // TODO Auto-generated method stub
+ }
+
+}
/*
- * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
+ * Copyright (c) 2015 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
public class HwvtepOperationalCommandAggregator implements TransactionCommand {
- private List<TransactionCommand> commands = new ArrayList<>();
+ private List<TransactionCommand> commands = new ArrayList<TransactionCommand>();
public HwvtepOperationalCommandAggregator(HwvtepConnectionInstance key,TableUpdates updates,
DatabaseSchema dbSchema) {
//TODO: Add commands in here
+ commands.add(new GlobalUpdateCommand(key, updates, dbSchema));
+ commands.add(new PhysicalSwitchUpdateCommand(key, updates, dbSchema));
+ commands.add(new PhysicalSwitchRemoveCommand(key, updates, dbSchema));
+ commands.add(new HwvtepManagerUpdateCommand(key, updates, dbSchema));
+ commands.add(new LogicalSwitchUpdateCommand(key, updates, dbSchema));
+ commands.add(new PhysicalPortUpdateCommand(key, updates, dbSchema));
+ commands.add(new HwvtepTunnelUpdateCommand(key, updates, dbSchema));
+ commands.add(new PhysicalLocatorUpdateCommand(key, updates, dbSchema));
+ commands.add(new PhysicalLocatorSetUpdateCommand(key, updates, dbSchema));
+ commands.add(new UcastMacsLocalUpdateCommand(key, updates, dbSchema));
+ commands.add(new UcastMacsRemoteUpdateCommand(key, updates, dbSchema));
+ commands.add(new McastMacsLocalUpdateCommand(key, updates, dbSchema));
+ commands.add(new McastMacsRemoteUpdateCommand(key, updates, dbSchema));
}
@Override
--- /dev/null
+/*
+ * Copyright (c) 2015 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.ovsdb.hwvtepsouthbound.transactions.md;
+
+import java.util.Map;
+
+import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
+import org.opendaylight.ovsdb.hwvtepsouthbound.HwvtepConnectionInstance;
+import org.opendaylight.ovsdb.lib.message.TableUpdates;
+import org.opendaylight.ovsdb.lib.notation.UUID;
+import org.opendaylight.ovsdb.lib.schema.DatabaseSchema;
+import org.opendaylight.ovsdb.lib.schema.typed.TyperUtils;
+import org.opendaylight.ovsdb.schema.hardwarevtep.Tunnel;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class HwvtepTunnelUpdateCommand extends AbstractTransactionCommand {
+
+ private static final Logger LOG = LoggerFactory.getLogger(HwvtepTunnelUpdateCommand.class);
+ private Map<UUID, Tunnel> updatedTunnelRows;
+ private Map<UUID, Tunnel> oldTunnelRows;
+
+ public HwvtepTunnelUpdateCommand(HwvtepConnectionInstance key, TableUpdates updates,
+ DatabaseSchema dbSchema) {
+ super(key, updates, dbSchema);
+ updatedTunnelRows = TyperUtils.extractRowsUpdated(Tunnel.class, getUpdates(),getDbSchema());
+ oldTunnelRows = TyperUtils.extractRowsOld(Tunnel.class, getUpdates(),getDbSchema());
+ }
+
+ @Override
+ public void execute(ReadWriteTransaction transaction) {
+ // TODO Auto-generated method stub
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2015 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.ovsdb.hwvtepsouthbound.transactions.md;
+
+import java.util.Map;
+
+import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
+import org.opendaylight.ovsdb.hwvtepsouthbound.HwvtepConnectionInstance;
+import org.opendaylight.ovsdb.lib.message.TableUpdates;
+import org.opendaylight.ovsdb.lib.notation.UUID;
+import org.opendaylight.ovsdb.lib.schema.DatabaseSchema;
+import org.opendaylight.ovsdb.lib.schema.typed.TyperUtils;
+import org.opendaylight.ovsdb.schema.hardwarevtep.LogicalSwitch;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class LogicalSwitchUpdateCommand extends AbstractTransactionCommand {
+
+ private static final Logger LOG = LoggerFactory.getLogger(LogicalSwitchUpdateCommand.class);
+ private Map<UUID, LogicalSwitch> updatedLSRows;
+ private Map<UUID, LogicalSwitch> oldLSRows;
+
+ public LogicalSwitchUpdateCommand(HwvtepConnectionInstance key, TableUpdates updates,
+ DatabaseSchema dbSchema) {
+ super(key, updates, dbSchema);
+ updatedLSRows = TyperUtils.extractRowsUpdated(LogicalSwitch.class, getUpdates(),getDbSchema());
+ oldLSRows = TyperUtils.extractRowsOld(LogicalSwitch.class, getUpdates(),getDbSchema());
+ }
+
+ @Override
+ public void execute(ReadWriteTransaction transaction) {
+ // TODO Auto-generated method stub
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2015 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.ovsdb.hwvtepsouthbound.transactions.md;
+
+import java.util.Map;
+
+import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
+import org.opendaylight.ovsdb.hwvtepsouthbound.HwvtepConnectionInstance;
+import org.opendaylight.ovsdb.lib.message.TableUpdates;
+import org.opendaylight.ovsdb.lib.notation.UUID;
+import org.opendaylight.ovsdb.lib.schema.DatabaseSchema;
+import org.opendaylight.ovsdb.lib.schema.typed.TyperUtils;
+import org.opendaylight.ovsdb.schema.hardwarevtep.McastMacsLocal;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class McastMacsLocalUpdateCommand extends AbstractTransactionCommand {
+
+ private static final Logger LOG = LoggerFactory.getLogger(McastMacsLocalUpdateCommand.class);
+ private Map<UUID, McastMacsLocal> updatedMMacsLocalRows;
+ private Map<UUID, McastMacsLocal> oldMMacsLocalRows;
+
+ public McastMacsLocalUpdateCommand(HwvtepConnectionInstance key, TableUpdates updates,
+ DatabaseSchema dbSchema) {
+ super(key, updates, dbSchema);
+ updatedMMacsLocalRows = TyperUtils.extractRowsUpdated(McastMacsLocal.class, getUpdates(),getDbSchema());
+ oldMMacsLocalRows = TyperUtils.extractRowsOld(McastMacsLocal.class, getUpdates(),getDbSchema());
+ }
+
+ @Override
+ public void execute(ReadWriteTransaction transaction) {
+ // TODO Auto-generated method stub
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2015 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.ovsdb.hwvtepsouthbound.transactions.md;
+
+import java.util.Map;
+
+import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
+import org.opendaylight.ovsdb.hwvtepsouthbound.HwvtepConnectionInstance;
+import org.opendaylight.ovsdb.lib.message.TableUpdates;
+import org.opendaylight.ovsdb.lib.notation.UUID;
+import org.opendaylight.ovsdb.lib.schema.DatabaseSchema;
+import org.opendaylight.ovsdb.lib.schema.typed.TyperUtils;
+import org.opendaylight.ovsdb.schema.hardwarevtep.McastMacsRemote;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class McastMacsRemoteUpdateCommand extends AbstractTransactionCommand {
+
+ private static final Logger LOG = LoggerFactory.getLogger(McastMacsRemoteUpdateCommand.class);
+ private Map<UUID, McastMacsRemote> updatedMMacsRemoteRows;
+ private Map<UUID, McastMacsRemote> oldMMacsRemoteRows;
+
+ public McastMacsRemoteUpdateCommand(HwvtepConnectionInstance key, TableUpdates updates,
+ DatabaseSchema dbSchema) {
+ super(key, updates, dbSchema);
+ updatedMMacsRemoteRows = TyperUtils.extractRowsUpdated(McastMacsRemote.class, getUpdates(),getDbSchema());
+ oldMMacsRemoteRows = TyperUtils.extractRowsOld(McastMacsRemote.class, getUpdates(),getDbSchema());
+ }
+
+ @Override
+ public void execute(ReadWriteTransaction transaction) {
+ // TODO Auto-generated method stub
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2015 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.ovsdb.hwvtepsouthbound.transactions.md;
+
+import java.util.Map;
+
+import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
+import org.opendaylight.ovsdb.hwvtepsouthbound.HwvtepConnectionInstance;
+import org.opendaylight.ovsdb.lib.message.TableUpdates;
+import org.opendaylight.ovsdb.lib.notation.UUID;
+import org.opendaylight.ovsdb.lib.schema.DatabaseSchema;
+import org.opendaylight.ovsdb.lib.schema.typed.TyperUtils;
+import org.opendaylight.ovsdb.schema.hardwarevtep.PhysicalLocatorSet;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class PhysicalLocatorSetUpdateCommand extends AbstractTransactionCommand {
+
+ private static final Logger LOG = LoggerFactory.getLogger(PhysicalLocatorSetUpdateCommand.class);
+ private Map<UUID, PhysicalLocatorSet> updatedPLocSetRows;
+ private Map<UUID, PhysicalLocatorSet> oldPLocSetRows;
+
+ public PhysicalLocatorSetUpdateCommand(HwvtepConnectionInstance key, TableUpdates updates,
+ DatabaseSchema dbSchema) {
+ super(key, updates, dbSchema);
+ updatedPLocSetRows = TyperUtils.extractRowsUpdated(PhysicalLocatorSet.class, getUpdates(),getDbSchema());
+ oldPLocSetRows = TyperUtils.extractRowsOld(PhysicalLocatorSet.class, getUpdates(),getDbSchema());
+ }
+
+ @Override
+ public void execute(ReadWriteTransaction transaction) {
+ // TODO Auto-generated method stub
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2015 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.ovsdb.hwvtepsouthbound.transactions.md;
+
+import java.util.Map;
+
+import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
+import org.opendaylight.ovsdb.hwvtepsouthbound.HwvtepConnectionInstance;
+import org.opendaylight.ovsdb.lib.message.TableUpdates;
+import org.opendaylight.ovsdb.lib.notation.UUID;
+import org.opendaylight.ovsdb.lib.schema.DatabaseSchema;
+import org.opendaylight.ovsdb.lib.schema.typed.TyperUtils;
+import org.opendaylight.ovsdb.schema.hardwarevtep.PhysicalLocator;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class PhysicalLocatorUpdateCommand extends AbstractTransactionCommand {
+
+ private static final Logger LOG = LoggerFactory.getLogger(PhysicalLocatorUpdateCommand.class);
+ private Map<UUID, PhysicalLocator> updatedPLocRows;
+ private Map<UUID, PhysicalLocator> oldPLocRows;
+
+ public PhysicalLocatorUpdateCommand(HwvtepConnectionInstance key, TableUpdates updates,
+ DatabaseSchema dbSchema) {
+ super(key, updates, dbSchema);
+ updatedPLocRows = TyperUtils.extractRowsUpdated(PhysicalLocator.class, getUpdates(),getDbSchema());
+ updatedPLocRows = TyperUtils.extractRowsOld(PhysicalLocator.class, getUpdates(),getDbSchema());
+ }
+
+ @Override
+ public void execute(ReadWriteTransaction transaction) {
+ // TODO Auto-generated method stub
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2015 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.ovsdb.hwvtepsouthbound.transactions.md;
+
+import java.util.Map;
+
+import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
+import org.opendaylight.ovsdb.hwvtepsouthbound.HwvtepConnectionInstance;
+import org.opendaylight.ovsdb.lib.message.TableUpdates;
+import org.opendaylight.ovsdb.lib.notation.UUID;
+import org.opendaylight.ovsdb.lib.schema.DatabaseSchema;
+import org.opendaylight.ovsdb.lib.schema.typed.TyperUtils;
+import org.opendaylight.ovsdb.schema.hardwarevtep.PhysicalPort;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class PhysicalPortUpdateCommand extends AbstractTransactionCommand {
+
+ private static final Logger LOG = LoggerFactory.getLogger(PhysicalPortUpdateCommand.class);
+ private Map<UUID, PhysicalPort> updatedPPRows;
+ private Map<UUID, PhysicalPort> oldPPRows;
+
+ public PhysicalPortUpdateCommand(HwvtepConnectionInstance key, TableUpdates updates,
+ DatabaseSchema dbSchema) {
+ super(key, updates, dbSchema);
+ updatedPPRows = TyperUtils.extractRowsUpdated(PhysicalPort.class, getUpdates(),getDbSchema());
+ oldPPRows = TyperUtils.extractRowsOld(PhysicalPort.class, getUpdates(),getDbSchema());
+ }
+
+ @Override
+ public void execute(ReadWriteTransaction transaction) {
+ // TODO Auto-generated method stub
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2015 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.ovsdb.hwvtepsouthbound.transactions.md;
+
+import java.util.Collection;
+import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.ovsdb.hwvtepsouthbound.HwvtepConnectionInstance;
+import org.opendaylight.ovsdb.hwvtepsouthbound.HwvtepSouthboundMapper;
+import org.opendaylight.ovsdb.lib.message.TableUpdates;
+import org.opendaylight.ovsdb.lib.schema.DatabaseSchema;
+import org.opendaylight.ovsdb.lib.schema.typed.TyperUtils;
+import org.opendaylight.ovsdb.schema.hardwarevtep.PhysicalSwitch;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepGlobalAugmentation;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepPhysicalSwitchRef;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.Switches;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.SwitchesKey;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class PhysicalSwitchRemoveCommand extends AbstractTransactionCommand {
+
+ private static final Logger LOG = LoggerFactory.getLogger(PhysicalSwitchRemoveCommand.class);
+
+ public PhysicalSwitchRemoveCommand(HwvtepConnectionInstance key, TableUpdates updates,
+ DatabaseSchema dbSchema) {
+ super(key, updates, dbSchema);
+ }
+
+ @Override
+ public void execute(ReadWriteTransaction transaction) {
+ Collection<PhysicalSwitch> deletedPSRows = TyperUtils.extractRowsRemoved(PhysicalSwitch.class, getUpdates(),getDbSchema()).values();
+ if(deletedPSRows != null && !deletedPSRows.isEmpty()) {
+ for (PhysicalSwitch pSwitch : deletedPSRows) {
+ InstanceIdentifier<Node> nodeIid = HwvtepSouthboundMapper.createInstanceIdentifier(
+ getOvsdbConnectionInstance(), pSwitch);
+ InstanceIdentifier<Switches> switchIid = getOvsdbConnectionInstance().getInstanceIdentifier()
+ .augmentation(HwvtepGlobalAugmentation.class)
+ .child(Switches.class, new SwitchesKey(new HwvtepPhysicalSwitchRef(nodeIid)));
+ // TODO handle removal of reference to managed switch from model
+ transaction.delete(LogicalDatastoreType.OPERATIONAL, nodeIid);
+ transaction.delete(LogicalDatastoreType.OPERATIONAL, switchIid);
+ }
+ }
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2015 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.ovsdb.hwvtepsouthbound.transactions.md;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+
+import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.ovsdb.hwvtepsouthbound.HwvtepConnectionInstance;
+import org.opendaylight.ovsdb.hwvtepsouthbound.HwvtepSouthboundMapper;
+import org.opendaylight.ovsdb.hwvtepsouthbound.HwvtepSouthboundUtil;
+import org.opendaylight.ovsdb.lib.message.TableUpdates;
+import org.opendaylight.ovsdb.lib.notation.UUID;
+import org.opendaylight.ovsdb.lib.schema.DatabaseSchema;
+import org.opendaylight.ovsdb.lib.schema.typed.TyperUtils;
+import org.opendaylight.ovsdb.schema.hardwarevtep.PhysicalSwitch;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepGlobalAugmentation;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepGlobalAugmentationBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepGlobalRef;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepNodeName;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepPhysicalSwitchRef;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.PhysicalSwitchAugmentation;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.PhysicalSwitchAugmentationBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.Switches;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.SwitchesBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.physical._switch.attributes.ManagementIps;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.physical._switch.attributes.ManagementIpsBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.physical._switch.attributes.ManagementIpsKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.physical._switch.attributes.PhysicalSwitchIdBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.physical._switch.attributes.TunnelIps;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.physical._switch.attributes.TunnelIpsBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.physical._switch.attributes.TunnelIpsKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.physical._switch.attributes.Tunnels;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.physical._switch.attributes.TunnelsBuilder;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeBuilder;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeKey;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.Optional;
+
+public class PhysicalSwitchUpdateCommand extends AbstractTransactionCommand {
+
+ private static final Logger LOG = LoggerFactory.getLogger(PhysicalSwitchUpdateCommand.class);
+ private Map<UUID, PhysicalSwitch> updatedPSRows;
+ private Map<UUID, PhysicalSwitch> oldPSRows;
+
+ public PhysicalSwitchUpdateCommand(HwvtepConnectionInstance key, TableUpdates updates,
+ DatabaseSchema dbSchema) {
+ super(key, updates, dbSchema);
+ updatedPSRows = TyperUtils.extractRowsUpdated(PhysicalSwitch.class, getUpdates(),getDbSchema());
+ oldPSRows = TyperUtils.extractRowsOld(PhysicalSwitch.class, getUpdates(),getDbSchema());
+ }
+
+ @Override
+ public void execute(ReadWriteTransaction transaction) {
+ if(updatedPSRows != null && !updatedPSRows.isEmpty()) {
+ for (Entry<UUID, PhysicalSwitch> entry : updatedPSRows.entrySet()) {
+ updatePhysicalSwitch(transaction, entry.getValue());
+ }
+ }
+ }
+
+ private void updatePhysicalSwitch(ReadWriteTransaction transaction, PhysicalSwitch pSwitch) {
+ final InstanceIdentifier<Node> connectionIId = getOvsdbConnectionInstance().getInstanceIdentifier();
+ Optional<Node> connection = HwvtepSouthboundUtil.readNode(transaction, connectionIId);
+ if (connection.isPresent()) {
+ LOG.debug("Connection {} is present",connection);
+ // Update the connection node to let it know it manages this Physical Switch
+ Node connectionNode = buildConnectionNode(pSwitch);
+ transaction.merge(LogicalDatastoreType.OPERATIONAL, connectionIId, connectionNode);
+
+ // Update the Physical Switch with whatever data we are getting
+ InstanceIdentifier<Node> psIid = getInstanceIdentifier(pSwitch);
+ Node psNode = buildPhysicalSwitchNode(pSwitch);
+ transaction.merge(LogicalDatastoreType.OPERATIONAL, psIid, psNode);
+// TODO: Delete entries that are no longer needed
+ }
+ }
+
+ private Node buildPhysicalSwitchNode(PhysicalSwitch pSwitch) {
+ NodeBuilder psNodeBuilder = new NodeBuilder();
+ NodeId psNodeId = getNodeId(pSwitch);
+ psNodeBuilder.setNodeId(psNodeId);
+ PhysicalSwitchAugmentationBuilder psAugmentationBuilder = new PhysicalSwitchAugmentationBuilder();
+ setManagedBy(psAugmentationBuilder, pSwitch);
+ setPhysicalSwitchId(psAugmentationBuilder, pSwitch);
+ setManagementIps(psAugmentationBuilder, pSwitch);
+ setTunnelIps(psAugmentationBuilder, pSwitch);
+ setUcastMacsLocal(psAugmentationBuilder, pSwitch);
+ setUcastMacsRemote(psAugmentationBuilder, pSwitch);
+ setMcastMacsLocal(psAugmentationBuilder, pSwitch);
+ setMcastMacsRemote(psAugmentationBuilder, pSwitch);
+
+ psNodeBuilder.addAugmentation(PhysicalSwitchAugmentation.class, psAugmentationBuilder.build());
+
+ LOG.trace("Built with the intent to store bridge data {}",
+ psAugmentationBuilder.build());
+ return psNodeBuilder.build();
+ }
+
+ private void setManagedBy(PhysicalSwitchAugmentationBuilder psAugmentationBuilder, PhysicalSwitch pSwitch) {
+ InstanceIdentifier<Node> connectionNodePath = getOvsdbConnectionInstance().getInstanceIdentifier();
+ psAugmentationBuilder.setManagedBy(new HwvtepGlobalRef(connectionNodePath));
+ }
+
+ private void setPhysicalSwitchId(PhysicalSwitchAugmentationBuilder psAugmentationBuilder, PhysicalSwitch pSwitch) {
+ PhysicalSwitchIdBuilder psIdBuilder = new PhysicalSwitchIdBuilder();
+ if(pSwitch.getName() != null) {
+ psIdBuilder.setHwvtepNodeName(new HwvtepNodeName(pSwitch.getName()));
+ }
+
+ if(pSwitch.getDescription() != null) {
+ psIdBuilder.setHwvtepNodeDescription(pSwitch.getDescription());
+ }
+ psAugmentationBuilder.setPhysicalSwitchId(psIdBuilder.build());
+ }
+
+ private void setManagementIps(PhysicalSwitchAugmentationBuilder psAugmentationBuilder, PhysicalSwitch pSwitch) {
+ if(pSwitch.getManagementIpsColumn() != null
+ && pSwitch.getManagementIpsColumn().getData() != null
+ && !pSwitch.getManagementIpsColumn().getData().isEmpty() ) {
+ List<ManagementIps> mgmtIps = new ArrayList<>();
+ for(String mgmtIp: pSwitch.getManagementIpsColumn().getData()) {
+ IpAddress ip = new IpAddress(mgmtIp.toCharArray());
+ mgmtIps.add(new ManagementIpsBuilder()
+ .setKey(new ManagementIpsKey(ip))
+ .setManagementIpsKey(ip)
+ .build());
+ }
+ psAugmentationBuilder.setManagementIps(mgmtIps);
+ }
+ }
+
+ private void setTunnelIps(PhysicalSwitchAugmentationBuilder psAugmentationBuilder, PhysicalSwitch pSwitch) {
+ if(pSwitch.getTunnelIpsColumn() != null
+ && pSwitch.getTunnelIpsColumn().getData() != null
+ && !pSwitch.getTunnelIpsColumn().getData().isEmpty()) {
+ List<TunnelIps> tunnelIps = new ArrayList<>();
+ for(String tunnelIp: pSwitch.getTunnelIpsColumn().getData()) {
+ IpAddress ip = new IpAddress(tunnelIp.toCharArray());
+ tunnelIps.add(new TunnelIpsBuilder()
+ .setKey(new TunnelIpsKey(ip))
+ .setTunnelIpsKey(ip)
+ .build());
+ }
+ psAugmentationBuilder.setTunnelIps(tunnelIps);
+ }
+ }
+
+ private void setUcastMacsLocal(PhysicalSwitchAugmentationBuilder psAugmentationBuilder, PhysicalSwitch pSwitch) {
+ // TODO Auto-generated method stub
+
+ }
+
+ private void setUcastMacsRemote(PhysicalSwitchAugmentationBuilder psAugmentationBuilder, PhysicalSwitch pSwitch) {
+ // TODO Auto-generated method stub
+
+ }
+
+ private void setMcastMacsLocal(PhysicalSwitchAugmentationBuilder psAugmentationBuilder, PhysicalSwitch pSwitch) {
+ // TODO Auto-generated method stub
+
+ }
+
+ private void setMcastMacsRemote(PhysicalSwitchAugmentationBuilder psAugmentationBuilder, PhysicalSwitch pSwitch) {
+ // TODO Auto-generated method stub
+
+ }
+
+ private Node buildConnectionNode(PhysicalSwitch pSwitch) {
+ //Update node with PhysicalSwitch reference
+ NodeBuilder connectionNode = new NodeBuilder();
+ connectionNode.setNodeId(getOvsdbConnectionInstance().getNodeId());
+
+ HwvtepGlobalAugmentationBuilder hgAugmentationBuilder = new HwvtepGlobalAugmentationBuilder();
+ List<Switches> switches = new ArrayList<>();
+ InstanceIdentifier<Node> switchIid = HwvtepSouthboundMapper.createInstanceIdentifier(getOvsdbConnectionInstance(),
+ pSwitch);
+ hgAugmentationBuilder.setSwitches(switches);
+ Switches physicalSwitch = new SwitchesBuilder().setSwitchRef(
+ new HwvtepPhysicalSwitchRef(switchIid)).build();
+ switches.add(physicalSwitch);
+
+ connectionNode.addAugmentation(HwvtepGlobalAugmentation.class, hgAugmentationBuilder.build());
+
+ LOG.debug("Update node with physicalswitch ref {}",
+ hgAugmentationBuilder.getSwitches().iterator().next());
+ return connectionNode.build();
+ }
+
+ private InstanceIdentifier<Node> getInstanceIdentifier(PhysicalSwitch pSwitch) {
+ return HwvtepSouthboundMapper.createInstanceIdentifier(getOvsdbConnectionInstance(),
+ pSwitch);
+ }
+
+ private NodeId getNodeId(PhysicalSwitch pSwitch) {
+ NodeKey nodeKey = getInstanceIdentifier(pSwitch).firstKeyOf(Node.class, NodeKey.class);
+ return nodeKey.getNodeId();
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2015 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.ovsdb.hwvtepsouthbound.transactions.md;
+
+import java.util.Map;
+
+import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
+import org.opendaylight.ovsdb.hwvtepsouthbound.HwvtepConnectionInstance;
+import org.opendaylight.ovsdb.lib.message.TableUpdates;
+import org.opendaylight.ovsdb.lib.notation.UUID;
+import org.opendaylight.ovsdb.lib.schema.DatabaseSchema;
+import org.opendaylight.ovsdb.lib.schema.typed.TyperUtils;
+import org.opendaylight.ovsdb.schema.hardwarevtep.UcastMacsLocal;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class UcastMacsLocalUpdateCommand extends AbstractTransactionCommand {
+
+ private static final Logger LOG = LoggerFactory.getLogger(UcastMacsLocalUpdateCommand.class);
+ private Map<UUID, UcastMacsLocal> updatedUMacsLocalRows;
+ private Map<UUID, UcastMacsLocal> oldUMacsLocalRows;
+
+ public UcastMacsLocalUpdateCommand(HwvtepConnectionInstance key, TableUpdates updates,
+ DatabaseSchema dbSchema) {
+ super(key, updates, dbSchema);
+ updatedUMacsLocalRows = TyperUtils.extractRowsUpdated(UcastMacsLocal.class, getUpdates(),getDbSchema());
+ oldUMacsLocalRows = TyperUtils.extractRowsOld(UcastMacsLocal.class, getUpdates(),getDbSchema());
+ }
+
+ @Override
+ public void execute(ReadWriteTransaction transaction) {
+ // TODO Auto-generated method stub
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2015 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.ovsdb.hwvtepsouthbound.transactions.md;
+
+import java.util.Map;
+
+import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
+import org.opendaylight.ovsdb.hwvtepsouthbound.HwvtepConnectionInstance;
+import org.opendaylight.ovsdb.lib.message.TableUpdates;
+import org.opendaylight.ovsdb.lib.notation.UUID;
+import org.opendaylight.ovsdb.lib.schema.DatabaseSchema;
+import org.opendaylight.ovsdb.lib.schema.typed.TyperUtils;
+import org.opendaylight.ovsdb.schema.hardwarevtep.UcastMacsRemote;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class UcastMacsRemoteUpdateCommand extends AbstractTransactionCommand {
+
+ private static final Logger LOG = LoggerFactory.getLogger(UcastMacsRemoteUpdateCommand.class);
+ private Map<UUID, UcastMacsRemote> updatedUMacsRemoteRows;
+ private Map<UUID, UcastMacsRemote> oldUMacsRemoteRows;
+
+ public UcastMacsRemoteUpdateCommand(HwvtepConnectionInstance key, TableUpdates updates,
+ DatabaseSchema dbSchema) {
+ super(key, updates, dbSchema);
+ updatedUMacsRemoteRows = TyperUtils.extractRowsUpdated(UcastMacsRemote.class, getUpdates(),getDbSchema());
+ oldUMacsRemoteRows = TyperUtils.extractRowsOld(UcastMacsRemote.class, getUpdates(),getDbSchema());
+ }
+
+ @Override
+ public void execute(ReadWriteTransaction transaction) {
+ // TODO Auto-generated method stub
+ }
+
+}