#include <vpr/md/SIM/Network/NetworkNode.h>
Collaboration diagram for vpr::sim::NetworkNode:

Public Member Functions | |
| NetworkNode () | |
| NetworkNode (const vpr::Uint32 index, const vpr::Uint8 type, const std::string &ip_str) | |
| Constructs a new network node using the given paramters. | |
| ~NetworkNode () | |
| void | addSocket (vpr::SocketImplSIM *sock) |
| vpr::ReturnStatus | removeSocket (const vpr::SocketImplSIM *sock) |
| bool | hasSocket (const vpr::Uint32 port, const vpr::SocketTypes::Type type) |
| Checks to see if this node currently has a socket of the given type in use on the named port. | |
| vpr::SocketImplSIM * | getSocket (const vpr::Uint32 port, const vpr::SocketTypes::Type type) |
| const vpr::Uint32 & | getIndex () const |
| void | setIndex (const vpr::Uint32 index) |
| const vpr::Uint8 & | getType () const |
| void | setType (const vpr::Uint8 type) |
| const vpr::Uint32 & | getIpAddress () const |
| Retrieves the 32-bit IPv4 address for this network node. | |
| const std::string & | getIpAddressString () const |
| vpr::Uint32 | getUnassignedTcpPortNumber () |
| Get an unused TCP port number. | |
| vpr::Uint32 | getUnassignedUdpPortNumber () |
| Get an unused UDP port number. | |
Definition at line 71 of file NetworkNode.h.
| vpr::sim::NetworkNode::NetworkNode | ( | ) | [inline] |
| vpr::sim::NetworkNode::NetworkNode | ( | const vpr::Uint32 | index, | |
| const vpr::Uint8 | type, | |||
| const std::string & | ip_str | |||
| ) |
Constructs a new network node using the given paramters.
This will parse the given IP address (it must be a standard IPv4 dotted-decimal string) and create the corresponding integer address.
Definition at line 63 of file NetworkNode.cpp.
References vpr::SystemPosix::Ntohl().
00065 : mIndex(index), mType(type), mIpStr(ip_str), mIpAddr(0) 00066 { 00067 std::string::size_type cur_pos, next_dot; 00068 std::string cur_val; 00069 00070 union 00071 { 00072 char bytes[4]; 00073 vpr::Uint32 value; 00074 } ip_addr; 00075 00076 cur_pos = 0; 00077 00078 for ( vpr::Uint8 i = 0; i < 4; ++i ) 00079 { 00080 next_dot = ip_str.find(".", cur_pos); 00081 cur_val = ip_str.substr(cur_pos, next_dot - cur_pos); 00082 00083 ip_addr.bytes[i] = atoi(cur_val.c_str()); 00084 00085 cur_pos = next_dot + 1; 00086 } 00087 00088 mIpAddr = vpr::System::Ntohl(ip_addr.value); 00089 }
| vpr::sim::NetworkNode::~NetworkNode | ( | ) | [inline] |
| void vpr::sim::NetworkNode::addSocket | ( | vpr::SocketImplSIM * | sock | ) |
Definition at line 137 of file NetworkNode.cpp.
References vpr::SocketTypes::DATAGRAM, vpr::InetAddrBSD::getAddressValue(), vpr::SocketImplSIM::getLocalAddr(), vpr::InetAddrBSD::getPort(), vpr::SocketImplSIM::getType(), hasSocket(), vpr::SocketTypes::STREAM, vprASSERT, vprDBG_ALL(), vprDBG_CRITICAL_LVL, vprDBG_STATE_LVL, vprDEBUG, and vprDEBUG_FLUSH.
00138 { 00139 vpr::Uint32 port = sock->getLocalAddr().getPort(); 00140 vprASSERT( mIpAddr == sock->getLocalAddr().getAddressValue() && "Trying to add socket to node of wrong ip addr"); 00141 if(hasSocket(port, sock->getType())) 00142 vprDEBUG(vprDBG_ALL, vprDBG_CRITICAL_LVL) << "NetworkNode::addSocket: Tried to overwrite existing socket: " << sock->getLocalAddr() << std::endl << vprDEBUG_FLUSH; 00143 vprASSERT(! hasSocket(port, sock->getType()) && "Tried to overwrite an existing socket"); 00144 00145 vprDEBUG(vprDBG_ALL, vprDBG_STATE_LVL) 00146 << "NetworkNode::addSocket() [" << mIpStr << "]: Adding socket (" << sock 00147 << ") with local address " << sock->getLocalAddr() << " to node " 00148 << mIpStr << "\n" << vprDEBUG_FLUSH; 00149 00150 switch (sock->getType()) 00151 { 00152 case vpr::SocketTypes::DATAGRAM: 00153 { 00154 //vpr::Guard<vpr::Mutex> guard(mDgramMapMutex); 00155 vprASSERT( dynamic_cast<vpr::SocketDatagramImplSIM*>(sock) != NULL); 00156 mDgramSocketMap[port] = sock; 00157 } 00158 break; 00159 case vpr::SocketTypes::STREAM: 00160 { 00161 //vpr::Guard<vpr::Mutex> guard(mStreamMapMutex); 00162 vprASSERT( dynamic_cast<vpr::SocketStreamImplSIM*>(sock) != NULL); 00163 mStreamSocketMap[port] = sock; 00164 } 00165 break; 00166 } 00167 }
| vpr::ReturnStatus vpr::sim::NetworkNode::removeSocket | ( | const vpr::SocketImplSIM * | sock | ) |
Definition at line 169 of file NetworkNode.cpp.
References vpr::SocketTypes::DATAGRAM, vpr::ReturnStatus::Fail, vpr::InetAddrBSD::getAddressValue(), vpr::SocketImplSIM::getLocalAddr(), vpr::InetAddrBSD::getPort(), vpr::SocketImplSIM::getType(), hasSocket(), vpr::ReturnStatus::setCode(), vpr::SocketTypes::STREAM, vpr::ReturnStatus::Succeed, vprASSERT, vprDBG_ALL(), vprDBG_STATE_LVL, vprDBG_VERB_LVL, vprDEBUG, and vprDEBUG_FLUSH.
00170 { 00171 vpr::ReturnStatus status(vpr::ReturnStatus::Fail); 00172 socket_map_t::iterator i; 00173 00174 vpr::Uint32 port( sock->getLocalAddr().getPort() ); 00175 vpr::Uint32 ip_addr( sock->getLocalAddr().getAddressValue() ); 00176 00177 vprASSERT( hasSocket(port, sock->getType()) && "Trying to remove a socket that isn't registered with node"); 00178 vprASSERT( mIpAddr == ip_addr && "Removing socket from wrong node [ip addresses differ]"); 00179 00180 vprDEBUG(vprDBG_ALL, vprDBG_STATE_LVL) 00181 << "NetworkNode::removeSocket() [" << mIpStr 00182 << "]: Removing socket bound to " << sock->getLocalAddr() << "\n" 00183 << vprDEBUG_FLUSH; 00184 00185 switch (sock->getType()) 00186 { 00187 case vpr::SocketTypes::DATAGRAM: 00188 { 00189 //vpr::Guard<vpr::Mutex> guard(mDgramMapMutex); 00190 i = mDgramSocketMap.find(port); 00191 00192 if ( i != mDgramSocketMap.end() ) 00193 { 00194 mDgramSocketMap.erase(i); 00195 status.setCode(vpr::ReturnStatus::Succeed); 00196 vprDEBUG(vprDBG_ALL, vprDBG_VERB_LVL) << "NetworkNode::removeSocket() [" << mIpStr 00197 << "]: Removed datagram socket\n" << vprDEBUG_FLUSH; 00198 vprASSERT(!hasSocket(port, sock->getType()) && "Erasing did nothing"); 00199 } 00200 } 00201 break; 00202 case vpr::SocketTypes::STREAM: 00203 { 00204 //vpr::Guard<vpr::Mutex> guard(mStreamMapMutex); 00205 00206 i = mStreamSocketMap.find(port); 00207 00208 if ( i != mStreamSocketMap.end() ) 00209 { 00210 mStreamSocketMap.erase(i); 00211 status.setCode(vpr::ReturnStatus::Succeed); 00212 vprDEBUG(vprDBG_ALL, vprDBG_VERB_LVL) << "NetworkNode::removeSocket() [" << mIpStr 00213 << "]: Removed stream socket\n" << vprDEBUG_FLUSH; 00214 vprASSERT(!hasSocket(port, sock->getType()) && "Erasing did nothing"); 00215 } 00216 } 00217 break; 00218 } 00219 00220 return status; 00221 }
| bool vpr::sim::NetworkNode::hasSocket | ( | const vpr::Uint32 | port, | |
| const vpr::SocketTypes::Type | type | |||
| ) |
Checks to see if this node currently has a socket of the given type in use on the named port.
Definition at line 91 of file NetworkNode.cpp.
References vpr::SocketTypes::DATAGRAM, and vpr::SocketTypes::STREAM.
Referenced by addSocket(), getSocket(), and removeSocket().
00093 { 00094 bool result = false; 00095 00096 switch (type) 00097 { 00098 case vpr::SocketTypes::DATAGRAM: 00099 //mDgramMapMutex.acquire(); 00100 result = (mDgramSocketMap.find(port) != mDgramSocketMap.end()); 00101 //mDgramMapMutex.release(); 00102 break; 00103 case vpr::SocketTypes::STREAM: 00104 //mStreamMapMutex.acquire(); 00105 result = (mStreamSocketMap.find(port) != mStreamSocketMap.end());; 00106 //mStreamMapMutex.release(); 00107 break; 00108 } 00109 00110 return result; 00111 }
| vpr::SocketImplSIM * vpr::sim::NetworkNode::getSocket | ( | const vpr::Uint32 | port, | |
| const vpr::SocketTypes::Type | type | |||
| ) |
Definition at line 113 of file NetworkNode.cpp.
References vpr::SocketTypes::DATAGRAM, hasSocket(), vpr::SocketTypes::STREAM, and vprASSERT.
00115 { 00116 vprASSERT( hasSocket(port,type) && "getSocket doesn't have a socket of the given type"); 00117 00118 switch (type) 00119 { 00120 case vpr::SocketTypes::DATAGRAM: 00121 { 00122 //vpr::Guard<vpr::Mutex> guard(mDgramMapMutex); 00123 return mDgramSocketMap[port]; 00124 } 00125 break; 00126 case vpr::SocketTypes::STREAM: 00127 { 00128 //vpr::Guard<vpr::Mutex> guard(mStreamMapMutex); 00129 return mStreamSocketMap[port]; 00130 } 00131 break; 00132 } 00133 00134 return NULL; 00135 }
| const vpr::Uint32& vpr::sim::NetworkNode::getIndex | ( | ) | const [inline] |
| void vpr::sim::NetworkNode::setIndex | ( | const vpr::Uint32 | index | ) | [inline] |
| const vpr::Uint8& vpr::sim::NetworkNode::getType | ( | ) | const [inline] |
| void vpr::sim::NetworkNode::setType | ( | const vpr::Uint8 | type | ) | [inline] |
| const vpr::Uint32& vpr::sim::NetworkNode::getIpAddress | ( | ) | const [inline] |
Retrieves the 32-bit IPv4 address for this network node.
Definition at line 132 of file NetworkNode.h.
| const std::string& vpr::sim::NetworkNode::getIpAddressString | ( | ) | const [inline] |
| vpr::Uint32 vpr::sim::NetworkNode::getUnassignedTcpPortNumber | ( | ) |
Get an unused TCP port number.
Definition at line 224 of file NetworkNode.cpp.
References vpr::prof::next(), and vprASSERT.
00225 { 00226 //vpr::Guard<vpr::Mutex> guard(mStreamMapMutex); 00227 00228 vpr::Uint32 ret_val(1); 00229 bool found_one(false); 00230 for(socket_map_t::iterator i = mStreamSocketMap.begin(); 00231 (!found_one) && (i != mStreamSocketMap.end()); ++i) 00232 { 00233 socket_map_t::iterator next = i; ++next; 00234 if(next != mStreamSocketMap.end()) 00235 { 00236 if((*next).first != ((*i).first + 1) ) // If not sequential 00237 { 00238 ret_val = (*i).first + 1; 00239 found_one = true; 00240 } 00241 } 00242 else // There is no next, so use the one after the current 00243 { 00244 ret_val = (*i).first +1; 00245 found_one = true; 00246 } 00247 00248 } 00249 00250 vprASSERT( mStreamSocketMap.find(ret_val) == mStreamSocketMap.end() && "Returned a value that already exists"); 00251 return ret_val; 00252 }
| vpr::Uint32 vpr::sim::NetworkNode::getUnassignedUdpPortNumber | ( | ) |
Get an unused UDP port number.
Definition at line 255 of file NetworkNode.cpp.
References vpr::prof::next(), and vprASSERT.
00256 { 00257 //vpr::Guard<vpr::Mutex> guard(mDgramMapMutex); 00258 00259 vpr::Uint32 ret_val(1); 00260 bool found_one(false); 00261 for(socket_map_t::iterator i = mDgramSocketMap.begin(); 00262 (!found_one) && (i != mDgramSocketMap.end()); ++i) 00263 { 00264 socket_map_t::iterator next = i; ++next; 00265 if(next != mDgramSocketMap.end()) 00266 { 00267 if((*next).first != ((*i).first + 1) ) // If not sequential 00268 { 00269 ret_val = (*i).first + 1; 00270 found_one = true; 00271 } 00272 } 00273 else // There is no next, so use the one after the current 00274 { 00275 ret_val = (*i).first +1; 00276 found_one = true; 00277 } 00278 } 00279 00280 vprASSERT( mDgramSocketMap.find(ret_val) == mDgramSocketMap.end() && "Returned a value that already exists"); 00281 return ret_val; 00282 }
1.5.1