Esempio n. 1
0
    def bandwidth_latency_loss_test(self, direction, bw_tx, bw_limit, latency, loss,
                                    expected_bw = None, expected_loss = None, expected_latency = None):
        self.reset_tc_rules_via_dynreconf()
        config = self.dynclient.update_configuration({ "bandwidth_" + direction: bw_limit, 
                                                       "latency_" + direction: latency,
                                                       "loss_" + direction: loss })

        self.assertTrue(config['status'] == "OK",
                        "Operation FAILed: " + config['errmsg'])

        test = self.srcnode.create_test(bw = bw_tx, pktsize = 1500, duration = 5.0,
                                        sink_ip = "127.0.0.1", sink_port = 12345,
                                        bw_type = LinktestGoal.BW_CONSTANT, max_return_time = 0.01)
        test.start()
        time.sleep(5.5)
        self.assertTrue(test.done, "Test should have finished already")

        (expected_bw, expected_latency, expected_loss) = get_projected_link_metrics(bw_limit, latency, loss, 1500.0, bw_tx)

        print "bw_limit: ", bw_limit, "loss: ", loss, "latency: ", latency, "bw_tx: ", bw_tx
        print "meas_bw: ", test.bandwidth.avg(), " meas_latency: ", test.latency.avg()*1e3, " meas_loss: ", test.loss.avg()
        print "exp_bw", expected_bw, " exp_latency: ", expected_latency * 1e3, " exp_loss: ", expected_loss
        self.assertTrue(test.bandwidth.avg() > expected_bw * 0.75  and test.bandwidth.avg() < expected_bw * 1.25,
                        "Expected measured bandwidth to be ~%.2fMbit/s, instead it was %.2fMbit/s"%
                        (expected_bw/1e6, test.bandwidth.avg()/1e6))
        self.assertTrue(test.latency.avg() > expected_latency - 0.015  and test.latency.avg() < expected_latency + 0.015,
                        "Expected latency to be ~%.2fms, instead it was %.2fms"%
                        (expected_latency * 1e3, test.latency.avg() * 1e3))
        self.assertTrue((test.loss.avg() < 4.0 and expected_loss < 2.0) or 
                        (test.loss.avg() > expected_loss - 10.0  and test.latency.avg() < expected_loss + 10.0),
                        "Expected loss to be ~%.2f%%, instead it was %.2f%%"%
                        (expected_loss, test.loss.avg()))
def measure_link(tx_bandwidth, bandwidth_limit, latency, loss,
                 packet_size, max_allowed_latency, max_return_time,
                 sink_ip, direction, duration):
    (proj_bandwidth, proj_latency, proj_loss) = get_projected_link_metrics(bandwidth_limit, latency, loss, \
                                                                           packet_size, tx_bandwidth)
    if proj_latency > max_allowed_latency:
        rospy.logerr("Max allowed latency %.2fms is smaller than projected latency %.2fms,"
                     "results will be flawed, exiting", max_allowed_latency * 1e3, proj_latency * 1e3)
        exit(1)

    dynclient = dynamic_reconfigure.client.Client("tc")
    config = dynclient.update_configuration({"bandwidth_egress" : 0.0, "bandwidth_ingress" : 0.0,
                                             "latency_egress" : 0.0, "latency_ingress" : 0.0,
                                             "loss_egress" : 0.0, "loss_ingress" : 0.0 })
    if config['status'] != "OK":
        rospy.logerr("Initalizing tc node failed: " + config['errmsg'])
        exit(1)
    config = dynclient.update_configuration({"bandwidth_" + direction: bandwidth_limit, 
                                             "latency_" + direction: latency,
                                             "loss_" + direction: loss })
    if config['status'] != "OK":
        rospy.logerr("Setting tc node config failed: " + config['errmsg'])

    srcnode = UdpmonsourceHandle('performance_test')
    test = srcnode.create_test(bw = tx_bandwidth, pktsize = packet_size, duration = duration,
                               sink_ip = sink_ip, sink_port = 12345,
                               bw_type = LinktestGoal.BW_CONSTANT, max_return_time = max_return_time,
                               latencybins = [ max_allowed_latency/4, max_allowed_latency/2, max_allowed_latency])
    test.start()

    time.sleep(duration + 0.5)
    
    rospy.loginfo("Link measurement completed!")
    rospy.loginfo("Link parameters: bandwidth_limit %.2fkbit/s latency %.2fms loss %.2f%% tx_bandwidth %.2fkbit/s\n"
                  "                 packet_size %dbytes max_allowed_latency %.2fms max_return_time %.2fms\n"
                  "                 direction %s duration %.2fs",
                  bandwidth_limit/1e3, latency*1e3, loss, tx_bandwidth/1e3, packet_size, max_allowed_latency*1e3,
                  max_return_time*1e3, direction, duration)
    rospy.loginfo("\nRESULTS: measured_bandwidth %.2fkbit/s measured_latency %.2fms measured_loss %.2f%%",
                  test.bandwidth.avg()/1e3, test.latency.avg() * 1e3, test.loss.avg())
def measure_link(
    tx_bandwidth,
    bandwidth_limit,
    latency,
    loss,
    packet_size,
    max_allowed_latency,
    max_return_time,
    sink_ip,
    direction,
    duration,
):
    (proj_bandwidth, proj_latency, proj_loss) = get_projected_link_metrics(
        bandwidth_limit, latency, loss, packet_size, tx_bandwidth
    )
    if proj_latency > max_allowed_latency:
        rospy.logerr(
            "Max allowed latency %.2fms is smaller than projected latency %.2fms," "results will be flawed, exiting",
            max_allowed_latency * 1e3,
            proj_latency * 1e3,
        )
        exit(1)

    dynclient = dynamic_reconfigure.client.Client("tc")
    config = dynclient.update_configuration(
        {
            "bandwidth_egress": 0.0,
            "bandwidth_ingress": 0.0,
            "latency_egress": 0.0,
            "latency_ingress": 0.0,
            "loss_egress": 0.0,
            "loss_ingress": 0.0,
        }
    )
    if config["status"] != "OK":
        rospy.logerr("Initalizing tc node failed: " + config["errmsg"])
        exit(1)
    config = dynclient.update_configuration(
        {"bandwidth_" + direction: bandwidth_limit, "latency_" + direction: latency, "loss_" + direction: loss}
    )
    if config["status"] != "OK":
        rospy.logerr("Setting tc node config failed: " + config["errmsg"])

    srcnode = UdpmonsourceHandle("performance_test")
    test = srcnode.create_test(
        bw=tx_bandwidth,
        pktsize=packet_size,
        duration=duration,
        sink_ip=sink_ip,
        sink_port=12345,
        bw_type=LinktestGoal.BW_CONSTANT,
        max_return_time=max_return_time,
        latencybins=[max_allowed_latency / 4, max_allowed_latency / 2, max_allowed_latency],
    )
    test.start()

    time.sleep(duration + 0.5)

    rospy.loginfo("Link measurement completed!")
    rospy.loginfo(
        "Link parameters: bandwidth_limit %.2fkbit/s latency %.2fms loss %.2f%% tx_bandwidth %.2fkbit/s\n"
        "                 packet_size %dbytes max_allowed_latency %.2fms max_return_time %.2fms\n"
        "                 direction %s duration %.2fs",
        bandwidth_limit / 1e3,
        latency * 1e3,
        loss,
        tx_bandwidth / 1e3,
        packet_size,
        max_allowed_latency * 1e3,
        max_return_time * 1e3,
        direction,
        duration,
    )
    rospy.loginfo(
        "\nRESULTS: measured_bandwidth %.2fkbit/s measured_latency %.2fms measured_loss %.2f%%",
        test.bandwidth.avg() / 1e3,
        test.latency.avg() * 1e3,
        test.loss.avg(),
    )