[asterisk-commits] tests/rtp/strict rtp: Add test for strict RTP support. (testsuite[master])

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Aug 31 07:58:28 CDT 2017


Jenkins2 has submitted this change and it was merged. ( https://gerrit.asterisk.org/6364 )

Change subject: tests/rtp/strict_rtp: Add test for strict RTP support.
......................................................................

tests/rtp/strict_rtp: Add test for strict RTP support.

This adds a test that sets up a call between two Asterisk
instances with strict RTP enabled and symmetric RTP enabled.
Once media has started flowing a flood of minimal RTP packets
are sent to each instance. If any traffic is received on the
port that the RTP packets were sent from the test fails as
strict RTP protection did not discard the packets.

ASTERISK-27013

Change-Id: Id24462bed062424295d32618658d94ef4209a934
---
A tests/rtp/strict_rtp/configs/ast1/extensions.conf
A tests/rtp/strict_rtp/configs/ast1/pjsip.conf
A tests/rtp/strict_rtp/configs/ast1/rtp.conf
A tests/rtp/strict_rtp/configs/ast2/extensions.conf
A tests/rtp/strict_rtp/configs/ast2/pjsip.conf
A tests/rtp/strict_rtp/configs/ast2/rtp.conf
A tests/rtp/strict_rtp/strict_rtp.py
A tests/rtp/strict_rtp/test-config.yaml
A tests/rtp/tests.yaml
M tests/tests.yaml
10 files changed, 224 insertions(+), 0 deletions(-)

Approvals:
  Joshua Colp: Looks good to me, approved
  Jenkins2: Approved for Submit



diff --git a/tests/rtp/strict_rtp/configs/ast1/extensions.conf b/tests/rtp/strict_rtp/configs/ast1/extensions.conf
new file mode 100644
index 0000000..eabe04d
--- /dev/null
+++ b/tests/rtp/strict_rtp/configs/ast1/extensions.conf
@@ -0,0 +1,15 @@
+
+[default]
+
+; -- Audio Source --
+
+exten => playback,1,NoOp()
+ same => n,Answer()
+ same => n,Playback(tt-monkeys)
+ same => n,Hangup()
+
+; -- Sender --
+
+exten => 1000,1,NoOp()
+ same => n,Dial(PJSIP/ast2)
+ same => n,Hangup()
diff --git a/tests/rtp/strict_rtp/configs/ast1/pjsip.conf b/tests/rtp/strict_rtp/configs/ast1/pjsip.conf
new file mode 100644
index 0000000..c633496
--- /dev/null
+++ b/tests/rtp/strict_rtp/configs/ast1/pjsip.conf
@@ -0,0 +1,19 @@
+[global]
+debug=yes
+
+[local-transport-udp]
+type=transport
+bind=127.0.0.1:5060
+protocol=udp
+
+[ast2]
+type=aor
+contact=sip:ast2 at 127.0.0.2:5060
+
+[ast2]
+type=endpoint
+aors=ast2
+context=default
+allow=!all,ulaw,alaw
+direct_media=no
+rtp_symmetric=yes
diff --git a/tests/rtp/strict_rtp/configs/ast1/rtp.conf b/tests/rtp/strict_rtp/configs/ast1/rtp.conf
new file mode 100644
index 0000000..25f04dd
--- /dev/null
+++ b/tests/rtp/strict_rtp/configs/ast1/rtp.conf
@@ -0,0 +1,4 @@
+[general]
+rtpstart=10000
+rtpend=10002
+strictrtp=yes
diff --git a/tests/rtp/strict_rtp/configs/ast2/extensions.conf b/tests/rtp/strict_rtp/configs/ast2/extensions.conf
new file mode 100644
index 0000000..4848420
--- /dev/null
+++ b/tests/rtp/strict_rtp/configs/ast2/extensions.conf
@@ -0,0 +1,9 @@
+
+[default]
+
+; -- Receiver --
+
+exten => ast2,1,NoOp()
+ same => n,Answer()
+ same => n,Echo()
+
diff --git a/tests/rtp/strict_rtp/configs/ast2/pjsip.conf b/tests/rtp/strict_rtp/configs/ast2/pjsip.conf
new file mode 100644
index 0000000..4db6013
--- /dev/null
+++ b/tests/rtp/strict_rtp/configs/ast2/pjsip.conf
@@ -0,0 +1,24 @@
+[global]
+debug=yes
+
+[local-transport-udp]
+type=transport
+bind=127.0.0.2:5060
+protocol=udp
+
+[ast1]
+type=identify
+endpoint=ast1
+match=127.0.0.1
+
+[ast1]
+type=aor
+contact=sip:ast1 at 127.0.0.1:5060
+
+[ast1]
+type=endpoint
+aors=ast1
+context=default
+allow=!all,ulaw,alaw
+direct_media=no
+rtp_symmetric=yes
diff --git a/tests/rtp/strict_rtp/configs/ast2/rtp.conf b/tests/rtp/strict_rtp/configs/ast2/rtp.conf
new file mode 100644
index 0000000..cb64420
--- /dev/null
+++ b/tests/rtp/strict_rtp/configs/ast2/rtp.conf
@@ -0,0 +1,4 @@
+[general]
+rtpstart=10100
+rtpend=10102
+strictrtp=yes
diff --git a/tests/rtp/strict_rtp/strict_rtp.py b/tests/rtp/strict_rtp/strict_rtp.py
new file mode 100644
index 0000000..a782152
--- /dev/null
+++ b/tests/rtp/strict_rtp/strict_rtp.py
@@ -0,0 +1,96 @@
+"""Strict RTP verification
+
+This module sends a flood of RTP packets to a target and considers the
+test failed if we receive any traffic back.
+
+Copyright (C) 2017, Digium, Inc.
+Joshua Colp <jcolp at digium.com>
+
+This program is free software, distributed under the terms of
+the GNU General Public License Version 2.
+"""
+
+import logging
+from datetime import datetime
+
+from twisted.internet.protocol import DatagramProtocol
+from twisted.internet import reactor
+
+LOGGER = logging.getLogger(__name__)
+
+
+class StrictRtpTester(object):
+    """A pluggable module for verifying the strict RTP functionality"""
+
+    class NoAnswerProtocol(DatagramProtocol):
+        """The twisted NoAnswerProtocol that fails the test if any packets are received
+        """
+
+        def __init__(self, test_object):
+            """Constructor
+
+            Keyword Arguments:
+            test_object Our one and only test object
+            """
+            self.test_object = test_object
+
+        def datagramReceived(self, data, (host, port)):
+            """Callback for when a datagram is received
+
+            Keyword Arguments:
+            data         The actual packet
+            (host, port) Tuple of source host and port
+            """
+            LOGGER.debug('Packet received from {0}:{1}\n{2}'.format(
+                host, port, data))
+
+            self.test_object.set_passed(False)
+
+    def __init__(self, module_config, test_object):
+        """Constructor
+
+        Keyword Arguments:
+        module_config The configuration for this pluggable module
+        test_object   The one and only test object
+        """
+
+        self.packet_count = 8
+
+        # Use the AMI callback to know for sure we are fully booted
+        self.test_object = test_object
+        test_object.register_ami_observer(self.ami_connect_cb)
+
+    def ami_connect_cb(self, ami):
+        """Callback called when AMI connects
+
+        Keyword Arguments:
+        ami The AMI manager object for our Asterisk instance
+        """
+        ami.registerEvent('RTCPReceived', self.rtcp_received_handler)
+
+    def rtcp_received_handler(self, ami, event):
+        """RTCPReceived callback
+
+        Keyword Arguments:
+        ami   The AMI protocol instance
+        event The Newchannel event
+        """
+        if event['sentpackets'] != '250':
+            return
+
+        self.test_object.set_passed(True)
+        protocol = StrictRtpTester.NoAnswerProtocol(self.test_object)
+        reactor.listenUDP(0, protocol)
+
+        # Determine the target of the packets from the RTCPReceived event
+        (host, port) = event["to"].split(":")
+
+        # Construct a minimal RTP header by setting the version to 2
+        header = bytearray(12)
+        header[0] = (2 << 6) & 0xC0
+
+        for packet in range(self.packet_count):
+            # Set the sequence number to the packet number
+            header[2] = (packet & 0xFF00) >> 8
+            header[3] = (packet & 0xFF)
+            protocol.transport.write(header, (host, int(port) - 1))
diff --git a/tests/rtp/strict_rtp/test-config.yaml b/tests/rtp/strict_rtp/test-config.yaml
new file mode 100644
index 0000000..e5d3c88
--- /dev/null
+++ b/tests/rtp/strict_rtp/test-config.yaml
@@ -0,0 +1,49 @@
+testinfo:
+    summary: 'Verify the strict RTP functionality of the RTP stack'
+    description: |
+        This test verifies that during a call with strict RTP and symmetric RTP
+        enabled that the act of sending multiple RTP packets at the same time
+        does not cause media to be taken away from the existing target. The test
+        listens for RTCP events which indicate media is flowing. The target RTP
+        address information is extracted from these and multiple basic RTP packets
+        sent. If any UDP traffic is received on the port that the packets were
+        sent from the test fails. If no packets are received the test passes.
+
+test-modules:
+    add-test-to-search-path: True
+    test-object:
+        config-section: test-object-config
+        typename: 'test_case.TestCaseModule'
+    modules:
+        -
+            typename: 'pluggable_modules.Originator'
+            config-section: originator-config
+        -
+            config-section: 'hangup-monitor'
+            typename: 'pluggable_modules.HangupMonitor'
+        -
+            typename: 'strict_rtp.StrictRtpTester'
+            config-section: dummy-config
+
+test-object-config:
+    asterisk-instances: 2
+    connect-ami: True
+
+hangup-monitor:
+    ids: '0'
+
+originator-config:
+    channel: 'Local/1000 at default'
+    exten: 'playback'
+    context: 'default'
+    priority: 1
+    async: True
+    trigger: 'ami_connect'
+    async: True
+
+dummy-config:
+
+properties:
+    minversion: '13.16.1'
+    dependencies:
+        - asterisk : 'chan_pjsip'
diff --git a/tests/rtp/tests.yaml b/tests/rtp/tests.yaml
new file mode 100644
index 0000000..4a5db65
--- /dev/null
+++ b/tests/rtp/tests.yaml
@@ -0,0 +1,3 @@
+# Enter tests here in the order they should be considered for execution:
+tests:
+    - test: 'strict_rtp'
diff --git a/tests/tests.yaml b/tests/tests.yaml
index e3a0b07..9d7ef0f 100644
--- a/tests/tests.yaml
+++ b/tests/tests.yaml
@@ -37,3 +37,4 @@
     - dir: 'sorcery'
     - test: 'remote-test'
     - dir: 'codecs'
+    - dir: 'rtp'

-- 
To view, visit https://gerrit.asterisk.org/6364
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-Project: testsuite
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: Id24462bed062424295d32618658d94ef4209a934
Gerrit-Change-Number: 6364
Gerrit-PatchSet: 1
Gerrit-Owner: Joshua Colp <jcolp at digium.com>
Gerrit-Reviewer: Jenkins2
Gerrit-Reviewer: Joshua Colp <jcolp at digium.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-commits/attachments/20170831/7bd1cd46/attachment-0001.html>


More information about the asterisk-commits mailing list