- Client and server now run indefinitely by default - Use -1 for infinite loops, positive numbers for limited runs - Better user feedback for infinite vs limited modes - Rebuilt binaries with infinite loop support Breaking change: Default behavior now runs until Ctrl+C
SRT Bonding Test Implementation
This project implements and tests SRT (Secure Reliable Transport) native bonding functionality, which allows aggregating multiple network connections for improved reliability and bandwidth.
Overview
SRT Connection Bonding provides:
- Broadcast Mode: Data sent redundantly over all member links
- Main/Backup Mode: Failover between primary and backup connections
- Seamless stream protection and hitless failover
- Multiple network path utilization for enhanced reliability
Features
- Native SRT bonding implementation in C++
- Broadcast bonding mode support
- Multiple endpoint configuration
- Real-time group status monitoring
- Non-blocking I/O with epoll
- Comprehensive error handling
- Cross-platform support (macOS, Linux)
Components
srt_bonding_streamer
The main streaming client that creates bonded SRT connections across multiple network interfaces and streams video data through them. Takes video input (like from FFmpeg) and sends it via multiple network paths simultaneously for redundancy and load balancing.
Usage:
./srt_bonding_streamer <srt_url> [interface1] [interface2] ...
Example:
# Auto-detect interfaces
ffmpeg -re -i video.mp4 -c copy -f mpegts - | ./srt_bonding_streamer srt://server:8282?streamid=publish/live/feed1
# Specify interfaces
./srt_bonding_streamer srt://server:8282?streamid=publish/live/feed1 en0 en1 en14
Prerequisites
SRT Library with Bonding Support
The SRT library must be compiled with bonding support enabled (-DENABLE_BONDING=ON).
Quick Installation
# Install SRT with bonding support
./install_srt.sh
Manual Installation
macOS (Homebrew):
brew install srt
Ubuntu/Debian:
sudo apt-get install libsrt-dev
Build from Source:
git clone https://github.com/Haivision/srt.git
cd srt
mkdir build && cd build
cmake .. -DENABLE_BONDING=ON -DCMAKE_BUILD_TYPE=Release
make -j$(nproc)
sudo make install
Build Dependencies
- CMake 3.10+
- C++17 compatible compiler
- pkg-config
- libsrt with bonding support
Building
# Make scripts executable
chmod +x *.sh
# Build the project
./build.sh
Usage
Basic Test
Run the automated test:
./test_bonding.sh
Manual Testing
Start Server:
cd build
./srt_bonding_server 0.0.0.0:9001 0.0.0.0:9002
Start Client:
cd build
./srt_bonding_client 127.0.0.1:9001 127.0.0.1:9002
Advanced Configuration
Multiple Interfaces:
# Server listening on different interfaces
./srt_bonding_server 192.168.1.100:9001 192.168.2.100:9002
# Client connecting to different endpoints
./srt_bonding_client 192.168.1.100:9001 192.168.2.100:9002
More Endpoints:
# Up to multiple bonded connections
./srt_bonding_server 0.0.0.0:9001 0.0.0.0:9002 0.0.0.0:9003
./srt_bonding_client 127.0.0.1:9001 127.0.0.1:9002 127.0.0.1:9003
How It Works
SRT Bonding Architecture
- Socket Groups: Multiple SRT sockets grouped together
- Broadcast Mode: Data transmitted over all available links
- Redundancy: Duplicate packets discarded at receiver
- Failover: Automatic switching when links fail
- Load Distribution: Traffic balanced across links
Key Components
Client Side:
- Creates socket group with
srt_create_group(SRT_GTYPE_BROADCAST) - Connects to multiple endpoints using
srt_connect_group() - Sends data through group with
srt_sendmsg2() - Monitors group status for link health
Server Side:
- Creates multiple listeners with
SRTO_GROUPCONNECTflag - Accepts bonded connections with
srt_accept_bond() - Receives data from group with
srt_recvmsg2() - Tracks group member status
Group Status Monitoring
Both client and server monitor connection status:
- Connected: Link is active and healthy
- Pending: Link is connecting or initializing
- Broken: Link has failed or disconnected
Testing Scenarios
Network Resilience Test
- Start server and client with multiple endpoints
- Monitor group status during transmission
- Simulate network interruption on one link
- Verify continued operation on remaining links
Bandwidth Aggregation Test
- Configure multiple network interfaces
- Bind server to different interface addresses
- Connect client through multiple paths
- Measure combined throughput
Failover Test
- Establish bonded connection
- Disable primary network interface
- Verify seamless failover to backup links
- Monitor for packet loss during transition
Troubleshooting
Common Issues
"Failed to create socket group":
- SRT library not compiled with bonding support
- Run
./install_srt.shto rebuild with bonding
"Connection refused":
- Check firewall settings
- Verify port availability with
netstat -ln | grep :9001 - Ensure server is running before client
"No group data available":
- Single socket connection instead of bonded group
- Verify both endpoints support bonding
- Check
SRTO_GROUPCONNECTflag on server
Verification Commands
# Check SRT version and bonding support
pkg-config --modversion srt
pkg-config --cflags srt | grep BONDING
# Check port usage
netstat -ln | grep :900
# Monitor network interfaces
ip addr show # Linux
ifconfig # macOS
Performance Considerations
Optimal Configuration
- Use separate physical network interfaces for each bonded link
- Configure appropriate buffer sizes for your network conditions
- Monitor group statistics for link health
- Implement reconnection logic for broken links
Network Requirements
- Multiple independent network paths
- Sufficient bandwidth on each link
- Low latency for real-time applications
- Stable network conditions for best results
API Reference
Key SRT Bonding Functions
// Create socket group
SRTSOCKET srt_create_group(SRT_GROUP_TYPE type);
// Connect to multiple endpoints
int srt_connect_group(SRTSOCKET u, SRT_SOCKGROUPCONFIG* config, int arraysize);
// Accept bonded connection
SRTSOCKET srt_accept_bond(const SRTSOCKET listeners[], int lsize, int msTimeOut);
// Send through group
int srt_sendmsg2(SRTSOCKET u, const char* buf, int len, SRT_MSGCTRL* mctrl);
// Receive from group
int srt_recvmsg2(SRTSOCKET u, char* buf, int len, SRT_MSGCTRL* mctrl);
Group Types
SRT_GTYPE_BROADCAST: Broadcast/redundant transmissionSRT_GTYPE_BACKUP: Main/backup failover mode
Contributing
- Fork the repository
- Create feature branch
- Add tests for new functionality
- Submit pull request
License
This project is provided as educational/testing code. Please refer to the SRT library license for usage terms.