180 likes | 376 Views
Phase 4: Network. For ACM05, By Mu LI. The Goal. Implement a full-duplex, reliable, byte-stream communication with no size limits. Write a chat-room program to test your codes. The network layer of nachos. IP Address LinkAddress Port Number Port Number
E N D
Phase 4: Network For ACM05, By Mu LI
The Goal • Implement a full-duplex, reliable, byte-stream communication with no size limits. • Write a chat-room program to test your codes.
The network layer of nachos • IP Address LinkAddress • Port Number Port Number • UDP Embedded in Machine.NetworkLink • UDP Packet Machine.Packet • TCP Embedded in the Network Package • TCP Packet Network.MailMessage • TCP Network Daemon Network.PostOffice • TCP Socket Tuple of (SrcLinkAddr, DestLinkAddr, SrcPort, DestPort)
A Graphic Example Provided
Codes provided • machine.NetworkLink.java – provides ordered, unreliable, transmission of limits size packets between nodes • machine.Packet.java – transmission unit
Your work • Define the message formats over Packet.java • Design a socket states transition table
A sample format • The control bit (FIN, …) take one bit, resp. and is in effect when 1 • Blank is just for keeping regular
Message Types • The message is the type iff all correspond control bits are 1 and the others are 0
Class: MailMessage • 持有其所对应的machine.Packet格式的对象packet • 发送时使用NetworkLink.send()发送packet • 重载hashcode()使得其与对应的packet有相同的hash,以便查找
Class: Socket • Socket类保存一个端对端的全双工通讯的信息 • Socket类继承自machine.Openfile
Socket.Read() • 从接收缓冲队列receiveBuffer中读取字节,无等待的返回实际读到的字节数 • receiveBuffer中消息按照先后顺序存放至多16个MailMessage,顺序是PostOffice保证的
Socket.Write() • 将所需要写的字节分割打包成MailMessage • 列队入发送窗口队列sendWindow • 当sendWindow满了时,列队入发送缓冲队列sendBuffer
Class: PostOffice • PostOffice类是实现状态转移的核心类,它管理所有的消息的发送与接受,维护所有的socket状态 • 运行时候只有一个实例,内部维护5条进程: • 处理中断的receiveHandler和sendHandler • 收发消息的receiveThread和sendThread • 定时启动发送消息的timeoutThread
Class: NetProcess • 主要任务是处理两个新的sysvcall: • syscallConnect • 首先新建相应的socket,将socket加入进程的descriptor table和PostOffice的socket table。然后维护socket状态,发送SYN,一直等待收到SYN/ACK才返回 • syscallAccept • 取出SYN,根据消息取出对应的socket,将socket放入进程的descriptor table,维护socket状态
Thank you • Q & A