/** * <p>createInterfaceEventBuilder</p> * * @param source a {@link java.lang.String} object. * @param uei a {@link java.lang.String} object. * @param iface a {@link org.opennms.netmgt.mock.MockInterface} object. * @return a {@link org.opennms.netmgt.model.events.EventBuilder} object. */ public static EventBuilder createInterfaceEventBuilder(String source, String uei, MockInterface iface) { return createEventBuilder(source, uei, iface.getNodeId(), iface.getIpAddr(), null, null); }
/** * <p>addService</p> * * @param svcName a {@link java.lang.String} object. * @return a {@link org.opennms.netmgt.mock.MockService} object. */ public MockService addService(String svcName) { int serviceId = getServiceId(svcName); m_currentService = m_currentInterface.addService(svcName, serviceId); return m_currentService; }
public void writeInterface(MockInterface iface) { LOG.info("Inserting interface into database with IP address {}", iface.getAddress()); Integer snmpInterfaceId = writeSnmpInterface(iface); Object[] values = { iface.getId(), iface.getNodeId(), str(iface.getAddress()), snmpInterfaceId, (iface.getIfIndex() == 1 ? "P" : "N"), "M" }; update("insert into ipInterface (id, nodeID, ipAddr, snmpInterfaceId, isSnmpPrimary, isManaged) values (?, ?, ?, ?, ?, ?);", values); }
/** * @return The ID of the inserted snmpinterface record */ public Integer writeSnmpInterface(MockInterface iface) { Integer nextId = getNextSnmpInterfaceId(); LOG.info("Inserting into snmpInterface {} {} {} {}", nextId, Integer.valueOf(iface.getNodeId()), iface.getIfAlias(), iface.getIfIndex() ); Object[] values = { nextId, Integer.valueOf(iface.getNodeId()), iface.getIfAlias(), iface.getIfAlias(), iface.getIfIndex() }; update("insert into snmpInterface (id, nodeID, snmpifAlias, snmpifDescr, snmpIfIndex) values (?, ?, ?, ?, ?);", values); return nextId; }
@Test(timeout=30000) public void testReparentStatusChanges() { // // Plan to bring down both nodes except the reparented interface // the node owning the interface should be up while the other is down // after reparenting we should got the old owner go down while the other // comes up. // anticipateDown(mNode2); anticipateDown(mDot1); // bring down both nodes but bring iface back up mNode1.bringDown(); mNode2.bringDown(); mDot2.bringUp(); pDot1Icmp.doPoll(); m_network.processStatusChange(new Date()); pDot2Icmp.doPoll(); m_network.processStatusChange(new Date()); pDot3Icmp.doPoll(); m_network.processStatusChange(new Date()); verifyAnticipated(); m_db.reparentInterface(mDot2.getIpAddr(), mDot2.getNodeId(), mNode2.getNodeId()); mDot2.moveTo(mNode2); resetAnticipated(); anticipateDown(mNode1); anticipateUp(mNode2); anticipateDown(mDot3); pDot2.reparentTo(pNode2); verifyAnticipated(); }
/** * <p>getPollStatus</p> * * @return a {@link org.opennms.netmgt.poller.PollStatus} object. */ @Override public PollStatus getPollStatus() { final String critSvcName = getNetwork().getCriticalService(); final MockService critSvc = getService(critSvcName); class IFStatusCalculator extends MockVisitorAdapter { PollStatus status = PollStatus.down(); public PollStatus getStatus() { return status; } @Override public void visitService(MockService svc) { if (critSvc == null || critSvc.equals(svc)) { if (svc.getPollStatus().isUp()) status = PollStatus.up(); } } } IFStatusCalculator calc = new IFStatusCalculator(); visit(calc); return calc.getStatus(); }
@Test public void testDontPollDuringScheduledOutages() { long start = System.currentTimeMillis(); MockInterface iface = m_network.getInterface(1, "192.168.1.2"); m_pollerConfig.addScheduledOutage(m_pollerConfig.getPackage("TestPackage"), "TestOutage", start, start + 5000, iface.getIpAddr()); MockUtil.println("Begin Outage"); startDaemons(); long now = System.currentTimeMillis(); sleep(3000 - (now - start)); MockUtil.println("End Outage"); assertEquals(0, iface.getPollCount()); sleep(5000); assertTrue(0 < iface.getPollCount()); }
@Override Object getKey() { return getIpAddr(); }
iface.resetPollCount(); iface.addAnticipator(anticipator); smtpService.visit(m_upChecker); icmpService.visit(m_upChecker); iface.visit(m_upChecker); iface.bringDown();
/** * <p>getNetwork</p> * * @return a {@link org.opennms.netmgt.mock.MockNetwork} object. */ @Override public MockNetwork getNetwork() { return getNode().getNetwork(); }
@Test public void testInterfaceWithNoCriticalService() { m_pollerConfig.setNodeOutageProcessingEnabled(true); MockInterface iface = m_network.getInterface(3, "192.168.1.4"); MockService svc = iface.getService("SMTP"); MockService otherService = iface.getService("HTTP"); startDaemons(); anticipateDown(iface); iface.bringDown(); verifyAnticipated(8000); anticipateUp(iface); anticipateDown(otherService, true); svc.bringUp(); verifyAnticipated(8000); }
/** * <p>getService</p> * * @param nodeid a int. * @param ipAddr a {@link java.lang.String} object. * @param svcName a {@link java.lang.String} object. * @return a {@link org.opennms.netmgt.mock.MockService} object. */ public MockService getService(int nodeid, String ipAddr, String svcName) { final MockInterface iface = getInterface(nodeid, ipAddr); LOG.debug("getService({}, {}, {}) = {}", nodeid, ipAddr, svcName, iface); return (iface == null ? null : iface.getService(svcName)); }
/** * <p>getAddress</p> * * @return a {@link java.net.InetAddress} object. */ @Override public InetAddress getAddress() { return getInterface().getAddress(); }
@Test public void testPolling() throws Exception { m_pollerConfig.setNodeOutageProcessingEnabled(false); // create a poll anticipator PollAnticipator anticipator = new PollAnticipator(); // register it with the interfaces services MockInterface iface = m_network.getInterface(1, "192.168.1.2"); iface.addAnticipator(anticipator); // // first ensure that polls are working while it is up // // anticipate three polls on all the interfaces services anticipator.anticipateAllServices(iface); anticipator.anticipateAllServices(iface); anticipator.anticipateAllServices(iface); // start the poller startDaemons(); // wait for the polls to occur while its up... 1 poll per second plus overhead assertEquals(0, anticipator.waitForAnticipated(4500L).size()); }
/** * <p>addInterface</p> * * @param ipAddr a {@link java.lang.String} object. * @return a {@link org.opennms.netmgt.mock.MockInterface} object. */ public MockInterface addInterface(String ipAddr) { return (MockInterface) addMember(new MockInterface(this, ipAddr)); }
public void testCreateInterfaces() { MockNode router = m_network.getNode(1); MockInterface iface = m_network.getInterface(1, "192.168.1.1"); assertEquals("192.168.1.1", iface.getIpAddr()); assertEquals(router, iface.getNode()); MockInterface iface2 = m_network.getInterface(1, "192.168.1.2"); assertEquals("192.168.1.2", iface2.getIpAddr()); assertEquals(router, iface2.getNode()); MockNode server = m_network.getNode(2); MockInterface iface3 = m_network.getInterface(2, "192.168.1.3"); assertEquals(server.getNodeId(), iface3.getNode().getNodeId()); assertEquals(server, iface3.getNode()); MockNode ipv6 = m_network.getNode(3); MockInterface iface4 = m_network.getInterface(3, "fe80:0000:0000:0000:0000:0000:0000:00ff"); assertEquals(ipv6.getNodeId(), iface4.getNode().getNodeId()); assertEquals(ipv6, iface4.getNode()); }
/** * @return The ID of the inserted snmpinterface record */ public Integer writeSnmpInterface(MockInterface iface) { Integer nextId = getNextSnmpInterfaceId(); LOG.info("Inserting into snmpInterface {} {} {} {}", nextId, Integer.valueOf(iface.getNodeId()), iface.getIfAlias(), iface.getIfIndex() ); Object[] values = { nextId, Integer.valueOf(iface.getNodeId()), iface.getIfAlias(), iface.getIfAlias(), iface.getIfIndex() }; update("insert into snmpInterface (id, nodeID, snmpifAlias, snmpifDescr, snmpIfIndex) values (?, ?, ?, ?, ?);", values); return nextId; }