00001 /* CHANNEL.H */ 00002 00003 #ifndef _CHANNEL_H_ 00004 #define _CHANNEL_H_ 00005 00006 #include "bytes.h" 00007 #include "Buffer.h" 00008 00009 00010 typedef enum { NoErrors, Random, File } errortype; 00011 00012 00013 #define MAX_FILENAME_LENGTH 256 00014 #define DEF_PACKET_SIZE 136 00015 #define DEF_CHANNEL_SPEED 30000 00016 #define DEF_CHANNEL_DELAY 100 00017 #define DEF_CHANNEL_ERROR NoErrors 00018 #define DEF_CHANNEL_BER 2.1e-2 00019 #define DEF_CHANNEL_FILE "./dect1.asc" 00020 00021 typedef struct { 00022 char label[256]; /* something like "Forward" or "Backward" */ 00023 errortype error; 00024 char filename[MAX_FILENAME_LENGTH]; /* only if errortype=FILE */ 00025 FILE *error_file; /* only if errortype=FILE */ 00026 int file_open; /* only if errortype=FILE 1 if efile open*/ 00027 float bit_error_rate; /* only if errortype=RANDOM */ 00028 Buffer *pdus; /* type=channel_pdu. 00029 * A list of the PDU's in the channel. 00030 */ 00031 00032 int transmission_speed; /* in bits per second */ 00033 int transmission_delay; /* in milliseconds */ 00034 00035 long int bit_count; /* number of bits xmitted over channel */ 00036 long int error_count; /* number of errors applied over channel */ 00037 00038 long int write_count; 00039 00040 long int read_count; 00041 00042 int error_offset; /* bits delay before channel applies errors */ 00043 } channel; 00044 00045 void apply_errors(byte *data, channel *chan); 00046 /* 00047 * This function will apply errors to the byte of data provided 00048 * based on the channel error characteristics (none, random, file) 00049 */ 00050 00051 int channel_write_indication(channel *one); 00052 /* 00053 * Called by MUX to see if it can write to the channel 00054 * Returns 0 if not ready to write, nonzero if ready to write 00055 * 00056 * The idea is to compare the actual amount of data written to 00057 * the amount of data that we are "allowed" to have written at 00058 * this point, based on the elapsed time and the transmission 00059 * speed. 00060 */ 00061 00062 int channel_write(channel *one, byte m); 00063 /* 00064 * Called by MUX to write bytes to the channel. 00065 * 00066 * Returns 1 if successful, 0 if unsuccessful 00067 */ 00068 00069 int channel_read_indication(channel *one); 00070 /* 00071 * Called by DEMUX to see if it can read a byte. 00072 * This is the complicated one. 00073 * 00074 * first, check to see if there is any data in the incoming buffer 00075 * second, check to see if the number of bytes that we have already read 00076 * is less than the amount we are "allowed" to have read at this point, 00077 * based on elapsed time, transmission delay, and transmission speed 00078 */ 00079 00080 byte channel_read(channel *one); 00081 /* 00082 * Called by DEMUX to read a byte from the channel. 00083 */ 00084 00085 channel *new_channel(char *name); 00086 /* 00087 * This function is called to make a new channel with label name 00088 */ 00089 00090 void close_channel(channel *c); 00091 /* 00092 * This function prints out the statistics for the channel 00093 * when the program is finished 00094 */ 00095 #endif 00096