use of org.opennms.netmgt.model.LldpElement in project opennms by OpenNMS.
the class EnhancedLinkdTopologyProvider method getLldpLinks.
private void getLldpLinks(Map<Integer, OnmsNode> nodemap, Map<Integer, List<OnmsSnmpInterface>> nodesnmpmap, Map<Integer, OnmsIpInterface> ipprimarymap) {
// Index the nodes by sysName
final Map<String, OnmsNode> nodesbysysname = new HashMap<>();
for (OnmsNode node : nodemap.values()) {
if (node.getSysName() != null) {
nodesbysysname.putIfAbsent(node.getSysName(), node);
}
}
// Index the LLDP elements by node id
Map<Integer, LldpElement> lldpelementmap = new HashMap<Integer, LldpElement>();
for (LldpElement lldpelement : m_lldpElementDao.findAll()) {
lldpelementmap.put(lldpelement.getNode().getId(), lldpelement);
}
// Pull all of the LLDP links and index them by remote chassis id
List<LldpLink> allLinks = m_lldpLinkDao.findAll();
Map<String, List<LldpLink>> linksByRemoteChassisId = new HashMap<>();
for (LldpLink link : allLinks) {
final String remoteChassisId = link.getLldpRemChassisId();
List<LldpLink> linksWithRemoteChassisId = linksByRemoteChassisId.get(remoteChassisId);
if (linksWithRemoteChassisId == null) {
linksWithRemoteChassisId = new ArrayList<>();
linksByRemoteChassisId.put(remoteChassisId, linksWithRemoteChassisId);
}
linksWithRemoteChassisId.add(link);
}
Set<LldpLinkDetail> combinedLinkDetails = new HashSet<LldpLinkDetail>();
Set<Integer> parsed = new HashSet<Integer>();
for (LldpLink sourceLink : allLinks) {
if (parsed.contains(sourceLink.getId())) {
continue;
}
LOG.debug("loadtopology: lldp link with id '{}' link '{}' ", sourceLink.getId(), sourceLink);
LldpElement sourceLldpElement = lldpelementmap.get(sourceLink.getNode().getId());
LldpLink targetLink = null;
// Limit the candidate links by only choosing those have a remote chassis id matching the chassis id of the source link
for (LldpLink link : linksByRemoteChassisId.getOrDefault(sourceLldpElement.getLldpChassisId(), Collections.emptyList())) {
if (parsed.contains(link.getId())) {
continue;
}
if (sourceLink.getId().intValue() == link.getId().intValue()) {
continue;
}
LOG.debug("loadtopology: checking lldp link with id '{}' link '{}' ", link.getId(), link);
LldpElement element = lldpelementmap.get(link.getNode().getId());
// Compare the chassis id on the other end of the link
if (!sourceLink.getLldpRemChassisId().equals(element.getLldpChassisId())) {
continue;
}
boolean bool1 = sourceLink.getLldpRemPortId().equals(link.getLldpPortId()) && link.getLldpRemPortId().equals(sourceLink.getLldpPortId());
boolean bool3 = sourceLink.getLldpRemPortIdSubType() == link.getLldpPortIdSubType() && link.getLldpRemPortIdSubType() == sourceLink.getLldpPortIdSubType();
if (bool1 && bool3) {
targetLink = link;
LOG.info("loadtopology: found lldp mutual link: '{}' and '{}' ", sourceLink, targetLink);
break;
}
}
if (targetLink == null && sourceLink.getLldpRemSysname() != null) {
final OnmsNode node = nodesbysysname.get(sourceLink.getLldpRemSysname());
if (node != null) {
targetLink = reverseLldpLink(node, sourceLldpElement, sourceLink);
LOG.info("loadtopology: found lldp link using lldp rem sysname: '{}' and '{}'", sourceLink, targetLink);
}
}
if (targetLink == null) {
LOG.info("loadtopology: cannot found target node for link: '{}'", sourceLink);
continue;
}
parsed.add(sourceLink.getId());
parsed.add(targetLink.getId());
Vertex source = getOrCreateVertex(nodemap.get(sourceLink.getNode().getId()), ipprimarymap.get(sourceLink.getNode().getId()));
Vertex target = getOrCreateVertex(nodemap.get(targetLink.getNode().getId()), ipprimarymap.get(targetLink.getNode().getId()));
combinedLinkDetails.add(new LldpLinkDetail(Math.min(sourceLink.getId(), targetLink.getId()) + "|" + Math.max(sourceLink.getId(), targetLink.getId()), source, sourceLink, target, targetLink));
}
for (LldpLinkDetail linkDetail : combinedLinkDetails) {
LinkdEdge edge = connectVertices(linkDetail, LLDP_EDGE_NAMESPACE);
edge.setTooltipText(getEdgeTooltipText(linkDetail, nodesnmpmap));
}
}
use of org.opennms.netmgt.model.LldpElement in project opennms by OpenNMS.
the class EnhancedLinkdMockDataPopulator method populateDatabase.
public void populateDatabase() {
final String icmp = "ICMP";
final String snmp = "SNMP";
final String http = "HTTP";
final NetworkBuilder builder = new NetworkBuilder();
setNode1(builder.addNode("node1").setForeignSource("imported:").setForeignId("1").setType(OnmsNode.NodeType.ACTIVE).setSysObjectId("1.3.6.1.4.1.5813.1.25").getNode());
Assert.assertNotNull("newly built node 1 should not be null", getNode1());
builder.setBuilding("HQ");
builder.addSnmpInterface(1).setCollectionEnabled(true).setIfOperStatus(1).setIfSpeed(10000000).setIfDescr("ATM0").setIfAlias("Initial ifAlias value").setIfType(37).addIpInterface("192.168.1.1").setIsManaged("M").setIsSnmpPrimary("P");
builder.addService(icmp);
builder.addService(snmp);
builder.addSnmpInterface(2).setCollectionEnabled(true).setIfOperStatus(1).setIfSpeed(10000000).setIfName("eth0").setIfType(6).addIpInterface("192.168.1.2").setIsManaged("M").setIsSnmpPrimary("S");
builder.addService(icmp);
builder.addService(http);
builder.addSnmpInterface(3).setCollectionEnabled(false).setIfOperStatus(1).setIfSpeed(10000000).addIpInterface("192.168.1.3").setIsManaged("M").setIsSnmpPrimary("N");
builder.addService(icmp);
builder.addSnmpInterface(4).setCollectionEnabled(false).setIfOperStatus(1).setIfSpeed(10000000).addIpInterface("fe80:0000:0000:0000:aaaa:bbbb:cccc:dddd%5").setIsManaged("M").setIsSnmpPrimary("N");
builder.addService(icmp);
final OnmsNode node1 = builder.getCurrentNode();
node1.setLldpElement(new LldpElement(node1, "node1ChassisId", "node1SysName", LldpChassisIdSubType.LLDP_CHASSISID_SUBTYPE_LOCAL));
setNode1(node1);
builder.addNode("node2").setForeignSource("imported:").setForeignId("2").setType(OnmsNode.NodeType.ACTIVE);
builder.setBuilding("HQ");
builder.addInterface("192.168.2.1").setIsManaged("M").setIsSnmpPrimary("P");
builder.addService(icmp);
builder.addService(snmp);
builder.addInterface("192.168.2.2").setIsManaged("M").setIsSnmpPrimary("S");
builder.addService(icmp);
builder.addService(http);
builder.addInterface("192.168.2.3").setIsManaged("M").setIsSnmpPrimary("N");
builder.addService(icmp);
OnmsNode node2 = builder.getCurrentNode();
node2.setLldpElement(new LldpElement(node2, "node2ChassisId", "node2SysName", LldpChassisIdSubType.LLDP_CHASSISID_SUBTYPE_LOCAL));
setNode2(node2);
builder.addNode("node3").setForeignSource("imported:").setForeignId("3").setType(OnmsNode.NodeType.ACTIVE);
builder.addInterface("192.168.3.1").setIsManaged("M").setIsSnmpPrimary("P");
builder.addService(icmp);
builder.addService(snmp);
builder.addInterface("192.168.3.2").setIsManaged("M").setIsSnmpPrimary("S");
builder.addService(icmp);
builder.addService(http);
builder.addInterface("192.168.3.3").setIsManaged("M").setIsSnmpPrimary("N");
builder.addService(icmp);
OnmsNode node3 = builder.getCurrentNode();
node3.setLldpElement(new LldpElement(node3, "node3ChassisId", "node3SysName", LldpChassisIdSubType.LLDP_CHASSISID_SUBTYPE_LOCAL));
setNode3(node3);
builder.addNode("node4").setForeignSource("imported:").setForeignId("4").setType(OnmsNode.NodeType.ACTIVE);
builder.addInterface("192.168.4.1").setIsManaged("M").setIsSnmpPrimary("P");
builder.addService(icmp);
builder.addService(snmp);
builder.addInterface("192.168.4.2").setIsManaged("M").setIsSnmpPrimary("S");
builder.addService(icmp);
builder.addService(http);
builder.addInterface("192.168.4.3").setIsManaged("M").setIsSnmpPrimary("N");
builder.addService(icmp);
OnmsNode node4 = builder.getCurrentNode();
node4.setLldpElement(new LldpElement(node4, "node4ChassisId", "node4SysName", LldpChassisIdSubType.LLDP_CHASSISID_SUBTYPE_LOCAL));
setNode4(node4);
//This node purposely doesn't have a foreignId style assetNumber
builder.addNode("alternate-node1").setType(OnmsNode.NodeType.ACTIVE).getAssetRecord().setAssetNumber("5");
builder.addInterface("10.1.1.1").setIsManaged("M").setIsSnmpPrimary("P");
builder.addService(icmp);
builder.addService(snmp);
builder.addInterface("10.1.1.2").setIsManaged("M").setIsSnmpPrimary("S");
builder.addService(icmp);
builder.addService(http);
builder.addInterface("10.1.1.3").setIsManaged("M").setIsSnmpPrimary("N");
builder.addService(icmp);
OnmsNode node5 = builder.getCurrentNode();
node5.setLldpElement(new LldpElement(node5, "node5ChassisId", "node5SysName", LldpChassisIdSubType.LLDP_CHASSISID_SUBTYPE_LOCAL));
setNode5(node5);
//This node purposely doesn't have a assetNumber and is used by a test to check the category
builder.addNode("alternate-node2").setType(OnmsNode.NodeType.ACTIVE).getAssetRecord().setDisplayCategory("category1");
builder.addInterface("10.1.2.1").setIsManaged("M").setIsSnmpPrimary("P");
builder.addService(icmp);
builder.addService(snmp);
builder.addInterface("10.1.2.2").setIsManaged("M").setIsSnmpPrimary("S");
builder.addService(icmp);
builder.addService(http);
builder.addInterface("10.1.2.3").setIsManaged("M").setIsSnmpPrimary("N");
builder.addService(icmp);
OnmsNode node6 = builder.getCurrentNode();
node6.setLldpElement(new LldpElement(node6, "node6ChassisId", "node6SysName", LldpChassisIdSubType.LLDP_CHASSISID_SUBTYPE_LOCAL));
setNode6(node6);
builder.addNode("alternate-node3").setType(OnmsNode.NodeType.ACTIVE).getAssetRecord().setDisplayCategory("category1");
builder.addInterface("10.1.3.1").setIsManaged("M").setIsSnmpPrimary("P");
builder.addService(icmp);
builder.addService(snmp);
builder.addInterface("10.1.3.2").setIsManaged("M").setIsSnmpPrimary("S");
builder.addService(icmp);
builder.addService(http);
builder.addInterface("10.1.3.3").setIsManaged("M").setIsSnmpPrimary("N");
builder.addService(icmp);
OnmsNode node7 = builder.getCurrentNode();
node7.setLldpElement(new LldpElement(node7, "node7ChassisId", "node7SysName", LldpChassisIdSubType.LLDP_CHASSISID_SUBTYPE_LOCAL));
setNode7(node7);
builder.addNode("alternate-node4").setType(OnmsNode.NodeType.ACTIVE).getAssetRecord().setDisplayCategory("category1");
builder.addInterface("10.1.4.1").setIsManaged("M").setIsSnmpPrimary("P");
builder.addService(icmp);
builder.addService(snmp);
builder.addInterface("10.1.4.2").setIsManaged("M").setIsSnmpPrimary("S");
builder.addService(icmp);
builder.addService(http);
builder.addInterface("10.1.4.3").setIsManaged("M").setIsSnmpPrimary("N");
builder.addService(icmp);
OnmsNode node8 = builder.getCurrentNode();
node8.setLldpElement(new LldpElement(node8, "node8ChassisId", "mode8SysName", LldpChassisIdSubType.LLDP_CHASSISID_SUBTYPE_LOCAL));
setNode8(node8);
List<OnmsNode> nodes = new ArrayList<OnmsNode>();
nodes.add(node1);
nodes.add(node2);
nodes.add(node3);
nodes.add(node4);
nodes.add(node5);
nodes.add(node6);
nodes.add(node7);
nodes.add(node8);
setNodes(nodes);
//final OnmsNode node, final int ifIndex, final int nodeParentId, final int parentIfIndex, final StatusType status,final Date lastPollTime
/*OnmsNode node, Integer localPortNum, Integer portIfIndex, String portId,
String portDescr, String remChassisId, String remSysname, LldpElement.LldpChassisIdSubType
remChassisIdSubType,
String remPortId, String remPortDescr*/
final LldpLink dli12 = createLldpLink(getNode1(), "node1PortId", "node1PortDescr", 12, 10, LldpPortIdSubType.LLDP_PORTID_SUBTYPE_LOCAL, getNode2().getLldpElement(), "node2PortDescr", "node2PortId");
final LldpLink dli21 = createLldpLink(getNode2(), "node2PortId", "node2PortDescr", 22, 20, LldpPortIdSubType.LLDP_PORTID_SUBTYPE_LOCAL, getNode1().getLldpElement(), "node1PortDescr", "node1PortId");
final LldpLink dli23 = createLldpLink(getNode2(), "node2PortId", "node2PortDescr", 22, 20, LldpPortIdSubType.LLDP_PORTID_SUBTYPE_LOCAL, getNode3().getLldpElement(), "node3PortDescr", "node3PortId");
final LldpLink dli32 = createLldpLink(getNode3(), "node3PortId", "node3PortDescr", 33, 30, LldpPortIdSubType.LLDP_PORTID_SUBTYPE_LOCAL, getNode2().getLldpElement(), "node2PortDescr", "node2PortId");
final LldpLink dli34 = createLldpLink(getNode3(), "node3PortId", "node3PortDescr", 33, 30, LldpPortIdSubType.LLDP_PORTID_SUBTYPE_LOCAL, getNode4().getLldpElement(), "node4PortDescr", "node4PortId");
final LldpLink dli43 = createLldpLink(getNode4(), "node4PortId", "node4PortDescr", 44, 40, LldpPortIdSubType.LLDP_PORTID_SUBTYPE_LOCAL, getNode3().getLldpElement(), "node3PortDescr", "node3PortId");
final LldpLink dli45 = createLldpLink(getNode4(), "node4PortId", "node4PortDescr", 44, 40, LldpPortIdSubType.LLDP_PORTID_SUBTYPE_LOCAL, getNode5().getLldpElement(), "node5PortDescr", "node5PortId");
final LldpLink dli54 = createLldpLink(getNode5(), "node5PortId", "node5PortDescr", 55, 50, LldpPortIdSubType.LLDP_PORTID_SUBTYPE_LOCAL, getNode4().getLldpElement(), "node4PortDescr", "node4PortId");
final LldpLink dli56 = createLldpLink(getNode5(), "node5PortId", "node5PortDescr", 55, 50, LldpPortIdSubType.LLDP_PORTID_SUBTYPE_LOCAL, getNode6().getLldpElement(), "node6PortDescr", "node6PortId");
final LldpLink dli65 = createLldpLink(getNode6(), "node6PortId", "node6PortDescr", 66, 60, LldpPortIdSubType.LLDP_PORTID_SUBTYPE_LOCAL, getNode5().getLldpElement(), "node5PortDescr", "node5PortId");
final LldpLink dli67 = createLldpLink(getNode6(), "node6PortId", "node6PortDescr", 66, 60, LldpPortIdSubType.LLDP_PORTID_SUBTYPE_LOCAL, getNode7().getLldpElement(), "node7PortDescr", "node7PortId");
final LldpLink dli76 = createLldpLink(getNode7(), "node7PortId", "node7PortDescr", 77, 70, LldpPortIdSubType.LLDP_PORTID_SUBTYPE_LOCAL, getNode6().getLldpElement(), "node6PortDescr", "node6PortId");
final LldpLink dli78 = createLldpLink(getNode7(), "node7PortId", "node7PortDescr", 77, 70, LldpPortIdSubType.LLDP_PORTID_SUBTYPE_LOCAL, getNode8().getLldpElement(), "node8PortDescr", "node8PortId");
final LldpLink dli87 = createLldpLink(getNode8(), "node8PortId", "node8PortDescr", 88, 80, LldpPortIdSubType.LLDP_PORTID_SUBTYPE_LOCAL, getNode7().getLldpElement(), "node7PortDescr", "node7PortId");
final LldpLink dli81 = createLldpLink(getNode8(), "node8PortId", "node8PortDescr", 88, 80, LldpPortIdSubType.LLDP_PORTID_SUBTYPE_LOCAL, getNode1().getLldpElement(), "node1PortDescr", "node1PortId");
final LldpLink dli18 = createLldpLink(getNode1(), "node1PortId", "node1PortDescr", 12, 10, LldpPortIdSubType.LLDP_PORTID_SUBTYPE_LOCAL, getNode8().getLldpElement(), "node8PortDescr", "node8PortId");
dli12.setId(10012);
dli21.setId(10021);
dli23.setId(10023);
dli32.setId(10032);
dli34.setId(10034);
dli43.setId(10043);
dli45.setId(10045);
dli54.setId(10054);
dli56.setId(10056);
dli65.setId(10065);
dli67.setId(10067);
dli76.setId(10076);
dli78.setId(10078);
dli87.setId(10087);
dli81.setId(10081);
dli18.setId(10018);
List<LldpLink> links = new ArrayList<LldpLink>();
links.add(dli12);
links.add(dli21);
links.add(dli23);
links.add(dli32);
links.add(dli34);
links.add(dli43);
links.add(dli45);
links.add(dli54);
links.add(dli56);
links.add(dli65);
links.add(dli67);
links.add(dli76);
links.add(dli78);
links.add(dli87);
links.add(dli81);
links.add(dli18);
setLinks(links);
//OSPF links
OspfLink ospfLink12 = createOspfLink(getNode1(), "192.168.100.246", "255.255.255.252", 0, 10101, "192.168.100.249", "192.168.100.245", 0);
OspfLink ospfLink21 = createOspfLink(getNode2(), "192.168.100.245", "255.255.255.252", 0, 10101, "192.168.100.250", "192.168.100.246", 0);
ospfLink12.setId(10112);
ospfLink21.setId(10121);
List<OspfLink> ospfLinks = new ArrayList<OspfLink>();
ospfLinks.add(ospfLink12);
ospfLinks.add(ospfLink21);
setOspfLinks(ospfLinks);
}
use of org.opennms.netmgt.model.LldpElement in project opennms by OpenNMS.
the class EnLinkdSnmpIT method testLldpLocalGroupWalk.
@Test
@JUnitSnmpAgents(value = { @JUnitSnmpAgent(host = SWITCH1_IP, port = 161, resource = "classpath:/linkd/nms17216/switch1-walk.txt") })
public void testLldpLocalGroupWalk() throws Exception {
String trackerName = "lldpLocalGroup";
SnmpAgentConfig config = SnmpPeerFactory.getInstance().getAgentConfig(InetAddress.getByName(SWITCH1_IP));
LldpLocalGroupTracker lldpLocalGroup = new LldpLocalGroupTracker();
try {
m_client.walk(config, lldpLocalGroup).withDescription(trackerName).withLocation(null).execute().get();
} catch (final InterruptedException e) {
LOG.error("run: collection interrupted, exiting", e);
return;
}
LldpElement eiA = lldpLocalGroup.getLldpElement();
System.err.println("local chassis type: " + LldpChassisIdSubType.getTypeString(eiA.getLldpChassisIdSubType().getValue()));
System.err.println("local chassis id: " + eiA.getLldpChassisId());
System.err.println("local sysname: " + eiA.getLldpSysname());
assertEquals("0016c8bd4d80", eiA.getLldpChassisId());
assertEquals(LldpChassisIdSubType.LLDP_CHASSISID_SUBTYPE_MACADDRESS, eiA.getLldpChassisIdSubType());
assertEquals("Switch1", eiA.getLldpSysname());
}
use of org.opennms.netmgt.model.LldpElement in project opennms by OpenNMS.
the class LldpLocalGroupTracker method getLldpElement.
public LldpElement getLldpElement() {
LldpElement lldpElement = new LldpElement();
lldpElement.setLldpChassisId(decodeLldpChassisId(getLldpLocChassisid(), getLldpLocChassisidSubType()));
lldpElement.setLldpChassisIdSubType(LldpChassisIdSubType.get(getLldpLocChassisidSubType()));
lldpElement.setLldpSysname(getLldpLocSysname());
return lldpElement;
}
use of org.opennms.netmgt.model.LldpElement 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);
}
Aggregations