Search in sources :

Example 16 with DefaultUdpTransportMapping

use of org.snmp4j.transport.DefaultUdpTransportMapping in project opennms by OpenNMS.

the class LLDPMibIT method sendRequestV3.

private PDU sendRequestV3(PDU pdu) throws IOException {
    PDU response;
    OctetString userId = new OctetString("opennmsUser");
    OctetString pw = new OctetString("0p3nNMSv3");
    UserTarget target = new UserTarget();
    target.setSecurityLevel(SecurityLevel.AUTH_PRIV);
    target.setSecurityName(userId);
    target.setAddress(new UdpAddress(m_agent.getInetAddress(), m_agent.getPort()));
    target.setVersion(SnmpConstants.version3);
    if (m_timeout > 0) {
        target.setTimeout(m_timeout);
    } else {
        target.setTimeout(5000);
    }
    TransportMapping<UdpAddress> transport = null;
    try {
        USM usm = new USM(SecurityProtocols.getInstance(), new OctetString(MPv3.createLocalEngineID()), 0);
        SecurityModels.getInstance().addSecurityModel(usm);
        transport = new DefaultUdpTransportMapping();
        Snmp snmp = new Snmp(transport);
        UsmUser user = new UsmUser(userId, AuthMD5.ID, pw, PrivDES.ID, pw);
        snmp.getUSM().addUser(userId, user);
        transport.listen();
        ResponseEvent e = snmp.send(pdu, target);
        response = e.getResponse();
    } finally {
        if (transport != null) {
            transport.close();
        }
    }
    return response;
}
Also used : ScopedPDU(org.snmp4j.ScopedPDU) PDU(org.snmp4j.PDU) OctetString(org.snmp4j.smi.OctetString) UdpAddress(org.snmp4j.smi.UdpAddress) Snmp(org.snmp4j.Snmp) DefaultUdpTransportMapping(org.snmp4j.transport.DefaultUdpTransportMapping) ResponseEvent(org.snmp4j.event.ResponseEvent) UserTarget(org.snmp4j.UserTarget) UsmUser(org.snmp4j.security.UsmUser) USM(org.snmp4j.security.USM)

Example 17 with DefaultUdpTransportMapping

use of org.snmp4j.transport.DefaultUdpTransportMapping in project opennms by OpenNMS.

the class LLDPMibIT method sendRequestV1V2.

private PDU sendRequestV1V2(PDU pdu, int version) throws Exception {
    PDU response;
    CommunityTarget target = new CommunityTarget();
    target.setCommunity(new OctetString("public"));
    target.setAddress(new UdpAddress(m_agent.getInetAddress(), m_agent.getPort()));
    target.setVersion(version);
    if (m_timeout > 0) {
        target.setTimeout(m_timeout);
    }
    TransportMapping<UdpAddress> transport = null;
    try {
        transport = new DefaultUdpTransportMapping();
        Snmp snmp = new Snmp(transport);
        transport.listen();
        ResponseEvent e = snmp.send(pdu, target);
        response = e.getResponse();
    } finally {
        if (transport != null) {
            transport.close();
        }
    }
    return response;
}
Also used : ScopedPDU(org.snmp4j.ScopedPDU) PDU(org.snmp4j.PDU) OctetString(org.snmp4j.smi.OctetString) UdpAddress(org.snmp4j.smi.UdpAddress) Snmp(org.snmp4j.Snmp) DefaultUdpTransportMapping(org.snmp4j.transport.DefaultUdpTransportMapping) ResponseEvent(org.snmp4j.event.ResponseEvent) CommunityTarget(org.snmp4j.CommunityTarget)

Aggregations

Snmp (org.snmp4j.Snmp)17 DefaultUdpTransportMapping (org.snmp4j.transport.DefaultUdpTransportMapping)17 OctetString (org.snmp4j.smi.OctetString)13 UdpAddress (org.snmp4j.smi.UdpAddress)11 PDU (org.snmp4j.PDU)9 ResponseEvent (org.snmp4j.event.ResponseEvent)8 CommunityTarget (org.snmp4j.CommunityTarget)7 ScopedPDU (org.snmp4j.ScopedPDU)7 UsmUser (org.snmp4j.security.UsmUser)7 USM (org.snmp4j.security.USM)6 IOException (java.io.IOException)4 UserTarget (org.snmp4j.UserTarget)4 DefaultTcpTransportMapping (org.snmp4j.transport.DefaultTcpTransportMapping)4 OID (org.snmp4j.smi.OID)3 InetAddress (java.net.InetAddress)2 Target (org.snmp4j.Target)2 Address (org.snmp4j.smi.Address)2 List (java.util.List)1 TimeoutException (java.util.concurrent.TimeoutException)1 Test (org.junit.Test)1