YellowPages.h

Go to the documentation of this file.
00001 // ----------------------------------------------------------------------------
00002 //
00003 // $Id$
00004 //
00005 // Copyright 2008, 2009, 2010, 2011, 2012  Antonio Franchi and Paolo Stegagno    
00006 //
00007 // This file is part of MIP.
00008 //
00009 // MIP is free software: you can redistribute it and/or modify
00010 // it under the terms of the GNU General Public License as published by
00011 // the Free Software Foundation, either version 3 of the License, or
00012 // (at your option) any later version.
00013 //
00014 // MIP is distributed in the hope that it will be useful,
00015 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017 // GNU General Public License for more details.
00018 //
00019 // You should have received a copy of the GNU General Public License
00020 // along with MIP. If not, see <http://www.gnu.org/licenses/>.
00021 //
00022 // Contact info: antonio.franchi@tuebingen.mpg.de stegagno@diag.uniroma1.it
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 // #include <Parameter.h>
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 //   string getAddrFromId(int id,char * protocol);
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 };// end namespace MipResources{
00183 
00184 
00185 #endif
00186 
00187 
00188 
00189 

Generated on Mon Feb 20 07:01:07 2017 for MIP by  doxygen 1.5.6