[Asterisk-code-review] strict rtp: Added test for strictrtp option 'seqno'. (testsuite[16])

Joshua Colp asteriskteam at digium.com
Tue Oct 2 05:32:55 CDT 2018


Joshua Colp has submitted this change and it was merged. ( https://gerrit.asterisk.org/10306 )

Change subject: strict_rtp: Added test for strictrtp option 'seqno'.
......................................................................

strict_rtp: Added test for strictrtp option 'seqno'.

This test verifies the functionality of the new option 'seqno' for
strictrtp. A channel is started up in the Echo application, which then
triggers a burst of packets from the test. The packets will continue to
be bursted to the target until strict RTP learns the source, which then
fires off another event that will send a packet from a different source.
The test passes if the packet from the source we did not learn is
dropped. The difference between this test and the existing test is that
it checks to see if the time interval during learning for receiving
packets is ignored, hence the bursts and not a normal call scenario.

Also added a new directory to account for multiple strictrtp tests.

Change-Id: I0067bb11793f97423752aef04c8716841a7ad0d9
---
A tests/rtp/strict_rtp/strict_rtp_seqno/configs/ast1/extensions.conf
A tests/rtp/strict_rtp/strict_rtp_seqno/configs/ast1/pjsip.conf
A tests/rtp/strict_rtp/strict_rtp_seqno/configs/ast1/rtp.conf
A tests/rtp/strict_rtp/strict_rtp_seqno/sipp/call_setup.xml
A tests/rtp/strict_rtp/strict_rtp_seqno/strict_rtp.py
A tests/rtp/strict_rtp/strict_rtp_seqno/test-config.yaml
R tests/rtp/strict_rtp/strict_rtp_yes/configs/ast1/extensions.conf
R tests/rtp/strict_rtp/strict_rtp_yes/configs/ast1/pjsip.conf
R tests/rtp/strict_rtp/strict_rtp_yes/configs/ast1/rtp.conf
R tests/rtp/strict_rtp/strict_rtp_yes/configs/ast2/extensions.conf
R tests/rtp/strict_rtp/strict_rtp_yes/configs/ast2/pjsip.conf
R tests/rtp/strict_rtp/strict_rtp_yes/configs/ast2/rtp.conf
R tests/rtp/strict_rtp/strict_rtp_yes/strict_rtp.py
R tests/rtp/strict_rtp/strict_rtp_yes/test-config.yaml
A tests/rtp/strict_rtp/tests.yaml
M tests/rtp/tests.yaml
16 files changed, 272 insertions(+), 1 deletion(-)

Approvals:
  Joshua Colp: Looks good to me, but someone else must approve; Approved for Submit
  Kevin Harwell: Looks good to me, approved



diff --git a/tests/rtp/strict_rtp/strict_rtp_seqno/configs/ast1/extensions.conf b/tests/rtp/strict_rtp/strict_rtp_seqno/configs/ast1/extensions.conf
new file mode 100644
index 0000000..6199b22
--- /dev/null
+++ b/tests/rtp/strict_rtp/strict_rtp_seqno/configs/ast1/extensions.conf
@@ -0,0 +1,6 @@
+[default]
+
+exten => echo,1,NoOp()
+ same => n,Answer()
+ same => n,Echo()
+ same => n,Hangup()
diff --git a/tests/rtp/strict_rtp/strict_rtp_seqno/configs/ast1/pjsip.conf b/tests/rtp/strict_rtp/strict_rtp_seqno/configs/ast1/pjsip.conf
new file mode 100644
index 0000000..bef6c2f
--- /dev/null
+++ b/tests/rtp/strict_rtp/strict_rtp_seqno/configs/ast1/pjsip.conf
@@ -0,0 +1,19 @@
+[global]
+type=global
+debug=yes
+
+[local]
+type=transport
+bind=0.0.0.0
+protocol=udp
+
+[alice]
+type=endpoint
+context=default
+allow=!all,ulaw
+transport=local
+direct_media=no
+
+[alice]
+type=aor
+contact=sip:alice at 127.0.0.1:5061
diff --git a/tests/rtp/strict_rtp/strict_rtp_seqno/configs/ast1/rtp.conf b/tests/rtp/strict_rtp/strict_rtp_seqno/configs/ast1/rtp.conf
new file mode 100644
index 0000000..4d49874
--- /dev/null
+++ b/tests/rtp/strict_rtp/strict_rtp_seqno/configs/ast1/rtp.conf
@@ -0,0 +1,4 @@
+[general]
+rtpstart=10000
+rtpend=10002
+strictrtp=seqno
diff --git a/tests/rtp/strict_rtp/strict_rtp_seqno/sipp/call_setup.xml b/tests/rtp/strict_rtp/strict_rtp_seqno/sipp/call_setup.xml
new file mode 100644
index 0000000..ab6ee31
--- /dev/null
+++ b/tests/rtp/strict_rtp/strict_rtp_seqno/sipp/call_setup.xml
@@ -0,0 +1,81 @@
+<?xml version="1.0" encoding="ISO-8859-1" ?>
+<!DOCTYPE scenario SYSTEM "sipp.dtd">
+
+<scenario name="INVITE to echo with SDP in initial INVITE">
+  <send retrans="500">
+    <![CDATA[
+
+      INVITE sip:echo@[remote_ip]:[remote_port] SIP/2.0
+      Via: SIP/2.0/[transport] [local_ip]:[local_port];branch=[branch]
+      From: test1 <sip:[service]@[local_ip]:[local_port]>;tag=[call_number]
+      To: test <sip:test@[remote_ip]:[remote_port]>
+      Call-ID: [call_id]
+      CSeq: 1 INVITE
+      Contact: <sip:test@[local_ip]:[local_port];transport=[transport]>
+      Max-Forwards: 70
+      Subject: Test
+      User-Agent: Test
+      Content-Type: application/sdp
+      Content-Length: [len]
+
+      v=0
+      o=phoneA 53655765 2353687637 IN IP[local_ip_type] [local_ip]
+      s=-
+      c=IN IP[media_ip_type] [media_ip]
+      t=0 0
+      m=audio 6000 RTP/AVP 0
+      a=rtpmap:0 PCMU/8000
+
+    ]]>
+  </send>
+
+  <recv response="100"
+        optional="true">
+  </recv>
+
+  <recv response="200" rtd="true">
+  </recv>
+
+  <send>
+    <![CDATA[
+
+      ACK sip:echo@[remote_ip]:[remote_port] SIP/2.0
+      Via: SIP/2.0/[transport] [local_ip]:[local_port];branch=[branch]
+      From: test1 <sip:[service]@[local_ip]:[local_port]>;tag=[call_number]
+      To: test <sip:test@[remote_ip]:[remote_port]>[peer_tag_param]
+      Call-ID: [call_id]
+      CSeq: 1 ACK
+      Contact: <sip:test@[local_ip]:[local_port];transport=[transport]>
+      Max-Forwards: 70
+      Subject: Test
+      Content-Length: 0
+
+    ]]>
+  </send>
+
+  <recv request="BYE">
+  </recv>
+
+  <send>
+    <![CDATA[
+
+      SIP/2.0 200 OK
+      [last_Via:]
+      [last_From:]
+      [last_To:]
+      [last_Call-ID:]
+      [last_CSeq:]
+      Contact: <sip:[local_ip]:[local_port];transport=[transport]>
+      Content-Length: 0
+
+    ]]>
+  </send>
+
+  <!-- definition of the response time repartition table (unit is ms)   -->
+  <ResponseTimeRepartition value="10, 20, 30, 40, 50, 100, 150, 200"/>
+
+  <!-- definition of the call length repartition table (unit is ms)     -->
+  <CallLengthRepartition value="10, 50, 100, 500, 1000, 5000, 10000"/>
+
+</scenario>
+
diff --git a/tests/rtp/strict_rtp/strict_rtp_seqno/strict_rtp.py b/tests/rtp/strict_rtp/strict_rtp_seqno/strict_rtp.py
new file mode 100644
index 0000000..ea58956
--- /dev/null
+++ b/tests/rtp/strict_rtp/strict_rtp_seqno/strict_rtp.py
@@ -0,0 +1,125 @@
+"""Strict RTP verification
+
+This module sends a flood of RTP packets to a target after SIPP starts a
+call in order to have Asterisk lock on to a new target address. It will also
+send a packet after the target has been locked onto and considers the test
+a success if that packet is denied.
+
+Copyright (C) 2018, Digium, Inc.
+Ben Ford <bford 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
+from twisted.internet import task
+
+LOGGER = logging.getLogger(__name__)
+
+class StrictRtpTester(object):
+    """A pluggable module for verifying strictrtp seqno functionality"""
+
+    class PacketSendProtocol(DatagramProtocol):
+        """The twisted protocol that sends packets
+        """
+
+        def __init__(self, test_object):
+            """Constructor
+            """
+            self.test_object = test_object
+
+        def datagramReceived(self, data, (host, port)):
+            """Callback for when a datagram is received.
+            We don't want anything to happen here because we do all
+            of the handling ourselves via TestEvent.
+
+            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))
+
+    def __init__(self, module_config, test_object):
+        """Constructor
+
+        Keyword Arguments:
+        module_config   The configuration for this pluggable module
+        test_object     Our test object
+        """
+        self.send_num = 1
+        self.send_task = None
+
+        # Use the AMI callback to know when we are fully booted
+        self.test_object = test_object
+        test_object.register_ami_observer(self.ami_connect_cb)
+
+    def send_packets(self, protocol, num):
+        """Send packets to endpoint
+        """
+        idx = 1
+        header = bytearray(12)
+        header[0] = (2 << 6) & 0xC0
+        while idx <= num:
+            header[2] = (self.send_num & 0xFF00) >> 8
+            header[3] = (self.send_num & 0xFF)
+            protocol.transport.write(header, ('127.0.0.1', 10000))
+            self.send_num = self.send_num + 1
+            idx = idx + 1
+
+    def ami_connect_cb(self, ami):
+        """Callback called when AMI connects
+
+        Keyword Arguments:
+        ami The AMI manager object for our Asterisk instance
+        """
+        ami.registerEvent('TestEvent', self.test_event_handler)
+        ami.registerEvent('Newexten', self.new_exten_handler)
+
+    def test_event_handler(self, ami, event):
+        """TestEvent handler
+
+        Keyword Arguments:
+        ami     The AMI protocol instance
+        event   The TestEvent
+        """
+        if event['state'] == 'STRICT_RTP_LEARN':
+            if event['source'] != '127.0.0.1:6000':
+                LOGGER.debug("Failure: Strict RTP did not lock on to source 127.0.0.1:6000")
+                self.test_object.set_passed(False)
+                ami.hangup(self.channel)
+                return
+            self.send_task.stop()
+            protocol = StrictRtpTester.PacketSendProtocol(self.test_object)
+            reactor.listenUDP(6001, protocol)
+            self.send_packets(protocol, 1)
+        elif event['state'] == 'STRICT_RTP_CLOSED':
+            if event['source'] != '127.0.0.1:6001':
+                LOGGER.debug("Failure: Strict RTP dropped packet from source other than 127.0.0.1:6001")
+                self.test_object.set_passed(False)
+            else:
+                self.test_object.set_passed(True)
+            ami.hangup(self.channel)
+
+    def new_exten_handler(self, ami, event):
+        """NewExten handler
+
+        Keyword Arguments:
+        ami     The AMI protocol instance
+        event   The Newexten event
+        """
+        def errback(err):
+            LOGGER.error(err)
+
+        if event['application'] != 'Echo':
+            return
+        self.channel = event['channel']
+        protocol = StrictRtpTester.PacketSendProtocol(self.test_object)
+        reactor.listenUDP(6000, protocol)
+        self.send_task = task.LoopingCall(self.send_packets, protocol, 20)
+        deferred = self.send_task.start(1.0)
+        deferred.addErrback(errback)
diff --git a/tests/rtp/strict_rtp/strict_rtp_seqno/test-config.yaml b/tests/rtp/strict_rtp/strict_rtp_seqno/test-config.yaml
new file mode 100644
index 0000000..8c12073
--- /dev/null
+++ b/tests/rtp/strict_rtp/strict_rtp_seqno/test-config.yaml
@@ -0,0 +1,32 @@
+testinfo:
+    summary: 'Verify strictrtp set to seqno ignores strictrtp time interval'
+    description: |
+        This test verifies that when strictrtp is set to seqno, Asterisk is
+        able to lock on to the target address, even if there is a burst of
+        packets during the learning period. It also ensures that packets from
+        other sources are dropped after we lock on to our target address.
+
+test-modules:
+    add-test-to-search-path: True
+    test-object:
+        config-section: 'test-object-config'
+        typename: 'sipp.SIPpTestCase'
+    modules:
+        -
+            config-section: 'dummy-config'
+            typename: 'strict_rtp.StrictRtpTester'
+
+test-object-config:
+    memcheck-delay-stop: 7
+    test-iterations:
+        -
+            scenarios:
+                - { 'key-args': {'scenario': 'call_setup.xml', '-i': '127.0.0.1', '-p': '5061', '-s': 'alice'} }
+
+dummy-config:
+
+properties:
+    dependencies:
+        - app : 'sipp'
+        - asterisk : 'app_echo'
+        - asterisk : 'res_pjsip'
diff --git a/tests/rtp/strict_rtp/configs/ast1/extensions.conf b/tests/rtp/strict_rtp/strict_rtp_yes/configs/ast1/extensions.conf
similarity index 100%
rename from tests/rtp/strict_rtp/configs/ast1/extensions.conf
rename to tests/rtp/strict_rtp/strict_rtp_yes/configs/ast1/extensions.conf
diff --git a/tests/rtp/strict_rtp/configs/ast1/pjsip.conf b/tests/rtp/strict_rtp/strict_rtp_yes/configs/ast1/pjsip.conf
similarity index 100%
rename from tests/rtp/strict_rtp/configs/ast1/pjsip.conf
rename to tests/rtp/strict_rtp/strict_rtp_yes/configs/ast1/pjsip.conf
diff --git a/tests/rtp/strict_rtp/configs/ast1/rtp.conf b/tests/rtp/strict_rtp/strict_rtp_yes/configs/ast1/rtp.conf
similarity index 100%
rename from tests/rtp/strict_rtp/configs/ast1/rtp.conf
rename to tests/rtp/strict_rtp/strict_rtp_yes/configs/ast1/rtp.conf
diff --git a/tests/rtp/strict_rtp/configs/ast2/extensions.conf b/tests/rtp/strict_rtp/strict_rtp_yes/configs/ast2/extensions.conf
similarity index 100%
rename from tests/rtp/strict_rtp/configs/ast2/extensions.conf
rename to tests/rtp/strict_rtp/strict_rtp_yes/configs/ast2/extensions.conf
diff --git a/tests/rtp/strict_rtp/configs/ast2/pjsip.conf b/tests/rtp/strict_rtp/strict_rtp_yes/configs/ast2/pjsip.conf
similarity index 100%
rename from tests/rtp/strict_rtp/configs/ast2/pjsip.conf
rename to tests/rtp/strict_rtp/strict_rtp_yes/configs/ast2/pjsip.conf
diff --git a/tests/rtp/strict_rtp/configs/ast2/rtp.conf b/tests/rtp/strict_rtp/strict_rtp_yes/configs/ast2/rtp.conf
similarity index 100%
rename from tests/rtp/strict_rtp/configs/ast2/rtp.conf
rename to tests/rtp/strict_rtp/strict_rtp_yes/configs/ast2/rtp.conf
diff --git a/tests/rtp/strict_rtp/strict_rtp.py b/tests/rtp/strict_rtp/strict_rtp_yes/strict_rtp.py
similarity index 100%
rename from tests/rtp/strict_rtp/strict_rtp.py
rename to tests/rtp/strict_rtp/strict_rtp_yes/strict_rtp.py
diff --git a/tests/rtp/strict_rtp/test-config.yaml b/tests/rtp/strict_rtp/strict_rtp_yes/test-config.yaml
similarity index 100%
rename from tests/rtp/strict_rtp/test-config.yaml
rename to tests/rtp/strict_rtp/strict_rtp_yes/test-config.yaml
diff --git a/tests/rtp/strict_rtp/tests.yaml b/tests/rtp/strict_rtp/tests.yaml
new file mode 100644
index 0000000..9becafb
--- /dev/null
+++ b/tests/rtp/strict_rtp/tests.yaml
@@ -0,0 +1,4 @@
+# Enter tests here in the order they should be considered for execution:
+tests:
+    - test: 'strict_rtp_seqno'
+    - test: 'strict_rtp_yes'
diff --git a/tests/rtp/tests.yaml b/tests/rtp/tests.yaml
index 4a5db65..3ff1e44 100644
--- a/tests/rtp/tests.yaml
+++ b/tests/rtp/tests.yaml
@@ -1,3 +1,3 @@
 # Enter tests here in the order they should be considered for execution:
 tests:
-    - test: 'strict_rtp'
+    - dir: 'strict_rtp'

-- 
To view, visit https://gerrit.asterisk.org/10306
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: testsuite
Gerrit-Branch: 16
Gerrit-MessageType: merged
Gerrit-Change-Id: I0067bb11793f97423752aef04c8716841a7ad0d9
Gerrit-Change-Number: 10306
Gerrit-PatchSet: 1
Gerrit-Owner: Benjamin Keith Ford <bford at digium.com>
Gerrit-Reviewer: Jenkins2 (1000185)
Gerrit-Reviewer: Joshua Colp <jcolp at digium.com>
Gerrit-Reviewer: Kevin Harwell <kharwell at digium.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20181002/8d0e542c/attachment-0001.html>


More information about the asterisk-code-review mailing list