use of org.opennms.netmgt.model.LldpLink in project opennms by OpenNMS.
the class NodeDiscoveryLldp method runCollection.
protected void runCollection() {
final Date now = new Date();
final LldpLocalGroupTracker lldpLocalGroup = new LldpLocalGroupTracker();
SnmpAgentConfig peer = m_linkd.getSnmpAgentConfig(getPrimaryIpAddress(), getLocation());
try {
m_linkd.getLocationAwareSnmpClient().walk(peer, lldpLocalGroup).withDescription("lldpLocalGroup").withLocation(getLocation()).execute().get();
} catch (ExecutionException e) {
LOG.info("run: Agent error while scanning the lldpLocalGroup table", e);
return;
} catch (final InterruptedException e) {
LOG.info("run: Lldp Linkd lldpLocalGroup table collection interrupted", e);
return;
}
if (lldpLocalGroup.getLldpLocChassisid() == null) {
LOG.info("run: node[{}]: address {}. LLDP_MIB not supported", getNodeId(), getPrimaryIpAddressString());
return;
} else {
LOG.info("run: node[{}]: address {}. lldp identifier : {}", getNodeId(), getPrimaryIpAddressString(), lldpLocalGroup.getLldpElement());
}
m_linkd.getQueryManager().store(getNodeId(), lldpLocalGroup.getLldpElement());
if (getSysoid() == null || getSysoid().equals(DW_SYSOID)) {
if (lldpLocalGroup.getLldpLocChassisid().toHexString().equals(DW_NULL_CHASSIS_ID) && lldpLocalGroup.getLldpLocChassisidSubType() == LldpChassisIdSubType.LLDP_CHASSISID_SUBTYPE_CHASSISCOMPONENT.getValue()) {
LOG.info("run: node[{}]: address {}. lldp identifier : {}. lldp not active for Dragon Wave Device.", getNodeId(), getPrimaryIpAddressString(), lldpLocalGroup.getLldpElement());
return;
}
if (lldpLocalGroup.getLldpLocSysname().equals(DW_NULL_SYSOID_ID)) {
LOG.info("run: node[{}]: address {}. lldp identifier : {}. lldp not active for Dragon Wave Device.", getNodeId(), getPrimaryIpAddressString(), lldpLocalGroup.getLldpElement());
return;
}
}
List<LldpLink> links = new ArrayList<LldpLink>();
LldpRemTableTracker lldpRemTable = new LldpRemTableTracker() {
public void processLldpRemRow(final LldpRemRow row) {
links.add(row.getLldpLink());
}
};
try {
m_linkd.getLocationAwareSnmpClient().walk(peer, lldpRemTable).withDescription("lldpRemTable").withLocation(getLocation()).execute().get();
} catch (ExecutionException e) {
LOG.error("run: collection execution failed, exiting", e);
return;
} catch (final InterruptedException e) {
LOG.error("run: collection interrupted, exiting", e);
return;
}
final LldpLocPortGetter lldpLocPort = new LldpLocPortGetter(peer, m_linkd.getLocationAwareSnmpClient(), getLocation());
for (LldpLink link : links) m_linkd.getQueryManager().store(getNodeId(), lldpLocPort.getLldpLink(link));
m_linkd.getQueryManager().reconcileLldp(getNodeId(), now);
}
use of org.opennms.netmgt.model.LldpLink in project opennms by OpenNMS.
the class Nms0123EnIT method testItpn0111Lldp.
/*
*
*
*/
@Test
@JUnitSnmpAgents(value = { @JUnitSnmpAgent(host = ITPN0111_IP, port = 161, resource = ITPN0111_SNMP_RESOURCE) })
public void testItpn0111Lldp() throws Exception {
m_nodeDao.save(builder.getItpn0111());
m_nodeDao.flush();
m_linkdConfig.getConfiguration().setUseBridgeDiscovery(false);
m_linkdConfig.getConfiguration().setUseCdpDiscovery(false);
m_linkdConfig.getConfiguration().setUseOspfDiscovery(false);
m_linkdConfig.getConfiguration().setUseLldpDiscovery(true);
m_linkdConfig.getConfiguration().setUseIsisDiscovery(false);
assertTrue(m_linkdConfig.useLldpDiscovery());
assertTrue(!m_linkdConfig.useCdpDiscovery());
assertTrue(!m_linkdConfig.useOspfDiscovery());
assertTrue(!m_linkdConfig.useBridgeDiscovery());
assertTrue(!m_linkdConfig.useIsisDiscovery());
final OnmsNode itpn0111 = m_nodeDao.findByForeignId("linkd", ITPN0111_NAME);
assertTrue(m_linkd.scheduleNodeCollection(itpn0111.getId()));
assertEquals(0, m_lldpLinkDao.countAll());
assertTrue(m_linkd.runSingleSnmpCollection(itpn0111.getId()));
for (final OnmsNode node : m_nodeDao.findAll()) {
if (node.getLldpElement() != null)
printLldpElement(node.getLldpElement());
}
final List<LldpLink> topologyA = m_lldpLinkDao.findAll();
assertEquals(4, topologyA.size());
printLldpTopology(topologyA);
}
use of org.opennms.netmgt.model.LldpLink in project opennms by OpenNMS.
the class Nms0002EnIT method testNetworkLinksCiscoJuniperLldp.
/*
*
* nodelabel | snmpifname | ifindex | parent | parentif | parentifindex
* --------------------+--------------+---------+--------------------+------------+---------------
* r-de-pots-amka-001 | Fa6/0/0 | 164 | r-de-juet-luck-001 | ge-0/0/0.0 | 510
* r-de-juet-luck-001 | ge-0/0/2.100 | 549 | s-de-juet-luck-001 | Fa0/1 | 10001
* r-de-juet-luck-001 | ge-0/0/2.950 | 550 | s-de-juet-luck-001 | Fa0/1 | 10001 *
*
* The links are mostly from the bridge forwarding table protocol in fact the
* ge-0/0/2.100 and ge-0/0/2.950 are logical interface for vlan 100 and
* vlan 950 on juniper router. with the same mac address 54e032ef3102
* So both vlan 100 and vlan 950 will address the same link
* No way to get layer 2 link because no STP is enabled on Juniper device
*
*/
@Test
@JUnitSnmpAgents(value = { @JUnitSnmpAgent(host = Rluck001_IP, port = 161, resource = Rluck001_SNMP_RESOURCE), @JUnitSnmpAgent(host = Sluck001_IP, port = 161, resource = Sluck001_SNMP_RESOURCE) })
public void testNetworkLinksCiscoJuniperLldp() throws Exception {
m_nodeDao.save(builder.getRluck001());
m_nodeDao.save(builder.getSluck001());
m_nodeDao.flush();
m_linkdConfig.getConfiguration().setUseBridgeDiscovery(false);
m_linkdConfig.getConfiguration().setUseCdpDiscovery(false);
m_linkdConfig.getConfiguration().setUseOspfDiscovery(false);
m_linkdConfig.getConfiguration().setUseLldpDiscovery(true);
m_linkdConfig.getConfiguration().setUseIsisDiscovery(false);
assertTrue(m_linkdConfig.useLldpDiscovery());
assertTrue(!m_linkdConfig.useCdpDiscovery());
assertTrue(!m_linkdConfig.useOspfDiscovery());
assertTrue(!m_linkdConfig.useBridgeDiscovery());
assertTrue(!m_linkdConfig.useIsisDiscovery());
final OnmsNode routerJuniper = m_nodeDao.findByForeignId("linkd", Rluck001_NAME);
final OnmsNode switchCisco = m_nodeDao.findByForeignId("linkd", Sluck001_NAME);
assertTrue(m_linkd.scheduleNodeCollection(routerJuniper.getId()));
assertTrue(m_linkd.scheduleNodeCollection(switchCisco.getId()));
assertEquals(0, m_lldpLinkDao.countAll());
assertTrue(m_linkd.runSingleSnmpCollection(routerJuniper.getId()));
final List<LldpLink> topologyA = m_lldpLinkDao.findAll();
printLldpTopology(topologyA);
assertEquals(1, m_lldpLinkDao.countAll());
for (final OnmsNode node : m_nodeDao.findAll()) {
if (node.getLldpElement() != null)
printLldpElement(node.getLldpElement());
}
assertTrue(m_linkd.runSingleSnmpCollection(switchCisco.getId()));
Thread.sleep(1000);
assertTrue(m_linkd.runSingleSnmpCollection(switchCisco.getId()));
final List<LldpLink> topologyB = m_lldpLinkDao.findAll();
printLldpTopology(topologyB);
assertEquals(2, topologyB.size());
for (final OnmsNode node : m_nodeDao.findAll()) {
if (node.getLldpElement() != null)
printLldpElement(node.getLldpElement());
}
}
use of org.opennms.netmgt.model.LldpLink in project opennms by OpenNMS.
the class Nms8000EnIT method testLldpLinks.
@Test
@JUnitSnmpAgents(value = { @JUnitSnmpAgent(host = NMMR1_IP, port = 161, resource = NMMR1_SNMP_RESOURCE_2), @JUnitSnmpAgent(host = NMMR2_IP, port = 161, resource = NMMR2_SNMP_RESOURCE_2), @JUnitSnmpAgent(host = NMMR3_IP, port = 161, resource = NMMR3_SNMP_RESOURCE_2), @JUnitSnmpAgent(host = NMMSW1_IP, port = 161, resource = NMMSW1_SNMP_RESOURCE_2), @JUnitSnmpAgent(host = NMMSW2_IP, port = 161, resource = NMMSW2_SNMP_RESOURCE_2) })
public void testLldpLinks() throws Exception {
m_nodeDao.save(builder.getNMMR1());
m_nodeDao.save(builder.getNMMR2());
m_nodeDao.save(builder.getNMMR3());
m_nodeDao.save(builder.getNMMSW1());
m_nodeDao.save(builder.getNMMSW2());
m_nodeDao.flush();
m_linkdConfig.getConfiguration().setUseBridgeDiscovery(false);
m_linkdConfig.getConfiguration().setUseCdpDiscovery(false);
m_linkdConfig.getConfiguration().setUseOspfDiscovery(false);
m_linkdConfig.getConfiguration().setUseLldpDiscovery(true);
m_linkdConfig.getConfiguration().setUseIsisDiscovery(false);
assertTrue(m_linkdConfig.useLldpDiscovery());
assertTrue(!m_linkdConfig.useCdpDiscovery());
assertTrue(!m_linkdConfig.useOspfDiscovery());
assertTrue(!m_linkdConfig.useBridgeDiscovery());
assertTrue(!m_linkdConfig.useIsisDiscovery());
final OnmsNode nmmr1 = m_nodeDao.findByForeignId("linkd", NMMR1_NAME);
final OnmsNode nmmr2 = m_nodeDao.findByForeignId("linkd", NMMR2_NAME);
final OnmsNode nmmr3 = m_nodeDao.findByForeignId("linkd", NMMR3_NAME);
final OnmsNode nmmsw1 = m_nodeDao.findByForeignId("linkd", NMMSW1_NAME);
final OnmsNode nmmsw2 = m_nodeDao.findByForeignId("linkd", NMMSW2_NAME);
assertTrue(m_linkd.scheduleNodeCollection(nmmr1.getId()));
assertTrue(m_linkd.scheduleNodeCollection(nmmr2.getId()));
assertTrue(m_linkd.scheduleNodeCollection(nmmr3.getId()));
assertTrue(m_linkd.scheduleNodeCollection(nmmsw1.getId()));
assertTrue(m_linkd.scheduleNodeCollection(nmmsw2.getId()));
assertTrue(m_linkd.runSingleSnmpCollection(nmmr1.getId()));
assertEquals(3, m_lldpLinkDao.countAll());
assertTrue(m_linkd.runSingleSnmpCollection(nmmr2.getId()));
assertEquals(6, m_lldpLinkDao.countAll());
assertTrue(m_linkd.runSingleSnmpCollection(nmmr3.getId()));
assertEquals(8, m_lldpLinkDao.countAll());
assertTrue(m_linkd.runSingleSnmpCollection(nmmsw1.getId()));
assertEquals(10, m_lldpLinkDao.countAll());
assertTrue(m_linkd.runSingleSnmpCollection(nmmsw2.getId()));
assertEquals(12, m_lldpLinkDao.countAll());
for (final OnmsNode node : m_nodeDao.findAll()) {
assertNotNull(node.getLldpElement());
printLldpElement(node.getLldpElement());
}
for (LldpLink link : m_lldpLinkDao.findAll()) {
printLldpLink(link);
}
List<LldpLink> allLinks = m_lldpLinkDao.findAll();
int combinedlinkfound = 0;
Set<Integer> parsed = new HashSet<Integer>();
for (LldpLink sourceLink : allLinks) {
System.err.println("loadtopology: parsing lldp link with id " + sourceLink.getId());
if (parsed.contains(sourceLink.getId())) {
continue;
}
parsed.add(sourceLink.getId());
LldpElement sourceElement = m_nodeDao.get(sourceLink.getNode().getId()).getLldpElement();
LldpLink targetLink = null;
for (LldpLink link : allLinks) {
if (parsed.contains(link.getId())) {
continue;
}
LldpElement element = m_nodeDao.get(link.getNode().getId()).getLldpElement();
//Compare the remote data to the targetNode element data
if (!sourceLink.getLldpRemChassisId().equals(element.getLldpChassisId()) || !link.getLldpRemChassisId().equals(sourceElement.getLldpChassisId()))
continue;
boolean bool1 = sourceLink.getLldpRemPortId().equals(link.getLldpPortId()) && link.getLldpRemPortId().equals(sourceLink.getLldpPortId());
boolean bool2 = sourceLink.getLldpRemPortDescr().equals(link.getLldpPortDescr()) && link.getLldpRemPortDescr().equals(sourceLink.getLldpPortDescr());
boolean bool3 = sourceLink.getLldpRemPortIdSubType() == link.getLldpPortIdSubType() && link.getLldpRemPortIdSubType() == sourceLink.getLldpPortIdSubType();
if (bool1 && bool2 && bool3) {
targetLink = link;
parsed.add(targetLink.getId());
System.err.println("loadtopology: lldp link with id " + link.getId() + " is target.");
break;
}
}
if (targetLink == null) {
final org.opennms.core.criteria.Criteria criteria = new org.opennms.core.criteria.Criteria(OnmsNode.class).addRestriction(new EqRestriction("sysName", sourceLink.getLldpRemSysname()));
List<OnmsNode> nodes = m_nodeDao.findMatching(criteria);
if (nodes.size() == 1) {
targetLink = reverseLldpLink(nodes.get(0), sourceLink.getNode().getLldpElement(), sourceLink);
System.err.println("loadtopology: found using sysname: lldp link with id " + targetLink + " is target.");
}
}
if (targetLink == null) {
continue;
}
combinedlinkfound++;
}
assertEquals(6, combinedlinkfound);
}
use of org.opennms.netmgt.model.LldpLink in project opennms by OpenNMS.
the class Nms7563EnIT method testHomeServerLinks.
@Test
@JUnitSnmpAgents(value = { @JUnitSnmpAgent(host = HOMESERVER_IP, port = 161, resource = HOMESERVER_SNMP_RESOURCE) })
public void testHomeServerLinks() throws Exception {
m_nodeDao.save(builder.getHomeServer());
m_nodeDao.flush();
m_linkdConfig.getConfiguration().setUseBridgeDiscovery(false);
m_linkdConfig.getConfiguration().setUseOspfDiscovery(false);
m_linkdConfig.getConfiguration().setUseIsisDiscovery(false);
m_linkdConfig.getConfiguration().setUseCdpDiscovery(false);
assertTrue(!m_linkdConfig.useIsisDiscovery());
assertTrue(!m_linkdConfig.useBridgeDiscovery());
assertTrue(!m_linkdConfig.useOspfDiscovery());
assertTrue(m_linkdConfig.useLldpDiscovery());
assertTrue(!m_linkdConfig.useCdpDiscovery());
final OnmsNode homeserver = m_nodeDao.findByForeignId("linkd", HOMESERVER_NAME);
assertTrue(m_linkd.scheduleNodeCollection(homeserver.getId()));
assertTrue(m_linkd.runSingleSnmpCollection(homeserver.getId()));
for (final OnmsNode node : m_nodeDao.findAll()) {
assertNotNull(node.getLldpElement());
printLldpElement(node.getLldpElement());
assertEquals(LldpChassisIdSubType.LLDP_CHASSISID_SUBTYPE_MACADDRESS, node.getLldpElement().getLldpChassisIdSubType());
assertEquals(HOMESERVER_LLDP_CHASSID_ID, node.getLldpElement().getLldpChassisId());
assertEquals(HOMESERVER_LLDP_SYSNAME, node.getLldpElement().getLldpSysname());
}
assertEquals(1, m_lldpLinkDao.countAll());
for (LldpLink link : m_lldpLinkDao.findAll()) {
assertNotNull(link);
printLldpLink(link);
assertEquals(2, link.getLldpLocalPortNum().intValue());
assertNull(link.getLldpPortIfindex());
assertEquals(LldpPortIdSubType.LLDP_PORTID_SUBTYPE_MACADDRESS, link.getLldpPortIdSubType());
assertEquals(HOMESERVER_IF_MAC_MAP.get(2), link.getLldpPortId());
assertEquals("eth0", link.getLldpPortDescr());
assertEquals(LldpChassisIdSubType.LLDP_CHASSISID_SUBTYPE_MACADDRESS, link.getLldpRemChassisIdSubType());
assertEquals(SWITCH02_LLDP_CHASSID_ID, link.getLldpRemChassisId());
assertEquals(SWITCH02_LLDP_SYSNAME, link.getLldpRemSysname());
assertEquals(LldpPortIdSubType.LLDP_PORTID_SUBTYPE_LOCAL, link.getLldpRemPortIdSubType());
assertEquals("7", link.getLldpRemPortId());
assertEquals("7", link.getLldpRemPortDescr());
}
}
Aggregations