Skip to content
softovPublic

About

A TypeScript CWMP/TR-069 CPE simulator for testing ACS sessions, SOAP RPC flows, Digest authentication, diagnostics, file transfers, and Connection Request handling.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

cwmp-sim

npm version node license

A TypeScript CWMP/TR-069 CPE simulator for testing ACS sessions, SOAP RPC flows, Digest authentication, diagnostics, file transfers, and Connection Request handling.

Published on npm as cwmp-sim. Run it as a CLI with npx cwmp-sim, or clone the repo to develop. Zero runtime dependencies — Node.js >=22 only.

What This Project Is

cwmp-sim is a developer-oriented CWMP (CPE WAN Management Protocol) simulator.

It is designed to help:

  • Test ACS provisioning logic.
  • Debug CWMP SOAP/XML request and response payloads.
  • Reproduce CPE session behavior.
  • Validate ACS handling of CPE-initiated sessions.
  • Test Connection Request flows.
  • Exercise parameter reads and writes.
  • Simulate diagnostics and transfer completion events.
  • Experiment with TR-098/TR-181-like data models.

What This Project Is Not

This project is not a complete router firmware, not a real CPE implementation, and not a CWMP/TR-069 certification suite.

It implements a practical subset of CWMP/TR-069 behavior for ACS testing, protocol development, and debugging.

Overview

cwmp-sim simulates a CPE (Customer Premises Equipment) talking to an ACS (Auto Configuration Server) over CWMP/TR-069. It starts a local Connection Request server, sends Inform messages to the ACS, processes SOAP RPCs from the ACS, updates an in-memory device data model, and can trigger follow-up sessions for events such as diagnostics completion, transfer completion, reboot, factory reset, and connection requests.

The project is intentionally small and uses native Node.js networking/XML helpers for the runtime path. It is written in TypeScript and uses TypeScript tooling for development.

What It Supports

CWMP session behavior

  • Initial 1 BOOT inform on startup.
  • Periodic inform scheduling after idle/end-of-session responses.
  • ACS-driven RPC request/response loop.
  • Empty HTTP POST handling during the CWMP session.
  • ACS empty response / HTTP 204 handling as end of session.
  • CPE-originated follow-up events:
    • 2 PERIODIC
    • 6 CONNECTION REQUEST
    • 7 TRANSFER COMPLETE
    • 8 DIAGNOSTICS COMPLETE
    • M Reboot
    • M Download
    • M Upload

ACS HTTP client

  • HTTP and HTTPS ACS URLs.
  • Keep-alive session transport.
  • Basic authentication.
  • Digest authentication retry after ACS 401 challenge.
  • Cookie forwarding from Set-Cookie during Digest retry.
  • SOAP request generation and response parsing.

Connection Requests

  • Local Connection Request listener, default port 7547.
  • HTTP listener by default.
  • Digest authentication by default when credentials are configured.
  • Basic authentication when configured through connection options.
  • Valid requests trigger a new CWMP session with 6 CONNECTION REQUEST.
  • Device.ManagementServer.ConnectionRequestURL is updated from the listener address.

Data models

The simulator keeps an in-memory CPE parameter tree. Leaf parameters follow this internal shape:

{
  _value: string;
  _type: string;
  _writable: boolean;
}

The simulator can use either root object:

Device

or:

InternetGatewayDevice

Built-in model areas include:

  • DeviceInfo
  • ManagementServer
  • WAN IP connection parameters
  • WLAN configuration parameters
  • port mapping objects
  • IP ping diagnostics
  • traceroute diagnostics
  • download diagnostics
  • upload diagnostics

Model fixtures are available under models/, including JSON and CSV files.

Supported RPC methods

The simulator advertises and handles these ACS RPCs:

  • GetRPCMethods
  • InformResponse
  • GetParameterValues
  • GetParameterNames
  • SetParameterValues
  • SetParameterAttributes
  • GetParameterAttributes
  • AddObject
  • DeleteObject
  • Download
  • Upload
  • Reboot
  • FactoryReset
  • ScheduleInform
  • GetQueuedTransfers
  • GetAllQueuedTransfers
  • ScheduleDownload
  • CancelTransfer
  • TransferCompleteResponse

Unsupported RPCs return a CWMP 9000 Method not supported fault.

CWMP Session Flow

A typical CWMP session follows this flow:

sequenceDiagram
  autonumber

  participant CPE
  participant ACS

  CPE->>ACS: Inform
  ACS-->>CPE: InformResponse
  CPE->>ACS: Empty HTTP POST
  ACS-->>CPE: RPC request
  CPE->>ACS: RPC response
  ACS-->>CPE: Empty response
  CPE->>CPE: End session
Loading

The simulator repeats the ACS RPC request and CPE RPC response part of the flow until the ACS ends the session with an empty response or HTTP 204.

Diagnostics

The simulator includes task-based diagnostic behavior. Diagnostics are triggered when the ACS sets the corresponding DiagnosticsState parameter to Requested:

Supported diagnostic areas include:

  • IP ping
  • traceroute
  • download diagnostics
  • upload diagnostics
  • neighboring Wi-Fi diagnostics

IP ping and traceroute shell out to the host's ping/traceroute (or tracert) and parse the output per platform — Windows, Linux, and macOS.

When a diagnostic finishes, the simulator can trigger a new inform session with 8 DIAGNOSTICS COMPLETE:

sequenceDiagram
  autonumber

  participant CPE
  participant ACS

  CPE->>ACS: HTTP POST Inform
  ACS-->>CPE: InformResponse

  CPE->>ACS: Empty HTTP POST

  ACS-->>CPE: SetParameterValues<br/>IPPingDiagnostics.Host
  CPE->>ACS: SetParameterValuesResponse

  ACS-->>CPE: SetParameterValues<br/>IPPingDiagnostics.DiagnosticsState = Requested
  CPE->>ACS: SetParameterValuesResponse

  ACS-->>CPE: Empty response
  CPE->>CPE: Run ping diagnostic
  CPE->>CPE: End session

  Note over CPE,ACS: Later session after diagnostic completion

  CPE->>ACS: HTTP POST Inform<br/>8 DIAGNOSTICS COMPLETE
  ACS-->>CPE: InformResponse

  CPE->>ACS: Empty HTTP POST

  ACS-->>CPE: GetParameterValues<br/>IPPingDiagnostics result parameters
  CPE->>ACS: GetParameterValuesResponse<br/>SuccessCount, FailureCount, AverageResponseTime

  ACS-->>CPE: Empty response
  CPE->>CPE: End session
Loading

Transfers

The simulator supports transfer-style tasks for CWMP Download and Upload RPCs.

  • Download performs an HTTP/HTTPS GET against the requested URL.
  • Upload performs an HTTP/HTTPS PUT to the requested URL.
  • Transfer tasks queue a TransferComplete RPC after completion or failure.
  • Delayed transfer execution is supported through DelaySeconds for immediate Download/Upload tasks.
  • Queued transfer inspection is available through GetQueuedTransfers and GetAllQueuedTransfers.

Transfer tasks can produce completion events such as:

7 TRANSFER COMPLETE; M Download
7 TRANSFER COMPLETE; M Upload

Or a more advanced asynchronous download flow:

sequenceDiagram
  autonumber

  participant CPE
  participant ACS
  participant FILE as File Server

  CPE->>ACS: HTTP POST Inform
  ACS-->>CPE: InformResponse

  CPE->>ACS: Empty HTTP POST

  ACS-->>CPE: Download<br/>FileType, URL, Username, Password, TargetFileName
  CPE->>ACS: DownloadResponse<br/>Status = 1

  ACS-->>CPE: Empty response
  CPE->>CPE: End session

  CPE->>FILE: HTTP GET file
  FILE-->>CPE: File content

  Note over CPE,ACS: Later session after transfer completion

  CPE->>ACS: HTTP POST TransferComplete<br/>CommandKey, FaultStruct, StartTime, CompleteTime
  ACS-->>CPE: TransferCompleteResponse

  CPE->>ACS: Empty HTTP POST
  ACS-->>CPE: Empty response
  CPE->>CPE: End session
Loading

This allows an ACS to test asynchronous transfer workflows, including delayed execution, successful transfers, failed transfers, and later TransferComplete reporting.

Requirements

  • Node.js >=22 (the entrypoints run as native TypeScript; the dev script uses tsx).
  • Development dependencies from package.json:
    • typescript
    • tsx
    • @types/node

Runtime code is built on native Node.js modules such as http, https, net, crypto, fs, and child_process. There are no runtime dependencies.

Installation & Usage

There are two ways to run cwmp-sim: install it from npm to use it as a tool, or clone the repo to develop it.

Option A — From npm (use it as a CLI)

Run it directly without installing:

npx cwmp-sim --acs http://your-acs:7547/ --serial SIM001

Or install it globally and run the cwmp-sim command:

npm install -g cwmp-sim
cwmp-sim --acs http://your-acs:7547/ --serial SIM001

Use as a library

import { CWMPSimulator } from "cwmp-sim";

const sim = new CWMPSimulator({
  device: {
    rootName: "InternetGatewayDevice",
    serialNumber: "SIM001",
  },
  acs: {
    url: "http://localhost:7547/acs",
    user: "",
    pass: "",
  },
  conn: {
    addr: "0.0.0.0",
    port: 7547,
    user: "",
    pass: "",
  },
});

sim.start();

The npm CLI is configured via CLI options and/or environment variables (ACS_URL, ACS_USER, DEVICE_SERIAL, …) exported in your shell. To load settings from a .env file instead, run the binary through Node's --env-file:

node --env-file=.env "$(npm root -g)/cwmp-sim/dist/main.js"

Option B — From source (development)

git clone https://github.com/softov/cwmp-sim.git
cd cwmp-sim
npm install
cp .env.example .env   # then edit .env for your ACS

Then use the npm scripts:

Command What it does
npm run dev Run main.ts directly via tsx, loading .env.
npm run build Compile TypeScript to dist/.
npm start Run the compiled build: node --env-file=.env ./dist/main.js.
npm run check Type-check only (tsc --noEmit).
npm test Run the unit suite (test/**/*.test.ts).

CLI flags can be passed through the scripts with --, e.g.:

npm run dev -- --acs http://your-acs:7547/ --serial SIM001

Configuration

Configuration can be provided through environment variables (see .env.example) and a small CLI parser.

Environment variables

Variable Description Default
ACS_URL ACS endpoint URL http://localhost:7547/
ACS_USER ACS username empty
ACS_PASS ACS password empty
CONN_ADDR Connection Request bind address 0.0.0.0
CONN_PORT Connection Request port 7547
CONN_USER Connection Request username empty
CONN_PASS Connection Request password empty
DEVICE_ROOT Root model name: Device or InternetGatewayDevice Device
DEVICE_SERIAL Device serial number (supports {i} templating) 123456
DEVICE_OUI Device OUI (supports {i} templating) 000000
DEVICE_MAC Device MAC address (supports {i} templating; injected into the model) empty
DEVICE_INDEX Device index used to resolve {i} in identity fields 0
DEVICE_PRODUCT_CLASS Product class Simulator
DEVICE_CSV CSV path used by the current placeholder export hook ./models/data_model_test.csv
DEVICE_JSON Optional JSON data-model fixture overlaid on the default tree (skipped if missing) ./models/data_model_tests.json
LOG_LEVEL Log verbosity: silent/error/warn/info/debug/trace info

CLI options

npm run dev -- --acs http://acs.example.test:7547/acs --ip 0.0.0.0 --port 7547 --serial SIM001

Supported CLI flags:

  • --acs <url>
  • --ip <address>
  • --port <port>
  • --serial <serial>
  • --mac <mac>
  • --index <n>
  • --log-level <level>

Templated identities

--serial, --oui, and --mac accept a {i} token that resolves against --index (default 0). This makes each simulated device's identity derivable from an index — groundwork for running a fleet.

Token Example (--index 7) Result
{i} SIM-{i} SIM-7
{i:04} SIM-{i:04} SIM-0007 (decimal, zero-padded)
{i+100} {i+100} 107
{i+10:03} dev-{i+10:03} dev-017
{i:02x} C0:FF:EE:00:00:{i:02x} C0:FF:EE:00:00:07 (hex byte)
{i:X} {i:X} 7 (upper-case hex)

A MAC address is six hex bytes (XX:XX:XX:XX:XX:XX), so build it with hex tokens — a bare {i:15} produces a 15-digit decimal string, not a MAC:

npm run dev -- --serial "SIM-{i:08}" --mac "C0:FF:EE:00:00:{i:02x}" --index 7

Logging

cwmp-sim uses a small, dependency-free, level-based logger. Levels from least to most verbose: silent < error < warn < info < debug < trace.

  • As a CLI, logging defaults to info (lifecycle messages). Change it with --log-level <level> or LOG_LEVEL. The raw SOAP envelopes exchanged with the ACS are logged at trace:

    npm run dev -- --log-level trace
  • As a library, logging is silent by default (an import never prints). Configure it via options.log:

    import { CWMPSimulator } from "cwmp-sim";
    
    new CWMPSimulator({
      device: { /* … */ }, acs: { /* … */ }, conn: { /* … */ },
      log: { level: "debug" },           // built-in console logger at this level
      // or bring your own logger:
      // log: { logger: myPinoLogger },   // any { error, warn, info, debug, trace }
    });

Project Structure

cwmp-sim/
├─ main.ts                 # Thin CLI dispatcher
├─ examples/               # Manual scratch/smoke scripts
├─ models/                 # Model fixtures
├─ src/
│  ├─ index.ts             # Public library entry
│  ├─ config/              # Env + CLI option builder (fields, parser, help)
│  ├─ logger.ts            # Level-based logger (silent default; CLI sets info)
│  ├─ cwmp-sim.ts          # Main simulator orchestrator and session lifecycle
│  ├─ cwmp-device.ts       # In-memory CPE data model, state, events, and task queue
│  ├─ cwmp-conn.ts         # Connection Request HTTP server
│  ├─ cwmp-http.ts         # HTTP/HTTPS client with Digest auth and cookie handling
│  ├─ cwmp-methods.ts      # CWMP RPC method implementations
│  ├─ cwmp-soap.ts         # SOAP envelope helpers and CWMP request extraction
│  ├─ cwmp-model.ts        # Default data model helpers and parameter structures
│  ├─ cwmp-task.ts         # Base class for diagnostics and transfer tasks
│  ├─ diag-ping.ts         # IPPing diagnostics
│  ├─ diag-traceroute.ts   # TraceRoute diagnostics
│  ├─ diag-download.ts     # Download diagnostics
│  ├─ diag-upload.ts       # Upload diagnostics
│  ├─ diag-wifi.ts         # Neighboring Wi-Fi diagnostics
│  ├─ task-download.ts     # Download RPC transfer task
│  ├─ task-upload.ts       # Upload RPC transfer task
│  ├─ xml-parser.ts        # Lightweight XML parser
│  ├─ xml-utils.ts         # XML node/fault helpers
│  └─ types.ts             # Shared simulator types
└─ test/                   # *.test.ts unit tests

Status

Experimental.

The project is intended for ACS testing, protocol debugging, and development environments. Behavior may not match every vendor CPE or every edge case from the full TR-069 specification.

Known limitations and the planned roadmap are tracked in PENDING.md.

Testing

Unit tests use the built-in Node.js test runner (node:test / node:assert) and cover the deterministic modules — XML parser/utils, SOAP envelope helpers, model helpers, and the device data model (parameter get/set, read-only enforcement, AddObject/DeleteObject, change listeners):

npm test

The script targets test/**/*.test.ts only. Manual scratch scripts for diagnostics, IGD behavior, and Windows-oriented device information live under examples/ and are intentionally excluded from npm test.

License

BSD-3-Clause. See LICENSE.

About

A TypeScript CWMP/TR-069 CPE simulator for testing ACS sessions, SOAP RPC flows, Digest authentication, diagnostics, file transfers, and Connection Request handling.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Sponsor this project

Packages

Contributors

Languages