forked from noahsug/CSMA-CD-emulator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathComputer.h
61 lines (47 loc) · 1.16 KB
/
Computer.h
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
#ifndef __COMPUTER_H__
#define __COMPUTER_H__
#include <vector>
#include "PriorityQueue.h"
class Event;
class Computer {
public:
static const unsigned KMAX = 10;
// values are in bit-times
static const unsigned TP = 512;
static const unsigned JAMMING_LENGTH = 48;
static const unsigned SENSE_MEDIUM_TIME = 96;
enum State {
IDLE = 0,
SENSING,
WAITING_TO_TRANSMIT,
TRANSMITTING,
BACKING_OFF,
};
Computer(PriorityQueue* events)
: events_(events)
, state_(IDLE)
, medium_busy_(false)
, backoff_count_(0)
, packet_queue_size_(0)
, last_jam_time_((unsigned long long)-1) {}
unsigned long GetBackoff();
unsigned PacketsInQueue() { return packet_queue_size_; }
void OnArrival();
void OnMediumSensed();
void OnMediumBusy();
void OnMediumFree();
void OnTransmittedFrame();
void OnRaspberryJam();
void OnBackoffDone();
void OnPacketReceived();
private:
PriorityQueue* events_;
State state_;
bool medium_busy_;
unsigned backoff_count_;
unsigned packet_queue_size_;
unsigned long long last_jam_time_;
std::vector<unsigned long long> cancellable_events_;
void CancelEvents();
};
#endif