Search in sources :

Example 6 with Switches

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

the class GlobalAugmentationHelper method addSwitches.

public static void addSwitches(HwvtepGlobalAugmentationBuilder augmentationBuilder, InstanceIdentifier<Node> psId) {
    List<Switches> switches = new ArrayList<>();
    SwitchesBuilder switchesBuilder = new SwitchesBuilder();
    switchesBuilder.setKey(new SwitchesKey(new HwvtepPhysicalSwitchRef(psId)));
    switchesBuilder.setSwitchRef(new HwvtepPhysicalSwitchRef(psId));
    switches.add(switchesBuilder.build());
    augmentationBuilder.setSwitches(switches);
}
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) LogicalSwitches(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.LogicalSwitches) Switches(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.Switches) ArrayList(java.util.ArrayList) SwitchesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.SwitchesBuilder)

Example 7 with Switches

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

the class TestComparators method verifySwitches.

public static void verifySwitches(Node globalOpNode, Node psOpNode) {
    for (Switches switches : globalOpNode.getAugmentation(HwvtepGlobalAugmentation.class).getSwitches()) {
        String switchValue = switches.getSwitchRef().getValue().firstKeyOf(Node.class).getNodeId().getValue();
        assertEquals("Switch Name should be equal", switchValue, psOpNode.getNodeId().getValue());
    }
}
Also used : 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)

Example 8 with Switches

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.Switches 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 9 with Switches

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.Switches 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 10 with Switches

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.Switches 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)

Aggregations

HwvtepGlobalAugmentation (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepGlobalAugmentation)8 LogicalSwitches (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.LogicalSwitches)7 Switches (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.Switches)7 Node (org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node)6 BigInteger (java.math.BigInteger)4 ArrayList (java.util.ArrayList)4 Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)3 InstanceIdentifier (org.opendaylight.yangtools.yang.binding.InstanceIdentifier)3 FlowEntity (org.opendaylight.genius.mdsalutil.FlowEntity)2 RouterToNaptSwitch (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.napt.switches.RouterToNaptSwitch)2 HwvtepNodeName (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepNodeName)2 HwvtepPhysicalSwitchRef (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepPhysicalSwitchRef)2 Optional (com.google.common.base.Optional)1 Strings (com.google.common.base.Strings)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Set (java.util.Set)1 TreeSet (java.util.TreeSet)1 ExecutionException (java.util.concurrent.ExecutionException)1