SNMP v1,v2c and v3 trap difference

This requires you to go through the RFC documents, which means this is not programming related, and probably belongs to ServerFault.

Give you some hints:

  1. SNMP v1 defines a special TRAP message format, different from other messages (such as GET). https://www.rfc-editor.org/rfc/rfc1157#page-27 This message format is not used any more in SNMP v2 and v3. If an SNMP agent sends out such TRAP messages for v2 or v3, that can be a bug.
  2. Since v2, TRAP starts to use the common message format (the same as GET and so on). So it is called SNMPv2-Trap-PDU. http://tools.ietf.org/search/rfc3416#page-22
  3. SNMP v3 introduces the security model to all messages, so TRAP receives such update too. It is still based on SNMPv2-Trap-PDU.

SNMPv2 defines traps in a slightly different way.

In a MIB, SNMPv1 traps are defined as Trap-PDU, SNMPv2 traps are defined as NOTIFICATION-TYPE. SNMPv2 also does away with the notion of generic traps instead, it defines many specific traps (properly speaking, notification) in public MIBs.

SNMPv3 traps, which are simply SNMPv2 traps with added authentication (credentials based) (Common authentication Techniques MD5 or SHA) and privacy capabilities(Encryption Techniques - DES,3DES,AES128/192/256).

Most SNMP implementation support only v1.

Reference_1 Reference_2

Below is the SNMP4j code to send snmpv3 trap.

  public void sendTrap_Version3() {
    //TrasportMapping
    TransportMapping transport;
    try {
        transport = new DefaultUdpTransportMapping();
        transport.listen();
        //Creating SNMP object
        snmp = new Snmp(transport);

         //Creating USM
        USM usm = new USM(SecurityProtocols.getInstance(), new OctetString(MPv3.createLocalEngineID()), 0);
        SecurityModels.getInstance().addSecurityModel(usm);

        // Add user to the USM
        snmp.getUSM().addUser(
                new OctetString("MD5DES"),
                new UsmUser(new OctetString("MD5DES"), AuthMD5.ID, new OctetString("MD5DESUsrAuthPwd"), PrivDES.ID,
                        new OctetString("MD5DESUsrPrivPwd")));

        // Create the target
        Address targetAddress = GenericAddress.parse("udp:10.120.7.107/162");
        UserTarget target = new UserTarget();
        target.setAddress(targetAddress);
        target.setRetries(3);
        target.setTimeout(5000);
        target.setVersion(SnmpConstants.version3);
        target.setSecurityLevel(SecurityLevel.AUTH_PRIV);
        target.setSecurityName(new OctetString("MD5DES"));
        // Create PDU
        ScopedPDU pdu = new ScopedPDU();

       pdu.add(new VariableBinding(SnmpConstants.sysUpTime, new TimeTic(new Date().toString())));
       pdu.add(new VariableBinding(SnmpConstants.snmpTrapOID,SnmpConstants.linkDown));
       pdu.add(new VariableBinding(SnmpConstants.snmpTrapAddress, new IpAddress("127.3.4.1")));
       pdu.add(new VariableBinding(new OID("1.3.6.1.2.1.2.2.1.1.1"), new Integer32(1)));

        pdu.setType(ScopedPDU.TRAP);
        snmp.send(pdu, target);

    } catch (IOException e) {
        e.printStackTrace();
    }
}

Tags:

Snmp