[wiki:WikiStart Orbit] > [wiki:Documentation/OTG OTG] > [wiki:Documentation/OTG/FuncSpec Function Specifications] > Class Gate = Gate = [source:otg/trunk/src/cpp/gate.h#latest Gate] is an abstract class for the interface to receive a packet, whether UDP, TCP Socket, or LIBMAC interface. The most basic virtual function for a gate is defined here: * receivePacket Generally, the OTR architecture assume one OTR could have more than one gates. Each gate is bound to only one port number. Thus, if there are multiple ports used to receive packets, there are multiple gates. There is only one thread associated with each gate. One gate, one thread. The gate could have multiple flows, but unlike [source:otg/trunk/src/cpp/port.h#latest Port], "Gate" is in charge of reception, and ''Flow'' is passive, associated with one sender address. [[Image(classGate.png)]] == De-multiplexing incoming packets == A link table data structure is used to store the sender information of all received packets. Each entry of sender information is defined as a class [source:otg/trunk/src/cpp/flow.h#latest Flow]. there are three points are defined to browse this data structure. * rlhead_ : This points to the head of Incoming flow List. * rltail_ : This points to the tail of incoming flow List. * rlcurr_ : This points to the current position of incoming flow list List of functions in Gate class to handle this flow list. * createFlow * addFlow * deleteFlow * searchFlowbyFd * searchFlowbyAddress * getFlowNum == Functions to prepare Gate opertion == To initialize the Gate object, there are two functions need to be called. * '''init''': the implementation of this depends on different child classes. * '''configGate''': this is used to bind the Gate object to the [source:otg/trunk/src/cpp/orbitapp.h#latest OrbitApp] and [source:otg/trunk/src/cpp/sink.h#latest Sink] objects. * '''startReceive''': when a Gate thread (receiving thread) is initialized by the OTR main function, this function is called to do final preparations. == Receive Operation == ''receivePacket'' is a virtual function for packet reception operation. In general, receivePacket are occurred in a per-packet basis. After it is called, for TCP sockets, recv() functions. For UDP and RAW sockets, recvfrom() functions are used to receive data. It is in the default blocking socket mode. So, when ''recv'' and ''recvfrom'' socket function is called, unless some packets or bytes are retrieved, this thread is blocked.