LINK="#0000bb" VLINK="#551a8b" ALINK="#ff0000">

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([dst[,iface]])

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

The default for dst 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 dst 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([(cb_fun, cb_ctx)[, 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 ('ifacename', port) tuples given in socket module notation.

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

The cb_fun, if given, must match the following prototype:

cb_fun(cb_ctx, (question, src))

Where question is an octet-string, as received from network, and src is question's source address given in socket module notation.

The callback function is expected to return a tuple of (answer, dst), where answer (string) is the data item to be replied back to manager by address dst (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


ilya@glas.net