Search in sources :

Example 36 with BridgeMacLink

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

the class NodeDiscoveryBridgeTopology method run.

@Override
public void run() {
    if (!m_linkd.getQueryManager().hasUpdatedBft(getNodeId())) {
        LOG.info("run: node: [{}], no bft.Exiting Bridge Topology Discovery", getNodeId());
        return;
    }
    List<BridgeMacLink> links = m_linkd.getQueryManager().getBridgeTopologyUpdateBFT(getNodeId());
    if (links == null || links.size() == 0) {
        LOG.info("run: node: [{}]. no updates macs found.", getNodeId());
        return;
    }
    Date now = new Date();
    Set<String> incomingSet = new HashSet<String>();
    synchronized (links) {
        for (BridgeMacLink link : links) {
            incomingSet.add(link.getMacAddress());
        }
    }
    LOG.debug("run: node: [{}]. macs found: {}", getNodeId(), incomingSet);
    LOG.info("run: node: [{}], getting broadcast domain. Start", getNodeId());
    for (BroadcastDomain domain : m_linkd.getQueryManager().getAllBroadcastDomains()) {
        LOG.debug("run: node: [{}], parsing domain with nodes: {}, macs: {}", getNodeId(), domain.getBridgeNodesOnDomain(), domain.getMacsOnDomain());
        Set<String> retainedSet = new HashSet<String>(domain.getMacsOnDomain());
        retainedSet.retainAll(incomingSet);
        LOG.debug("run: node: [{}], retained: {}", getNodeId(), retainedSet);
        // should contain at list 5 or 10% of the all size
        if (retainedSet.size() > DOMAIN_MATCH_MIN_SIZE || retainedSet.size() >= incomingSet.size() * DOMAIN_MATCH_MIN_RATIO) {
            if (LOG.isDebugEnabled()) {
                LOG.debug("run: node: [{}], domain {} found!", getNodeId(), domain.getBridgeNodesOnDomain());
            }
            m_domain = domain;
        // TODO: We should find the *best* domain, instead of using the last match
        }
    }
    if (m_domain == null) {
        LOG.debug("run: node: [{}] Creating a new Domain", getNodeId());
        m_domain = new BroadcastDomain();
        m_linkd.getQueryManager().save(m_domain);
    } else if (!m_domain.hasRootBridge()) {
        LOG.debug("run: node: [{}] Domain without root, clearing topology", getNodeId());
        m_domain.clearTopology();
    }
    LOG.info("run: node: [{}], getting broadcast domain. End", getNodeId());
    Map<Integer, List<BridgeMacLink>> nodeBftMap = m_linkd.getQueryManager().getUpdateBftMap();
    Set<Integer> nodeswithupdatedbftonbroadcastdomain = getAllNodesWithUpdatedBFTOnDomain(incomingSet, nodeBftMap);
    LOG.info("run: node: [{}], clean broadcast domains. Start", getNodeId());
    boolean clean = false;
    for (BroadcastDomain domain : m_linkd.getQueryManager().getAllBroadcastDomains()) {
        if (m_domain == domain)
            continue;
        if (LOG.isDebugEnabled()) {
            LOG.debug("run: node [{}]: cleaning broadcast domain {}.", getNodeId(), domain.getBridgeNodesOnDomain());
        }
        for (Integer curNodeId : nodeswithupdatedbftonbroadcastdomain) {
            if (domain.containBridgeId(curNodeId)) {
                if (LOG.isDebugEnabled()) {
                    LOG.debug("run: node [{}]: node [{}]: removing from broadcast domain {}!", getNodeId(), curNodeId, domain.getBridgeNodesOnDomain());
                }
                synchronized (domain) {
                    domain.clearTopologyForBridge(curNodeId);
                    domain.removeBridge(curNodeId);
                    m_linkd.getQueryManager().store(domain);
                    m_linkd.getQueryManager().reconcileBridgeTopology(domain, now);
                }
                clean = true;
            }
        }
    }
    if (clean) {
        m_linkd.getQueryManager().cleanBroadcastDomains();
    }
    LOG.info("run: node: [{}], clean broadcast domains. End", getNodeId());
    synchronized (m_domain) {
        m_notYetParsedBFTMap = new HashMap<Bridge, List<BridgeMacLink>>();
        for (Integer nodeid : nodeswithupdatedbftonbroadcastdomain) {
            sendStartEvent(nodeid);
            m_domain.addBridge(new Bridge(nodeid));
            LOG.debug("run: node: [{}], getting update bft for node [{}] on domain", getNodeId(), nodeid);
            List<BridgeMacLink> bft = m_linkd.getQueryManager().useBridgeTopologyUpdateBFT(nodeid);
            if (bft == null || bft.isEmpty()) {
                LOG.debug("run: node: [{}], no update bft for node [{}] on domain", getNodeId(), nodeid);
                continue;
            }
            m_notYetParsedBFTMap.put(m_domain.getBridge(nodeid), bft);
        }
        Set<Integer> nodetoberemovedondomain = new HashSet<Integer>();
        synchronized (nodeBftMap) {
            for (Integer nodeid : nodeBftMap.keySet()) {
                if (nodeswithupdatedbftonbroadcastdomain.contains(nodeid))
                    continue;
                LOG.info("run: node [{}]: bridge [{}] with updated bft. Not even more on broadcast domain {}: clear topology.", getNodeId(), nodeid, m_domain.getBridgeNodesOnDomain());
                nodetoberemovedondomain.add(nodeid);
            }
        }
        for (Integer nodeid : nodetoberemovedondomain) {
            m_domain.clearTopologyForBridge(nodeid);
            m_domain.removeBridge(nodeid);
        }
        m_linkd.getQueryManager().cleanBroadcastDomains();
        m_domain.setBridgeElements(m_linkd.getQueryManager().getBridgeElements(m_domain.getBridgeNodesOnDomain()));
        if (m_notYetParsedBFTMap.isEmpty()) {
            LOG.info("run: node: [{}], broadcast domain has no topology updates. No more action is needed.", getNodeId());
        } else {
            calculate();
        }
        LOG.info("run: node: [{}], saving Topology.", getNodeId());
        m_linkd.getQueryManager().store(m_domain);
        m_linkd.getQueryManager().reconcileBridgeTopology(m_domain, now);
        LOG.info("run: node: [{}], saved Topology.", getNodeId());
        for (Integer curNode : nodeswithupdatedbftonbroadcastdomain) {
            sendCompletedEvent(curNode);
        }
    }
}
Also used : Date(java.util.Date) BroadcastDomain(org.opennms.netmgt.model.topology.BroadcastDomain) ArrayList(java.util.ArrayList) List(java.util.List) BridgeMacLink(org.opennms.netmgt.model.BridgeMacLink) Bridge(org.opennms.netmgt.model.topology.Bridge) HashSet(java.util.HashSet)

Example 37 with BridgeMacLink

use of org.opennms.netmgt.model.BridgeMacLink 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_linkd.getQueryManager().getAllBroadcastDomains().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);
    assertTrue(nodeAbd.hasRootBridge());
    assertEquals(nodeAbd.getRootBridgeId().intValue(), nodeB.getId().intValue());
    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_linkd.getQueryManager().getAllBroadcastDomains().size());
    BroadcastDomain domain = m_linkd.getQueryManager().getAllBroadcastDomains().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)

Example 38 with BridgeMacLink

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

the class EnLinkdIT method testStoreBft.

@Test
public void testStoreBft() {
    OneBridgeCompleteTopology topology = new OneBridgeCompleteTopology();
    m_nodeDao.save(topology.nodeA);
    m_linkd.getQueryManager().updateBft(topology.nodeAId, topology.bftA);
    List<BridgeMacLink> links = m_linkd.getQueryManager().useBridgeTopologyUpdateBFT(topology.nodeAId);
    assertEquals(topology.bftA.size(), links.size());
    for (BridgeMacLink link : links) {
        assertEquals(BridgeDot1qTpFdbStatus.DOT1D_TP_FDB_STATUS_LEARNED, link.getBridgeDot1qTpFdbStatus());
        System.err.println(link.printTopology());
    }
}
Also used : BridgeMacLink(org.opennms.netmgt.model.BridgeMacLink) Test(org.junit.Test)

Example 39 with BridgeMacLink

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

the class Nms4930EnIT method checkTopologyDlink1.

private void checkTopologyDlink1(OnmsNode dlink1) {
    // port: 1—>1
    // port: 2—>2
    // port: 3—>1
    // port: 4—>8
    // port: 5—>2
    // port: 6—>14
    // port: 24—>30
    assertEquals(0, m_bridgeBridgeLinkDao.countAll());
    assertEquals(1, m_bridgeMacLinkDao.findByNodeIdBridgePort(dlink1.getId(), 1).size());
    assertEquals(2, m_bridgeMacLinkDao.findByNodeIdBridgePort(dlink1.getId(), 2).size());
    assertEquals(1, m_bridgeMacLinkDao.findByNodeIdBridgePort(dlink1.getId(), 3).size());
    assertEquals(8, m_bridgeMacLinkDao.findByNodeIdBridgePort(dlink1.getId(), 4).size());
    assertEquals(2, m_bridgeMacLinkDao.findByNodeIdBridgePort(dlink1.getId(), 5).size());
    assertEquals(14, m_bridgeMacLinkDao.findByNodeIdBridgePort(dlink1.getId(), 6).size());
    assertEquals(30, m_bridgeMacLinkDao.findByNodeIdBridgePort(dlink1.getId(), 24).size());
    assertEquals(58, m_bridgeMacLinkDao.countAll());
    assertEquals(2, m_bridgeMacLinkDao.getAllBridgeLinksToIpAddrToNodes().size());
    assertEquals(0, m_bridgeMacLinkDao.getAllBridgeLinksToBridgeNodes().size());
    for (BridgeMacLink maclink : m_bridgeMacLinkDao.findAll()) {
        assertEquals(null, maclink.getBridgeDot1qTpFdbStatus());
        assertNotNull(maclink.getBridgePortIfIndex());
        assertNotNull(maclink.getBridgePort());
        assertNotNull(maclink.getNode());
        assertNotNull(maclink.getMacAddress());
    }
}
Also used : BridgeMacLink(org.opennms.netmgt.model.BridgeMacLink)

Example 40 with BridgeMacLink

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

the class Nms4930EnIT method checkTopologyDlink2.

private void checkTopologyDlink2(OnmsNode dlink2) {
    assertEquals(0, m_bridgeBridgeLinkDao.countAll());
    // INTEGER: 1     35
    // INTEGER: 2      71
    // INTEGER: 3      29
    // INTEGER: 5     142
    // INTEGER: 6      47
    // INTEGER: 7       5
    // INTEGER: 8     123
    // INTEGER: 10     362
    // INTEGER: 12     163
    assertEquals(35, m_bridgeMacLinkDao.findByNodeIdBridgePort(dlink2.getId(), 1).size());
    assertEquals(71, m_bridgeMacLinkDao.findByNodeIdBridgePort(dlink2.getId(), 2).size());
    assertEquals(29, m_bridgeMacLinkDao.findByNodeIdBridgePort(dlink2.getId(), 3).size());
    assertEquals(142, m_bridgeMacLinkDao.findByNodeIdBridgePort(dlink2.getId(), 5).size());
    assertEquals(47, m_bridgeMacLinkDao.findByNodeIdBridgePort(dlink2.getId(), 6).size());
    assertEquals(5, m_bridgeMacLinkDao.findByNodeIdBridgePort(dlink2.getId(), 7).size());
    assertEquals(123, m_bridgeMacLinkDao.findByNodeIdBridgePort(dlink2.getId(), 8).size());
    assertEquals(362, m_bridgeMacLinkDao.findByNodeIdBridgePort(dlink2.getId(), 10).size());
    assertEquals(163, m_bridgeMacLinkDao.findByNodeIdBridgePort(dlink2.getId(), 12).size());
    // total number of entry in bridgemaclink: 977
    assertEquals(977, m_bridgeMacLinkDao.countAll());
    assertEquals(1, m_bridgeMacLinkDao.getAllBridgeLinksToIpAddrToNodes().size());
    assertEquals(0, m_bridgeMacLinkDao.getAllBridgeLinksToBridgeNodes().size());
    for (BridgeMacLink maclink : m_bridgeMacLinkDao.findAll()) {
        assertEquals(null, maclink.getBridgeDot1qTpFdbStatus());
        assertNotNull(maclink.getBridgePortIfIndex());
        assertNotNull(maclink.getBridgePort());
        assertNotNull(maclink.getNode());
        assertNotNull(maclink.getMacAddress());
    }
}
Also used : BridgeMacLink(org.opennms.netmgt.model.BridgeMacLink)

Aggregations

BridgeMacLink (org.opennms.netmgt.model.BridgeMacLink)51 Test (org.junit.Test)15 BridgeBridgeLink (org.opennms.netmgt.model.BridgeBridgeLink)15 OnmsNode (org.opennms.netmgt.model.OnmsNode)14 SharedSegment (org.opennms.netmgt.model.topology.SharedSegment)14 ArrayList (java.util.ArrayList)13 HashSet (java.util.HashSet)11 HashMap (java.util.HashMap)10 BroadcastDomain (org.opennms.netmgt.model.topology.BroadcastDomain)10 JUnitSnmpAgents (org.opennms.core.test.snmp.annotations.JUnitSnmpAgents)8 Bridge (org.opennms.netmgt.model.topology.Bridge)7 List (java.util.List)6 Date (java.util.Date)5 Set (java.util.Set)3 NetworkBuilder (org.opennms.netmgt.model.NetworkBuilder)3 OnmsIpInterface (org.opennms.netmgt.model.OnmsIpInterface)3 BridgePort (org.opennms.netmgt.model.topology.BridgePort)3 Nms10205bNetworkBuilder (org.opennms.netmgt.nb.Nms10205bNetworkBuilder)3 Nms17216NetworkBuilder (org.opennms.netmgt.nb.Nms17216NetworkBuilder)3 InetAddress (java.net.InetAddress)2