use of org.opennms.netmgt.model.topology.BroadcastDomain in project opennms by OpenNMS.
the class EnhancedLinkdTopologyProvider method getBridgeLinks.
private void getBridgeLinks(Map<Integer, OnmsNode> nodemap, Map<Integer, List<OnmsSnmpInterface>> nodesnmpmap, Map<String, List<OnmsIpInterface>> macToIpMap, Map<Integer, List<OnmsIpInterface>> ipmap, Map<Integer, OnmsIpInterface> ipprimarymap) {
for (BroadcastDomain domain : m_bridgeTopologyDao.load()) {
LOG.info("loadtopology: parsing broadcast Domain: '{}', {}", domain);
for (SharedSegment segment : domain.getTopology()) {
if (segment.noMacsOnSegment() && segment.getBridgeBridgeLinks().size() == 1) {
for (BridgeBridgeLink link : segment.getBridgeBridgeLinks()) {
Vertex source = getOrCreateVertex(nodemap.get(link.getNode().getId()), ipprimarymap.get(link.getNode().getId()));
Vertex target = getOrCreateVertex(nodemap.get(link.getDesignatedNode().getId()), ipprimarymap.get(link.getDesignatedNode().getId()));
BridgeLinkDetail detail = new BridgeLinkDetail(EnhancedLinkdTopologyProvider.TOPOLOGY_NAMESPACE_LINKD, source, link.getBridgePortIfIndex(), target, link.getDesignatedPortIfIndex(), link.getBridgePort(), link.getDesignatedPort(), link.getId(), link.getId());
LinkdEdge edge = connectVertices(detail, BRIDGE_EDGE_NAMESPACE);
edge.setTooltipText(getEdgeTooltipText(detail, nodesnmpmap));
}
continue;
}
if (segment.getBridgeMacLinks().size() == 1 && segment.getBridgeBridgeLinks().size() == 0) {
for (BridgeMacLink sourcelink : segment.getBridgeMacLinks()) {
if (macToIpMap.containsKey(sourcelink.getMacAddress()) && macToIpMap.get(sourcelink.getMacAddress()).size() > 0) {
List<OnmsIpInterface> targetInterfaces = macToIpMap.get(sourcelink.getMacAddress());
OnmsIpInterface targetIp = targetInterfaces.get(0);
if (segment.getBridgeIdsOnSegment().contains(targetIp.getNode().getId()))
continue;
Vertex source = getOrCreateVertex(nodemap.get(sourcelink.getNode().getId()), ipprimarymap.get(sourcelink.getNode().getId()));
Vertex target = getOrCreateVertex(nodemap.get(targetIp.getNode().getId()), ipprimarymap.get(targetIp.getNode().getId()));
LinkdEdge edge = connectVertices(sourcelink, source, target, BRIDGE_EDGE_NAMESPACE);
edge.setTooltipText(getEdgeTooltipText(sourcelink, source, target, targetInterfaces, nodesnmpmap));
}
}
continue;
}
String cloudId = segment.getDesignatedBridge() + ":" + segment.getDesignatedPort();
AbstractVertex cloudVertex = addVertex(cloudId, 0, 0);
cloudVertex.setLabel("");
cloudVertex.setIconKey("cloud");
cloudVertex.setTooltipText("Shared Segment: " + nodemap.get(segment.getDesignatedBridge()).getLabel() + " port: " + segment.getDesignatedPort());
addVertices(cloudVertex);
LOG.info("loadtopology: adding cloud: id: '{}', {}", cloudId, cloudVertex.getTooltipText());
for (BridgePort targetport : segment.getBridgePortsOnSegment()) {
Vertex target = getOrCreateVertex(nodemap.get(targetport.getNode().getId()), ipprimarymap.get(targetport.getNode().getId()));
LinkdEdge edge = connectVertices(targetport, cloudVertex, target, BRIDGE_EDGE_NAMESPACE);
edge.setTooltipText(getEdgeTooltipText(targetport, target, nodesnmpmap));
}
for (String targetmac : segment.getMacsOnSegment()) {
if (macToIpMap.containsKey(targetmac) && macToIpMap.get(targetmac).size() > 0) {
List<OnmsIpInterface> targetInterfaces = macToIpMap.get(targetmac);
OnmsIpInterface targetIp = targetInterfaces.get(0);
if (segment.getBridgeIdsOnSegment().contains(targetIp.getNode().getId()))
continue;
Vertex target = getOrCreateVertex(nodemap.get(targetIp.getNode().getId()), ipprimarymap.get(targetIp.getNode().getId()));
LinkdEdge edge = connectCloudMacVertices(targetmac, cloudVertex, target, BRIDGE_EDGE_NAMESPACE);
edge.setTooltipText(getEdgeTooltipText(targetmac, target, targetInterfaces));
}
}
}
}
}
use of org.opennms.netmgt.model.topology.BroadcastDomain in project opennms by OpenNMS.
the class BridgeTopologyDaoHibernate method load.
@Override
public Set<BroadcastDomain> load() {
List<SharedSegment> bblsegments = new ArrayList<SharedSegment>();
Map<Integer, Set<Integer>> rootnodetodomainnodemap = new HashMap<Integer, Set<Integer>>();
// start bridge bridge link parsing
for (BridgeBridgeLink link : m_bridgeBridgeLinkDao.findAll()) {
if (LOG.isDebugEnabled()) {
LOG.debug("getAllPersisted: Parsing BridgeBridgeLink: {}", link.printTopology());
}
boolean segmentnotfound = true;
for (SharedSegment bblsegment : bblsegments) {
if (bblsegment.containsPort(link.getDesignatedNode().getId(), link.getDesignatedPort())) {
bblsegment.add(link);
segmentnotfound = false;
if (LOG.isDebugEnabled()) {
LOG.debug("getAllPersisted: found Bridge Bridge Link Shared Segment: {}", bblsegment.printTopology());
}
break;
}
}
if (segmentnotfound) {
SharedSegment bblsegment = new SharedSegment();
bblsegment.add(link);
bblsegment.setDesignatedBridge(link.getDesignatedNode().getId());
bblsegments.add(bblsegment);
if (LOG.isDebugEnabled()) {
LOG.debug("getAllPersisted: created new Bridge Bridge Link Shared Segment: {}", bblsegment.printTopology());
}
}
// set up domains
if (rootnodetodomainnodemap.containsKey(link.getDesignatedNode().getId())) {
rootnodetodomainnodemap.get(link.getDesignatedNode().getId()).add(link.getNode().getId());
if (rootnodetodomainnodemap.containsKey(link.getNode().getId())) {
rootnodetodomainnodemap.get(link.getDesignatedNode().getId()).addAll(rootnodetodomainnodemap.remove(link.getNode().getId()));
}
if (LOG.isDebugEnabled()) {
LOG.debug("getAllPersisted: designated {} is root, dependency set: {}", link.getDesignatedNode().getId(), rootnodetodomainnodemap.get(link.getDesignatedNode().getId()));
}
} else if (rootnodetodomainnodemap.containsKey(link.getNode().getId())) {
Set<Integer> dependentsnode = rootnodetodomainnodemap.remove(link.getNode().getId());
dependentsnode.add(link.getNode().getId());
if (LOG.isDebugEnabled()) {
LOG.debug("getAllPersisted: node {} is root, dependency set: {}", link.getNode().getId(), dependentsnode);
}
Integer rootdesignated = null;
for (Integer rootid : rootnodetodomainnodemap.keySet()) {
if (rootnodetodomainnodemap.get(rootid).contains(link.getDesignatedNode().getId())) {
rootdesignated = rootid;
break;
}
}
if (rootdesignated != null) {
if (LOG.isDebugEnabled()) {
LOG.debug("getAllPersisted: node {} found root: {}", link.getNode().getId(), rootdesignated);
}
dependentsnode.add(link.getDesignatedNode().getId());
rootnodetodomainnodemap.get(rootdesignated).addAll(dependentsnode);
if (LOG.isDebugEnabled()) {
LOG.debug("getAllPersisted: node {} found root: {}, dependency set: {}", link.getNode().getId(), rootdesignated, rootnodetodomainnodemap.get(rootdesignated));
}
} else {
rootnodetodomainnodemap.put(link.getDesignatedNode().getId(), dependentsnode);
if (LOG.isDebugEnabled()) {
LOG.debug("getAllPersisted: node {} created root: {}, dependency set: {}", link.getNode().getId(), link.getDesignatedNode().getId(), rootnodetodomainnodemap.get(link.getDesignatedNode().getId()));
}
}
} else {
Integer rootdesignated = null;
for (Integer rootid : rootnodetodomainnodemap.keySet()) {
if (rootnodetodomainnodemap.get(rootid).contains(link.getDesignatedNode().getId())) {
rootdesignated = rootid;
break;
}
}
if (rootdesignated != null) {
rootnodetodomainnodemap.get(rootdesignated).add(link.getNode().getId());
if (LOG.isDebugEnabled()) {
LOG.debug("getAllPersisted: designatednode {} found root: {}, dependency set: {}", link.getDesignatedNode().getId(), rootdesignated, rootnodetodomainnodemap.get(rootdesignated));
}
} else {
rootnodetodomainnodemap.put(link.getDesignatedNode().getId(), new HashSet<Integer>());
rootnodetodomainnodemap.get(link.getDesignatedNode().getId()).add(link.getNode().getId());
if (LOG.isDebugEnabled()) {
LOG.debug("getAllPersisted: designatednode {} : {}", link.getDesignatedNode().getId(), rootnodetodomainnodemap.get(link.getDesignatedNode().getId()));
}
// FIXME: Check if node is a child of some other and manage exception :-)
}
}
}
LOG.debug("getAllPersisted: bridge topology set: {}", rootnodetodomainnodemap);
// end bridge bridge link parsing
List<SharedSegment> bmlsegments = new ArrayList<SharedSegment>();
Map<String, List<BridgeMacLink>> mactobridgeportbbl = new HashMap<String, List<BridgeMacLink>>();
BML: for (BridgeMacLink link : m_bridgeMacLinkDao.findAll()) {
link.setBridgeDot1qTpFdbStatus(BridgeDot1qTpFdbStatus.DOT1D_TP_FDB_STATUS_LEARNED);
if (LOG.isDebugEnabled()) {
LOG.debug("getAllPersisted: Parsing BridgeMacLink: {}", link.printTopology());
}
for (SharedSegment bblsegment : bblsegments) {
if (bblsegment.containsPort(link.getNode().getId(), link.getBridgePort())) {
if (!mactobridgeportbbl.containsKey(link.getMacAddress())) {
mactobridgeportbbl.put(link.getMacAddress(), new ArrayList<BridgeMacLink>());
}
if (LOG.isDebugEnabled()) {
LOG.debug("getAllPersisted: Found BridgeBridgeLink Segment: {}", bblsegment.printTopology());
}
mactobridgeportbbl.get(link.getMacAddress()).add(link);
continue BML;
}
}
if (!rootnodetodomainnodemap.containsKey(link.getNode().getId())) {
boolean norootnodetodomainmapentry = true;
for (Set<Integer> nodes : rootnodetodomainnodemap.values()) {
if (nodes.contains(link.getNode().getId())) {
norootnodetodomainmapentry = false;
break;
}
}
if (norootnodetodomainmapentry)
rootnodetodomainnodemap.put(link.getNode().getId(), new HashSet<Integer>());
}
for (SharedSegment bmlsegment : bmlsegments) {
if (bmlsegment.containsPort(link.getNode().getId(), link.getBridgePort())) {
bmlsegment.add(link);
if (LOG.isDebugEnabled()) {
LOG.debug("getAllPersisted: found Bridge Mac Link Shared Segment: {}", bmlsegment.printTopology());
}
continue BML;
}
}
SharedSegment bmlsegment = new SharedSegment();
bmlsegment.add(link);
bmlsegment.setDesignatedBridge(link.getNode().getId());
if (LOG.isDebugEnabled()) {
LOG.debug("getAllPersisted: created new Bridge Mac Link Shared Segment: {}", bmlsegment.printTopology());
}
bmlsegments.add(bmlsegment);
}
List<BridgeMacLink> forwarders = new ArrayList<BridgeMacLink>();
for (String macaddress : mactobridgeportbbl.keySet()) {
LOG.debug("getAllPersisted: assigning mac {} to Bridge Bridge Link Shared Segment", macaddress);
for (SharedSegment segment : bblsegments) {
if (LOG.isDebugEnabled()) {
LOG.debug("getAllPersisted: parsing Bridge Bridge Link Shared Segment {}", segment.printTopology());
}
List<BridgeMacLink> bblfoundonsegment = new ArrayList<BridgeMacLink>();
for (BridgeMacLink link : mactobridgeportbbl.get(macaddress)) {
if (LOG.isDebugEnabled()) {
LOG.debug("getAllPersisted: parsing Bridge Mac Link {}", link.printTopology());
}
if (segment.containsPort(link.getNode().getId(), link.getBridgePort())) {
bblfoundonsegment.add(link);
if (LOG.isDebugEnabled()) {
LOG.debug("getAllPersisted: adding Bridge Mac Link {}", link.printTopology());
}
}
}
if (bblfoundonsegment.size() == segment.getBridgePortsOnSegment().size()) {
for (BridgeMacLink link : bblfoundonsegment) segment.add(link);
} else {
forwarders.addAll(bblfoundonsegment);
}
}
}
Set<BroadcastDomain> domains = new CopyOnWriteArraySet<BroadcastDomain>();
for (Integer rootnode : rootnodetodomainnodemap.keySet()) {
BroadcastDomain domain = new BroadcastDomain();
domain.addBridge(new Bridge(rootnode));
for (Integer nodeid : rootnodetodomainnodemap.get(rootnode)) domain.addBridge(new Bridge(nodeid));
if (LOG.isDebugEnabled()) {
LOG.debug("getAllPersisted: created new Broadcast Domain: {}", domain.getBridgeNodesOnDomain());
}
domains.add(domain);
}
for (SharedSegment segment : bblsegments) {
for (BroadcastDomain cdomain : domains) {
if (cdomain.containsAtleastOne(segment.getBridgeIdsOnSegment())) {
cdomain.loadTopologyEntry(segment);
break;
}
}
}
for (SharedSegment segment : bmlsegments) {
for (BroadcastDomain cdomain : domains) {
if (cdomain.containsAtleastOne(segment.getBridgeIdsOnSegment())) {
cdomain.loadTopologyEntry(segment);
break;
}
}
}
for (BridgeMacLink forwarder : forwarders) {
for (BroadcastDomain domain : domains) {
if (domain.containBridgeId(forwarder.getNode().getId())) {
domain.addForwarding(forwarder);
break;
}
}
}
for (BroadcastDomain domain : domains) {
if (LOG.isDebugEnabled()) {
LOG.info("getAllPersisted: loading root Broadcast Domain: {}", domain.getBridgeNodesOnDomain());
}
domain.loadTopologyRoot();
}
return domains;
}
use of org.opennms.netmgt.model.topology.BroadcastDomain in project opennms by OpenNMS.
the class EnhancedLinkd method onInit.
/**
* <p>
* onInit
* </p>
*/
protected void onInit() {
BeanUtils.assertAutowiring(this);
Assert.state(m_eventForwarder != null, "must set the eventForwarder property");
LOG.info("init: Loading nodes.....");
m_nodes = m_queryMgr.getSnmpNodeList();
Assert.notNull(m_nodes);
LOG.info("init: Nodes loaded.");
LOG.info("init: Loading Bridge Topology.....");
m_queryMgr.loadBridgeTopology();
LOG.info("init: Bridge Topology loaded.");
for (BroadcastDomain domain : m_queryMgr.getAllBroadcastDomains()) {
LOG.debug("init: Found BroadcastDomain with topology {}", domain.printTopology());
}
scheduleCollection();
LOG.info("init: ENHANCED LINKD INITIALIZED");
}
use of org.opennms.netmgt.model.topology.BroadcastDomain in project opennms by OpenNMS.
the class EnhancedLinkdServiceImpl method delete.
@Override
public void delete(int nodeId) {
m_lldpElementDao.deleteByNodeId(nodeId);
m_lldpLinkDao.deleteByNodeId(nodeId);
m_lldpElementDao.flush();
m_lldpLinkDao.flush();
m_cdpElementDao.deleteByNodeId(nodeId);
m_cdpLinkDao.deleteByNodeId(nodeId);
m_cdpElementDao.flush();
m_cdpLinkDao.flush();
m_ospfElementDao.deleteByNodeId(nodeId);
m_ospfLinkDao.deleteByNodeId(nodeId);
m_ospfElementDao.flush();
m_ospfLinkDao.flush();
m_isisElementDao.deleteByNodeId(nodeId);
m_isisLinkDao.deleteByNodeId(nodeId);
m_isisElementDao.flush();
m_isisLinkDao.flush();
m_ipNetToMediaDao.deleteBySourceNodeId(nodeId);
m_ipNetToMediaDao.flush();
m_bridgeElementDao.deleteByNodeId(nodeId);
m_bridgeElementDao.flush();
m_bridgeTopologyDao.delete(nodeId);
m_bridgeStpLinkDao.deleteByNodeId(nodeId);
m_bridgeStpLinkDao.flush();
synchronized (m_domains) {
for (BroadcastDomain domain : m_domains) {
synchronized (domain) {
if (domain.containBridgeId(nodeId)) {
domain.removeBridge(nodeId);
break;
}
}
}
}
}
use of org.opennms.netmgt.model.topology.BroadcastDomain in project opennms by OpenNMS.
the class NodeDiscoveryBridgeTopology method run.
@Override
public void run() {
if (!m_linkd.getQueryManager().hasUpdatedBft(getNodeId())) {
LOG.info("run: node: [{}], no bft.Exiting Bridge Topology Discovery", getNodeId());
return;
}
List<BridgeMacLink> links = m_linkd.getQueryManager().getBridgeTopologyUpdateBFT(getNodeId());
if (links == null || links.size() == 0) {
LOG.info("run: node: [{}]. no updates macs found.", getNodeId());
return;
}
Date now = new Date();
Set<String> incomingSet = new HashSet<String>();
synchronized (links) {
for (BridgeMacLink link : links) {
incomingSet.add(link.getMacAddress());
}
}
LOG.debug("run: node: [{}]. macs found: {}", getNodeId(), incomingSet);
LOG.info("run: node: [{}], getting broadcast domain. Start", getNodeId());
for (BroadcastDomain domain : m_linkd.getQueryManager().getAllBroadcastDomains()) {
LOG.debug("run: node: [{}], parsing domain with nodes: {}, macs: {}", getNodeId(), domain.getBridgeNodesOnDomain(), domain.getMacsOnDomain());
Set<String> retainedSet = new HashSet<String>(domain.getMacsOnDomain());
retainedSet.retainAll(incomingSet);
LOG.debug("run: node: [{}], retained: {}", getNodeId(), retainedSet);
// should contain at list 5 or 10% of the all size
if (retainedSet.size() > DOMAIN_MATCH_MIN_SIZE || retainedSet.size() >= incomingSet.size() * DOMAIN_MATCH_MIN_RATIO) {
if (LOG.isDebugEnabled()) {
LOG.debug("run: node: [{}], domain {} found!", getNodeId(), domain.getBridgeNodesOnDomain());
}
m_domain = domain;
// TODO: We should find the *best* domain, instead of using the last match
}
}
if (m_domain == null) {
LOG.debug("run: node: [{}] Creating a new Domain", getNodeId());
m_domain = new BroadcastDomain();
m_linkd.getQueryManager().save(m_domain);
} else if (!m_domain.hasRootBridge()) {
LOG.debug("run: node: [{}] Domain without root, clearing topology", getNodeId());
m_domain.clearTopology();
}
LOG.info("run: node: [{}], getting broadcast domain. End", getNodeId());
Map<Integer, List<BridgeMacLink>> nodeBftMap = m_linkd.getQueryManager().getUpdateBftMap();
Set<Integer> nodeswithupdatedbftonbroadcastdomain = getAllNodesWithUpdatedBFTOnDomain(incomingSet, nodeBftMap);
LOG.info("run: node: [{}], clean broadcast domains. Start", getNodeId());
boolean clean = false;
for (BroadcastDomain domain : m_linkd.getQueryManager().getAllBroadcastDomains()) {
if (m_domain == domain)
continue;
if (LOG.isDebugEnabled()) {
LOG.debug("run: node [{}]: cleaning broadcast domain {}.", getNodeId(), domain.getBridgeNodesOnDomain());
}
for (Integer curNodeId : nodeswithupdatedbftonbroadcastdomain) {
if (domain.containBridgeId(curNodeId)) {
if (LOG.isDebugEnabled()) {
LOG.debug("run: node [{}]: node [{}]: removing from broadcast domain {}!", getNodeId(), curNodeId, domain.getBridgeNodesOnDomain());
}
synchronized (domain) {
domain.clearTopologyForBridge(curNodeId);
domain.removeBridge(curNodeId);
m_linkd.getQueryManager().store(domain);
m_linkd.getQueryManager().reconcileBridgeTopology(domain, now);
}
clean = true;
}
}
}
if (clean) {
m_linkd.getQueryManager().cleanBroadcastDomains();
}
LOG.info("run: node: [{}], clean broadcast domains. End", getNodeId());
synchronized (m_domain) {
m_notYetParsedBFTMap = new HashMap<Bridge, List<BridgeMacLink>>();
for (Integer nodeid : nodeswithupdatedbftonbroadcastdomain) {
sendStartEvent(nodeid);
m_domain.addBridge(new Bridge(nodeid));
LOG.debug("run: node: [{}], getting update bft for node [{}] on domain", getNodeId(), nodeid);
List<BridgeMacLink> bft = m_linkd.getQueryManager().useBridgeTopologyUpdateBFT(nodeid);
if (bft == null || bft.isEmpty()) {
LOG.debug("run: node: [{}], no update bft for node [{}] on domain", getNodeId(), nodeid);
continue;
}
m_notYetParsedBFTMap.put(m_domain.getBridge(nodeid), bft);
}
Set<Integer> nodetoberemovedondomain = new HashSet<Integer>();
synchronized (nodeBftMap) {
for (Integer nodeid : nodeBftMap.keySet()) {
if (nodeswithupdatedbftonbroadcastdomain.contains(nodeid))
continue;
LOG.info("run: node [{}]: bridge [{}] with updated bft. Not even more on broadcast domain {}: clear topology.", getNodeId(), nodeid, m_domain.getBridgeNodesOnDomain());
nodetoberemovedondomain.add(nodeid);
}
}
for (Integer nodeid : nodetoberemovedondomain) {
m_domain.clearTopologyForBridge(nodeid);
m_domain.removeBridge(nodeid);
}
m_linkd.getQueryManager().cleanBroadcastDomains();
m_domain.setBridgeElements(m_linkd.getQueryManager().getBridgeElements(m_domain.getBridgeNodesOnDomain()));
if (m_notYetParsedBFTMap.isEmpty()) {
LOG.info("run: node: [{}], broadcast domain has no topology updates. No more action is needed.", getNodeId());
} else {
calculate();
}
LOG.info("run: node: [{}], saving Topology.", getNodeId());
m_linkd.getQueryManager().store(m_domain);
m_linkd.getQueryManager().reconcileBridgeTopology(m_domain, now);
LOG.info("run: node: [{}], saved Topology.", getNodeId());
for (Integer curNode : nodeswithupdatedbftonbroadcastdomain) {
sendCompletedEvent(curNode);
}
}
}
Aggregations