Search in sources :

Example 86 with InstanceIdentifier

use of org.opendaylight.yangtools.yang.binding.InstanceIdentifier in project netvirt by opendaylight.

the class L2GatewayConnectionUtils method readAndCopyLocalUcastMacsToCache.

private void readAndCopyLocalUcastMacsToCache(final String elanName, final L2GatewayDevice l2GatewayDevice) {
    final InstanceIdentifier<Node> nodeIid = HwvtepSouthboundUtils.createInstanceIdentifier(new NodeId(l2GatewayDevice.getHwvtepNodeId()));
    jobCoordinator.enqueueJob(elanName + ":" + l2GatewayDevice.getDeviceName(), () -> {
        final SettableFuture settableFuture = SettableFuture.create();
        Futures.addCallback(broker.newReadOnlyTransaction().read(LogicalDatastoreType.OPERATIONAL, nodeIid), new SettableFutureCallback<Optional<Node>>(settableFuture) {

            @Override
            public void onSuccess(@Nonnull Optional<Node> resultNode) {
                LocalUcastMacListener localUcastMacListener = new LocalUcastMacListener(broker, haOpClusteredListener, elanL2GatewayUtils, jobCoordinator, elanInstanceCache);
                settableFuture.set(resultNode);
                Optional<Node> nodeOptional = resultNode;
                if (nodeOptional.isPresent()) {
                    Node node = nodeOptional.get();
                    if (node.getAugmentation(HwvtepGlobalAugmentation.class) != null) {
                        List<LocalUcastMacs> localUcastMacs = node.getAugmentation(HwvtepGlobalAugmentation.class).getLocalUcastMacs();
                        if (localUcastMacs == null) {
                            return;
                        }
                        localUcastMacs.stream().filter((mac) -> {
                            return macBelongsToLogicalSwitch(mac, elanName);
                        }).forEach((mac) -> {
                            InstanceIdentifier<LocalUcastMacs> macIid = getMacIid(nodeIid, mac);
                            localUcastMacListener.added(macIid, mac);
                        });
                    }
                }
            }
        }, MoreExecutors.directExecutor());
        return Lists.newArrayList(settableFuture);
    }, 5);
}
Also used : SettableFuture(com.google.common.util.concurrent.SettableFuture) MoreExecutors(com.google.common.util.concurrent.MoreExecutors) L2gatewayConnection(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l2gateways.rev150712.l2gateway.connections.attributes.l2gatewayconnections.L2gatewayConnection) ElanL2GwCacheUtils(org.opendaylight.netvirt.elanmanager.utils.ElanL2GwCacheUtils) L2gateways(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l2gateways.rev150712.l2gateways.attributes.L2gateways) L2gateway(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l2gateways.rev150712.l2gateways.attributes.l2gateways.L2gateway) LoggerFactory(org.slf4j.LoggerFactory) AssociateHwvtepToElanJob(org.opendaylight.netvirt.elan.l2gw.jobs.AssociateHwvtepToElanJob) SettableFuture(com.google.common.util.concurrent.SettableFuture) Singleton(javax.inject.Singleton) HwvtepLogicalSwitchListener(org.opendaylight.netvirt.elan.l2gw.listeners.HwvtepLogicalSwitchListener) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) Neutron(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.rev150712.Neutron) HwvtepUtils(org.opendaylight.genius.utils.hwvtep.HwvtepUtils) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) PreDestroy(javax.annotation.PreDestroy) NodeId(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId) HAOpClusteredListener(org.opendaylight.netvirt.elan.l2gw.ha.listeners.HAOpClusteredListener) ElanClusterUtils(org.opendaylight.netvirt.elan.utils.ElanClusterUtils) Lists(com.google.common.collect.Lists) Optional(com.google.common.base.Optional) LocalUcastMacs(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.LocalUcastMacs) MDSALUtil(org.opendaylight.genius.mdsalutil.MDSALUtil) LocalUcastMacListener(org.opendaylight.netvirt.elan.l2gw.listeners.LocalUcastMacListener) Nonnull(javax.annotation.Nonnull) HwvtepSouthboundUtils(org.opendaylight.genius.utils.hwvtep.HwvtepSouthboundUtils) Devices(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l2gateways.rev150712.l2gateway.attributes.Devices) LogicalSwitches(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.LogicalSwitches) Logger(org.slf4j.Logger) Node(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node) ElanInstanceCache(org.opendaylight.netvirt.elan.cache.ElanInstanceCache) LogicalDatastoreType(org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType) JobCoordinator(org.opendaylight.infrautils.jobcoordinator.JobCoordinator) Set(java.util.Set) DataBroker(org.opendaylight.controller.md.sal.binding.api.DataBroker) ElanInstance(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.instances.ElanInstance) HwvtepGlobalAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepGlobalAugmentation) Futures(com.google.common.util.concurrent.Futures) List(java.util.List) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) L2gatewayConnections(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l2gateways.rev150712.l2gateway.connections.attributes.L2gatewayConnections) L2gatewayKey(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l2gateways.rev150712.l2gateways.attributes.l2gateways.L2gatewayKey) DisAssociateHwvtepFromElanJob(org.opendaylight.netvirt.elan.l2gw.jobs.DisAssociateHwvtepFromElanJob) ElanUtils.isVxlanNetworkOrVxlanSegment(org.opendaylight.netvirt.elan.utils.ElanUtils.isVxlanNetworkOrVxlanSegment) Collections(java.util.Collections) L2GatewayCache(org.opendaylight.netvirt.neutronvpn.api.l2gw.L2GatewayCache) L2GatewayDevice(org.opendaylight.netvirt.neutronvpn.api.l2gw.L2GatewayDevice) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) Optional(com.google.common.base.Optional) Node(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node) NodeId(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) ArrayList(java.util.ArrayList) List(java.util.List) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) LocalUcastMacListener(org.opendaylight.netvirt.elan.l2gw.listeners.LocalUcastMacListener)

Example 87 with InstanceIdentifier

use of org.opendaylight.yangtools.yang.binding.InstanceIdentifier in project netvirt by opendaylight.

the class HwvtepHAUtil method deletePSNodesOfNode.

/**
 * Delete PS data of HA node of Config Data tree.
 *
 * @param key Node object
 * @param haNode Ha Node from which to be deleted
 * @param tx Transaction
 * @throws ReadFailedException  Exception thrown if read fails
 */
public static void deletePSNodesOfNode(InstanceIdentifier<Node> key, Node haNode, ReadWriteTransaction tx) throws ReadFailedException {
    // read from switches attribute and clean up them
    HwvtepGlobalAugmentation globalAugmentation = haNode.getAugmentation(HwvtepGlobalAugmentation.class);
    if (globalAugmentation == null) {
        return;
    }
    HashMap<InstanceIdentifier<Node>, Boolean> deleted = new HashMap<>();
    List<Switches> switches = globalAugmentation.getSwitches();
    if (switches != null) {
        for (Switches switche : switches) {
            InstanceIdentifier<Node> psId = (InstanceIdentifier<Node>) switche.getSwitchRef().getValue();
            deleteNodeIfPresent(tx, CONFIGURATION, psId);
            deleted.put(psId, Boolean.TRUE);
        }
    }
    // also read from managed by attribute of switches and cleanup them as a back up if the above cleanup fails
    Optional<Topology> topologyOptional = tx.read(CONFIGURATION, key.firstIdentifierOf(Topology.class)).checkedGet();
    String deletedNodeId = key.firstKeyOf(Node.class).getNodeId().getValue();
    if (topologyOptional.isPresent()) {
        Topology topology = topologyOptional.get();
        if (topology.getNode() != null) {
            for (Node psNode : topology.getNode()) {
                PhysicalSwitchAugmentation ps = psNode.getAugmentation(PhysicalSwitchAugmentation.class);
                if (ps != null) {
                    InstanceIdentifier<Node> iid = (InstanceIdentifier<Node>) ps.getManagedBy().getValue();
                    String nodeIdVal = iid.firstKeyOf(Node.class).getNodeId().getValue();
                    if (deletedNodeId.equals(nodeIdVal)) {
                        InstanceIdentifier<Node> psNodeId = convertToInstanceIdentifier(psNode.getNodeId().getValue());
                        if (deleted.containsKey(psNodeId)) {
                            deleteNodeIfPresent(tx, CONFIGURATION, psNodeId);
                        }
                    }
                }
            }
        }
    }
}
Also used : HashMap(java.util.HashMap) Switches(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.Switches) LogicalSwitches(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.LogicalSwitches) Node(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node) HwvtepGlobalAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepGlobalAugmentation) NetworkTopology(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology) Topology(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology) PhysicalSwitchAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.PhysicalSwitchAugmentation) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier)

Example 88 with InstanceIdentifier

use of org.opendaylight.yangtools.yang.binding.InstanceIdentifier in project netvirt by opendaylight.

the class HwvtepHAUtil method deleteSwitchesManagedByNode.

/**
 * Delete switches from Node in Operational Data Tree .
 *
 * @param haPath HA node path from whih switches will be deleted
 * @param tx  Transaction object
 * @throws ReadFailedException  Exception thrown if read fails
 */
public static void deleteSwitchesManagedByNode(InstanceIdentifier<Node> haPath, ReadWriteTransaction tx) throws ReadFailedException {
    Optional<Node> nodeOptional = tx.read(OPERATIONAL, haPath).checkedGet();
    if (!nodeOptional.isPresent()) {
        return;
    }
    Node node = nodeOptional.get();
    HwvtepGlobalAugmentation globalAugmentation = node.getAugmentation(HwvtepGlobalAugmentation.class);
    if (globalAugmentation == null) {
        return;
    }
    List<Switches> switches = globalAugmentation.getSwitches();
    if (switches != null) {
        for (Switches switche : switches) {
            InstanceIdentifier<Node> id = (InstanceIdentifier<Node>) switche.getSwitchRef().getValue();
            deleteNodeIfPresent(tx, OPERATIONAL, id);
        }
    }
}
Also used : Node(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node) Switches(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.Switches) LogicalSwitches(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.LogicalSwitches) HwvtepGlobalAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepGlobalAugmentation) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier)

Example 89 with InstanceIdentifier

use of org.opendaylight.yangtools.yang.binding.InstanceIdentifier in project netvirt by opendaylight.

the class SwitchesCmd method transform.

@Override
public Switches transform(InstanceIdentifier<Node> nodePath, Switches src) {
    SwitchesBuilder builder = new SwitchesBuilder(src);
    InstanceIdentifier<Node> psNodeIid = (InstanceIdentifier<Node>) src.getSwitchRef().getValue();
    String psNodeId = psNodeIid.firstKeyOf(Node.class).getNodeId().getValue();
    String nodeId = nodePath.firstKeyOf(Node.class).getNodeId().getValue();
    int idx = nodeId.indexOf("/physicalswitch/");
    if (idx > 0) {
        nodeId = nodeId.substring(0, idx);
    }
    idx = psNodeId.indexOf("/physicalswitch/") + "/physicalswitch/".length();
    String switchName = psNodeId.substring(idx);
    String dstNodeId = nodeId + "/physicalswitch/" + switchName;
    InstanceIdentifier<Node> id2 = HwvtepHAUtil.convertToInstanceIdentifier(dstNodeId);
    builder.setSwitchRef(new HwvtepPhysicalSwitchRef(id2));
    builder.setKey(new SwitchesKey(new HwvtepPhysicalSwitchRef(id2)));
    return builder.build();
}
Also used : HwvtepPhysicalSwitchRef(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepPhysicalSwitchRef) SwitchesKey(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.SwitchesKey) Node(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) SwitchesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.SwitchesBuilder)

Example 90 with InstanceIdentifier

use of org.opendaylight.yangtools.yang.binding.InstanceIdentifier in project netvirt by opendaylight.

the class TunnelCmd method areEqual.

@Override
public boolean areEqual(Tunnels updated, Tunnels orig) {
    InstanceIdentifier<TerminationPoint> remoteLocatorRefUpdated = (InstanceIdentifier<TerminationPoint>) updated.getRemoteLocatorRef().getValue();
    InstanceIdentifier<TerminationPoint> remoteLocatorRefOriginal = (InstanceIdentifier<TerminationPoint>) orig.getRemoteLocatorRef().getValue();
    TpId tpId1 = remoteLocatorRefUpdated.firstKeyOf(TerminationPoint.class).getTpId();
    TpId tpId2 = remoteLocatorRefOriginal.firstKeyOf(TerminationPoint.class).getTpId();
    return tpId1.equals(tpId2);
}
Also used : TpId(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TpId) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) TerminationPoint(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPoint)

Aggregations

InstanceIdentifier (org.opendaylight.yangtools.yang.binding.InstanceIdentifier)142 Logger (org.slf4j.Logger)57 LoggerFactory (org.slf4j.LoggerFactory)57 DataBroker (org.opendaylight.controller.md.sal.binding.api.DataBroker)52 LogicalDatastoreType (org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType)52 ArrayList (java.util.ArrayList)47 List (java.util.List)47 Collections (java.util.Collections)40 Optional (com.google.common.base.Optional)39 WriteTransaction (org.opendaylight.controller.md.sal.binding.api.WriteTransaction)37 BigInteger (java.math.BigInteger)36 ManagedNewTransactionRunner (org.opendaylight.genius.infra.ManagedNewTransactionRunner)35 Inject (javax.inject.Inject)34 Singleton (javax.inject.Singleton)34 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)30 ManagedNewTransactionRunnerImpl (org.opendaylight.genius.infra.ManagedNewTransactionRunnerImpl)29 JobCoordinator (org.opendaylight.infrautils.jobcoordinator.JobCoordinator)28 Node (org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node)26 PostConstruct (javax.annotation.PostConstruct)24 DataObject (org.opendaylight.yangtools.yang.binding.DataObject)24