Search in sources :

Example 1 with Dot1qTpFdbTableTracker

use of org.opennms.netmgt.enlinkd.snmp.Dot1qTpFdbTableTracker in project opennms by OpenNMS.

the class EnLinkdSnmpIT method testDot1qTpFdbTableWalk.

@Test
@JUnitSnmpAgents(value = { @JUnitSnmpAgent(host = DLINK1_IP, port = 161, resource = DLINK1_SNMP_RESOURCE), @JUnitSnmpAgent(host = DLINK2_IP, port = 161, resource = DLINK2_SNMP_RESOURCE) })
public void testDot1qTpFdbTableWalk() throws Exception {
    String trackerName = "dot1qTpFdbTable";
    final Map<String, Integer> macs1 = new HashMap<String, Integer>();
    final Map<String, Integer> macs2 = new HashMap<String, Integer>();
    SnmpAgentConfig config1 = SnmpPeerFactory.getInstance().getAgentConfig(InetAddress.getByName(DLINK1_IP));
    Dot1qTpFdbTableTracker tracker1 = new Dot1qTpFdbTableTracker() {

        @Override
        public void processDot1qTpFdbRow(final Dot1qTpFdbRow row) {
            macs1.put(row.getDot1qTpFdbAddress(), row.getDot1qTpFdbPort());
        }
    };
    try {
        m_client.walk(config1, tracker1).withDescription(trackerName).withLocation(null).execute().get();
    } catch (final InterruptedException e) {
        LOG.error("run: collection interrupted, exiting", e);
        return;
    }
    SnmpAgentConfig config2 = SnmpPeerFactory.getInstance().getAgentConfig(InetAddress.getByName(DLINK2_IP));
    Dot1qTpFdbTableTracker tracker2 = new Dot1qTpFdbTableTracker() {

        @Override
        public void processDot1qTpFdbRow(final Dot1qTpFdbRow row) {
            macs2.put(row.getDot1qTpFdbAddress(), row.getDot1qTpFdbPort());
        }
    };
    try {
        m_client.walk(config2, tracker2).withDescription(trackerName).withLocation(null).execute().get();
    } catch (final InterruptedException e) {
        LOG.error("run: collection interrupted, exiting", e);
        return;
    }
    assertEquals(59, macs1.size());
    assertEquals(979, macs2.size());
    for (Entry<String, Integer> entry : macs1.entrySet()) {
        if (macs2.containsKey(entry.getKey())) {
            System.out.println("-----------mac on 1 learned on 2 port-----------------");
            System.out.println("Mac: " + entry.getKey());
            System.out.println("learned on PortOn1: " + entry.getValue());
            System.out.println("learned on PortOn2: " + macs2.get(entry.getKey()));
        } else {
            System.out.println("-----------mac found on 1 not learned on 2 port-----------------");
            System.out.println("Mac: " + entry.getKey());
            System.out.println("learned on PortOn1: " + entry.getValue());
        }
    }
    for (Entry<String, Integer> entry : macs2.entrySet()) {
        if (macs1.containsKey(entry.getKey())) {
            System.out.println("-----------mac on 2 learned on 1 port-----------------");
            System.out.println("Mac: " + entry.getKey());
            System.out.println("learned on PortOn2: " + entry.getValue());
            System.out.println("learned on PortOn1: " + macs1.get(entry.getKey()));
        }
    }
}
Also used : SnmpAgentConfig(org.opennms.netmgt.snmp.SnmpAgentConfig) HashMap(java.util.HashMap) Dot1qTpFdbTableTracker(org.opennms.netmgt.enlinkd.snmp.Dot1qTpFdbTableTracker) Test(org.junit.Test) JUnitSnmpAgents(org.opennms.core.test.snmp.annotations.JUnitSnmpAgents)

Example 2 with Dot1qTpFdbTableTracker

use of org.opennms.netmgt.enlinkd.snmp.Dot1qTpFdbTableTracker in project opennms by OpenNMS.

the class NodeDiscoveryBridge method walkDot1qTpFdb.

private List<BridgeMacLink> walkDot1qTpFdb(SnmpAgentConfig peer, final Map<Integer, Integer> bridgeifindex, final List<BridgeMacLink> bft) {
    Dot1qTpFdbTableTracker dot1qTpFdbTableTracker = new Dot1qTpFdbTableTracker() {

        @Override
        public void processDot1qTpFdbRow(final Dot1qTpFdbRow row) {
            BridgeMacLink link = row.getLink();
            if (link.getBridgeDot1qTpFdbStatus() == null) {
                LOG.info("processDot1qTpFdbRow: node [{}]: mac {}: on port {}. row has null status.", getNodeId(), row.getDot1qTpFdbAddress(), row.getDot1qTpFdbPort());
                return;
            }
            if (link.getBridgePort() == null) {
                LOG.info("processDot1qTpFdbRow: node [{}]: mac {}: on port {} status {}. row has null bridge port.", getNodeId(), row.getDot1qTpFdbAddress(), row.getDot1qTpFdbPort(), link.getBridgeDot1qTpFdbStatus());
                return;
            }
            if (link.getMacAddress() == null || !isValidBridgeAddress(link.getMacAddress())) {
                LOG.info("processDot1qTpFdbRow: node [{}]: mac {}: on port {} ifindex {} status {}. row has invalid mac.", getNodeId(), row.getDot1qTpFdbAddress(), row.getDot1qTpFdbPort(), link.getBridgePortIfIndex(), link.getBridgeDot1qTpFdbStatus());
                return;
            }
            if (bridgeifindex.isEmpty() && link.getBridgeDot1qTpFdbStatus() != BridgeDot1qTpFdbStatus.DOT1D_TP_FDB_STATUS_SELF) {
                link.setBridgePortIfIndex(link.getBridgePort());
                LOG.debug("processDot1qTpFdbRow: node [{}]: mac {}: on port {} ifindex {} status {}. Empty map from bridgeport to ifindex. Assuming ifindex=bridgeport", getNodeId(), row.getDot1qTpFdbAddress(), row.getDot1qTpFdbPort(), link.getBridgePortIfIndex(), link.getBridgeDot1qTpFdbStatus());
            } else if (!bridgeifindex.containsKey(link.getBridgePort()) && bridgeifindex.containsValue(link.getBridgePort()) && link.getBridgeDot1qTpFdbStatus() != BridgeDot1qTpFdbStatus.DOT1D_TP_FDB_STATUS_SELF) {
                for (Integer bridgeport : bridgeifindex.keySet()) {
                    if (link.getBridgePort().intValue() == bridgeifindex.get(bridgeport).intValue()) {
                        link.setBridgePort(bridgeport);
                        link.setBridgePortIfIndex(bridgeifindex.get(bridgeport));
                    }
                }
                LOG.debug("processDot1qTpFdbRow: node [{}]: mac {}: on port {} ifindex {} status {}. Assument bridgeport index is ifindex. Reverting bridgeport/ifindex", getNodeId(), row.getDot1qTpFdbAddress(), row.getDot1qTpFdbPort(), link.getBridgePortIfIndex(), link.getBridgeDot1qTpFdbStatus());
            } else if (!bridgeifindex.containsKey(link.getBridgePort()) && link.getBridgeDot1qTpFdbStatus() != BridgeDot1qTpFdbStatus.DOT1D_TP_FDB_STATUS_SELF) {
                LOG.debug("processDot1qTpFdbRow: node [{}]: mac {}: on port {} ifindex {} status {}. Cnnot find suitable skipping entry", getNodeId(), row.getDot1qTpFdbAddress(), row.getDot1qTpFdbPort(), link.getBridgePortIfIndex(), link.getBridgeDot1qTpFdbStatus());
                return;
            } else {
                link.setBridgePortIfIndex(bridgeifindex.get(link.getBridgePort()));
            }
            LOG.debug("processDot1qTpFdbRow: node [{}]: mac {}: vlan {}: on port {} ifindex {} status {}. row processed.", getNodeId(), link.getMacAddress(), link.getVlan(), link.getBridgePort(), link.getBridgePortIfIndex(), link.getBridgeDot1qTpFdbStatus());
            bft.add(link);
        }
    };
    try {
        m_linkd.getLocationAwareSnmpClient().walk(peer, dot1qTpFdbTableTracker).withDescription("dot1qTbFdbPortTable").withLocation(getLocation()).execute().get();
    } catch (ExecutionException e) {
        LOG.info("run: node [{}]: ExecutionException: dot1qTbFdbPortTable: {}", getNodeId(), e.getMessage());
    } catch (final InterruptedException e) {
        LOG.info("run: node [{}]: InterruptedException: dot1qTbFdbPortTable: {}", getNodeId(), e.getMessage());
    }
    return bft;
}
Also used : Dot1qTpFdbTableTracker(org.opennms.netmgt.enlinkd.snmp.Dot1qTpFdbTableTracker) ExecutionException(java.util.concurrent.ExecutionException) BridgeMacLink(org.opennms.netmgt.model.BridgeMacLink)

Aggregations

Dot1qTpFdbTableTracker (org.opennms.netmgt.enlinkd.snmp.Dot1qTpFdbTableTracker)2 HashMap (java.util.HashMap)1 ExecutionException (java.util.concurrent.ExecutionException)1 Test (org.junit.Test)1 JUnitSnmpAgents (org.opennms.core.test.snmp.annotations.JUnitSnmpAgents)1 BridgeMacLink (org.opennms.netmgt.model.BridgeMacLink)1 SnmpAgentConfig (org.opennms.netmgt.snmp.SnmpAgentConfig)1