X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsamples%2Fl2switch%2Fimplementation%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fsample%2Fl2switch%2Fmd%2Finventory%2FInventoryService.java;fp=opendaylight%2Fmd-sal%2Fsamples%2Fl2switch%2Fimplementation%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fsample%2Fl2switch%2Fmd%2Finventory%2FInventoryService.java;h=0000000000000000000000000000000000000000;hp=1ec65e8f811235865372d6369827c192c800c71e;hb=034cd42ff377039471c19c75d7e57d8199525723;hpb=139937c2e646894af6a9b2b8a8a1047c6ef82485 diff --git a/opendaylight/md-sal/samples/l2switch/implementation/src/main/java/org/opendaylight/controller/sample/l2switch/md/inventory/InventoryService.java b/opendaylight/md-sal/samples/l2switch/implementation/src/main/java/org/opendaylight/controller/sample/l2switch/md/inventory/InventoryService.java deleted file mode 100644 index 1ec65e8f81..0000000000 --- a/opendaylight/md-sal/samples/l2switch/implementation/src/main/java/org/opendaylight/controller/sample/l2switch/md/inventory/InventoryService.java +++ /dev/null @@ -1,106 +0,0 @@ -/* - * Copyright (c) 2014 Cisco Systems, Inc. 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.controller.sample.l2switch.md.inventory; - -import org.opendaylight.controller.sample.l2switch.md.util.InstanceIdentifierUtils; -import org.opendaylight.controller.sal.binding.api.data.DataBrokerService; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeConnector; -import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorRef; -import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes; -import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector; -import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnectorKey; -import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node; -import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey; -import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology; -import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology; -import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Link; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -/** - * InventoryService provides functions related to Nodes & NodeConnectors. - */ -public class InventoryService { - private DataBrokerService dataService; - // Key: SwitchId, Value: NodeConnectorRef that corresponds to NC between controller & switch - private HashMap controllerSwitchConnectors; - - /** - * Construct an InventoryService object with the specified inputs. - * @param dataService The DataBrokerService associated with the InventoryService. - */ - public InventoryService(DataBrokerService dataService) { - this.dataService = dataService; - controllerSwitchConnectors = new HashMap(); - } - - public HashMap getControllerSwitchConnectors() { - return controllerSwitchConnectors; - } - - // ToDo: Improve performance for thousands of switch ports - /** - * Get the External NodeConnectors of the network, which are the NodeConnectors connected to hosts. - * @return The list of external node connectors. - */ - public List getExternalNodeConnectors() { - // External NodeConnectors = All - Internal - ArrayList externalNodeConnectors = new ArrayList(); - Set internalNodeConnectors = new HashSet<>(); - - // Read Topology -- find list of switch-to-switch internal node connectors - NetworkTopology networkTopology = - (NetworkTopology)dataService.readOperationalData( - InstanceIdentifier.builder(NetworkTopology.class).toInstance()); - - for (Topology topology : networkTopology.getTopology()) { - Topology completeTopology = - (Topology)dataService.readOperationalData( - InstanceIdentifierUtils.generateTopologyInstanceIdentifier( - topology.getTopologyId().getValue())); - - for (Link link : completeTopology.getLink()) { - internalNodeConnectors.add(link.getDestination().getDestTp().getValue()); - internalNodeConnectors.add(link.getSource().getSourceTp().getValue()); - } - } - - // Read Inventory -- contains list of all nodeConnectors - InstanceIdentifier.InstanceIdentifierBuilder nodesInsIdBuilder = InstanceIdentifier.builder(Nodes.class); - Nodes nodes = (Nodes)dataService.readOperationalData(nodesInsIdBuilder.toInstance()); - if (nodes != null) { - for (Node node : nodes.getNode()) { - Node completeNode = (Node)dataService.readOperationalData(InstanceIdentifierUtils.createNodePath(node.getId())); - for (NodeConnector nodeConnector : completeNode.getNodeConnector()) { - // NodeConnector isn't switch-to-switch, so it must be controller-to-switch (internal) or external - if (!internalNodeConnectors.contains(nodeConnector.getId().getValue())) { - NodeConnectorRef ncRef = new NodeConnectorRef( - InstanceIdentifier.builder(Nodes.class).child(Node.class, node.getKey()) - .child(NodeConnector.class, nodeConnector.getKey()).toInstance()); - - // External node connectors have "-" in their name for mininet, i.e. "s1-eth1" - if (nodeConnector.getAugmentation(FlowCapableNodeConnector.class).getName().contains("-")) { - externalNodeConnectors.add(ncRef); - } - // Controller-to-switch internal node connectors - else { - controllerSwitchConnectors.put(node.getId().getValue(), ncRef); - } - } - } - } - } - - return externalNodeConnectors; - } -} \ No newline at end of file