Simulate 300+ ONVIF Cameras on a Single PC

A step-by-step guide to use Multi ONVIF Server for large-scale device testing.

Introduction

Multi ONVIF Server supports simulating a large number of IP cameras on a single PC. Follow the steps below to configure and generate a configuration file for 300+ devices.

1. Prepare the Configuration Generation Script

Create a Python script named generate-onvif-config.py in the same directory as your onvif.cfg file. This script will read your existing configuration and automatically generate a new one with 300 device nodes, each with unique HTTP and HTTPS ports.

1.1 Python Script Code

Copy the complete script below into your generate-onvif-config.py file:

# Import the XML parsing library
import xml.etree.ElementTree as ET

# Read the original onvif.cfg configuration file
tree = ET.parse('onvif.cfg')
root = tree.getroot()

# Extract global settings (log_enable, log_level) if they exist
log_enable = root.find('log_enable')
log_level = root.find('log_level')

# Find all existing <device> nodes
devices = root.findall('device')
if len(devices) < 1:
    raise ValueError("onvif.cfg must contain at least 1 <device> node")

# Use the first device as a template for cloning
device = devices[0]

# Create a new XML root element for the generated configuration
new_root = ET.Element('config')

# Preserve global log settings in the new configuration
if log_enable is not None:
    ET.SubElement(new_root, 'log_enable').text = log_enable.text
if log_level is not None:
    ET.SubElement(new_root, 'log_level').text = log_level.text

# Generate 300 device nodes with incrementing ports
for i in range(300):
    # Assign unique HTTP port (starts at 10000)
    http_port = 10000 + i
    # Assign unique HTTPS port (starts at 8443)
    https_port = 8443 + i
    
    # Create a deep copy of the template device
    device_copy = ET.fromstring(ET.tostring(device))
    
    # Update the HTTP port in the copied device
    http_port_elem = device_copy.find('http_port')
    if http_port_elem is not None:
        http_port_elem.text = str(http_port)
    else:
        ET.SubElement(device_copy, 'http_port').text = str(http_port)
    
    # Update the HTTPS port in the copied device
    https_port_elem = device_copy.find('https_port')
    if https_port_elem is not None:
        https_port_elem.text = str(https_port)
    else:
        ET.SubElement(device_copy, 'https_port').text = str(https_port)
        
    # Add the modified device node to the new configuration
    new_root.append(device_copy)

# Improve the formatting of the generated XML with indentation
ET.indent(new_root, space="  ")

# Write the new configuration to a file
new_tree = ET.ElementTree(new_root)
# Add XML declaration and proper encoding
with open('onvif_generated.cfg', 'wb') as f:
    f.write(b'<?xml version="1.0" encoding="utf-8"?>\n')
    new_tree.write(f, encoding='utf-8', xml_declaration=False)

# Print success message
print("? Successfully generated onvif_generated.cfg")
print(f"   - Contains {300} device nodes with unique ports")
print("   - HTTP ports: 10000 - {10000 + 299}")
print("   - HTTPS ports: 8443 - {8443 + 299}")
Tip: Ensure the script and onvif.cfg are in the same directory.

1.2 Execute the Script

Open a command prompt or terminal, navigate to the directory containing the script and onvif.cfg, then run:

python generate-onvif-config.py

On successful execution, a file named onvif_generated.cfg will be created.

Warning: Make sure you have Python installed and the required xml.etree.ElementTree module available.

2. Update Multi ONVIF Server Configuration

Replace the server's configuration with the generated file:

  1. Backup your original onvif.cfg file.
  2. Rename onvif_generated.cfg to onvif.cfg.
  3. If a runtime configuration file named onvifrun.cfg exists, delete it to force the server to reload the new configuration.

3. Start Multi ONVIF Server

Launch the Multi ONVIF Server application. It will now simulate 300+ ONVIF cameras, each accessible on its assigned HTTP and HTTPS port.

4. Verification

Use an ONVIF client tool such as ONVIF Device Manager (ODM) to discover devices on the network. The tool should detect and list all 300+ simulated cameras.