forest-net
an overlay networks for large-scale virtual worlds
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator
RouterInProc.h
Go to the documentation of this file.
1 
9 #ifndef ROUTERINPROC_H
10 #define ROUTERINPROC_H
11 
12 #include <queue>
13 #include <map>
14 
15 #include "stdinc.h"
16 #include "Forest.h"
17 
18 #include "IfaceTable.h"
19 #include "LinkTable.h"
20 #include "ComtreeTable.h"
21 #include "RouteTable.h"
22 #include "PacketStore.h"
23 #include "CtlPkt.h"
24 #include "QuManager.h"
25 #include "Quu.h"
26 #include "IoProcessor.h"
27 #include "StatsModule.h"
28 #include "PacketLog.h"
29 
30 using namespace std::chrono;
31 using std::thread;
32 using std::mutex;
33 using std::unique_lock;
34 
35 namespace forest {
36 
37 class Router;
38 
39 class RouterInProc {
40 public:
42  ~RouterInProc();
43 
44  static void start(RouterInProc*);
45 private:
46  const static int numThreads = 100;
47  const static int maxReplies = 10000;
48  typedef high_resolution_clock::time_point timePoint;
49 
50  uint64_t now;
51 
53 
54  int maxSockNum;
55  fd_set *sockets;
56  int cIf;
57  int nRdy;
58 
60 
62  struct ThreadInfo {
63  thread thred;
66  pktx px;
67  int reps;
68  int64_t rcvSeqNum;
69  };
71  List freeThreads;
73  int64_t rcvSeqNum;
74 
75  HashSet<comt_t, Hash::u32> *comtSet;
78 
79  void run();
80  bool inBound();
81  bool outBound();
82 
83  // booting
84  int bootSock;
85  bool bootStart();
86  pktx bootReceive();
87  void bootSend(pktx);
88 
89  // basic forwarding
90  pktx receive();
91  void forward(pktx);
92  bool pktCheck(pktx,int);
93 
94  // inband control
95  void handleConnDisc(pktx);
96  void handleRteReply(pktx, int);
97  void sendRteReply(pktx,int);
98  void subUnsub(pktx,int);
99 };
100 
101 inline void RouterInProc::forward(pktx px) {
102  if (rtr->booting) bootSend(px);
103  else rtr->xferQ.enq(px);
104 }
105 
106 } // ends namespace
107 
108 #endif