当前位置: 首页>>代码示例>>Java>>正文


Java TransportMapping类代码示例

本文整理汇总了Java中org.snmp4j.TransportMapping的典型用法代码示例。如果您正苦于以下问题:Java TransportMapping类的具体用法?Java TransportMapping怎么用?Java TransportMapping使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


TransportMapping类属于org.snmp4j包,在下文中一共展示了TransportMapping类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: setUpTarget

import org.snmp4j.TransportMapping; //导入依赖的package包/类
/**
 * Helper method that initializes the snmp target to listening mode. This
 * method is explicitly for V1 and V2 messages. This method will create and
 * set up the TransportMapping and target for SNMP V1 and V2. It creates a
 * TransportMapping and puts it in the listening mode. Also Creates
 * CommunityTarget object and sets SNMP target properties.
 *
 * @param communityName
 *            Community name of the target
 * @param targetIP
 *            IP address of Target machine
 * @param portNumber
 *            Port number
 * @return The Target created
 * @throws IOException
 *             IOException
 */
private Target setUpTarget( final String communityName, final String targetIP, final int portNumber )
        throws IOException
{
    final InetAddress inetAddress = InetAddress.getByName( targetIP );
    final Address address = new UdpAddress( inetAddress, portNumber );
    final OctetString community = new OctetString( communityName );
    final TransportMapping transport = new DefaultUdpTransportMapping();
    snmp = new Snmp( transport );
    snmp.listen();

    // Creating the communityTarget object and setting its properties
    final CommunityTarget communityTarget = new CommunityTarget();
    communityTarget.setCommunity( community );
    // TODO Needs to check also for v2 messages
    communityTarget.setVersion( SnmpConstants.version1 );
    communityTarget.setAddress( address );
    // TODO Need to confirm, whether this value needs to be configures
    communityTarget.setRetries( SnmpManager.DEFAULT_RETRIES );
    // TODO Need to confirm, whether this value needs to be configures
    communityTarget.setTimeout( SnmpManager.DEFAULT_TIMEOUT );
    return communityTarget;
}
 
开发者ID:Comcast,项目名称:cats,代码行数:40,代码来源:SnmpManagerImpl.java

示例2: sendTest

import org.snmp4j.TransportMapping; //导入依赖的package包/类
public void sendTest(String agentAddress, int port, String community, PDU pdu) {
    for (RegistrationInfo info : s_registrations.values()) {
        if (port == info.getPort()) {
            Snmp snmp = info.getSession();
            MessageDispatcher dispatcher = snmp.getMessageDispatcher();
            TransportMapping transport = info.getTransportMapping();
            
            int securityModel = (pdu instanceof PDUv1 ? SecurityModel.SECURITY_MODEL_SNMPv1 :SecurityModel.SECURITY_MODEL_SNMPv2c);
            int messageModel = (pdu instanceof PDUv1 ? MessageProcessingModel.MPv1 : MessageProcessingModel.MPv2c);
            CommandResponderEvent e = new CommandResponderEvent(dispatcher, transport, new IpAddress(agentAddress), messageModel, 
                                                                securityModel, community.getBytes(), 
                                                                SecurityLevel.NOAUTH_NOPRIV, new PduHandle(), pdu, 1000, null);

            info.getHandler().processPdu(e);
        }
    }

}
 
开发者ID:qoswork,项目名称:opennmszh,代码行数:19,代码来源:Snmp4JStrategy.java

示例3: startUp

import org.snmp4j.TransportMapping; //导入依赖的package包/类
@Override
public void startUp() throws IOException {
	log.info("Snmp Trap Receiver Start");
	log.info("listened on " + Configure.getInstance().getUdpTrapIpPort());
	ThreadPool pool = ThreadPool.create(Const.THREAD_POOL_NAME, Const.AGENT_THREAD_NUM);
	MultiThreadedMessageDispatcher dispatcher = new MultiThreadedMessageDispatcher(pool, new MessageDispatcherImpl());
	Address listenAddress = GenericAddress.parse(Configure.getInstance().getUdpTrapIpPort());
	TransportMapping transport = new DefaultUdpTransportMapping((UdpAddress) listenAddress);
	// ����SNMP������ʹ�俪ʼ����
	Snmp snmp = new Snmp(dispatcher, transport);
       snmp.getMessageDispatcher().addMessageProcessingModel(new MPv2c());
       snmp.listen();
       snmp.addCommandResponder(new CommandResponderImpl());
}
 
开发者ID:wangzijian777,项目名称:snmpTool,代码行数:15,代码来源:SnmpReceiver.java

示例4: start

import org.snmp4j.TransportMapping; //导入依赖的package包/类
/**
 * Start the Snmp session. If you forget the listen() method you will not get any answers because the communication is asynchronous and the
 * listen() method listens for answers.
 * 
 * @throws IOException
 */

public void start() throws IOException {
	TransportMapping transport = new DefaultUdpTransportMapping();

	if (SNMPversion == 3) {
		USM usm = new USM(SecurityProtocols.getInstance(), new OctetString(MPv3.createLocalEngineID()), 0);
		SecurityModels.getInstance().addSecurityModel(usm);
	}
	snmp = new Snmp(transport);

	if (SNMPversion == 3)
		snmp.getUSM().addUser(new OctetString(ver3Username),
				new UsmUser(new OctetString(ver3Username), AuthMD5.ID, new OctetString(ver3AuthPasscode), null, null));

	// Do not forget this line!
	transport.listen();
}
 
开发者ID:dana-i2cat,项目名称:opennaas-routing-nfv,代码行数:24,代码来源:SNMPManager.java

示例5: createSnmpSession

import org.snmp4j.TransportMapping; //导入依赖的package包/类
public Snmp createSnmpSession() throws IOException {
    TransportMapping transport = new DefaultUdpTransportMapping();
    Snmp session = new Snmp(transport);
    
    if (isSnmpV3()) {
        // Make a new USM
        USM usm = new USM(SecurityProtocols.getInstance(), new OctetString(MPv3.createLocalEngineID()), 0);
        // Add the specified user to the USM
        usm.addUser(
            getSecurityName(),
            new UsmUser(
                getSecurityName(),
                getAuthProtocol(),
                getAuthPassPhrase(),
                getPrivProtocol(),
                getPrivPassPhrase()
            )
        );
        // Remove the old SNMPv3 MessageProcessingModel. If you don't do this, you'll end up with
        // two SNMPv3 MessageProcessingModel instances in the dispatcher and connections will fail.
        MessageProcessingModel oldModel = session.getMessageDispatcher().getMessageProcessingModel(MessageProcessingModel.MPv3);
        if (oldModel != null) {
            session.getMessageDispatcher().removeMessageProcessingModel(oldModel);
        }
        // Add a new SNMPv3 MessageProcessingModel with the newly-created USM
        session.getMessageDispatcher().addMessageProcessingModel(new MPv3(usm));
    }
    
    return session;
}
 
开发者ID:vishwaabhinav,项目名称:OpenNMS,代码行数:31,代码来源:Snmp4JAgentConfig.java

示例6: createDevice

import org.snmp4j.TransportMapping; //导入依赖的package包/类
private void createDevice(String ipAddress, int port) throws IOException {
    Address targetAddress = GenericAddress.parse("udp:" + ipAddress + "/" + port);
    TransportMapping transport = new DefaultUdpTransportMapping();
    transport.listen();
    snmp = new Snmp(transport);

    // setting up target
    target = new CommunityTarget();
    target.setCommunity(new OctetString("public"));
    target.setAddress(targetAddress);
    target.setRetries(3);
    target.setTimeout(1000 * 3);
    target.setVersion(SnmpConstants.version2c);
    target.setMaxSizeRequestPDU(MAX_SIZE_RESPONSE_PDU);
}
 
开发者ID:shlee89,项目名称:athena,代码行数:16,代码来源:LumentumSnmpDevice.java

示例7: AbstractRequest

import org.snmp4j.TransportMapping; //导入依赖的package包/类
AbstractRequest(PDU request, Target target,
    TransportMapping<?> transportMapping, Object userHandle,
    int retries, long timeout) {
  this.request = request;
  this.target = target;
  this.transportMapping = transportMapping;
  this.userHandle = userHandle;
  this.retries = retries;
  this.timeout = timeout;
}
 
开发者ID:soulwing,项目名称:tnm4j,代码行数:11,代码来源:SessionWrapper.java

示例8: start

import org.snmp4j.TransportMapping; //导入依赖的package包/类
/**
 * Start the Snmp session. If you forget the listen() method you will not
 * get any answers because the communication is asynchronous
 * and the listen() method listens for answers.
 * @throws IOException
 */
public void start() throws IOException 
{
	TransportMapping transport = new DefaultUdpTransportMapping();
	snmp = new Snmp(transport);
	if("3".equals(this.version))//add v3 support
	{
		USM usm = new USM(SecurityProtocols.getInstance(), new OctetString(MPv3.createLocalEngineID()), 0);  
		SecurityModels.getInstance().addSecurityModel(usm);  
	}
	// Do not forget this line!
	transport.listen();
}
 
开发者ID:yahoo,项目名称:mysql_perf_analyzer,代码行数:19,代码来源:SNMPClient.java

示例9: start

import org.snmp4j.TransportMapping; //导入依赖的package包/类
/**
* Start the Snmp session. If you forget the listen() method you will not
* get any answers because the communication is asynchronous
* and the listen() method listens for answers.
* @throws IOException
*/
private void start() throws IOException {
TransportMapping transport = new DefaultUdpTransportMapping();
snmp = new Snmp(transport);
// Do not forget this line!
transport.listen();
}
 
开发者ID:rhamnett,项目名称:dazzl,代码行数:13,代码来源:SnmpTest.java

示例10: init

import org.snmp4j.TransportMapping; //导入依赖的package包/类
public void init() throws IOException {
	System.out.println("----> 初始 Trap 的IP和端口 <----");
	target = createTarget4Trap("udp:127.0.0.1/162");
	TransportMapping transport = new DefaultUdpTransportMapping();
	snmp = new Snmp(transport);
	transport.listen();
}
 
开发者ID:micmiu,项目名称:snmp-tutorial,代码行数:8,代码来源:SnmpTrapSendDemo.java

示例11: start

import org.snmp4j.TransportMapping; //导入依赖的package包/类
/**
 * Start the Snmp session. If you forget the listen() method you will not
 * get any answers because the communication is asynchronous
 * and the listen() method listens for answers.
 * @throws IOException
 */
private void start() throws IOException {
	TransportMapping transport = new DefaultUdpTransportMapping();
	snmp = new Snmp(transport);
	// Do not forget this line!
	transport.listen();
}
 
开发者ID:javiroman,项目名称:flume-snmp-source,代码行数:13,代码来源:testSNMPQuery2.java

示例12: sendSnmpV1Trap

import org.snmp4j.TransportMapping; //导入依赖的package包/类
/**
 * This methods sends the V1 trap to the Localhost in port 163
 */
public void sendSnmpV1Trap()
{
  try
  {
    //Create Transport Mapping
    TransportMapping transport = new DefaultUdpTransportMapping();
    transport.listen();

    //Create Target 
    CommunityTarget comtarget = new CommunityTarget();
    comtarget.setCommunity(new OctetString(community));
    comtarget.setVersion(SnmpConstants.version1);
    comtarget.setAddress(new UdpAddress(ipAddress + "/" + port));
    comtarget.setRetries(2);
    comtarget.setTimeout(5000);

    //Create PDU for V1
    PDUv1 pdu = new PDUv1();
    pdu.setType(PDU.V1TRAP);
    pdu.setEnterprise(new OID(trapOid));
    pdu.setGenericTrap(PDUv1.ENTERPRISE_SPECIFIC);
    pdu.setSpecificTrap(1);
    pdu.setAgentAddress(new IpAddress(ipAddress));

    //Send the PDU
    Snmp snmp = new Snmp(transport);
    System.out.println("Sending V1 Trap to " + ipAddress + " on Port " + port);
    snmp.send(pdu, comtarget);
    snmp.close();
  }
  catch (Exception e)
  {
    System.err.println("Error in Sending V1 Trap to " + ipAddress + " on Port " + port);
    System.err.println("Exception Message = " + e.getMessage());
  }
}
 
开发者ID:javiroman,项目名称:flume-snmp-source,代码行数:40,代码来源:sendSNMPTrap.java

示例13: initTransportMappings

import org.snmp4j.TransportMapping; //导入依赖的package包/类
/** {@inheritDoc} */
@Override
protected void initTransportMappings() throws IOException {
    try {
        final MockUdpTransportMapping mapping = new MockUdpTransportMapping(new UdpAddress(m_address.get()), true);
        mapping.setThreadName("MockSnmpAgent-UDP-Transport");
        transportMappings = new TransportMapping[] { mapping };
    } catch (final IOException e) {
        m_failure.set(e);
        throw e;
    }
}
 
开发者ID:qoswork,项目名称:opennmszh,代码行数:13,代码来源:MockSnmpAgent.java

示例14: sendTrapV1

import org.snmp4j.TransportMapping; //导入依赖的package包/类
public static void sendTrapV1(String port) throws IOException {

        TransportMapping<?> transport = new DefaultUdpTransportMapping();
        transport.listen();

        CommunityTarget comtarget = new CommunityTarget();
        comtarget.setCommunity(new OctetString(new OctetString("public")));
        comtarget.setVersion(SnmpConstants.version1);
        comtarget.setAddress(new UdpAddress("127.0.0.1/" + port));
        comtarget.setRetries(2);
        comtarget.setTimeout(5000);

        PDU trap = new PDUv1();
        trap.setType(PDU.V1TRAP);

        OID oid = new OID("1.2.3.4.5");
        trap.add(new VariableBinding(SnmpConstants.snmpTrapOID, oid));
        trap.add(new VariableBinding(SnmpConstants.sysUpTime, new TimeTicks(5000)));
        trap.add(new VariableBinding(SnmpConstants.sysDescr, new OctetString("System Description")));

        // Add Payload
        Variable var = new OctetString("some string");
        trap.add(new VariableBinding(oid, var));

        // Send
        Snmp snmp = new Snmp(transport);
        snmp.send(trap, comtarget);
        transport.close();
        snmp.close();

    }
 
开发者ID:Stratio,项目名称:ingestion,代码行数:32,代码来源:SNMPUtils.java

示例15: sendTrapV3

import org.snmp4j.TransportMapping; //导入依赖的package包/类
public static void sendTrapV3(String port) {
    try {
        Address targetAddress = GenericAddress.parse("udp:127.0.0.1/" + port);
        TransportMapping<?> transport = new DefaultUdpTransportMapping();
        Snmp snmp = new Snmp(transport);
        USM usm = new USM(SecurityProtocols.getInstance(), new OctetString(
                MPv3.createLocalEngineID()), 0);
        SecurityModels.getInstance().addSecurityModel(usm);
        transport.listen();

        snmp.getUSM().addUser(new OctetString("MD5DES"),
                new UsmUser(new OctetString("MD5DES"), null, null, null, null));

        // Create Target
        UserTarget target = new UserTarget();
        target.setAddress(targetAddress);
        target.setRetries(1);
        target.setTimeout(11500);
        target.setVersion(SnmpConstants.version3);
        target.setSecurityLevel(SecurityLevel.NOAUTH_NOPRIV);
        target.setSecurityName(new OctetString("MD5DES"));

        // Create PDU for V3
        ScopedPDU pdu = new ScopedPDU();
        pdu.setType(ScopedPDU.NOTIFICATION);
        pdu.add(new VariableBinding(SnmpConstants.sysUpTime));
        pdu.add(new VariableBinding(SnmpConstants.snmpTrapOID, SnmpConstants.linkDown));
        pdu.add(new VariableBinding(new OID("1.2.3.4.5"), new OctetString("Major")));

        // Send the PDU
        snmp.send(pdu, target);

        transport.close();
        snmp.close();
    } catch (Exception e) {
        System.err.println("Error in Sending Trap to (IP:Port)=> " + "127.0.0.1" + ":" + port);
        System.err.println("Exception Message = " + e.getMessage());
    }
}
 
开发者ID:Stratio,项目名称:ingestion,代码行数:40,代码来源:SNMPUtils.java


注:本文中的org.snmp4j.TransportMapping类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。