| 1 | #include "packet.h" |
|---|
| 2 | #include "flow.h" |
|---|
| 3 | #include "generator.h" |
|---|
| 4 | #include "popt.h" |
|---|
| 5 | #include "unixtime.h" |
|---|
| 6 | #include "sink.h" |
|---|
| 7 | #include "otr_application.h" |
|---|
| 8 | |
|---|
| 9 | #define MAXBUFLENGTH 10000 |
|---|
| 10 | |
|---|
| 11 | #ifndef GATE_H |
|---|
| 12 | #define GATE_H |
|---|
| 13 | |
|---|
| 14 | #define MAX_STREAM_NUM_PER_GATE 16 |
|---|
| 15 | #define DEFAULT_RECV_PORT 4000 |
|---|
| 16 | |
|---|
| 17 | |
|---|
| 18 | // changes in Sep, 2005 removal of flow in OTR design |
|---|
| 19 | |
|---|
| 20 | |
|---|
| 21 | /** |
|---|
| 22 | * Gate is an abstract class for the interface to receive a packet, whether UDP, TCP Socket, or LIBMAC inteface. |
|---|
| 23 | * The common funcitons for a port are defiend here: |
|---|
| 24 | * - Receive Packet |
|---|
| 25 | * |
|---|
| 26 | * Genereally, the OTR architrecture assume one OTR could have more than one gates. Each gate is bound to only one port. |
|---|
| 27 | * Thus, if there are multiple ports used to receive packets, there are multiple gates. |
|---|
| 28 | * There is only one thread associated with each gate. One gate, one thread. The gate could have multiple flows, |
|---|
| 29 | * but unlike Port, "Gate" is in charge of reception, and flow is passive, associated with sender address and a sink. |
|---|
| 30 | */ |
|---|
| 31 | |
|---|
| 32 | class Gate |
|---|
| 33 | { |
|---|
| 34 | public: |
|---|
| 35 | Gate(); |
|---|
| 36 | virtual ~Gate(){} |
|---|
| 37 | /** |
|---|
| 38 | * Function to initialize the port |
|---|
| 39 | * @param app: OrbitApp object associate with this gate. |
|---|
| 40 | * @param sin: the default traffic sink used for this Gate, could be NULL |
|---|
| 41 | */ |
|---|
| 42 | virtual void init()=0; |
|---|
| 43 | /** |
|---|
| 44 | * Function to start an endless receiving loop |
|---|
| 45 | * This Marks the beginning of an independent receiving thread |
|---|
| 46 | */ |
|---|
| 47 | virtual void startReceive()=0; |
|---|
| 48 | /** |
|---|
| 49 | * Function to receive a packet. Support receiving multiple streams for UDP or TCP. |
|---|
| 50 | * For UDP, the default sockfd wlll be used for call recvfrom() whatever sender it is. |
|---|
| 51 | * For TCP, the default sockfd will be used for listen new connectiongs. |
|---|
| 52 | * and a new file descriptor has to be created dynamicalluy for call recv() |
|---|
| 53 | * param fd: the file descriptor to call recv or recvfrom function |
|---|
| 54 | */ |
|---|
| 55 | virtual bool receivePacket(int fd)=0; |
|---|
| 56 | /** |
|---|
| 57 | * Function to close a port |
|---|
| 58 | */ |
|---|
| 59 | virtual void closeGate()=0; |
|---|
| 60 | /** |
|---|
| 61 | * Function to get Command line Options |
|---|
| 62 | * |
|---|
| 63 | */ |
|---|
| 64 | virtual const struct poptOption* getOptions()=0; |
|---|
| 65 | |
|---|
| 66 | void configGate(OrbitApp* app, Sink* sin, int clockref=-1); |
|---|
| 67 | Flow* createFlow(int recvfd); |
|---|
| 68 | //Flow* createFlow(int recvfd, Sink * sin); |
|---|
| 69 | Flow* addFlow(int flowid, Address *src); |
|---|
| 70 | bool deleteFlow(Flow *strm); |
|---|
| 71 | Flow *searchFlowbyFd (int fd); |
|---|
| 72 | Flow *searchFlowbyAddress (Address *addr); |
|---|
| 73 | int getFlowNum(); |
|---|
| 74 | void inboundPacket(); |
|---|
| 75 | Flow* demultiplex(Address* addr); |
|---|
| 76 | protected: |
|---|
| 77 | |
|---|
| 78 | /**This pointer points to the packet. |
|---|
| 79 | * This packet is just received in OTR |
|---|
| 80 | */ |
|---|
| 81 | Packet *pkt_; |
|---|
| 82 | Flow* rlhead_; ///< This points to the head of Incoming flow List |
|---|
| 83 | Flow* rltail_; ///< This points to the tail of incoming flow List |
|---|
| 84 | Flow* rlcurr_; ///< This points to the incoming flow whose packet buffer is receving packet now... |
|---|
| 85 | Address myaddr_; ///< The default address of mine |
|---|
| 86 | Address itsaddr_; ///< This variable could be used to store the source address of incoming packet |
|---|
| 87 | UnixTime gateclock_; |
|---|
| 88 | int flownum_; |
|---|
| 89 | Sink *sin_; |
|---|
| 90 | OrbitApp *app_; |
|---|
| 91 | |
|---|
| 92 | }; |
|---|
| 93 | |
|---|
| 94 | #endif |
|---|
| 95 | |
|---|
| 96 | |
|---|