YellowPages.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #define DEBUG_YELLOWPAGES 0
00028
00029
00030 #ifndef __YELLOW_PAGES_H_
00031 #define __YELLOW_PAGES_H_
00032
00033 #ifdef MIP_HOST_APPLE
00034 #include <applePatch.h>
00035 #endif
00036
00037 #include <vector>
00038 #include <stdlib.h>
00039 #include <iostream>
00040 #include <string.h>
00041 #include <sstream>
00042 #include <fstream>
00043
00044
00045
00046 #include <CommonOptions.h>
00047
00048 using namespace std;
00049
00050
00051 namespace MipResources{
00053
00054
00055
00056 enum IPProtocol{
00057 TCP,
00058 UDP,
00059 PROTOCOL_NUM
00060 };
00061
00062 static const char* IPProtocolNames[PROTOCOL_NUM] = {
00063 "TCP",
00064 "UDP"
00065 };
00066
00067
00071 class YellowPage{
00072 public:
00073 int name;
00074 IPProtocol prot;
00075 string IP;
00076 int port;
00077 bool rx;
00078 bool tx;
00080 int state;
00081
00083 YellowPage(){
00084 }
00086 YellowPage(int n, IPProtocol p, string &ip, int po, bool r, bool t, int s){
00087 name = n;
00088 prot = p;
00089 IP = ip;
00090 port = po;
00091 rx = r;
00092 tx = t;
00093 state = s;
00094 }
00096 YellowPage(const YellowPage& A){
00097 name = A.name;
00098 prot = A.prot;
00099 IP = A.IP;
00100 port = A.port;
00101 rx = A.rx;
00102 tx = A.tx;
00103 state = A.state;
00104 }
00105
00107 void operator=(const YellowPage& A){
00108 name = A.name;
00109 prot = A.prot;
00110 IP = A.IP;
00111 port = A.port;
00112 rx = A.rx;
00113 tx = A.tx;
00114 state = A.state;
00115 }
00117 string print(){
00118 stringstream s;
00119
00120 s << name << " " ;
00121
00122 if (prot == UDP) s << "UDP";
00123 else if (prot == TCP) s << "TCP";
00124
00125 s << " " << IP << " " << port;
00126
00127 if (rx) s << " rx";
00128 if (tx) s << " tx";
00129 s << " " << state;
00130
00131 return s.str();
00132 }
00133 };
00134
00138 class YellowPages : public vector<YellowPage>{
00139 private:
00140 ScenarioType scenary;
00141 int myId;
00142
00143 void computeLine(string line, IPProtocol protocol);
00144
00145 public:
00146
00150 YellowPages(ScenarioType scen, int id);
00151
00156 int getCommParams(int *broadPort, int *listPort, string *subnet);
00157
00159 int getAddrPort();
00160
00162 string print(){
00163 stringstream s;
00164
00165 int siz = size();
00166 for(int i = 0; i < siz; i++)
00167 s << (*this)[i].print() << endl;
00168 return s.str();
00169 }
00170
00172 int find(int a, IPProtocol p);
00173
00174
00175 void set(int a, IPProtocol p){
00176 (*this)[find(a, p)].state = 0;
00177 }
00178 };
00179
00180
00181
00182 };
00183
00184
00185 #endif
00186
00187
00188
00189