突然想起一个毕设的遗留问题----对实际带宽估计。
当时想到一个简单的方式对网络情况不复杂的带宽进行测试,可行性还需进一步确认。论坛里无人答复,默泪点击打开链接
大致原理:在链路上没有其他数据流量的情况下,用高于带宽的吞吐量发送UDP包,然后在收端统计收包或丢包数量,对实际带宽进行估计。
程序很简单,定义一个包含序列号的UDP包,链路两端一收一发,最后统计收发包数量即可。
PS:当时还统计了双方时间戳,用于测量两端时延,没有去掉该部分直接附上来了
包定义:
#ifndef STRUCT_H
#define STRUCT_H
struct udp_packet
{
long int sendtime; //发送时间戳
unsigned long int seq; //数据包序列号
};
#endi
发送端:
#include<stdio.h>
#include<stdlib.h>
#include<netinet/in.h>
#include<sys/socket.h>
#include<sys/types.h>
#include<sys/time.h>
#include<string.h>
#include<time.h>
#include"struct.h