Search in sources :

Example 16 with BridgeMacLink

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

the class BroadcastDomain method calculateBFT.

public List<BridgeMacLink> calculateBFT(Bridge bridge) {
    Map<Integer, Set<String>> bft = new HashMap<Integer, Set<String>>();
    Integer bridgeId = bridge.getId();
    List<BridgeMacLink> links = new ArrayList<BridgeMacLink>();
    OnmsNode node = new OnmsNode();
    node.setId(bridgeId);
    for (SharedSegment segment : getTopology()) {
        Set<String> macs = segment.getMacsOnSegment();
        if (macs == null || macs.isEmpty())
            continue;
        Integer bridgeport = goUp(segment, bridge, 0);
        if (!bft.containsKey(bridgeport))
            bft.put(bridgeport, new HashSet<String>());
        bft.get(bridgeport).addAll(macs);
    }
    for (Integer bridgePort : bft.keySet()) {
        for (String mac : bft.get(bridgePort)) {
            BridgeMacLink link = new BridgeMacLink();
            link.setNode(node);
            link.setBridgePort(bridgePort);
            link.setMacAddress(mac);
            link.setBridgeDot1qTpFdbStatus(BridgeDot1qTpFdbStatus.DOT1D_TP_FDB_STATUS_LEARNED);
            links.add(link);
        }
    }
    return links;
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) OnmsNode(org.opennms.netmgt.model.OnmsNode) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) BridgeMacLink(org.opennms.netmgt.model.BridgeMacLink) HashSet(java.util.HashSet)

Example 17 with BridgeMacLink

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

the class EnhancedLinkdServiceImpl method store.

@Override
public void store(int nodeId, List<BridgeMacLink> bft) {
    Map<BridgeMacLinkHash, BridgeMacLink> effectiveBFT = new HashMap<BridgeMacLinkHash, BridgeMacLink>();
    for (BridgeMacLink link : bft) {
        OnmsNode node = new OnmsNode();
        node.setId(nodeId);
        link.setNode(node);
        effectiveBFT.put(new BridgeMacLinkHash(link), link);
    }
    m_nodetoBroadcastDomainMap.put(nodeId, new ArrayList<BridgeMacLink>(effectiveBFT.values()));
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) HashMap(java.util.HashMap) BridgeMacLinkHash(org.opennms.netmgt.model.topology.BridgeMacLinkHash) BridgeMacLink(org.opennms.netmgt.model.BridgeMacLink)

Example 18 with BridgeMacLink

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

the class NodeDiscoveryBridgeTopology method getAllNodesWithUpdatedBFTOnDomain.

private Set<Integer> getAllNodesWithUpdatedBFTOnDomain(Set<String> incomingSet, Map<Integer, List<BridgeMacLink>> nodeBftMap) {
    Set<Integer> nodeswithupdatedbftonbroadcastdomain = new HashSet<Integer>();
    nodeswithupdatedbftonbroadcastdomain.add(getNodeId());
    LOG.info("run: node: [{}], getting nodes with updated bft on broadcast domain. Start", getNodeId());
    for (Integer curNodeId : nodeBftMap.keySet()) {
        if (curNodeId.intValue() == getNodeId())
            continue;
        Set<String> retainedSet = new HashSet<String>();
        for (BridgeMacLink link : nodeBftMap.get(curNodeId)) {
            retainedSet.add(link.getMacAddress());
        }
        LOG.debug("run: node: [{}], parsing updated bft node: [{}], macs {}", getNodeId(), curNodeId, retainedSet);
        retainedSet.retainAll(incomingSet);
        LOG.debug("run: node: [{}], node: [{}] - common mac address set: {}", getNodeId(), curNodeId, retainedSet);
        if (retainedSet.size() > 10 || retainedSet.size() >= incomingSet.size() * 0.1) {
            nodeswithupdatedbftonbroadcastdomain.add(curNodeId);
            LOG.debug("run: node: [{}], node: [{}] - put on same broadcast domain, common macs: {} ", getNodeId(), curNodeId, retainedSet);
        }
    }
    LOG.info("run: node: [{}], getting nodes with updated bft on broadcast domain. End", getNodeId());
    return nodeswithupdatedbftonbroadcastdomain;
}
Also used : BridgeMacLink(org.opennms.netmgt.model.BridgeMacLink) HashSet(java.util.HashSet)

Example 19 with BridgeMacLink

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

the class NodeDiscoveryBridgeTopology method loadFirstLevelSharedSegment.

private void loadFirstLevelSharedSegment(List<BridgeMacLink> electedRootBFT) {
    Map<Integer, SharedSegment> rootleafs = new HashMap<Integer, SharedSegment>();
    for (BridgeMacLink link : electedRootBFT) {
        if (link.getBridgeDot1qTpFdbStatus() != BridgeDot1qTpFdbStatus.DOT1D_TP_FDB_STATUS_LEARNED)
            continue;
        if (rootleafs.containsKey(link.getBridgePort()))
            rootleafs.get(link.getBridgePort()).add(link);
        else
            rootleafs.put(link.getBridgePort(), new SharedSegment(m_domain, link));
    }
    for (SharedSegment rootleaf : rootleafs.values()) {
        LOG.debug("calculate: node [{}]: add shared segment[designated bridge:[{}]," + "designated port:{}, macs: {}]", getNodeId(), rootleaf.getDesignatedBridge(), rootleaf.getDesignatedPort(), rootleaf.getMacsOnSegment());
        m_domain.add(rootleaf);
    }
}
Also used : HashMap(java.util.HashMap) SharedSegment(org.opennms.netmgt.model.topology.SharedSegment) BridgeMacLink(org.opennms.netmgt.model.BridgeMacLink)

Example 20 with BridgeMacLink

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

the class NodeDiscoveryBridgeTopology method calculate.

protected void calculate() {
    LOG.debug("calculate: node[{}]: Print Topology {}", getNodeId(), m_domain.printTopology());
    LOG.info("calculate: node: [{}]: start: broadcast domain {} topology calculation.", getNodeId(), m_domain.getBridgeNodesOnDomain());
    Bridge electedRoot = m_domain.electRootBridge();
    if (electedRoot == null && m_domain.hasRootBridge()) {
        LOG.debug("calculate: node [{}]: electRootBridge: mantaining old root bridge: {}", getNodeId(), m_domain.getRootBridgeId());
        electedRoot = m_domain.getRootBridge();
    } else if (electedRoot == null) {
        // no spanning tree root?
        // why I'm here?
        // not root bridge defined (this mean no calculation yet done...
        // so checking the best into not parsed
        int size = 0;
        Bridge rootBridge = null;
        for (Bridge bridge : m_notYetParsedBFTMap.keySet()) {
            LOG.debug("calculate: node [{}]: bridge [{}]: max bft size \"{}\" in topology", getNodeId(), bridge.getId(), m_notYetParsedBFTMap.get(bridge).size());
            if (size < m_notYetParsedBFTMap.get(bridge).size()) {
                rootBridge = bridge;
                size = m_notYetParsedBFTMap.get(bridge).size();
            }
        }
        if (rootBridge != null) {
            LOG.debug("calculate: node [{}]: bridge [{}]: elected root with max bft size \"{}\" in topology", getNodeId(), rootBridge.getId(), size);
            electedRoot = rootBridge;
        }
    }
    if (electedRoot == null) {
        electedRoot = m_domain.getBridges().iterator().next();
        LOG.debug("calculate: node [{}]: electRootBridge: first root bridge: {}", getNodeId(), electedRoot.getId());
    }
    if (electedRoot == null || electedRoot.getId() == null) {
        LOG.error("calculate: [{}]: electedRootBridge should not be null", getNodeId());
        return;
    }
    List<BridgeMacLink> rootBft = m_notYetParsedBFTMap.remove(electedRoot);
    if (m_domain.hasRootBridge() && m_domain.getRootBridge().getId() == electedRoot.getId() && rootBft == null) {
        LOG.debug("calculate: node [{}]: elected root bridge: [{}], old root bridge. no updated bft", getNodeId(), electedRoot.getId());
        rootBft = m_domain.calculateRootBFT();
    } else if (m_domain.hasRootBridge() && m_domain.getRootBridge().getId() == electedRoot.getId() && rootBft != null) {
        LOG.debug("calculate: node [{}]: elected root bridge: [{}], old root bridge. updated bft", getNodeId(), electedRoot.getId());
        if (m_domain.getTopology().isEmpty()) {
            LOG.debug("calculate: node [{}]: elected root bridge: [{}], clean topology found. Adding root shared segments", getNodeId(), electedRoot.getId());
            loadFirstLevelSharedSegment(rootBft);
        }
    } else if (rootBft != null) {
        LOG.debug("calculate: node [{}]: elected root bridge: [{}], new root. updated bft", getNodeId(), electedRoot.getId());
        if (m_domain.getTopology().isEmpty()) {
            LOG.debug("calculate: node [{}]: new elected root bridge: [{}], is the first bridge in topology. Adding root shared segments", getNodeId(), electedRoot.getId());
            loadFirstLevelSharedSegment(rootBft);
            electedRoot.setRootBridge(true);
            electedRoot.setRootPort(null);
        } else {
            m_domain.clearTopologyForBridge(electedRoot.getId());
            calculate(m_domain.getRootBridge(), m_domain.calculateRootBFT(), electedRoot, rootBft);
            m_domain.hierarchySetUp(electedRoot);
        }
    } else {
        LOG.debug("calculate: node [{}]: elected root bridge: [{}], is new root bridge with old bft", getNodeId(), electedRoot.getId());
        m_domain.hierarchySetUp(electedRoot);
        rootBft = m_domain.calculateRootBFT();
    }
    LOG.debug("calculate: node[{}]: Root Bridge [{}] elected.", getNodeId(), electedRoot.getId(), m_domain.printTopology());
    for (Bridge xBridge : m_notYetParsedBFTMap.keySet()) {
        m_domain.clearTopologyForBridge(xBridge.getId());
        LOG.debug("calculate: node[{}]: Removed bridge: [{}].", getNodeId(), xBridge.getId());
    }
    LOG.debug("calculate: node[{}]: Print Topology {}", getNodeId(), m_domain.printTopology());
    Set<Bridge> nodetobeparsed = new HashSet<Bridge>(m_notYetParsedBFTMap.keySet());
    for (Bridge xBridge : nodetobeparsed) {
        LOG.info("calculate: node: [{}]: bridge [{}]: calculate topology: start.", getNodeId(), xBridge.getId());
        calculate(electedRoot, rootBft, xBridge, new ArrayList<BridgeMacLink>(m_notYetParsedBFTMap.remove(xBridge)));
        LOG.info("calculate: node: [{}]: bridge [{}]: calculate topology: stop.", getNodeId(), xBridge.getId());
    }
    LOG.info("calculate: node: [{}]: stop: broadcast domain {} topology calculated.", getNodeId(), m_domain.getBridgeNodesOnDomain());
    LOG.debug("calculate: node[{}]: Print Topology {}", getNodeId(), m_domain.printTopology());
}
Also used : BridgeMacLink(org.opennms.netmgt.model.BridgeMacLink) Bridge(org.opennms.netmgt.model.topology.Bridge) HashSet(java.util.HashSet)

Aggregations

BridgeMacLink (org.opennms.netmgt.model.BridgeMacLink)42 Test (org.junit.Test)15 OnmsNode (org.opennms.netmgt.model.OnmsNode)13 BridgeBridgeLink (org.opennms.netmgt.model.BridgeBridgeLink)12 SharedSegment (org.opennms.netmgt.model.topology.SharedSegment)10 ArrayList (java.util.ArrayList)9 HashSet (java.util.HashSet)9 BroadcastDomain (org.opennms.netmgt.model.topology.BroadcastDomain)9 JUnitSnmpAgents (org.opennms.core.test.snmp.annotations.JUnitSnmpAgents)8 HashMap (java.util.HashMap)7 Bridge (org.opennms.netmgt.model.topology.Bridge)6 List (java.util.List)4 Date (java.util.Date)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 Set (java.util.Set)2