[asterisk-commits] wdoekes: testsuite/asterisk/trunk r5709 - in /asterisk/trunk/tests/channels/S...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Oct 10 02:25:26 CDT 2014


Author: wdoekes
Date: Fri Oct 10 02:25:08 2014
New Revision: 5709

URL: http://svnview.digium.com/svn/testsuite?view=rev&rev=5709
Log:
Test chan_sip dialog leak reported in ASTERISK-20784.

Under the right circumstances, a leg never gets destroyed, resulting in
file leaks and other nastiness.

Fix committed in asterisk 1.8 r425068.

Added:
    asterisk/trunk/tests/channels/SIP/no_ack_dialog_cleanup/
    asterisk/trunk/tests/channels/SIP/no_ack_dialog_cleanup/configs/
    asterisk/trunk/tests/channels/SIP/no_ack_dialog_cleanup/configs/ast1/
    asterisk/trunk/tests/channels/SIP/no_ack_dialog_cleanup/configs/ast1/extensions.conf   (with props)
    asterisk/trunk/tests/channels/SIP/no_ack_dialog_cleanup/configs/ast1/sip.conf   (with props)
    asterisk/trunk/tests/channels/SIP/no_ack_dialog_cleanup/run-test   (with props)
    asterisk/trunk/tests/channels/SIP/no_ack_dialog_cleanup/sipp/
    asterisk/trunk/tests/channels/SIP/no_ack_dialog_cleanup/sipp/alice.xml   (with props)
    asterisk/trunk/tests/channels/SIP/no_ack_dialog_cleanup/sipp/bob.xml   (with props)
    asterisk/trunk/tests/channels/SIP/no_ack_dialog_cleanup/test-config.yaml   (with props)
Modified:
    asterisk/trunk/tests/channels/SIP/tests.yaml

Added: asterisk/trunk/tests/channels/SIP/no_ack_dialog_cleanup/configs/ast1/extensions.conf
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/channels/SIP/no_ack_dialog_cleanup/configs/ast1/extensions.conf?view=auto&rev=5709
==============================================================================
--- asterisk/trunk/tests/channels/SIP/no_ack_dialog_cleanup/configs/ast1/extensions.conf (added)
+++ asterisk/trunk/tests/channels/SIP/no_ack_dialog_cleanup/configs/ast1/extensions.conf Fri Oct 10 02:25:08 2014
@@ -1,0 +1,2 @@
+[default]
+exten => bob,1,Dial(SIP/bob)

Propchange: asterisk/trunk/tests/channels/SIP/no_ack_dialog_cleanup/configs/ast1/extensions.conf
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: asterisk/trunk/tests/channels/SIP/no_ack_dialog_cleanup/configs/ast1/extensions.conf
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: asterisk/trunk/tests/channels/SIP/no_ack_dialog_cleanup/configs/ast1/extensions.conf
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: asterisk/trunk/tests/channels/SIP/no_ack_dialog_cleanup/configs/ast1/sip.conf
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/channels/SIP/no_ack_dialog_cleanup/configs/ast1/sip.conf?view=auto&rev=5709
==============================================================================
--- asterisk/trunk/tests/channels/SIP/no_ack_dialog_cleanup/configs/ast1/sip.conf (added)
+++ asterisk/trunk/tests/channels/SIP/no_ack_dialog_cleanup/configs/ast1/sip.conf Fri Oct 10 02:25:08 2014
@@ -1,0 +1,19 @@
+[general]
+udpbindaddr=127.0.0.1:5060
+; debugging is nice
+sipdebug=yes
+; don't do any re-invites, it messes up our scenario
+directmedia=no
+; wait 3.2 seconds to timeout retransmitting 200 to re-invite
+; instead of 32 seconds
+timert1=50
+
+[alice]
+host=127.0.0.1
+port=5062
+type=friend
+
+[bob]
+host=127.0.0.1
+port=5063
+type=friend

Propchange: asterisk/trunk/tests/channels/SIP/no_ack_dialog_cleanup/configs/ast1/sip.conf
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: asterisk/trunk/tests/channels/SIP/no_ack_dialog_cleanup/configs/ast1/sip.conf
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: asterisk/trunk/tests/channels/SIP/no_ack_dialog_cleanup/configs/ast1/sip.conf
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: asterisk/trunk/tests/channels/SIP/no_ack_dialog_cleanup/run-test
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/channels/SIP/no_ack_dialog_cleanup/run-test?view=auto&rev=5709
==============================================================================
--- asterisk/trunk/tests/channels/SIP/no_ack_dialog_cleanup/run-test (added)
+++ asterisk/trunk/tests/channels/SIP/no_ack_dialog_cleanup/run-test Fri Oct 10 02:25:08 2014
@@ -1,0 +1,156 @@
+#!/usr/bin/env python
+'''
+Copyright (C) 2014, Digium, Inc.
+Walter Doekes <walter+asterisk at wjd.nu>
+
+This program is free software, distributed under the terms of
+the GNU General Public License Version 2.
+
+
+Bug ASTERISK-20784:
+
+    A INVITE> asterisk INVITE> B
+    A <200 OK asterisk <200 OK B
+    A -ACK--> asterisk -ACK--> B
+              asterisk <INVITE B
+              asterisk 200 OK> B
+                      (ack lost)
+    A -BYE--> asterisk
+    A <200 OK asterisk
+
+At this point the B leg retransmit the 200 to the INVITE and finally
+leaks a dialog object.  Or at least, it did until this bug was fixed.
+
+We cannot just use the yaml-based sipp.SIPpTestCase config, because
+we need to extract a bit of extra info from Asterisk after the
+scenario's complete.
+'''
+
+import logging
+import os
+import sys
+import time
+
+sys.path.append("lib/python")
+sys.path.append("utils")
+
+from twisted.internet import reactor
+from asterisk.sipp import SIPpTest
+
+WORKING_DIR = os.path.abspath(os.path.dirname(__file__))
+TEST_DIR = os.path.dirname(os.path.realpath(__file__))
+
+LOGGER = logging.getLogger(__name__)
+
+
+class MySIPpTest(SIPpTest):
+    def __init__(self):
+        # A list of jobs to complete before stopping completely. This
+        # list is extended during the stoppage.
+        self.stop_jobs = [self.get_sleep,
+                          self.get_channels,
+                          self.get_sip_objects]
+
+        SIPP_SCENARIOS = [
+            {'scenario': 'bob.xml',
+             '-p': '5063',
+             '-default_behaviors': '-bye'},
+            {'scenario': 'alice.xml',
+             '-p': '5062',
+             '-s': 'bob',
+             '-default_behaviors': '-bye'},
+        ]
+
+        super(MySIPpTest, self).__init__(WORKING_DIR, TEST_DIR, SIPP_SCENARIOS)
+
+    def clean_cli_output(self, output):
+        if output.endswith('Asterisk ending (0).\n'):
+            output = output[0:-21]
+        return output.strip()
+
+    def should_be_done_by_now(self):
+        # We use a timert1 of 50 which should stop retransmissions
+        # after 3.2 seconds.
+        # t0 = call is initiated
+        # t1 = call is complete (except for Bob-leg)
+        # t5 = asterisk has timed out sending 200s, start sending BYE
+        # t9 = asterisk has timed out sending BYE, destroy object
+        # (in practice, it turns out it takes about 13+ seconds)
+        # t20 = give everyone some extra time
+        return (time.time() - self.t0 > 20)
+
+    def get_channels(self):
+        def ret(obj):
+            output = self.clean_cli_output(obj.output)
+            if output.startswith('0 active channels'):
+                # No need to schedule ourselves anymore.
+                pass
+            elif self.should_be_done_by_now():
+                LOGGER.warn('Expected 0 active calls: %r' % (output,))
+                self.passed = False
+            else:
+                # Try again in a while.
+                self.stop_jobs.extend([self.get_sleep, self.get_channels])
+            self.next_job()
+        self.ast[0].cli_exec('core show channels count').addCallback(ret)
+
+    def get_sip_objects(self):
+        def ret(obj):
+            output = self.clean_cli_output(obj.output)
+            dialog_objs = output.split('-= Dialog objects:', 1)[-1].strip()
+            if not dialog_objs:
+                # No need to schedule ourselves anymore.
+                pass
+            elif self.should_be_done_by_now():
+                LOGGER.warn('Expected 0 sip dialog objects:\n  %s' %
+                            (dialog_objs.replace('\n', '\n  '),))
+                self.passed = False
+            else:
+                # Try again in a while.
+                self.stop_jobs.extend([self.get_sleep, self.get_sip_objects])
+            self.next_job()
+        self.ast[0].cli_exec('sip show objects').addCallback(ret)
+
+    def get_sleep(self):
+        reactor.callLater(1, self.next_job)
+
+    def next_job(self):
+        if not self.stop_jobs:
+            # Really done.
+            super(MySIPpTest, self).stop_reactor()
+        else:
+            # Schedule the next job.
+            first_job = self.stop_jobs.pop(0)
+            first_job()
+
+    def run(self):
+        """
+        This is called by the TestCase when we start.  Start counting
+        the clock.
+        """
+        super(MySIPpTest, self).run()
+        self.t0 = time.time()
+
+    def stop_reactor(self):
+        """
+        This is called by the TestCase when we're done.  Defer that
+        until after we've pulled some info out of asterisk.
+        """
+        self.next_job()
+
+
+def main():
+    test = MySIPpTest()
+    reactor.run()
+
+    # If it failed, bail.
+    if not test.passed:
+        return 1
+
+    return 0
+
+
+if __name__ == "__main__":
+    sys.exit(main())
+
+# vim:sw=4:ts=4:expandtab:textwidth=79

Propchange: asterisk/trunk/tests/channels/SIP/no_ack_dialog_cleanup/run-test
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: asterisk/trunk/tests/channels/SIP/no_ack_dialog_cleanup/run-test
------------------------------------------------------------------------------
    svn:executable = *

Propchange: asterisk/trunk/tests/channels/SIP/no_ack_dialog_cleanup/run-test
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: asterisk/trunk/tests/channels/SIP/no_ack_dialog_cleanup/run-test
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: asterisk/trunk/tests/channels/SIP/no_ack_dialog_cleanup/sipp/alice.xml
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/channels/SIP/no_ack_dialog_cleanup/sipp/alice.xml?view=auto&rev=5709
==============================================================================
--- asterisk/trunk/tests/channels/SIP/no_ack_dialog_cleanup/sipp/alice.xml (added)
+++ asterisk/trunk/tests/channels/SIP/no_ack_dialog_cleanup/sipp/alice.xml Fri Oct 10 02:25:08 2014
@@ -1,0 +1,75 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!DOCTYPE scenario SYSTEM "sipp.dtd">
+<scenario name="ASTERISK-20784-alice">
+
+  <!-- invite with ulaw -->
+  <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:alice@[local_ip]:[local_port]>;tag=[pid]SIPpTag00[call_number]
+      To: [service] <sip:[service]@[remote_ip]:[remote_port]>
+      Call-ID: [call_id]
+      CSeq: 1 INVITE
+      Contact: <sip:alice@[local_ip]:[local_port]>
+      Content-Type: application/sdp
+      Content-Length: [len]
+
+      v=0
+      o=user1 [pid][call_number][cseq] [pid][call_number][cseq] IN IP[local_ip_type] [local_ip]
+      s=-
+      c=IN IP[media_ip_type] [media_ip]
+      t=0 0
+      m=audio [media_port] RTP/AVP 0
+      a=rtpmap:0 PCMU/8000
+
+    ]]>
+  </send>
+
+  <recv response="100" optional="true">
+  </recv>
+
+  <recv response="180" optional="true">
+  </recv>
+
+  <recv response="200" rrs="true">
+  </recv>
+
+  <send>
+    <![CDATA[
+
+      ACK [next_url] SIP/2.0
+      Via: SIP/2.0/[transport] [local_ip]:[local_port];branch=[branch]
+      [last_From:]
+      [last_To:]
+      [last_Call-ID:]
+      CSeq: 1 ACK
+      Contact: <sip:alice@[local_ip]:[local_port]>
+      Content-Length: 0
+
+    ]]>
+  </send>
+
+  <!-- make sure bob is first with his reinvite -->
+  <pause milliseconds="100"/>
+
+  <!-- done with the call -->
+  <send retrans="500">
+    <![CDATA[
+
+      BYE [next_url] SIP/2.0
+      Via: SIP/2.0/[transport] [local_ip]:[local_port];branch=[branch]
+      From: alice <sip:alice@[local_ip]:[local_port]>;tag=[pid]SIPpTag00[call_number]
+      To: [service] <sip:[service]@[remote_ip]:[remote_port]>[peer_tag_param]
+      [last_Call-ID:]
+      CSeq: 3 BYE
+      Content-Length: 0
+
+    ]]>
+  </send>
+
+  <recv response="200">
+  </recv>
+
+</scenario>

Propchange: asterisk/trunk/tests/channels/SIP/no_ack_dialog_cleanup/sipp/alice.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: asterisk/trunk/tests/channels/SIP/no_ack_dialog_cleanup/sipp/alice.xml
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: asterisk/trunk/tests/channels/SIP/no_ack_dialog_cleanup/sipp/alice.xml
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: asterisk/trunk/tests/channels/SIP/no_ack_dialog_cleanup/sipp/bob.xml
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/channels/SIP/no_ack_dialog_cleanup/sipp/bob.xml?view=auto&rev=5709
==============================================================================
--- asterisk/trunk/tests/channels/SIP/no_ack_dialog_cleanup/sipp/bob.xml (added)
+++ asterisk/trunk/tests/channels/SIP/no_ack_dialog_cleanup/sipp/bob.xml Fri Oct 10 02:25:08 2014
@@ -1,0 +1,94 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!DOCTYPE scenario SYSTEM "sipp.dtd">
+<scenario name="ASTERISK-20784-bob">
+
+  <!-- expect call from alice -->
+  <recv request="INVITE">
+  </recv>
+
+  <send>
+    <![CDATA[
+
+      SIP/2.0 180 Ringing
+      [last_Via:]
+      [last_From:]
+      [last_To:];tag=[pid]SIPpTag01[call_number]
+      [last_Call-ID:]
+      [last_CSeq:]
+      Contact: <sip:bob@[local_ip]:[local_port]>
+      Content-Length: 0
+
+    ]]>
+  </send>
+
+  <send retrans="500">
+    <![CDATA[
+
+      SIP/2.0 200 OK
+      [last_Via:]
+      [last_From:]
+      [last_To:];tag=[pid]SIPpTag01[call_number]
+      [last_Call-ID:]
+      [last_CSeq:]
+      Contact: <sip:bob@[local_ip]:[local_port]>
+      Content-Type: application/sdp
+      Content-Length: [len]
+
+      v=0
+      o=user1 [pid][call_number][cseq] [pid][call_number][cseq] IN IP[local_ip_type] [local_ip]
+      s=-
+      c=IN IP[media_ip_type] [media_ip]
+      t=0 0
+      m=audio [media_port] RTP/AVP 0
+      a=rtpmap:0 PCMU/8000
+
+    ]]>
+  </send>
+
+  <recv request="ACK">
+    <action>
+      <ereg regexp="<(.*)>" search_in="hdr" header="Contact:" assign_to="_,contact"/>
+      <ereg regexp=".*" search_in="hdr" header="From:" assign_to="from"/>
+      <ereg regexp=".*" search_in="hdr" header="To:" assign_to="to"/>
+    </action>
+  </recv>
+  <Reference variables="_"/>
+
+  <!-- re-invite with alaw -->
+  <send retrans="500">
+    <![CDATA[
+
+      INVITE [$contact] SIP/2.0
+      Via: SIP/2.0/[transport] [local_ip]:[local_port];branch=[branch]
+      From: [$to]
+      To: [$from]
+      Call-ID: [call_id]
+      CSeq: 2 INVITE
+      Contact: <sip:bob@[local_ip]:[local_port]>
+      Content-Type: application/sdp
+      Content-Length: [len]
+
+      v=0
+      o=user1 [pid][call_number][cseq] [pid][call_number][cseq] IN IP[local_ip_type] [local_ip]
+      s=-
+      c=IN IP[media_ip_type] [media_ip]
+      t=0 0
+      m=audio [media_port] RTP/AVP 8
+      a=rtpmap:8 PCMA/8000
+
+    ]]>
+  </send>
+
+  <!-- expect hung up call -->
+  <recv request="BYE" optional="true">
+  </recv>
+
+  <!-- expected response to our reinvite -->
+  <recv response="100" optional="true">
+  </recv>
+
+  <!-- expected response to our reinvite -->
+  <recv response="200">
+  </recv>
+
+</scenario>

Propchange: asterisk/trunk/tests/channels/SIP/no_ack_dialog_cleanup/sipp/bob.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: asterisk/trunk/tests/channels/SIP/no_ack_dialog_cleanup/sipp/bob.xml
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: asterisk/trunk/tests/channels/SIP/no_ack_dialog_cleanup/sipp/bob.xml
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: asterisk/trunk/tests/channels/SIP/no_ack_dialog_cleanup/test-config.yaml
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/channels/SIP/no_ack_dialog_cleanup/test-config.yaml?view=auto&rev=5709
==============================================================================
--- asterisk/trunk/tests/channels/SIP/no_ack_dialog_cleanup/test-config.yaml (added)
+++ asterisk/trunk/tests/channels/SIP/no_ack_dialog_cleanup/test-config.yaml Fri Oct 10 02:25:08 2014
@@ -1,0 +1,17 @@
+testinfo:
+    summary: 'Test channel leak as described in ASTERISK-20784'
+    description: |
+        'This tests a scenario where Alice calls Bob through Asterisk.
+        Alice hangs up immediately.  But Bob attempts a re-INVITE at
+        the same time.  At this point Bob stops to respond.
+        If the bug is not fixed, this will leak a sip dialog object.'
+
+properties:
+    minversion: '1.8.0.0'
+    dependencies:
+        - python: 'starpy'
+        - sipp:
+            version: 'v3.1'
+        - asterisk : 'chan_sip'
+    tags:
+        - SIP

Propchange: asterisk/trunk/tests/channels/SIP/no_ack_dialog_cleanup/test-config.yaml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: asterisk/trunk/tests/channels/SIP/no_ack_dialog_cleanup/test-config.yaml
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: asterisk/trunk/tests/channels/SIP/no_ack_dialog_cleanup/test-config.yaml
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: asterisk/trunk/tests/channels/SIP/tests.yaml
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/channels/SIP/tests.yaml?view=diff&rev=5709&r1=5708&r2=5709
==============================================================================
--- asterisk/trunk/tests/channels/SIP/tests.yaml (original)
+++ asterisk/trunk/tests/channels/SIP/tests.yaml Fri Oct 10 02:25:08 2014
@@ -70,3 +70,4 @@
     - test: 'tel_uri'
     - dir: 'ami'
     - test: 'invite_retransmit'
+    - test: 'no_ack_dialog_cleanup'




More information about the asterisk-commits mailing list