Search in sources :

Example 6 with BridgeBridgeLink

use of org.opennms.netmgt.model.BridgeBridgeLink in project opennms by OpenNMS.

the class BridgeTopologyDaoInMemory method getBridgeNodeSharedSegments.

@Override
public List<SharedSegment> getBridgeNodeSharedSegments(BridgeBridgeLinkDao bridgeBridgeLinkDao, BridgeMacLinkDao bridgeMacLinkDao, int nodeid) {
    List<SharedSegment> segments = new ArrayList<SharedSegment>();
    /*
        for (BroadcastDomain domain: getAllPersisted(bridgeBridgeLinkDao, bridgeMacLinkDao)) {
            System.out.println("parsing domain:" + domain);
            System.out.println("parsing domain with nodes:" + domain.getBridgeNodesOnDomain());
            System.out.println("parsing domain with macs:" + domain.getMacsOnDomain());
            if (domain.getBridgeNodesOnDomain().contains(nodeid)) {
                System.out.println("got domain with nodeid:" + nodeid);
                for (SharedSegment segment: domain.getTopology()) {
                    System.out.println("parsing segment:" + segment);
                    System.out.println("parsing segment with nodes:" + segment.getBridgeIdsOnSegment());
                    System.out.println("parsing segment with macs:" + segment.getMacsOnSegment());
                    if (segment.getBridgeIdsOnSegment().contains(nodeid)) {
                        segments.add(segment);
                        System.out.println("added segment:" + segment);
                    }
                }
            }
        }*/
    Set<Integer> designated = new HashSet<Integer>();
    BRIDGELINK: for (BridgeBridgeLink link : bridgeBridgeLinkDao.findByNodeId(nodeid)) {
        for (SharedSegment segment : segments) {
            if (segment.containsPort(link.getNode().getId(), link.getBridgePort()) || segment.containsPort(link.getDesignatedNode().getId(), link.getDesignatedPort())) {
                segment.add(link);
                designated.add(link.getDesignatedNode().getId());
                continue BRIDGELINK;
            }
        }
        SharedSegment segment = new SharedSegment();
        segment.add(link);
        segment.setDesignatedBridge(link.getDesignatedNode().getId());
        segments.add(segment);
    }
    designated.add(nodeid);
    for (Integer curNodeId : designated) {
        DBRIDGELINK: for (BridgeBridgeLink link : bridgeBridgeLinkDao.findByDesignatedNodeId(curNodeId)) {
            for (SharedSegment segment : segments) {
                if (segment.containsPort(link.getNode().getId(), link.getBridgePort()) || segment.containsPort(link.getDesignatedNode().getId(), link.getDesignatedPort())) {
                    segment.add(link);
                    continue DBRIDGELINK;
                }
            }
            SharedSegment segment = new SharedSegment();
            segment.add(link);
            segment.setDesignatedBridge(link.getDesignatedNode().getId());
            segments.add(segment);
        }
    }
    MACLINK: for (BridgeMacLink link : bridgeMacLinkDao.findByNodeId(nodeid)) {
        link.setBridgeDot1qTpFdbStatus(BridgeDot1qTpFdbStatus.DOT1D_TP_FDB_STATUS_LEARNED);
        for (SharedSegment segment : segments) {
            if (segment.containsMac(link.getMacAddress()) || segment.containsPort(link.getNode().getId(), link.getBridgePort())) {
                segment.add(link);
                continue MACLINK;
            }
        }
        SharedSegment segment = new SharedSegment();
        segment.add(link);
        segment.setDesignatedBridge(link.getNode().getId());
        segments.add(segment);
    }
    return segments;
}
Also used : ArrayList(java.util.ArrayList) BridgeBridgeLink(org.opennms.netmgt.model.BridgeBridgeLink) SharedSegment(org.opennms.netmgt.model.topology.SharedSegment) BridgeMacLink(org.opennms.netmgt.model.BridgeMacLink) HashSet(java.util.HashSet)

Example 7 with BridgeBridgeLink

use of org.opennms.netmgt.model.BridgeBridgeLink in project opennms by OpenNMS.

the class EnhancedLinkdTopologyProvider method getBridgeLinks.

private void getBridgeLinks(Map<Integer, OnmsNode> nodemap, Map<Integer, List<OnmsSnmpInterface>> nodesnmpmap, Map<String, List<OnmsIpInterface>> macToIpMap, Map<Integer, List<OnmsIpInterface>> ipmap, Map<Integer, OnmsIpInterface> ipprimarymap) {
    for (BroadcastDomain domain : m_bridgeTopologyDao.getAllPersisted(m_bridgeBridgeLinkDao, m_bridgeMacLinkDao)) {
        LOG.info("loadtopology: parsing broadcast Domain: '{}', {}", domain);
        for (SharedSegment segment : domain.getTopology()) {
            if (segment.noMacsOnSegment() && segment.getBridgeBridgeLinks().size() == 1) {
                for (BridgeBridgeLink link : segment.getBridgeBridgeLinks()) {
                    Vertex source = getOrCreateVertex(nodemap.get(link.getNode().getId()), ipprimarymap.get(link.getNode().getId()));
                    Vertex target = getOrCreateVertex(nodemap.get(link.getDesignatedNode().getId()), ipprimarymap.get(link.getDesignatedNode().getId()));
                    BridgeLinkDetail detail = new BridgeLinkDetail(EnhancedLinkdTopologyProvider.TOPOLOGY_NAMESPACE_LINKD, source, link.getBridgePortIfIndex(), target, link.getDesignatedPortIfIndex(), link.getBridgePort(), link.getDesignatedPort(), link.getId(), link.getId());
                    LinkdEdge edge = connectVertices(detail, BRIDGE_EDGE_NAMESPACE);
                    edge.setTooltipText(getEdgeTooltipText(detail, nodesnmpmap));
                }
                continue;
            }
            if (segment.getBridgeMacLinks().size() == 1 && segment.getBridgeBridgeLinks().size() == 0) {
                for (BridgeMacLink sourcelink : segment.getBridgeMacLinks()) {
                    if (macToIpMap.containsKey(sourcelink.getMacAddress()) && macToIpMap.get(sourcelink.getMacAddress()).size() > 0) {
                        List<OnmsIpInterface> targetInterfaces = macToIpMap.get(sourcelink.getMacAddress());
                        OnmsIpInterface targetIp = targetInterfaces.get(0);
                        if (segment.getBridgeIdsOnSegment().contains(targetIp.getNode().getId()))
                            continue;
                        Vertex source = getOrCreateVertex(nodemap.get(sourcelink.getNode().getId()), ipprimarymap.get(sourcelink.getNode().getId()));
                        Vertex target = getOrCreateVertex(nodemap.get(targetIp.getNode().getId()), ipprimarymap.get(targetIp.getNode().getId()));
                        LinkdEdge edge = connectVertices(sourcelink, source, target, BRIDGE_EDGE_NAMESPACE);
                        edge.setTooltipText(getEdgeTooltipText(sourcelink, source, target, targetInterfaces, nodesnmpmap));
                    }
                }
                continue;
            }
            String cloudId = segment.getDesignatedBridge() + ":" + segment.getDesignatedPort();
            AbstractVertex cloudVertex = addVertex(cloudId, 0, 0);
            cloudVertex.setLabel("");
            cloudVertex.setIconKey("cloud");
            cloudVertex.setTooltipText("Shared Segment: " + nodemap.get(segment.getDesignatedBridge()).getLabel() + " port: " + segment.getDesignatedPort());
            addVertices(cloudVertex);
            LOG.info("loadtopology: adding cloud: id: '{}', {}", cloudId, cloudVertex.getTooltipText());
            for (BridgePort targetport : segment.getBridgePortsOnSegment()) {
                Vertex target = getOrCreateVertex(nodemap.get(targetport.getNode().getId()), ipprimarymap.get(targetport.getNode().getId()));
                LinkdEdge edge = connectVertices(targetport, cloudVertex, target, BRIDGE_EDGE_NAMESPACE);
                edge.setTooltipText(getEdgeTooltipText(targetport, target, nodesnmpmap));
            }
            for (String targetmac : segment.getMacsOnSegment()) {
                if (macToIpMap.containsKey(targetmac) && macToIpMap.get(targetmac).size() > 0) {
                    List<OnmsIpInterface> targetInterfaces = macToIpMap.get(targetmac);
                    OnmsIpInterface targetIp = targetInterfaces.get(0);
                    if (segment.getBridgeIdsOnSegment().contains(targetIp.getNode().getId()))
                        continue;
                    Vertex target = getOrCreateVertex(nodemap.get(targetIp.getNode().getId()), ipprimarymap.get(targetIp.getNode().getId()));
                    LinkdEdge edge = connectCloudMacVertices(targetmac, cloudVertex, target, BRIDGE_EDGE_NAMESPACE);
                    edge.setTooltipText(getEdgeTooltipText(targetmac, target, targetInterfaces));
                }
            }
        }
    }
}
Also used : AbstractVertex(org.opennms.features.topology.api.topo.AbstractVertex) Vertex(org.opennms.features.topology.api.topo.Vertex) AbstractVertex(org.opennms.features.topology.api.topo.AbstractVertex) BridgePort(org.opennms.netmgt.model.topology.BridgePort) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) BroadcastDomain(org.opennms.netmgt.model.topology.BroadcastDomain) BridgeBridgeLink(org.opennms.netmgt.model.BridgeBridgeLink) SharedSegment(org.opennms.netmgt.model.topology.SharedSegment) BridgeMacLink(org.opennms.netmgt.model.BridgeMacLink)

Example 8 with BridgeBridgeLink

use of org.opennms.netmgt.model.BridgeBridgeLink in project opennms by OpenNMS.

the class BridgeTopologyDaoInMemory method getAllPersisted.

@Override
public Set<BroadcastDomain> getAllPersisted(BridgeBridgeLinkDao bridgeBridgeLinkDao, BridgeMacLinkDao bridgeMacLinkDao) {
    List<SharedSegment> segments = new ArrayList<SharedSegment>();
    BRIDGELINK: for (BridgeBridgeLink link : bridgeBridgeLinkDao.findAll()) {
        for (SharedSegment segment : segments) {
            if (segment.containsPort(link.getNode().getId(), link.getBridgePort()) || segment.containsPort(link.getDesignatedNode().getId(), link.getDesignatedPort())) {
                segment.add(link);
                continue BRIDGELINK;
            }
        }
        SharedSegment segment = new SharedSegment();
        segment.add(link);
        segment.setDesignatedBridge(link.getDesignatedNode().getId());
        segments.add(segment);
    }
    MACLINK: for (BridgeMacLink link : bridgeMacLinkDao.findAll()) {
        link.setBridgeDot1qTpFdbStatus(BridgeDot1qTpFdbStatus.DOT1D_TP_FDB_STATUS_LEARNED);
        for (SharedSegment segment : segments) {
            if (segment.containsMac(link.getMacAddress()) || segment.containsPort(link.getNode().getId(), link.getBridgePort())) {
                segment.add(link);
                continue MACLINK;
            }
        }
        SharedSegment segment = new SharedSegment();
        segment.add(link);
        segment.setDesignatedBridge(link.getNode().getId());
        segments.add(segment);
    }
    Set<Set<Integer>> nodelinked = new HashSet<Set<Integer>>();
    SHARED: for (SharedSegment segment : segments) {
        Set<Integer> nodesOnSegment = new HashSet<Integer>(segment.getBridgeIdsOnSegment());
        for (Set<Integer> nodes : nodelinked) {
            for (Integer nodeid : nodesOnSegment) {
                if (nodes.contains(nodeid))
                    continue SHARED;
            }
        }
        nodelinked.add(getNodesOnDomainSet(segments, segment, new HashSet<SharedSegment>(), nodesOnSegment));
    }
    Set<BroadcastDomain> domains = new HashSet<BroadcastDomain>();
    for (Set<Integer> nodes : nodelinked) {
        BroadcastDomain domain = new BroadcastDomain();
        for (Integer nodeid : nodes) domain.addBridge(new Bridge(nodeid));
        domains.add(domain);
    }
    // Assign the segment to domain and add to single nodes
    for (SharedSegment segment : segments) {
        BroadcastDomain domain = null;
        for (BroadcastDomain cdomain : domains) {
            if (cdomain.containsAtleastOne(segment.getBridgeIdsOnSegment())) {
                domain = cdomain;
                break;
            }
        }
        if (domain == null) {
            domain = new BroadcastDomain();
            domains.add(domain);
        }
        domain.loadTopologyEntry(segment);
    }
    return domains;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) ArrayList(java.util.ArrayList) BroadcastDomain(org.opennms.netmgt.model.topology.BroadcastDomain) BridgeBridgeLink(org.opennms.netmgt.model.BridgeBridgeLink) SharedSegment(org.opennms.netmgt.model.topology.SharedSegment) BridgeMacLink(org.opennms.netmgt.model.BridgeMacLink) Bridge(org.opennms.netmgt.model.topology.Bridge) HashSet(java.util.HashSet)

Example 9 with BridgeBridgeLink

use of org.opennms.netmgt.model.BridgeBridgeLink in project opennms by OpenNMS.

the class EnLinkdBuilderITCase method tearDown.

@After
public void tearDown() throws Exception {
    for (final IpNetToMedia at : m_ipNetToMediaDao.findAll()) m_ipNetToMediaDao.delete(at);
    m_ipNetToMediaDao.flush();
    for (final BridgeBridgeLink bb : m_bridgeBridgeLinkDao.findAll()) m_bridgeBridgeLinkDao.delete(bb);
    m_bridgeBridgeLinkDao.flush();
    for (final OnmsNode node : m_nodeDao.findAll()) m_nodeDao.delete(node);
    m_nodeDao.flush();
}
Also used : IpNetToMedia(org.opennms.netmgt.model.IpNetToMedia) OnmsNode(org.opennms.netmgt.model.OnmsNode) BridgeBridgeLink(org.opennms.netmgt.model.BridgeBridgeLink) After(org.junit.After)

Example 10 with BridgeBridgeLink

use of org.opennms.netmgt.model.BridgeBridgeLink in project opennms by OpenNMS.

the class EnLinkdIT method testDeleteBridgeC.

@Test
public void testDeleteBridgeC() {
    ABCTopology topology = new ABCTopology();
    NetworkBuilder nb = new NetworkBuilder();
    nb.addNode("nodeA").setForeignSource("linkd").setForeignId("nodeA").setSysObjectId("0.0").setSysName("nodeA").setType(NodeType.ACTIVE);
    nb.addInterface("10.0.1.1").setIsSnmpPrimary("P").setIsManaged("M");
    m_nodeDao.save(nb.getCurrentNode());
    nb.addNode("nodeB").setForeignSource("linkd").setForeignId("nodeB").setSysObjectId("0.0").setSysName("nodeB").setType(NodeType.ACTIVE);
    nb.addInterface("10.0.1.2").setIsSnmpPrimary("P").setIsManaged("M");
    m_nodeDao.save(nb.getCurrentNode());
    nb.addNode("nodeC").setForeignSource("linkd").setForeignId("nodeC").setSysObjectId("0.0").setSysName("nodeC").setType(NodeType.ACTIVE);
    nb.addInterface("10.0.1.3").setIsSnmpPrimary("P").setIsManaged("M");
    m_nodeDao.save(nb.getCurrentNode());
    OnmsNode nodeA = m_nodeDao.findByForeignId("linkd", "nodeA");
    OnmsNode nodeB = m_nodeDao.findByForeignId("linkd", "nodeB");
    OnmsNode nodeC = m_nodeDao.findByForeignId("linkd", "nodeC");
    topology.nodeAId = nodeA.getId();
    topology.nodeBId = nodeB.getId();
    topology.nodeCId = nodeC.getId();
    topology.nodeA = nodeA;
    topology.nodeB = nodeB;
    topology.nodeC = nodeC;
    BridgeBridgeLink ablink = new BridgeBridgeLink();
    ablink.setNode(nodeA);
    ablink.setBridgePort(topology.portAB);
    ablink.setDesignatedNode(nodeB);
    ablink.setDesignatedPort(topology.portBA);
    ablink.setBridgeBridgeLinkLastPollTime(ablink.getBridgeBridgeLinkCreateTime());
    m_bridgeBridgeLinkDao.save(ablink);
    BridgeBridgeLink bclink = new BridgeBridgeLink();
    bclink.setNode(nodeC);
    bclink.setBridgePort(topology.portCB);
    bclink.setDesignatedNode(nodeB);
    bclink.setDesignatedPort(topology.portBC);
    bclink.setBridgeBridgeLinkLastPollTime(ablink.getBridgeBridgeLinkCreateTime());
    m_bridgeBridgeLinkDao.save(bclink);
    BridgeMacLink mac1 = new BridgeMacLink();
    mac1.setNode(nodeA);
    mac1.setBridgePort(topology.portA);
    mac1.setMacAddress(topology.mac1);
    mac1.setBridgeMacLinkLastPollTime(mac1.getBridgeMacLinkCreateTime());
    m_bridgeMacLinkDao.save(mac1);
    BridgeMacLink mac2 = new BridgeMacLink();
    mac2.setNode(nodeB);
    mac2.setBridgePort(topology.portB);
    mac2.setMacAddress(topology.mac2);
    mac2.setBridgeMacLinkLastPollTime(mac2.getBridgeMacLinkCreateTime());
    m_bridgeMacLinkDao.save(mac2);
    BridgeMacLink mac3 = new BridgeMacLink();
    mac3.setNode(nodeC);
    mac3.setBridgePort(topology.portC);
    mac3.setMacAddress(topology.mac3);
    mac3.setBridgeMacLinkLastPollTime(mac3.getBridgeMacLinkCreateTime());
    m_bridgeMacLinkDao.save(mac3);
    m_bridgeMacLinkDao.flush();
    m_bridgeBridgeLinkDao.flush();
    assertEquals(3, m_bridgeMacLinkDao.countAll());
    assertEquals(2, m_bridgeBridgeLinkDao.countAll());
    assertNotNull(m_bridgeTopologyDao);
    m_linkd.getQueryManager().loadBridgeTopology();
    assertEquals(1, m_bridgeTopologyDao.getAll().size());
    BroadcastDomain nodeAbd = m_linkd.getQueryManager().getBroadcastDomain(nodeA.getId().intValue());
    assertNotNull(nodeAbd);
    BroadcastDomain nodeBbd = m_linkd.getQueryManager().getBroadcastDomain(nodeB.getId().intValue());
    assertNotNull(nodeBbd);
    assertEquals(nodeAbd, nodeBbd);
    BroadcastDomain nodeCbd = m_linkd.getQueryManager().getBroadcastDomain(nodeC.getId().intValue());
    assertNotNull(nodeCbd);
    assertEquals(nodeAbd, nodeCbd);
    assertNull(nodeAbd.getRootBridgeId());
    assertTrue(nodeAbd.containBridgeId(nodeA.getId()));
    assertTrue(nodeAbd.containBridgeId(nodeB.getId()));
    assertTrue(nodeAbd.containBridgeId(nodeC.getId()));
    nodeAbd.hierarchySetUp(nodeAbd.getBridge(nodeA.getId()));
    assertNotNull(nodeAbd.getRootBridgeId());
    topology.check(nodeAbd);
    m_linkd.deleteNode(nodeC.getId());
    assertEquals(1, m_bridgeTopologyDao.getAll().size());
    BroadcastDomain domain = m_bridgeTopologyDao.getAll().iterator().next();
    topology.checkAB(domain);
}
Also used : Nms10205bNetworkBuilder(org.opennms.netmgt.nb.Nms10205bNetworkBuilder) Nms17216NetworkBuilder(org.opennms.netmgt.nb.Nms17216NetworkBuilder) NetworkBuilder(org.opennms.netmgt.model.NetworkBuilder) OnmsNode(org.opennms.netmgt.model.OnmsNode) BroadcastDomain(org.opennms.netmgt.model.topology.BroadcastDomain) BridgeBridgeLink(org.opennms.netmgt.model.BridgeBridgeLink) BridgeMacLink(org.opennms.netmgt.model.BridgeMacLink) Test(org.junit.Test)

Aggregations

BridgeBridgeLink (org.opennms.netmgt.model.BridgeBridgeLink)14 BridgeMacLink (org.opennms.netmgt.model.BridgeMacLink)12 BroadcastDomain (org.opennms.netmgt.model.topology.BroadcastDomain)6 OnmsNode (org.opennms.netmgt.model.OnmsNode)5 SharedSegment (org.opennms.netmgt.model.topology.SharedSegment)5 Test (org.junit.Test)4 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 NetworkBuilder (org.opennms.netmgt.model.NetworkBuilder)3 Nms10205bNetworkBuilder (org.opennms.netmgt.nb.Nms10205bNetworkBuilder)3 Nms17216NetworkBuilder (org.opennms.netmgt.nb.Nms17216NetworkBuilder)3 IpNetToMedia (org.opennms.netmgt.model.IpNetToMedia)2 OnmsIpInterface (org.opennms.netmgt.model.OnmsIpInterface)2 BridgePort (org.opennms.netmgt.model.topology.BridgePort)2 InetAddress (java.net.InetAddress)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Set (java.util.Set)1 After (org.junit.After)1