use of org.opennms.netmgt.model.topology.SharedSegment in project opennms by OpenNMS.
the class BridgeTopologyDaoInMemory method getAllPersisted.
@Override
public Set<BroadcastDomain> getAllPersisted(BridgeBridgeLinkDao bridgeBridgeLinkDao, BridgeMacLinkDao bridgeMacLinkDao) {
List<SharedSegment> segments = new ArrayList<SharedSegment>();
BRIDGELINK: for (BridgeBridgeLink link : bridgeBridgeLinkDao.findAll()) {
for (SharedSegment segment : segments) {
if (segment.containsPort(link.getNode().getId(), link.getBridgePort()) || segment.containsPort(link.getDesignatedNode().getId(), link.getDesignatedPort())) {
segment.add(link);
continue BRIDGELINK;
}
}
SharedSegment segment = new SharedSegment();
segment.add(link);
segment.setDesignatedBridge(link.getDesignatedNode().getId());
segments.add(segment);
}
MACLINK: for (BridgeMacLink link : bridgeMacLinkDao.findAll()) {
link.setBridgeDot1qTpFdbStatus(BridgeDot1qTpFdbStatus.DOT1D_TP_FDB_STATUS_LEARNED);
for (SharedSegment segment : segments) {
if (segment.containsMac(link.getMacAddress()) || segment.containsPort(link.getNode().getId(), link.getBridgePort())) {
segment.add(link);
continue MACLINK;
}
}
SharedSegment segment = new SharedSegment();
segment.add(link);
segment.setDesignatedBridge(link.getNode().getId());
segments.add(segment);
}
Set<Set<Integer>> nodelinked = new HashSet<Set<Integer>>();
SHARED: for (SharedSegment segment : segments) {
Set<Integer> nodesOnSegment = new HashSet<Integer>(segment.getBridgeIdsOnSegment());
for (Set<Integer> nodes : nodelinked) {
for (Integer nodeid : nodesOnSegment) {
if (nodes.contains(nodeid))
continue SHARED;
}
}
nodelinked.add(getNodesOnDomainSet(segments, segment, new HashSet<SharedSegment>(), nodesOnSegment));
}
Set<BroadcastDomain> domains = new HashSet<BroadcastDomain>();
for (Set<Integer> nodes : nodelinked) {
BroadcastDomain domain = new BroadcastDomain();
for (Integer nodeid : nodes) domain.addBridge(new Bridge(nodeid));
domains.add(domain);
}
// Assign the segment to domain and add to single nodes
for (SharedSegment segment : segments) {
BroadcastDomain domain = null;
for (BroadcastDomain cdomain : domains) {
if (cdomain.containsAtleastOne(segment.getBridgeIdsOnSegment())) {
domain = cdomain;
break;
}
}
if (domain == null) {
domain = new BroadcastDomain();
domains.add(domain);
}
domain.loadTopologyEntry(segment);
}
return domains;
}
use of org.opennms.netmgt.model.topology.SharedSegment in project opennms by OpenNMS.
the class BroadcastDomainTest method testCleanTopologyRoot.
@Test
public void testCleanTopologyRoot() {
TwoBridgeWithBackbonePortsTopology topology = new TwoBridgeWithBackbonePortsTopology();
BroadcastDomain domain = new BroadcastDomain();
domain.addBridge(new Bridge(topology.nodeAId));
domain.addBridge(new Bridge(topology.nodeBId));
domain.setBridgeElements(topology.elemlist);
NodeDiscoveryBridgeTopology ndbt = new NodeDiscoveryBridgeTopology(linkd, new Node(topology.nodeAId, null, null, null, location));
ndbt.setDomain(domain);
ndbt.addUpdatedBFT(domain.getBridge(topology.nodeAId), topology.bftA);
ndbt.addUpdatedBFT(domain.getBridge(topology.nodeBId), topology.bftB);
ndbt.calculate();
domain.clearTopologyForBridge(topology.nodeAId);
assertEquals(5, domain.getMacsOnDomain().size());
assertEquals(topology.nodeBId.intValue(), domain.getRootBridge().getId().intValue());
assertEquals(2, domain.getTopology().size());
for (SharedSegment segment : domain.getTopology()) {
assertEquals(0, segment.getBridgeBridgeLinks().size());
assertEquals(1, segment.getBridgeIdsOnSegment().size());
assertEquals(topology.nodeBId.intValue(), segment.getBridgeIdsOnSegment().iterator().next().intValue());
if (segment.containsMac(topology.macA11) && segment.containsMac(topology.macA12) && segment.containsMac(topology.macAB)) {
assertEquals(3, segment.getMacsOnSegment().size());
assertEquals(3, segment.getBridgeMacLinks().size());
for (BridgeMacLink link : segment.getBridgeMacLinks()) {
assertEquals(topology.portBA.intValue(), link.getBridgePort().intValue());
}
} else if (segment.containsMac(topology.macB21) && segment.containsMac(topology.macB22)) {
assertEquals(2, segment.getMacsOnSegment().size());
assertEquals(2, segment.getBridgeMacLinks().size());
for (BridgeMacLink link : segment.getBridgeMacLinks()) {
assertEquals(topology.portB2.intValue(), link.getBridgePort().intValue());
}
} else {
assertEquals(true, false);
}
}
}
use of org.opennms.netmgt.model.topology.SharedSegment in project opennms by OpenNMS.
the class BroadcastDomainTest method testTwoBridgeTwoCalculationReverse.
@Test
public void testTwoBridgeTwoCalculationReverse() {
TwoNodeTopology topology = new TwoNodeTopology();
BroadcastDomain domain = new BroadcastDomain();
domain.addBridge(new Bridge(topology.nodeAId));
domain.setBridgeElements(topology.elemlist);
NodeDiscoveryBridgeTopology ndbt = new NodeDiscoveryBridgeTopology(linkd, new Node(topology.nodeAId, null, null, null, location));
ndbt.setDomain(domain);
ndbt.addUpdatedBFT(domain.getBridge(topology.nodeAId), topology.bftA);
ndbt.calculate();
printBridgeTopology(ndbt.getDomain());
List<SharedSegment> shsegs = ndbt.getDomain().getTopology();
assertEquals(3, shsegs.size());
domain.addBridge(new Bridge(topology.nodeBId));
domain.setBridgeElements(topology.elemlist);
ndbt.addUpdatedBFT(domain.getBridge(topology.nodeBId), topology.bftB);
ndbt.calculate();
topology.check2nodeTopology(ndbt.getDomain(), false);
assertEquals(topology.nodeAId, domain.getRootBridgeId());
}
use of org.opennms.netmgt.model.topology.SharedSegment in project opennms by OpenNMS.
the class NodeDiscoveryBridgeTopology method findBridgesTopo.
// here we assume that rbridge exists in topology
// while xBridge is to be added
private boolean findBridgesTopo(BridgeTopologyHelper rx, SharedSegment topSegment, Bridge xBridge, List<BridgeMacLink> xBFT, int level) {
level++;
LOG.debug("calculate: node [{}]: level {}: bridge: [{}], topo top segment found: [ids {}, designated bridge [{}, port {}], macs {}", getNodeId(), level, xBridge.getId(), topSegment.getBridgeIdsOnSegment(), topSegment.getDesignatedBridge(), topSegment.getDesignatedPort(), topSegment.getMacsOnSegment());
if (level == 30) {
LOG.warn("calculate: node [{}]: level {}: bridge: [{}], too many iteration on topology exiting.....", getNodeId(), level, xBridge.getId());
return false;
}
Set<Integer> portsAdded = new HashSet<Integer>();
Set<String> throughSets = new HashSet<String>();
Map<Integer, List<BridgeMacLink>> bftSets = new HashMap<Integer, List<BridgeMacLink>>();
for (Bridge yBridge : m_domain.getBridgeOnSharedSegment(topSegment)) {
bftSets.put(yBridge.getId(), m_domain.calculateBFT(yBridge));
}
for (Bridge yBridge : m_domain.getBridgeOnSharedSegment(topSegment)) {
Integer yBridgeId = yBridge.getId();
// X is a leaf of top segment: of course
if (yBridgeId.intValue() == topSegment.getDesignatedBridge().intValue()) {
continue;
}
LOG.debug("calculate: node [{}]: level {}: bridge: [{}]: Bridge [{}] on top segment. Searching simple connection", getNodeId(), level, xBridge.getId(), yBridge.getId());
Integer yrDesignatedPort = yBridge.getRootPort();
LOG.debug("calculate: node [{}]: level {}: bridge: {}, Bridge: [{}, designated port: {}]", getNodeId(), level, xBridge.getId(), yBridgeId, yrDesignatedPort);
BridgeTopologyHelper yx = new BridgeTopologyHelper(yBridge, bftSets.get(yBridgeId), xBridge, xBFT);
Integer xyDesignatedPort = yx.getSecondBridgeConnectionPort();
Integer yxDesignatedPort = yx.getFirstBridgeConnectionPort();
// X is a leaf of Y then iterate
if (xyDesignatedPort == rx.getSecondBridgeConnectionPort() && yxDesignatedPort != yrDesignatedPort) {
LOG.debug("calculate: node [{}]: level {}: Bridge: [{}] is a leaf of Bridge: [{}], going one level down", getNodeId(), level, xBridge.getId(), yBridge.getId());
if (!findBridgesTopo(yx, m_domain.getSharedSegment(yBridgeId, yxDesignatedPort), xBridge, xBFT, level))
return false;
return true;
}
// Y is a leaf of X then remove Y from topSegment
if (yxDesignatedPort == yrDesignatedPort && xyDesignatedPort != rx.getSecondBridgeConnectionPort()) {
//create a SharedSegment with root port
LOG.debug("calculate: node [{}]: level {}: bridge: [{},designated port [{}]]: is 'upper' Bridge: [{}]. Adding shared segment.", getNodeId(), level, xBridge.getId(), yBridge.getId(), xyDesignatedPort);
SharedSegment leafSegment = new SharedSegment(m_domain, yx.getSimpleConnection().getDlink(), yx.getSimpleConnection().getMacs());
leafSegment.setDesignatedBridge(xBridge.getId());
m_domain.add(leafSegment);
portsAdded.add(xyDesignatedPort);
LOG.debug("calculate: node [{}]: level {}: bridge [{}]. Removing Bridge [{}]: through set {} from top segment.", getNodeId(), level, xBridge.getId(), yBridge.getId(), yx.getFirstBridgeTroughSet());
topSegment.removeMacs(yx.getFirstBridgeTroughSet());
LOG.debug("calculate: node [{}]: level {}: bridge [{}]. Remove bridge [{}] from top segment.", getNodeId(), level, xBridge.getId(), yBridge.getId());
topSegment.removeBridge(yBridgeId);
}
// this is a clear violation of the topology tree rule
if (xyDesignatedPort != rx.getSecondBridgeConnectionPort() && yxDesignatedPort != yrDesignatedPort) {
LOG.warn("calculate: node [{}]: level {}: bridge [{}]. Topology mismatch. Clearing...topology", getNodeId(), level, xBridge.getId());
return false;
}
throughSets.addAll(yx.getFirstBridgeTroughSet());
}
// if we are here is because X is NOT a leaf of any bridge found
// on topSegment so X is connected to top Segment by it's root
// port or rx is a direct connection
LOG.debug("calculate: node [{}]: level {}: bridge: [{}]. removing through set {} from top segment", getNodeId(), level, xBridge.getId(), rx.getSecondBridgeTroughSet());
topSegment.removeMacs(rx.getSecondBridgeTroughSet());
LOG.debug("calculate: node [{}]: level {}: bridge: [{}]. assign macs {} to top segment", getNodeId(), level, xBridge.getId(), rx.getSimpleConnection().getMacs());
topSegment.assign(rx.getSimpleConnection().getMacs(), rx.getSimpleConnection().getDlink());
LOG.debug("calculate: node [{}]: level {}: bridge: [{}]. removing through sets {} from top segment", getNodeId(), level, xBridge.getId(), throughSets);
topSegment.removeMacs(throughSets);
LOG.debug("calculate: node [{}]: level {}: bridge: [{}]. resulting top segment: [ids {}, designated bridge [{}, port: {}], mac : {}]", getNodeId(), level, xBridge.getId(), topSegment.getBridgeIdsOnSegment(), topSegment.getDesignatedBridge(), topSegment.getDesignatedPort(), topSegment.getMacsOnSegment());
for (Integer xbridgePort : rx.getSecondBridgeTroughSetBft().keySet()) {
if (portsAdded.contains(xbridgePort))
continue;
SharedSegment xleafSegment = new SharedSegment(m_domain, rx.getSecondBridgeTroughSetBft().get(xbridgePort));
xleafSegment.setDesignatedBridge(xBridge.getId());
m_domain.add(xleafSegment);
LOG.debug("calculate: node [{}]: level {}: bridge: [{}]. Add shared segment. " + "[ designated bridge:[{}], " + "port:{}, " + "mac: {}]", getNodeId(), level, xBridge.getId(), xleafSegment.getDesignatedBridge(), xleafSegment.getDesignatedPort(), xleafSegment.getMacsOnSegment());
}
return true;
}
use of org.opennms.netmgt.model.topology.SharedSegment in project opennms by OpenNMS.
the class EnhancedLinkdServiceImpl method store.
@Override
public void store(BroadcastDomain domain, Date now) {
for (SharedSegment segment : domain.getTopology()) {
for (BridgeBridgeLink link : segment.getBridgeBridgeLinks()) {
link.setBridgeBridgeLinkLastPollTime(new Date());
saveBridgeBridgeLink(link);
}
for (BridgeMacLink link : segment.getBridgeMacLinks()) {
link.setBridgeMacLinkLastPollTime(new Date());
saveBridgeMacLink(link);
}
}
for (Integer nodeid : domain.getBridgeNodesOnDomain()) {
m_bridgeMacLinkDao.deleteByNodeIdOlderThen(nodeid, now);
m_bridgeMacLinkDao.flush();
m_bridgeBridgeLinkDao.deleteByNodeIdOlderThen(nodeid, now);
m_bridgeBridgeLinkDao.deleteByDesignatedNodeIdOlderThen(nodeid, now);
m_bridgeBridgeLinkDao.flush();
}
}
Aggregations