00001 //========================================================================== 00002 // CTOPO.H - header for 00003 // OMNeT++ 00004 // Discrete System Simulation in C++ 00005 // 00006 // 00007 // Declaration of the following classes: 00008 // cTopology : network topology to find shortest paths etc. 00009 // 00010 //========================================================================== 00011 00012 /*--------------------------------------------------------------* 00013 Copyright (C) 1992-2001 Andras Varga 00014 Technical University of Budapest, Dept. of Telecommunications, 00015 Stoczek u.2, H-1111 Budapest, Hungary. 00016 00017 This file is distributed WITHOUT ANY WARRANTY. See the file 00018 `license' for details on this and other legal matters. 00019 *--------------------------------------------------------------*/ 00020 00021 #ifndef __CTOPO_H 00022 #define __CTOPO_H 00023 00024 #include "cobject.h" 00025 00026 class cPar; 00027 00028 00029 #define INFINITY HUGE_VAL 00030 00031 class sTopoLink; 00032 class sTopoLinkIn; 00033 class sTopoLinkOut; 00034 00035 00039 class SIM_API sTopoNode 00040 { 00041 friend class cTopology; 00042 00043 private: 00044 int module_id; 00045 double wgt; 00046 bool enabl; 00047 00048 int num_in_links; 00049 sTopoLink **in_links; 00050 int num_out_links; 00051 sTopoLink *out_links; 00052 00053 // variables used by the shortest-path algorithms 00054 bool known; 00055 double dist; 00056 sTopoLink *out_path; 00057 00058 public: 00061 00065 int moduleId() const {return module_id;} 00066 00070 cModule *module() const {return &simulation[module_id];} 00071 00076 double weight() const {return wgt;} 00077 00082 void setWeight(double d) {wgt=d;} 00083 00088 bool enabled() const {return enabl;} 00089 00094 void enable() {enabl=true;} 00095 00100 void disable() {enabl=false;} 00102 00105 00109 int inLinks() const {return num_in_links;} 00110 00114 sTopoLinkIn *in(int i); 00115 00119 int outLinks() const {return num_out_links;} 00120 00124 sTopoLinkOut *out(int i); 00126 00129 00133 double distanceToTarget() const {return dist;} 00134 00139 int paths() const {return out_path?1:0;} 00140 00146 sTopoLinkOut *path(int) const {return (sTopoLinkOut *)out_path;} 00148 }; 00149 00150 00154 class SIM_API sTopoLink 00155 { 00156 friend class cTopology; 00157 00158 protected: 00159 sTopoNode *src_node; 00160 int src_gate; 00161 sTopoNode *dest_node; 00162 int dest_gate; 00163 double wgt; 00164 bool enabl; 00165 00166 public: 00171 double weight() const {return wgt;} 00172 00177 void setWeight(double d) {wgt=d;} 00178 00183 bool enabled() const {return enabl;} 00184 00189 void enable() {enabl=true;} 00190 00195 void disable() {enabl=false;} 00196 }; 00197 00198 00207 class SIM_API sTopoLinkIn : public sTopoLink 00208 { 00209 public: 00217 sTopoNode *remoteNode() const {return src_node;} 00218 00222 int remoteGateId() const {return src_gate;} 00223 00227 int localGateId() const {return dest_gate;} 00228 00232 cGate *remoteGate() const {return src_node->module()->gate(src_gate);} 00233 00237 cGate *localGate() const {return dest_node->module()->gate(dest_gate);} 00238 }; 00239 00240 00249 class SIM_API sTopoLinkOut : public sTopoLink 00250 { 00251 public: 00259 sTopoNode *remoteNode() const {return dest_node;} 00260 00264 int remoteGateId() const {return dest_gate;} 00265 00269 int localGateId() const {return src_gate;} 00270 00274 cGate *remoteGate() const {return dest_node->module()->gate(dest_gate);} 00275 00279 cGate *localGate() const {return src_node->module()->gate(src_gate);} 00280 }; 00281 00282 00304 class SIM_API cTopology : public cObject 00305 { 00306 protected: 00307 int num_nodes; 00308 sTopoNode *nodev; 00309 sTopoNode *target; 00310 00311 public: 00314 00318 explicit cTopology(const char *name=NULL); 00319 00323 cTopology(const cTopology& topo); 00324 00328 virtual ~cTopology(); 00329 00333 cTopology& operator=(const cTopology& topo); 00335 00338 00342 virtual const char *className() const {return "cTopology";} 00343 00348 virtual cObject *dup() const {return new cTopology(*this);} 00349 00354 virtual void info(char *buf); 00355 00360 virtual const char *inspectorFactoryName() const {return "cTopologyIFC";} 00361 00367 virtual int netPack(); 00368 00374 virtual int netUnpack(); 00376 00385 00390 void extractFromNetwork(int (*selfunc)(cModule *,void *), void *data=NULL); 00391 00397 void extractByModuleType(const char *type1,...); 00398 00404 void extractByParameter(const char *parname, cPar *value=NULL); 00405 00409 void clear(); 00411 00418 00422 int nodes() const {return num_nodes;} 00423 00428 sTopoNode *node(int i); 00429 00437 sTopoNode *nodeFor(cModule *mod); 00439 00448 00453 void unweightedSingleShortestPathsTo(sTopoNode *target); 00454 00459 sTopoNode *targetNode() const {return target;} 00461 }; 00462 00463 #endif