use of org.opennms.netmgt.model.BridgeMacLink in project opennms by OpenNMS.
the class EnLinkdIT method testStoreBft.
@Test
public void testStoreBft() {
OneBridgeCompleteTopology topology = new OneBridgeCompleteTopology();
m_nodeDao.save(topology.nodeA);
m_linkd.getQueryManager().store(topology.nodeAId, topology.bftA);
List<BridgeMacLink> links = m_linkd.getQueryManager().useBridgeTopologyUpdateBFT(topology.nodeAId);
assertEquals(topology.bftA.size(), links.size());
for (BridgeMacLink link : links) {
assertEquals(BridgeDot1qTpFdbStatus.DOT1D_TP_FDB_STATUS_LEARNED, link.getBridgeDot1qTpFdbStatus());
System.err.println(link.printTopology());
}
}
use of org.opennms.netmgt.model.BridgeMacLink in project opennms by OpenNMS.
the class EnLinkdIT method testDeleteBridgeC.
@Test
public void testDeleteBridgeC() {
ABCTopology topology = new ABCTopology();
NetworkBuilder nb = new NetworkBuilder();
nb.addNode("nodeA").setForeignSource("linkd").setForeignId("nodeA").setSysObjectId("0.0").setSysName("nodeA").setType(NodeType.ACTIVE);
nb.addInterface("10.0.1.1").setIsSnmpPrimary("P").setIsManaged("M");
m_nodeDao.save(nb.getCurrentNode());
nb.addNode("nodeB").setForeignSource("linkd").setForeignId("nodeB").setSysObjectId("0.0").setSysName("nodeB").setType(NodeType.ACTIVE);
nb.addInterface("10.0.1.2").setIsSnmpPrimary("P").setIsManaged("M");
m_nodeDao.save(nb.getCurrentNode());
nb.addNode("nodeC").setForeignSource("linkd").setForeignId("nodeC").setSysObjectId("0.0").setSysName("nodeC").setType(NodeType.ACTIVE);
nb.addInterface("10.0.1.3").setIsSnmpPrimary("P").setIsManaged("M");
m_nodeDao.save(nb.getCurrentNode());
OnmsNode nodeA = m_nodeDao.findByForeignId("linkd", "nodeA");
OnmsNode nodeB = m_nodeDao.findByForeignId("linkd", "nodeB");
OnmsNode nodeC = m_nodeDao.findByForeignId("linkd", "nodeC");
topology.nodeAId = nodeA.getId();
topology.nodeBId = nodeB.getId();
topology.nodeCId = nodeC.getId();
topology.nodeA = nodeA;
topology.nodeB = nodeB;
topology.nodeC = nodeC;
BridgeBridgeLink ablink = new BridgeBridgeLink();
ablink.setNode(nodeA);
ablink.setBridgePort(topology.portAB);
ablink.setDesignatedNode(nodeB);
ablink.setDesignatedPort(topology.portBA);
ablink.setBridgeBridgeLinkLastPollTime(ablink.getBridgeBridgeLinkCreateTime());
m_bridgeBridgeLinkDao.save(ablink);
BridgeBridgeLink bclink = new BridgeBridgeLink();
bclink.setNode(nodeC);
bclink.setBridgePort(topology.portCB);
bclink.setDesignatedNode(nodeB);
bclink.setDesignatedPort(topology.portBC);
bclink.setBridgeBridgeLinkLastPollTime(ablink.getBridgeBridgeLinkCreateTime());
m_bridgeBridgeLinkDao.save(bclink);
BridgeMacLink mac1 = new BridgeMacLink();
mac1.setNode(nodeA);
mac1.setBridgePort(topology.portA);
mac1.setMacAddress(topology.mac1);
mac1.setBridgeMacLinkLastPollTime(mac1.getBridgeMacLinkCreateTime());
m_bridgeMacLinkDao.save(mac1);
BridgeMacLink mac2 = new BridgeMacLink();
mac2.setNode(nodeB);
mac2.setBridgePort(topology.portB);
mac2.setMacAddress(topology.mac2);
mac2.setBridgeMacLinkLastPollTime(mac2.getBridgeMacLinkCreateTime());
m_bridgeMacLinkDao.save(mac2);
BridgeMacLink mac3 = new BridgeMacLink();
mac3.setNode(nodeC);
mac3.setBridgePort(topology.portC);
mac3.setMacAddress(topology.mac3);
mac3.setBridgeMacLinkLastPollTime(mac3.getBridgeMacLinkCreateTime());
m_bridgeMacLinkDao.save(mac3);
m_bridgeMacLinkDao.flush();
m_bridgeBridgeLinkDao.flush();
assertEquals(3, m_bridgeMacLinkDao.countAll());
assertEquals(2, m_bridgeBridgeLinkDao.countAll());
assertNotNull(m_bridgeTopologyDao);
m_linkd.getQueryManager().loadBridgeTopology();
assertEquals(1, m_bridgeTopologyDao.getAll().size());
BroadcastDomain nodeAbd = m_linkd.getQueryManager().getBroadcastDomain(nodeA.getId().intValue());
assertNotNull(nodeAbd);
BroadcastDomain nodeBbd = m_linkd.getQueryManager().getBroadcastDomain(nodeB.getId().intValue());
assertNotNull(nodeBbd);
assertEquals(nodeAbd, nodeBbd);
BroadcastDomain nodeCbd = m_linkd.getQueryManager().getBroadcastDomain(nodeC.getId().intValue());
assertNotNull(nodeCbd);
assertEquals(nodeAbd, nodeCbd);
assertNull(nodeAbd.getRootBridgeId());
assertTrue(nodeAbd.containBridgeId(nodeA.getId()));
assertTrue(nodeAbd.containBridgeId(nodeB.getId()));
assertTrue(nodeAbd.containBridgeId(nodeC.getId()));
nodeAbd.hierarchySetUp(nodeAbd.getBridge(nodeA.getId()));
assertNotNull(nodeAbd.getRootBridgeId());
topology.check(nodeAbd);
m_linkd.deleteNode(nodeC.getId());
assertEquals(1, m_bridgeTopologyDao.getAll().size());
BroadcastDomain domain = m_bridgeTopologyDao.getAll().iterator().next();
topology.checkAB(domain);
}
use of org.opennms.netmgt.model.BridgeMacLink 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.BridgeMacLink in project opennms by OpenNMS.
the class NodeDiscoveryBridge method runCollection.
protected void runCollection() {
final Date now = new Date();
SnmpAgentConfig peer = m_linkd.getSnmpAgentConfig(getPrimaryIpAddress(), getLocation());
String community = peer.getReadCommunity();
Map<Integer, String> vlanmap = getVtpVlanMap(peer);
Map<Integer, SnmpAgentConfig> vlanSnmpAgentConfigMap = new HashMap<Integer, SnmpAgentConfig>();
for (Integer vlanId : vlanmap.keySet()) {
LOG.debug("run: node [{}], support cisco vtp: setting peer community for vlan: {}, vlanname: {}", getNodeId(), vlanId, vlanmap.get(vlanId));
SnmpAgentConfig vlanpeer = m_linkd.getSnmpAgentConfig(getPrimaryIpAddress(), getLocation());
if (vlanpeer.isVersion3()) {
vlanpeer.setContextName("vlan-" + vlanId);
} else {
vlanpeer.setReadCommunity(community + "@" + vlanId);
}
vlanSnmpAgentConfigMap.put(vlanId, vlanpeer);
}
if (vlanmap.isEmpty()) {
vlanSnmpAgentConfigMap.put(null, peer);
vlanmap.put(null, null);
}
List<BridgeMacLink> bft = new ArrayList<BridgeMacLink>();
Map<Integer, Integer> bridgeifindex = new HashMap<Integer, Integer>();
for (Entry<Integer, SnmpAgentConfig> entry : vlanSnmpAgentConfigMap.entrySet()) {
Map<Integer, Integer> vlanbridgetoifindex = walkDot1dBasePortTable(entry.getValue());
LOG.debug("run: node: [{}], vlan: {}, bridge ifindex map {}", getNodeId(), vlanmap.get(entry.getKey()), vlanbridgetoifindex);
bridgeifindex.putAll(vlanbridgetoifindex);
}
for (Entry<Integer, String> entry : vlanmap.entrySet()) {
BridgeElement bridge = getDot1dBridgeBase(vlanSnmpAgentConfigMap.get(entry.getKey()));
if (bridge != null) {
bridge.setVlan(entry.getKey());
bridge.setVlanname(vlanmap.get(entry.getKey()));
m_linkd.getQueryManager().store(getNodeId(), bridge);
} else {
LOG.debug("run: node: [{}], vlan {}. no dot1d bridge data found. skipping other operations", getNodeId(), entry.getValue());
continue;
}
if (!isValidStpBridgeId(bridge.getStpDesignatedRoot())) {
LOG.info("run: node: [{}], vlan {}. invalid designated root: spanning tree not supported.", getNodeId(), entry.getValue());
} else if (bridge.getBaseBridgeAddress().equals(getBridgeAddressFromStpBridgeId(bridge.getStpDesignatedRoot()))) {
LOG.info("run: node [{}]: vlan {}. designated root {} is itself. Skipping store.", getNodeId(), entry.getValue(), bridge.getStpDesignatedRoot());
} else {
for (BridgeStpLink stplink : walkSpanningTree(vlanSnmpAgentConfigMap.get(entry.getKey()), bridge.getBaseBridgeAddress())) {
stplink.setVlan(entry.getKey());
stplink.setStpPortIfIndex(bridgeifindex.get(stplink.getStpPort()));
m_linkd.getQueryManager().store(getNodeId(), stplink);
}
}
bft = walkDot1dTpFdp(entry.getValue(), entry.getKey(), bridgeifindex, bft, vlanSnmpAgentConfigMap.get(entry.getKey()));
}
LOG.debug("run: node [{}]: bridge ifindex map {}", getNodeId(), bridgeifindex);
bft = walkDot1qTpFdb(peer, bridgeifindex, bft);
LOG.debug("run: node [{}]: bft size:{}", getNodeId(), bft.size());
if (bft.size() > 0) {
LOG.debug("run: node [{}]: updating topology", getNodeId());
m_linkd.getQueryManager().store(getNodeId(), bft);
m_linkd.scheduleBridgeTopologyDiscovery(getNodeId());
}
LOG.debug("run: node [{}]: deleting older the time {}", getNodeId(), now);
m_linkd.collectedBft(getNodeId());
m_linkd.getQueryManager().reconcileBridge(getNodeId(), now);
}
use of org.opennms.netmgt.model.BridgeMacLink 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 10 or 10% of the all size
if (retainedSet.size() > 10 || retainedSet.size() >= incomingSet.size() * 0.1) {
LOG.debug("run: node: [{}], domain {} found!", getNodeId(), domain.getBridgeNodesOnDomain());
m_domain = domain;
}
}
if (m_domain == null) {
LOG.debug("run: node: [{}] Creating a new Domain", getNodeId());
m_domain = new BroadcastDomain();
m_linkd.getQueryManager().save(m_domain);
}
LOG.debug("run: node: [{}], Found Broadcast Bomain. Print Topology. {} ", getNodeId(), m_domain.printTopology());
LOG.info("run: node: [{}], getting broadcast domain. End", getNodeId());
Map<Integer, List<BridgeMacLink>> nodeBftMap = m_linkd.getQueryManager().getUpdateBftMap();
Set<Integer> nodeswithupdatedbftonbroadcastdomain = getAllNodesWithUpdatedBFTOnDomain(incomingSet, nodeBftMap);
boolean stop = false;
for (BroadcastDomain domain : m_linkd.getQueryManager().getAllBroadcastDomains()) {
if (m_domain == domain)
continue;
LOG.debug("run: node [{}]: cleaning broadcast domain {}.", getNodeId(), domain.getBridgeNodesOnDomain());
for (Integer curNodeId : nodeswithupdatedbftonbroadcastdomain) {
if (domain.containBridgeId(curNodeId)) {
LOG.debug("run: node [{}]: node [{}]: removing from broadcast domain {}!", getNodeId(), curNodeId, domain.getBridgeNodesOnDomain());
if (!domain.getLock(this)) {
LOG.info("run: node [{}]: node [{}]: broadcast domain {}: is locked. cannot clear topology.", getNodeId(), curNodeId, domain.getBridgeNodesOnDomain());
stop = true;
continue;
}
domain.clearTopologyForBridge(curNodeId);
domain.removeBridge(curNodeId);
m_linkd.getQueryManager().store(domain, now);
domain.releaseLock(this);
m_linkd.getQueryManager().cleanBroadcastDomains();
}
}
}
if (stop || !m_domain.getLock(this)) {
LOG.info("run: node [{}]: broadcast domain locked. scheduling with time interval {}", getNodeId(), getInitialSleepTime());
schedule();
return;
}
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);
}
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());
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());
return;
}
calculate();
LOG.info("run: node: [{}], saving Topology.", getNodeId());
m_linkd.getQueryManager().store(m_domain, now);
LOG.info("run: node: [{}], saved Topology.", getNodeId());
for (Integer curNode : nodeswithupdatedbftonbroadcastdomain) sendCompletedEvent(curNode);
m_domain.releaseLock(this);
LOG.info("run: node: {}, releaseLock broadcast domain: {}.", getNodeId(), m_domain.getBridgeNodesOnDomain());
}
Aggregations