/* File: server.c */ /* ********************************************************************* ALTERNATING BIT AND GO-BACK-N NETWORK EMULATOR Revised version of code by J.F. Kurose From the companion website for _Computer Networking: A Top-Down Approach Featuring the Internet_ by J.F. Kurose and K. W. Ross (c) 2001 by Addison Wesley Longman Based on document at (as of 02 July 2002) ********************************************************************* */ #include #include "message.h" #include "payload.h" #include "packet.h" #include "server.h" #include "KRnet.h" /* prototypes for private functions */ static void startTimer(float howlong); static void cancelTimer(void); static void sendToNWSlayer(packet_t packet); static void deliverToAppLayer(char datasent[]); /* ****************** */ /* Server functions */ /* ****************** */ void sendToNWSlayer(packet_t packet) { toNWSlayer(Server, packet); } /* sendToNWSlayer() */ void deliverToAppLayer(char datasent[]) { toAppLayer(Server, datasent); } /* deliverToAppLayer() */ void startTimer(float howlong) { startServerTimer(howlong); } /* startTimer() */ void cancelTimer(void) { stopServerTimer(); } /* cancelTimer() */ /******** STUDENTS WRITE THESE NEXT THREE (OR FOUR) ROUTINES ********/ /*-------------*/ /* serverInit */ /* *---------------------------------------------------*/ /* Called only once, before any other Server (entity B) routines */ /* are called. You can use it to do any initialization. */ /*-----------------------------------------------------------------*/ void serverInit(void) { } /* serverInit() */ /*------------*/ /* serverEnd */ /* *----------------------------------------------------*/ /* Called only once, after all other Server (entity B) routines */ /* are called. You can use it to print any final output. */ /*-----------------------------------------------------------------*/ void serverEnd(void) { }/* serverEnd() */ /*--------------*/ /* serverInput */ /* *--------------------------------------------------*/ /* */ /* called from layer 3 (Network Services), when a packet arrives */ /* for layer 4 (Transport) at Server (entity B) */ /* */ /* Note that with simplex transfer from Client (entity A) to */ /* Server (entity B), there is no Server_output() */ /*-----------------------------------------------------------------*/ void serverInput(packet_t packet) { }/* serverInput() */ /*-----------------------*/ /* serverTimerinterrupt */ /* *-----------------------------------------*/ /* */ /* Called when the server's timer goes off */ /*-----------------------------------------------------------------*/ void serverTimerInterrupt(void) { } /* serverTimerInterrupt() */ /*---------------*/ /* serverOutput */ /* *-------------------------------------------------*/ /* */ /* OPTIONAL: used only for bidirectional (duplex) transfer. */ /*-----------------------------------------------------------------*/ void serverOutput(message_t message) { return; } /* serverOutput()*/ /*--------------------------*/ /* serverCanSendMorePackets */ /* *--------------------------------------*/ /* */ /* called from the application layer (layer 5) , before passing */ /* data to GBN layer, return true(nonzero) if sliding window is */ /* not full, else return false (zero) */ /* */ /* OPTIONAL: used only for bidirectional (duplex) transfer. */ /*-----------------------------------------------------------------*/ int serverCanSendMorePkt(void) { /* if (nextseqnum < base + N ) return true; else return false; */ return 0; } /* EOF (server.c) */