forest-net
an overlay networks for large-scale virtual worlds
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator
NetMgr.h
Go to the documentation of this file.
1 
9 #ifndef NETMGR_H
10 #define NETMGR_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 "Queue.h"
21 #include "CpHandler.h"
22 #include "Substrate.h"
23 #include "NetBuffer.h"
24 #include "Logger.h"
25 #include <map>
26 
27 #ifdef DB_MODE
28  #include "DBConnector.h"
29 #else
30  #include "AdminTable.h"
31 #endif
32 
33 namespace forest {
34 
35 
42 ipa_t myIp;
43 fAdr_t myAdr;
44 fAdr_t rtrAdr;
47 int netMgr;
48 int nmRtr;
49 
50 Logger *logger;
52 
53 #ifndef DB_MODE
55 #endif
56 
57 NetInfo *net;
59 
60 Substrate *sub;
61 
62 // Information relating client addresses and router addresses
63 // This is a temporary expedient and will be replaced later
64 int numPrefixes;
65 struct prefixInfo {
66  string prefix;
67  fAdr_t rtrAdr;
68 };
69 struct clientInfo {
70  ipa_t cliIp;
71  fAdr_t rtrAdr;
72  fAdr_t cliAdr;
73  ipa_t rtrIp;
74 };
75 prefixInfo prefixes[1000];
76 
77 #ifdef DB_MODE
78  DBConnector *dbConn; //DB Connector
79 #else
80  char *dummyRecord;
81  int maxRecord;
82 
83  fstream adminFile;
84  pthread_mutex_t adminFileLock;
85 #endif
86 
87 
88 static int const RECORD_SIZE = 256;
89 
90 bool init(const char*);
91 bool readPrefixInfo(char*);
92 
93 void* handler(void *);
94 bool handleConsole(int,CpHandler&);
95 bool handleConDisc(int,CtlPkt&,CpHandler&);
98 bool handleBootLeaf(int,CtlPkt&,CpHandler&);
100 
101 bool login(NetBuffer&,string&,string&);
102 bool newAccount(NetBuffer&,string&,string&);
103 void getProfile(NetBuffer&, string&, string&);
104 void updateProfile(NetBuffer&, string&, string&);
105 void changePassword(NetBuffer&, string&, string&);
106 void writeAdminRecord(int);
107 
108 void getLinkTable(NetBuffer&, string&, CpHandler&);
109 void getComtreeTable(NetBuffer&, string&, CpHandler&);
110 void getIfaceTable(NetBuffer&, string&, CpHandler&);
111 void getRouteTable(NetBuffer&, string&, CpHandler&);
112 
113 void addFilter(NetBuffer&, string&, CpHandler&);
114 void modFilter(NetBuffer&, string&, CpHandler&);
115 void dropFilter(NetBuffer&, string&, CpHandler&);
116 void getFilter(NetBuffer&, string&, CpHandler&);
117 void getFilterSet(NetBuffer&, string&, CpHandler&);
118 void getLoggedPackets(NetBuffer& buf, string& reply, CpHandler& cph);
119 void enablePacketLog(NetBuffer& buf, string& reply, CpHandler& cph);
120 
121 uint64_t generateNonce();
122 fAdr_t setupLeaf(int, pktx, CtlPkt&, int, int, uint64_t,CpHandler&,bool=false);
123 bool setupEndpoint(int, int, pktx, CtlPkt&, CpHandler&, bool=false);
124 bool setupComtree(int, int, pktx, CtlPkt&, CpHandler&, bool=false);
125 bool processReply(pktx, CtlPkt&, pktx, CtlPkt&, CpHandler&, const string&);
126 
127 void sendToCons(int);
128 int recvFromCons();
129 
130 bool findCliRtr(ipa_t,fAdr_t&);
131 
132 } // ends namespace
133 
134 
135 #endif