Пример #1
0
    def test_decode_RR(self):
        ttt = time.time()
        (ssrc, ntp, rtp_ts, total_packets, total_bytes, ssrc_1, frac_lost, lost, highest, jitter, lsr, dlsr) = (
            424242,
            ttt,
            143,
            100,
            800,
            424243,
            1,
            1,
            65535,
            15,
            int(time.time() - 10),
            10,
        )

        frac_lost = int(lost / float(total_packets + lost))

        members = {}
        new_member = self.member.copy()
        new_member["last_ts"] = rtp_ts
        new_member["last_seq"] = highest
        new_member["jitter"] = jitter
        new_member["lost"] = lost
        new_member["lsr"] = lsr
        new_member["dlsr"] = dlsr

        members_table = {}
        members_table[ssrc_1] = new_member

        arg_list = (ssrc, members_table)

        rtcp = RTCPPacket("RR", ptcode=201, contents=arg_list)
        rtcp_pac = rtcp.encode()

        # Unpacking
        # Decoding packet
        packet = RTCPCompound(rtcp_pac)

        # Getting content of the first block
        cont = packet._rtcp[0].getContents()

        lsr = ext_32_out_of_64(lsr)
        lsr = unformat_from_32(lsr)

        dlsr = ext_32_out_of_64(dlsr)
        dlsr = unformat_from_32(dlsr)

        # Testing content decode
        assert cont[0] == ssrc, self.fail("SSRC is not correctly encode or " + "decode")
        assert cont[1][0]["ssrc"] == ssrc_1, self.fail("SSRC_1 is not correctly encode or decode")
        assert cont[1][0]["jitter"] == jitter, self.fail("Jitter is not correctly encode or decode")
        assert cont[1][0]["fraclost"] == frac_lost, self.fail("Frac lost is not correctly encode or decode")

        assert cont[1][0]["lsr"] == lsr, self.fail("Last received is not correctly encode or decode")
        assert cont[1][0]["highest"] == highest, self.fail("Highest seq num is not correctly encode or decode")
Пример #2
0
    def test_unformat_from_32(self):
        ref = 10
        res = ext_32_out_of_64(ref)
        res_2 = unformat_from_32(res)
        assert(res_2==ref), self.fail("Wrong encoding or decoding")

        ref = 10.245
        res = ext_32_out_of_64(ref)
        res_2 = unformat_from_32(res)
        assert(res_2==ref), self.fail("Wrong encoding or decoding")
Пример #3
0
    def test_unformat_from_32(self):
        ref = 10
        res = ext_32_out_of_64(ref)
        res_2 = unformat_from_32(res)
        assert res_2 == ref, self.fail("Wrong encoding or decoding")

        ref = 10.245
        res = ext_32_out_of_64(ref)
        res_2 = unformat_from_32(res)
        assert res_2 == ref, self.fail("Wrong encoding or decoding")
Пример #4
0
    def test_decode_RR(self):
        ttt = time.time()
        (ssrc, ntp, rtp_ts, total_packets, total_bytes, ssrc_1, \
             frac_lost, lost, highest, jitter, lsr, dlsr) \
             = (424242, ttt, 143, 100, 800, 424243, 1, 1, 65535, 15, \
                    int(time.time()-10), 10)

        frac_lost = int(lost / float(total_packets + lost))

        members = {}
        new_member = self.member.copy()
        new_member['last_ts'] = rtp_ts
        new_member['last_seq'] = highest
        new_member['jitter'] = jitter
        new_member['lost'] = lost
        new_member['lsr'] = lsr
        new_member['dlsr'] = dlsr

        members_table = {}
        members_table[ssrc_1] = new_member

        arg_list = (ssrc, members_table)

        rtcp = RTCPPacket("RR", ptcode=201, contents=arg_list)
        rtcp_pac = rtcp.encode()

        #Unpacking
        #Decoding packet
        packet = RTCPCompound(rtcp_pac)

        #Getting content of the first block
        cont = packet._rtcp[0].getContents()

        lsr = ext_32_out_of_64(lsr)
        lsr = unformat_from_32(lsr)

        dlsr = ext_32_out_of_64(dlsr)
        dlsr = unformat_from_32(dlsr)

        #Testing content decode
        assert(cont[0]== ssrc), self.fail("SSRC is not correctly encode or " \
                                              + "decode")
        assert(cont[1][0]['ssrc']==ssrc_1), \
            self.fail("SSRC_1 is not correctly encode or decode")
        assert(cont[1][0]['jitter']==jitter), \
            self.fail("Jitter is not correctly encode or decode")
        assert(cont[1][0]['fraclost']==frac_lost), \
            self.fail("Frac lost is not correctly encode or decode")

        assert(cont[1][0]['lsr']==lsr), \
            self.fail("Last received is not correctly encode or decode")
        assert(cont[1][0]['highest']==highest), \
            self.fail("Highest seq num is not correctly encode or decode")
Пример #5
0
    def round_trip_time(self, lsr, dlsr):
        """Calcule round trip time
        Caution: TO make this work all the users must use NTP to syncronize
        their wallclock"""
        #Calculate round trip time
        if lsr != 0 and dlsr != 0:
            marker_a = time()
            marker_a = ext_32_out_of_64(marker_a)
            marker_a = unformat_from_32(marker_a)
            round_trip = marker_a - dlsr - lsr
            round_trip = "%.3f" % round_trip
            round_trip_time = float(round_trip)
            #print "Round trip time " + str(round_trip_time)

            #Perform test in case ntp is not syncronize
            #if
            return round_trip_time
        else:
            return None
Пример #6
0
    def round_trip_time(self, lsr, dlsr):
        """Calcule round trip time
        Caution: TO make this work all the users must use NTP to syncronize
        their wallclock"""
        #Calculate round trip time
        if lsr != 0 and dlsr != 0:
            marker_a = time()
            marker_a = ext_32_out_of_64(marker_a)
            marker_a = unformat_from_32(marker_a)
            round_trip = marker_a - dlsr - lsr
            round_trip = "%.3f" % round_trip
            round_trip_time = float(round_trip)
            #print "Round trip time " + str(round_trip_time)

            #Perform test in case ntp is not syncronize
            #if
            return round_trip_time
        else:
            return None