⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 uip-doc.txt

📁 spi口的超小型网络连接器
💻 TXT
📖 第 1 页 / 共 4 页
字号:
" message with the connection. This message will later be sent out bythe senddata() function.The acked() function is called whenever data that previously was senthas been acknowleged by the receiving host. This acked() functionfirst reduces the amount of data that is left to send, by subtractingthe length of the previously sent data (obtained from "uip_conn->len")from the "textlen" variable, and also adjusts the "textptr" pointeraccordingly. It then checks if the "textlen" variable now is zero,which indicates that all data now has been successfully received, andif so changes application state. If the application was in the"STATE_HELLO" state, it switches state to "STATE_WORLD" and sets up a7 byte "world!\n" message to be sent. If the application was in the"STATE_WORLD" state, it closes the connection.Finally, the senddata() function takes care of actually sending thedata that is to be sent. It is called by the event handler functionwhen new data has been received, when data has been acknowledged, whena new connection has been established, when the connection is polledbecause of inactivity, or when a retransmission should be made. Thepurpose of the senddata() function is to optionally format the datathat is to be sent, and to call the uip_send() function to actuallysend out the data. In this particular example, the function simplycalls uip_send() with the appropriate arguments if data is to be sent,after checking if data should be sent out or not as indicated by the"textlen" variable.It is important to note that the senddata() function never shouldaffect the application state; this should only be done in the acked()and newdata() functions.\section protoimpl Protocol ImplementationsThe protocols in the TCP/IP protocol suite are designed in a layeredfashion where each protocol performs a specific function and theinteractions between the protocol layers are strictly defined. Whilethe layered approach is a good way to design protocols, it is notalways the best way to implement them. In uIP, the protocolimplementations are tightly coupled in order to save code space.This section gives detailed information on the specific protocolimplementations in uIP.\subsection ip IP --- Internet ProtocolWhen incoming packets are processed by uIP, the IP layer is the firstprotocol that examines the packet. The IP layer does a few simplechecks such as if the destination IP address of the incoming packetmatches any of the local IP address and verifies the IP headerchecksum. Since there are no IP options that are strictly required andbecause they are very uncommon, any IP options in received packets aredropped.\subsubsection ipreass IP Fragment ReassemblyIP fragment reassembly is implemented using a separate buffer thatholds the packet to be reassembled. An incoming fragment is copiedinto the right place in the buffer and a bit map is used to keep trackof which fragments have been received. Because the first byte of an IPfragment is aligned on an 8-byte boundary, the bit map requires asmall amount of memory. When all fragments have been reassembled, theresulting IP packet is passed to the transport layer. If all fragmentshave not been received within a specified time frame, the packet isdropped.The current implementation only has a single buffer for holdingpackets to be reassembled, and therefore does not support simultaneousreassembly of more than one packet. Since fragmented packets areuncommon, this ought to be a reasonable decision. Extending theimplementation to support multiple buffers would be straightforward,however.\subsubsection ipbroadcast Broadcasts and MulticastsIP has the ability to broadcast and multicast packets on the localnetwork. Such packets are addressed to special broadcast and multicastaddresses. Broadcast is used heavily in many UDP based protocols suchas the Microsoft Windows file-sharing SMB protocol. Multicast isprimarily used in protocols used for multimedia distribution such asRTP. TCP is a point-to-point protocol and does not use broadcast ormulticast packets. uIP current supports broadcast packets as well assending multicast packets. Joining multicast groups (IGMP) andreceiving non-local multicast packets is not currently supported.\subsection icmp ICMP --- Internet Control Message ProtocolThe ICMP protocol is used for reporting soft error conditions and forquerying host parameters. Its main use is, however, the echo mechanismwhich is used by the "ping" program.The ICMP implementation in uIP is very simple as itis restricted toonly implement ICMP echo messages. Replies to echo messages areconstructed by simply swapping the source and destination IP addressesof incoming echo requests and rewriting the ICMP header with theEcho-Reply message type. The ICMP checksum is adjusted using standardtechniques (see RFC1624).Since only the ICMP echo message is implemented, there is no supportfor Path MTU discovery or ICMP redirect messages. Neither of these isstrictly required for interoperability; they are performanceenhancement mechanisms.\subsection tcp TCP --- Transmission Control ProtocolThe TCP implementation in uIP is driven by incoming packets and timerevents. Incoming packets are parsed by TCP and if the packet containsdata that is to be delivered to the application, the application isinvoked by the means of the application function call. If the incomingpacket acknowledges previously sent data, the connection state isupdated and the application is informed, allowing it to send out newdata.\subsubsection listeb Listening ConnectionsTCP allows a connection to listen for incoming connection requests. InuIP, a listening connection is identified by the 16-bit port numberand incoming connection requests are checked against the list oflistening connections. This list of listening connections is dynamicand can be altered by the applications in the system.\subsubsection slidingwindow Sliding WindowMost TCP implementations use a sliding window mechanism for sendingdata. Multiple data segments are sent in succession without waitingfor an acknowledgment for each segment.The sliding window algorithm uses a lot of 32-bit operations andbecause 32-bit arithmetic is fairly expensive on most 8-bit CPUs, uIPdoes not implement it. Also, uIP does not buffer sent packets and asliding window implementation that does not buffer sent packets will haveto be supported by a complex application layer. Instead, uIP allowsonly a single TCP segment per connection to be unacknowledged at anygiven time.It is important to note that even though most TCP implementations usethe sliding window algorithm, it is not required by the TCPspecifications. Removing the sliding window mechanism does not affectinteroperability in any way.\subsubsection rttest Round-Trip Time EstimationTCP continuously estimates the current Round-Trip Time (RTT) of everyactive connection in order to find a suitable value for theretransmission time-out.The RTT estimation in uIP is implemented using TCP's periodictimer. Each time the periodic timer fires, it increments a counter foreach connection that has unacknowledged data in the network. When anacknowledgment is received, the current value of the counter is usedas a sample of the RTT. The sample is used together with VanJacobson's standard TCP RTT estimation function to calculate anestimate of the RTT. Karn's algorithm is used to ensure thatretransmissions do not skew the estimates.\subsubsection rexmit RetransmissionsRetransmissions are driven by the periodic TCP timer. Every time theperiodic timer is invoked, the retransmission timer for eachconnection is decremented. If the timer reaches zero, a retransmissionshould be made.As uIP does not keep track of packet contents after they havebeen sent by the device driver, uIP requires that theapplication takes an active part in performing theretransmission. When uIP decides that a segment should beretransmitted, it calls the application with a flag set indicatingthat a retransmission is required. The application checks theretransmission flag and produces the same data that was previouslysent. From the application's standpoint, performing a retransmissionis not different from how the data originally was sent. Therefore theapplication can be written in such a way that the same code is usedboth for sending data and retransmitting data. Also, it is importantto note that even though the actual retransmission operation iscarried out by the application, it is the responsibility of the stackto know when the retransmission should be made. Thus the complexity ofthe application does not necessarily increase because it takes anactive part in doing retransmissions.\subsubsection flowcontrol Flow ControlThe purpose of TCP's flow control mechanisms is to allow communicationbetween hosts with wildly varying memory dimensions. In each TCPsegment, the sender of the segment indicates its available bufferspace. A TCP sender must not send more data than the buffer spaceindicated by the receiver.In uIP, the application cannot send more data than the receiving hostcan buffer. And application cannot send more data than the amount ofbytes it is allowed to send by the receiving host. If the remote hostcannot accept any data at all, the stack initiates the zero windowprobing mechanism.\subsubsection congestioncontrol Congestion ControlThe congestion control mechanisms limit the number of simultaneous TCPsegments in the network. The algorithms used for congestion controlare designed to be simple to implement and require only a few lines ofcode.Since uIP only handles one in-flight TCP segment per connection,the amount of simultaneous segments cannot be further limited, thusthe congestion control mechanisms are not needed.\subsubsection urgdata Urgent DataTCP's urgent data mechanism provides an application-to-applicationnotification mechanism, which can be used by an application to markparts of the data stream as being more urgent than the normalstream. It is up to the receiving application to interpret the meaningof the urgent data.In many TCP implementations, including the BSD implementation, theurgent data feature increases the complexity of the implementationbecause it requires an asynchronous notification mechanism in anotherwise synchronous API. As uIP already use an asynchronous eventbased API, the implementation of the urgent data feature does not leadto increased complexity.\section performance PerformanceIn TCP/IP implementations for high-end systems, processing time isdominated by the checksum calculation loop, the operation of copyingpacket data and context switching. Operating systems for high-endsystems often have multiple protection domains for protecting kerneldata from user processes and user processes from each other. Becausethe TCP/IP stack is run in the kernel, data has to be copied betweenthe kernel space and the address space of the user processes and acontext switch has to be performed once the data has beencopied. Performance can be enhanced by combining the copy operationwith the checksum calculation. Because high-end systems usually havenumerous active connections, packet demultiplexing is also anexpensive operation.A small embedded device does not have the necessary processing powerto have multiple protection domains and the power to run amultitasking operating system. Therefore there is no need to copydata between the TCP/IP stack and the application program. With anevent based API there is no context switch between the TCP/IP stackand the applications.In such limited systems, the TCP/IP processing overhead is dominatedby the copying of packet data from the network device to host memory,and checksum calculation. Apart from the checksum calculation andcopying, the TCP processing done for an incoming packet involves onlyupdating a few counters and flags before handing the data over to theapplication. Thus an estimate of the CPU overhead of our TCP/IPimplementations can be obtained by calculating the amount of CPUcycles needed for the checksum calculation and copying of a maximumsized packet.\subsection delack The Impact of Delayed AcknowledgmentsMost TCP receivers implement the delayed acknowledgment algorithm forreducing the number of pure acknowledgment packets sent. A TCPreceiver using this algorithm will only send acknowledgments for everyother received segment. If no segment is received within a specifictime-frame, an acknowledgment is sent. The time-frame can be as highas 500 ms but typically is 200 ms.A TCP sender such as uIP that only handles a single outstanding TCPsegment will interact poorly with the delayed acknowledgmentalgorithm. Because the receiver only receives a single segment at atime, it will wait as much as 500 ms before an acknowledgment issent. This means that the maximum possible throughput is severelylimited by the 500 ms idle time.Thus the maximum throughput equation when sending data from uIP willbe $p = s / (t + t_d)$ where $s$ is the segment size and $t_d$ is thedelayed acknowledgment timeout, which typically is between 200 and500 ms. With a segment size of 1000 bytes, a round-trip time of 40 msand a delayed acknowledgment timeout of 200 ms, the maximumthroughput will be 4166 bytes per second. With the delayed acknowledgmentalgorithm disabled at the receiver, the maximum throughput would be25000 bytes per second.It should be noted, however, that since small systems running uIP arenot very likely to have large amounts of data to send, the delayedacknowledgmen t throughput degradation of uIP need not be verysevere. Small amounts of data sent by such a system will not span morethan a single TCP segment, and would therefore not be affected by thethroughput degradation anyway.The maximum throughput when uIP acts as a receiver is not affected bythe delayed acknowledgment throughput degradation.*//** @} */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -