Skip to content

Bindings

Xinxin Mei edited this page Sep 6, 2024 · 10 revisions

Bindings

Python Bindings

The Python bindings for E2SAR are implemented with pybind11. You can find the source code in the 'src/pybind' directory.

Usage

The pybind11 module, named e2sar_py, is built alongside the C++ library and is named e2sar_py.cpython-<platform>.so based on the platform. To use the module, add its path to the Python environment:

# Add the path of the pybind module
import sys
sys.path.append('/path/to/e2sar_py.cpython-<platform>.so')

# Import the module
import e2sar_py
# Your Python code here

Examples

We provide Jupyter notebooks in the 'scripts/notebooks/pybind11_examples' directory to demonstrate Python usage.

  • example_DataPlane.ipynb: Shows how to use the Python Segmenter and Reassembler classes to send and receive messages without a real FPGA control plane.
  • example_EjfatURI.ipynb: Demonstrates how to create Python EjfatURI classes and handle cases where C++ functions return result<T> types.

Binding details

We list the C++ e2sar classes that are bound to Python and explain how their input, output, and return types are mapped to Python equivalents.

Bindings for e2sar::EjfatURI

The C++ e2sar::EjfatURI class is mapped to the Python class e2sar_py.EjfatURI with its public methods listed in the table below.

Click to expand
Members C++ `e2sar::EjfatURI` class Python `e2sar_py.EjfatURI` class
Notes
Enum class EjfatURI::TokenType::admin;
EjfatURI::TokenType::instance;
EjfatURI::TokenType::session;
EjfatURI.TokenType.admin
EjfatURI.TokenType.instance
EjfatURI.TokenType.session
Constructor EjfatURI(const std::string &, TokenType, bool); EjfatURI(uri: str, tt: e2sar_py.EjfatURI.TokenType) The same default parameters.
Get/Set LB name const std::string get_lbName();
void set_lbName(const std::string &);
EjfatURI.lb_name The C++ get and set methods are mapped to the `lb_name` attribute of type string in the Python `EjfatURI` class.
Get/Set LB ID const std::string get_lbId();
void set_lbId(const std::string &);
EjfatURI.lb_id
Get/Set session ID const std::string get_sessionId();
void set_sessionId(const std::string &);
EjfatURI.session_id
Void function - set tokens set_InstanceToken(const std::string &);
set_SessionToken(const std::string &);
EjfatURI.set_instance_token(token: str) -> None
EjfatURI.set_session_token(token: str) -> None
Void function - set IP v4/v6 addresses set_syncAddr(const std::pair<ip::address, u_int16_t> &);
set_dataAddr(const std::pair<ip::address, u_int16_t> &);
EjfatURI.set_isync_addr(ip_tuple: Tuple[e2sar_py.IPAddress, int]) -> None
EjfatURI.set_data_addr(ip_tuple: Tuple[e2sar_py.IPAddress, int]) -> None
The C++ `std::pair` is mapped to a Python tuple, and the C++ `ip::address` class is mapped to the Python helper class `e2sar_py.IPAddress`. You can create `e2sar_py.IPAddress` Python objects using the method `e2sar_py.IPAddress.from_string(ip_str: str)`.

Clone this wiki locally