Search in sources :

Example 6 with UserTarget

use of org.snmp4j.UserTarget 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)

Aggregations

UserTarget (org.snmp4j.UserTarget)6 UsmUser (org.snmp4j.security.UsmUser)5 OctetString (org.snmp4j.smi.OctetString)5 PDU (org.snmp4j.PDU)4 ScopedPDU (org.snmp4j.ScopedPDU)4 Snmp (org.snmp4j.Snmp)4 USM (org.snmp4j.security.USM)4 DefaultUdpTransportMapping (org.snmp4j.transport.DefaultUdpTransportMapping)4 ResponseEvent (org.snmp4j.event.ResponseEvent)3 UdpAddress (org.snmp4j.smi.UdpAddress)3 OID (org.snmp4j.smi.OID)2 IOException (java.io.IOException)1 CommunityTarget (org.snmp4j.CommunityTarget)1 Address (org.snmp4j.smi.Address)1 GenericAddress (org.snmp4j.smi.GenericAddress)1 DefaultTcpTransportMapping (org.snmp4j.transport.DefaultTcpTransportMapping)1