forest-net
an overlay networks for large-scale virtual worlds
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator
ComtCtl.h
Go to the documentation of this file.
1 
9 #ifndef COMTCTL_H
10 #define COMTCTL_H
11 
12 #include <pthread.h>
13 #include "Forest.h"
14 #include "Packet.h"
15 #include "PacketStoreTs.h"
16 #include "NetInfo.h"
17 #include "ComtInfo.h"
18 #include "UiSetPair.h"
19 #include "IdMap.h"
20 #include "Heap.h"
21 #include "Queue.h"
22 #include "NetBuffer.h"
23 #include "Logger.h"
24 #include "Substrate.h"
25 #include "CpHandler.h"
26 #include <map>
27 
28 namespace forest {
29 
30 
36 ipa_t nmIp;
37 fAdr_t nmAdr;
38 ipa_t myIp;
39 fAdr_t myAdr;
40 fAdr_t rtrAdr;
41 
42 PacketStoreTs *ps;
43 
46 Substrate *sub;
47 
48 Logger *logger;
49 
51 int firstComt, lastComt;
52 UiSetPair *comtSet;
53 pthread_mutex_t comtSetLock;
54 
55 // pair of queues used by a thread
56 struct QueuePair {
57 Queue in;
58 Queue out;
59 };
60 
61 // display handler queue definitions
62 struct EventStruct {
63  int comt;
64  int rtr;
65  int upDown;
66 };
67 
68 static const int NORESPONSE = (1 << 31);
69 
70 // defines thread pool
71 static const int TPSIZE = 500;
72 struct ThreadInfo {
73  pthread_t thid;
75  uint64_t seqNum;
76  uint64_t ts;
77 };
79 UiSetPair *threads;
80 IdMap *reqMap;
81 
82 IdMap *tMap;
83 
84 
85 bool init(ipa_t, ipa_t, int, int, const char *topoFile);
86 bool bootMe(ipa_t, ipa_t, fAdr_t&, fAdr_t&, fAdr_t&, ipa_t&, ipp_t&,
87  uint64_t&);
88 void cleanup();
89 void* run(void*);
90 
91 // handlers for various operations
92 void* handler(void *);
93 bool handleComtreeDisplay(int);
94 bool handleAddComtReq(int,CtlPkt&, CpHandler&);
95 bool handleDropComtReq(int,CtlPkt&, CpHandler&);
96 bool handleJoinComtReq(int,CtlPkt&, CpHandler&);
97 bool handleLeaveComtReq(int,CtlPkt&, CpHandler&);
98 bool handleComtPath(int,CtlPkt&, CpHandler&);
99 bool handleComtNewLeaf(int,CtlPkt&, CpHandler&);
100 bool handleComtPrune(int,CtlPkt&, CpHandler&);
101 
102 void removeSubtree(int, fAdr_t);
103 
104 // helper functions for allocating comtree numbers from pool
105 int newComtreeNum();
106 void releaseComtreeNum(int);
107 
108 // helper funnctions for coniguring routers to add/remove paths to comtrees
109 bool setupPath(int, list<LinkMod>&, CpHandler&);
110 bool teardownPath(int, list<LinkMod>&, CpHandler&);
111 bool setupComtNode(int, int, CpHandler&);
112 bool teardownComtNode(int, int, CpHandler&);
113 bool setupComtLink(int, int, int, CpHandler&);
114 int setupClientLink(int, fAdr_t, int, CpHandler&);
115 bool teardownClientLink(int, fAdr_t, int, CpHandler&);
116 bool setupComtAttrs(int, int, CpHandler&);
117 bool setComtLinkRates(int, int, int, CpHandler&);
118 bool setComtLeafRates(int, fAdr_t, CpHandler&);
119 bool modComtRates(int, list<LinkMod>&, bool, CpHandler&);
120 
121 void connect();
122 void disconnect();
123 
124 void sendToRemote(int);
125 int recvFromRemote();
126 
127 void sendToForest(int);
128 int rcvFromForest();
129 
130 } // ends namespace
131 
132 #endif