use of org.opennms.netmgt.model.BridgeMacLink in project opennms by OpenNMS.
the class BroadcastDomain method printTopologyBFT.
public static String printTopologyBFT(List<BridgeMacLink> bft) {
final StringBuilder strbfr = new StringBuilder();
for (BridgeMacLink link : bft) {
strbfr.append("nodeid:[");
strbfr.append(link.getNode().getId());
strbfr.append("]:");
strbfr.append(link.getMacAddress());
strbfr.append(":bridgeport:");
strbfr.append(link.getBridgePort());
strbfr.append(":ifindex:");
strbfr.append(link.getBridgePortIfIndex());
strbfr.append("\n");
}
return strbfr.toString();
}
use of org.opennms.netmgt.model.BridgeMacLink in project opennms by OpenNMS.
the class BroadcastDomain method cleanForwarders.
public void cleanForwarders(Set<String> macs) {
Map<Integer, List<BridgeMacLink>> forwadingMap = new HashMap<Integer, List<BridgeMacLink>>();
for (Integer bridgeId : m_forwarding.keySet()) {
List<BridgeMacLink> forwarders = new ArrayList<BridgeMacLink>();
for (BridgeMacLink forward : m_forwarding.get(bridgeId)) {
if (macs.contains(forward.getMacAddress()))
continue;
forwarders.add(forward);
}
if (forwarders.isEmpty())
continue;
forwadingMap.put(bridgeId, forwarders);
}
m_forwarding = forwadingMap;
}
use of org.opennms.netmgt.model.BridgeMacLink in project opennms by OpenNMS.
the class EnhancedLinkdServiceImpl method updateBft.
@Override
public void updateBft(int nodeId, List<BridgeMacLink> bft) {
Map<BridgeMacLinkHash, BridgeMacLink> effectiveBFT = new HashMap<BridgeMacLinkHash, BridgeMacLink>();
for (BridgeMacLink link : bft) {
OnmsNode node = new OnmsNode();
node.setId(nodeId);
link.setNode(node);
effectiveBFT.put(new BridgeMacLinkHash(link), link);
}
synchronized (m_nodetoBroadcastDomainMap) {
m_nodetoBroadcastDomainMap.put(nodeId, new ArrayList<BridgeMacLink>(effectiveBFT.values()));
}
}
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<>();
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.info("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().updateBft(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 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) {
if (topSegment == null) {
LOG.warn("calculate: node: [{}]: level: {}, bridge: [{}], top segment is null exiting.....", getNodeId(), level, xBridge.getId());
return false;
}
level++;
if (level == 30) {
LOG.warn("calculate: node: [{}]: level: {}, bridge: [{}], too many iteration on topology exiting.....", getNodeId(), level, xBridge.getId());
return false;
}
if (LOG.isDebugEnabled()) {
LOG.debug("calculate: node: [{}], level: {}, bridge: [{}], checking if is child of segment: [ids {}, designated bridge {}, port {}, macs {}]", getNodeId(), level, xBridge.getId(), topSegment.getBridgeIdsOnSegment(), topSegment.getDesignatedBridge(), topSegment.getDesignatedPort(), topSegment.getMacsOnSegment());
}
Set<Integer> portsAdded = new HashSet<Integer>();
Set<String> macsOnSegment = rx.getSimpleConnectionMacs();
Map<Integer, List<BridgeMacLink>> bftSets = new HashMap<Integer, List<BridgeMacLink>>();
List<BridgeMacLink> forwarders = new ArrayList<BridgeMacLink>();
forwarders.addAll(rx.getFirstBridgeForwarders());
forwarders.addAll(rx.getSecondBridgeForwarders());
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;
}
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();
// if 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;
}
// Clean also topSegment macs.
if (yxDesignatedPort == yrDesignatedPort && xyDesignatedPort != rx.getSecondBridgeConnectionPort()) {
// create a SharedSegment with root port
LOG.info("calculate: node: [{}], level: {}, bridge: [{},designated port [{}]]: found level.", getNodeId(), level, xBridge.getId(), xyDesignatedPort);
LOG.debug("calculate: node: [{}], level: {}, bridge: [{},designated port [{}]]: is 'up' for bridge: [{}].", getNodeId(), level, xBridge.getId(), xyDesignatedPort, yBridge.getId());
SharedSegment leafSegment = m_domain.getSharedSegment(xBridge.getId(), xyDesignatedPort);
if (leafSegment == null) {
leafSegment = new SharedSegment(m_domain, yx.getSimpleConnection(), yx.getSimpleConnectionMacs());
leafSegment.setDesignatedBridge(xBridge.getId());
m_domain.add(leafSegment);
} else {
leafSegment.retain(yx.getSimpleConnectionMacs(), yx.getFirstBridgePort());
}
portsAdded.add(xyDesignatedPort);
if (LOG.isDebugEnabled()) {
LOG.debug("calculate: node: [{}], level: {}, bridge [{}]. Remove bridge [{}] and macs {} from top segment.", getNodeId(), level, xBridge.getId(), yBridge.getId(), topSegment.getMacsOnSegment());
}
topSegment.getMacsOnSegment().clear();
topSegment.removeBridge(yBridgeId);
} else if (xyDesignatedPort != rx.getSecondBridgeConnectionPort() && yxDesignatedPort != yrDesignatedPort) {
LOG.warn("calculate: node: [{}]: level {}: bridge [{}]. Topology mismatch. Clearing...topology", getNodeId(), level, xBridge.getId());
return false;
} else {
macsOnSegment.retainAll(yx.getSimpleConnectionMacs());
}
forwarders.addAll(yx.getFirstBridgeForwarders());
forwarders.addAll(yx.getSecondBridgeForwarders());
}
// 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: [{}]. assign macs {} to top segment", getNodeId(), level, xBridge.getId(), macsOnSegment);
topSegment.assign(macsOnSegment, rx.getSecondBridgePort());
if (LOG.isDebugEnabled()) {
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);
if (LOG.isDebugEnabled()) {
LOG.debug("calculate: node: [{}]: level: {}, bridge: [{}]. Add shared segment. " + "[ designated bridge:[{}], " + "port:{}, " + "mac: {}]", getNodeId(), level, xBridge.getId(), xleafSegment.getDesignatedBridge(), xleafSegment.getDesignatedPort(), xleafSegment.getMacsOnSegment());
}
}
addForwarding(m_domain, forwarders);
return true;
}
Aggregations