Any debug method for SNMP4J-Agent?

I wrote a SNMP agent referring to SNMP4J-Agent SampleAgent code.
Problem is:
After ‘agent.run();’ I see the agent is in running state by printing ‘agent.getState()’, but it always responds to SNMP request with a ‘Timeout: No Response from 127.0.0.1’.

Is there any debug method to figure out the root cause?
I use SNMP4J-Agent 2.7.1.

Very appreciate.

Have you tried to increase the log level to debug?
You can find the how-to for this here:
https://doc.snmp.app/pages/viewpage.action?pageId=27459590

Thanks Frank for your timely response!
But where could I find the logs? In which file are they saved?
Thanks again.

If activated the log output is printed to stdout (console). If you want to have it stored into a file, you need to use the Java log adapter and configure it to store the logs into a file.

Thanks Frank.
I could get logs and find the root cause:

    <INFO> 07-Nov-2019::10:37:21.208 CommandProcessor DefaultUDPTransportMapping_0.0.0.0/161: - Community name 'public' not found in SNMP-COMMUNITY-MIB

It seems I need to load “SampleAgentTableSizeLimits.properties” in my code to configure it.

But after I added this code, I got new issue:
the ‘serverPersistence.loadData(config);’ process could not be finished and thus agent could not move on to ‘STATE_CONFIGURED’ state.

From logs, process stopped at handling of USM ‘SHA256AES128’. There’s no more log printed after ‘07-Nov-2019::16:16:09.728’. I tested 3 times, and each time got the same result.

Could you please help to check what’s the problem? Did I miss anything else to configure?
Very appreciated.

07-Nov-2019::16:16:09.707 PropertyMOInput main: - Read indexed variables IndexVariables[index=13.128.0.19.112.1.127.0.0.1.252.151.81.186.5.117.110.115.101.99,values=[unsec, , 1.3.6.1.6.3.10.1.1.1, , , 1.3.6.1.6.3.10.1.2.1, , , , 3, 1, null, null, null]] for OID 1.3.6.1.6.3.15.1.2.2.1 in context null
07-Nov-2019::16:16:09.707 USM main: - getUser(engineID=80:00:13:70:01:7f:00:00:01:fc:97:51:ba, securityName=unsec)
07-Nov-2019::16:16:09.707 USM main: - USM.getUser - User ‘unsec’ unknown
07-Nov-2019::16:16:09.707 USM main: - getUser(engineID=80:00:13:70:01:7f:00:00:01:fc:97:51:ba, securityName=unsec)
07-Nov-2019::16:16:09.707 USM main: - USM.getUser - User ‘unsec’ unknown
07-Nov-2019::16:16:09.708 USM main: - getUser(engineID=80:00:13:70:01:7f:00:00:01:fc:97:51:ba, securityName=unsec)
07-Nov-2019::16:16:09.708 USM main: - USM.getUser - User ‘unsec’ unknown
07-Nov-2019::16:16:09.708 USM main: - getUser(engineID=80:00:13:70:01:7f:00:00:01:fc:97:51:ba, securityName=unsec)
07-Nov-2019::16:16:09.708 USM main: - USM.getUser - User ‘unsec’ unknown
07-Nov-2019::16:16:09.708 UsmUserTable main: - Adding user unsec = UsmUser[secName=unsec,authProtocol=null,authPassphrase=null,privProtocol=null,privPassphrase=null,localizationEngineID=80:00:13:70:01:7f:00:00:01:fc:97:51:ba]
07-Nov-2019::16:16:09.708 DefaultMOTable main: - Loaded row DefaultMOMutableRow2PC[index=13.128.0.19.112.1.127.0.0.1.252.151.81.186.5.117.110.115.101.99,values=[unsec, , 1.3.6.1.6.3.10.1.1.1, , , 1.3.6.1.6.3.10.1.2.1, , , , 3, 1, null, null, null, null, null] into table 1.3.6.1.6.3.15.1.2.2.1
07-Nov-2019::16:16:09.708 PropertyMOInput main: - Read indexed variables IndexVariables[index=13.128.0.19.112.1.127.0.0.1.252.151.81.186.12.83.72.65.50.53.54.65.69.83.49.50.56,values=[SHA256AES128, , 1.3.6.1.6.3.10.1.1.5, , , 1.3.6.1.6.3.10.1.2.4, , , , 4, 1, SHA256AES128AuthPassword, SHA256AES128PrivPassword, null]] for OID 1.3.6.1.6.3.15.1.2.2.1 in context null
07-Nov-2019::16:16:09.709 USM main: - getUser(engineID=80:00:13:70:01:7f:00:00:01:fc:97:51:ba, securityName=SHA256AES128)
07-Nov-2019::16:16:09.709 USM main: - USM.getUser - User ‘SHA256AES128’ unknown
07-Nov-2019::16:16:09.709 USM main: - getUser(engineID=80:00:13:70:01:7f:00:00:01:fc:97:51:ba, securityName=SHA256AES128)
07-Nov-2019::16:16:09.709 USM main: - USM.getUser - User ‘SHA256AES128’ unknown
07-Nov-2019::16:16:09.709 USM main: - getUser(engineID=80:00:13:70:01:7f:00:00:01:fc:97:51:ba, securityName=SHA256AES128)
07-Nov-2019::16:16:09.709 USM main: - USM.getUser - User ‘SHA256AES128’ unknown
07-Nov-2019::16:16:09.709 USM main: - getUser(engineID=80:00:13:70:01:7f:00:00:01:fc:97:51:ba, securityName=SHA256AES128)
07-Nov-2019::16:16:09.709 USM main: - USM.getUser - User ‘SHA256AES128’ unknown
07-Nov-2019::16:16:09.710 USM main: - getUser(engineID=80:00:13:70:01:7f:00:00:01:fc:97:51:ba, securityName=SHA256AES128)
07-Nov-2019::16:16:09.710 USM main: - USM.getUser - User ‘SHA256AES128’ unknown
07-Nov-2019::16:16:09.728 AuthGeneric main: - SHA-256First digest: f7:3d:87:80:40:27:8f:51:3c:a5:20:0d:34:c7:ae:71:80:b9:5c:71:12:f8:92:23:08:03:45:3b:72:ba:27:74

That log stops here is very unusual. I do not see the log level in the output. Maybe the DEBUG level is not active for all packages?

Are you using the SampleAgentConfig.properties?

Maybe the security protocols are missing in the agent that are configured in the properties file. But I would expect that then an error is logged but the agent still starts with the rest of the (working) config.

@Override
public Variable getVariable(String name) {
OID oid;
OctetString context = null;
LOGGER.debug("getVariable name: " + name);
int pos = name.indexOf(’:’);
if (pos >= 0) {
context = new OctetString(name.substring(0, pos));
oid = new OID(name.substring(pos + 1, name.length()));
} else {
oid = new OID(name);
}
LOGGER.debug("getVariable OID: " + oid.toString());
final DefaultMOContextScope scope = new DefaultMOContextScope(context, oid, true, oid, true);
MOQuery query = new MOQueryWithSource(scope, false, this);
ManagedObject mo = server.lookup(query);

    if (mo != null) {
        LOGGER.debug("getVariable: mo found");
        final VariableBinding vb = new VariableBinding(oid);
        final RequestStatus status = new RequestStatus();
        SubRequest req = new SubRequest() {
            private boolean completed;
            private MOQuery query;

            public boolean hasError() {
                return false;
            }

            public void setErrorStatus(int errorStatus) {
                status.setErrorStatus(errorStatus);
            }

            public int getErrorStatus() {
                return status.getErrorStatus();
            }

            public RequestStatus getStatus() {
                return status;
            }

            public MOScope getScope() {
                return scope;
            }

            public VariableBinding getVariableBinding() {
                return vb;
            }

            public Request getRequest() {
                return null;
            }

            public Object getUndoValue() {
                return null;
            }

            public void setUndoValue(Object undoInformation) {
            }

            public void completed() {
                completed = true;
            }

            public boolean isComplete() {
                return completed;
            }

            public void setTargetMO(ManagedObject managedObject) {
            }

            public ManagedObject getTargetMO() {
                return null;
            }

            public int getIndex() {
                return 0;
            }

            public void setQuery(MOQuery query) {
                this.query = query;
            }

            public MOQuery getQuery() {
                return query;
            }

            public SubRequestIterator<SubRequest> repetitions() {
                return null;
            }

            public void updateNextRepetition() {
            }

            public Object getUserObject() {
                return null;
            }

            public void setUserObject(Object userObject) {
            }

        };
        mo.get(req);
        LOGGER.debug("getVariable: return ");
        return vb.getVariable();
    }
    return null;
}

public void run() {
    agent.initialize();
    agent.setupProxyForwarder();
    registerMIBs();
    agent.registerShutdownHook();
    agent.run();
    if (agent.getState() == AgentConfigManager.STATE_RUNNING) {
        LOGGER.info("agent is in running state now. ");
    } else {
        LOGGER.error("agent state is " + agent.getState() + ", not running!");
    }
}

}

Yes, I just double confirmed the SampleAgentConfig.properties I use is totally the same as that in ‘example’ folder.
I set log level to ‘ALL’, and below are part of the contents in log file.

07-Nov-2019::16:16:09.708 PropertyMOInput main: - Read indexed variables IndexVariables[index=13.128.0.19.112.1.127.0.0.1.252.151.81.186.12.83.72.65.50.53.54.65.69.83.49.50.56,values=[SHA256AES128, , 1.3.6.1.6.3.10.1.1.5, , , 1.3.6.1.6.3.10.1.2.4, , , , 4, 1, SHA256AES128AuthPassword, SHA256AES128PrivPassword, null]] for OID 1.3.6.1.6.3.15.1.2.2.1 in context null
07-Nov-2019::16:16:09.709 USM main: - getUser(engineID=80:00:13:70:01:7f:00:00:01:fc:97:51:ba, securityName=SHA256AES128)
07-Nov-2019::16:16:09.709 USM main: - USM.getUser - User ‘SHA256AES128’ unknown
07-Nov-2019::16:16:09.709 USM main: - getUser(engineID=80:00:13:70:01:7f:00:00:01:fc:97:51:ba, securityName=SHA256AES128)
07-Nov-2019::16:16:09.709 USM main: - USM.getUser - User ‘SHA256AES128’ unknown
07-Nov-2019::16:16:09.709 USM main: - getUser(engineID=80:00:13:70:01:7f:00:00:01:fc:97:51:ba, securityName=SHA256AES128)
07-Nov-2019::16:16:09.709 USM main: - USM.getUser - User ‘SHA256AES128’ unknown
07-Nov-2019::16:16:09.709 USM main: - getUser(engineID=80:00:13:70:01:7f:00:00:01:fc:97:51:ba, securityName=SHA256AES128)
07-Nov-2019::16:16:09.709 USM main: - USM.getUser - User ‘SHA256AES128’ unknown
07-Nov-2019::16:16:09.710 USM main: - getUser(engineID=80:00:13:70:01:7f:00:00:01:fc:97:51:ba, securityName=SHA256AES128)
07-Nov-2019::16:16:09.710 USM main: - USM.getUser - User ‘SHA256AES128’ unknown
07-Nov-2019::16:16:09.728 AuthGeneric main: - SHA-256First digest: f7:3d:87:80:40:27:8f:51:3c:a5:20:0d:34:c7:ae:71:80:b9:5c:71:12:f8:92:23:08:03:45:3b:72:ba:27:74

What’s more, I could see bootCounterFile.bc generated, but there’s no ‘configFile.cfg’ generated. Is this normal behavior?

I paste my code here for your reference.

  1. main class

public class SnmpApp {
private static Logger LOGGER = Logger.getLogger(SnmpApp.class);

/**
 * 
 * Expects parameters: poolSize, isdebug
 * 
 * @param args
 * @throws Exception
 */
public static void main(String[] args) throws Exception {
    int poolSize = Integer.valueOf(args[0]).intValue();
    SnmpAgent sa = new SnmpAgent(poolSize);
    sa.run();

}

}

  1. agent class
    public class SnmpAgent implements VariableProvider {

    static {
    LogFactory.setLogFactory(new Log4jLogFactory());
    org.apache.log4j.BasicConfigurator.configure();
    LogFactory.getLogFactory().getRootLogger().setLogLevel(LogLevel.ALL);
    }

    private static Logger LOGGER = Logger.getLogger(SnmpAgent.class);

    private int saPoolSize = 0;
    protected AgentConfigManager agent;
    protected MOServer server;
    private String configFile;
    private File bootCounterFile;

    // supported MIBs
    protected Modules modules;

    public SnmpAgent(int poolSize) {
    saPoolSize = poolSize;
    LOGGER.debug("SnmpAgent started, poolSize " + poolSize);

    try {
        configFile = "configFile.cfg";
        bootCounterFile = new File("bootCounterFile.bc");
        server = new DefaultMOServer();
        MOServer[] moServers = new MOServer[] { server };
    
        InputStream configInputStream = null;
        final Properties props = new Properties();
        try {
        	configInputStream = SnmpAgent.class.getResourceAsStream("SnmpAgentConfig.properties");
            props.load(configInputStream);
        } catch (IOException ex) {
        	LOGGER.error("Failed to load SnmpAgentConfig.properties");
            ex.printStackTrace();
            return;
        }
        MOInputFactory configurationFactory = new MOInputFactory() {
            public MOInput createMOInput() {
                return new PropertyMOInput(props, SnmpAgent.this);
            }
        };
    
        String addressString = "udp:0.0.0.0/161";
        Address address = GenericAddress.parse(addressString);
        if (address == null) {
            LOGGER.error("Could not parse address string: " + addressString);
            return;
        }
        DefaultUdpTransportMapping tm = null;
        try {
            tm = new DefaultUdpTransportMapping((UdpAddress) address);
        } catch (IOException ex) {
            LOGGER.error("Failed to new DefaultUdpTransportMapping for address: " + address);
            ex.printStackTrace();
            return;
        }
        MessageDispatcher messageDispatcher = new MessageDispatcherImpl();
    	messageDispatcher.addTransportMapping(tm);
    	// Add TLSTM
        try {
            messageDispatcher.addTransportMapping(new TLSTM(new TlsAddress()));
        } catch (IOException iox) {
        	LOGGER.error("Caught exception while adding TLS transport mapping: "+iox.getMessage(), iox);
        }
    
        agent = new AgentConfigManager(new OctetString(MPv3.createLocalEngineID()), messageDispatcher, null,
            moServers, ThreadPool.create("SnmpApp", saPoolSize), configurationFactory,
            new DefaultMOPersistenceProvider(moServers, configFile), new EngineBootsCounterFile(bootCounterFile));
    
        SecurityProtocols.getInstance().addDefaultProtocols();
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    

    }

The .cfg file is only created on agent shutdown by default.

If the log output is correctly quoted then within the following code, the agent hangs:

    /*****************************************************/
    /* Now localize the key with the engine_id and pass  */
    /* through MD to produce final key                   */
    /*****************************************************/
    md.reset();
    md.update(digest);
    md.update(engineID);
    md.update(digest);
    digest = md.digest();

The next DEBUG log output will then start with “SHA-256localized key”. If that does not appear, something with the Java security protocols is not working properly on your system.

Hi Frank,

Glad to tell you that the ‘agent hang’ issue is now fixed by changing ‘LogLevel.ALL’ to ‘LogLevel.INFO’.
The thread was hanged when log4j was trying to write log file.

	static {
		  LogFactory.setLogFactory(new Log4jLogFactory());
		  org.apache.log4j.BasicConfigurator.configure();
		  LogFactory.getLogFactory().getRootLogger().setLogLevel(LogLevel.INFO);
	}

But I’m still curious why this happens.

And, the other issue I mentioned previously still exists.
Although there’s no DEBUG log printed now, the exception is still printed.

28881 [main] DEBUG org.snmp4j.transport.TLSTM  - Socket for address '127.0.0.1/1162' is closed, opening it...

Exception in thread "main" java.lang.NullPointerException
        at java.io.FileInputStream.<init>(FileInputStream.java:130)
        at java.io.FileInputStream.<init>(FileInputStream.java:93)
        at org.snmp4j.transport.TLSTM$DefaultSSLEngineConfiguration.getSSLContext(TLSTM.java:1814)
        at org.snmp4j.transport.TLSTM$SocketEntry.<init>(TLSTM.java:663)
        at org.snmp4j.transport.TLSTM$ServerThread.sendMessage(TLSTM.java:1201)
        at org.snmp4j.transport.TLSTM.sendMessage(TLSTM.java:477)
        at org.snmp4j.transport.TLSTM.sendMessage(TLSTM.java:69)
        at org.snmp4j.MessageDispatcherImpl.sendMessage(MessageDispatcherImpl.java:203)
        at org.snmp4j.MessageDispatcherImpl.sendPdu(MessageDispatcherImpl.java:522)
        at org.snmp4j.Snmp.sendMessage(Snmp.java:1087)
        at org.snmp4j.Snmp.send(Snmp.java:968)
        at org.snmp4j.Snmp.send(Snmp.java:961)
        at org.snmp4j.Snmp.send(Snmp.java:926)
        at org.snmp4j.agent.mo.snmp.NotificationOriginatorImpl.sendNotification(NotificationOriginatorImpl.java:270)
        at org.snmp4j.agent.mo.snmp.NotificationOriginatorImpl.notify(NotificationOriginatorImpl.java:376)
        at org.snmp4j.agent.mo.snmp.NotificationOriginatorImpl.notify(NotificationOriginatorImpl.java:140)
        at org.snmp4j.agent.AgentConfigManager.fireLaunchNotifications(AgentConfigManager.java:400)
        at org.snmp4j.agent.AgentConfigManager.launch(AgentConfigManager.java:392)
        at org.snmp4j.agent.AgentConfigManager.run(AgentConfigManager.java:248)
        at com.nokia.snmpapp.SnmpAgent.run(SnmpAgent.java:269)
        at com.nokia.snmpapp.SnmpApp.main(SnmpApp.java:38)

But there’s no such exception on version snmp4j-agent-2.6.0 and snmp4j-2.5.3.

Would you please kindly help to check this issue?
Appreciated.

After shutdown agent, I could see the .cfg file.

Is there any debug method to find which security protocol is not working properly?

I use Eclipse ‘Debug Configurations -> Remote Java Application’ to make a debug running.
Result is different from previous: agent was not hanged at ‘SHA-256localized key’ but went on and hanged at below prints:

28876 [main] INFO org.snmp4j.agent.mo.snmp.NotificationOriginatorImpl  - Sent notification with ID 1 TRAP[{contextEngineID=80:00:13:70:01:7f:00:00:01:50:88:65:b4, contextName=}, requestID=1630291867, errorStatus=0, errorIndex=0, VBS[1.3.6.1.2.1.1.3.0 = 0:00:25.75; 1.3.6.1.6.3.1.1.4.1.0 = 1.3.6.1.6.3.1.1.5.1]] to UserTarget[address=127.0.0.1/162,version=3,timeout=2500,retries=1,securityLevel=3,securityModel=3,securityName=SHA256DES,preferredTransports=null, authoritativeEngineID=80:00:13:70:01:7f:00:00:01:50:88:65:b4]
28876 [main] DEBUG org.snmp4j.agent.mo.snmp.VacmMIB  - VACM access requested for context=, securityName=TLSPRIV, securityModel=4, securityLevel=3, viewType=0, OID=1.3.6.1.6.3.1.1.5.1
28876 [main] DEBUG org.snmp4j.agent.mo.snmp.VacmMIB  - Found group name 'v3group' for secName 'TLSPRIV' and secModel 4
28876 [main] DEBUG org.snmp4j.agent.mo.snmp.VacmMIB  - Got views [DefaultMOMutableRow2PC[index=7.118.51.103.114.111.117.112.0.3.1,values=[1, unrestrictedReadView, , unrestrictedNotifyView, 3, 1], DefaultMOMutableRow2PC[index=7.118.51.103.114.111.117.112.0.3.2,values=[1, unrestrictedReadView, unrestrictedWriteView, unrestrictedNotifyView, 3, 1], DefaultMOMutableRow2PC[index=7.118.51.103.114.111.117.112.0.3.3,values=[1, unrestrictedReadView, unrestrictedWriteView, unrestrictedNotifyView, 3, 1], DefaultMOMutableRow2PC[index=7.118.51.103.114.111.117.112.0.4.1,values=[1, unrestrictedReadView, , unrestrictedNotifyView, 3, 1]] for group name 'v3group'
28877 [main] DEBUG org.snmp4j.agent.mo.snmp.VacmMIB  - Matching against access entry DefaultMOMutableRow2PC[index=7.118.51.103.114.111.117.112.0.3.1,values=[1, unrestrictedReadView, , unrestrictedNotifyView, 3, 1] with exactContextMatch=true, prefixMatch=false, matchSecModel=false and matchSecLevel=true
28877 [main] DEBUG org.snmp4j.agent.mo.snmp.VacmMIB  - Matching against access entry DefaultMOMutableRow2PC[index=7.118.51.103.114.111.117.112.0.3.2,values=[1, unrestrictedReadView, unrestrictedWriteView, unrestrictedNotifyView, 3, 1] with exactContextMatch=true, prefixMatch=false, matchSecModel=false and matchSecLevel=true
28877 [main] DEBUG org.snmp4j.agent.mo.snmp.VacmMIB  - Matching against access entry DefaultMOMutableRow2PC[index=7.118.51.103.114.111.117.112.0.3.3,values=[1, unrestrictedReadView, unrestrictedWriteView, unrestrictedNotifyView, 3, 1] with exactContextMatch=true, prefixMatch=false, matchSecModel=false and matchSecLevel=true
28877 [main] DEBUG org.snmp4j.agent.mo.snmp.VacmMIB  - Matching against access entry DefaultMOMutableRow2PC[index=7.118.51.103.114.111.117.112.0.4.1,values=[1, unrestrictedReadView, , unrestrictedNotifyView, 3, 1] with exactContextMatch=true, prefixMatch=false, matchSecModel=true and matchSecLevel=true
28877 [main] DEBUG org.snmp4j.agent.mo.snmp.VacmMIB  - Matching view found for group name 'v3group' is 'unrestrictedNotifyView'
28877 [main] DEBUG org.snmp4j.agent.mo.snmp.VacmMIB  - Access allowed for view 'unrestrictedNotifyView' by subtree 1.3.6 for OID 1.3.6.1.6.3.1.1.5.1
28881 [main] DEBUG org.snmp4j.mp.MPv3  - Adding cache entry: StateReference[msgID=68829,pduHandle=PduHandle[1630291868],securityEngineID=80:00:13:70:01:7f:00:00:01:50:88:65:b4,securityModel=org.snmp4j.security.TSM@3e74829,securityName=TLSPRIV,securityLevel=1,contextEngineID=80:00:13:70:01:7f:00:00:01:50:88:65:b4,contextName=,retryMsgIDs=null]
28881 [main] DEBUG org.snmp4j.transport.TLSTM  - Looking up connection for destination '127.0.0.1/1162' returned: null
28881 [main] DEBUG org.snmp4j.transport.TLSTM  - {}
28881 [main] DEBUG org.snmp4j.transport.TLSTM  - Socket for address '127.0.0.1/1162' is closed, opening it...
Exception in thread "main" java.lang.NullPointerException
        at java.io.FileInputStream.<init>(FileInputStream.java:130)
        at java.io.FileInputStream.<init>(FileInputStream.java:93)
        at org.snmp4j.transport.TLSTM$DefaultSSLEngineConfiguration.getSSLContext(TLSTM.java:1814)
        at org.snmp4j.transport.TLSTM$SocketEntry.<init>(TLSTM.java:663)
        at org.snmp4j.transport.TLSTM$ServerThread.sendMessage(TLSTM.java:1201)
        at org.snmp4j.transport.TLSTM.sendMessage(TLSTM.java:477)
        at org.snmp4j.transport.TLSTM.sendMessage(TLSTM.java:69)
        at org.snmp4j.MessageDispatcherImpl.sendMessage(MessageDispatcherImpl.java:203)
        at org.snmp4j.MessageDispatcherImpl.sendPdu(MessageDispatcherImpl.java:522)
        at org.snmp4j.Snmp.sendMessage(Snmp.java:1087)
        at org.snmp4j.Snmp.send(Snmp.java:968)
        at org.snmp4j.Snmp.send(Snmp.java:961)
        at org.snmp4j.Snmp.send(Snmp.java:926)
        at org.snmp4j.agent.mo.snmp.NotificationOriginatorImpl.sendNotification(NotificationOriginatorImpl.java:270)
        at org.snmp4j.agent.mo.snmp.NotificationOriginatorImpl.notify(NotificationOriginatorImpl.java:376)
        at org.snmp4j.agent.mo.snmp.NotificationOriginatorImpl.notify(NotificationOriginatorImpl.java:140)
        at org.snmp4j.agent.AgentConfigManager.fireLaunchNotifications(AgentConfigManager.java:400)
        at org.snmp4j.agent.AgentConfigManager.launch(AgentConfigManager.java:392)
        at org.snmp4j.agent.AgentConfigManager.run(AgentConfigManager.java:248)
        at com.nokia.snmpapp.SnmpAgent.run(SnmpAgent.java:269)
        at com.nokia.snmpapp.SnmpApp.main(SnmpApp.java:38)

What’s strange is, the address in TLSTM was changed to ‘127.0.0.1/1162’, while it’s ‘127.0.0.1/162’ in NotificationOriginatorImpl UserTarget.
Why is the port changed from 162 to 1162?

The NullPointerException means that you are using TLSTM but you have no key store configured.
You can configure a key store file programmatically but also with the following Java system properties:

javax.net.ssl.keyStore
javax.net.ssl.keyStorePassword

In version 3.3.2 you will get an error log message instead of a NullPointerException with the reason as follows:

Failed to initialize SSLContext because of missing key store (javax.net.ssl.keyStore)

The port 1162 is configured in the SNMP-TARGET-MIB for the trap target that is using TLSTM as transport protocol.
That configuration is part of the org/snmp4j/agent/example/SampleAgentConfig.properties file.

Thanks Frank for the explanation.
I don’t need TLSTM, so I don’t add it to messageDispatcher now.
Then I get below exception.
Although the agent works well to respond SNMP requests, could it be improved to not send the TLS trap in case there’s no TLSTM configured?

Anyway, my original problem has been solved.
Very appreciate your help, Frank.

<INFO> 11-Nov-2019::10:03:50.758 AgentConfigManager$AgentState main: - Agent state advanced to 40
<INFO> 11-Nov-2019::10:03:50.759 NotificationOriginatorImpl main: - Notification 1.3.6.1.6.3.1.1.5.1 reported with [] for context 


<INFO> 11-Nov-2019::10:03:55.770 NotificationOriginatorImpl main: - Sent notification with ID 1 INFORM[requestID=1927599613, errorStatus=Success(0), errorIndex=0, VBS[1.3.6.1.2.1.1.3.0 = 0:00:00.47; 1.3.6.1.6.3.1.1.4.1.0 = 1.3.6.1.6.3.1.1.5.1]] to CommunityTarget[address=127.0.0.1/162,version=1,timeout=2500,retries=1,securityLevel=1,securityModel=1,securityName=public,preferredTransports=null]
<INFO> 11-Nov-2019::10:03:55.772 NotificationOriginatorImpl main: - Sent notification with ID 1 TRAP[requestID=1927599614, errorStatus=Success(0), errorIndex=0, VBS[1.3.6.1.2.1.1.3.0 = 0:00:05.48; 1.3.6.1.6.3.1.1.4.1.0 = 1.3.6.1.6.3.1.1.5.1]] to CommunityTarget[address=127.0.0.1/162,version=1,timeout=2500,retries=1,securityLevel=1,securityModel=1,securityName=public,preferredTransports=null]
<INFO> 11-Nov-2019::10:03:56.070 NotificationOriginatorImpl main: - Sent notification with ID 1 TRAP[{contextEngineID=80:00:13:70:01:7f:00:00:01:df:df:57:89, contextName=}, requestID=1927599615, errorStatus=0, errorIndex=0, VBS[1.3.6.1.2.1.1.3.0 = 0:00:05.48; 1.3.6.1.6.3.1.1.4.1.0 = 1.3.6.1.6.3.1.1.5.1]] to UserTarget[address=127.0.0.1/162,version=3,timeout=2500,retries=1,securityLevel=3,securityModel=3,securityName=SHA256DES,preferredTransports=null, authoritativeEngineID=80:00:13:70:01:7f:00:00:01:df:df:57:89]
<ERROR> 11-Nov-2019::10:03:56.073 NotificationOriginatorImpl main: - Failed to send notification: Unsupported address class (transport mapping): org.snmp4j.smi.TlsAddress
org.snmp4j.transport.UnsupportedAddressClassException: Unsupported address class (transport mapping): org.snmp4j.smi.TlsAddress
        at org.snmp4j.MessageDispatcherImpl.sendPdu(MessageDispatcherImpl.java:455)
        at org.snmp4j.Snmp.sendMessage(Snmp.java:1087)
        at org.snmp4j.Snmp.send(Snmp.java:968)
        at org.snmp4j.Snmp.send(Snmp.java:961)
        at org.snmp4j.Snmp.send(Snmp.java:926)
        at org.snmp4j.agent.mo.snmp.NotificationOriginatorImpl.sendNotification(NotificationOriginatorImpl.java:270)
        at org.snmp4j.agent.mo.snmp.NotificationOriginatorImpl.notify(NotificationOriginatorImpl.java:376)
        at org.snmp4j.agent.mo.snmp.NotificationOriginatorImpl.notify(NotificationOriginatorImpl.java:140)
        at org.snmp4j.agent.AgentConfigManager.fireLaunchNotifications(AgentConfigManager.java:400)
        at org.snmp4j.agent.AgentConfigManager.launch(AgentConfigManager.java:392)
        at org.snmp4j.agent.AgentConfigManager.run(AgentConfigManager.java:248)
        at com.nokia.snmpapp.SnmpAgent.run(SnmpAgent.java:263)
        at com.nokia.snmpapp.SnmpApp.main(SnmpApp.java:38)
<INFO> 11-Nov-2019::10:03:56.080 NotificationOriginatorImpl main: - Sent notification with ID 1 V1TRAP[reqestID=0,timestamp=0:00:05.79,enterprise=0.0,genericTrap=0,specificTrap=0, VBS[]] to CommunityTarget[address=127.0.0.1/162,version=0,timeout=2500,retries=1,securityLevel=1,securityModel=1,securityName=public,preferredTransports=null]
<INFO> 11-Nov-2019::10:03:56.080 SnmpAgent main: - agent is in running state now.

If I disable the error log output, you won’t be able to detect a misconfiguration. That’s why it works that way. Nevertheless you are right: there should be more dynamic adaption between code and config.

I will think about that for one of the next releases.

That’ll be great.
Thanks Frank for all your help on this issue.