PySNMP: Transport Mappings: UDP/IP: Synchronous

### Synchronous I/O engine

The following code implements network transport that performs synchronous, blocking I/O over a single BSD socket. It is intended to serve as a network transport for SNMP messages, within a synchronous SNMP entity process, over a TCP/IP network.

The pysnmp.mapping.udp.role module defines the following items:

class Manager([dstAddr[,iface]])

  Returns a new instance of Manager class, representing network client (SNMP manager) optionally connected to a SNMP agent running at dstAddr. The dstAddr argument, whenever given, must follow the socket module notation -- ('hostname', port) where hostname is a string and port is an integer.

  The default for dstAddr is None what means no default destination, so user would unconditionally have to specify destination to each Manager.send() method (see below).

  Once a default dstAddr is specified, specific destination may not be given to the Manager.send() method.

  The iface parameter, if given, specifies the interface and port on local machine to bind() to. This argument must also follow the socket module notation. All further requests would then be originated from the given interface/port (for example, ('127.0.0.1', 0)).

  The default for iface is ('0.0.0.0', 0) what stands for binding to a primary interface at the local machine.

class Agent([(cbFun, cbCtx)[, ifaces]])

  Returns a new instance of Agent class, representing network server optionally bound to specific network interfaces/ports ifaces at the local machine. The ifaces argument, whenever given, must be a list of ('iface', port) tuples given in socket module notation.

  The optional cbFun and cbCtx parameters may be used on class instaniation to specify the default user callback function to be invoked on message receiption. A reference to user-specific data (context) may be passed as cbCtx parameter.

  The cbFun, if given, must support the following interface:

  cbFun(cbCtx, (reqMsg, srcAddr))

    Where reqMsg is an octet-string, as received from network, and srcAddr is message source address given in socket module notation.

    The callback function is expected to return a tuple of (rspMsg, srcAddr), where rspMsg (string) is the serialized agent's response to be replied back to manager by address dstAddr (given in socket module notation).

  The default for the ifaces is to listen on the loopback interface, port 161/UDP, so the default value is [('127.0.0.1', 161)].

  Be aware that for a UNIX process to bind(2) to a low port, such as 161 (that is less than 1024), a superuser privelege is required. Since running scripts under superuser privelege is not particular secure in UNIX environment, binding to a non-priveleged port is therefore strongly recommended.

Methods of the above classes may raise exceptions based on error.SnmpOverUdpError base class.

Subsections

- Objects of the role.Manager class
- Objects of the role.Agent class