www.pudn.com > ARQ.rar > protocol.h
#include "stdio.h"
#define MAX_PKT 4 /* determines packet size in bytes */
typedef enum {false, true} boolean; /* boolean type */
typedef unsigned int seq_nr; /* sequence or ack numbers */
typedef struct {unsigned char data[MAX_PKT];} packet; /* packet definition */
typedef enum {data, ack, nak} frame_kind; /* frame_kind definition */
typedef struct { /* frames are transported in this layer */
frame_kind kind; /* what kind of a 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(event_type *event)
{
printf("wait for event\n");
}
/* Fetch a packet from the network layer for transmission on the channel. */
void from_network_layer(packet *p)
{
printf("from network layer\n");
}
/* Deliver information from an inbound frame to the network layer. */
void to_network_layer(packet *p)
{
printf("to network layer\n");
}
/* Go get an inbound frame from the physical layer and copy it to r. */
void from_physical_layer(frame *r)
{
printf("from physical layer\n");
}
/* Pass the frame to the physical layer for transmission. */
void to_physical_layer(frame *s)
{
printf("to physical layer\n");
}
/* Start the clock running and enable the timeout event. */
void start_timer(seq_nr k)
{
printf("start timer\n");
}
/* Stop the clock and disable the timeout event. */
void stop_timer(seq_nr k)
{
printf("stop timer\n");
}
/* Start an auxiliary timer and enable the ack_timeout event. */
void start_ack_timer(void)
{
printf("start ack timer\n");
}
/* Stop the auxiliary timer and disable the ack_timeout event. */
void stop_ack_timer(void)
{
printf("stop ack timer\n");
}
/* Allow the network layer to cause a network_layer_ready event. */
void enable_network_layer(void)
{
printf("enable network layer\n");
}
/* Forbid the network layer from causing a network_layer_ready event. */
void disable_network_layer(void)
{
printf("disable network layer\n");
}
/* Macro inc is expanded in-line: Increment k circularly. */
#define inc(k) if (k < MAX_SEQ) k = k + 1; else k = 0