Protected Member Functions

SingleHostUnderlayConfigurator Class Reference

#include <SingleHostUnderlayConfigurator.h>

Inheritance diagram for SingleHostUnderlayConfigurator:
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.
void handleTimerEvent (cMessage *msg)
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.

Detailed Description

Definition at line 36 of file SingleHostUnderlayConfigurator.h.


Member Function Documentation

TransportAddress* SingleHostUnderlayConfigurator::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.

Definition at line 46 of file SingleHostUnderlayConfigurator.h.

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

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

Cleans up concrete underlay configurator.

Reimplemented from UnderlayConfigurator.

Definition at line 189 of file SingleHostUnderlayConfigurator.cc.

{
    if (!isInInitPhase()) {
        struct timeval now, diff;
        gettimeofday(&now, NULL);
        timersub(&now, &initFinishedTime, &diff);
        printf("Simulation time: %li.%06li\n", diff.tv_sec, diff.tv_usec);
    }
}

void SingleHostUnderlayConfigurator::handleTimerEvent ( cMessage *  msg  )  [protected, virtual]

Reimplemented from UnderlayConfigurator.

Definition at line 171 of file SingleHostUnderlayConfigurator.cc.

{
    if (std::string(msg->getName()) != "init phase finished") {
        throw cRuntimeError("unknown self-message received");
    }
    delete msg;

    initFinished();
}

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

Init method for derived underlay configurators.

Implements UnderlayConfigurator.

Definition at line 57 of file SingleHostUnderlayConfigurator.cc.

{
    StunAddress4 publicAddr, stunServerAddr;
    IPvXAddress addr;

    if(stage != MAX_STAGE_UNDERLAY)
        return;

    overlayTerminalCount = 1;

    // Set IP, Routes, etc
    cModule* node = getParentModule()->getSubmodule("overlayTerminal", 0);

    std::string nodeInterface = std::string(par("nodeInterface").stringValue());
    std::string stunServer = std::string(par("stunServer").stringValue());
    std::string nodeIP = std::string(par("nodeIP").stringValue());

    if (!nodeInterface.size() && !stunServer.size() && !nodeIP.size()) {
        throw cRuntimeError("SingleHostConfigurator::initializeUnderlay(): "
                            "Please specify at least one of "
                            "**.nodeInterface, **.nodeIP, or **.stunServer");
    }

    if (nodeInterface.size()) {
#ifndef _WIN32
        SOCKET sock_fd;
        struct ifreq req;
        if ((sock_fd = socket(PF_INET, SOCK_DGRAM, IPPROTO_IP)) !=
            INVALID_SOCKET) {

            snprintf(req.ifr_name, sizeof(req.ifr_name), "%s", nodeInterface.c_str());

            if (!ioctl(sock_fd, SIOCGIFADDR, &req)) {
                addr = IPAddress(inet_ntoa(((struct sockaddr_in *)
                        (&req.ifr_addr))->sin_addr));
            } else {
                throw cRuntimeError("SingleHostConfigurator::"
                                        "initializeUnderlay(): "
                                        "Invalid interface!");
            }
            close(sock_fd);
        }
#else
        throw cRuntimeError("SingleHostConfigurator::"
                "initializeUnderlay(): "
                "**.nodeInterface parameter not supported on WIN32 yet!");
#endif
    } else if (nodeIP.size()) {
        addr = IPAddress(nodeIP.c_str());
    }

    if (stunServer.size()) {
        // TODO: use and set overlayPort!
        throw cRuntimeError("SingleHostConfigurator::initializeUnderlay():"
                                " Not implemented yet!");
        int srcPort = 0;
        publicAddr.addr = 0;
        publicAddr.port = srcPort;
        stunServerAddr.addr = 0;
        char tmpAddr[512];
        strncpy (tmpAddr, stunServer.c_str(), 512);

        if (stunParseServerName(tmpAddr, stunServerAddr)) {
            bool presPort = false;
            bool hairpin = false;

            NatType stype = stunNatType(stunServerAddr, false, &presPort,
                                        &hairpin, srcPort, &publicAddr);
            if (stype != StunTypeOpen) {
                EV << "SingleHostConfigurator::initializeUnderlay(): "
                   << "Node is behind NAT or invalid STUN server configuration!"
                   << std::endl;
            }

            publicAddr.addr = htonl(publicAddr.addr);
            addr = IPAddress(inet_ntoa(*((struct in_addr *)(&(publicAddr.addr)))));
        }
    }

    IPvXAddress gw = addr;
    InterfaceEntry* ifEntry = IPAddressResolver().interfaceTableOf(node)->
            getInterfaceByName("outDev");
    IRoutingTable* rTable = check_and_cast<IRoutingTable*>(node->getSubmodule("routingTable", 0));

    ifEntry->ipv4Data()->setIPAddress(addr.get4());
    ifEntry->ipv4Data()->setNetmask(IPAddress::ALLONES_ADDRESS);

    IPRoute* te = new IPRoute();
    te->setHost(IPAddress::UNSPECIFIED_ADDRESS);
    te->setNetmask(IPAddress::UNSPECIFIED_ADDRESS);
    te->setGateway(gw.get4());
    te->setInterface(ifEntry);
    te->setType(IPRoute::REMOTE);
    te->setSource(IPRoute::MANUAL);
    rTable->addRoute(te);

    //add node to bootstrap oracle
    PeerInfo* info = new PeerInfo(0, node->getId(), NULL);
    globalNodeList->addPeer(addr, info);

    if (strlen(par("bootstrapIP")) > 0) {
        PeerInfo* bootstrapInfo = new PeerInfo(0, -1, NULL);
        globalNodeList->addPeer(IPAddress(par("bootstrapIP").stringValue()),
                                bootstrapInfo);

        globalNodeList->registerPeer(NodeHandle(OverlayKey::ONE,
            IPAddress(par("bootstrapIP").stringValue()), par("bootstrapPort")));
    }

    // update display
    setDisplayString();

    scheduleAt(simTime(), new cMessage("init phase finished"));
}

void SingleHostUnderlayConfigurator::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.

Definition at line 48 of file SingleHostUnderlayConfigurator.h.

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

void SingleHostUnderlayConfigurator::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.

Definition at line 47 of file SingleHostUnderlayConfigurator.h.

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

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

Sets display string.

Implements UnderlayConfigurator.

Definition at line 181 of file SingleHostUnderlayConfigurator.cc.

Referenced by initializeUnderlay().

{
    // updates the statistics display string
    char buf[80];
    sprintf(buf, "%i overlay terminals", overlayTerminalCount);
    getDisplayString().setTagArg("t", 0, buf);
}


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