基于UDP传输协议的实现分析之流量和拥塞控制

所属分类: 网络 / 网络协议 阅读数: 1684
收藏 0 赞 0 分享

  UDP的概念

  UDP 是User Datagram Protocol的简称, 中文名是用户数据报协议,是OSI(Open System Interconnection,开放式系统互联) 参考模型中一种无连接的传输层协议,提供面向事务的简单不可靠信息传送服务,IETF RFC 768是UDP的正式规范。UDP在IP报文的协议号是17。

  流量控制

  对于一个带宽1Gbps, RTT为100ms的网络来说

  BDP=1,000,000,000*0.1/8=12,500,000字节=12207K=12M

  传统TCP接收窗口大小=65535byte=64K, 显然满足不了

  udt使用包大小1500byte, 默认接口窗口大小为8192, 因此

  接收窗口的大小为=1500*8192=12,288,000字节=12000K=11.7M

  因此, 可以看到udt的默认设置已经足够.

  Congestion Control(拥塞控制)

  1. 两个重要的参数:

  congestion window size and the inter-packet sending interval

  2. 主要的接口

  1) init: when the UDT socket is connected.

  2) close: when the UDT socket is closed.

  3) onACK: when ACK is received.

  4) onLOSS: when NACK is received.

  5) onTimeout: when timeout occurs.

  6) onPktSent: when a data packet is sent.

  7) onPktRecv: when a data packet is received.

  3. udt的拥塞算法:

  On ACK packet received:

  1) If the current status is in the slow start phase, set the

  congestion window size to the product of packet arrival rate and

  (RTT + SYN). Slow Start ends. Stop.

  2) Set the congestion window size (CWND) to: CWND = A * (RTT + SYN) +16.

  3) The number of sent packets to be increased in the next SYN period

  (inc) is calculated as:

  if (B <= C)

  inc = 1/PS;

  else

  inc = max(10^(ceil(log10((B-C)*PS*8))) * Beta/PS, 1/PS);

  where B is the estimated link capacity and C is the current

  sending speed. All are counted as packets per second. PS is the

  fixed size of UDT packet counted in bytes. Beta is a constant

  value of 0.0000015.

  4) The SND period is updated as:

  SND = (SND * SYN) / (SND * inc + SYN).

  Java代码


复制代码
代码如下:
<strong>  </strong>1.Java代码
  2.*/
  3.publicvoidonACK(longackSeqno){
  4.//increasewindowduringslowstart
  5.if(slowStartPhase){
  6.congestionWindowSize+=ackSeqno-lastAckSeqNumber;
  7.lastAckSeqNumber=ackSeqno;
  8.//butnotbeyondamaximumsize
  9.if(congestionWindowSize>session.getFlowWindowSize()){
  10.slowStartPhase=false;
  11.if(packetArrivalRate>0){
  12.packetSendingPeriod=1000000.0/packetArrivalRate;
  13.}
  14.else{
  15.packetSendingPeriod=(double)congestionWindowSize/(roundTripTime+Util.getSYNTimeD());
  16.}
  17.}
  18.
  19.}else{
  20.//1.ifitisnotinslowstartphase,setthecongestionwindowsize
  21.//totheproductofpacketarrivalrateand(rtt+SYN)
  22.doubleA=packetArrivalRate/1000000.0*(roundTripTime+Util.getSYNTimeD());
  23.congestionWindowSize=(long)A+16;
  24.if(logger.isLoggable(Level.FINER)){
  25.logger.finer("receiverate"+packetArrivalRate+"rtt"+roundTripTime+"settowindowsize:"+(A+16));
  26.}
  27.}
  28.
  29.//norateincreaseduringslowstart
  30.if(slowStartPhase)return;
  31.
  32.//norateincrease"immediately"afteraNAK
  33.if(loss){
  34.loss=false;
  35.return;
  36.}
  37.
  38.//4.computetheincreaseinsentpacketsforthenextSYNperiod
  39.doublenumOfIncreasingPacket=computeNumOfIncreasingPacket();
  40.
  41.//5.updatethesendperiod
  42.doublefactor=Util.getSYNTimeD()/(packetSendingPeriod*numOfIncreasingPacket+Util.getSYNTimeD());
  43.packetSendingPeriod=factor*packetSendingPeriod;
  44.//packetSendingPeriod=0.995*packetSendingPeriod;
  45.
  46.statistics.setSendPeriod(packetSendingPeriod);
  47.}

  On NAK packet received:

  1) If it is in slow start phase, set inter-packet interval to

  1/recvrate. Slow start ends. Stop.

  2) If this NAK starts a new congestion period, increase inter-packet

  interval (snd) to snd = snd * 1.125; Update AvgNAKNum, reset

  NAKCount to 1, and compute DecRandom to a random (average

  distribution) number between 1 and AvgNAKNum. Update LastDecSeq.

  Stop.

  3) If DecCount <= 5, and NAKCount == DecCount * DecRandom:

  a. Update SND period: SND = SND * 1.125;

  b. Increase DecCount by 1;

  c. Record the current largest sent sequence number (LastDecSeq).

  Java代码


复制代码
代码如下:
  1./*(non-Javadoc)
  2.*@seeudt.CongestionControl#onNAK(java.util.List)
  3.*/
  4.publicvoidonLoss(List<Integer>lossInfo){
  5.loss=true;
  6.longfirstBiggestlossSeqNo=lossInfo.get(0);
  7.nACKCount++;
  8./*1)Ifitisinslowstartphase,setinter-packetintervalto
  9.1/recvrate.Slowstartends.Stop.*/
  10.if(slowStartPhase){
  11.if(packetArrivalRate>0){
  12.packetSendingPeriod=100000.0/packetArrivalRate;
  13.}
  14.else{
  15.packetSendingPeriod=congestionWindowSize/(roundTripTime+Util.getSYNTime());
  16.}
  17.slowStartPhase=false;
  18.return;
  19.}
  20.
  21.longcurrentMaxSequenceNumber=session.getSocket().getSender().getCurrentSequenceNumber();
  22.//2)IfthisNAKstartsanewcongestionepoch
  23.if(firstBiggestlossSeqNo>lastDecreaseSeqNo){
  24.//-increaseinter-packetinterval
  25.packetSendingPeriod=Math.ceil(packetSendingPeriod*1.125);
  26.//-UpdateAvgNAKNum(theaveragenumberofNAKspercongestion)
  27.averageNACKNum=(int)Math.ceil(averageNACKNum*0.875+nACKCount*0.125);
  28.//-resetNAKCountandDecCountto1,
  29.nACKCount=1;
  30.decCount=1;
  31./*-computeDecRandomtoarandom(averagedistribution)numberbetween1andAvgNAKNum*/
  32.decreaseRandom=(int)Math.ceil((averageNACKNum-1)*Math.random()+1);
  33.//-UpdateLastDecSeq
  34.lastDecreaseSeqNo=currentMaxSequenceNumber;
  35.//-Stop.
  36.}
  37.//*3)IfDecCount<=5,andNAKCount==DecCount*DecRandom:
  38.elseif(decCount<=5&&nACKCount==decCount*decreaseRandom){
  39.//a.UpdateSNDperiod:SNDSND=SND*1.125;
  40.packetSendingPeriod=Math.ceil(packetSendingPeriod*1.125);
  41.//b.IncreaseDecCountby1;
  42.decCount++;
  43.//c.Recordthecurrentlargestsentsequencenumber(LastDecSeq).
  44.lastDecreaseSeqNo=currentMaxSequenceNumber;
  45.}
  46.
  47.statistics.setSendPeriod(packetSendingPeriod);
  48.return;
  49.}

  以上就是基于UDP传输协议的流量和拥塞控制的代码,希望能帮到大家,谢谢阅读。

更多精彩内容其他人还在看

fiddler如何清除证书? Fiddler https证书清除图文教程

Fiddler是一个http协议调试代理工具,它能够记录并检查所有你的电脑和互联网之间的http通讯,打开主界面,就可在里面进行相关的操作,那么fiddler如何清除证书呢?下面就详情来看看fiddler清除证书具体的步骤吧
收藏 0 赞 0 分享

用示波器直接破解30种通信协议解析

数字示波器的发展极大的降低了低速总线调试的难度,传闻近日有一台示波器可以直接破解30多种通信协议,这是怎么回事呢?下面就来看看随着示波器的发展,协议解码出现了哪些变化吧
收藏 0 赞 0 分享

HTTPS协议数据加密传输基本内容解析

很多网友了解过有关于网络协议部分的内容,HTTPS协议还是一知半解的,下面这边文章就为大家简单介绍下HTTPS协议的基本内容,大家了解下,希望对大家有帮助
收藏 0 赞 0 分享

LoRa与ZigBee有什么区别?LoRa与ZigBee技术全面分析

ZigBee是基于IEEE802.15.4标准的低功耗局域网协议,LoRa 是LPWAN通信技术中的一种,那么两者之间有什么区别和联系呢?下面就详情来为大家解析下,希望对大家有帮助
收藏 0 赞 0 分享

无线网络IEEE802.11/IEEE802.3协议标准和区别

IEEE802协议是一种物理协议集,而以太网协议是由一组IEEE 802.3标准定义的局域网协议集,下面就为大家介绍下IEEE802.11/IEEE802.3协议标准和区别,大家了解下吧
收藏 0 赞 0 分享

如何屏蔽https网站、禁止访问https、禁止跳转https的方法

由于网络安全形势越发严峻,为了保护用户隐私和网络安全,越来越多的网站都开启了HTTPS,如何禁止访问HTTPS网站、如何屏蔽HTTPS网站就成为重要的网络管理工作,下面就来看看大势至“聚生网管”实现网络行为管理系统的方式吧
收藏 0 赞 0 分享

最常用路由协议RIP-1/2 OSPF IS-IS BGP的特点对比

RIP协议是最早的路由协议,OSPF是目前应用最广泛的IGP协议,IS-IS是另外一种链路状态型的路由协议,BGP协议是唯一的EGP协议,那么这几种路由协议有什么特点和不同呢?下面就一起来看看了解下
收藏 0 赞 0 分享

5G时代 HTTP和DNS协议将发生哪些变化?

HTTP和DNS这两种协议几乎已经成为家喻户晓,现在5G时代的来临,这些协议也都将发生巨大的变化,本文就介绍下HTTP和DNS这些协议在未来会如何发展的,如何改变的
收藏 0 赞 0 分享

IOT通信协议有哪些?物联网七大通信协议对比介绍

物联网简称iot,本文中为大家的是物联网的7大协议以及对比,有需要的朋友可以阅读本文参考一下
收藏 0 赞 0 分享

Apache Flink的网络协议栈详细介绍

Flink 的网络协议栈是组成 flink-runtime 模块的核心组件之一,本文中介绍了Apache Flink网络协议栈,感兴趣的朋友可以阅读本文参考一下
收藏 0 赞 0 分享
查看更多