/** * Builds target resource. * @param context Process context */ private void buildTargetResource(ProcessContext context) { if((this.transportMapping == null) || !this.transportMapping.isListening() || (this.snmp == null)) { try { this.transportMapping = new DefaultUdpTransportMapping(); this.snmp = new Snmp(this.transportMapping); if("SNMPv3".equals(context.getProperty(SNMP_VERSION).getValue())) { USM usm = new USM(SecurityProtocols.getInstance(), new OctetString(MPv3.createLocalEngineID()), 0); SecurityModels.getInstance().addSecurityModel(usm); } this.transportMapping.listen(); } catch (Exception e) { throw new IllegalStateException("Failed to initialize UDP transport mapping", e); } } if (this.snmpTarget == null) { this.snmpTarget = this.createSnmpTarget(context); } if (this.targetResource == null) { this.targetResource = this.finishBuildingTargetResource(context); } }
/** * Start listening for responses * * @throws IOException */ public void startListen() throws IOException { transport.listen(); listening = true; }
@Override public synchronized void start() throws Exception { super.start(); // again listen to the transport this.transport.listen(); }
/** * Puts a list of transport mappings into listen mode. * * @param transportMappings * a list of {@link TransportMapping} instances. * * @throws IOException * if a transport cannot listen to incoming messages. */ protected static void launchTransportMappings(Collection<? extends TransportMapping> transportMappings) throws IOException { ArrayList<? extends TransportMapping> l = new ArrayList<TransportMapping>(transportMappings); for (TransportMapping tm : l) { if (!tm.isListening()) { tm.listen(); } } }
/** * Puts a list of transport mappings into listen mode. * @param transportMappings * a list of {@link TransportMapping} instances. * @throws IOException * if a transport cannot listen to incoming messages. */ protected static void launchTransportMappings(Collection transportMappings) throws IOException { ArrayList l = new ArrayList(transportMappings); for (Iterator it = l.iterator(); it.hasNext();) { TransportMapping tm = (TransportMapping) it.next(); if (!tm.isListening()) { tm.listen(); } } }
/** * Puts all associated transport mappings into listen mode. * @throws IOException * if a transport mapping throws an <code>IOException</code> when its * {@link TransportMapping#listen()} method has been called. */ public void listen() throws IOException { for (Iterator it = messageDispatcher.getTransportMappings().iterator(); it.hasNext(); ) { TransportMapping tm = (TransportMapping) it.next(); if (!tm.isListening()) { tm.listen(); } } }
public SNMPProvider(String address) { try { this.address = address; TransportMapping transport = new DefaultUdpTransportMapping(); this.snmp = new Snmp(transport); transport.listen(); } catch (IOException e) { throw new RuntimeException(e); } }
@Override public synchronized void start() throws Exception { super.start(); // listening is only allowed if the endpoint was initialized if (isEnabled()) { // listen to the transport this.transport.listen(); } }
private void start() throws IOException { TransportMapping transport = new DefaultUdpTransportMapping(); snmp = new Snmp(transport); // Do not forget this line! transport.listen(); }
/** * Puts all associated transport mappings into listen mode. * @throws IOException * if a transport mapping throws an <code>IOException</code> when its * {@link TransportMapping#listen()} method has been called. */ public void listen() throws IOException { for (TransportMapping tm : messageDispatcher.getTransportMappings()) { if (!tm.isListening()) { tm.listen(); } } }
/** * Puts all associated transport mappings into listen mode. * * @throws IOException * if a transport mapping throws an <code>IOException</code> when its * {@link TransportMapping#listen()} method has been called. */ public void listen() throws IOException { for (TransportMapping<?> tm : messageDispatcher.getTransportMappings()) { if (!tm.isListening()) { tm.listen(); } } }
/** * <p>init.</p> * * @throws java.io.IOException if any. */ public void init() throws IOException { TransportMapping transportMapping = transportMappingAbstractFactory.createTransportMapping(transportLocalIpAddress); MessageDispatcher messageDispatcher = messageDispatcherFactory.createMessageDispatcherMapping(); snmp = new Snmp(messageDispatcher, transportMapping); doInit(); transportMapping.listen(); }
@Override protected void doStart() throws Exception { super.doStart(); // load connection data only if the endpoint is enabled if (LOG.isInfoEnabled()) { LOG.info("Starting trap consumer on {}", this.endpoint.getAddress()); } this.listenGenericAddress = GenericAddress.parse(this.endpoint.getAddress()); // either tcp or udp if ("tcp".equals(endpoint.getProtocol())) { this.transport = new DefaultTcpTransportMapping((TcpAddress)this.listenGenericAddress); } else if ("udp".equals(endpoint.getProtocol())) { this.transport = new DefaultUdpTransportMapping((UdpAddress)this.listenGenericAddress); } else { throw new IllegalArgumentException("Unknown protocol: " + endpoint.getProtocol()); } this.snmp = new Snmp(transport); this.snmp.addCommandResponder(this); // listen to the transport if (LOG.isDebugEnabled()) { LOG.debug("Starting trap consumer on {} using {} protocol", endpoint.getAddress(), endpoint.getProtocol()); } this.transport.listen(); if (LOG.isInfoEnabled()) { LOG.info("Started trap consumer on {} using {} protocol", endpoint.getAddress(), endpoint.getProtocol()); } }
@Override public boolean start() { try { TransportMapping<?> transport = null; if(UDP.equals(proto)) { UdpAddress listenAddress = new UdpAddress(port); transport = new DefaultUdpTransportMapping(listenAddress, true); } if(transport != null) { snmp = new Snmp(transport); snmp.addCommandResponder(trapReceiver); transport.listen(); } else { log(Level.ERROR, "unsupported UDP listener protocol: %s", proto); return false; } return super.start(); } catch (IOException e) { log(Level.ERROR, e, "failed to start the trap listener: %s", e.getMessage()); return false; } }
transport.listen();
public MockProxy(int port) throws IOException { // Set socket option SO_REUSEADDR so that we can bind to the port even if it // has recently been closed by passing 'true' as the second argument here. m_transport = new DefaultUdpTransportMapping(new UdpAddress(InetAddress.getLocalHost(), port), true); m_snmp = new Snmp(m_transport); m_snmp.addCommandResponder(this); m_transport.listen(); }
/** * Builds target resource. * @param context Process context */ private void buildTargetResource(ProcessContext context) { if((this.transportMapping == null) || !this.transportMapping.isListening() || (this.snmp == null)) { try { this.transportMapping = new DefaultUdpTransportMapping(); this.snmp = new Snmp(this.transportMapping); if("SNMPv3".equals(context.getProperty(SNMP_VERSION).getValue())) { USM usm = new USM(SecurityProtocols.getInstance(), new OctetString(MPv3.createLocalEngineID()), 0); SecurityModels.getInstance().addSecurityModel(usm); } this.transportMapping.listen(); } catch (Exception e) { throw new IllegalStateException("Failed to initialize UDP transport mapping", e); } } if (this.snmpTarget == null) { this.snmpTarget = this.createSnmpTarget(context); } if (this.targetResource == null) { this.targetResource = this.finishBuildingTargetResource(context); } }
Address targetAddress = GenericAddress.parse("udp:"+serverIp+"/162"); TransportMapping transport = new DefaultUdpTransportMapping(); transport.listen(); Snmp snmp = new Snmp(transport);
private org.snmp4j.Snmp createSnmp3(Profile profile) { try { TransportMapping<?> transport = new DefaultUdpTransportMapping(); org.snmp4j.Snmp snmp = new org.snmp4j.Snmp(transport); SecurityProtocols securityProtocols = SecurityProtocols.getInstance(); securityProtocols.addDefaultProtocols(); securityProtocols.addAuthenticationProtocol(new AuthMD5()); securityProtocols.addAuthenticationProtocol(new AuthSHA()); securityProtocols.addPrivacyProtocol(new PrivAES128()); securityProtocols.addPrivacyProtocol(new PrivAES192()); securityProtocols.addPrivacyProtocol(new PrivAES256()); USM usm = new USM(securityProtocols, profile.engineId, 0); ((org.snmp4j.mp.MPv3) snmp.getMessageProcessingModel(org.snmp4j.mp.MPv3.ID)) .setLocalEngineID(profile.engineId.getValue()); ((org.snmp4j.mp.MPv3) snmp.getMessageProcessingModel(org.snmp4j.mp.MPv3.ID)) .getSecurityModels().addSecurityModel(usm); SecurityModels.getInstance().addSecurityModel( usm); transport.listen(); snmp.getUSM().addUser( profile.username, getUsmUser(profile)); return snmp; } catch (IOException e) { throw new NotificationServiceException("error creating version 3 snmp " + getClass().getName()); } }