Package rosgraph :: Module network
[frames] | no frames]

Module network

source code

Network APIs for ROS-based systems, including IP address and ROS TCP header libraries. Because ROS-based runtimes must respect the ROS_IP and ROS_HOSTNAME environment variables, ROS-specific APIs are necessary for correctly retrieving local IP address information.

Classes
  ROSHandshakeException
Exception to represent errors decoding handshake
Functions
 
parse_http_host_and_port(url)
Convenience routine to handle parsing and validation of HTTP URL port due to the fact that Python only provides easy accessors in Python 2.5 and later.
source code
 
get_address_override()
:returns: ROS_IP/ROS_HOSTNAME override or None, ``str`` :raises: :exc:`ValueError` If ROS_IP/ROS_HOSTNAME/__ip/__hostname are invalidly specified
source code
 
is_local_address(hostname)
:param hostname: host name/address, ``str`` :returns True: if hostname maps to a local address, False otherwise.
source code
 
get_local_address()
:returns: default local IP address (e.g.
source code
 
get_local_addresses()
:returns: known local addresses.
source code
 
use_ipv6() source code
 
get_bind_address(address=None)
:param address: (optional) address to compare against, ``str`` :returns: address TCP/IP sockets should use for binding.
source code
 
get_host_name()
Determine host-name for use in host-name-based addressing (e.g.
source code
 
create_local_xmlrpc_uri(port)
Determine the XMLRPC URI for local servers.
source code
 
decode_ros_handshake_header(header_str)
Decode serialized ROS handshake header into a Python dictionary
source code
 
read_ros_handshake_header(sock, b, buff_size)
Read in tcpros header off the socket  sock using buffer  b.
source code
 
encode_ros_handshake_header(header)
Encode ROS handshake header as a byte string.
source code
 
write_ros_handshake_header(sock, header)
Write ROS handshake header header to socket sock
source code
Variables
  python3 = 0
  SIOCGIFADDR = 35093
  SIOCGIFCONF = 35090
  logger = logging.getLogger('rosgraph.network')
  __package__ = 'rosgraph'
Function Details

parse_http_host_and_port(url)

source code 

Convenience routine to handle parsing and validation of HTTP URL port due to the fact that Python only provides easy accessors in Python 2.5 and later. Validation checks that the protocol and host are set.

:param url: URL to parse, ``str`` :returns: hostname and port number in URL or 80 (default), ``(str, int)`` :raises: :exc:`ValueError` If the url does not validate

is_local_address(hostname)

source code 

:param hostname: host name/address, ``str`` :returns True: if hostname maps to a local address, False otherwise. False conditions include invalid hostnames.

get_local_address()

source code 

:returns: default local IP address (e.g. eth0). May be overriden by ROS_IP/ROS_HOSTNAME/__ip/__hostname, ``str``

get_local_addresses()

source code 

:returns: known local addresses. Not affected by ROS_IP/ROS_HOSTNAME, ``[str]``

get_bind_address(address=None)

source code 

:param address: (optional) address to compare against, ``str``
:returns: address TCP/IP sockets should use for binding. This is
  generally 0.0.0.0, but if  address or ROS_IP/ROS_HOSTNAME is set
  to localhost it will return 127.0.0.1, ``str``

get_host_name()

source code 

Determine host-name for use in host-name-based addressing (e.g. XML-RPC URIs):

  • if ROS_IP/ROS_HOSTNAME is set, use that address
  • if the hostname returns a non-localhost value, use that
  • use whatever get_local_address() returns

create_local_xmlrpc_uri(port)

source code 

Determine the XMLRPC URI for local servers. This handles the search logic of checking ROS environment variables, the known hostname, and local interface IP addresses to determine the best possible URI.

:param port: port that server is running on, ``int`` :returns: XMLRPC URI, ``str``

decode_ros_handshake_header(header_str)

source code 

Decode serialized ROS handshake header into a Python dictionary

header is a list of string key=value pairs, each prefixed by a 4-byte length field. It is preceeded by a 4-byte length field for the entire header.

:param header_str: encoded header string. May contain extra data at the end, ``str`` :returns: key value pairs encoded in  header_str, ``{str: str}``

read_ros_handshake_header(sock, b, buff_size)

source code 

Read in tcpros header off the socket  sock using buffer  b.

:param sock: socket must be in blocking mode, ``socket`` :param b: buffer to use, ``StringIO`` for Python2, ``BytesIO`` for Python 3 :param buff_size: incoming buffer size to use, ``int`` :returns: key value pairs encoded in handshake, ``{str: str}`` :raises: :exc:`ROSHandshakeException` If header format does not match expected

encode_ros_handshake_header(header)

source code 

Encode ROS handshake header as a byte string. Each header field is a string key value pair. The encoded header is prefixed by a length field, as is each field key/value pair. key/value pairs a separated by a '=' equals sign.

FORMAT: (4-byte length + [4-byte field length + field=value ]*)

:param header: header field keys/values, ``dict`` :returns: header encoded as byte string, ``bytes``

write_ros_handshake_header(sock, header)

source code 

Write ROS handshake header header to socket sock

:param sock: socket to write to (must be in blocking mode), ``socket.socket`` :param header: header field keys/values, ``{str : str}`` :returns: Number of bytes sent (for statistics), ``int``