Ok, grazie mille per la dritta, il più è: scrivendo così, perchè dovrebbe inviarmela al file pingApp.cc? Come fa a saperlo?
Il codice di LinearMobility.cc è:
#include "LinearMobility.h"
#include "FWMath.h"
Define_Module(LinearMobility);
void LinearMobility::initialize(int stage)
{
BasicMobility::initialize(stage);
EV << "initializing LinearMobility stage " << stage << endl;
if (stage == 0)
{
updateInterval = par("updateInterval");
speed = par("speed");
angle = par("angle");
acceleration = par("acceleration");
angle = fmod(angle,360);
// if the initial speed is lower than 0, the node is stationary
stationary = (speed == 0);
// host moves the first time after some random delay to avoid synchronized movements
if (!stationary)
scheduleAt(simTime() + uniform(0, updateInterval), new cMessage("move"));
}
}
/**
* The only self message possible is to indicate a new movement. If
* host is stationary this function is never called.
*/
void LinearMobility::handleSelfMsg(cMessage * msg)
{
move();
updatePosition();
if (!stationary)
scheduleAt(simTime() + updateInterval, msg);
}
/**
* Move the host if the destination is not reached yet. Otherwise
* calculate a new random position
*/
void LinearMobility::move()
{
pos.x += speed * cos(PI * angle / 180) * updateInterval;
pos.y += speed * sin(PI * angle / 180) * updateInterval;
// do something if we reach the wall
Coord dummy;
handleIfOutside(REFLECT, dummy, dummy, angle);
// accelerate
speed += acceleration * updateInterval;
if (speed <= 0)
{
speed = 0;
stationary = true;
}
EV << " xpos= " << pos.x << " ypos=" << pos.y << " speed=" << speed << endl;
}
Mentre il codice di PingApp.cc è:
#include <limits.h>
#include <stdlib.h>
#include <iostream>
#include <string.h>
#include <sstream>
#include <string>
#include "IPAddressResolver.h"
#include "PingApp.h"
#include "PingPayload_m.h"
#include "IPControlInfo.h"
#include "IPv6ControlInfo.h"
#include "IP.h"
#include "FlatNetworkConfigurator.h"
#include "BasicMobility.h"
#include "LinearMobility.h"
using std::cout;
using std::string;
Define_Module(PingApp);
void PingApp::initialize()
{
// read params
// (defer reading srcAddr/destAddr to when ping starts, maybe
// addresses will be assigned later by some protocol)
packetSize = par("packetSize");
intervalp = & par("interval");
hopLimit = par("hopLimit");
count = par("count");
startTime = par("startTime");
stopTime = par("stopTime");
printPing = (bool)par("printPing");
numHosts = par("numHosts");
int i;
string lista[numHosts];
string a;
// state
sendSeqNo = expectedReplySeqNo = 0;
WATCH(sendSeqNo);
WATCH(expectedReplySeqNo);
// statistics
delayStat.setName("pingRTT");
delayVector.setName("pingRTT");
dropVector.setName("pingDrop");
dropCount = outOfOrderArrivalCount = numPongs = 0;
WATCH(dropCount);
WATCH(outOfOrderArrivalCount);
WATCH(numPongs);
for (i=1;i<numHosts;i++)
{
std::string s;
std::stringstream out;
out << i;
s = out.str();
string ip="192.168.0."+s;
lista[i]=ip;
}
EV << "Questi sono gli indirizzi IP: \n";
for (i=1;i<numHosts+1;i++)
{
EV <<"Nodo" <<(i-1)<< ": " <<lista[i] << "\n";
}
// schedule first ping (use empty destAddr or stopTime<=startTime to disable)
if (par("destAddr").stringValue()[0] && (stopTime==0 || stopTime>=startTime))
{
cMessage *msg = new cMessage("sendPing");
scheduleAt(startTime, msg);
}
}
void PingApp::handleMessage(cMessage *msg)
{
if (msg->isSelfMessage())
{
// on first call we need to initialize
if (destAddr.isUnspecified())
{
destAddr = IPAddressResolver().resolve(par("destAddr"));
ASSERT(!destAddr.isUnspecified());
srcAddr = IPAddressResolver().resolve(par("srcAddr"));
EV << "Starting up: dest=" << destAddr << " src=" << srcAddr << "\n";
}
EV << "Il numero di hosts è: "<< numHosts << " \n";
contatore++;
EV<< "Ho ricevuto esattamente " << contatore << " ping \n";
// send a ping
sendPing();
// then schedule next one if needed
scheduleNextPing(msg);
}
else
{
// process ping response
processPingResponse(check_and_cast<PingPayload *>(msg));
}
}
void PingApp::sendPing()
{
EV << "Sending ping #" << sendSeqNo << "\n";
char name[32];
sprintf(name,"ping%ld", sendSeqNo);
PingPayload *msg = new PingPayload(name);
msg->setOriginatorId(getId());
msg->setSeqNo(sendSeqNo);
msg->setByteLength(packetSize);
sendToICMP(msg, destAddr, srcAddr, hopLimit);
}
void PingApp::scheduleNextPing(cMessage *timer)
{
simtime_t nextPing = simTime() + intervalp->doubleValue();
sendSeqNo++;
if ((count==0 || sendSeqNo<count) && (stopTime==0 || nextPing<stopTime))
scheduleAt(nextPing, timer);
else
delete timer;
}
void PingApp::sendToICMP(cMessage *msg, const IPvXAddress& destAddr, const IPvXAddress& srcAddr, int hopLimit)
{
if (!destAddr.isIPv6())
{
// send to IPv4
IPControlInfo *ctrl = new IPControlInfo();
ctrl->setSrcAddr(srcAddr.get4());
ctrl->setDestAddr(destAddr.get4());
ctrl->setTimeToLive(hopLimit);
msg->setControlInfo(ctrl);
send(msg, "pingOut");
}
else
{
// send to IPv6
IPv6ControlInfo *ctrl = new IPv6ControlInfo();
ctrl->setSrcAddr(srcAddr.get6());
ctrl->setDestAddr(destAddr.get6());
ctrl->setHopLimit(hopLimit);
msg->setControlInfo(ctrl);
send(msg, "pingv6Out");
}
}
void PingApp:rocessPingResponse(PingPayload *msg)
{
// get src, hopCount etc from packet, and print them
IPvXAddress src, dest;
int msgHopCount = -1;
if (dynamic_cast<IPControlInfo *>(msg->getControlInfo())!=NULL)
{
IPControlInfo *ctrl = (IPControlInfo *)msg->getControlInfo();
src = ctrl->getSrcAddr();
dest = ctrl->getDestAddr();
msgHopCount = ctrl->getTimeToLive();
}
else if (dynamic_cast<IPv6ControlInfo *>(msg->getControlInfo())!=NULL)
{
IPv6ControlInfo *ctrl = (IPv6ControlInfo *)msg->getControlInfo();
src = ctrl->getSrcAddr();
dest = ctrl->getDestAddr();
msgHopCount = ctrl->getHopLimit();
}
simtime_t rtt = simTime() - msg->getCreationTime();
if (printPing)
{
cout << getFullPath() << ": reply of " << std::dec << msg->getByteLength()
<< " bytes from " << src
<< " icmp_seq=" << msg->getSeqNo() << " ttl=" << msgHopCount
<< " time=" << (rtt * 1000) << " msec"
<< " (" << msg->getName() << ")" << endl;
}
// update statistics
countPingResponse(msg->getByteLength(), msg->getSeqNo(), rtt);
delete msg;
}
void PingApp::countPingResponse(int bytes, long seqNo, simtime_t rtt)
{
EV << "Ping reply #" << seqNo << " arrived, rtt=" << rtt << "\n";
numPongs++;
delayStat.collect(rtt);
delayVector.record(rtt);
if (seqNo == expectedReplySeqNo)
{
// expected ping reply arrived; expect next sequence number
expectedReplySeqNo++;
}
else if (seqNo > expectedReplySeqNo)
{
EV << "Jump in seq numbers, assuming pings since #" << expectedReplySeqNo << " got lost\n";
// jump in the sequence: count pings in gap as lost
long jump = seqNo - expectedReplySeqNo;
dropCount += jump;
dropVector.record(dropCount);
// expect sequence numbers to continue from here
expectedReplySeqNo = seqNo+1;
}
else // seqNo < expectedReplySeqNo
{
// ping arrived too late: count as out of order arrival
EV << "Arrived out of order (too late)\n";
outOfOrderArrivalCount++;
}
}
void PingApp::finish()
{
if (sendSeqNo==0)
{
if (printPing)
EV << getFullPath() << ": No pings sent, skipping recording statistics and printing results.\n";
recordScalar("Pings sent", sendSeqNo);
return;
}
Come dovrei modificare il tutto affinchè PingApp.cc riceva i due valori desiderati? Grazie mille sempre!


rocessPingResponse(PingPayload *msg)
Rispondi quotando