3. Interface with the Lickelider Transmission Protocol (LTP)

pyion provides two main abstraction to send/request data through LTP (without BP):

  • LtpProxy: Proxy to ION’s LTP engine for a given node (identified by a client id). You should only ever have one proxy per node number. To ensure that this is the case, do not create Proxies manually. Instead, use pyion.get_ltp_proxy.

  • AccessPoint: Access point to send/receive data using LTP. Do not open/close/interrupt/delete access points manually, always do it through the proxy (note that all AccessPoints reference the Proxy that create them).

Under most normal circumstances LTP will ensure delivery of data to destination without errors. However, just like TCP or any other practical Automatic Repeat Request mechansims, LTP eventually ceases transmission if it has no success in getting any bytes through (this is a defense mechanism to avoid having LTP hung forever). When that happens, ltp_send will raise a RuntimeError exception that must be processed by the user.

Example 1: LTP Transmitter

 1# General imports
 2from random import choice
 3import string
 4
 5# Import module
 6import pyion
 7
 8# =================================================================
 9# === Define global variables
10# =================================================================
11
12# ION node numbers
13node_nbr, peer_nbr = 1, 2
14
15# Client identifier
16client_id = 4
17
18# Define data size in bytes. Set to 1200 bytes because LTP block and
19# LTP segment are set to this value
20data_size = 2400
21
22# Define data to send as a stream of random ASCII chars. Each char
23# uses 1 byte.
24chars = list(string.ascii_lowercase)
25data  = ''.join([choice(chars) for _ in range(data_size)]).encode('utf-8')
26
27# =================================================================
28# === MAIN
29# =================================================================
30
31# Create a proxy to LTP
32pxy = pyion.get_ltp_proxy(node_nbr)
33
34# Open a endpoint access point for this client and send data
35with pxy.ltp_open(client_id) as sap:
36    print('Sending', data)
37    sap.ltp_send(peer_nbr, data)

Example 1: LTP Receiver

 1# Import module
 2import pyion
 3
 4# =================================================================
 5# === Define global variables
 6# =================================================================
 7
 8# ION node numbers
 9node_nbr, peer_nbr = 2, 1
10
11# Client identifier
12client_id = 4
13
14# =================================================================
15# === MAIN
16# =================================================================
17
18# Create a proxies to ION
19pxy = pyion.get_ltp_proxy(node_nbr)
20
21# Open a service access point and receive data
22with pxy.ltp_open(client_id) as sap:
23    # You are now ready to received
24    print('LTP ready to receive data')
25
26    # Receive
27    while sap.is_open:
28        try:
29            # This is a blocking call
30            data = sap.ltp_receive()
31            print(data)
32        except ConnectionAbortedError:
33            break