forked from noahsug/CSMA-CD-emulator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEvents.cpp
71 lines (56 loc) · 1.62 KB
/
Events.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include "Events.h"
#include "Environment.h"
#include "Computer.h"
#include <cmath>
#include <iostream>
#include "Clock.h"
#include "Random.h"
bool Event::operator<(const Event& e) {
return time_ < e.time_;
}
bool Event::operator>(const Event& e) {
return time_ > e.time_;
}
bool Event::operator<=(const Event& e) {
return time_ <= e.time_;
}
bool Event::operator>=(const Event& e) {
return time_ >= e.time_;
}
ArrivalEvent::ArrivalEvent(Computer* dest) {
dest_ = dest;
double rand = Random::GetDouble();
time_ = Clock::GetTime() +
(unsigned long long)((-1 / Environment::ARRIVAL_RATE) * log(1 - rand));
}
MediumSensedEvent::MediumSensedEvent(Computer* dest) {
dest_ = dest;
time_ = Clock::GetTime() + Computer::SENSE_MEDIUM_TIME;
}
MediumBusyEvent::MediumBusyEvent(Computer* dest) {
dest_ = dest;
time_ = Clock::GetTime() + 2*Environment::PROP_TIME;
}
MediumFreeEvent::MediumFreeEvent(Computer* dest) {
dest_ = dest;
time_ = Clock::GetTime() + Environment::PACKET_LENGTH;
}
TransmittedFrameEvent::TransmittedFrameEvent(Computer* dest) {
dest_ = dest;
time_ = Clock::GetTime() + Environment::PACKET_LENGTH;
}
RaspberryJamEvent::RaspberryJamEvent(Computer* dest) {
dest_ = dest;
time_ = Clock::GetTime() + 2*Environment::PROP_TIME;
}
BackoffDoneEvent::BackoffDoneEvent(Computer* dest) {
dest_ = dest;
unsigned long b = dest->GetBackoff();
unsigned long val = (1 << b) - 1;
unsigned long rand = Random::GetInt(val);
time_ = Clock::GetTime() + Computer::TP * rand;
}
PacketReceivedEvent::PacketReceivedEvent(Computer* dest) {
dest_ = dest;
time_ = Clock::GetTime() + Environment::PROP_TIME;
}