@Test
 @Transactional
 public void testSortOnNodeLabel() {
   Criteria criteria = new Criteria(OnmsAlarm.class);
   criteria.setAliases(Arrays.asList(new Alias[] {new Alias("node", "node", JoinType.LEFT_JOIN)}));
   criteria.setOrders(Arrays.asList(new Order[] {Order.asc("node.label")}));
   m_alarmDao.findMatching(criteria);
 }
  /**
   * closeOutagesForNode
   *
   * @param closeDate a {@link java.util.Date} object.
   * @param eventId a int.
   * @param nodeId a int.
   */
  @Override
  public void closeOutagesForNode(Date closeDate, int eventId, int nodeId) {
    Criteria criteria = new Criteria(OnmsOutage.class);
    criteria.setAliases(
        Arrays.asList(
            new Alias[] {
              new Alias("monitoredService.ipInterface", "ipInterface", JoinType.LEFT_JOIN),
              new Alias("ipInterface.node", "node", JoinType.LEFT_JOIN)
            }));
    criteria.addRestriction(new EqRestriction("node.id", nodeId));
    criteria.addRestriction(new NullRestriction("ifRegainedService"));
    List<OnmsOutage> outages = m_outageDao.findMatching(criteria);

    for (OnmsOutage outage : outages) {
      outage.setIfRegainedService(closeDate);
      outage.setServiceRegainedEvent(m_eventDao.get(eventId));
      m_outageDao.update(outage);
    }
  }
  @Override
  public List<String[]> getNodeServices(int nodeId) {
    final LinkedList<String[]> servicemap = new LinkedList<String[]>();

    Criteria criteria = new Criteria(OnmsMonitoredService.class);
    criteria.setAliases(
        Arrays.asList(
            new Alias[] {
              new Alias("ipInterface", "ipInterface", JoinType.LEFT_JOIN),
              new Alias("ipInterface.node", "node", JoinType.LEFT_JOIN)
            }));
    criteria.addRestriction(new EqRestriction("node.id", nodeId));
    criteria.addRestriction(new NeRestriction("status", "F")); // Ignore forced-unmanaged
    for (OnmsMonitoredService service : m_monitoredServiceDao.findMatching(criteria)) {
      servicemap.add(new String[] {service.getIpAddressAsString(), service.getServiceName()});
    }

    return servicemap;
  }
  @Override
  public List<LinkableSnmpNode> getSnmpNodeList() {
    final List<LinkableSnmpNode> nodes = new ArrayList<LinkableSnmpNode>();

    final Criteria criteria = new Criteria(OnmsNode.class);
    criteria.setAliases(
        Arrays.asList(new Alias[] {new Alias("ipInterfaces", "iface", JoinType.LEFT_JOIN)}));
    criteria.addRestriction(new EqRestriction("type", NodeType.ACTIVE));
    criteria.addRestriction(new EqRestriction("iface.isSnmpPrimary", PrimaryType.PRIMARY));
    for (final OnmsNode node : m_nodeDao.findMatching(criteria)) {
      nodes.add(
          new LinkableSnmpNode(
              node.getId(),
              node.getPrimaryInterface().getIpAddress(),
              node.getSysObjectId(),
              node.getSysName()));
    }
    return nodes;
  }
  @Test
  @Transactional
  public void testSave() {
    OnmsEvent event = new OnmsEvent();
    event.setEventLog("Y");
    event.setEventDisplay("Y");
    event.setEventCreateTime(new Date());
    event.setDistPoller(m_distPollerDao.load("localhost"));
    event.setEventTime(new Date());
    event.setEventSeverity(new Integer(7));
    event.setEventUei("uei://org/opennms/test/EventDaoTest");
    event.setEventSource("test");
    m_eventDao.save(event);

    OnmsNode node = m_nodeDao.findAll().iterator().next();

    OnmsAlarm alarm = new OnmsAlarm();

    alarm.setNode(node);
    alarm.setUei(event.getEventUei());
    alarm.setSeverityId(event.getEventSeverity());
    alarm.setFirstEventTime(event.getEventTime());
    alarm.setLastEvent(event);
    alarm.setCounter(1);
    alarm.setDistPoller(m_distPollerDao.load("localhost"));

    m_alarmDao.save(alarm);
    // It works we're so smart! hehe

    OnmsAlarm newAlarm = m_alarmDao.load(alarm.getId());
    assertEquals("uei://org/opennms/test/EventDaoTest", newAlarm.getUei());
    assertEquals(alarm.getLastEvent().getId(), newAlarm.getLastEvent().getId());

    Collection<OnmsAlarm> alarms;
    Criteria criteria = new Criteria(OnmsAlarm.class);
    criteria.addRestriction(new EqRestriction("node.id", node.getId()));
    alarms = m_alarmDao.findMatching(criteria);
    assertEquals(1, alarms.size());
    newAlarm = alarms.iterator().next();
    assertEquals("uei://org/opennms/test/EventDaoTest", newAlarm.getUei());
    assertEquals(alarm.getLastEvent().getId(), newAlarm.getLastEvent().getId());
  }
  @Override
  public LinkableSnmpNode getSnmpNode(final int nodeid) {
    final Criteria criteria = new Criteria(OnmsNode.class);
    criteria.setAliases(
        Arrays.asList(new Alias[] {new Alias("ipInterfaces", "iface", JoinType.LEFT_JOIN)}));
    criteria.addRestriction(new EqRestriction("type", NodeType.ACTIVE));
    criteria.addRestriction(new EqRestriction("iface.isSnmpPrimary", PrimaryType.PRIMARY));
    criteria.addRestriction(new EqRestriction("id", nodeid));
    final List<OnmsNode> nodes = m_nodeDao.findMatching(criteria);

    if (nodes.size() > 0) {
      final OnmsNode node = nodes.get(0);
      return new LinkableSnmpNode(
          node.getId(),
          node.getPrimaryInterface().getIpAddress(),
          node.getSysObjectId(),
          node.getSysName());
    } else {
      return null;
    }
  }
  @Override
  public void closeOutagesForUnmanagedServices() {
    Date closeDate = new java.util.Date();
    Criteria criteria = new Criteria(OnmsOutage.class);
    criteria.setAliases(
        Arrays.asList(
            new Alias[] {new Alias("monitoredService", "monitoredService", JoinType.LEFT_JOIN)}));
    criteria.addRestriction(
        new AnyRestriction(
            new EqRestriction("monitoredService.status", "D"),
            new EqRestriction("monitoredService.status", "F"),
            new EqRestriction("monitoredService.status", "U")));
    criteria.addRestriction(new NullRestriction("ifRegainedService"));
    List<OnmsOutage> outages = m_outageDao.findMatching(criteria);

    for (OnmsOutage outage : outages) {
      outage.setIfRegainedService(closeDate);
      m_outageDao.update(outage);
    }

    criteria = new Criteria(OnmsOutage.class);
    criteria.setAliases(
        Arrays.asList(
            new Alias[] {
              new Alias("monitoredService.ipInterface", "ipInterface", JoinType.LEFT_JOIN)
            }));
    criteria.addRestriction(
        new AnyRestriction(
            new EqRestriction("ipInterface.isManaged", "F"),
            new EqRestriction("ipInterface.isManaged", "U")));
    criteria.addRestriction(new NullRestriction("ifRegainedService"));
    outages = m_outageDao.findMatching(criteria);

    for (OnmsOutage outage : outages) {
      outage.setIfRegainedService(closeDate);
      m_outageDao.update(outage);
    }
  }
  protected void applyQueryFilters(
      final MultivaluedMap<String, String> p, final CriteriaBuilder builder) {
    final MultivaluedMap<String, String> params = new MultivaluedMapImpl();
    params.putAll(p);

    builder.distinct();
    builder.limit(DEFAULT_LIMIT);

    // not sure why we remove this, but that's what the old query filter code did, I presume there's
    // a reason  :)
    params.remove("_dc");

    if (params.containsKey("limit")) {
      builder.limit(Integer.valueOf(params.getFirst("limit")));
      params.remove("limit");
    }
    if (params.containsKey("offset")) {
      builder.offset(Integer.valueOf(params.getFirst("offset")));
      params.remove("offset");
    }
    // Is this necessary anymore? setLimitOffset() comments implies it's for Ext-JS.
    if (params.containsKey("start")) {
      builder.offset(Integer.valueOf(params.getFirst("start")));
      params.remove("start");
    }

    if (params.containsKey("orderBy")) {
      builder.orderBy(params.getFirst("orderBy"));
      params.remove("orderBy");

      if (params.containsKey("order")) {
        if ("desc".equalsIgnoreCase(params.getFirst("order"))) {
          builder.desc();
        } else {
          builder.asc();
        }
        params.remove("order");
      }
    }

    final String query = removeParameter(params, "query");
    if (query != null) builder.sql(query);

    final String matchType;
    final String match = removeParameter(params, "match");
    if (match == null) {
      matchType = "all";
    } else {
      matchType = match;
    }
    builder.match(matchType);

    final Class<?> criteriaClass = builder.toCriteria().getCriteriaClass();
    final BeanWrapper wrapper = getBeanWrapperForClass(criteriaClass);

    final String comparatorParam = removeParameter(params, "comparator", "eq").toLowerCase();
    final Criteria currentCriteria = builder.toCriteria();

    for (final String key : params.keySet()) {
      for (final String paramValue : params.get(key)) { // NOSONAR
        // NOSONAR the interface of MultivaluedMap.class declares List<String> as return value,
        // the actual implementation com.sun.jersey.core.util.MultivaluedMapImpl returns a String,
        // so this is fine in some way ...
        if ("null".equalsIgnoreCase(paramValue)) {
          builder.isNull(key);
        } else if ("notnull".equalsIgnoreCase(paramValue)) {
          builder.isNotNull(key);
        } else {
          Object value;
          Class<?> type = Object.class;
          try {
            type = currentCriteria.getType(key);
          } catch (final IntrospectionException e) {
            LOG.debug("Unable to determine type for key {}", key);
          }
          if (type == null) {
            type = Object.class;
          }
          LOG.warn("comparator = {}, key = {}, propertyType = {}", comparatorParam, key, type);

          if (comparatorParam.equals("contains")
              || comparatorParam.equals("iplike")
              || comparatorParam.equals("ilike")
              || comparatorParam.equals("like")) {
            value = paramValue;
          } else {
            LOG.debug("convertIfNecessary({}, {})", key, paramValue);
            try {
              value = wrapper.convertIfNecessary(paramValue, type);
            } catch (final Throwable t) {
              LOG.debug("failed to introspect (key = {}, value = {})", key, paramValue, t);
              value = paramValue;
            }
          }

          try {
            final Method m =
                builder.getClass().getMethod(comparatorParam, String.class, Object.class);
            m.invoke(builder, new Object[] {key, value});
          } catch (final Throwable t) {
            LOG.warn(
                "Unable to find method for comparator: {}, key: {}, value: {}",
                comparatorParam,
                key,
                value,
                t);
          }
        }
      }
    }
  }
Exemple #9
0
  @Test
  @JUnitSnmpAgents(
      value = {
        @JUnitSnmpAgent(
            host = DARWIN_10_8_IP,
            port = 161,
            resource = "classpath:linkd/nms7467/" + DARWIN_10_8_IP + "-walk.txt")
      })
  public void testDarwin108Collection() throws Exception {
    m_nodeDao.save(builder.getDarwin108());
    m_nodeDao.flush();

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

    m_linkdConfig.update();

    final OnmsNode mac = m_nodeDao.findByForeignId("linkd", DARWIN_10_8_NAME);

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

    assertTrue(m_linkd.runSingleSnmpCollection(mac.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 1 route (next hop must be valid!) no ip route table
    assertEquals(0, linkNode.getRouteInterfaces().size());
    // has 0 vlan
    assertEquals(0, m_vlanDao.countAll());

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

    assertEquals("example1", packageName);

    assertEquals(false, linkNode.isBridgeNode());

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

    // no cdp inteface also if the walk return several interfaces
    assertEquals("cdp not supported", 0, linkNode.getCdpInterfaces().size());

    // This make shure that the ip/mac association is saved
    /*
     * nodelabel:ip:mac:ifindex:ifdescr
     * DARWIN_10_8:172.20.1.28:0026b0ed8fb8:4:en0
     *
     */

    final Set<String> macAddresses = m_linkd.getMacAddressesOnPackage(packageName);
    assertNotNull(macAddresses);
    assertEquals(1, macAddresses.size());

    List<AtInterface> ats = m_linkd.getAtInterfaces(packageName, "0026b0ed8fb8");
    assertNotNull(ats);
    assertEquals("should have saved 1 ip to mac", 1, ats.size());

    for (AtInterface at : ats) {
      if (at.getIpAddress().getHostAddress().equals("172.20.1.28"))
        assertTrue(at.getIfIndex().intValue() == 4);
      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(0, m_atInterfaceDao.findAll().size());

    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", mac.getId()));
    final List<OnmsIpRouteInterface> iproutes = m_ipRouteInterfaceDao.findMatching(criteria);
    // 4 route entry in database
    for (OnmsIpRouteInterface iproute : iproutes) {
      System.out.println(
          iproute.getRouteDest()
              + "/"
              + iproute.getRouteMask()
              + "/"
              + iproute.getRouteNextHop()
              + "/"
              + iproute.getRouteIfIndex());
    }
    assertEquals(20, iproutes.size());

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

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

    // 0 entry in stpinterface
    assertEquals(0, m_stpInterfaceDao.findAll().size());
  }
Exemple #10
0
  @Test
  @JUnitSnmpAgents(
      value = {
        @JUnitSnmpAgent(
            host = NETGEAR_SW_108_IP,
            port = 161,
            resource = "classpath:linkd/nms7467/" + NETGEAR_SW_108_IP + "-walk.txt")
      })
  public void testNetGearSw108Collection() throws Exception {
    m_nodeDao.save(builder.getNetGearSw108());
    m_nodeDao.flush();

    final OnmsNode ngsw108 = m_nodeDao.findByForeignId("linkd", NETGEAR_SW_108_NAME);

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

    assertTrue(m_linkd.runSingleSnmpCollection(ngsw108.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!) no ip route table
    assertEquals(0, linkNode.getRouteInterfaces().size());
    // has 0 vlan
    assertEquals(0, m_vlanDao.countAll());

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

    assertEquals("example1", packageName);

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

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

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

    // no cdp inteface also if the walk return several interfaces
    assertEquals("cdp not supported", 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
     *
     * NETGEAR_SW_108:172.20.1.8:00223ff00b7b::
     * Run the spanning tree protocol
     * with bridge identifier: 00223ff00b7b
     * Transparent Bridge
     */

    final Set<String> macAddresses = m_linkd.getMacAddressesOnPackage(packageName);
    assertNotNull(macAddresses);
    assertEquals(1, macAddresses.size());
    List<AtInterface> ats = m_linkd.getAtInterfaces(packageName, "00223ff00b7b");

    for (AtInterface at : ats) {
      if (at.getIpAddress().getHostAddress().equals("172.20.1.8"))
        assertTrue(at.getIfIndex().intValue() == -1);
      else
        fail("ip: " + at.getIpAddress().getHostAddress() + "does not match any known ip address");
    }

    // Now Let's test the database
    // 1 atinterface in database: has itself in ipadress to media
    assertEquals(1, m_atInterfaceDao.findAll().size());

    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", ngsw108.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(0, 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(ngsw108.getId(), 1);
    assertTrue(NETGEAR_SW_108_BRIDGEID.equals(stpnode.getBaseBridgeAddress()));
    assertEquals(8, stpnode.getBaseNumPorts().intValue());

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

    // 50 entry in stpinterface
    assertEquals(8, m_stpInterfaceDao.findAll().size());
  }
Exemple #11
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());
  }
Exemple #12
0
  @Test
  @JUnitSnmpAgents(
      value = {
        @JUnitSnmpAgent(
            host = CISCO_WS_C2948_IP,
            port = 161,
            resource = "classpath:linkd/nms7467/" + CISCO_WS_C2948_IP + "-walk.txt")
      })
  public void testCiscoWsC2948Collection() throws Exception {

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

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

    final OnmsNode ciscosw = m_nodeDao.findByForeignId("linkd", CISCO_WS_C2948_NAME);

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

    assertTrue(m_linkd.runSingleSnmpCollection(ciscosw.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 only one route with valid next hop must be valid but type is ethernet so skipped
    // but it is itself so 0
    assertEquals(0, linkNode.getRouteInterfaces().size());
    // has 5
    assertEquals(2, m_ipRouteInterfaceDao.countAll());

    assertEquals(5, m_vlanDao.countAll());

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

    assertEquals("example1", packageName);

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

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

    // has 50 stp entry che ifIndex must be different then -1
    //
    assertEquals(50, 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_WS_C2948_IP:172.20.1.7:0002baaacffe:3:me1
     */

    final List<AtInterface> atInterfaces = m_linkd.getAtInterfaces(packageName, "0002baaacffe");
    assertNotNull(atInterfaces);
    assertEquals(1, atInterfaces.size());
    AtInterface at = atInterfaces.get(0);
    assertEquals(CISCO_WS_C2948_IP, at.getIpAddress().getHostAddress());
    assertEquals(3, at.getIfIndex().intValue());
    // Now Let's test the database
    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", ciscosw.getId()));

    // 2 route entry in database
    assertEquals(2, m_ipRouteInterfaceDao.findMatching(criteria).size());
    // 0 atinterface in database
    assertEquals(0, m_atInterfaceDao.findAll().size());

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

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

    OnmsStpNode stpnode = m_stpNodeDao.findByNodeAndVlan(ciscosw.getId(), 1);
    assertTrue(CISCO_WS_C2948_BRIDGEID.equals(stpnode.getBaseBridgeAddress()));
    assertEquals(50, stpnode.getBaseNumPorts().intValue());

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

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