Download presentation
Presentation is loading. Please wait.
1
Phase 4: Network For ACM05, By Mu LI
2
The Goal Implement a full-duplex, reliable, byte-stream communication with no size limits. Write a chat-room program to test your codes.
3
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)
4
A Graphic Example Provided
5
Codes provided machine.NetworkLink.java – provides ordered, unreliable, transmission of limits size packets between nodes machine.Packet.java – transmission unit ID (1 byte) Dst Link Src Link Content Len Data (<= 28 byte)
6
Your work Define the message formats over Packet.java
Design a socket states transition table
7
A sample format The control bit (FIN, …) take one bit, resp. and is in effect when 1 Blank is just for keeping regular ID (1 byte) Dst Link Src Link Content Len Dst Port Src Port Blank (1byte+4bit) F I N S T P A C K Y Sequence No (4 byte) Data (<=20 byte)
8
Message Types The message is the type iff all correspond control bits are 1 and the others are 0 Type Control bit Description SYN 请求同目标机器建立连接 SYN/ACK SYN, ACK 同意建立连接 DATA - 数据包 ACK 回答数据包 STP 使对方停止向己传输数据 FIN 通知对方己方数据传输已完成 FIN/ACK FIN, ACK 回答完成通知
9
The states for socket Name Description Duty CLOSED 无连接 等待连接或者连接已结束
SYN_SENT 已发送SYN 等待SYN/ACK SYN_RECVD 接受到SYN 调用accept() ESTABLISHED 全双工连接已建立 发送接受数据 STP_SENT 已发送STP 不过要将未发送完的数据发完 STP_RECVD 接受到STP 不再发送,不过可以接受 CLOSING 发送FIN 等待FIN/ACK,连接结束
10
The Events Cause Transition
Name Property Description CONNECT 主动调用 程序调用connect() ACCEPT 程序调用accept() RECV 程序调用read() SEND 程序调用write() CLOSE 程序调用close() TIMER 系统自动调用 SYN 接受到数据 接受到SYN包 SYNACK 接受到SYN/ACK包 DATA 接受到DATA包 ACK 接受到ACK包 STP 接受到STP包 FIN 接受到FIN包 FINACK 接受到FIN/ACK包
11
States Transition Table
Cur. State Event New State Operation CLOSED CONNECT SYN_SENT Send(SYN), block等待SYN/ACK RECV - 取数据出队,队为空时失败 SYN SYN_RCVD FIN Send(FINACK) (由于有可能FINACK丢失) TIMER Send(SYN) Deadlock! (双方都等待对方SYN/ACK) SYNACK ESTABLISHED 叫醒等待connect()的线程 DATA, STP, FIN 取数据出队 SEND 列数据入队,移动发送窗口 CLOSE CLOSING STP_SENT 如果发送队列为空,send(FIN) 否则send(STP) 重新发送未收到回答的包 Send(SYN/ACK) DATA 列包入队,send(ACK) ACK 转移发送窗口 STP STP_RCVD 清空发送队列 清空发送队列,send(FIN/ACK)
12
Class: MailMessage 持有其所对应的machine.Packet格式的对象packet
发送时使用NetworkLink.send()发送packet 重载hashcode()使得其与对应的packet有相同的hash,以便查找
13
Class: Socket Socket类保存一个端对端的全双工通讯的信息 Socket类继承自machine.Openfile
14
Socket.Read() 从接收缓冲队列receiveBuffer中读取字节,无等待的返回实际读到的字节数
receiveBuffer中消息按照先后顺序存放至多16个MailMessage,顺序是PostOffice保证的
15
Socket.Write() 将所需要写的字节分割打包成MailMessage 列队入发送窗口队列sendWindow
当sendWindow满了时,列队入发送缓冲队列sendBuffer
16
Class: PostOffice PostOffice类是实现状态转移的核心类,它管理所有的消息的发送与接受,维护所有的socket状态
运行时候只有一个实例,内部维护5条进程: 处理中断的receiveHandler和sendHandler 收发消息的receiveThread和sendThread 定时启动发送消息的timeoutThread
17
Class: NetProcess 主要任务是处理两个新的sysvcall: syscallConnect syscallAccept
首先新建相应的socket,将socket加入进程的descriptor table和PostOffice的socket table。然后维护socket状态,发送SYN,一直等待收到SYN/ACK才返回 syscallAccept 取出SYN,根据消息取出对应的socket,将socket放入进程的descriptor table,维护socket状态
18
Thank you Q & A
Similar presentations