Alex Bikfalvi
SimStream Documentation
MulticastTree.cpp
00001 #include "Headers.h" 00002 #include "MulticastTree.h" 00003 #include "Console.h" 00004 #include "Debug.h" 00005 00006 CMulticastTree::CMulticastTree(CTopo* topology, __uint32 group, __uint32 source) 00007 { 00008 assert(topology); 00009 00010 this->topology = topology; 00011 this->source = source; 00012 this->group = group; 00013 00014 // Create tree nodes 00015 this->nodes = new CMulticastNode[this->topology->Nodes()]; 00016 00017 // Stat 00018 this->sizeCoreLast = 0; 00019 this->sizeCoreTime = 0; 00020 this->sizeCore = 0; 00021 00022 this->sizeEdgeLast = 0; 00023 this->sizeEdgeTime = 0; 00024 this->sizeEdge = 0; 00025 } 00026 00027 CMulticastTree::~CMulticastTree() 00028 { 00029 delete[] this->nodes; 00030 } 00031 00032 void CMulticastTree::Add(__time time, __uint32 host, __uint32 gw) 00033 { 00034 assert(gw < this->topology->Nodes()); 00035 00036 // Check the host is not attached to the gateway node 00037 assert(this->nodes[gw].Hosts()->find(host) == this->nodes[gw].Hosts()->end()); 00038 00039 #ifdef LOG_MCAST 00040 if(LOG_GROUP == this->group) printf("\nT = %7.3lf GROUP %u ADD [%u] --- (%u)", time, this->group, host, gw); 00041 #endif 00042 00043 // Add the host to the node 00044 this->nodes[gw].Hosts()->insert(host); 00045 00046 // Calculate stat 00047 this->sizeEdge += (time - this->sizeEdgeTime) * this->sizeEdgeLast; 00048 this->sizeEdgeTime = time; 00049 00050 this->sizeCore += (time - this->sizeCoreTime) * this->sizeCoreLast; 00051 this->sizeCoreTime = time; 00052 00053 // Update edge stat 00054 this->sizeEdgeLast++; 00055 00056 // Generate the path from the host node to the source 00057 __uint32 node = gw; 00058 __uint32 next = node; 00059 while(node != this->source) 00060 { 00061 // Get the next node toward the destination 00062 next = this->topology->Route()->NextNode(node, this->source); 00063 00064 // Check if next node is already part of the group 00065 bool member = (this->nodes[next].Out()->size() > 0) || (this->nodes[next].Hosts()->size() > 0); 00066 00067 // If the next node has the current node in the output list, stop 00068 if(this->nodes[next].Out()->find(node) != this->nodes[next].Out()->end()) 00069 { 00070 #ifdef LOG_MCAST 00071 CConsole::SetColor(CConsole::LIGHT_CYAN); 00072 if(LOG_GROUP == this->group) printf(" --> (%u)", next); 00073 CConsole::SetColor(CConsole::LIGHT_GRAY); 00074 #endif 00075 break; 00076 } 00077 #ifdef LOG_MCAST 00078 else 00079 { 00080 CConsole::SetColor(CConsole::LIGHT_GREEN); 00081 if(LOG_GROUP == this->group) printf(" --> (%u)", next); 00082 CConsole::SetColor(CConsole::LIGHT_GRAY); 00083 } 00084 #endif 00085 00086 // Else, add the current node to the next node 00087 this->nodes[next].Out()->insert(node); 00088 00089 // Update core stat 00090 this->sizeCoreLast++; 00091 00092 // If the next node was already a member, stop 00093 if(member) break; 00094 00095 // Move to next node 00096 node = next; 00097 } 00098 00099 #ifdef LOG_MCAST 00100 // If current node is not the source, display path to the source 00101 for(node = next; node != this->source; ) 00102 { 00103 next = this->topology->Route()->NextNode(node, this->source); 00104 00105 CConsole::SetColor(CConsole::LIGHT_CYAN); 00106 if(LOG_GROUP == this->group) printf(" --> (%u)", next); 00107 CConsole::SetColor(CConsole::LIGHT_GRAY); 00108 00109 node = next; 00110 } 00111 00112 if(LOG_GROUP == this->group) printf("\n%3u\t\t%3u\t\t%7.3lf\t\t%7.3lf", this->sizeCoreLast, this->sizeEdgeLast, this->sizeCore/time, this->sizeEdge/time); 00113 #endif 00114 } 00115 00116 void CMulticastTree::Remove(__time time, __uint32 host, __uint32 gw) 00117 { 00118 #ifdef LOG_MCAST 00119 if(LOG_GROUP == this->group) printf("\nT = %7.3lf GROUP %u REM [%u]", time, this->group, host); 00120 CConsole::SetColor(CConsole::LIGHT_RED); 00121 if(LOG_GROUP == this->group) printf(" -x- (%u)", gw); 00122 CConsole::SetColor(CConsole::LIGHT_GRAY); 00123 #endif 00124 00125 // Check the host is attached to the gateway node 00126 assert(this->nodes[gw].Hosts()->find(host) != this->nodes[gw].Hosts()->end()); 00127 00128 // Remove the host from the node 00129 this->nodes[gw].Hosts()->erase(host); 00130 00131 // Calculate stat 00132 this->sizeEdge += (time - this->sizeEdgeTime) * this->sizeEdgeLast; 00133 this->sizeEdgeTime = time; 00134 00135 this->sizeCore += (time - this->sizeCoreTime) * this->sizeCoreLast; 00136 this->sizeCoreTime = time; 00137 00138 // Update edge stat 00139 this->sizeEdgeLast--; 00140 00141 // If the hosts list is not empty, stop 00142 if(this->nodes[gw].Hosts()->size()) 00143 { 00144 #ifdef LOG_MCAST 00145 if(LOG_GROUP == this->group) printf("\n%3u\t\t%3u\t\t%7.3lf\t\t%7.3lf", this->sizeCoreLast, this->sizeEdgeLast, this->sizeCore/time, this->sizeEdge/time); 00146 #endif 00147 return; 00148 } 00149 00150 // If the out list is not empty, stop 00151 if(this->nodes[gw].Out()->size()) 00152 { 00153 #ifdef LOG_MCAST 00154 if(LOG_GROUP == this->group) printf("\n%3u\t\t%3u\t\t%7.3lf\t\t%7.3lf", this->sizeCoreLast, this->sizeEdgeLast, this->sizeCore/time, this->sizeEdge/time); 00155 #endif 00156 return; 00157 } 00158 00159 // Remove nodes from the tree 00160 for(__uint32 node = gw; node != this->source;) 00161 { 00162 // Get the next node 00163 __uint32 next = this->topology->Route()->NextNode(node, this->source); 00164 00165 // Check the next node has the current node 00166 assert(this->nodes[next].Out()->find(node) != this->nodes[next].Out()->end()); 00167 00168 // Remove the current node from the next node 00169 this->nodes[next].Out()->erase(node); 00170 00171 // Update core stat 00172 this->sizeCoreLast--; 00173 00174 #ifdef LOG_MCAST 00175 CConsole::SetColor(CConsole::LIGHT_RED); 00176 if(LOG_GROUP == this->group) printf(" -x- (%u)", next); 00177 CConsole::SetColor(CConsole::LIGHT_GRAY); 00178 #endif 00179 00180 // If the next node has other hosts, stop 00181 if(this->nodes[next].Hosts()->size()) break; 00182 00183 // If the next node has other nodes, stop 00184 if(this->nodes[next].Out()->size()) break; 00185 00186 // Else, go to next node 00187 node = next; 00188 } 00189 00190 #ifdef LOG_MCAST 00191 if(LOG_GROUP == this->group) printf("\n%3u\t\t%3u\t\t%7.3lf\t\t%7.3lf", this->sizeCoreLast, this->sizeEdgeLast, this->sizeCore/time, this->sizeEdge/time); 00192 #endif 00193 } 00194 00195 void CMulticastTree::Clear() 00196 { 00197 for(__uint32 index = 0; index < this->topology->Nodes(); index++) 00198 { 00199 this->nodes[index].Hosts()->clear(); 00200 this->nodes[index].Out()->clear(); 00201 } 00202 00203 // Stat 00204 this->sizeCoreLast = 0; 00205 this->sizeCoreTime = 0; 00206 this->sizeCore = 0; 00207 00208 this->sizeEdgeLast = 0; 00209 this->sizeEdgeTime = 0; 00210 this->sizeEdge = 0; 00211 } 00212 00213 void CMulticastTree::Finalize(__time time) 00214 { 00215 this->sizeCore += (time - this->sizeCoreTime) * this->sizeCoreLast; 00216 this->sizeEdge += (time - this->sizeEdgeTime) * this->sizeEdgeLast; 00217 00218 this->sizeCore /= time; 00219 this->sizeEdge /= time; 00220 }
Last updated: February 8, 2011