Search in sources :

Example 1 with BridgeStpLink

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

the class NodeDiscoveryBridge method walkSpanningTree.

private List<BridgeStpLink> walkSpanningTree(SnmpAgentConfig peer, final String baseBridgeAddress) {
    final List<BridgeStpLink> stplinks = new ArrayList<>();
    Dot1dStpPortTableTracker stpPortTableTracker = new Dot1dStpPortTableTracker() {

        @Override
        public void processDot1dStpPortRow(final Dot1dStpPortRow row) {
            BridgeStpLink link = row.getLink();
            LOG.debug("processDot1dStpPortRow: node [{}]: stp: port:{}/{}, vlan:{}, designated root/bridge/port:{}/{}/{}.", getNodeId(), link.getStpPort(), link.getStpPortState(), link.getVlan(), link.getDesignatedRoot(), link.getDesignatedBridge(), link.getDesignatedPort());
            if (isValidStpBridgeId(link.getDesignatedRoot()) && isValidStpBridgeId(link.getDesignatedBridge()) && !baseBridgeAddress.equals(link.getDesignatedBridgeAddress())) {
                LOG.debug("processDot1dStpPortRow: node [{}]: stp: port:{}/{}, vlan:{}, designated root/bridge/port:{}/{}/{}. row added", getNodeId(), link.getStpPort(), link.getStpPortState(), link.getVlan(), link.getDesignatedRoot(), link.getDesignatedBridge(), link.getDesignatedPort());
                stplinks.add(link);
            }
        }
    };
    try {
        m_linkd.getLocationAwareSnmpClient().walk(peer, stpPortTableTracker).withDescription("dot1dStpPortTable").withLocation(getLocation()).execute().get();
    } catch (ExecutionException e) {
        LOG.info("run: node [{}]: ExecutionException: dot1dStpPortTable: {}", getNodeId(), e.getMessage());
    } catch (final InterruptedException e) {
        LOG.info("run: node [{}]: InterruptedException: dot1dStpPortTable: {}", getNodeId(), e.getMessage());
    }
    return stplinks;
}
Also used : BridgeStpLink(org.opennms.netmgt.model.BridgeStpLink) ArrayList(java.util.ArrayList) Dot1dStpPortTableTracker(org.opennms.netmgt.enlinkd.snmp.Dot1dStpPortTableTracker) ExecutionException(java.util.concurrent.ExecutionException)

Example 2 with BridgeStpLink

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

the class EnLinkdSnmpIT method testDot1dStpPortTableWalk.

@Test
@JUnitSnmpAgents(value = { @JUnitSnmpAgent(host = DLINK1_IP, port = 161, resource = DLINK1_SNMP_RESOURCE) })
public void testDot1dStpPortTableWalk() throws Exception {
    String trackerName = "dot1dbaseStpTable";
    final List<BridgeStpLink> links = new ArrayList<>();
    SnmpAgentConfig config = SnmpPeerFactory.getInstance().getAgentConfig(InetAddress.getByName(DLINK1_IP));
    Dot1dStpPortTableTracker tracker = new Dot1dStpPortTableTracker() {

        @Override
        public void processDot1dStpPortRow(final Dot1dStpPortRow row) {
            links.add(row.getLink());
        }
    };
    try {
        m_client.walk(config, tracker).withDescription(trackerName).withLocation(null).execute().get();
    } catch (final InterruptedException e) {
        LOG.error("run: collection interrupted, exiting", e);
        return;
    }
    assertEquals(26, links.size());
    int i = 0;
    for (BridgeStpLink link : links) {
        assertEquals(++i, link.getStpPort().intValue());
        assertEquals(128, link.getStpPortPriority().intValue());
        if (link.getStpPort() <= 6 || link.getStpPort() == 24)
            assertEquals(BridgeDot1dStpPortState.DOT1D_STP_PORT_STATUS_FORWARDING, link.getStpPortState());
        else
            assertEquals(BridgeDot1dStpPortState.DOT1D_STP_PORT_STATUS_DISABLED, link.getStpPortState());
        assertEquals(BridgeDot1dStpPortEnable.DOT1D_STP_PORT_ENABLED, link.getStpPortEnable());
        assertEquals(2000000, link.getStpPortPathCost().intValue());
        assertEquals("0000000000000000", link.getDesignatedRoot());
        assertEquals(0, link.getDesignatedCost().intValue());
        assertEquals("0000000000000000", link.getDesignatedBridge());
        assertEquals("0000", link.getDesignatedPort());
    }
}
Also used : SnmpAgentConfig(org.opennms.netmgt.snmp.SnmpAgentConfig) BridgeStpLink(org.opennms.netmgt.model.BridgeStpLink) ArrayList(java.util.ArrayList) Dot1dStpPortTableTracker(org.opennms.netmgt.enlinkd.snmp.Dot1dStpPortTableTracker) Test(org.junit.Test) JUnitSnmpAgents(org.opennms.core.test.snmp.annotations.JUnitSnmpAgents)

Example 3 with BridgeStpLink

use of org.opennms.netmgt.model.BridgeStpLink 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)

Aggregations

ArrayList (java.util.ArrayList)3 BridgeStpLink (org.opennms.netmgt.model.BridgeStpLink)3 Dot1dStpPortTableTracker (org.opennms.netmgt.enlinkd.snmp.Dot1dStpPortTableTracker)2 SnmpAgentConfig (org.opennms.netmgt.snmp.SnmpAgentConfig)2 Date (java.util.Date)1 HashMap (java.util.HashMap)1 ExecutionException (java.util.concurrent.ExecutionException)1 Test (org.junit.Test)1 JUnitSnmpAgents (org.opennms.core.test.snmp.annotations.JUnitSnmpAgents)1 BridgeElement (org.opennms.netmgt.model.BridgeElement)1 BridgeMacLink (org.opennms.netmgt.model.BridgeMacLink)1