Search in sources :

Example 1 with PhysicalSwitchAugmentation

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.PhysicalSwitchAugmentation in project netvirt by opendaylight.

the class L2GwValidateCli method compareNodes.

private boolean compareNodes(Node node1, Node node2, boolean parentChildComparison, LogicalDatastoreType datastoreType) {
    if (node1 == null || node2 == null) {
        return false;
    }
    InstanceIdentifier<Node> nodeIid1 = HwvtepSouthboundUtils.createInstanceIdentifier(node1.getNodeId());
    InstanceIdentifier<Node> nodeIid2 = HwvtepSouthboundUtils.createInstanceIdentifier(node2.getNodeId());
    NodeId nodeId1 = nodeIid1.firstKeyOf(Node.class).getNodeId();
    NodeId nodeId2 = nodeIid2.firstKeyOf(Node.class).getNodeId();
    PhysicalSwitchAugmentation psAug1 = node1.getAugmentation(PhysicalSwitchAugmentation.class);
    PhysicalSwitchAugmentation psAug2 = node2.getAugmentation(PhysicalSwitchAugmentation.class);
    HwvtepGlobalAugmentation aug1 = node1.getAugmentation(HwvtepGlobalAugmentation.class);
    HwvtepGlobalAugmentation aug2 = node2.getAugmentation(HwvtepGlobalAugmentation.class);
    boolean globalNodes = psAug1 == null && psAug2 == null ? true : false;
    MergeCommand[] commands = globalNodes ? globalCommands : physicalSwitchCommands;
    for (MergeCommand cmd : commands) {
        List<DataObject> data1 = null;
        List<DataObject> data2 = null;
        if (globalNodes) {
            data1 = cmd.getData(aug1);
            data2 = cmd.getData(aug2);
        } else {
            data1 = cmd.getData(node1);
            data2 = cmd.getData(node2);
        }
        data1 = data1 == null ? Collections.EMPTY_LIST : data1;
        data2 = data2 == null ? Collections.EMPTY_LIST : data2;
        if (parentChildComparison) {
            data2 = cmd.transform(nodeIid1, data2);
        }
        Function<DataObject, DataObject> withoutUuidTransformer = cmd::withoutUuid;
        data1 = Lists.transform(data1, withoutUuidTransformer);
        data2 = Lists.transform(data2, withoutUuidTransformer);
        Map<Identifier<?>, DataObject> map1 = new HashMap<>();
        Map<Identifier<?>, DataObject> map2 = new HashMap<>();
        for (DataObject dataObject : data1) {
            map1.put(cmd.getKey(dataObject), dataObject);
        }
        for (DataObject dataObject : data2) {
            map2.put(cmd.getKey(dataObject), dataObject);
        }
        Set<DataObject> diff = Sets.newHashSet();
        for (Entry<Identifier<?>, DataObject> entry : map1.entrySet()) {
            DataObject obj1 = entry.getValue();
            DataObject obj2 = map2.get(entry.getKey());
            if (obj2 == null || !cmd.areEqual(obj1, obj2)) {
                diff.add(obj1);
            }
        }
        if (!diff.isEmpty()) {
            if (parentChildComparison) {
                pw.println("Missing " + cmd.getDescription() + " child entries in " + datastoreType + " parent node " + nodeId1 + " contain " + " more entries than child " + nodeId2 + " " + diff.size());
            } else {
                pw.println("Missing " + cmd.getDescription() + " op entries config " + nodeId1 + " contain " + " more entries than operational node " + diff.size());
            }
            if (diff.size() < 10) {
                for (Object obj : diff) {
                    pw.println(cmd.getKey((DataObject) obj));
                }
            }
        }
        diff = Sets.newHashSet();
        for (Entry<Identifier<?>, DataObject> entry : map2.entrySet()) {
            DataObject obj1 = entry.getValue();
            DataObject obj2 = map1.get(entry.getKey());
            if (globalNodes || parentChildComparison) {
                if (obj2 == null || !cmd.areEqual(obj1, obj2)) {
                    diff.add(obj1);
                }
            }
        }
        if (!diff.isEmpty()) {
            if (parentChildComparison) {
                pw.println("Extra " + cmd.getDescription() + " child entries in " + datastoreType + " node " + nodeId2 + " contain " + " more entries than parent node " + nodeId1 + " " + diff.size());
            } else {
                pw.println("Extra " + cmd.getDescription() + " operational node " + nodeId2 + " contain " + " more entries than config node " + diff.size());
            }
            if (diff.size() < 10) {
                for (Object obj : diff) {
                    pw.println(cmd.getKey((DataObject) obj));
                }
            }
        }
    }
    return true;
}
Also used : HashMap(java.util.HashMap) 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) MergeCommand(org.opendaylight.netvirt.elan.l2gw.ha.commands.MergeCommand) DataObject(org.opendaylight.yangtools.yang.binding.DataObject) Identifier(org.opendaylight.yangtools.yang.binding.Identifier) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) NodeId(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId) PhysicalSwitchAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.PhysicalSwitchAugmentation) DataObject(org.opendaylight.yangtools.yang.binding.DataObject)

Example 2 with PhysicalSwitchAugmentation

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.PhysicalSwitchAugmentation in project netvirt by opendaylight.

the class HwvtepPhysicalSwitchListener method updated.

/**
 * Upon update checks if the tunnels Ip was null earlier and it got newly added.
 * In that case simply call add.
 * If not then check if Tunnel Ip has been updated from an old value to new value.
 * If yes. delete old ITM tunnels of odl Tunnel Ipand add new ITM tunnels with new Tunnel
 * IP then call added ().
 *
 * @param identifier iid
 * @param phySwitchBefore ps Node before update
 * @param phySwitchAfter ps Node after update
 */
@Override
protected void updated(InstanceIdentifier<PhysicalSwitchAugmentation> identifier, PhysicalSwitchAugmentation phySwitchBefore, PhysicalSwitchAugmentation phySwitchAfter) {
    NodeId nodeId = getNodeId(identifier);
    LOG.trace("Received PhysicalSwitch Update Event for node {}: PhysicalSwitch Before: {}, " + "PhysicalSwitch After: {}", nodeId.getValue(), phySwitchBefore, phySwitchAfter);
    String psName = getPsName(identifier);
    if (psName == null) {
        LOG.error("Could not find the physical switch name for node {}", nodeId.getValue());
        return;
    }
    L2GatewayDevice existingDevice = l2GatewayCache.get(psName);
    LOG.info("Received physical switch {} update event for node {}", psName, nodeId.getValue());
    InstanceIdentifier<Node> globalNodeIid = getManagedByNodeIid(identifier);
    if (DEVICE_NOT_CACHED_OR_PARENT_CONNECTED.test(existingDevice, globalNodeIid)) {
        if (TUNNEL_IP_AVAILABLE.test(phySwitchAfter)) {
            added(identifier, phySwitchAfter);
        }
    } else {
        if (!Objects.equals(phySwitchAfter.getTunnelIps(), phySwitchBefore.getTunnelIps()) && TUNNEL_IP_CHANGED.test(phySwitchAfter, existingDevice)) {
            final String hwvtepId = existingDevice.getHwvtepNodeId();
            elanClusterUtils.runOnlyInOwnerNode(existingDevice.getDeviceName(), "handling Physical Switch add create itm tunnels ", () -> {
                LOG.info("Deleting itm tunnels for device {}", existingDevice.getDeviceName());
                L2GatewayUtils.deleteItmTunnels(itmRpcService, hwvtepId, existingDevice.getDeviceName(), existingDevice.getTunnelIp());
                // TODO remove these sleeps
                Thread.sleep(10000L);
                LOG.info("Creating itm tunnels for device {}", existingDevice.getDeviceName());
                ElanL2GatewayUtils.createItmTunnels(dataBroker, itmRpcService, hwvtepId, psName, phySwitchAfter.getTunnelIps().get(0).getTunnelIpsKey());
                return Collections.emptyList();
            });
            try {
                // TODO remove the sleep by using better itm api to detect finish of prev op
                Thread.sleep(20000L);
            } catch (InterruptedException e) {
                LOG.error("Interrupted ");
            }
            existingDevice.setTunnelIps(new HashSet<>());
            added(identifier, phySwitchAfter);
        }
    }
}
Also used : 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) L2GatewayDevice(org.opendaylight.netvirt.neutronvpn.api.l2gw.L2GatewayDevice)

Example 3 with PhysicalSwitchAugmentation

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.PhysicalSwitchAugmentation in project netvirt by opendaylight.

the class NodeConnectedHandler method copyHAPSConfigToChildPS.

/**
 * Copy HA physical switch data to Child Physical switch node of config data tree.
 *
 * @param haPsNode HA physical Switch Node
 * @param childPath HA Child Node path
 * @param tx Transaction
 */
public void copyHAPSConfigToChildPS(Node haPsNode, InstanceIdentifier<Node> childPath, ReadWriteTransaction tx) {
    InstanceIdentifier<Node> childPsPath = HwvtepHAUtil.convertPsPath(haPsNode, childPath);
    NodeBuilder childPsBuilder = HwvtepHAUtil.getNodeBuilderForPath(childPsPath);
    PhysicalSwitchAugmentationBuilder dstBuilder = new PhysicalSwitchAugmentationBuilder();
    PhysicalSwitchAugmentation src = haPsNode.getAugmentation(PhysicalSwitchAugmentation.class);
    psAugmentationMerger.mergeConfigData(dstBuilder, src, childPath);
    psNodeMerger.mergeConfigData(childPsBuilder, haPsNode, childPath);
    childPsBuilder.addAugmentation(PhysicalSwitchAugmentation.class, dstBuilder.build());
    Node childPSNode = childPsBuilder.build();
    tx.put(CONFIGURATION, childPsPath, childPSNode, WriteTransaction.CREATE_MISSING_PARENTS);
}
Also used : PhysicalSwitchAugmentationBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.PhysicalSwitchAugmentationBuilder) Node(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node) PhysicalSwitchAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.PhysicalSwitchAugmentation) NodeBuilder(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeBuilder)

Example 4 with PhysicalSwitchAugmentation

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.PhysicalSwitchAugmentation in project netvirt by opendaylight.

the class NodeCopier method copyPSNode.

@Override
public void copyPSNode(Optional<Node> srcPsNodeOptional, InstanceIdentifier<Node> srcPsPath, InstanceIdentifier<Node> dstPsPath, InstanceIdentifier<Node> dstGlobalPath, LogicalDatastoreType logicalDatastoreType, ReadWriteTransaction tx) throws ReadFailedException {
    if (!srcPsNodeOptional.isPresent() && logicalDatastoreType == CONFIGURATION) {
        Futures.addCallback(tx.read(logicalDatastoreType, srcPsPath), new FutureCallback<Optional<Node>>() {

            @Override
            public void onSuccess(Optional<Node> nodeOptional) {
                HAJobScheduler.getInstance().submitJob(() -> {
                    try {
                        ReadWriteTransaction tx1 = new BatchedTransaction();
                        if (nodeOptional.isPresent()) {
                            copyPSNode(nodeOptional, srcPsPath, dstPsPath, dstGlobalPath, logicalDatastoreType, tx1);
                        } else {
                            /**
                             * Deleting node please refer @see #copyGlobalNode for explanation
                             */
                            HwvtepHAUtil.deleteNodeIfPresent(tx1, logicalDatastoreType, dstPsPath);
                        }
                    } catch (ReadFailedException e) {
                        LOG.error("Failed to read src node {}", srcPsNodeOptional.get());
                    }
                });
            }

            @Override
            public void onFailure(Throwable throwable) {
            }
        });
        return;
    }
    NodeBuilder dstPsNodeBuilder = HwvtepHAUtil.getNodeBuilderForPath(dstPsPath);
    PhysicalSwitchAugmentationBuilder dstPsAugmentationBuilder = new PhysicalSwitchAugmentationBuilder();
    PhysicalSwitchAugmentation srcPsAugmenatation = srcPsNodeOptional.get().getAugmentation(PhysicalSwitchAugmentation.class);
    Node existingDstPsNode = HwvtepHAUtil.readNode(tx, logicalDatastoreType, dstPsPath);
    PhysicalSwitchAugmentation existingDstPsAugmentation = HwvtepHAUtil.getPhysicalSwitchAugmentationOfNode(existingDstPsNode);
    if (OPERATIONAL == logicalDatastoreType) {
        psAugmentationMerger.mergeOperationalData(dstPsAugmentationBuilder, existingDstPsAugmentation, srcPsAugmenatation, dstPsPath);
        psNodeMerger.mergeOperationalData(dstPsNodeBuilder, existingDstPsNode, srcPsNodeOptional.get(), dstPsPath);
    } else {
        psAugmentationMerger.mergeConfigData(dstPsAugmentationBuilder, srcPsAugmenatation, dstPsPath);
        psNodeMerger.mergeConfigData(dstPsNodeBuilder, srcPsNodeOptional.get(), dstPsPath);
    }
    mergeOpManagedByAttributes(srcPsAugmenatation, dstPsAugmentationBuilder, dstGlobalPath);
    dstPsNodeBuilder.addAugmentation(PhysicalSwitchAugmentation.class, dstPsAugmentationBuilder.build());
    Node dstPsNode = dstPsNodeBuilder.build();
    tx.merge(logicalDatastoreType, dstPsPath, dstPsNode, true);
    LOG.debug("Copied {} physical switch node from {} to {}", logicalDatastoreType, srcPsPath, dstPsPath);
}
Also used : ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException) BatchedTransaction(org.opendaylight.netvirt.elan.l2gw.ha.BatchedTransaction) PhysicalSwitchAugmentationBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.PhysicalSwitchAugmentationBuilder) 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) PhysicalSwitchAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.PhysicalSwitchAugmentation) ReadWriteTransaction(org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction) NodeBuilder(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeBuilder)

Example 5 with PhysicalSwitchAugmentation

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.PhysicalSwitchAugmentation in project netvirt by opendaylight.

the class HwvtepPhysicalSwitchListener method added.

@Override
protected void added(InstanceIdentifier<PhysicalSwitchAugmentation> identifier, final PhysicalSwitchAugmentation phySwitchAdded) {
    String globalNodeId = getManagedByNodeId(identifier);
    final InstanceIdentifier<Node> globalNodeIid = getManagedByNodeIid(identifier);
    NodeId nodeId = getNodeId(identifier);
    if (TUNNEL_IP_NOT_AVAILABLE.test(phySwitchAdded)) {
        LOG.error("Could not find the /tunnel ips for node {}", nodeId.getValue());
        return;
    }
    final String psName = getPsName(identifier);
    LOG.trace("Received physical switch {} added event received for node {}", psName, nodeId.getValue());
    haOpClusteredListener.runAfterNodeIsConnected(globalNodeIid, (node) -> {
        LOG.trace("Running job for node {} ", globalNodeIid);
        if (!node.isPresent()) {
            LOG.error("Global node is absent {}", globalNodeId);
            return;
        }
        HAOpClusteredListener.addToCacheIfHAChildNode(globalNodeIid, node.get());
        if (hwvtepHACache.isHAEnabledDevice(globalNodeIid)) {
            LOG.trace("Ha enabled device {}", globalNodeIid);
            return;
        }
        LOG.trace("Updating cache for node {}", globalNodeIid);
        L2GatewayDevice l2GwDevice = l2GatewayCache.get(psName);
        if (childConnectedAfterParent.test(l2GwDevice, globalNodeIid)) {
            LOG.trace("Device {} {} is already Connected by {}", psName, globalNodeId, l2GwDevice.getHwvtepNodeId());
            return;
        }
        InstanceIdentifier<Node> existingIid = globalNodeIid;
        if (l2GwDevice != null && l2GwDevice.getHwvtepNodeId() != null) {
            existingIid = HwvtepHAUtil.convertToInstanceIdentifier(l2GwDevice.getHwvtepNodeId());
        }
        if (parentConnectedAfterChild.test(l2GwDevice, globalNodeIid) && alreadyHasL2Gwids.test(l2GwDevice)) {
            LOG.error("Child node {} having l2gw configured became ha node " + " removing the l2device {} from all elan cache and provision parent node {}", existingIid, psName, globalNodeIid);
            ElanL2GwCacheUtils.removeL2GatewayDeviceFromAllElanCache(l2GwDevice.getHwvtepNodeId());
        }
        l2GwDevice = l2GatewayCache.addOrGet(psName);
        l2GwDevice.setConnected(true);
        l2GwDevice.setHwvtepNodeId(globalNodeId);
        List<TunnelIps> tunnelIps = phySwitchAdded.getTunnelIps();
        if (tunnelIps != null) {
            for (TunnelIps tunnelIp : tunnelIps) {
                IpAddress tunnelIpAddr = tunnelIp.getTunnelIpsKey();
                l2GwDevice.addTunnelIp(tunnelIpAddr);
            }
        }
        handleAdd(l2GwDevice);
        elanClusterUtils.runOnlyInOwnerNode("Update config tunnels IP ", () -> {
            try {
                updateConfigTunnelIp(identifier, phySwitchAdded);
            } catch (ReadFailedException e) {
                LOG.error("Failed to update tunnel ips {}", identifier);
            }
        });
        return;
    });
}
Also used : ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException) TunnelIps(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.physical._switch.attributes.TunnelIps) 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) IpAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress) L2GatewayDevice(org.opendaylight.netvirt.neutronvpn.api.l2gw.L2GatewayDevice)

Aggregations

Node (org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node)9 PhysicalSwitchAugmentation (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.PhysicalSwitchAugmentation)7 NodeId (org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId)5 L2GatewayDevice (org.opendaylight.netvirt.neutronvpn.api.l2gw.L2GatewayDevice)3 HwvtepGlobalRef (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepGlobalRef)3 PhysicalSwitchAugmentationBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.PhysicalSwitchAugmentationBuilder)3 NodeBuilder (org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeBuilder)3 InstanceIdentifier (org.opendaylight.yangtools.yang.binding.InstanceIdentifier)3 HashMap (java.util.HashMap)2 ReadFailedException (org.opendaylight.controller.md.sal.common.api.data.ReadFailedException)2 HwvtepGlobalAugmentation (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepGlobalAugmentation)2 NetworkTopology (org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology)2 Topology (org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology)2 Optional (com.google.common.base.Optional)1 ReadWriteTransaction (org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction)1 BatchedTransaction (org.opendaylight.netvirt.elan.l2gw.ha.BatchedTransaction)1 MergeCommand (org.opendaylight.netvirt.elan.l2gw.ha.commands.MergeCommand)1 IpAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress)1 LogicalSwitches (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.LogicalSwitches)1 Switches (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.Switches)1