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;
}
}
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);
}
Aggregations