12 #include <sys/types.h>
13 #include <sys/socket.h>
14 #include <netinet/in.h>
15 #include <netinet/tcp.h>
16 #include <arpa/inet.h>
32 using namespace grafalgo;
120 static const uint8_t FOREST_VERSION = 1;
121 static const int HDR_LENG = 20;
122 static const int MAX_PLENG = 1450;
123 static const int OVERHEAD = 24;
130 static const ipp_t CC_PORT = 30121;
131 static const ipp_t CM_PORT = 30122;
132 static const ipp_t ROUTER_PORT = 30123;
135 static const short int MAXINTF= 20;
136 static const short int MAXLNK = 1000;
137 static const int MINBITRATE = 1;
138 static const int MAXBITRATE = 900000;
139 static const int MINPKTRATE = 1;
140 static const int MAXPKTRATE = 450000;
141 static const uint32_t BUF_SIZ = 1600;
149 static bool validUcastAdr(
fAdr_t);
150 static bool mcastAdr(
fAdr_t);
151 static int zipCode(
fAdr_t);
152 static int localAdr(
fAdr_t);
153 static fAdr_t forestAdr(
int,
int);
154 static fAdr_t forestAdr(
const char*);
155 static string fAdr2string(
fAdr_t);
156 static bool readForestAdr(istream&,
fAdr_t&);
159 static int truPktLeng(
int);
160 static string nodeType2string(
ntyp_t);
161 static ntyp_t getNodeType(
string&);
165 typedef uint32_t buffer_t[Forest::BUF_SIZ/
sizeof(uint32_t)];
172 inline bool Forest::validUcastAdr(
fAdr_t adr) {
173 return adr > 0 && zipCode(adr) != 0 && localAdr(adr) != 0;
180 inline bool Forest::mcastAdr(
fAdr_t adr) {
return adr < 0; }
187 inline int Forest::zipCode(
fAdr_t adr) {
return (adr >> 16) & 0x7fff; }
194 inline int Forest::localAdr(
fAdr_t adr) {
return adr & 0xffff; }
202 inline fAdr_t Forest::forestAdr(
int zip,
int local ) {
203 return ((zip & 0xffff) << 16) | (local & 0xffff);
216 inline fAdr_t Forest::forestAdr(
const char *fas) {
217 int zip, local, mcAdr;
218 if (sscanf(fas,
"%d.%d", &zip, &local) == 2 && zip > 0 && local > 0) {
219 return forestAdr(zip,local);
221 else if (sscanf(fas,
"%d", &mcAdr) == 1 && mcAdr < 0)
232 inline string Forest::fAdr2string(
fAdr_t fAdr) {
234 if (mcastAdr(fAdr)) ss << fAdr;
235 else ss << zipCode(fAdr) <<
"." << localAdr(fAdr);
245 inline int Forest::truPktLeng(
int x) {
return 70+x; }