Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
load => res_pjsip_maintenance.so
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[system]
type=system
timer_t1=100
timer_b=6400

[global]
type=global
debug=yes

[local]
type=transport
protocol=udp
bind=0.0.0.0

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

; Endpoint "alice" exists only so that PJSIPSetMaintenance can validate
; it via ast_sorcery_retrieve_by_id. No calls are made in this test.
[alice]
type=endpoint
transport=local
context=default
disallow=all
allow=ulaw
82 changes: 82 additions & 0 deletions tests/channels/pjsip/maintenance/ami_actions/test-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
testinfo:
summary: 'Test PJSIPSetMaintenance and PJSIPShowMaintenance AMI actions'
description: |
Verifies the full AMI control plane for res_pjsip_maintenance:

* PJSIPSetMaintenance State: on emits PJSIPMaintenanceStatus (enabled)
* PJSIPShowMaintenance returns a PJSIPMaintenanceStatus list entry
followed by PJSIPMaintenanceStatusComplete

Sequence:
1. On AMI connect, fire PJSIPSetMaintenance for endpoint "alice".
2. The resulting PJSIPMaintenanceStatus (enabled) notification triggers
PJSIPShowMaintenance (with a known ActionID). trigger-on-count
ensures this fires exactly once even though Show itself also emits
a PJSIPMaintenanceStatus event.
3. The test stops when PJSIPMaintenanceStatusComplete arrives with the
expected ActionID.

test-modules:
test-object:
config-section: object-config
typename: 'test_case.TestCaseModule'
modules:
-
config-section: ami-config
typename: 'pluggable_modules.EventActionModule'

object-config:
reactor-timeout: 15
connect-ami: True

ami-config:
# Step 1: enable maintenance for "alice" via AMI
-
ami-start:
ami-actions:
action:
Action: 'PJSIPSetMaintenance'
Endpoint: 'alice'
State: 'on'

# Step 2: when the State change notification event arrives, trigger
# PJSIPShowMaintenance. trigger-on-count: True with count: '>1' (min=1)
# ensures the action fires only on the *first* matching event
# (count['event'] == min == 1); subsequent events - including the
# PJSIPMaintenanceStatus emitted by the Show list response itself - do
# not re-trigger the action (count==2, not equal to min==1).
# count: '>1' (at-least-1) also keeps the end-of-test count check happy
# when two matching events total have been received.
-
ami-events:
conditions:
match:
Event: 'PJSIPMaintenanceStatus'
Status: 'enabled'
Endpoint: 'alice'
count: '>1'
trigger-on-count: True
ami-actions:
action:
Action: 'PJSIPShowMaintenance'
Endpoint: 'alice'
ActionID: 'maint-show-01'

# Step 3: stop (pass) when the Show list-complete event arrives
-
ami-events:
conditions:
match:
Event: 'PJSIPMaintenanceStatusComplete'
requirements:
match:
ActionID: 'maint-show-01'
count: 1
stop_test:

properties:
dependencies:
- asterisk: 'res_pjsip'
- asterisk: 'res_pjsip_maintenance'
tags:
- pjsip
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[default]
; This dialplan is not reached during a maintenance-mode test; the
; PJSIP maintenance module rejects the INVITE with 503 before Asterisk
; ever matches a dialplan extension. The context is required by the
; endpoint configuration.
exten => alice,1,Answer()
same => n,Wait(1)
same => n,Hangup()
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
load => res_pjsip_maintenance.so
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
[system]
type=system
timer_t1=100
timer_b=6400

[global]
type=global
debug=yes

[local]
type=transport
protocol=udp
bind=0.0.0.0

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

[alice]
type=endpoint
transport=local
context=default
direct_media=no
disallow=all
allow=ulaw

[alice-identify]
type=identify
endpoint=alice
match=127.0.0.1
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE scenario SYSTEM "sipp.dtd">

<!-- UAC scenario: send an INVITE and expect a 503 Service Unavailable.
A brief pause at the start ensures the AMI PJSIPSetMaintenance action
has been processed before the request reaches Asterisk. -->
<scenario name="INVITE expecting 503 Service Unavailable">

<!-- Wait long enough for the AMI action to enable maintenance mode -->
<pause milliseconds="2000"/>

<send retrans="500">
<![CDATA[

INVITE sip:[service]@[remote_ip]:[remote_port] SIP/2.0
Via: SIP/2.0/[transport] [local_ip]:[local_port];branch=[branch]
From: alice <sip:[service]@[local_ip]:[local_port]>;tag=[call_number]
To: asterisk <sip:[service]@[remote_ip]:[remote_port]>
Call-ID: [call_id]
CSeq: 1 INVITE
Contact: <sip:[service]@[local_ip]:[local_port];transport=[transport]>
Max-Forwards: 70
Subject: Maintenance Test
Content-Length: 0

]]>
</send>

<recv response="100" optional="true"/>

<recv response="503">
</recv>

<send>
<![CDATA[

ACK sip:[service]@[remote_ip]:[remote_port] SIP/2.0
Via: SIP/2.0/[transport] [local_ip]:[local_port];branch=[branch]
From: alice <sip:[service]@[local_ip]:[local_port]>;tag=[call_number]
To: asterisk <sip:[service]@[remote_ip]:[remote_port]>[peer_tag_param]
Call-ID: [call_id]
CSeq: 1 ACK
Contact: <sip:[service]@[local_ip]:[local_port];transport=[transport]>
Max-Forwards: 70
Content-Length: 0

]]>
</send>

<ResponseTimeRepartition value="10, 20, 30, 40, 50, 100, 150, 200"/>
<CallLengthRepartition value="10, 50, 100, 500, 1000, 5000, 10000"/>

</scenario>
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
testinfo:
summary: 'Test res_pjsip_maintenance rejects inbound INVITE with 503'
description: |
Places a PJSIP endpoint into maintenance mode via the AMI
PJSIPSetMaintenance action and verifies that a new inbound INVITE
from that endpoint is rejected with "503 Service Unavailable".
The SIPp scenario pauses briefly after startup to allow the AMI
action to complete before sending the INVITE.

test-modules:
test-object:
config-section: test-object-config
typename: 'sipp.SIPpAMIActionTestCase'

test-object-config:
memcheck-delay-stop: 7
reactor-timeout: 30
fail-on-any: True
test-iterations:
-
scenarios:
- { 'key-args': { 'scenario': 'invite_expect_503.xml',
'-i': '127.0.0.1', '-p': '5061',
'-s': 'alice' } }
ami-action:
delay: 0
args:
Action: 'PJSIPSetMaintenance'
Endpoint: 'alice'
State: 'on'

properties:
dependencies:
- sipp:
version: 'v3.0'
- asterisk: 'res_pjsip'
- asterisk: 'res_pjsip_maintenance'
tags:
- pjsip
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
load => res_pjsip_maintenance.so
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[system]
type=system
timer_t1=100
timer_b=6400

[global]
type=global
debug=yes

[local]
type=transport
protocol=udp
bind=0.0.0.0

; Endpoint "alice" - no registered contact is needed. The session_create
; supplement check in ast_sip_session_create_outgoing() fires before any
; contact or AOR lookup, so the origination is refused immediately.
[alice]
type=endpoint
transport=local
context=default
disallow=all
allow=ulaw
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
testinfo:
summary: 'Test res_pjsip_maintenance blocks outbound origination'
description: |
Places a PJSIP endpoint into maintenance mode via the AMI
PJSIPSetMaintenance action and verifies that an outbound origination
to that endpoint via AMI Originate is refused before any SIP session
is created.

Sequence:
1. On AMI connect, enable maintenance for endpoint "alice".
2. On PJSIPMaintenanceStatus (enabled), fire an async AMI Originate
to PJSIP/alice with a known ActionID.
3. The test passes when OriginateResponse arrives with
Response: Failure for that ActionID, confirming the channel was
never created.

test-modules:
test-object:
config-section: object-config
typename: 'test_case.TestCaseModule'
modules:
-
config-section: ami-config
typename: 'pluggable_modules.EventActionModule'

object-config:
reactor-timeout: 15
connect-ami: True

ami-config:
# Step 1: enable maintenance for "alice" via AMI
-
ami-start:
ami-actions:
action:
Action: 'PJSIPSetMaintenance'
Endpoint: 'alice'
State: 'on'

# Step 2: once maintenance is confirmed, attempt an outbound origination
-
ami-events:
conditions:
match:
Event: 'PJSIPMaintenanceStatus'
Status: 'enabled'
Endpoint: 'alice'
count: 1
ami-actions:
action:
Action: 'Originate'
Channel: 'PJSIP/alice'
Context: 'default'
Exten: 's'
Priority: '1'
Async: 'yes'
ActionID: 'maint-outbound-01'

# Step 3: stop (pass) when the origination fails as expected
-
ami-events:
conditions:
match:
Event: 'OriginateResponse'
Response: 'Failure'
requirements:
match:
ActionID: 'maint-outbound-01'
count: 1
stop_test:

properties:
dependencies:
- asterisk: 'res_pjsip'
- asterisk: 'res_pjsip_maintenance'
tags:
- pjsip
4 changes: 4 additions & 0 deletions tests/channels/pjsip/maintenance/tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
tests:
- test: 'inbound_rejection'
- test: 'ami_actions'
- test: 'outbound_blocking'
1 change: 1 addition & 0 deletions tests/channels/pjsip/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ tests:
- dir: 'history_info'
- dir: 'headers'
- dir: 'identify'
- dir: 'maintenance'
- dir: 'mediasec'
- dir: 'message'
- dir: 'nat'
Expand Down
Loading