📄 t-cc.htm
字号:
<html><head><meta http-equiv="Content-Language" content="en-us"><meta http-equiv="Content-Type" content="text/html; charset=windows-1252"><title>UDT Reference</title></head><body><table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" width="100%" id="table8" bgcolor="#99CCFF" bordercolor="#99CCFF"> <tr> <td width="100%"><font face="Verdana" size="2"><i> UDT </i></font><i> <font face="Verdana" size="2">Tutorial</font></i></td> </tr></table><h1><font face="Verdana" size="4">Add New Congestion Control Algorithm</font></h1><p><font face="Verdana" size="2"><b><font color="#FF0000">STOP</font></b>: Make surethat you have uncommented the -DCUSTOM_CC compiler option in ./src/Makefile.Otherwise your control algorithm will NOT be used.</font></p><p><font face="Verdana" size="2">You can add your own congestion control algorithm into UDT. It is as simple as to define several callback functions that will be triggered on certain events, e.g, when an ACK is received.</font></p><p><font face="Verdana" size="2">All the congestion control callback functions are collected in a C++ class <b><a href="ccc.htm">CCC</a></b>. You have to inherit this class to define your own congestion control algorithm. That is, UDT/CCC uses an object-oriented design. CCC in defined in ccc.h, which you have to include in your files in order to enable this feature.</font></p><p><font face="Verdana" size="2">The CCC class contains two control variables: <a href="ccc.htm#11">m_dPktSndPeriod</a>, and <a href="ccc.htm#12">m_dCWndSize</a>. <a href="ccc.htm#11">m_dPktSndPeriod</a> is a double float number representing the packet sending period (as to be used in rate control), in microseconds. <a href="ccc.htm#12">m_dCWndSize</a> is a double float number representing the size of the congestion window (cwnd), in number of packets. The congestion control algorithm will need to update at least one of them. For example, for pure window based approach, <a href="ccc.htm#11">m_dPktSndPeriod</a> should always be zero.</font></p><p><font face="Verdana" size="2">The fast way to learn CCC is to use the examples in ./app/cc.h. The file cc.h also includes many more advanced control mechanisms that your control classes can be derived from. For example, if you are designing a new TCP variant, you can implement the new control class directly from CTCP.</font></p><p><font face="Verdana" size="2">Here we demonstrate the usage of UDT/CCC by writing a reliable UDP blast control mechanism.</font></p><table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" width="100%" id="table9" bgcolor="#C0C0C0" bordercolor="#C0C0C0"> <tr> <td width="100%"> <p style="margin-top: 0; margin-bottom: 0"> <font face="Courier New" size="1">class CUDPBlast: public CCC<br> {<br> public:<br> CUDPBlast() {m_dCWndSize = 83333.0;}<br> <br> public:<br> void setRate(int mbps)<br> {<br> m_dPktSndPeriod = (m_iSMSS * 8.0) / mbps;<br> }<br> <br> protected:<br> static const int m_iSMSS = 1500;<br> };</font></p> </td> </tr></table><p><font face="Verdana" size="2">In this example, <i>CUDPBlast</i> inherits from the base class <b><a href="ccc.htm">CCC</a></b>. In the constructor, it sets the congestion window size to a large value so that it will not affect the packet sending. (This is pure rate based method to blast UDP packets.) The method <i>SetRate()</i> can be used to set a fixed packet sending rate at any time.</font></p><p><font face="Verdana" size="2">The application can use <b><a href="opt.htm">setsockopt/getsockopt</a></b> to assign this control class to a UDT instance, and/or set its parameters.</font></p><table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" width="100%" id="table10" bgcolor="#C0C0C0" bordercolor="#C0C0C0"> <tr> <td width="100%"> <p style="margin-top: 0; margin-bottom: 0"> <font face="Courier New" size="1">UDT::setsockopt(usock, 0, UDT_CC, new CCCFactory<CUDPBlast>, sizeof(CCCFactory<CUDPBlast>));</font></p> </td> </tr></table><p><font face="Verdana" size="2">The above code assigns the <i>CUDPBlast</i> control algorthm to a UDT socket <i>usock</i>. Note that <i>CCCFactory<CUDPBlast></i> is using the Abstract Factory design pattern.</font></p><p><font face="Verdana" size="2">To set a specific data sending rate, the application needs to obtain a handle to the concrete CCC class instance used by the UDT socket <i>usock</i>.</font></p><table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" width="100%" id="table11" bgcolor="#C0C0C0" bordercolor="#C0C0C0"> <tr> <td width="100%"> <p style="margin-top: 0; margin-bottom: 0"> <font face="Courier New" size="1">CUDPBlast* cchandle = NULL;<br> int temp;<br> UDT::getsockopt(usock, 0, UDT_CC, &cchandle, &temp);</font></p> </td> </tr></table><p><font face="Verdana" size="2">The application can then call the method of <i>setRate() </i>to set a 500Mbps data rate.</font></p><table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" width="100%" id="table12" bgcolor="#C0C0C0" bordercolor="#C0C0C0"> <tr> <td width="100%"> <p style="margin-top: 0; margin-bottom: 0"> <font face="Courier New" size="1">if (NULL != cchandle)<br> cchandle->setRate(500);</font></p> </td> </tr></table><p><font face="Verdana" size="2">The UDT/CCC can be used to implement most control mechanims, including but not limited to rate-based approaches, TCP variants (e.g., TCP, Scalable, HighSpeed, BiC, Vegas, FAST), and group-based approaches (e.g., GTP, CM).</font></p><H4><font face="Verdana" size="2">Note</font></H4><p><font face="Verdana" size="2">Do NOT call regular UDT API inside CCC or its derived classes. Unknown error could happen.</font></p><p><font face="Verdana" size="2">CCCFactory<...> is a C++ template class. You do not need to derive any classes from it.</font></p><p><font face="Verdana" size="2">UDT will not release the CCCFactory<...> instance. The application should release it, at anywhere after the setsockopt() call.</font></p><H4><font face="Verdana" size="2">See Also</font></H4><P><b><font face="Verdana" size="2"><a href="ccc.htm">Congestion Control Class</a></font></b></P></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -