Hello everybody, I have a problem. At a peer-to-peer network, I want to define a wall clock for each node that is synchronized which each other. But OMNet++ is an event based simulator and real world time (wall clock) is different with simulation time for that. Would you please ask my question that "How I can implement wall clock for each node (with millisecond precision) at the OMNet++?" Thanks in advance, Maziar Manouchehry
This code is not tested but can help you
//
// Copyright (C) Alfonso Ariza
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//
#ifndef __TIMESLICE_H
#define __TIMESLICE_H
#include <omnetpp.h>
/**
* This class tries to model the operating system time slice
*
* @author Alfonso Ariza
*/
//INET_API
class TimeSlice : public cPolymorphic
{
private:
simtime_t timeSlice;
simtime_t minimunTime;
double jitter;
bool withoutDerive;
public:
void setTimeSlice(double val){timeSlice = val;}
void setMinimTime(double val){minimunTime = val;}
void setJitter(double val){jitter = val;}
void setDerive(bool val){withoutDerive=val;}
double getTimeSlice(){return SIMTIME_DBL(timeSlice);}
double getMinimTime(){return SIMTIME_DBL(minimunTime);}
double getJitter(){return SIMTIME_DBL(jitter);}
bool isDeriveCorrection(){return withoutDerive;}
simtime_t getNextTimer(double delay)
{
if (delay<minimunTime)
return simTime();
simtime_t nextTimer;
int numSlices = ceil(delay/SIMTIME_DBL(timeSlice));
if (withoutDerive)
{
int value = (SIMTIME_DBL(simTime())/SIMTIME_DBL(timeSlice));
nextTimer = (value+numSlices)*timeSlice;
if (nextTimer<simTime())
nextTimer = (value+numSlices+1)*timeSlice;
}
else
nextTimer = (numSlices*timeSlice)+simTime();
return nextTimer*(uniform()*jitter);
}
};
--
--
Sent from the OMNeT++ mailing list. To configure your membership,
visit http://groups.google.com/group/omnetpp
---
You received this message because you are subscribed to the Google Groups "omnetpp" group.
To unsubscribe from this group and stop receiving emails from it, send an email to omnetpp+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
To unsubscribe from this group and stop receiving emails from it, send an email to omnetpp+unsubscribe@googlegroups.com.
Hello everybody, I have similar problem. I need to implement a clock in my simulation model.
In my simulation model, there are time slots and the modules should do a particular task on the start of each time slot.
So, the modules should know about the start of time slot. I implement a clock as a simple module that sends selfmsg periodically to update the time and sends notification to notificationboad about start of the new time slot. but it does not work. because the number of events that clock produces is very very much.How to solve this problem?
Thanks in advance,
Mahsa