基于UDP傳輸協(xié)議的實現(xiàn)分析之流量和擁塞控制

UDP的概念
UDP 是User Datagram Protocol的簡稱, 中文名是用戶數(shù)據(jù)報協(xié)議,是OSI(Open System Interconnection,開放式系統(tǒng)互聯(lián)) 參考模型中一種無連接的傳輸層協(xié)議,提供面向事務(wù)的簡單不可靠信息傳送服務(wù),IETF RFC 768是UDP的正式規(guī)范。UDP在IP報文的協(xié)議號是17。
流量控制
對于一個帶寬1Gbps, RTT為100ms的網(wǎng)絡(luò)來說
BDP=1,000,000,000*0.1/8=12,500,000字節(jié)=12207K=12M
傳統(tǒng)TCP接收窗口大小=65535byte=64K, 顯然滿足不了
udt使用包大小1500byte, 默認接口窗口大小為8192, 因此
接收窗口的大小為=1500*8192=12,288,000字節(jié)=12000K=11.7M
因此, 可以看到udt的默認設(shè)置已經(jīng)足夠.
Congestion Control(擁塞控制)
1. 兩個重要的參數(shù):
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代碼
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代碼
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傳輸協(xié)議的流量和擁塞控制的代碼,希望能幫到大家,謝謝閱讀。
相關(guān)文章
三大網(wǎng)絡(luò)管理協(xié)議:SNMP、NETCONF、RESTCONF介紹
本文將詳細介紹三種主要的協(xié)議:SNMP(Simple Network Management Protocol)、NETCONF(Network Configuration Protocol)和RESTCONF,需要的朋友可以參考下2024-02-13- 常見的網(wǎng)絡(luò)協(xié)議有:TCP/IP協(xié)議、UDP協(xié)議、HTTP協(xié)議、FTP協(xié)議等,本文就詳細的介紹一下常見的網(wǎng)絡(luò)協(xié)議,通過這些具體的協(xié)議更深刻的認識整體網(wǎng)絡(luò)的傳輸流程及相關(guān)網(wǎng)絡(luò)原理,2023-05-30
- 本文主要介紹了L2TP和PPTP的區(qū)別,主要的前區(qū)別在于用途不同、使用要求不同,下面就來介紹一下L2TP和PPTP的聯(lián)系與區(qū)別,感興趣的可以了解一下2023-05-30
自組織網(wǎng)絡(luò)Ad Hoc之OLSR 協(xié)議詳解
這篇文章主要介紹了自組織網(wǎng)絡(luò)Ad Hoc之OLSR 協(xié)議詳解,需要的朋友可以參考下2023-05-08自組織網(wǎng)絡(luò)Ad Hoc之AODV協(xié)議詳解
這篇文章主要介紹了自組織網(wǎng)絡(luò)Ad Hoc之AODV協(xié)議詳解,需要的朋友可以參考下2023-05-08自組織網(wǎng)絡(luò)Ad Hoc 網(wǎng)絡(luò)基礎(chǔ)知識
自組織網(wǎng)絡(luò)(Ad Hoc)是一種移動通信和計算機網(wǎng)絡(luò)相結(jié)合的網(wǎng)絡(luò),是移動計算機網(wǎng)絡(luò)的一種,用戶終端可以在網(wǎng)絡(luò)內(nèi)隨意移動而保持通信2023-05-08- 瀏覽器輸入一個URL回車后,會發(fā)生什么呢?這里就為大家分享一下,需要的朋友可以參考下2022-10-19
- 本篇主要是對網(wǎng)絡(luò)協(xié)議進行一個歸納總結(jié),方便后續(xù)查閱及復(fù)習,當然如有新的認知或新的理解,也會持續(xù)更新2022-10-19
- 今日回顧網(wǎng)絡(luò)知識時,發(fā)現(xiàn)自己專門整理過一篇關(guān)于日常生活中常見的網(wǎng)絡(luò)協(xié)議知識以及作用的梳理,特發(fā)此一貼,也當給自己鞏固網(wǎng)絡(luò)知識了,如有錯誤,望各大佬指正2022-10-19
- HTTP即超文本傳輸協(xié)議,是一種實現(xiàn)客戶端和服務(wù)器之間通信的響應(yīng)協(xié)議,它是用作客戶端和服務(wù)器之間的請求,需要的朋友可以參考下2022-10-19