use of org.opennms.netmgt.enlinkd.snmp.OspfIpAddrTableGetter in project opennms by OpenNMS.
the class EnLinkdSnmpIT method testOspfIfTableWalk.
@Test
@JUnitSnmpAgents(value = { @JUnitSnmpAgent(host = SWITCH1_IP, port = 161, resource = "classpath:/linkd/nms17216/switch1-walk.txt") })
public void testOspfIfTableWalk() throws Exception {
SnmpAgentConfig config = SnmpPeerFactory.getInstance().getAgentConfig(InetAddress.getByName(SWITCH1_IP));
String trackerName = "ospfIfTable";
final List<OspfLink> links = new ArrayList<>();
OspfIfTableTracker ospfIfTableTracker = new OspfIfTableTracker() {
public void processOspfIfRow(final OspfIfRow row) {
links.add(row.getOspfLink());
}
};
try {
m_client.walk(config, ospfIfTableTracker).withDescription(trackerName).withLocation(null).execute().get();
} catch (final InterruptedException e) {
LOG.error("run: collection interrupted, exiting", e);
return;
}
final OspfIpAddrTableGetter ipAddrTableGetter = new OspfIpAddrTableGetter(config, m_client, null, 0);
for (OspfLink link : links) {
link = ipAddrTableGetter.get(link);
assertEquals(0, link.getOspfAddressLessIndex().intValue());
if (link.getOspfIpAddr().equals(InetAddress.getByName("192.168.100.246"))) {
assertEquals(10101, link.getOspfIfIndex().intValue());
assertEquals(InetAddress.getByName("255.255.255.252"), link.getOspfIpMask());
} else if (link.getOspfIpAddr().equals(InetAddress.getByName("172.16.10.1"))) {
assertEquals(10, link.getOspfIfIndex().intValue());
assertEquals(InetAddress.getByName("255.255.255.0"), link.getOspfIpMask());
} else if (link.getOspfIpAddr().equals(InetAddress.getByName("172.16.20.1"))) {
assertEquals(20, link.getOspfIfIndex().intValue());
assertEquals(InetAddress.getByName("255.255.255.0"), link.getOspfIpMask());
} else if (link.getOspfIpAddr().equals(InetAddress.getByName("172.16.30.1"))) {
assertEquals(30, link.getOspfIfIndex().intValue());
assertEquals(InetAddress.getByName("255.255.255.0"), link.getOspfIpMask());
} else if (link.getOspfIpAddr().equals(InetAddress.getByName("172.16.40.1"))) {
assertEquals(40, link.getOspfIfIndex().intValue());
assertEquals(InetAddress.getByName("255.255.255.0"), link.getOspfIpMask());
} else {
assertEquals(false, true);
}
}
}
use of org.opennms.netmgt.enlinkd.snmp.OspfIpAddrTableGetter 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);
}
use of org.opennms.netmgt.enlinkd.snmp.OspfIpAddrTableGetter in project opennms by OpenNMS.
the class EnLinkdSnmpIT method testOspfGeneralGroupWalk.
@Test
@JUnitSnmpAgents(value = { @JUnitSnmpAgent(host = SWITCH1_IP, port = 161, resource = "classpath:/linkd/nms17216/switch1-walk.txt") })
public void testOspfGeneralGroupWalk() throws Exception {
SnmpAgentConfig config = SnmpPeerFactory.getInstance().getAgentConfig(InetAddress.getByName(SWITCH1_IP));
String trackerName = "ospfGeneralGroup";
final OspfGeneralGroupTracker ospfGeneralGroup = new OspfGeneralGroupTracker();
try {
m_client.walk(config, ospfGeneralGroup).withDescription(trackerName).withLocation(null).execute().get();
} catch (final InterruptedException e) {
LOG.error("run: collection interrupted, exiting", e);
return;
}
OspfElement ospfElement = ospfGeneralGroup.getOspfElement();
assertEquals(InetAddress.getByName("192.168.100.246"), ospfElement.getOspfRouterId());
assertEquals(null, ospfElement.getOspfRouterIdNetmask());
assertEquals(null, ospfElement.getOspfRouterIdIfindex());
assertEquals(Status.enabled, ospfElement.getOspfAdminStat());
assertEquals(2, ospfElement.getOspfVersionNumber().intValue());
assertEquals(TruthValue.FALSE, ospfElement.getOspfBdrRtrStatus());
assertEquals(TruthValue.FALSE, ospfElement.getOspfASBdrRtrStatus());
final OspfIpAddrTableGetter ipAddrTableGetter = new OspfIpAddrTableGetter(config, m_client, null, 0);
OspfElement ospfElementN = ipAddrTableGetter.get(ospfElement);
assertEquals(InetAddress.getByName("192.168.100.246"), ospfElementN.getOspfRouterId());
assertEquals(InetAddress.getByName("255.255.255.252"), ospfElementN.getOspfRouterIdNetmask());
assertEquals(10101, ospfElementN.getOspfRouterIdIfindex().intValue());
assertEquals(Status.enabled, ospfElementN.getOspfAdminStat());
assertEquals(2, ospfElementN.getOspfVersionNumber().intValue());
assertEquals(TruthValue.FALSE, ospfElementN.getOspfBdrRtrStatus());
assertEquals(TruthValue.FALSE, ospfElementN.getOspfASBdrRtrStatus());
}
Aggregations