Main Page   Compound List   File List   Compound Members   File Members  

nettest.cc

Go to the documentation of this file.
00001 // nettest.cc 
00002 //      Test out message delivery between two "Nachos" machines,
00003 //      using the Post Office to coordinate delivery.
00004 //
00005 //      Two caveats:
00006 //        1. Two copies of Nachos must be running, with machine ID's 0 and 1:
00007 //              ./nachos -m 0 -o 1 &
00008 //              ./nachos -m 1 -o 0 &
00009 //
00010 //        2. You need an implementation of condition variables,
00011 //           which is *not* provided as part of the baseline threads 
00012 //           implementation.  The Post Office won't work without
00013 //           a correct implementation of condition variables.
00014 //
00015 // Copyright (c) 1992-1993 The Regents of the University of California.
00016 // All rights reserved.  See copyright.h for copyright notice and limitation 
00017 // of liability and disclaimer of warranty provisions.
00018 
00019 #include "copyright.h"
00020 
00021 #include "system.h"
00022 #include "network.h"
00023 #include "post.h"
00024 #include "interrupt.h"
00025 
00026 // Test out message delivery, by doing the following:
00027 //      1. send a message to the machine with ID "farAddr", at mail box #0
00028 //      2. wait for the other machine's message to arrive (in our mailbox #0)
00029 //      3. send an acknowledgment for the other machine's message
00030 //      4. wait for an acknowledgement from the other machine to our 
00031 //          original message
00032 
00033 void
00034 MailTest(int farAddr)
00035 {
00036     PacketHeader outPktHdr, inPktHdr;
00037     MailHeader outMailHdr, inMailHdr;
00038     char *data = "Hello there!";
00039     char *ack = "Got it!";
00040     char buffer[MaxMailSize];
00041 
00042     // construct packet, mail header for original message
00043     // To: destination machine, mailbox 0
00044     // From: our machine, reply to: mailbox 1
00045     outPktHdr.to = farAddr;             
00046     outMailHdr.to = 0;
00047     outMailHdr.from = 1;
00048     outMailHdr.length = strlen(data) + 1;
00049 
00050     // Send the first message
00051     postOffice->Send(outPktHdr, outMailHdr, data); 
00052 
00053     // Wait for the first message from the other machine
00054     postOffice->Receive(0, &inPktHdr, &inMailHdr, buffer);
00055     printf("Got \"%s\" from %d, box %d\n",buffer,inPktHdr.from,inMailHdr.from);
00056     fflush(stdout);
00057 
00058     // Send acknowledgement to the other machine (using "reply to" mailbox
00059     // in the message that just arrived
00060     outPktHdr.to = inPktHdr.from;
00061     outMailHdr.to = inMailHdr.from;
00062     outMailHdr.length = strlen(ack) + 1;
00063     postOffice->Send(outPktHdr, outMailHdr, ack); 
00064 
00065     // Wait for the ack from the other machine to the first message we sent.
00066     postOffice->Receive(1, &inPktHdr, &inMailHdr, buffer);
00067     printf("Got \"%s\" from %d, box %d\n",buffer,inPktHdr.from,inMailHdr.from);
00068     fflush(stdout);
00069 
00070     // Then we're done!
00071     interrupt->Halt();
00072 }

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