Your SlideShare is downloading. ×
0
NETWORK IN NACHOS The operating system can use a simulated network to send and receive small, fixed – length messages. Mes...
<ul><li>When data has been sent or when data is available to be received, interrupts are generated. The network simulation...
NachOs involved in the folders are: </li><ul><li>#include <fcntl.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>  </li></ul></ul>
Network.cc <ul>#include &quot;copyright.h&quot; #include &quot;system.h&quot; #include <strings.h> static void NetworkRead...
Upcoming SlideShare
Loading in...5
×

Nach os network

133

Published on

Published in: Education, Technology, Business
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
133
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
1
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Transcript of "Nach os network"

  1. 1. NETWORK IN NACHOS The operating system can use a simulated network to send and receive small, fixed – length messages. Message delivery is unreliable – messages may be lost.
  2. 2. <ul><li>When data has been sent or when data is available to be received, interrupts are generated. The network simulation is implemented using UNIX, domain sockets.
  3. 3. NachOs involved in the folders are: </li><ul><li>#include <fcntl.h>
  4. 4. #include <sys/types.h>
  5. 5. #include <sys/socket.h>
  6. 6. #include <netinet/in.h>
  7. 7. #include <arpa/inet.h>
  8. 8. #include <netdb.h> </li></ul></ul>
  9. 9. Network.cc <ul>#include &quot;copyright.h&quot; #include &quot;system.h&quot; #include <strings.h> static void NetworkReadPoll(int arg) { Network *net = (Network *)arg; net->CheckPktAvail(); } static void NetworkSendDone(int arg) { // Initialize the network emulation Network *net = (Network *)arg; net->SendDone(); } Network::Network(NetworkAddress addr, double reliability, VoidFunctionPtr readAvail, VoidFunctionPtr writeDone, int callArg) </ul>
  10. 10. Network.cc <ul>{ ident = addr; if (reliability < 0) chanceToWork = 0; else if (reliability > 1) chanceToWork = 1; else chanceToWork = reliability; // set up the stuff to emulate asynchronous interrupts writeHandler = writeDone; readHandler = readAvail; handlerArg = callArg; sendBusy = FALSE; inHdr.length = 0; </ul>
  11. 11. Network.cc <ul>sock = OpenSocket(); sprintf(sockName, &quot;SOCKET_%d&quot;, (int)addr); AssignNameToSocket(sockName, sock); // Bind socket to a filename in the current directory. interrupt->Schedule(NetworkReadPoll, (int)this, NetworkTime, NetworkRecvInt); } Network::~Network() { CloseSocket(sock); DeAssignNameToSocket(sockName); } </ul>
  12. 12. Network.cc <ul>void Network::CheckPktAvail() { interrupt->Schedule(NetworkReadPoll, (int)this, NetworkTime, NetworkRecvInt); if (inHdr.length != 0) // do nothing if packet is already buffered return; if (!PollSocket(sock)) // do nothing if no packet to be read return; char *buffer = new char[MaxWireSize]; ReadFromSocket(sock, buffer, MaxWireSize); inHdr = *(PacketHeader *)buffer; ASSERT((inHdr.to == ident) && (inHdr.length <= MaxPacketSize)); bcopy(buffer + sizeof(PacketHeader), inbox, inHdr.length); delete []buffer ; </ul>
  13. 13. Network.cc <ul>DEBUG('n', &quot;Network received packet from %d, length %d...n&quot;, (int) inHdr.from, inHdr.length); stats->numPacketsRecvd++; (*readHandler)(handlerArg); } void Network::SendDone() { sendBusy = FALSE; stats->numPacketsSent++; (*writeHandler)(handlerArg); } </ul>
  14. 14. Network.cc <ul>void Network::Send(PacketHeader hdr, char* data) { char toName[32]; sprintf(toName, &quot;SOCKET_%d&quot;, (int)hdr.to); ASSERT((sendBusy == FALSE) && (hdr.length > 0) && (hdr.length <= MaxPacketSize) && (hdr.from == ident)); DEBUG('n', &quot;Sending to addr %d, %d bytes... &quot;, hdr.to, hdr.length); interrupt->Schedule(NetworkSendDone, (int)this, NetworkTime, NetworkSendInt); if (Random() % 100 >= chanceToWork * 100) { // emulate a lost packet DEBUG('n', &quot;oops, lost it!n&quot;); return; } </ul>
  15. 15. Network.cc <ul>char *buffer = new char[MaxWireSize]; *(PacketHeader *)buffer = hdr; bcopy(data, buffer + sizeof(PacketHeader), hdr.length); SendToSocket(sock, buffer, MaxWireSize, toName); delete []buffer; } PacketHeader Network::Receive(char* data) { PacketHeader hdr = inHdr; inHdr.length = 0; if (hdr.length != 0) bcopy(inbox, data, hdr.length); return hdr; } </ul>
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×