Main Page   Compound List   File List   Compound Members   File Members  

network.h

Go to the documentation of this file.
00001 // network.h 
00002 //      Data structures to emulate a physical network connection.
00003 //      The network provides the abstraction of ordered, unreliable,
00004 //      fixed-size packet delivery to other machines on the network.
00005 //
00006 //      You may note that the interface to the network is similar to 
00007 //      the console device -- both are full duplex channels.
00008 //
00009 //  DO NOT CHANGE -- part of the machine emulation
00010 //
00011 // Copyright (c) 1992-1993 The Regents of the University of California.
00012 // All rights reserved.  See copyright.h for copyright notice and limitation 
00013 // of liability and disclaimer of warranty provisions.
00014 
00015 #ifndef NETWORK_H
00016 #define NETWORK_H
00017 
00018 #include "copyright.h"
00019 #include "utility.h"
00020 
00021 // Network address -- uniquely identifies a machine.  This machine's ID 
00022 //  is given on the command line.
00023 typedef int NetworkAddress;      
00024 
00025 // The following class defines the network packet header.
00026 // The packet header is prepended to the data payload by the Network driver, 
00027 // before the packet is sent over the wire.  The format on the wire is:  
00028 //      packet header (PacketHeader)
00029 //      data (containing MailHeader from the PostOffice!)
00030 
00031 class PacketHeader {
00032   public:
00033     NetworkAddress to;          // Destination machine ID
00034     NetworkAddress from;        // source machine ID
00035     unsigned length;            // bytes of packet data, excluding the 
00036                                 // packet header (but including the 
00037                                 // MailHeader prepended by the post office)
00038 };
00039 
00040 #define MaxWireSize     64      // largest packet that can go out on the wire
00041 #define MaxPacketSize   (MaxWireSize - sizeof(struct PacketHeader))     
00042                                 // data "payload" of the largest packet
00043 
00044 
00045 // The following class defines a physical network device.  The network
00046 // is capable of delivering fixed sized packets, in order but unreliably, 
00047 // to other machines connected to the network.
00048 //
00049 // The "reliability" of the network can be specified to the constructor.
00050 // This number, between 0 and 1, is the chance that the network will lose 
00051 // a packet.  Note that you can change the seed for the random number 
00052 // generator, by changing the arguments to RandomInit() in Initialize().
00053 // The random number generator is used to choose which packets to drop.
00054 
00055 class Network {
00056   public:
00057     Network(NetworkAddress addr, double reliability,
00058           VoidFunctionPtr readAvail, VoidFunctionPtr writeDone, int callArg);
00059                                 // Allocate and initialize network driver
00060     ~Network();                 // De-allocate the network driver data
00061     
00062     void Send(PacketHeader hdr, char* data);
00063                                 // Send the packet data to a remote machine,
00064                                 // specified by "hdr".  Returns immediately.
00065                                 // "writeHandler" is invoked once the next 
00066                                 // packet can be sent.  Note that writeHandler 
00067                                 // is called whether or not the packet is 
00068                                 // dropped, and note that the "from" field of 
00069                                 // the PacketHeader is filled in automatically 
00070                                 // by Send().
00071 
00072     PacketHeader Receive(char* data);
00073                                 // Poll the network for incoming messages.  
00074                                 // If there is a packet waiting, copy the 
00075                                 // packet into "data" and return the header.
00076                                 // If no packet is waiting, return a header 
00077                                 // with length 0.
00078 
00079     void SendDone();            // Interrupt handler, called when message is 
00080                                 // sent
00081     void CheckPktAvail();       // Check if there is an incoming packet
00082 
00083   private:
00084     NetworkAddress ident;       // This machine's network address
00085     double chanceToWork;        // Likelihood packet will be dropped
00086     int sock;                   // UNIX socket number for incoming packets
00087     char sockName[32];          // File name corresponding to UNIX socket
00088     VoidFunctionPtr writeHandler; // Interrupt handler, signalling next packet 
00089                                 //      can be sent.  
00090     VoidFunctionPtr readHandler;  // Interrupt handler, signalling packet has 
00091                                 //      arrived.
00092     int handlerArg;             // Argument to be passed to interrupt handler
00093                                 //   (pointer to post office)
00094     bool sendBusy;              // Packet is being sent.
00095     bool packetAvail;           // Packet has arrived, can be pulled off of
00096                                 //   network
00097     PacketHeader inHdr;         // Information about arrived packet
00098     char inbox[MaxPacketSize];  // Data for arrived packet
00099 };
00100 
00101 #endif // NETWORK_H

Generated on Mon Feb 10 09:54:46 2003 for nachos by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002
The University of Southern California does not screen or control the content on this website and thus does not guarantee the accuracy, integrity, or quality of such content. All content on this website is provided by and is the sole responsibility of the person from which such content originated, and such content does not necessarily reflect the opinions of the University administration or the Board of Trustees