示例#1
0
  @Test
  public void testGetNodeidFromIp() throws UnknownHostException, SQLException {
    m_nodeDao.save(builder.getCiscoC870());
    m_nodeDao.flush();

    HibernateEventWriter db = (HibernateEventWriter) m_linkd.getQueryManager();

    final OnmsNode node = db.getNodeidFromIp(InetAddressUtils.addr(CISCO_C870_IP)).get(0);
    assertEquals(m_nodeDao.findByForeignId("linkd", CISCO_C870_NAME).getId(), node.getId());
  }
示例#2
0
  @Test
  @Transactional
  public void testGetIfIndexByName() throws SQLException {
    m_nodeDao.save(builder.getCiscoC870());
    m_nodeDao.save(builder.getCiscoWsC2948());
    m_nodeDao.flush();

    OnmsNode ciscorouter = m_nodeDao.findByForeignId("linkd", CISCO_C870_NAME);
    assertEquals("FastEthernet2", ciscorouter.getSnmpInterfaceWithIfIndex(3).getIfDescr());

    OnmsNode ciscosw = m_nodeDao.findByForeignId("linkd", CISCO_WS_C2948_NAME);
    assertEquals("2/44", ciscosw.getSnmpInterfaceWithIfIndex(52).getIfName());

    HibernateEventWriter db = (HibernateEventWriter) m_linkd.getQueryManager();
    assertEquals(3, db.getIfIndexByName(ciscorouter.getId(), "FastEthernet2"));
    assertEquals(52, db.getIfIndexByName(ciscosw.getId(), "2/44"));
  }
示例#3
0
  @Test
  public void testDefaultConfiguration2()
      throws MarshalException, ValidationException, IOException {

    assertEquals(5, m_linkdConfig.getThreads());
    assertEquals(3600000, m_linkdConfig.getInitialSleepTime());
    assertEquals(18000000, m_linkdConfig.getSnmpPollInterval());
    assertEquals(1800000, m_linkdConfig.getDiscoveryLinkInterval());

    assertEquals(false, m_linkdConfig.isAutoDiscoveryEnabled());
    assertEquals(true, m_linkdConfig.isVlanDiscoveryEnabled());
    assertEquals(true, m_linkdConfig.useCdpDiscovery());
    assertEquals(true, m_linkdConfig.useIpRouteDiscovery());
    assertEquals(true, m_linkdConfig.useBridgeDiscovery());
    assertEquals(true, m_linkdConfig.useOspfDiscovery());
    assertEquals(true, m_linkdConfig.useLldpDiscovery());
    assertEquals(true, m_linkdConfig.useIsIsDiscovery());

    assertEquals(true, m_linkdConfig.saveRouteTable());
    assertEquals(true, m_linkdConfig.saveStpNodeTable());
    assertEquals(true, m_linkdConfig.saveStpInterfaceTable());
    assertEquals(false, m_linkdConfig.forceIpRouteDiscoveryOnEthernet());

    Enumeration<org.opennms.netmgt.config.linkd.Package> iter = m_linkdConfig.enumeratePackage();
    org.opennms.netmgt.config.linkd.Package example1 = iter.nextElement();

    assertEquals(false, iter.hasMoreElements());
    assertEquals("example1", example1.getName());
    assertEquals(false, example1.hasAutoDiscovery());
    assertEquals(false, example1.hasDiscovery_link_interval());
    assertEquals(false, example1.hasEnableVlanDiscovery());
    assertEquals(false, example1.hasForceIpRouteDiscoveryOnEthernet());
    assertEquals(false, example1.hasSaveRouteTable());
    assertEquals(false, example1.hasSaveStpInterfaceTable());
    assertEquals(false, example1.hasSaveStpNodeTable());
    assertEquals(false, example1.hasSnmp_poll_interval());
    assertEquals(false, example1.hasUseBridgeDiscovery());
    assertEquals(false, example1.hasUseCdpDiscovery());
    assertEquals(false, example1.hasUseIpRouteDiscovery());
    assertEquals(false, example1.hasUseIsisDiscovery());

    assertEquals(
        false, m_linkdConfig.isInterfaceInPackage(InetAddressUtils.addr(CISCO_C870_IP), example1));

    m_nodeDao.save(builder.getCiscoC870());
    m_nodeDao.save(builder.getCiscoWsC2948());
    m_nodeDao.flush();

    m_linkdConfig.update();

    assertEquals(
        true, m_linkdConfig.isInterfaceInPackage(InetAddressUtils.addr(CISCO_C870_IP), example1));
    assertEquals(
        true,
        m_linkdConfig.isInterfaceInPackage(InetAddressUtils.addr(CISCO_WS_C2948_IP), example1));

    final OnmsNode ciscorouter = m_nodeDao.findByForeignId("linkd", CISCO_C870_NAME);
    final OnmsNode ciscows = m_nodeDao.findByForeignId("linkd", CISCO_WS_C2948_NAME);
    assertTrue(m_linkd.scheduleNodeCollection(ciscorouter.getId()));
    assertTrue(m_linkd.scheduleNodeCollection(ciscows.getId()));

    LinkableNode lciscorouter =
        m_linkd.removeNode("example1", InetAddressUtils.addr(CISCO_C870_IP));
    assertNotNull(lciscorouter);
    assertEquals(ciscorouter.getId().intValue(), lciscorouter.getNodeId());

    assertEquals(1, m_linkd.getActivePackages().size());
  }
示例#4
0
  @Test
  @JUnitSnmpAgents(
      value = {
        @JUnitSnmpAgent(
            host = CISCO_C870_IP,
            port = 161,
            resource = "classpath:linkd/nms7467/" + CISCO_C870_IP + "-walk.txt")
      })
  public void testCiscoC870Collection() throws Exception {
    m_nodeDao.save(builder.getCiscoC870());
    m_nodeDao.flush();

    Package example1 = m_linkdConfig.getPackage("example1");
    example1.setUseLldpDiscovery(false);
    example1.setUseOspfDiscovery(false);
    example1.setUseIsisDiscovery(false);

    final OnmsNode ciscorouter = m_nodeDao.findByForeignId("linkd", CISCO_C870_NAME);

    assertTrue(m_linkd.scheduleNodeCollection(ciscorouter.getId()));

    assertTrue(m_linkd.runSingleSnmpCollection(ciscorouter.getId()));

    // linkd has 1 linkable node
    assertEquals(1, m_linkd.getLinkableNodesOnPackage("example1").size());
    LinkableNode linkNode = m_linkd.getLinkableNodesOnPackage("example1").iterator().next();

    // linkabble node is not null
    assertTrue(linkNode != null);

    // has 0 route (next hop must be valid!)
    assertEquals(0, linkNode.getRouteInterfaces().size());
    // has 0 vlan
    assertEquals(0, m_vlanDao.countAll());

    String packageName =
        m_linkdConfig.getFirstPackageMatch(InetAddressUtils.addr(CISCO_C870_IP)).getName();

    assertEquals("example1", packageName);

    assertEquals(1, linkNode.getBridgeIdentifiers().size());

    // has 1 stp node entry check the bridge identifier and protocol
    assertEquals(CISCO_C870_BRIDGEID, linkNode.getBridgeIdentifier(1));

    // has 50 stp entry che ifIndex must be different then -1
    //
    assertEquals(1, linkNode.getStpInterfaces().get(1).size());

    // no cdp inteface also if the walk return several interfaces
    assertEquals(
        "No cdp interface because no other node is there", 0, linkNode.getCdpInterfaces().size());

    for (OnmsStpInterface stpiface : linkNode.getStpInterfaces().get(1)) {
      assertTrue("should have a valid ifindex", stpiface.getIfIndex().intValue() > 0);
      assertTrue("should have a valid bridgeport", stpiface.getBridgePort().intValue() > 0);
    }

    // This make shure that the ip/mac association is saved
    /*
     * nodelabel:ip:mac:ifindex:ifdescr
     *
     * CISCO_C870:172.20.1.1:001f6cd034e7:12:Vlan1
     * CISCO_C870:172.20.2.1:001f6cd034e7:13:Vlan2
     * CISCO_C870:10.255.255.2:001f6cd034e7:12:Vlan1
     * CISCO_C870:65.41.39.146:00000c03b09e:14:BVI1
     */

    final Set<String> macAddresses = m_linkd.getMacAddressesOnPackage(packageName);
    assertEquals(2, macAddresses.size());
    List<AtInterface> ats = m_linkd.getAtInterfaces(packageName, "001f6cd034e7");
    assertNotNull(ats);

    assertEquals(3, ats.size());
    for (final AtInterface at : ats) {
      if (at.getIpAddress().getHostAddress().equals("172.20.1.1"))
        assertEquals(12, at.getIfIndex().intValue());
      else if (at.getIpAddress().getHostAddress().equals("172.20.2.1"))
        assertEquals(13, at.getIfIndex().intValue());
      else if (at.getIpAddress().getHostAddress().equals("10.255.255.2"))
        assertEquals(12, at.getIfIndex().intValue());
      else
        assertTrue(
            "ip: " + at.getIpAddress().getHostAddress() + "does not match any known ip address",
            false);
    }

    ats = m_linkd.getAtInterfaces(packageName, "00000c03b09e");
    assertEquals(1, ats.size());
    for (AtInterface at : ats) {
      if (at.getIpAddress().getHostAddress().equals("65.41.39.146"))
        assertEquals(14, at.getIfIndex().intValue());
      else
        assertTrue(
            "ip: " + at.getIpAddress().getHostAddress() + "does not match any known ip address",
            false);
    }

    // Now Let's test the database
    // 0 atinterface in database
    assertEquals(4, m_atInterfaceDao.countAll());

    final Criteria criteria = new Criteria(OnmsIpRouteInterface.class);
    criteria.setAliases(Arrays.asList(new Alias[] {new Alias("node", "node", JoinType.LEFT_JOIN)}));
    criteria.addRestriction(new EqRestriction("node.id", ciscorouter.getId()));
    final List<OnmsIpRouteInterface> iproutes = m_ipRouteInterfaceDao.findMatching(criteria);
    // 7 route entry in database
    for (OnmsIpRouteInterface iproute : iproutes) {
      System.out.println(
          iproute.getRouteDest()
              + "/"
              + iproute.getRouteMask()
              + "/"
              + iproute.getRouteNextHop()
              + "/"
              + iproute.getRouteIfIndex());
    }
    assertEquals(7, iproutes.size());

    // 0 entry in vlan
    assertEquals(0, m_vlanDao.findAll().size());

    // 1 entry in stpnode
    assertEquals(1, m_stpNodeDao.countAll());

    OnmsStpNode stpnode = m_stpNodeDao.findByNodeAndVlan(ciscorouter.getId(), 1);
    assertTrue(CISCO_C870_BRIDGEID.equals(stpnode.getBaseBridgeAddress()));
    assertEquals(1, stpnode.getBaseNumPorts().intValue());

    assertEquals(BridgeBaseType.SRT, stpnode.getBaseType());
    assertEquals(StpProtocolSpecification.IEEE8021D, stpnode.getStpProtocolSpecification());

    // 1 entry in stpinterface
    assertEquals(1, m_stpInterfaceDao.findAll().size());
  }