[asterisk-commits] mmichelson: branch group/rls-tests r5169 - in /asterisk/team/group/rls-tests:...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Mon Jun 23 17:04:08 CDT 2014
Author: mmichelson
Date: Mon Jun 23 17:04:00 2014
New Revision: 5169
URL: http://svnview.digium.com/svn/testsuite?view=rev&rev=5169
Log:
Make changes to the pcap test library to deal with Multipart, RLMI, and PIDF documents.
Tests have shown that we can properly parse NOTIFYs with multipart/related bodies,
and we can parse the RLMI parts from within. Nothing is being done for PIDF documents
other than to store their text.
With this junk out of the way, I can actually start writing some test cases.
Added:
asterisk/team/group/rls-tests/tests/channels/pjsip/subscriptions/rls/
Modified:
asterisk/team/group/rls-tests/lib/python/asterisk/pcap.py
asterisk/team/group/rls-tests/tests/channels/pjsip/subscriptions/tests.yaml
Modified: asterisk/team/group/rls-tests/lib/python/asterisk/pcap.py
URL: http://svnview.digium.com/svn/testsuite/asterisk/team/group/rls-tests/lib/python/asterisk/pcap.py?view=diff&rev=5169&r1=5168&r2=5169
==============================================================================
--- asterisk/team/group/rls-tests/lib/python/asterisk/pcap.py (original)
+++ asterisk/team/group/rls-tests/lib/python/asterisk/pcap.py Mon Jun 23 17:04:00 2014
@@ -25,6 +25,8 @@
except:
PCAP_AVAILABLE = False
+import rlmi
+
LOGGER = logging.getLogger(__name__)
class PcapListener(object):
@@ -57,7 +59,7 @@
# Let exceptions propagate - if we can't create the pcap, this should
# throw the exception to the pluggable module creation routines
test_object.create_pcap_listener(
- device=None,
+ device=device,
bpf_filter=bpf_filter,
dumpfile=filename)
@@ -201,6 +203,85 @@
self.rtcp_port = self.rtp_port + 1
+class PIDFPacket(Packet):
+ '''A PIDF presence body. Owned by SIPPacket or a MultipartPacket.'''
+
+ def __init__(self, ascii_packet, raw_packet):
+ Packet.__init__(self, packet_type="PIDF", raw_packet=raw_packet)
+ self.xml = ascii_packet.strip()
+
+
+class RLMIPacket(Packet):
+ '''An RLMI body. Owned either by a SIPPacket or a MultipartPacket.'''
+
+ def __init__(self, ascii_packet, raw_packet):
+ Packet.__init__(self, packet_type="RLMI", raw_packet=raw_packet)
+ self.list_elem = rlmi.CreateFromDocument(ascii_packet.strip())
+
+
+class MultipartPart:
+ def __init__(self, part, raw_packet):
+ self.headers = {}
+
+ last_pos = part.find('\r\n\r\n')
+ headers = part[:last_pos].split('\r\n')
+ body = part[last_pos:]
+
+ for header in headers:
+ colon_pos = header.find(':')
+ self.headers[header[:colon_pos]] = header[colon_pos + 1:].strip()
+
+ content_type = self.headers.get('Content-Type')
+ self.content_id = self.headers.get('Content-ID').strip('<>')
+ self.body = BodyFactory.create_body(content_type, body.strip(),
+ raw_packet)
+
+
+class MultipartPacket(Packet):
+ '''A multipart body. Owned either by a SIPPacket or a Multipartpacket.'''
+
+ def __init__(self, content_type, ascii_packet, raw_packet):
+ Packet.__init__(self, packet_type="Multipart", raw_packet=raw_packet)
+ self.boundary = None
+ self.parts = []
+
+ for part in content_type.split(';'):
+ param, equal, value = part.partition('=')
+ if param == 'boundary':
+ self.boundary = '--%s' % value.strip('"')
+
+ if not self.boundary:
+ raise Exception
+
+ parts = ascii_packet.split(self.boundary)
+
+ # Start with the second part since the initial boundary has no content
+ # before it.
+ for part in parts[1:]:
+ stripped = part.strip('\r\n ')
+ # The final boundary in a multipart body is --boundary--
+ if stripped == '--':
+ break
+ self.parts.append(MultipartPart(stripped, raw_packet))
+
+
+class BodyFactory(object):
+ @staticmethod
+ def create_body(content_type, ascii_packet, raw_packet):
+ body_type, _, _ = content_type.partition(';')
+ if (body_type == 'application/sdp'):
+ return SDPPacket(ascii_packet, raw_packet)
+ elif (body_type == 'multipart/related'):
+ return MultipartPacket(content_type, ascii_packet, raw_packet)
+ elif (body_type == 'application/rlmi+xml'):
+ return RLMIPacket(ascii_packet, raw_packet)
+ elif (body_type == 'application/pidf+xml'):
+ return PIDFPacket(ascii_packet, raw_packet)
+ else:
+ return Packet(body_type, raw_packet)
+ pass
+
+
class SIPPacket(Packet):
''' A SIP packet '''
@@ -213,7 +294,7 @@
'''
Packet.__init__(self, packet_type='SIP', raw_packet=raw_packet)
- self.sdp_packet = None
+ self.body = None
self.headers = {}
self.request_line = ''
self.ascii_packet = ascii_packet
@@ -232,8 +313,11 @@
colon_pos = header.find(':')
self.headers[header[:colon_pos]] = header[colon_pos + 1:].strip()
if int(self.headers.get('Content-Length')) > 0:
- self.sdp_packet = SDPPacket(ascii_packet=remainder_packet,
- raw_packet=raw_packet)
+ content_type = self.headers.get('Content-Type',
+ 'application/sdp').strip()
+ self.body = BodyFactory.create_body(content_type,
+ ascii_packet=remainder_packet,
+ raw_packet=raw_packet)
class SIPPacketFactory():
@@ -270,9 +354,10 @@
# RTP port and RTCP port; then set that information for this particular
# stream in the factory manager so that the factories for RTP can
# interpret packets correctly
- if ret_packet != None and ret_packet.sdp_packet != None and \
- ret_packet.sdp_packet.rtp_port != 0 and \
- ret_packet.sdp_packet.rtcp_port != 0:
+ if ret_packet and ret_packet.body and \
+ ret_packet.body.packet_type == 'SDP' and \
+ ret_packet.sdp_packet.rtp_port != 0 and \
+ ret_packet.sdp_packet.rtcp_port != 0:
self._factory_manager.add_global_data(ret_packet.ip_layer.header.source,
{'rtp': ret_packet.sdp_packet.rtp_port,
'rtcp': ret_packet.sdp_packet.rtcp_port})
Modified: asterisk/team/group/rls-tests/tests/channels/pjsip/subscriptions/tests.yaml
URL: http://svnview.digium.com/svn/testsuite/asterisk/team/group/rls-tests/tests/channels/pjsip/subscriptions/tests.yaml?view=diff&rev=5169&r1=5168&r2=5169
==============================================================================
--- asterisk/team/group/rls-tests/tests/channels/pjsip/subscriptions/tests.yaml (original)
+++ asterisk/team/group/rls-tests/tests/channels/pjsip/subscriptions/tests.yaml Mon Jun 23 17:04:00 2014
@@ -6,3 +6,4 @@
- test: 'unknown_event_package'
- test: 'unallowed'
- test: 'below_min_expiry'
+ - dir: 'rls'
More information about the asterisk-commits
mailing list