Class McpSnmpBuilder

java.lang.Object
org.snmp4j.mcp.tool.snmp.McpSnmpBuilder

public class McpSnmpBuilder extends Object
Fluent builder that translates an SnmpMcpServer.ServerConfiguration.SnmpTargetConfig into the SNMP4J fluent-API objects (Target, Snmp, PduBuilder) used by MCP tool implementations.

Besides the connectionless udp: and the connection oriented tcp: transports, the builder supports the secure transports tls: (RFC 6353) and dtls: (RFC 5953). Their transport mappings and targets are configured entirely from the TLS section of the target configuration, see SnmpMcpServer.ServerConfiguration.TlsConfig. A (D)TLS target always uses the Transport Security Model (TSM, RFC 5591) instead of the User-based Security Model.

Transport mappings are shared between all targets of a SnmpBuilder that need the same transport configuration, because a transport mapping owns the listen socket and the key material of a connection. Two targets that differ in any transport level (D)TLS parameter - key store, trust store, local certificate alias, protocol versions, revocation checking or message sizes - therefore get their own transport mapping, and every built target is bound to its transport mapping with AbstractTarget.setPreferredTransports(List). Target level parameters (security name, certificate fingerprints, expected server identity) do not require a separate transport mapping: they are carried by the TlsX509CertifiedTarget and its TlsTmSecurityCallback, which takes precedence over the callback of the transport mapping.

  • Method Details

    • builder

      public static McpSnmpBuilder builder(org.snmp4j.fluent.SnmpBuilder snmpBuilder)
      Creates a builder wrapping the given SnmpBuilder.
      Parameters:
      snmpBuilder - the underlying SNMP4J fluent builder
      Returns:
      a new McpSnmpBuilder
    • withTarget

      Sets the target configuration to use when building the SNMP target.
      Parameters:
      targetConfig - the server target configuration
      Returns:
      this builder
    • buildTarget

      public org.snmp4j.Target<org.snmp4j.smi.Address> buildTarget() throws IOException
      Builds and returns an SNMP Target from the current target configuration. As a side effect, the transport mapping, message processing model and security model that the target requires are added to the underlying SnmpBuilder unless an equally configured one has been added before.
      Returns:
      the configured SNMP target, or null if no config has been set
      Throws:
      IOException - if transport initialization fails
      IllegalArgumentException - if the target address or a (D)TLS parameter is invalid
    • buildSnmp

      public org.snmp4j.Snmp buildSnmp(org.snmp4j.Snmp existingSnmp) throws IOException
      Returns existingSnmp if non-null, otherwise builds and returns a new Snmp instance. If buildTarget() had to add a new transport mapping to an already open session, that transport mapping is started here.
      Parameters:
      existingSnmp - an already-open session to reuse, or null
      Returns:
      an open SNMP session
      Throws:
      IOException - if building a new session fails
    • buildPdu

      public org.snmp4j.fluent.PduBuilder buildPdu()
      Returns a PduBuilder for constructing the PDU to be sent.
      Returns:
      a PDU builder for the current target