prog2.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. #ifndef PROG2_H
  2. #define PROG2_H
  3. /* change to 1 if you're doing extra credit */
  4. /* and write a routine called B_output */
  5. //#define BIDIRECTIONAL 1
  6. typedef struct msg msg_t;
  7. typedef struct pkt pkt_t;
  8. typedef struct event event_t;
  9. /* a "msg" is the data unit passed from layer 5 (teachers code) to layer */
  10. /* 4 (students' code). It contains the data (characters) to be delivered */
  11. /* to layer 5 via the students transport level protocol entities. */
  12. struct msg {
  13. char data[20];
  14. };
  15. /* a packet is the data unit passed from layer 4 (students code) to layer */
  16. /* 3 (teachers code). Note the pre-defined packet structure, which all */
  17. /* students must follow. */
  18. struct pkt {
  19. int seqnum;
  20. int acknum;
  21. int checksum;
  22. char payload[20];
  23. };
  24. struct event {
  25. float evtime; /* event time */
  26. int evtype; /* event type code */
  27. int eventity; /* entity where event occurs */
  28. pkt_t *pktptr; /* ptr to packet (if any) assoc w/ this event */
  29. event_t *prev;
  30. event_t *next;
  31. };
  32. /* possible events: */
  33. #define TIMER_INTERRUPT 0
  34. #define FROM_LAYER5 1
  35. #define FROM_LAYER3 2
  36. #define OFF 0
  37. #define ON 1
  38. #define A 0
  39. #define B 1
  40. void insertevent(struct event *p);
  41. void init();
  42. void generate_next_arrival();
  43. /********* STUDENTS WRITE THE NEXT SEVEN ROUTINES *********/
  44. /* The following routine will be called once (only) before any other */
  45. /* entity A routines are called. You can use it to do any initialization */
  46. void A_init();
  47. /* called from layer 3, when a packet arrives for layer 4 */
  48. void A_input( pkt_t packet );
  49. /* called from layer 5, passed the data to be sent to other side */
  50. void A_output( msg_t message );
  51. /* called when A's timer goes off */
  52. void A_timerinterrupt();
  53. /* the following rouytine will be called once (only) before any other */
  54. /* entity B routines are called. You can use it to do any initialization */
  55. void B_init();
  56. /* called from layer 3, when a packet arrives for layer 4 at B*/
  57. void B_input( pkt_t packet );
  58. /* Note that with simplex transfer from a-to-B, there is no B_output() */
  59. void B_output( msg_t message ); /* need be completed only for extra credit */
  60. /* called when B's timer goes off */
  61. void B_timerinterrupt();
  62. /**
  63. * STUDENT CALLABLE FUNCTIONS: Dont implement (they allready are, int prog2.c)
  64. **/
  65. void starttimer( int AorB, float increment );
  66. /* called by students routine to cancel a previously-started timer */
  67. void stoptimer(int AorB);
  68. /* TOLAYER3 */
  69. void tolayer3( int AorB, pkt_t packet );
  70. /* TOLAYER5 */
  71. void tolayer5(int AorB, char datasent[20]);
  72. #endif