#include <cSocketRTScheduler.h>
inet::cSocketRTScheduler::cSocketRTScheduler |
( |
| ) |
|
Constructor.
int fd
Definition: cSocketRTScheduler.h:44
inet::cSocketRTScheduler::~cSocketRTScheduler |
( |
| ) |
|
|
virtual |
void inet::cSocketRTScheduler::endRun |
( |
| ) |
|
|
overridevirtual |
Called at the end of a simulation run.
93 if (pcap_stats(
pds.at(i), &ps) < 0)
94 throw cRuntimeError(
"cSocketRTScheduler::endRun(): Cannot query pcap statistics: %s", pcap_geterr(
pds.at(i)));
96 EV <<
modules.at(i)->getFullPath() <<
": Received Packets: " << ps.ps_recv <<
" Dropped Packets: " << ps.ps_drop <<
".\n";
97 pcap_close(
pds.at(i));
int fd
Definition: cSocketRTScheduler.h:44
static std::vector< cModule * > modules
Definition: cSocketRTScheduler.h:59
static std::vector< int > headerLengths
Definition: cSocketRTScheduler.h:62
static std::vector< int > datalinks
Definition: cSocketRTScheduler.h:61
bool close(double one, double two)
Tests whether two doubles are close enough to be declared equal.
Definition: INETMath.h:135
static std::vector< pcap_t * > pds
Definition: cSocketRTScheduler.h:60
uint16_t uint16
Definition: Compat.h:32
void inet::cSocketRTScheduler::executionResumed |
( |
| ) |
|
|
overridevirtual |
Recalculates "base time" from current wall clock time.
static timeval baseTime
Definition: cSocketRTScheduler.h:63
cEvent * inet::cSocketRTScheduler::guessNextEvent |
( |
| ) |
|
|
overridevirtual |
Returns the first event in the Future Event Set.
292 return FES(sim)->peekFirst();
#define FES(sim)
Definition: cSocketRTScheduler.cc:44
void inet::cSocketRTScheduler::putBackEvent |
( |
cEvent * |
event | ) |
|
|
overridevirtual |
Scheduler function – it comes from the cScheduler interface.
336 FES(sim)->putBackFirst(event);
#define FES(sim)
Definition: cSocketRTScheduler.cc:44
int inet::cSocketRTScheduler::receiveUntil |
( |
const timeval & |
targetTime | ) |
|
|
protectedvirtual |
Referenced by takeNextEvent().
271 gettimeofday(&curTime,
nullptr);
272 while (targetTime.tv_sec-curTime.tv_sec >=2 ||
277 if (getEnvir()->idle())
279 gettimeofday(&curTime,
nullptr);
283 long usec = timeval_diff_usec(targetTime, curTime);
virtual bool receiveWithTimeout(long usec)
Definition: cSocketRTScheduler.cc:223
#define UI_REFRESH_TIME
Definition: cSocketRTScheduler.cc:38
bool inet::cSocketRTScheduler::receiveWithTimeout |
( |
long |
usec | ) |
|
|
protectedvirtual |
Referenced by receiveUntil().
226 struct timeval timeout;
235 timeout.tv_usec = usec;
239 for (
uint16 i = 0; i <
pds.size(); i++) {
240 fd[i] = pcap_get_selectable_fd(
pds.at(i));
243 FD_SET(fd[i], &rdfds);
245 if (select(maxfd + 1, &rdfds,
nullptr,
nullptr, &timeout) < 0) {
249 for (
uint16 i = 0; i <
pds.size(); i++) {
251 if (!(FD_ISSET(fd[i], &rdfds)))
253 #endif // ifdef __linux__ 254 if ((n = pcap_dispatch(
pds.at(i), 1, packet_handler, (
uint8 *)&i)) < 0)
255 throw cRuntimeError(
"cSocketRTScheduler::pcap_dispatch(): An error occured: %s", pcap_geterr(
pds.at(i)));
261 select(0,
nullptr,
nullptr,
nullptr, &timeout);
uint8_t uint8
Definition: Compat.h:34
int fd
Definition: cSocketRTScheduler.h:44
int32_t int32
Definition: Compat.h:31
static std::vector< pcap_t * > pds
Definition: cSocketRTScheduler.h:60
uint16_t uint16
Definition: Compat.h:32
void inet::cSocketRTScheduler::sendBytes |
( |
unsigned char * |
buf, |
|
|
size_t |
numBytes, |
|
|
struct sockaddr * |
from, |
|
|
socklen_t |
addrlen |
|
) |
| |
Send on the currently open connection.
Referenced by inet::ExtInterface::handleMessage().
341 if (
fd == INVALID_SOCKET)
342 throw cRuntimeError(
"cSocketRTScheduler::sendBytes(): no raw socket.");
344 int sent = sendto(
fd, (
char *)buf, numBytes, 0, to, addrlen);
346 if ((
size_t)sent == numBytes)
347 EV <<
"Sent an IP packet with length of " << sent <<
" bytes.\n";
349 EV <<
"Sending of an IP packet FAILED! (sendto returned " << sent <<
" (" << strerror(errno) <<
") instead of " << numBytes <<
").\n";
int fd
Definition: cSocketRTScheduler.h:44
void inet::cSocketRTScheduler::setInterfaceModule |
( |
cModule * |
mod, |
|
|
const char * |
dev, |
|
|
const char * |
filter |
|
) |
| |
To be called from the module which wishes to receive data from the socket.
The method must be called from the module's initialize() function.
Referenced by inet::ExtInterface::initialize().
115 char errbuf[PCAP_ERRBUF_SIZE];
116 struct bpf_program fcode;
121 if (!
mod || !dev || !filter)
122 throw cRuntimeError(
"cSocketRTScheduler::setInterfaceModule(): arguments must be non-nullptr");
125 memset(&errbuf, 0,
sizeof(errbuf));
126 if ((pd = pcap_create(dev, errbuf)) ==
nullptr)
127 throw cRuntimeError(
"cSocketRTScheduler::setInterfaceModule(): Cannot create pcap device, error = %s", errbuf);
128 else if (strlen(errbuf) > 0)
129 EV <<
"cSocketRTScheduler::setInterfaceModule(): pcap_open_live returned warning: " << errbuf <<
"\n";
132 if (pcap_set_immediate_mode(pd, 1) != 0)
133 throw cRuntimeError(
"cSocketRTScheduler::setInterfaceModule(): Cannot set immediate mode to pcap device");
135 if (pcap_activate(pd) != 0)
136 throw cRuntimeError(
"cSocketRTScheduler::setInterfaceModule(): Cannot activate pcap device");
139 if (pcap_compile(pd, &fcode, (
char *)filter, 0, 0) < 0)
140 throw cRuntimeError(
"cSocketRTScheduler::setInterfaceModule(): Cannot compile pcap filter: %s", pcap_geterr(pd));
143 if (pcap_setfilter(pd, &fcode) < 0)
144 throw cRuntimeError(
"cSocketRTScheduler::setInterfaceModule(): Cannot apply compiled pcap filter: %s", pcap_geterr(pd));
146 if ((datalink = pcap_datalink(pd)) < 0)
147 throw cRuntimeError(
"cSocketRTScheduler::setInterfaceModule(): Cannot query pcap link-layer header type: %s", pcap_geterr(pd));
150 if (pcap_setnonblock(pd, 1, errbuf) < 0)
151 throw cRuntimeError(
"cSocketRTScheduler::setInterfaceModule(): Cannot put pcap device into non-blocking mode, error: %s", errbuf);
172 throw cRuntimeError(
"cSocketRTScheduler::setInterfaceModule(): Unsupported datalink: %d", datalink);
179 EV <<
"Opened pcap device " << dev <<
" with filter " << filter <<
" and datalink " << datalink <<
".\n";
double mod(double dividend, double divisor)
Returns the rest of a whole-numbered division.
Definition: INETMath.h:108
static std::vector< cModule * > modules
Definition: cSocketRTScheduler.h:59
static std::vector< int > headerLengths
Definition: cSocketRTScheduler.h:62
int32_t int32
Definition: Compat.h:31
static std::vector< int > datalinks
Definition: cSocketRTScheduler.h:61
static std::vector< pcap_t * > pds
Definition: cSocketRTScheduler.h:60
void inet::cSocketRTScheduler::startRun |
( |
| ) |
|
|
overridevirtual |
Called at the beginning of a simulation run.
78 fd = socket(AF_INET, SOCK_RAW, IPPROTO_RAW);
79 if (
fd == INVALID_SOCKET)
80 throw cRuntimeError(
"cSocketRTScheduler: Root privileges needed");
82 if (setsockopt(
fd, IPPROTO_IP,
IP_HDRINCL, (
char *)&on,
sizeof(on)) < 0)
83 throw cRuntimeError(
"cSocketRTScheduler: couldn't set sockopt for raw socket");
#define IP_HDRINCL
Definition: lwip_ip.h:69
static timeval baseTime
Definition: cSocketRTScheduler.h:63
int fd
Definition: cSocketRTScheduler.h:44
int32_t int32
Definition: Compat.h:31
cEvent * inet::cSocketRTScheduler::takeNextEvent |
( |
| ) |
|
|
overridevirtual |
Scheduler function – it comes from the cScheduler interface.
300 cEvent *
event =
FES(sim)->peekFirst();
302 targetTime.tv_sec = LONG_MAX;
303 targetTime.tv_usec = 0;
307 simtime_t eventSimtime =
event->getArrivalTime();
308 targetTime = timeval_add(
baseTime, eventSimtime.dbl());
313 gettimeofday(&curTime,
nullptr);
314 if (timeval_greater(targetTime, curTime))
320 event =
FES(sim)->peekFirst();
325 timeval diffTime = timeval_substract(curTime, targetTime);
326 EV <<
"We are behind: " << diffTime.tv_sec + diffTime.tv_usec * 1
e-6 <<
" seconds\n";
328 cEvent *tmp =
FES(sim)->removeFirst();
329 ASSERT(tmp == event);
static timeval baseTime
Definition: cSocketRTScheduler.h:63
const value< double, units::C > e(1.602176487e-19)
#define FES(sim)
Definition: cSocketRTScheduler.cc:44
virtual int receiveUntil(const timeval &targetTime)
Definition: cSocketRTScheduler.cc:266
timeval inet::cSocketRTScheduler::baseTime |
|
static |
std::vector< int32 > inet::cSocketRTScheduler::datalinks |
|
static |
int inet::cSocketRTScheduler::fd |
|
protected |
std::vector< int32 > inet::cSocketRTScheduler::headerLengths |
|
static |
std::vector< cModule * > inet::cSocketRTScheduler::modules |
|
static |
std::vector< pcap_t * > inet::cSocketRTScheduler::pds |
|
static |
The documentation for this class was generated from the following files: