예제 #1
0
def listenForServerRequests():
    print "Listening for server requests!"
    while (True):
        data = RTP.receiveData(snew)
        #if "GET" in str(request):
        #    print "GETTING a file"
        #    request = str(request).replace("GET: ", "")
        #    print "Getting file: ", request

        #with open (request, "r") as myfile:
        #    data = myfile.read()

        RTP.sendData(snew, data)
예제 #2
0
    def test_fromBytes_default(self):
        self.thisRTP.sequenceNumber = 0
        self.thisRTP.ssrc = 0
        default = b'\x80\x60\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'

        newRTP = RTP().fromBytes(default)
        self.assertEqual(newRTP, self.thisRTP)
예제 #3
0
    def test_processData(self, data):
        doc, encoding, bom = data

        payload = RTPPayload_TTML(userDataWords=doc,
                                  encoding=encoding,
                                  bom=bom).toBytearray()
        packet = RTP(payload=payload, marker=True)
        packetBytes = packet.toBytes()
        with mock.patch("rtpTTML.ttmlReceiver.RTPPayload_TTML") as mockTTML:
            thisReceiver = TTMLReceiver(0,
                                        self.callback,
                                        encoding=encoding,
                                        bom=bom)

            thisReceiver._processData(packetBytes)

            mockTTML.assert_called_once_with(encoding=encoding, bom=bom)
예제 #4
0
 def test_pushGet(self, startKey, len):
     self.assertFalse(self.buffer.available())
     for x in range(len):
         seqNum = (startKey + x) % (MAX_SEQ_NUM + 1)
         packet = RTP(sequenceNumber=seqNum)
         ret = self.buffer.pushGet(seqNum, packet)
         self.assertEqual([packet], ret)
         self.assertFalse(self.buffer.available())
예제 #5
0
    def test_fromBytearray_marker(self, value):
        self.thisRTP.sequenceNumber = 0
        self.thisRTP.ssrc = 0
        payload = bytearray(
            b'\x80\x60\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
        payload[1] |= value << 7
        newRTP = RTP().fromBytearray(payload)

        self.thisRTP.marker = value
        self.assertEqual(newRTP, self.thisRTP)
예제 #6
0
    def test_fromBytearray_ssrc(self, value):
        self.thisRTP.sequenceNumber = 0
        self.thisRTP.ssrc = 0
        payload = bytearray(
            b'\x80\x60\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
        payload[8:12] = value.to_bytes(4, byteorder='big')
        newRTP = RTP().fromBytearray(payload)

        self.thisRTP.ssrc = value
        self.assertEqual(newRTP, self.thisRTP)
예제 #7
0
    def test_fromBytearray_payload(self, value):
        self.thisRTP.sequenceNumber = 0
        self.thisRTP.ssrc = 0
        payload = bytearray(
            b'\x80\x60\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
        payload += value
        newRTP = RTP().fromBytearray(payload)

        self.thisRTP.payload = bytearray(value)
        self.assertEqual(newRTP, self.thisRTP)
    def _processData(self, data: bytes) -> None:
        newPacket = RTP().fromBytes(data)

        packets = self._packetBuff.pushGet(
            newPacket.sequenceNumber, newPacket)

        for packet in packets:
            self._processPacket(packet)

            if packet.marker:
                self._processFragments()
예제 #9
0
    def test_pop(self, startKey, len):
        fragments = []
        for x in range(len):
            seqNum = (startKey + x) % (MAX_SEQ_NUM + 1)
            packet = RTP(sequenceNumber=seqNum)
            fragments.append((seqNum, packet))
            self.buffer.push(seqNum, packet)

        for _, packet in fragments[-5:]:
            poppedPacket = self.buffer.pop()
            self.assertEqual(packet, poppedPacket)
예제 #10
0
    def test_get(self, startKey, len):
        fragments = []
        for x in range(len):
            seqNum = (startKey + x) % (MAX_SEQ_NUM + 1)
            packet = RTP(sequenceNumber=seqNum)
            fragments.append(packet)
            self.buffer.push(seqNum, packet)

        gotPackets = self.buffer.get()

        self.assertEqual(gotPackets, fragments[-5:])
        self.assertFalse(self.buffer.available())
예제 #11
0
    def test_fromBytearray_csrcList(self, value):
        self.thisRTP.sequenceNumber = 0
        self.thisRTP.ssrc = 0
        payload = bytearray(
            b'\x80\x60\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
        payload[0] |= len(value)
        for x in range(len(value)):
            payload[12 + (4 * x):12 + (4 * x)] = value[x].to_bytes(
                4, byteorder='big')
        newRTP = RTP().fromBytearray(payload)

        self.thisRTP.csrcList.extend(value)
        self.assertEqual(newRTP, self.thisRTP)
예제 #12
0
    def test_push(self, startKey, len):
        fragments = []
        for x in range(len):
            seqNum = (startKey + x) % (MAX_SEQ_NUM + 1)
            packet = RTP(sequenceNumber=seqNum)
            fragments.append((seqNum, packet))
            self.buffer.push(seqNum, packet)

        for seqNum, packet in fragments[-5:]:
            self.assertIn(seqNum, self.buffer._buffer)
            self.assertEqual(packet, self.buffer._buffer[seqNum])

        for seqNum, packet in fragments[:-5]:
            self.assertNotIn(seqNum, self.buffer._buffer)
예제 #13
0
    def test_fromBytearray_extension(self, startBits, headerExtension):
        self.thisRTP.sequenceNumber = 0
        self.thisRTP.ssrc = 0
        newExt = Extension()
        newExt.startBits = bytearray(startBits)
        newExt.headerExtension = bytearray(headerExtension)

        payload = bytearray(
            b'\x80\x60\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
        payload[0] |= 1 << 4
        payload[12:12] = newExt.toBytearray()
        newRTP = RTP().fromBytearray(payload)

        self.thisRTP.extension = newExt
        self.assertEqual(newRTP, self.thisRTP)
예제 #14
0
    def test_available(self, startKey, len):
        self.assertFalse(self.buffer.available())

        fragments = []
        for x in range(len):
            seqNum = (startKey + x) % (MAX_SEQ_NUM + 1)
            packet = RTP(sequenceNumber=seqNum)
            fragments.append((seqNum, packet))
            self.buffer.push(seqNum, packet)

        for _, packet in fragments[-5:]:
            self.assertTrue(self.buffer.available())
            self.buffer.pop()

        self.assertFalse(self.buffer.available())
예제 #15
0
    def _generateRTPPacket(self, doc: str, time: int, isFirst: bool,
                           marker: bool) -> RTP:
        # Only include bom in first packet for doc
        thisBOM = (isFirst and self._bom)

        packet = RTP(timestamp=time,
                     sequenceNumber=self._nextSeqNum,
                     payload=RTPPayload_TTML(userDataWords=doc,
                                             encoding=self._encoding,
                                             bom=thisBOM).toBytearray(),
                     marker=marker,
                     payloadType=self._payloadType)
        self._nextSeqNum += 1

        return packet
예제 #16
0
    def test_pushGetMissing(self, startKey, keepList):
        self.assertFalse(self.buffer.available())
        keepList += ([True] * 5)

        expectedList = []
        receivedList = []

        for x in range(10):
            seqNum = (startKey + x) % (MAX_SEQ_NUM + 1)
            packet = RTP(sequenceNumber=seqNum)
            if keepList[x]:
                expectedList.append(packet)
                ret = self.buffer.pushGet(seqNum, packet)
                receivedList += ret

        self.assertEqual(expectedList, receivedList)
        self.assertFalse(self.buffer.available())
예제 #17
0
    def test_pushGetSwapped(self, startKey, swap):
        self.assertFalse(self.buffer.available())
        expectedList = []
        receivedList = []

        for x in list(range(10)):
            seqNum = (startKey + x) % (MAX_SEQ_NUM + 1)
            packet = RTP(sequenceNumber=seqNum)
            expectedList.append(packet)

        swappedPackets = expectedList.copy()
        swappedPackets[swap[0]], swappedPackets[swap[1]] = (
            swappedPackets[swap[1]], swappedPackets[swap[0]])

        for packet in swappedPackets:
            ret = self.buffer.pushGet(packet.sequenceNumber, packet)
            receivedList += ret

        self.assertFalse(self.buffer.available())

        self.assertEqual(len(expectedList), len(receivedList))
        self.assertEqual(expectedList, receivedList)
예제 #18
0
    def test_init(self, padding, marker, payloadType, sequenceNumber,
                  timestamp, ssrc, csrcList, payload):
        newExt = Extension()
        newRTP = RTP(version=2,
                     padding=padding,
                     marker=marker,
                     payloadType=payloadType,
                     sequenceNumber=sequenceNumber,
                     timestamp=timestamp,
                     ssrc=ssrc,
                     extension=newExt,
                     csrcList=csrcList,
                     payload=bytearray(payload))

        self.assertEqual(newRTP.version, 2)
        self.assertEqual(newRTP.padding, padding)
        self.assertEqual(newRTP.marker, marker)
        self.assertEqual(newRTP.payloadType, payloadType)
        self.assertEqual(newRTP.sequenceNumber, sequenceNumber)
        self.assertEqual(newRTP.timestamp, timestamp)
        self.assertEqual(newRTP.ssrc, ssrc)
        self.assertEqual(newRTP.extension, newExt)
        self.assertEqual(newRTP.csrcList, csrcList)
        self.assertEqual(newRTP.payload, payload)
예제 #19
0
class TestRTP(TestCase):
    def setUp(self):
        self.thisRTP = RTP()

    def setup_example(self):
        self.setUp()

    @given(st.booleans(), st.booleans(), st.sampled_from(PayloadType),
           st.integers(min_value=0, max_value=(2**16) - 1),
           st.integers(min_value=0, max_value=(2**32) - 1),
           st.integers(min_value=0, max_value=(2**32) - 1),
           st.lists(st.integers(min_value=0, max_value=(2**16) - 1),
                    max_size=15), st.binary())
    def test_init(self, padding, marker, payloadType, sequenceNumber,
                  timestamp, ssrc, csrcList, payload):
        newExt = Extension()
        newRTP = RTP(version=2,
                     padding=padding,
                     marker=marker,
                     payloadType=payloadType,
                     sequenceNumber=sequenceNumber,
                     timestamp=timestamp,
                     ssrc=ssrc,
                     extension=newExt,
                     csrcList=csrcList,
                     payload=bytearray(payload))

        self.assertEqual(newRTP.version, 2)
        self.assertEqual(newRTP.padding, padding)
        self.assertEqual(newRTP.marker, marker)
        self.assertEqual(newRTP.payloadType, payloadType)
        self.assertEqual(newRTP.sequenceNumber, sequenceNumber)
        self.assertEqual(newRTP.timestamp, timestamp)
        self.assertEqual(newRTP.ssrc, ssrc)
        self.assertEqual(newRTP.extension, newExt)
        self.assertEqual(newRTP.csrcList, csrcList)
        self.assertEqual(newRTP.payload, payload)

    def test_version_default(self):
        # Test default
        self.assertEqual(self.thisRTP.version, 2)

    @given(st.integers())
    @example(2)
    def test_version(self, value):
        if value == 2:
            self.thisRTP.version = value
            self.assertEqual(self.thisRTP.version, value)
        else:
            with self.assertRaises(ValueError):
                self.thisRTP.version = value

    def test_padding_default(self):
        self.assertEqual(self.thisRTP.padding, False)

    @given(st.booleans())
    def test_padding(self, value):
        self.thisRTP.padding = value
        self.assertEqual(self.thisRTP.padding, value)

    def test_padding_invalidType(self):
        with self.assertRaises(AttributeError):
            self.thisRTP.padding = ""

    def test_marker_default(self):
        self.assertEqual(self.thisRTP.marker, False)

    @given(st.booleans())
    def test_marker(self, value):
        self.thisRTP.marker = value
        self.assertEqual(self.thisRTP.marker, value)

    def test_marker_invalidType(self):
        with self.assertRaises(AttributeError):
            self.thisRTP.marker = ""

    def test_payloadType_default(self):
        self.assertEqual(self.thisRTP.payloadType, PayloadType.DYNAMIC_96)

    @given(st.sampled_from(PayloadType))
    def test_payloadType(self, value):
        self.thisRTP.payloadType = value
        self.assertEqual(self.thisRTP.payloadType, value)

    def test_payloadType_invalidType(self):
        with self.assertRaises(AttributeError):
            self.thisRTP.payloadType = ""

    def test_sequenceNumber_default(self):
        self.assertIsInstance(self.thisRTP.sequenceNumber, int)

    @given(st.integers(min_value=0, max_value=(2**16) - 1))
    def test_sequenceNumber_valid(self, value):
        self.thisRTP.sequenceNumber = value
        self.assertEqual(self.thisRTP.sequenceNumber, value)

    @given(st.integers().filter(lambda x: (x < 0) or (x >= 2**16)))
    def test_sequenceNumber_invalid(self, value):
        with self.assertRaises(ValueError):
            self.thisRTP.sequenceNumber = value

    def test_sequenceNumber_invalidType(self):
        with self.assertRaises(AttributeError):
            self.thisRTP.sequenceNumber = ""

    def test_timestamp_default(self):
        self.assertEqual(self.thisRTP.timestamp, 0)

    @given(st.integers(min_value=0, max_value=(2**32) - 1))
    def test_timestamp_valid(self, value):
        self.thisRTP.timestamp = value
        self.assertEqual(self.thisRTP.timestamp, value)

    @given(st.integers().filter(lambda x: (x < 0) or (x >= 2**32)))
    def test_timestamp_invalid(self, value):
        with self.assertRaises(ValueError):
            self.thisRTP.timestamp = value

    def test_timestamp_invalidType(self):
        with self.assertRaises(AttributeError):
            self.thisRTP.timestamp = ""

    def test_ssrc_default(self):
        self.assertIsInstance(self.thisRTP.ssrc, int)

    @given(st.integers(min_value=0, max_value=(2**32) - 1))
    def test_ssrc_valid(self, value):
        self.thisRTP.ssrc = value
        self.assertEqual(self.thisRTP.ssrc, value)

    @given(st.integers().filter(lambda x: (x < 0) or (x >= 2**32)))
    def test_ssrc_invalid(self, value):
        with self.assertRaises(ValueError):
            self.thisRTP.ssrc = value

    def test_ssrc_invalidType(self):
        with self.assertRaises(AttributeError):
            self.thisRTP.ssrc = ""

    def test_extension_default(self):
        self.assertEqual(self.thisRTP.extension, None)

    def test_extension(self):
        self.thisRTP.extension = None
        self.assertEqual(self.thisRTP.extension, None)

        newExt = Extension()
        self.thisRTP.extension = newExt
        self.assertEqual(self.thisRTP.extension, newExt)

    def test_extension_invalidType(self):
        with self.assertRaises(AttributeError):
            self.thisRTP.extension = ""

    def test_csrcList_default(self):
        self.assertEqual(self.thisRTP.csrcList, CSRCList())

    def test_payload_default(self):
        self.assertEqual(self.thisRTP.payload, bytearray())

    @given(st.binary())
    def test_payload(self, value):
        self.thisRTP.payload = bytearray(value)
        self.assertEqual(self.thisRTP.payload, value)

    def test_payload_invalidType(self):
        with self.assertRaises(AttributeError):
            self.thisRTP.payload = ""

    def test_fromBytearray_default(self):
        self.thisRTP.sequenceNumber = 0
        self.thisRTP.ssrc = 0
        default = bytearray(
            b'\x80\x60\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')

        newRTP = RTP().fromBytearray(default)
        self.assertEqual(newRTP, self.thisRTP)

    def test_toBytearray_default(self):
        self.thisRTP.sequenceNumber = 0
        self.thisRTP.ssrc = 0
        expected = b'\x80\x60\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
        self.assertEqual(self.thisRTP.toBytearray(), expected)

    @given(st.booleans())
    def test_fromBytearray_padding(self, value):
        self.thisRTP.sequenceNumber = 0
        self.thisRTP.ssrc = 0
        payload = bytearray(
            b'\x80\x60\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
        payload[0] |= value << 5
        newRTP = RTP().fromBytearray(payload)

        self.thisRTP.padding = value
        self.assertEqual(newRTP, self.thisRTP)

    @given(st.booleans())
    def test_toBytearray_padding(self, value):
        self.thisRTP.sequenceNumber = 0
        self.thisRTP.ssrc = 0
        expected = bytearray(
            b'\x80\x60\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
        expected[0] |= value << 5
        self.thisRTP.padding = value
        self.assertEqual(self.thisRTP.toBytearray(), expected)

    @given(st.binary(min_size=2, max_size=2),
           st.binary(max_size=((2**16) - 1) *
                     4).filter(lambda x: (len(x) % 4) == 0))
    def test_fromBytearray_extension(self, startBits, headerExtension):
        self.thisRTP.sequenceNumber = 0
        self.thisRTP.ssrc = 0
        newExt = Extension()
        newExt.startBits = bytearray(startBits)
        newExt.headerExtension = bytearray(headerExtension)

        payload = bytearray(
            b'\x80\x60\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
        payload[0] |= 1 << 4
        payload[12:12] = newExt.toBytearray()
        newRTP = RTP().fromBytearray(payload)

        self.thisRTP.extension = newExt
        self.assertEqual(newRTP, self.thisRTP)

    @given(st.binary(min_size=2, max_size=2),
           st.binary(max_size=((2**16) - 1) *
                     4).filter(lambda x: (len(x) % 4) == 0))
    def test_toBytearray_extension(self, startBits, headerExtension):
        self.thisRTP.sequenceNumber = 0
        self.thisRTP.ssrc = 0
        newExt = Extension()
        newExt.startBits = bytearray(startBits)
        newExt.headerExtension = bytearray(headerExtension)

        expected = bytearray(
            b'\x80\x60\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
        expected[0] |= 1 << 4
        expected[12:12] = newExt.toBytearray()
        self.thisRTP.extension = newExt
        self.assertEqual(self.thisRTP.toBytearray(), expected)

    @given(
        st.lists(st.integers(min_value=0, max_value=(2**16) - 1), max_size=15))
    def test_fromBytearray_csrcList(self, value):
        self.thisRTP.sequenceNumber = 0
        self.thisRTP.ssrc = 0
        payload = bytearray(
            b'\x80\x60\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
        payload[0] |= len(value)
        for x in range(len(value)):
            payload[12 + (4 * x):12 + (4 * x)] = value[x].to_bytes(
                4, byteorder='big')
        newRTP = RTP().fromBytearray(payload)

        self.thisRTP.csrcList.extend(value)
        self.assertEqual(newRTP, self.thisRTP)

    @given(
        st.lists(st.integers(min_value=0, max_value=(2**16) - 1), max_size=15))
    def test_toBytearray_csrcList(self, value):
        self.thisRTP.sequenceNumber = 0
        self.thisRTP.ssrc = 0
        expected = bytearray(
            b'\x80\x60\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
        expected[0] |= len(value)
        for x in range(len(value)):
            expected[12 + (4 * x):12 + (4 * x)] = value[x].to_bytes(
                4, byteorder='big')

        self.thisRTP.csrcList.extend(value)
        self.assertEqual(self.thisRTP.toBytearray(), expected)

    @given(st.booleans())
    def test_fromBytearray_marker(self, value):
        self.thisRTP.sequenceNumber = 0
        self.thisRTP.ssrc = 0
        payload = bytearray(
            b'\x80\x60\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
        payload[1] |= value << 7
        newRTP = RTP().fromBytearray(payload)

        self.thisRTP.marker = value
        self.assertEqual(newRTP, self.thisRTP)

    @given(st.booleans())
    def test_toBytearray_marker(self, value):
        self.thisRTP.sequenceNumber = 0
        self.thisRTP.ssrc = 0
        expected = bytearray(
            b'\x80\x60\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
        expected[1] |= value << 7

        self.thisRTP.marker = value
        self.assertEqual(self.thisRTP.toBytearray(), expected)

    @given(st.sampled_from(PayloadType))
    def test_fromBytearray_payloadType(self, value):
        self.thisRTP.sequenceNumber = 0
        self.thisRTP.ssrc = 0
        payload = bytearray(
            b'\x80\x60\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
        payload[1] = value.value
        newRTP = RTP().fromBytearray(payload)

        self.thisRTP.payloadType = value
        self.assertEqual(newRTP, self.thisRTP)

    @given(st.sampled_from(PayloadType))
    def test_toBytearray_payloadType(self, value):
        self.thisRTP.sequenceNumber = 0
        self.thisRTP.ssrc = 0
        expected = bytearray(
            b'\x80\x60\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
        expected[1] = value.value

        self.thisRTP.payloadType = value
        self.assertEqual(self.thisRTP.toBytearray(), expected)

    @given(st.integers(min_value=0, max_value=(2**16) - 1))
    def test_fromBytearray_sequenceNumber(self, value):
        self.thisRTP.sequenceNumber = 0
        self.thisRTP.ssrc = 0
        payload = bytearray(
            b'\x80\x60\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
        payload[2:4] = value.to_bytes(2, byteorder='big')
        newRTP = RTP().fromBytearray(payload)

        self.thisRTP.sequenceNumber = value
        self.assertEqual(newRTP, self.thisRTP)

    @given(st.integers(min_value=0, max_value=(2**16) - 1))
    def test_toBytearray_sequenceNumber(self, value):
        self.thisRTP.sequenceNumber = 0
        self.thisRTP.ssrc = 0
        expected = bytearray(
            b'\x80\x60\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
        expected[2:4] = value.to_bytes(2, byteorder='big')
        self.thisRTP.sequenceNumber = value
        self.assertEqual(self.thisRTP.toBytearray(), expected)

    @given(st.integers(min_value=0, max_value=(2**32) - 1))
    def test_fromBytearray_timestamp(self, value):
        self.thisRTP.sequenceNumber = 0
        self.thisRTP.ssrc = 0
        payload = bytearray(
            b'\x80\x60\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
        payload[4:8] = value.to_bytes(4, byteorder='big')
        newRTP = RTP().fromBytearray(payload)

        self.thisRTP.timestamp = value
        self.assertEqual(newRTP, self.thisRTP)

    @given(st.integers(min_value=0, max_value=(2**32) - 1))
    def test_toBytearray_timestamp(self, value):
        self.thisRTP.sequenceNumber = 0
        self.thisRTP.ssrc = 0
        expected = bytearray(
            b'\x80\x60\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
        expected[4:8] = value.to_bytes(4, byteorder='big')
        self.thisRTP.timestamp = value
        self.assertEqual(self.thisRTP.toBytearray(), expected)

    @given(st.integers(min_value=0, max_value=(2**32) - 1))
    def test_fromBytearray_ssrc(self, value):
        self.thisRTP.sequenceNumber = 0
        self.thisRTP.ssrc = 0
        payload = bytearray(
            b'\x80\x60\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
        payload[8:12] = value.to_bytes(4, byteorder='big')
        newRTP = RTP().fromBytearray(payload)

        self.thisRTP.ssrc = value
        self.assertEqual(newRTP, self.thisRTP)

    @given(st.integers(min_value=0, max_value=(2**32) - 1))
    def test_toBytearray_ssrc(self, value):
        self.thisRTP.sequenceNumber = 0
        self.thisRTP.ssrc = 0
        expected = bytearray(
            b'\x80\x60\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
        expected[8:12] = value.to_bytes(4, byteorder='big')
        self.thisRTP.ssrc = value
        self.assertEqual(self.thisRTP.toBytearray(), expected)

    @given(st.binary())
    def test_fromBytearray_payload(self, value):
        self.thisRTP.sequenceNumber = 0
        self.thisRTP.ssrc = 0
        payload = bytearray(
            b'\x80\x60\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
        payload += value
        newRTP = RTP().fromBytearray(payload)

        self.thisRTP.payload = bytearray(value)
        self.assertEqual(newRTP, self.thisRTP)

    @given(st.binary())
    def test_toBytearray_payload(self, value):
        self.thisRTP.sequenceNumber = 0
        self.thisRTP.ssrc = 0
        expected = bytearray(
            b'\x80\x60\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
        expected += value
        self.thisRTP.payload = bytearray(value)
        self.assertEqual(self.thisRTP.toBytearray(), expected)

    def test_fromBytes_default(self):
        self.thisRTP.sequenceNumber = 0
        self.thisRTP.ssrc = 0
        default = b'\x80\x60\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'

        newRTP = RTP().fromBytes(default)
        self.assertEqual(newRTP, self.thisRTP)

    def test_toBytes_default(self):
        self.thisRTP.sequenceNumber = 0
        self.thisRTP.ssrc = 0
        expected = b'\x80\x60\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
        self.assertEqual(self.thisRTP.toBytes(), expected)

    def test_bytes_default(self):
        self.thisRTP.sequenceNumber = 0
        self.thisRTP.ssrc = 0
        expected = b'\x80\x60\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
        self.assertEqual(bytes(self.thisRTP), expected)
예제 #20
0
from RTPSocket import RTPSocket, SocketState
from RTPPacket import RTPPacket
from RTPPacketHeader import RTPPacketHeader
from RTPException import RTPException

# bring in IP and PORT for socket
TCP_IP, TCP_PORT = sys.argv[1].split(":")
TCP_PORT = int(TCP_PORT)

# buffer size for information being sent
BUFFER_SIZE = 1024

windowSize = 20
# setup socket and set to stream for TCP connection
global snew
source_address, snew = RTP.createRTPSocket(TCP_IP, TCP_PORT)

snew.source_address = source_address
###s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
print snew
#RTP.setWindowSize(snew, windowSize)

####try:
ip, port = snew.source_address
RTP.connectToRTP(snew, ip, port)
####s.connect((TCP_IP, TCP_PORT))
####except snew.error, msg:
####print "Couldn't connect to server. Closing"
####sys.exit(1)

studentData = []
예제 #21
0
import socket
import sys
from rtp import RTP
from RTPSocket import RTPSocket, SocketState
from RTPPacket import RTPPacket
from RTPPacketHeader import RTPPacketHeader
from RTPException import RTPException
import threading

TCP_IP = '0.0.0.0'
TCP_PORT = int(sys.argv[1])
BUFFER_SIZE = 20  # Normally 1024, but we want fast response

#create/bind
global snew
source_address, snew = RTP.createRTPSocket(TCP_IP, TCP_PORT)
snew.bind(source_address)
#s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
#s.bind((TCP_IP, TCP_PORT))
in_conn = RTP.listenForRTPConnections(snew)
#s.listen(1)

students = []
students.append({
    'ID': '903076259',  # Are these sets?
    'first_name': 'Anthony',
    'last_name': 'Peterson',
    'quality_points': 231,
    'gpa_hours': 63,
    'gpa': 3.666667
})
예제 #22
0
 def setUp(self):
     self.thisRTP = RTP()