Search in sources :

Example 1 with Dot1dStpPortTableTracker

use of org.opennms.netmgt.enlinkd.snmp.Dot1dStpPortTableTracker 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 Dot1dStpPortTableTracker

use of org.opennms.netmgt.enlinkd.snmp.Dot1dStpPortTableTracker 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)

Aggregations

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