-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprotocol.h
66 lines (48 loc) · 2.28 KB
/
protocol.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
61
62
63
64
65
66
#ifndef PROTOCOL_H
#define PROTOCOL_H
#include <stdbool.h>
typedef struct simulator_state simulator_state;
#define MAX_SEQ 7
typedef enum {
frame_arrival,
cksum_err,
timeout,
network_layer_ready
} event_type;
#define MAX_PKT 8 /* determines packet size in bytes */
typedef unsigned int seq_nr; /* sequence or ack numbers */
typedef struct {
char data[MAX_PKT];
} packet; /* packet definition */
typedef enum { data, ack } frame_kind; /* frame kind definition */
typedef struct { /* frames are transported in this layer */
frame_kind kind; /* what kind of frame is it? */
seq_nr seq; /* sequence number */
seq_nr ack; /* acknowledgement number */
packet info; /* the network layer packet */
} frame;
/* Wait for an event to happen; return its type in event. */
void wait_for_event(simulator_state *simulator, event_type *event);
/* Fetch a packet from the network layer for transmission on the channel. */
void from_network_layer(simulator_state *simulator, packet *p);
/* Deliver information from an inbound frame to the network layer. */
void to_network_layer(simulator_state *simulator, packet *p);
/*Go get an inbound frame from the physical layer and copy it to r. */
void from_physical_layer(simulator_state *simulator, frame *r);
/* Pass the frame to the physical layer for transmission. */
void to_physical_layer(simulator_state *simulator, frame *s);
/* Start the clock running and enable the timeout event. */
void start_timer(simulator_state *simulator, seq_nr k);
/* Stop the clock and disable the timeout event. */
void stop_timer(simulator_state *simulator, seq_nr k);
/* Allow the network layer to cause a network layer ready event. */
void enable_network_layer(simulator_state *simulator);
/* Forbid the network layer from causing a network layer ready event. */
void disable_network_layer(simulator_state *simulator);
/* Macro inc is expanded in - line : increment k circularly. */
#define inc(k) \
if (k < MAX_SEQ) \
k = k + 1; \
else \
k = 0
#endif /* PROTOCOL_H */