SingleHostConfigurator Class Reference

#include <SingleHostConfigurator.h>

Inheritance diagram for SingleHostConfigurator:

UnderlayConfigurator

List of all members.

Protected Member Functions

void initializeUnderlay (int stage)
 Init method for derived underlay configurators.
void finishUnderlay ()
 Cleans up concrete underlay configurator.
void setDisplayString ()
 Sets display string.
TransportAddresscreateNode (NodeType type, bool initialize)
 Creates an overlay node.
void preKillNode (NodeType type, TransportAddress *addr=NULL)
 Notifies and schedules overlay nodes for removal.
void migrateNode (NodeType type, TransportAddress *addr=NULL)
 Migrates overlay nodes from one access net to another.
void handleMessage (cMessage *msg)
 Node mobility simulation.


Member Function Documentation

void SingleHostConfigurator::initializeUnderlay ( int  stage  )  [protected, virtual]

Init method for derived underlay configurators.

Implements UnderlayConfigurator.

00054 {
00055     int sock_fd;
00056     struct ifreq req;
00057     StunAddress4 publicAddr, stunServerAddr;
00058     IPvXAddress addr;
00059 
00060     if(stage != MAX_STAGE_UNDERLAY)
00061         return;
00062 
00063     overlayTerminalCount = 1;
00064 
00065     // Set IP, Routes, etc
00066     cModule* node = parentModule()->submodule("singleHost", 0);
00067 
00068     std::string interface = std::string(par("nodeInterface").stringValue());
00069     std::string stunServer = std::string(par("stunServer").stringValue());
00070     std::string nodeIP = std::string(par("nodeIP").stringValue());
00071 
00072     if (!interface.size() && !stunServer.size() && !nodeIP.size()) {
00073         throw new cRuntimeError("SingleHostConfigurator::initializeUnderlay(): "
00074                                 "Please specify at least one of "
00075                                 "**.nodeInterface, **.nodeIP, or **.stunServer");
00076     }
00077 
00078     if (interface.size()) {
00079         if ((sock_fd = socket(PF_INET, SOCK_DGRAM, IPPROTO_IP)) != -1) {
00080             snprintf(req.ifr_name, sizeof(req.ifr_name), interface.c_str());
00081 
00082             if (!ioctl(sock_fd, SIOCGIFADDR, &req)) {
00083                 addr = IPAddress(inet_ntoa(((struct sockaddr_in *)
00084                         (&req.ifr_addr))->sin_addr));
00085             } else {
00086                 throw new cRuntimeError("SingleHostConfigurator::"
00087                                         "initializeUnderlay(): "
00088                                         "Invalid interface!");
00089             }
00090 
00091             close(sock_fd);
00092         }
00093     } else if (nodeIP.size()) {
00094         addr = IPAddress(nodeIP.c_str());
00095     }
00096 
00097     if (stunServer.size()) {
00098         // TODO: use and set overlayPort!
00099         throw new cRuntimeError("SingleHostConfigurator::initializeUnderlay():"
00100                                 " Not implemented yet!");
00101         int srcPort = 0;
00102         publicAddr.addr = 0;
00103         publicAddr.port = srcPort;
00104         stunServerAddr.addr = 0;
00105         char tmpAddr[512];
00106         strncpy (tmpAddr, stunServer.c_str(), 512);
00107 
00108         if (stunParseServerName(tmpAddr, stunServerAddr)) {
00109             bool presPort = false;
00110             bool hairpin = false;
00111 
00112             NatType stype = stunNatType(stunServerAddr, false, &presPort,
00113                                         &hairpin, srcPort, &publicAddr);
00114             if (stype != StunTypeOpen) {
00115                 EV << "SingleHostConfigurator::initializeUnderlay(): "
00116                    << "Node is behind NAT or invalid STUN server configuration!"
00117                    << std::endl;
00118             }
00119 
00120             publicAddr.addr = htonl(publicAddr.addr);
00121             addr = IPAddress(inet_ntoa(*((struct in_addr *)(&(publicAddr.addr)))));
00122         }
00123     }
00124 
00125     IPvXAddress gw = addr;
00126     InterfaceEntry* ifEntry = IPAddressResolver().interfaceTableOf(node)->
00127             interfaceByName("outDev");
00128     RoutingTable* rTable = (RoutingTable*) node->submodule("routingTable", 0);
00129     ifEntry->ipv4()->setInetAddress(addr.get4());
00130     ifEntry->ipv4()->setNetmask(IPAddress::ALLONES_ADDRESS);
00131 
00132     RoutingEntry* te = new RoutingEntry();
00133     te->host = IPAddress::UNSPECIFIED_ADDRESS;
00134     te->netmask = IPAddress::UNSPECIFIED_ADDRESS;
00135     te->gateway = gw.get4();
00136     te->interfaceName = "outDev";
00137     te->interfacePtr = ifEntry;
00138     te->type = RoutingEntry::REMOTE;
00139     te->source = RoutingEntry::MANUAL;
00140     rTable->addRoutingEntry(te);
00141 
00142     //add node to bootstrap oracle
00143     PeerInfo* info = new PeerInfo(0, node->id());
00144     bootstrapOracle->addPeer(addr, info);
00145 
00146     if (strlen(par("bootstrapIP")) > 0) {
00147         PeerInfo* bootstrapInfo = new PeerInfo(0, -1);
00148         bootstrapOracle->addPeer(IPAddress(par("bootstrapIP").stringValue()),
00149                                  bootstrapInfo);
00150 
00151         bootstrapOracle->registerPeer(NodeHandle(OverlayKey::ONE,
00152           IPAddress(par("bootstrapIP").stringValue()), par("bootstrapPort")));
00153     }
00154 
00155     // update display
00156     setDisplayString();
00157 
00158 }

void SingleHostConfigurator::finishUnderlay (  )  [protected, virtual]

Cleans up concrete underlay configurator.

Reimplemented from UnderlayConfigurator.

00169 {
00170     if (!isInInitPhase()) {
00171         struct timeval now, diff;
00172         gettimeofday(&now, NULL);
00173         timersub(&now, &initFinishedTime, &diff);
00174         printf("Simulation time: %li.%06li\n", diff.tv_sec, diff.tv_usec);
00175     }
00176 }

void SingleHostConfigurator::setDisplayString (  )  [protected, virtual]

Sets display string.

Implements UnderlayConfigurator.

Referenced by initializeUnderlay().

00161 {
00162     // updates the statistics display string
00163     char buf[80];
00164     sprintf(buf, "%i overlay terminals", overlayTerminalCount);
00165     displayString().setTagArg("t", 0, buf);
00166 }

TransportAddress* SingleHostConfigurator::createNode ( NodeType  type,
bool  initialize 
) [inline, protected, virtual]

Creates an overlay node.

Parameters:
type NodeType of the node to create
initialize are we in init phase?

Implements UnderlayConfigurator.

00044 {error("createNode can't be used with singleHostUnderlay!"); return NULL;}

void SingleHostConfigurator::preKillNode ( NodeType  type,
TransportAddress addr = NULL 
) [inline, protected, virtual]

Notifies and schedules overlay nodes for removal.

Parameters:
type NodeType of the node to remove
addr NULL for random node

Implements UnderlayConfigurator.

00045 {error("preKillNode can't be used with singleHostUnderlay!");}

void SingleHostConfigurator::migrateNode ( NodeType  type,
TransportAddress addr = NULL 
) [inline, protected, virtual]

Migrates overlay nodes from one access net to another.

Parameters:
type NodeType of the node to migrate
addr NULL for random node

Implements UnderlayConfigurator.

00046 {error("migrateNode can't be used with singleHostUnderlay!");}

void SingleHostConfigurator::handleMessage ( cMessage *  msg  )  [inline, protected]

Node mobility simulation.

Parameters:
msg timer-message

Reimplemented from UnderlayConfigurator.

00047 {error("handleMessage can't be used with singleHostUnderlay!");}


The documentation for this class was generated from the following files:

Generated on Fri Sep 19 13:05:08 2008 for ITM OverSim by  doxygen 1.5.5