Search in sources :

Example 31 with BridgeMacLink

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

the class BroadcastDomain method printTopologyBFT.

public static String printTopologyBFT(List<BridgeMacLink> bft) {
    final StringBuilder strbfr = new StringBuilder();
    for (BridgeMacLink link : bft) {
        strbfr.append("nodeid:[");
        strbfr.append(link.getNode().getId());
        strbfr.append("]:");
        strbfr.append(link.getMacAddress());
        strbfr.append(":bridgeport:");
        strbfr.append(link.getBridgePort());
        strbfr.append(":ifindex:");
        strbfr.append(link.getBridgePortIfIndex());
        strbfr.append("\n");
    }
    return strbfr.toString();
}
Also used : BridgeMacLink(org.opennms.netmgt.model.BridgeMacLink)

Example 32 with BridgeMacLink

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

the class BroadcastDomain method cleanForwarders.

public void cleanForwarders(Set<String> macs) {
    Map<Integer, List<BridgeMacLink>> forwadingMap = new HashMap<Integer, List<BridgeMacLink>>();
    for (Integer bridgeId : m_forwarding.keySet()) {
        List<BridgeMacLink> forwarders = new ArrayList<BridgeMacLink>();
        for (BridgeMacLink forward : m_forwarding.get(bridgeId)) {
            if (macs.contains(forward.getMacAddress()))
                continue;
            forwarders.add(forward);
        }
        if (forwarders.isEmpty())
            continue;
        forwadingMap.put(bridgeId, forwarders);
    }
    m_forwarding = forwadingMap;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) BridgeMacLink(org.opennms.netmgt.model.BridgeMacLink)

Example 33 with BridgeMacLink

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

the class EnhancedLinkdServiceImpl method updateBft.

@Override
public void updateBft(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);
    }
    synchronized (m_nodetoBroadcastDomainMap) {
        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 34 with BridgeMacLink

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

the class NodeDiscoveryBridge method runCollection.

protected void runCollection() {
    final Date now = new Date();
    SnmpAgentConfig peer = m_linkd.getSnmpAgentConfig(getPrimaryIpAddress(), getLocation());
    String community = peer.getReadCommunity();
    Map<Integer, String> vlanmap = getVtpVlanMap(peer);
    Map<Integer, SnmpAgentConfig> vlanSnmpAgentConfigMap = new HashMap<Integer, SnmpAgentConfig>();
    for (Integer vlanId : vlanmap.keySet()) {
        LOG.debug("run: node [{}], support cisco vtp: setting peer community for vlan: {}, vlanname: {}", getNodeId(), vlanId, vlanmap.get(vlanId));
        SnmpAgentConfig vlanpeer = m_linkd.getSnmpAgentConfig(getPrimaryIpAddress(), getLocation());
        if (vlanpeer.isVersion3()) {
            vlanpeer.setContextName("vlan-" + vlanId);
        } else {
            vlanpeer.setReadCommunity(community + "@" + vlanId);
        }
        vlanSnmpAgentConfigMap.put(vlanId, vlanpeer);
    }
    if (vlanmap.isEmpty()) {
        vlanSnmpAgentConfigMap.put(null, peer);
        vlanmap.put(null, null);
    }
    List<BridgeMacLink> bft = new ArrayList<>();
    Map<Integer, Integer> bridgeifindex = new HashMap<Integer, Integer>();
    for (Entry<Integer, SnmpAgentConfig> entry : vlanSnmpAgentConfigMap.entrySet()) {
        Map<Integer, Integer> vlanbridgetoifindex = walkDot1dBasePortTable(entry.getValue());
        LOG.debug("run: node: [{}], vlan: {}, bridge ifindex map {}", getNodeId(), vlanmap.get(entry.getKey()), vlanbridgetoifindex);
        bridgeifindex.putAll(vlanbridgetoifindex);
    }
    for (Entry<Integer, String> entry : vlanmap.entrySet()) {
        BridgeElement bridge = getDot1dBridgeBase(vlanSnmpAgentConfigMap.get(entry.getKey()));
        if (bridge != null) {
            bridge.setVlan(entry.getKey());
            bridge.setVlanname(vlanmap.get(entry.getKey()));
            m_linkd.getQueryManager().store(getNodeId(), bridge);
        } else {
            LOG.info("run: node: [{}], vlan {}. no dot1d bridge data found. skipping other operations", getNodeId(), entry.getValue());
            continue;
        }
        if (!isValidStpBridgeId(bridge.getStpDesignatedRoot())) {
            LOG.info("run: node: [{}], vlan {}. invalid designated root: spanning tree not supported.", getNodeId(), entry.getValue());
        } else if (bridge.getBaseBridgeAddress().equals(getBridgeAddressFromStpBridgeId(bridge.getStpDesignatedRoot()))) {
            LOG.info("run: node [{}]: vlan {}. designated root {} is itself. Skipping store.", getNodeId(), entry.getValue(), bridge.getStpDesignatedRoot());
        } else {
            for (BridgeStpLink stplink : walkSpanningTree(vlanSnmpAgentConfigMap.get(entry.getKey()), bridge.getBaseBridgeAddress())) {
                stplink.setVlan(entry.getKey());
                stplink.setStpPortIfIndex(bridgeifindex.get(stplink.getStpPort()));
                m_linkd.getQueryManager().store(getNodeId(), stplink);
            }
        }
        bft = walkDot1dTpFdp(entry.getValue(), entry.getKey(), bridgeifindex, bft, vlanSnmpAgentConfigMap.get(entry.getKey()));
    }
    LOG.debug("run: node [{}]: bridge ifindex map {}", getNodeId(), bridgeifindex);
    bft = walkDot1qTpFdb(peer, bridgeifindex, bft);
    LOG.debug("run: node [{}]: bft size:{}", getNodeId(), bft.size());
    if (bft.size() > 0) {
        LOG.debug("run: node [{}]: updating topology", getNodeId());
        m_linkd.getQueryManager().updateBft(getNodeId(), bft);
        m_linkd.scheduleBridgeTopologyDiscovery(getNodeId());
    }
    LOG.debug("run: node [{}]: deleting older the time {}", getNodeId(), now);
    m_linkd.collectedBft(getNodeId());
    m_linkd.getQueryManager().reconcileBridge(getNodeId(), now);
}
Also used : SnmpAgentConfig(org.opennms.netmgt.snmp.SnmpAgentConfig) HashMap(java.util.HashMap) BridgeStpLink(org.opennms.netmgt.model.BridgeStpLink) ArrayList(java.util.ArrayList) BridgeElement(org.opennms.netmgt.model.BridgeElement) Date(java.util.Date) BridgeMacLink(org.opennms.netmgt.model.BridgeMacLink)

Example 35 with BridgeMacLink

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

the class NodeDiscoveryBridgeTopology method findBridgesTopo.

// here we assume that rbridge exists in topology
// while xBridge is to be added
private boolean findBridgesTopo(BridgeTopologyHelper rx, SharedSegment topSegment, Bridge xBridge, List<BridgeMacLink> xBFT, int level) {
    if (topSegment == null) {
        LOG.warn("calculate: node: [{}]: level: {}, bridge: [{}], top segment is null exiting.....", getNodeId(), level, xBridge.getId());
        return false;
    }
    level++;
    if (level == 30) {
        LOG.warn("calculate: node: [{}]: level: {}, bridge: [{}], too many iteration on topology exiting.....", getNodeId(), level, xBridge.getId());
        return false;
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("calculate: node: [{}], level: {}, bridge: [{}], checking if is child of segment: [ids {}, designated bridge {}, port {}, macs {}]", getNodeId(), level, xBridge.getId(), topSegment.getBridgeIdsOnSegment(), topSegment.getDesignatedBridge(), topSegment.getDesignatedPort(), topSegment.getMacsOnSegment());
    }
    Set<Integer> portsAdded = new HashSet<Integer>();
    Set<String> macsOnSegment = rx.getSimpleConnectionMacs();
    Map<Integer, List<BridgeMacLink>> bftSets = new HashMap<Integer, List<BridgeMacLink>>();
    List<BridgeMacLink> forwarders = new ArrayList<BridgeMacLink>();
    forwarders.addAll(rx.getFirstBridgeForwarders());
    forwarders.addAll(rx.getSecondBridgeForwarders());
    for (Bridge yBridge : m_domain.getBridgeOnSharedSegment(topSegment)) {
        bftSets.put(yBridge.getId(), m_domain.calculateBFT(yBridge));
    }
    for (Bridge yBridge : m_domain.getBridgeOnSharedSegment(topSegment)) {
        Integer yBridgeId = yBridge.getId();
        // X is a leaf of top segment: of course
        if (yBridgeId.intValue() == topSegment.getDesignatedBridge().intValue()) {
            continue;
        }
        Integer yrDesignatedPort = yBridge.getRootPort();
        LOG.debug("calculate: node: [{}], level: {}, bridge: [{}], bridge: [{}, designated port: {}]", getNodeId(), level, xBridge.getId(), yBridgeId, yrDesignatedPort);
        BridgeTopologyHelper yx = new BridgeTopologyHelper(yBridge, bftSets.get(yBridgeId), xBridge, xBFT);
        Integer xyDesignatedPort = yx.getSecondBridgeConnectionPort();
        Integer yxDesignatedPort = yx.getFirstBridgeConnectionPort();
        // if X is a leaf of Y then iterate
        if (xyDesignatedPort == rx.getSecondBridgeConnectionPort() && yxDesignatedPort != yrDesignatedPort) {
            LOG.debug("calculate: node: [{}]: level: {}, bridge: [{}] is a leaf of bridge: [{}], going one level down", getNodeId(), level, xBridge.getId(), yBridge.getId());
            if (!findBridgesTopo(yx, m_domain.getSharedSegment(yBridgeId, yxDesignatedPort), xBridge, xBFT, level))
                return false;
            return true;
        }
        // Clean also topSegment macs.
        if (yxDesignatedPort == yrDesignatedPort && xyDesignatedPort != rx.getSecondBridgeConnectionPort()) {
            // create a SharedSegment with root port
            LOG.info("calculate: node: [{}], level: {}, bridge: [{},designated port [{}]]: found level.", getNodeId(), level, xBridge.getId(), xyDesignatedPort);
            LOG.debug("calculate: node: [{}], level: {}, bridge: [{},designated port [{}]]: is 'up' for bridge: [{}].", getNodeId(), level, xBridge.getId(), xyDesignatedPort, yBridge.getId());
            SharedSegment leafSegment = m_domain.getSharedSegment(xBridge.getId(), xyDesignatedPort);
            if (leafSegment == null) {
                leafSegment = new SharedSegment(m_domain, yx.getSimpleConnection(), yx.getSimpleConnectionMacs());
                leafSegment.setDesignatedBridge(xBridge.getId());
                m_domain.add(leafSegment);
            } else {
                leafSegment.retain(yx.getSimpleConnectionMacs(), yx.getFirstBridgePort());
            }
            portsAdded.add(xyDesignatedPort);
            if (LOG.isDebugEnabled()) {
                LOG.debug("calculate: node: [{}], level: {}, bridge [{}]. Remove bridge [{}] and macs {} from top segment.", getNodeId(), level, xBridge.getId(), yBridge.getId(), topSegment.getMacsOnSegment());
            }
            topSegment.getMacsOnSegment().clear();
            topSegment.removeBridge(yBridgeId);
        } else if (xyDesignatedPort != rx.getSecondBridgeConnectionPort() && yxDesignatedPort != yrDesignatedPort) {
            LOG.warn("calculate: node: [{}]: level {}: bridge [{}]. Topology mismatch. Clearing...topology", getNodeId(), level, xBridge.getId());
            return false;
        } else {
            macsOnSegment.retainAll(yx.getSimpleConnectionMacs());
        }
        forwarders.addAll(yx.getFirstBridgeForwarders());
        forwarders.addAll(yx.getSecondBridgeForwarders());
    }
    // if we are here is because X is NOT a leaf of any bridge found
    // on topSegment so X is connected to top Segment by it's root
    // port or rx is a direct connection
    LOG.debug("calculate: node: [{}]: level: {}, bridge: [{}]. assign macs {} to top segment", getNodeId(), level, xBridge.getId(), macsOnSegment);
    topSegment.assign(macsOnSegment, rx.getSecondBridgePort());
    if (LOG.isDebugEnabled()) {
        LOG.debug("calculate: node: [{}]: level: {}, bridge: [{}]. resulting top segment: [ids {}, designated bridge [{}, port: {}], mac : {}]", getNodeId(), level, xBridge.getId(), topSegment.getBridgeIdsOnSegment(), topSegment.getDesignatedBridge(), topSegment.getDesignatedPort(), topSegment.getMacsOnSegment());
    }
    for (Integer xbridgePort : rx.getSecondBridgeTroughSetBft().keySet()) {
        if (portsAdded.contains(xbridgePort))
            continue;
        SharedSegment xleafSegment = new SharedSegment(m_domain, rx.getSecondBridgeTroughSetBft().get(xbridgePort));
        xleafSegment.setDesignatedBridge(xBridge.getId());
        m_domain.add(xleafSegment);
        if (LOG.isDebugEnabled()) {
            LOG.debug("calculate: node: [{}]: level: {}, bridge: [{}]. Add shared segment. " + "[ designated bridge:[{}], " + "port:{}, " + "mac: {}]", getNodeId(), level, xBridge.getId(), xleafSegment.getDesignatedBridge(), xleafSegment.getDesignatedPort(), xleafSegment.getMacsOnSegment());
        }
    }
    addForwarding(m_domain, forwarders);
    return true;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) SharedSegment(org.opennms.netmgt.model.topology.SharedSegment) BridgeMacLink(org.opennms.netmgt.model.BridgeMacLink) Bridge(org.opennms.netmgt.model.topology.Bridge) HashSet(java.util.HashSet)

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