Search in sources :

Example 1 with OspfNbrTableTracker

use of org.opennms.netmgt.enlinkd.snmp.OspfNbrTableTracker in project opennms by OpenNMS.

the class EnLinkdSnmpIT method testOspfNbrTableWalk.

@Test
@JUnitSnmpAgents(value = { @JUnitSnmpAgent(host = SWITCH1_IP, port = 161, resource = "classpath:/linkd/nms17216/switch1-walk.txt") })
public void testOspfNbrTableWalk() throws Exception {
    SnmpAgentConfig config = SnmpPeerFactory.getInstance().getAgentConfig(InetAddress.getByName(SWITCH1_IP));
    String trackerName = "ospfNbrTable";
    OspfNbrTableTracker ospfNbrTableTracker = new OspfNbrTableTracker() {

        public void processOspfNbrRow(final OspfNbrRow row) {
            OspfLink link = row.getOspfLink();
            try {
                assertEquals(InetAddress.getByName("192.168.100.249"), link.getOspfRemRouterId());
                assertEquals(InetAddress.getByName("192.168.100.245"), link.getOspfRemIpAddr());
            } catch (UnknownHostException e) {
                e.printStackTrace();
            }
            assertEquals(0, link.getOspfRemAddressLessIndex().intValue());
        }
    };
    try {
        m_client.walk(config, ospfNbrTableTracker).withDescription(trackerName).withLocation(null).execute().get();
    } catch (final InterruptedException e) {
        LOG.error("run: collection interrupted, exiting", e);
        return;
    }
}
Also used : SnmpAgentConfig(org.opennms.netmgt.snmp.SnmpAgentConfig) UnknownHostException(java.net.UnknownHostException) OspfNbrTableTracker(org.opennms.netmgt.enlinkd.snmp.OspfNbrTableTracker) OspfLink(org.opennms.netmgt.model.OspfLink) Test(org.junit.Test) JUnitSnmpAgents(org.opennms.core.test.snmp.annotations.JUnitSnmpAgents)

Example 2 with OspfNbrTableTracker

use of org.opennms.netmgt.enlinkd.snmp.OspfNbrTableTracker in project opennms by OpenNMS.

the class NodeDiscoveryOspf method runCollection.

protected void runCollection() {
    final Date now = new Date();
    SnmpAgentConfig peer = m_linkd.getSnmpAgentConfig(getPrimaryIpAddress(), getLocation());
    final OspfIpAddrTableGetter ipAddrTableGetter = new OspfIpAddrTableGetter(peer, m_linkd.getLocationAwareSnmpClient(), getLocation(), getNodeId());
    final OspfGeneralGroupTracker ospfGeneralGroup = new OspfGeneralGroupTracker();
    try {
        m_linkd.getLocationAwareSnmpClient().walk(peer, ospfGeneralGroup).withDescription("ospfGeneralGroup").withLocation(getLocation()).execute().get();
    } catch (ExecutionException e) {
        LOG.info("run: node [{}]: ExecutionException: ospfGeneralGroup: {}", getNodeId(), e.getMessage());
        return;
    } catch (final InterruptedException e) {
        LOG.info("run: node [{}]: InterruptedException: ospfGeneralGroup: {}", getNodeId(), e.getMessage());
        return;
    }
    if (ospfGeneralGroup.getOspfRouterId() == null) {
        LOG.info("run: node[{}]: ospf mib not supported", getNodeId());
        return;
    }
    if (ospfGeneralGroup.getOspfRouterId().equals(InetAddressUtils.addr("0.0.0.0"))) {
        LOG.info("run: node[{}]: not valid ospf identifier 0.0.0.0", getNodeId());
        return;
    }
    if (Status.get(ospfGeneralGroup.getOspfAdminStat()) == Status.disabled) {
        LOG.info("run: node[{}]: ospf status: disabled", getNodeId());
        return;
    }
    m_linkd.getQueryManager().store(getNodeId(), ipAddrTableGetter.get(ospfGeneralGroup.getOspfElement()));
    final List<OspfLink> links = new ArrayList<>();
    OspfNbrTableTracker ospfNbrTableTracker = new OspfNbrTableTracker() {

        public void processOspfNbrRow(final OspfNbrRow row) {
            links.add(row.getOspfLink());
        }
    };
    try {
        m_linkd.getLocationAwareSnmpClient().walk(peer, ospfNbrTableTracker).withDescription("ospfNbrTable").withLocation(getLocation()).execute().get();
    } catch (ExecutionException e) {
        LOG.info("run: node [{}]: ExecutionException: ospfNbrTable: {}", getNodeId(), e.getMessage());
        return;
    } catch (final InterruptedException e) {
        LOG.info("run: node [{}]: InterruptedException: ospfNbrTable: {}", getNodeId(), e.getMessage());
        return;
    }
    List<OspfLink> localOspfPorts = new ArrayList<>();
    OspfIfTableTracker ospfIfTableTracker = new OspfIfTableTracker() {

        public void processOspfIfRow(final OspfIfRow row) {
            localOspfPorts.add(row.getOspfLink());
        }
    };
    try {
        m_linkd.getLocationAwareSnmpClient().walk(peer, ospfIfTableTracker).withDescription("ospfIfTable").withLocation(getLocation()).execute().get();
    } catch (ExecutionException e) {
        LOG.info("run: node [{}]: ExecutionException: ospfIfTable: {}", getNodeId(), e.getMessage());
        return;
    } catch (final InterruptedException e) {
        LOG.info("run: node [{}]: InterruptedException: ospfIfTable: {}", getNodeId(), e.getMessage());
        return;
    }
    for (OspfLink link : links) {
        for (OspfLink localospfport : localOspfPorts) {
            if (localospfport.getOspfAddressLessIndex() != 0 && link.getOspfRemAddressLessIndex() != 0) {
                link.setOspfIpAddr(localospfport.getOspfIpAddr());
                link.setOspfAddressLessIndex(localospfport.getOspfAddressLessIndex());
                link.setOspfIfIndex(localospfport.getOspfAddressLessIndex());
                break;
            }
            if (localospfport.getOspfAddressLessIndex() == 0 && link.getOspfRemAddressLessIndex() != 0)
                continue;
            if (localospfport.getOspfAddressLessIndex() != 0 && link.getOspfRemAddressLessIndex() == 0)
                continue;
            localospfport = ipAddrTableGetter.get(localospfport);
            if (InetAddressUtils.inSameNetwork(localospfport.getOspfIpAddr(), link.getOspfRemIpAddr(), localospfport.getOspfIpMask())) {
                link.setOspfIpAddr(localospfport.getOspfIpAddr());
                link.setOspfAddressLessIndex(localospfport.getOspfAddressLessIndex());
                link.setOspfIpMask(localospfport.getOspfIpMask());
                link.setOspfIfIndex(localospfport.getOspfIfIndex());
                break;
            }
        }
        m_linkd.getQueryManager().store(getNodeId(), link);
    }
    m_linkd.getQueryManager().reconcileOspf(getNodeId(), now);
}
Also used : SnmpAgentConfig(org.opennms.netmgt.snmp.SnmpAgentConfig) OspfIfTableTracker(org.opennms.netmgt.enlinkd.snmp.OspfIfTableTracker) ArrayList(java.util.ArrayList) OspfNbrTableTracker(org.opennms.netmgt.enlinkd.snmp.OspfNbrTableTracker) Date(java.util.Date) OspfIpAddrTableGetter(org.opennms.netmgt.enlinkd.snmp.OspfIpAddrTableGetter) OspfGeneralGroupTracker(org.opennms.netmgt.enlinkd.snmp.OspfGeneralGroupTracker) ExecutionException(java.util.concurrent.ExecutionException) OspfLink(org.opennms.netmgt.model.OspfLink)

Aggregations

OspfNbrTableTracker (org.opennms.netmgt.enlinkd.snmp.OspfNbrTableTracker)2 OspfLink (org.opennms.netmgt.model.OspfLink)2 SnmpAgentConfig (org.opennms.netmgt.snmp.SnmpAgentConfig)2 UnknownHostException (java.net.UnknownHostException)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 ExecutionException (java.util.concurrent.ExecutionException)1 Test (org.junit.Test)1 JUnitSnmpAgents (org.opennms.core.test.snmp.annotations.JUnitSnmpAgents)1 OspfGeneralGroupTracker (org.opennms.netmgt.enlinkd.snmp.OspfGeneralGroupTracker)1 OspfIfTableTracker (org.opennms.netmgt.enlinkd.snmp.OspfIfTableTracker)1 OspfIpAddrTableGetter (org.opennms.netmgt.enlinkd.snmp.OspfIpAddrTableGetter)1