├── Homework ├── HW1-2022spring.pdf ├── HW2-2022spring.pdf ├── my_sol_CS305 Homework 1.pdf └── my_sol_CS305 Homework 2.pdf ├── Lecture_Slide ├── CS305 Lec13.md ├── LocalDNSServer.py ├── Week1 - course overview and introduction.pdf ├── Week10-chapter4-part1.pdf ├── Week11-chapter4-part2.pdf ├── Week12-chapter4-part2-chapter5-part1 (1).pdf ├── Week12-chapter4-part2-chapter5-part1.pdf ├── Week13-chapter5-part2.pdf ├── Week14-chapter5-part2-chapter6-part1.pdf ├── Week15-chapter6-part2.pdf ├── Week16-chapter6-part2-chapter7.pdf ├── Week2-Chapter1-part1.pdf ├── Week3-Chapter1-part2-Chapter2-part1.pdf ├── Week4-Chapter2-part1.pdf ├── Week5-Chapter2-part2.pdf ├── Week6-Chapter2-part2-chapter3-part1.pdf ├── Week7-chapter3-part1.pdf ├── Week8-chapter3-part2.pdf ├── Week9-chapter3-part3.pdf ├── 第二章计网复习要点.md ├── 网络层:控制平面概念整理.md └── 计网 Lecture 13.md ├── Programming_Assignments ├── DNS server │ ├── CS305 Assignment1-0316.pdf │ ├── LocalDNSServer.py │ └── report on local DNS server.pdf ├── Danmuku System │ ├── README.md │ ├── http │ │ ├── .idea │ │ │ ├── .gitignore │ │ │ ├── http.iml │ │ │ ├── inspectionProfiles │ │ │ │ ├── Project_Default.xml │ │ │ │ └── profiles_settings.xml │ │ │ ├── misc.xml │ │ │ └── modules.xml │ │ ├── danmu.html │ │ ├── server.py │ │ └── test.py │ ├── requirement.pdf │ └── ws │ │ ├── .idea │ │ ├── .gitignore │ │ ├── inspectionProfiles │ │ │ ├── Project_Default.xml │ │ │ └── profiles_settings.xml │ │ ├── misc.xml │ │ ├── modules.xml │ │ └── ws.iml │ │ ├── danmu.html │ │ ├── main.js │ │ ├── server.py │ │ ├── style.css │ │ └── tempCodeRunnerFile.js └── Routing │ ├── .idea │ ├── .gitignore │ ├── Routing.iml │ ├── inspectionProfiles │ │ ├── Project_Default.xml │ │ └── profiles_settings.xml │ ├── misc.xml │ └── modules.xml │ ├── CS305 Assignment3-compare version.pdf │ ├── CS305 Assignment3-new version.pdf │ ├── PA3.py │ ├── data │ ├── 100router.txt │ ├── 100router_output.txt │ ├── 100router_test.txt │ ├── 10router.txt │ ├── 10router_output.txt │ ├── 10router_test.txt │ ├── debug1.txt │ ├── debug2.txt │ ├── input.txt │ ├── input2.txt │ ├── output.txt │ ├── output1.txt │ └── output2.txt │ └── testcase │ ├── input1.txt │ ├── input2.txt │ ├── output1.txt │ └── output2.txt ├── README.md ├── Video_CDN_Project ├── README.md ├── document │ ├── CS305_Video CDN_Project.pdf │ ├── howToRun.txt │ └── 计网project小结.md ├── graph │ ├── onelink_twoservers_06 │ │ ├── fairness.jpg │ │ ├── onelink.events │ │ ├── proxylog1.txt │ │ ├── proxylog2.txt │ │ ├── serverlog.txt │ │ ├── smoothness.jpg │ │ ├── twolink.events │ │ └── utilization.jpg │ ├── result.png │ ├── sharelink_twoservers_06 │ │ ├── fairness.jpg │ │ ├── onelink.events │ │ ├── proxylog1.txt │ │ ├── proxylog2.txt │ │ ├── serverlog.txt │ │ ├── sharelink.events │ │ ├── smoothness.jpg │ │ ├── twolink.events │ │ └── utilization.jpg │ ├── twolink_twoservers_01 │ │ ├── fairness.jpg │ │ ├── onelink.events │ │ ├── proxylog1.txt │ │ ├── proxylog2.txt │ │ ├── serverlog.txt │ │ ├── sharelink.events │ │ ├── smoothness.jpg │ │ ├── twolink.events │ │ └── utilization.jpg │ ├── twolink_twoservers_05 │ │ ├── fairness.jpg │ │ ├── onelink.events │ │ ├── proxylog1.txt │ │ ├── proxylog2.txt │ │ ├── serverlog.txt │ │ ├── sharelink.events │ │ ├── smoothness.jpg │ │ ├── twolink.events │ │ └── utilization.jpg │ └── twolink_twoservers_09 │ │ ├── fairness.jpg │ │ ├── onelink.events │ │ ├── proxylog1.txt │ │ ├── proxylog2.txt │ │ ├── serverlog.txt │ │ ├── sharelink.events │ │ ├── smoothness.jpg │ │ ├── twolink.events │ │ └── utilization.jpg └── source │ ├── dns.py │ ├── index4.html │ └── proxy9.py ├── concept └── 网络层:控制平面概念整理.md ├── picture ├── ISP.png └── access.png └── 计算机网络:自顶向下方法 概念整理.pdf /Homework/HW1-2022spring.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Leo-Adventure/CS305-Computer-Network/f1310a5bec455ee77fe768c79387274949952ed1/Homework/HW1-2022spring.pdf -------------------------------------------------------------------------------- /Homework/HW2-2022spring.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Leo-Adventure/CS305-Computer-Network/f1310a5bec455ee77fe768c79387274949952ed1/Homework/HW2-2022spring.pdf -------------------------------------------------------------------------------- /Homework/my_sol_CS305 Homework 1.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Leo-Adventure/CS305-Computer-Network/f1310a5bec455ee77fe768c79387274949952ed1/Homework/my_sol_CS305 Homework 1.pdf -------------------------------------------------------------------------------- /Homework/my_sol_CS305 Homework 2.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Leo-Adventure/CS305-Computer-Network/f1310a5bec455ee77fe768c79387274949952ed1/Homework/my_sol_CS305 Homework 2.pdf -------------------------------------------------------------------------------- /Lecture_Slide/CS305 Lec13.md: -------------------------------------------------------------------------------- 1 | ## CS305 Lec13 2 | 3 | ### Transition from IPv4 to IPv6 4 | 5 | 隧道技术(Tunneling):将IPV6 的数据报作为 payload 的方式放在 IPV4 的数据当中(由路由器完成) 6 | 7 | 进行封装,将 IPv6 的数据包封装到 IPv4 的数据当中,等到离开之后进行解封,去除 IPv4 头部![image-20220507163843613](C:\Users\86181\AppData\Roaming\Typora\typora-user-images\image-20220507163843613.png) 8 | 9 | IPv4 依然是主流的互联网协议,基础架构越底层,越难改变。 10 | 11 | ### 通用转发 & SDN 12 | 13 | 基于目的地转发:查询转发表,只是基于目的地进行转发 14 | 15 | 通用转发:match: 不只是基于目的地进行转发,还基于 header的相应字段; action: 也不只是可以转发,还可以进行丢包、调整、发送给控制器等动作;priority and count 16 | 17 | ### 控制平面 18 | 19 | 路由协议:找到一个从发送端到接收端的 good path 20 | 21 | -------------------------------------------------------------------------------- /Lecture_Slide/Week1 - course overview and introduction.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Leo-Adventure/CS305-Computer-Network/f1310a5bec455ee77fe768c79387274949952ed1/Lecture_Slide/Week1 - course overview and introduction.pdf -------------------------------------------------------------------------------- /Lecture_Slide/Week10-chapter4-part1.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Leo-Adventure/CS305-Computer-Network/f1310a5bec455ee77fe768c79387274949952ed1/Lecture_Slide/Week10-chapter4-part1.pdf -------------------------------------------------------------------------------- /Lecture_Slide/Week11-chapter4-part2.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Leo-Adventure/CS305-Computer-Network/f1310a5bec455ee77fe768c79387274949952ed1/Lecture_Slide/Week11-chapter4-part2.pdf -------------------------------------------------------------------------------- /Lecture_Slide/Week12-chapter4-part2-chapter5-part1 (1).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Leo-Adventure/CS305-Computer-Network/f1310a5bec455ee77fe768c79387274949952ed1/Lecture_Slide/Week12-chapter4-part2-chapter5-part1 (1).pdf -------------------------------------------------------------------------------- /Lecture_Slide/Week12-chapter4-part2-chapter5-part1.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Leo-Adventure/CS305-Computer-Network/f1310a5bec455ee77fe768c79387274949952ed1/Lecture_Slide/Week12-chapter4-part2-chapter5-part1.pdf -------------------------------------------------------------------------------- /Lecture_Slide/Week13-chapter5-part2.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Leo-Adventure/CS305-Computer-Network/f1310a5bec455ee77fe768c79387274949952ed1/Lecture_Slide/Week13-chapter5-part2.pdf -------------------------------------------------------------------------------- /Lecture_Slide/Week14-chapter5-part2-chapter6-part1.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Leo-Adventure/CS305-Computer-Network/f1310a5bec455ee77fe768c79387274949952ed1/Lecture_Slide/Week14-chapter5-part2-chapter6-part1.pdf -------------------------------------------------------------------------------- /Lecture_Slide/Week15-chapter6-part2.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Leo-Adventure/CS305-Computer-Network/f1310a5bec455ee77fe768c79387274949952ed1/Lecture_Slide/Week15-chapter6-part2.pdf -------------------------------------------------------------------------------- /Lecture_Slide/Week16-chapter6-part2-chapter7.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Leo-Adventure/CS305-Computer-Network/f1310a5bec455ee77fe768c79387274949952ed1/Lecture_Slide/Week16-chapter6-part2-chapter7.pdf -------------------------------------------------------------------------------- /Lecture_Slide/Week2-Chapter1-part1.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Leo-Adventure/CS305-Computer-Network/f1310a5bec455ee77fe768c79387274949952ed1/Lecture_Slide/Week2-Chapter1-part1.pdf -------------------------------------------------------------------------------- /Lecture_Slide/Week3-Chapter1-part2-Chapter2-part1.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Leo-Adventure/CS305-Computer-Network/f1310a5bec455ee77fe768c79387274949952ed1/Lecture_Slide/Week3-Chapter1-part2-Chapter2-part1.pdf -------------------------------------------------------------------------------- /Lecture_Slide/Week4-Chapter2-part1.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Leo-Adventure/CS305-Computer-Network/f1310a5bec455ee77fe768c79387274949952ed1/Lecture_Slide/Week4-Chapter2-part1.pdf -------------------------------------------------------------------------------- /Lecture_Slide/Week5-Chapter2-part2.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Leo-Adventure/CS305-Computer-Network/f1310a5bec455ee77fe768c79387274949952ed1/Lecture_Slide/Week5-Chapter2-part2.pdf -------------------------------------------------------------------------------- /Lecture_Slide/Week6-Chapter2-part2-chapter3-part1.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Leo-Adventure/CS305-Computer-Network/f1310a5bec455ee77fe768c79387274949952ed1/Lecture_Slide/Week6-Chapter2-part2-chapter3-part1.pdf -------------------------------------------------------------------------------- /Lecture_Slide/Week7-chapter3-part1.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Leo-Adventure/CS305-Computer-Network/f1310a5bec455ee77fe768c79387274949952ed1/Lecture_Slide/Week7-chapter3-part1.pdf -------------------------------------------------------------------------------- /Lecture_Slide/Week8-chapter3-part2.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Leo-Adventure/CS305-Computer-Network/f1310a5bec455ee77fe768c79387274949952ed1/Lecture_Slide/Week8-chapter3-part2.pdf -------------------------------------------------------------------------------- /Lecture_Slide/Week9-chapter3-part3.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Leo-Adventure/CS305-Computer-Network/f1310a5bec455ee77fe768c79387274949952ed1/Lecture_Slide/Week9-chapter3-part3.pdf -------------------------------------------------------------------------------- /Lecture_Slide/第二章计网复习要点.md: -------------------------------------------------------------------------------- 1 | ## 第二章计网复习要点 2 | 3 | [TOC] 4 | 5 | ### 电子邮件 6 | 7 | #### 2.3 8 | 9 | 电子邮件三部分:用户代理(user agent),邮件服务器(mail server)(邮件体系结构核心),简单邮件传输协议(SMTP) 10 | 11 | SMTP是因特网电子邮件主要的应用层协议,使用TCP可靠数据传输服务 12 | 13 | SMTP有两部分,客户端和服务器端 14 | 15 | #### 2.3.1 SMTP 16 | 17 | SMTP 是互联网电子邮件的核心 18 | 19 | 限制所有报文的报问题部分只能采用简单的7比特ASCII表示,所以在使用SMTP传送邮件之前先要转成ASCII码 20 | 21 | 不使用中间邮件服务器发送邮件 22 | 23 | 一个客户的多份报文通过同一个TCP连接传输(持续连接) 24 | 25 | 在报文当中发送一个只包含一个句点的向服务器指示报文结束 26 | 27 | #### 2.3.2 与HTTP对比 28 | 29 | 持续的HTTP 和 SMTP都使用持续连接 30 | 31 | HTTP 是一个拉协议(用户使用HTTP从服务器拉取信息),SMTP是一个推协议(发送邮件服务器把文件推向接受邮件服务器) 32 | 33 | SMTP报文必须按照7比特ASCII进行编码,但是HTTP不受这种限制 34 | 35 | #### 2.3.3 邮件报文格式 36 | 37 | 首部行包括,**From:**, **To:**, 也许包含一个**Subject:**, 38 | 39 | 在报文首部之后,通过空白行与报文体进行间隔 40 | 41 | SMTP uses a line containing only a period to mark the end of a message body. 42 | 43 | #### 2.3.4 邮件访问协议 44 | 45 | **POP3** 46 | 47 | 1. 特许(authorization): 用户代理发送铭文用户名以及口令鉴别用户 48 | 2. 事务处理:用户代理取回报文,并可以对报文做标记;用户代理通常被用户配置成”下载并删除“或者”下载并保留“的方式 49 | 3. 更新:结束POP3会话,会删除被标记为删除的报文 50 | 51 | 无法建立远程服务器文件夹以及为报文指派文件夹,且不维护POP3会话的用户状态信息 52 | 53 | **IMAP** 54 | 55 | 可以创建文件夹并且将邮件在不同文件夹之间移动 56 | 57 | 维护IMAP会话的用户状态信息 58 | 59 | 允许用户代理获取报文某些部分 60 | 61 | **基于Web的电子邮件** 62 | 63 | 用户代理就是普通的浏览器,和远程邮箱之间通信通过HTTP进行。 64 | 65 | 但是在服务器间发送接收邮件使用的还是SMTP 66 | 67 | ### DNS 68 | 69 | #### 2.4.1 DNS 提供的服务 70 | 71 | DNS是 72 | 73 | - 一个由分层的DNS服务器实现的分布式数据库 74 | - 一个使得主机能够查询分布式数据库的应用层协议 75 | 76 | 运行在UDP之上,使用53号端口 77 | 78 | DNS 服务: 79 | 80 | - 主机别名(host aliasing): 查询主机别名对应的主机规范名(canonical hostname) 81 | - 邮件服务器别名(mail server aliasing) 82 | - 负载分配(load distribution):由于有冗余的Web服务器,一个IP地址集合因此与同一个规范主机名相联系,所以,服务器在回答中循环这些地址次序 83 | 84 | #### 2.4.2 DNS 工作机理 85 | 86 | 集中式设计问题: 87 | 88 | - 单点故障(single point of failure) 89 | - 通信容量(traffic volume) 90 | - 远距离的集中式数据库(distant centralized database) 91 | - 维护(maintenance) 92 | 93 | 分布式设计: 94 | 95 | - 分布式、层次数据库:根服务器(提供TLD 的IP地址)、顶级域DNS服务器(提供权威DNS服务器的IP地址)、权威DNS服务器;本地服务器:不属于服务器的层次结构每个ISP都有一台本地的DNS服务器(默认名字服务器) 96 | - DNS缓存(caching):改善时延性能并减少在因特网到处传输的DNS报文数量;在一个请求链当中,如果某个DNS服务器接收到一个回答,就将其缓存到本地的存储器当中,但映射过一段时间后就会被丢弃 97 | 98 | #### 2.4.3 DNS记录和报文 99 | 100 | 每个DNS回答报文包含了**一条或者多条**资源记录(Resource Record, RR) 101 | 102 | 资源记录为一个包含了下列字段的四元组:(Name,Value, Type, TTL) 103 | 104 | Type A: name 是 主机名,value 是该主机名对应的IP地址 105 | 106 | Type NS:Name 是 域名,Value 是知道如何获得该域中主机IP地址的**权威DNS服务器的主机名** 107 | 108 | Type CNAME: Name 主机名, Value, 该主机名对应的规范主机名 109 | 110 | Type MX: Name 邮件服务器名,value 该邮件服务器对应的规范主机名 111 | 112 | **DNS报文** 113 | 114 | 首部区域:第一个字段是标识符,用于标识该查询;标志字段:指出报文是查询报文还是回复报文、是否是权威服务器、递归可用与否、首部之后各数据区域的长度 115 | 116 | 问题区域:名字字段、类型字段 117 | 118 | 回答区域:对最初请求名字的RR 119 | 120 | 权威区域、附加区域 121 | 122 | **在DNS数据库中插入记录** 123 | 124 | 在注册登记机构注册域名,提供基本和辅助权威DNS服务器名字和IP地址,该注册登记机构确保将一个类型NS和一个类型A记录输入TLD.com 服务器 125 | 126 | 并且还需要确保权威DNS服务器中有用于Web服务器的 A RR记录以及 MX RR记录 127 | 128 | ### P2P文件分发 129 | 130 | #### P2P 体系结构的扩展性 131 | 132 | 其中 $u_s$表示服务器接入链路的上载速率,$u_i$表示第$i$对等方接入链路的上载速率,$d_i$表示了第 $i$ 对等方接入链路下载速率。还用F表示被分发的文件长度(以比特计),$N$ 表示要获得的该文件副本的对等方数量。分发时间是所有 $N$个对等方得到该文件的副本所需要的时间。 133 | $$ 134 | D_{cs} = max\{\frac{NF}{u_s}, \frac{F}{d_{min}}\}\\ 135 | D_{p2p} = max\{\frac{F}{u_s}, \frac{F}{d_{min}}, \frac{NF}{u_s +\sum_{i=1}^{N}{u_i}}\} 136 | $$ 137 | 138 | 扩展性的直接成因:对等方除了是比特的消费者外还是它们的重新分发者。 139 | 140 | #### BitTorrent 141 | 142 | 参与一个特定文件分发的所有对等方的集合被称为一个洪流。在一个洪流中的对等方彼此下载等长度的文件块。 143 | 144 | 每个洪流具有一个基础设施节点,即追踪器。当一个新的对等方进入该洪流时,追踪器随机地从参与对等方的集合中选择对等方的一个子集,新的对等方如果能成功地与该集合中的对等方创建一个TCP连接,则该对等方为"邻近对等方" 145 | 146 | 最稀缺优先:一个对等方针对它没有的文件块在邻近对等方当中决定最稀缺的块,并首先请求那些最稀缺的块。其目标是(大致地)均衡每个块在洪流中的副本数量 147 | 148 | 响应决定,激励机制,一报还一报(Tit for Tat):每10秒重新计算提供文件的邻居提供文件的速率并且重新决定疏通4个对等方的集合,称之为疏通。每过30秒随机地选择另外一个邻居发送块 149 | 150 | ### 视频流和内容分发网 151 | 152 | #### 因特网视频 153 | 154 | 比特率越高,图像质量越好,用户的总体视觉体验越好 155 | 156 | 对流式视频最重要的性能度量是平均端到端吞吐量 157 | 158 | #### HTTP流 和 DASH 159 | 160 | DASH:经HTTP的动态适应性流,视频编码为几个不同的版本,客户用HTTP GET 请求报文一次选择一个不同的块。允许客户适应可用带宽 161 | 162 | 使用DASH之后,每个视频版本存储在HTTP服务器中,每个版本都有一个不同的URL。HTTP服务器也有一个告示文件,为每个版本提供了一个URL及其比特率。 163 | 164 | 客户首先请求该告示文件并得知不同的版本信息,然后在HTTP GET 请求报文中对每块指定一个URL 以及一个字节范围,一次选择一块 165 | 166 | #### 内容分发网(CDN) 167 | 168 | 专用CDN:由内容提供商自己拥有;第三方CDN:代表多个内容提供商分发内容 169 | 170 | CDN使用简单的拉策略,如果接受到用户请求时没有视频的缓存,那么就从某中心仓库或者是另一个集群检索该视频,向用户提供之后同时在本地存储一个副本 171 | 172 | **CDN操作**:CDN需要截获用户的视频请求,确定此事适合用于该用户的CDN服务器集群,并将客户的请求重定向到该集群的某台服务器。 173 | 174 | **集群选择策略**:动态地将客户定向到CDN中的某个服务器集群或者数据中心的机制。 175 | 176 | 地理上最为邻近;基于当前流量条件为客户决定最好的集群 177 | -------------------------------------------------------------------------------- /Lecture_Slide/网络层:控制平面概念整理.md: -------------------------------------------------------------------------------- 1 | ## 网络层:控制平面概念整理 2 | 3 | ### 概述 4 | 5 | - 计算转发表和流表方法:每路由器控制(OSPF、BGP)(与其他路由器的组件进行通信)以及 逻辑集中式控制(由逻辑集中式控制器计算并分发转发表) 6 | - 控制代理(CA) 功能:与控制器通信并且按控制器命令行事,不能直接相互交互也不能主动参与计算转发表(SDN) 7 | 8 | ### 路由选择算法 9 | 10 | - 目的:从发送方到接收方的过程中确定一条通过路由器网络的好的路径(通常是最低开销) 11 | - 分类方式: 12 | - 集中式路由选择算法(centralized)具有全局状态信息(链路状态(Link state)算法) 13 | - 分散式路由选择算法(decentralized)使用迭代、分布式的方式计算出最低开销路径,没有完整信息,距离向量算法(DV算法) 14 | - 第二种分类方式: 15 | - 静态路由选择算法(static)路由随时间变化非常缓慢,通常是人工进行调整 16 | - 动态路由选择算法(dynamic)随着网络流量负载或拓扑发生变化而改变路由选择路径 17 | 18 | #### 链路状态路由选择算法(LS 算法) 19 | 20 | 通过让每个节点向网络中所有其他节点广播链路状态分组来完成全局信息输入,经常由链路状态广播算法来完成 21 | 22 | Dijkstra 算法 23 | 24 | #### 距离向量路由选择算法(DV 算法) 25 | 26 | 分布式:每个节点都要从一个或者多个直接相连邻居接收某些信息 27 | 28 | 迭代:过程持续到邻居之间没有更多信息要交换为止 29 | 30 | 异步:不要求所有节点相互之间步伐一致地操作 31 | 32 | 过程:当节点 x 发现它的直接相连的链路开销变化或从某个邻居接收到一个距离向量的更新时,就更新其距离向量估计值。 33 | 34 | 链路开销改变和链路故障 35 | 36 | 增加毒性逆转:如果 z 通过 y 路由选择到目的地 x, 则 z 将会通告 y,它到 x 的距离是无穷大 37 | 38 | #### 算法比较 39 | 40 | ##### 报文复杂性 41 | 42 | LS 要求每个节点都知道网络中每条链路的开销。而DV 算法只要求在每次迭代时,在两个直接相连的邻居之间交换报文。 43 | 44 | ##### 收敛速度 45 | 46 | DV 算法相较于 LS 算法收敛较慢,且会遇到路由选择环路以及无穷计数问题 47 | 48 | ##### 健壮性 49 | 50 | 在 LS 算法下,路由计算在某种程度上面是分离的,一个 LS 节点仅仅计算自己的转发表。 51 | 52 | DV 算法则会想任意或者所有目的节点通告其不正确的最低开销路径。 53 | 54 | ### 因特网自治系统内部的路由选择:OSPF 55 | 56 | 在相同 AS 中的路由器都运行相同的路由选择算法并且有彼此的信息,在一个自治系统内运行的路由选择算法叫做自治系统内部路由选择协议(intra-autonomous system routing protocal)kaifan 57 | 58 | #### 开放最短路优先(OSPF) 59 | 60 | OSPF 是一种链路状态协议,使用洪泛链路状态信息和 Dijkstra 最低开销路径算法。 61 | 62 | 使用 OSPF 时,路由器向自治系统内所有其他路由器广播路由选择信息,而不仅仅是向其相邻路由器广播 63 | 64 | 如果链路状态变化,则路由器就会广播链路状态信息;即使没有变化,路由器也会周期性的广播链路状态。 65 | 66 | ##### 优点 67 | 68 | - 安全:能够鉴别 OSPF 路由器之间的交换,仅有受信任的路由器能参与一个 AS 内的 OSPF 协议,因此可以防止恶意入侵者将不正确的信息注入路由表内。 69 | - 可以选择多条相同开销的路径,无须仅仅使用单一的路径来承载所有的流量 70 | - 对单播和多播路由选择的综合支持 71 | - 支持在单个 AS 内部提供层次结构 72 | 73 | ### ISP 之间的路由选择:BGP 74 | 75 | 分组跨越多个 AS 进行路由时,需要自治系统间路由选择协议(intra-autonomous system routing protocol)。 76 | 77 | 因为 AS 间路由协议涉及多个 AS 之间的协调,所以 AS 通信必须运行相同的 AS 间路由选择协议,在互联网当中,所有的 AS 运行相同的 AS 间路由选择协议,成为边界网关协议(Border Gateway Protocol **BGP**) 78 | 79 | #### BGP 作用 80 | 81 | 在 BGP 中,分组并不是路由到一个特定的目的地址,相反是路由到 CIDR 化的前缀,其中每个前缀表示一个子网或者一个子网的集合。 82 | 83 | - 从邻居 AS 获得前缀的可达性信息 84 | - 确定到该前缀的“最好的”路由 85 | 86 | #### 通告 BGP 路由信息 87 | 88 | 对于每个 AS, 每台路由器要么是一台网关路由器,要么是一台内部路由器 89 | 90 | 每条直接连接以及所有通过该连接发送的 BGP 报文成为 BGP 连接,跨越两个 AS 的 BGP 连接成为外部 BGP(eBGP),在相同 AS 中的两台路由器之间的 BGP 会话称为 内部 BGP 连接 (iBGP) 91 | 92 | 为了传播可达性信息,使用了 iBGP 和 eBGP 会话。 93 | 94 | #### 确定最好的路由 95 | 96 | 当路由器通过 BGP 连接通告前缀时,它在前缀中包括一些 BGP 属性。用BGP术语来说,前缀以及其属性称为路由。 97 | 98 | 两个较为重要的属性是 AS-PATH 和 NEXT-HOP。AS-PATH 属性包含了通告已经通过的 AS 列表。如果一台路由器在路径列表中看到了包含它自己的 AS, 它将拒绝该通告。NEXT-HOP 是 AS-PATH 起始的路由器接口的 IP 地址, 99 | 100 | ##### 热土豆路由选择 101 | 102 | 1. 从 AS 间协议学到经多个网关可达子网 103 | 2. 使用来自 AS 内部协议的路由选择信息,以决定到达每个网关的最低开销路径的开销 104 | 3. 热土豆路由选择:选择具有最小最低开销的网关 105 | 4. 从转发表确定通往最低开销网关的接口 I,在转发表中加入表项(x, I) 106 | 107 | ##### 路由选择算法 108 | 109 | 1. 路由被指派一个本地偏好值作为属性之一 110 | 2. 从余下的路由中选择具有最短 AS-PATH 的路由 111 | 3. 从余下的路由中,使用热土豆路由选择,即选择最靠近 NEXT-HOP 的路由 112 | 4. 最后使用BGP标识选择路由 -------------------------------------------------------------------------------- /Lecture_Slide/计网 Lecture 13.md: -------------------------------------------------------------------------------- 1 | ## 计网 Lecture 13 2 | 3 | ### 回顾 4 | 5 | 通用转发(generalized forwarding):不仅仅根据目的地进行下一跳路径的选择,并且动作也不止转发 6 | 7 | 控制平面转发算法 8 | 9 | 每一个路由器等待邻居发送距离向量,并根据这个距离向量去更新转发表,如果距离改变,则还需要通知邻居节点做更新 10 | 11 | 分布式(distributed):并不知道全局的网络拓扑,只知道邻居到附近的最短路径的值。 12 | 13 | 迪杰斯特拉算法需要每一个路由器去进行全局广播,才能计算最终的路径,所以在实际当中使用bellmanFord 算法。 14 | 15 | ### 距离向量(distance vector)(BellmanFord) 16 | 17 | 只需要计算下一跳是哪一个路由器即可,初始化除了邻居,距离都是 $\infin$,所有节点都会发送自己的距离向量给邻居,每一个节点在接收完邻居的距离向量之后进行计算与更新,并进行传递 + 更新,直到最后距离向量不再改变,整个迭代停止。是一个异步算法,不需要等待所有节点才能更新。 18 | 19 | #### 优点 20 | 21 | - 链路代价变小的消息传递地很快,产生很迅速的影响 22 | 23 | - 链路代价变大的消息传递地很慢,需要不断反复更新 24 | 25 | ### 链路状态与距离向量对比 26 | 27 | 链路状态:$O(N^2)$ 的消息复杂度,速度比较稳定,鲁棒性好(只计算自己的路由,影响的都是本地的运算) 28 | 29 | 距离向量:收敛的时间难以估计,速度不稳定(可能有路由环路、无穷问题),鲁棒性不好(任何一个路由器出错,错误的代价非常高(黑洞问题,错误传遍网络)) 30 | 31 | ### ISP 之间的路由(OSPF) 32 | 33 | 之前讲的算法都是比较理想化的场景,假设所有路由器都是一样的,且网络没有层级结构,这样会导致以下问题 34 | 35 | - 路由器数量很多的时候,如果每一个路由器都需要维护一个路由表,则会造成路由表的规模非常大。 36 | - 路由表本身也是一个市场,则每一个服务商都会进行相互的竞争,与 ISP 管理自治冲突 37 | 38 | 每一个 自治系统 (AS) 内部有自己的路由算法,在 AS 边缘,需要一个网关路由器,负责和其他的 AS 进行连接以及信息交互。网关路由处理来自其他 AS 传递过来的路由 39 | 40 | ### BGP(边界网关协议) 41 | 42 | -------------------------------------------------------------------------------- /Programming_Assignments/DNS server/CS305 Assignment1-0316.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Leo-Adventure/CS305-Computer-Network/f1310a5bec455ee77fe768c79387274949952ed1/Programming_Assignments/DNS server/CS305 Assignment1-0316.pdf -------------------------------------------------------------------------------- /Programming_Assignments/DNS server/report on local DNS server.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Leo-Adventure/CS305-Computer-Network/f1310a5bec455ee77fe768c79387274949952ed1/Programming_Assignments/DNS server/report on local DNS server.pdf -------------------------------------------------------------------------------- /Programming_Assignments/Danmuku System/README.md: -------------------------------------------------------------------------------- 1 | # Danmuku System 2 | 3 | ## Basic part 4 | 5 | ### Web Socket 6 | 7 | #### Building a Websocket connection 8 | 9 | Using 10 | 11 | ```js 12 | var ws = new WebSocket('ws://localhost:8765'); 13 | ``` 14 | 15 | to build the websocket connection to `localhost:8765` 16 | 17 | #### Receiving danmakus with "Send" button and send the danmakus 18 | 19 | Using the code showing below, we can receive the message by "click" action, then accept the danmakus information in web page. Then I wiil send the message to the server using "send" method. 20 | 21 | ```javascript 22 | $(".send").on("click", function () { 23 | const v = document.getElementById("danmakutext").value; 24 | ws.send(v) 25 | }); 26 | ``` 27 | 28 | #### Broadcast to all the clients and show the danmakus in them 29 | 30 | In Python code, when I finish building the connection to the websocket server, I can maintein a global list to record all the clients connecting to the server. 31 | 32 | ```python 33 | connected.append(websocket) 34 | 35 | ``` 36 | 37 | Then the server will accept all the information sent by clients, then will broadcast the message to all the clients, then the clients will show the message reveived. 38 | 39 | ```python 40 | while True: 41 | msg = await websocket.recv() 42 | websockets.broadcast(connected, msg) 43 | print ("Receive a message: {}".format(msg)) 44 | ``` 45 | 46 | ```js 47 | ws.onmessage = function (data) { 48 | const rec_danmuku = createDanmaku(data.data); 49 | addInterval(rec_danmuku); 50 | } 51 | ``` 52 | 53 | #### The exit of client 54 | 55 | The exit of client will trigger a `websockets.exceptions.ConnectionClosedOK` exception, then we can catch the exception then signal the exit information to user. 56 | 57 | ```python 58 | try: 59 | while True: 60 | msg = await websocket.recv() 61 | websockets.broadcast(connected, msg) 62 | except websockets.exceptions.ConnectionClosedOK: 63 | print("Bye{}".format(name)) 64 | finally: 65 | connected.remove(websocket) 66 | websocket.close() 67 | ``` 68 | 69 | #### Display the history danmakus in newcomer client 70 | 71 | Using a global list to save all the history danmakus, we can make all the newcomer client will display all the history danmakus. 72 | 73 | ```python 74 | for msg in history: 75 | await websocket.send(msg) 76 | ``` 77 | 78 | The 'history' in it save the history danmakus. 79 | 80 | The basic part of websocket danmakus is shown as above. 81 | 82 | ### HTTP Part 83 | 84 | #### Send Danmakus to Server 85 | 86 | By concat the danmakus in the end of url, we can then use POST method to pass the danmakus to the server. 87 | 88 | ```javascript 89 | $(".send").on("click", function () { 90 | 91 | const v = document.getElementById("danmakutext").value; 92 | console.log(v) 93 | url = "http://127.0.0.1:8765/" + v 94 | 95 | $.post(url, v, function (data) { 96 | 97 | }); 98 | 99 | }); 100 | ``` 101 | 102 | #### Receive and save the danmakus. 103 | 104 | By analyze the path information passed by url, the server can extract the danmakus information from URL and save it. 105 | 106 | ```python 107 | if httpHeader.get('method') == 'POST': 108 | danmu = httpHeader.path 109 | danmu = danmu[1:len(danmu)] 110 | danmakus.append(danmu) # save in the global list 111 | httpHeader.set_state('200 OK') 112 | writer.write(httpHeader.message().encode(encoding='utf-8') 113 | ``` 114 | 115 | #### Require the danmakus by polling 116 | 117 | ```javascript 118 | // 发起长轮询,得到弹幕之后进行create 之后addinterval发送 119 | setInterval("request();", 0.001 * 60 * 1000);//每隔一段时间执行一次request 函数 120 | 121 | function request() { 122 | 123 | request_danmu_url = "http://127.0.0.1:8765/" + id; 124 | 125 | $.get(request_danmu_url, function (data) { 126 | // console.log("In conducting...") 127 | // console.log(data) 128 | // get the id information from data 129 | if (data != '') { 130 | // get the danmakus information 131 | // console.log("data is not empty") 132 | const danmaku_to_print = createDanmaku(data); 133 | addInterval(danmaku_to_print); 134 | id = id + 1; 135 | } 136 | }) 137 | } 138 | ``` 139 | 140 | #### Send the danmakus information 141 | 142 | When the server reveive the "GET" request to get new danmakus information, the server will use "writer.write" method to write back the danmakus information to the client. 143 | 144 | ```javascript 145 | id = httpHeader.get('path')[1:] 146 | id = int(id) 147 | httpHeader.set_state('200 OK') 148 | writer.write(httpHeader.message().encode(encoding='utf-8')) 149 | if id < len(danmakus): #return the danmakus required by client 150 | for index in range(id, len(danmakus)): 151 | writer.write(danmakus[index].encode(encoding='utf-8')) 152 | ``` 153 | 154 | 155 | 156 | 157 | ## Result show 158 | 159 | ### Websocket 160 | 161 | ![image-20220427232042671](C:\Users\86181\AppData\Roaming\Typora\typora-user-images\image-20220427232042671.png) 162 | 163 | ### HTTP 164 | 165 | ![image-20220427231507893](C:\Users\86181\AppData\Roaming\Typora\typora-user-images\image-20220427231507893.png) 166 | 167 | 168 | 169 | ## Bonus Part 170 | 171 | ### Beautify the Danmakus 172 | 173 | Changing the HTML code to make the color and size of danmakus to change in random. Then the users will find it comfortable to watch the danmakus. 174 | 175 | ```javascript 176 | var timestamp = Date.parse(new Date()); 177 | timestamp = timestamp % 255; 178 | var time_str_r = timestamp + ""; 179 | var time_str_g = (timestamp + Math.random() * 100) % 255 + ""; 180 | var time_str_b = (timestamp + Math.random() * 200) % 255 + ""; 181 | const jqueryDom = $("
" + text + "
"); 182 | const fontColor = "rgb(" + time_str_r + "," + time_str_g + "," + time_str_b + ")"; 183 | var fsize = (Math.random() * 20 + 20) + ""; 184 | const fontSize = fsize + "px"; 185 | ``` 186 | 187 | And I also change the margin color and add background picture, etc to make the system more beatiful. 188 | 189 | ![image-20220427234720200](C:\Users\86181\AppData\Roaming\Typora\typora-user-images\image-20220427234720200.png) 190 | 191 | ## Comparision between WebSocket and HTTP 192 | 193 | 1. Websocket is a two-way communication protocol, which can send or receive information in both directions. While HTTP is a one-way communication protocol, which can only be launched by client, not server. 194 | 2. After I implemented the two version of Danmakus system, I noticed that the WebSocket requires a handshake between the browser and the server to establish a connection, while http is a connection initiated by the browser to the server. 195 | 3. Because of the polling rule in HTTP, the pressure of server is bigger than the Websocket server. 196 | 4. The data transmitted by Websocket is usually less than which sent by HTTP, because the HTTP is stateless, which means that redundant information about the request is sent in every HTTP request and response in order to use Cookie to identify client, while Websocket client has its status. The transmission of Websocket upgrade the efficiency compared to HTTP. 197 | 5. The speed of Websocket is faster than the HTTP. Because data is displayed on the client side using a web socket, which is continuously sent by the backend server. In WebSocket, data is continuously pushed/transmitted into the same connection that is already open, while HTTP will somtimes close the connection after return some information, which is why WebSocket is faster than HTTP and improves application performance. 198 | -------------------------------------------------------------------------------- /Programming_Assignments/Danmuku System/http/.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | -------------------------------------------------------------------------------- /Programming_Assignments/Danmuku System/http/.idea/http.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 12 | -------------------------------------------------------------------------------- /Programming_Assignments/Danmuku System/http/.idea/inspectionProfiles/Project_Default.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 12 | -------------------------------------------------------------------------------- /Programming_Assignments/Danmuku System/http/.idea/inspectionProfiles/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | -------------------------------------------------------------------------------- /Programming_Assignments/Danmuku System/http/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /Programming_Assignments/Danmuku System/http/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Programming_Assignments/Danmuku System/http/danmu.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Danmaku 7 | 8 | 9 | 10 | 11 | 12 |
13 |
14 | 15 | 16 |
17 | 18 | 19 |
20 | 59 | 60 | 61 | 62 | 63 | 141 | 142 | 143 | -------------------------------------------------------------------------------- /Programming_Assignments/Danmuku System/http/server.py: -------------------------------------------------------------------------------- 1 | import asyncio 2 | import json 3 | 4 | keys = ('method', 'path', 'Range') 5 | danmakus = [] 6 | 7 | class HTTPHeader: 8 | """ 9 | HTTPHeader template, you can use it directly 10 | """ 11 | 12 | def __init__(self): 13 | self.headers = {key: None for key in keys} 14 | self.version = '1.0 ' 15 | self.server = 'Tai' 16 | self.contentLength = None 17 | self.contentRange = None 18 | self.contentType = None 19 | self.location = None 20 | self.range = None 21 | self.state = None 22 | 23 | def parse_header(self, line): 24 | fileds = line.split(' ') 25 | if fileds[0] == 'GET' or fileds[0] == 'POST' or fileds[0] == 'HEAD': 26 | self.headers['method'] = fileds[0] 27 | self.headers['path'] = fileds[1] 28 | fileds = line.split(':', 1) 29 | if fileds[0] == 'Range': 30 | start, end = (fileds[1].strip().strip('bytes=')).split('-') 31 | self.headers['Range'] = start, end 32 | 33 | def set_version(self, version): 34 | self.version = version 35 | 36 | def set_location(self, location): 37 | self.location = location 38 | 39 | def set_state(self, state): 40 | self.state = state 41 | 42 | def set_info(self, contentType, contentRange): 43 | self.contentRange = contentRange 44 | self.contentType = contentType 45 | 46 | def set_range(self): 47 | start, end = self.headers['Range'] 48 | contentRange = int(self.contentRange) 49 | if start == '': 50 | end = int(end) 51 | start = contentRange - end 52 | end = contentRange - 1 53 | if end == '': 54 | end = contentRange - 1 55 | start = int(start) 56 | end = int(end) 57 | self.contentLength = str(end - start + 1) 58 | self.range = (start, end) 59 | 60 | def get(self, key): 61 | return self.headers.get(key) 62 | 63 | def message(self): # Return response header 64 | return 'HTTP/' + self.version + self.state + '\r\n' \ 65 | + ('Content-Length:' + self.contentLength + '\r\n' if self.contentLength else '') \ 66 | + ('Content-Type:' + 'text/html' + '; charset=utf-8' + '\r\n' if self.contentType else '') \ 67 | + 'Server:' + self.server + '\r\n' \ 68 | + ('Accept-Ranges: bytes\r\n' if self.range else '') \ 69 | + ('Content-Range: bytes ' + str(self.range[0]) + '-' + str( 70 | self.range[1]) + '/' + self.contentRange + '\r\n' if self.range else '') \ 71 | + ('Location: ' + self.location + '\r\n' if self.location else '') \ 72 | + 'Connection: close\r\n' + '\r\n' 73 | 74 | 75 | 76 | 77 | 78 | async def dispatch(reader, writer): 79 | # Use reader to receive HTTP request 80 | # Writer to send HTTP request 81 | httpHeader = HTTPHeader() 82 | while True: 83 | data = await reader.readline() 84 | message = data.decode() 85 | httpHeader.parse_header(message) 86 | if data == b'\r\n': 87 | break 88 | if data == b'': 89 | break 90 | # if the type is GET PAGE or the path is '/favicon.ico' 91 | if httpHeader.get('method') == 'GET': 92 | if httpHeader.get('path') == '/' or httpHeader.get('path') == '/favicon.ico': 93 | httpHeader.set_state('200 OK') 94 | writer.write(httpHeader.message().encode(encoding='utf-8')) # construct 200 OK HTTP header 95 | html_page = open("danmu.html", encoding='utf-8') 96 | contents = html_page.readlines() 97 | homepage = '' 98 | for e in contents: 99 | homepage += e 100 | writer.write(homepage.encode()) # Response for GET PAGE 101 | else: # if the get type is NEWDAMAKUS 102 | id = httpHeader.get('path')[1:] 103 | id = int(id) 104 | httpHeader.set_state('200 OK') 105 | writer.write(httpHeader.message().encode(encoding='utf-8')) 106 | if id < len(danmakus): #return the danmakus required by client 107 | for index in range(id, len(danmakus)): 108 | writer.write(danmakus[index].encode(encoding='utf-8')) 109 | # if the type is POST, then extract the danmakus in it and save it. 110 | if httpHeader.get('method') == 'POST': 111 | # print("receive POST") 112 | danmu = httpHeader.get('path') 113 | danmu = danmu[1:len(danmu)] 114 | danmakus.append(danmu) 115 | # print(danmu) 116 | httpHeader.set_state('200 OK') 117 | writer.write(httpHeader.message().encode(encoding='utf-8')) # construct 200 OK HTTP header 118 | 119 | writer.close() 120 | 121 | 122 | if __name__ == '__main__': 123 | port = 8765 124 | loop = asyncio.new_event_loop() 125 | asyncio.set_event_loop(loop) 126 | co_ro = asyncio.start_server(dispatch, '127.0.0.1', port) 127 | server = loop.run_until_complete(co_ro) 128 | try: 129 | loop.run_forever() 130 | except KeyboardInterrupt: 131 | pass 132 | server.close() 133 | loop.run_until_complete(server.wait_closed()) 134 | loop.close() 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | -------------------------------------------------------------------------------- /Programming_Assignments/Danmuku System/http/test.py: -------------------------------------------------------------------------------- 1 | import re 2 | 3 | price = '25.34-34.55' 4 | 5 | test = re.compile(r'[1-9]\d*\.\d*|0\.\d*[1-9]|[1-9]\d*').findall(price)[0] 6 | test2 = re.compile(r'-[1-9]\d*\.\d*|-0\.\d*[1-9]|-[1-9]\d*').findall(price)[0] 7 | 8 | i = float(test) 9 | x = -float(test2) 10 | print(i) 11 | print(x) -------------------------------------------------------------------------------- /Programming_Assignments/Danmuku System/requirement.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Leo-Adventure/CS305-Computer-Network/f1310a5bec455ee77fe768c79387274949952ed1/Programming_Assignments/Danmuku System/requirement.pdf -------------------------------------------------------------------------------- /Programming_Assignments/Danmuku System/ws/.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | -------------------------------------------------------------------------------- /Programming_Assignments/Danmuku System/ws/.idea/inspectionProfiles/Project_Default.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 12 | -------------------------------------------------------------------------------- /Programming_Assignments/Danmuku System/ws/.idea/inspectionProfiles/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | -------------------------------------------------------------------------------- /Programming_Assignments/Danmuku System/ws/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /Programming_Assignments/Danmuku System/ws/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Programming_Assignments/Danmuku System/ws/.idea/ws.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 12 | -------------------------------------------------------------------------------- /Programming_Assignments/Danmuku System/ws/danmu.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Danmaku 6 | 7 | 8 | 9 | 10 | 11 |
12 |
13 | 14 |
15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /Programming_Assignments/Danmuku System/ws/main.js: -------------------------------------------------------------------------------- 1 | const timers = []; 2 | const jqueryDom = createDanmaku('hihihi'); // test danmaku, delete it as you like 3 | addInterval(jqueryDom);// test danmaku, delete it as you like 4 | 5 | // TODO: construct websocket for communication 6 | var ws = new WebSocket('ws://localhost:8765'); 7 | // ws.onopen = function () { 8 | // console.log('ws连接状态:' + ws.readyState); 9 | // //连接成功则发送一个数据 10 | // // ws.send('test1'); 11 | // } 12 | ws.onmessage = function (data) { 13 | console.log('接收到来自服务器的消息:'); 14 | console.log(data); 15 | const rec_danmuku = createDanmaku(data.data); 16 | addInterval(rec_danmuku); 17 | } 18 | 19 | $(".send").on("click", function () { 20 | // TODO: send danmaku to server 21 | const v = document.getElementById("danmakutext").value; 22 | console.log("Send!"); 23 | // const enprint_danmuku = createDanmaku(v); 24 | // addInterval(enprint_danmuku); 25 | ws.send(v) 26 | }); 27 | 28 | // create a Dom object corresponding to a danmaku 29 | function createDanmaku(text) { 30 | var timestamp = Date.parse(new Date()); 31 | timestamp = timestamp % 255; 32 | var time_str_r = timestamp + ""; 33 | var time_str_g = (timestamp + Math.random() * 100) % 255 + ""; 34 | var time_str_b = (timestamp + Math.random() * 200) % 255 + ""; 35 | const jqueryDom = $("
" + text + "
"); 36 | const fontColor = "rgb(" + time_str_r + "," + time_str_g + "," + time_str_b + ")"; 37 | var fsize = (Math.random() * 20 + 20) + ""; 38 | const fontSize = fsize + "px"; 39 | let top = Math.floor(Math.random() * 400) + "px"; 40 | const left = $(".screen_container").width() + "px"; 41 | jqueryDom.css({ 42 | "position": 'absolute', 43 | "color": fontColor, 44 | "font-size": fontSize, 45 | "left": left, 46 | "top": top, 47 | }); 48 | $(".screen_container").append(jqueryDom); 49 | return jqueryDom; 50 | } 51 | // add timer task to let the danmaku fly from right to left 52 | function addInterval(jqueryDom) { 53 | let left = jqueryDom.offset().left - $(".screen_container").offset().left; 54 | const timer = setInterval(function () { 55 | left--; 56 | jqueryDom.css("left", left + "px"); 57 | if (jqueryDom.offset().left + jqueryDom.width() < $(".screen_container").offset().left) { 58 | jqueryDom.remove(); 59 | clearInterval(timer); 60 | } 61 | }, 5); // set delay as 5ms,which means the danmaku changes its position every 5ms 62 | timers.push(timer); 63 | } -------------------------------------------------------------------------------- /Programming_Assignments/Danmuku System/ws/server.py: -------------------------------------------------------------------------------- 1 | import asyncio 2 | import time 3 | from socket import create_connection 4 | from xml.etree.ElementTree import tostring 5 | 6 | import websockets 7 | 8 | clients = [] 9 | connected = [] 10 | JOIN = {} 11 | history = [] 12 | 13 | 14 | class DanmakuServer: 15 | """ 16 | Receive danmakus from clients, reply them correctly 17 | """ 18 | 19 | def __init__(self): 20 | # TODO: define your variables needed in this class 21 | 22 | print("I'd like to run now") 23 | # raise NotImplementedError 24 | 25 | async def reply(self, websocket): 26 | # TODO: design your reply method 27 | # print("I cannot reply you: {}".format(websocket)) 28 | ticks = int(time.time() % 10086) 29 | name = "user" + str(ticks) 30 | clients.append(name) 31 | # print("Now we have ") 32 | # print(clients) 33 | connected.append(websocket) 34 | for msg in history: 35 | await websocket.send(msg) 36 | 37 | try: 38 | while True: 39 | msg = await websocket.recv() 40 | history.append(msg) 41 | websockets.broadcast(connected, msg) 42 | # print ("Receive a message: {}".format(msg)) 43 | 44 | except websockets.exceptions.ConnectionClosedOK: 45 | print("Bye{}".format(name)) 46 | finally: 47 | clients.remove(name) 48 | connected.remove(websocket) 49 | websocket.close() 50 | print(len(connected)) 51 | print("{} has been removed".format(name)) 52 | # raise NotImplementedError 53 | 54 | 55 | if __name__ == "__main__": 56 | server = DanmakuServer() 57 | asyncio.get_event_loop().run_until_complete( 58 | websockets.serve(server.reply, 'localhost', 8765)) 59 | asyncio.get_event_loop().run_forever() 60 | -------------------------------------------------------------------------------- /Programming_Assignments/Danmuku System/ws/style.css: -------------------------------------------------------------------------------- 1 | .screen_container{ 2 | position: relative; 3 | width: 800px; 4 | height: 400px; 5 | margin: 30px auto; 6 | background: #000; 7 | overflow: hidden; 8 | border-style: solid; 9 | border-radius: 25px; 10 | border-color: deeppink; 11 | } 12 | 13 | .main{ 14 | width: 600px; 15 | margin: 20px auto; 16 | text-align: center; 17 | } -------------------------------------------------------------------------------- /Programming_Assignments/Danmuku System/ws/tempCodeRunnerFile.js: -------------------------------------------------------------------------------- 1 | print("{} is from some clients".format(data)) -------------------------------------------------------------------------------- /Programming_Assignments/Routing/.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | -------------------------------------------------------------------------------- /Programming_Assignments/Routing/.idea/Routing.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Programming_Assignments/Routing/.idea/inspectionProfiles/Project_Default.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 12 | -------------------------------------------------------------------------------- /Programming_Assignments/Routing/.idea/inspectionProfiles/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | -------------------------------------------------------------------------------- /Programming_Assignments/Routing/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /Programming_Assignments/Routing/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Programming_Assignments/Routing/CS305 Assignment3-compare version.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Leo-Adventure/CS305-Computer-Network/f1310a5bec455ee77fe768c79387274949952ed1/Programming_Assignments/Routing/CS305 Assignment3-compare version.pdf -------------------------------------------------------------------------------- /Programming_Assignments/Routing/CS305 Assignment3-new version.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Leo-Adventure/CS305-Computer-Network/f1310a5bec455ee77fe768c79387274949952ed1/Programming_Assignments/Routing/CS305 Assignment3-new version.pdf -------------------------------------------------------------------------------- /Programming_Assignments/Routing/data/10router.txt: -------------------------------------------------------------------------------- 1 | 210.166.168.1/24 210.166.168.2/24 24.141.14.1/24 24.141.14.2/24 42.208.204.1/24 42.208.204.2/24 3.224.230.1/24 3.224.230.2/24 199.77.174.1/24 199.77.174.2/24 212.145.246.1/24 212.145.246.2/24 226.92.142.1/24 226.92.142.2/24 189.31.120.1/24 189.31.120.2/24 198.34.216.1/24 198.34.216.2/24 217.15.205.1/24 217.15.205.2/24 95.185.248.1/24 95.185.248.2/24 129.23.226.1/24 129.23.226.2/24 179.251.255.1/24 179.251.255.2/24 116.67.206.1/24 116.67.206.2/24 18.227.121.1/24 18.227.121.2/24 168.30.120.1/24 168.30.120.2/24 209.37.96.1/24 209.37.96.2/24 15.84.166.1/24 15.84.166.2/24 57.153.183.1/24 57.153.183.2/24 141.202.216.1/24 141.202.216.2/24 185.17.240.1/24 185.17.240.2/24 101.79.57.1/24 101.79.57.2/24 181.75.161.1/24 181.75.161.2/24 172.194.166.1/24 172.194.166.2/24 223.35.62.1/24 223.35.62.2/24 122.6.222.1/24 122.6.222.2/24 97.54.102.1/24 97.54.102.2/24 138.131.187.1/24 138.131.187.2/24 250.34.115.1/24 250.34.115.2/24 204.165.175.1/24 204.165.175.2/24 27.109.203.1/24 27.109.203.2/24 1.48.114.1/24 1.48.114.2/24 158.221.44.1/24 158.221.44.2/24 218.238.122.1/24 218.238.122.2/24 173.177.163.1/24 173.177.163.2/24 206.74.216.1/24 206.74.216.2/24 216.100.159.1/24 216.100.159.2/24 204.37.40.1/24 204.37.40.2/24 32.254.183.1/24 32.254.183.2/24 245.183.101.1/24 245.183.101.2/24 2 | ('210.166.168.1/24','24.141.14.1/24','42.208.204.1/24','3.224.230.1/24','199.77.174.1/24','212.145.246.1/24','27.109.203.1/24') ('210.166.168.2/24','226.92.142.1/24','189.31.120.1/24','198.34.216.1/24','217.15.205.1/24','1.48.114.1/24') ('24.141.14.2/24','95.185.248.1/24','129.23.226.1/24','158.221.44.1/24') ('226.92.142.2/24','179.251.255.1/24','116.67.206.1/24','18.227.121.1/24','168.30.120.1/24','218.238.122.1/24') ('189.31.120.2/24','18.227.121.2/24','209.37.96.1/24','15.84.166.1/24','57.153.183.1/24','141.202.216.1/24','173.177.163.1/24') ('217.15.205.2/24','209.37.96.2/24','185.17.240.1/24','101.79.57.1/24','181.75.161.1/24','172.194.166.1/24','206.74.216.1/24') ('212.145.246.2/24','95.185.248.2/24','141.202.216.2/24','185.17.240.2/24','223.35.62.1/24','122.6.222.1/24','97.54.102.1/24','216.100.159.1/24') ('42.208.204.2/24','198.34.216.2/24','168.30.120.2/24','15.84.166.2/24','101.79.57.2/24','223.35.62.2/24','138.131.187.1/24','250.34.115.1/24','204.37.40.1/24') ('199.77.174.2/24','129.23.226.2/24','179.251.255.2/24','181.75.161.2/24','122.6.222.2/24','250.34.115.2/24','204.165.175.1/24','32.254.183.1/24') ('3.224.230.2/24','116.67.206.2/24','57.153.183.2/24','172.194.166.2/24','97.54.102.2/24','138.131.187.2/24','204.165.175.2/24','245.183.101.1/24') 3 | ('210.166.168.1/24','210.166.168.2/24',45) ('24.141.14.1/24','24.141.14.2/24',432) ('42.208.204.1/24','42.208.204.2/24',689) ('3.224.230.1/24','3.224.230.2/24',525) ('199.77.174.1/24','199.77.174.2/24',683) ('212.145.246.1/24','212.145.246.2/24',616) ('226.92.142.1/24','226.92.142.2/24',308) ('189.31.120.1/24','189.31.120.2/24',359) ('198.34.216.1/24','198.34.216.2/24',202) ('217.15.205.1/24','217.15.205.2/24',158) ('95.185.248.1/24','95.185.248.2/24',340) ('129.23.226.1/24','129.23.226.2/24',799) ('179.251.255.1/24','179.251.255.2/24',664) ('116.67.206.1/24','116.67.206.2/24',395) ('18.227.121.1/24','18.227.121.2/24',384) ('168.30.120.1/24','168.30.120.2/24',946) ('209.37.96.1/24','209.37.96.2/24',279) ('15.84.166.1/24','15.84.166.2/24',735) ('57.153.183.1/24','57.153.183.2/24',774) ('141.202.216.1/24','141.202.216.2/24',256) ('185.17.240.1/24','185.17.240.2/24',455) ('101.79.57.1/24','101.79.57.2/24',310) ('181.75.161.1/24','181.75.161.2/24',600) ('172.194.166.1/24','172.194.166.2/24',417) ('223.35.62.1/24','223.35.62.2/24',812) ('122.6.222.1/24','122.6.222.2/24',916) ('97.54.102.1/24','97.54.102.2/24',228) ('138.131.187.1/24','138.131.187.2/24',446) ('250.34.115.1/24','250.34.115.2/24',356) ('204.165.175.1/24','204.165.175.2/24',855) ('27.109.203.1/24','27.109.203.2/24',383) ('1.48.114.1/24','1.48.114.2/24',893) ('158.221.44.1/24','158.221.44.2/24',458) ('218.238.122.1/24','218.238.122.2/24',495) ('173.177.163.1/24','173.177.163.2/24',617) ('206.74.216.1/24','206.74.216.2/24',401) ('216.100.159.1/24','216.100.159.2/24',319) ('204.37.40.1/24','204.37.40.2/24',182) ('32.254.183.1/24','32.254.183.2/24',633) ('245.183.101.1/24','245.183.101.2/24',977) 4 | 19 5 | PATH 27.109.203.2/24 245.183.101.2/24 6 | PATH 1.48.114.2/24 245.183.101.2/24 7 | PATH 158.221.44.2/24 245.183.101.2/24 8 | PATH 218.238.122.2/24 245.183.101.2/24 9 | PATH 173.177.163.2/24 245.183.101.2/24 10 | PATH 206.74.216.2/24 245.183.101.2/24 11 | PATH 216.100.159.2/24 245.183.101.2/24 12 | PATH 204.37.40.2/24 245.183.101.2/24 13 | PATH 32.254.183.2/24 245.183.101.2/24 14 | TABLE ('210.166.168.1/24','24.141.14.1/24','42.208.204.1/24','3.224.230.1/24','199.77.174.1/24','212.145.246.1/24','27.109.203.1/24') 15 | TABLE ('210.166.168.2/24','226.92.142.1/24','189.31.120.1/24','198.34.216.1/24','217.15.205.1/24','1.48.114.1/24') 16 | TABLE ('24.141.14.2/24','95.185.248.1/24','129.23.226.1/24','158.221.44.1/24') 17 | TABLE ('226.92.142.2/24','179.251.255.1/24','116.67.206.1/24','18.227.121.1/24','168.30.120.1/24','218.238.122.1/24') 18 | TABLE ('189.31.120.2/24','18.227.121.2/24','209.37.96.1/24','15.84.166.1/24','57.153.183.1/24','141.202.216.1/24','173.177.163.1/24') 19 | TABLE ('217.15.205.2/24','209.37.96.2/24','185.17.240.1/24','101.79.57.1/24','181.75.161.1/24','172.194.166.1/24','206.74.216.1/24') 20 | TABLE ('212.145.246.2/24','95.185.248.2/24','141.202.216.2/24','185.17.240.2/24','223.35.62.1/24','122.6.222.1/24','97.54.102.1/24','216.100.159.1/24') 21 | TABLE ('42.208.204.2/24','198.34.216.2/24','168.30.120.2/24','15.84.166.2/24','101.79.57.2/24','223.35.62.2/24','138.131.187.1/24','250.34.115.1/24','204.37.40.1/24') 22 | TABLE ('199.77.174.2/24','129.23.226.2/24','179.251.255.2/24','181.75.161.2/24','122.6.222.2/24','250.34.115.2/24','204.165.175.1/24','32.254.183.1/24') 23 | TABLE ('3.224.230.2/24','116.67.206.2/24','57.153.183.2/24','172.194.166.2/24','97.54.102.2/24','138.131.187.2/24','204.165.175.2/24','245.183.101.1/24') 24 | -------------------------------------------------------------------------------- /Programming_Assignments/Routing/data/debug2.txt: -------------------------------------------------------------------------------- 1 | 1.1.1.1 1.1.1.2 2.2.2.1 2.2.2.2 3.3.3.1 3.3.3.2 2 | 1.1.1.1 1.1.1.2 2.2.2.1 2.2.2.2 5.5.6.1 5.5.6.2 6.6.6.1 6.6.6.2 3 | 3.3.3.2 3.3.3.1 5.5.6.1 5.5.6.2 6.6.6.1 6.6.6.2 4 | 1.1.1.0/24 is directly connected 5 | 2.2.2.0/24 is directly connected 6 | 3.3.3.0/24 via 2.2.2.1 7 | 4.4.4.0/24 is directly connected 8 | 5.5.5.0/24 via 2.2.2.1 9 | 5.5.6.0/24 via 2.2.2.1 10 | 6.6.6.0/24 via 2.2.2.1 11 | After 12 | 1.1.1.0/24 is directly connected 13 | 2.2.2.0/24 is directly connected 14 | 3.3.3.0/24 via 2.2.2.1 15 | 4.4.4.0/24 is directly connected 16 | 5.5.4.0/22 via 2.2.2.1 17 | 6.6.6.0/24 via 2.2.2.1 18 | 1.1.1.0/24 via 5.5.5.1 19 | 2.2.2.0/24 via 5.5.5.1 20 | 3.3.3.0/24 via 5.5.5.1 21 | 4.4.4.0/24 is directly connected 22 | 5.5.5.0/24 is directly connected 23 | 5.5.6.0/24 via 5.5.5.1 24 | 6.6.6.0/24 via 5.5.5.1 25 | After 26 | 1.1.1.0/24 via 5.5.5.1 27 | 2.2.2.0/24 via 5.5.5.1 28 | 3.3.3.0/24 via 5.5.5.1 29 | 4.4.4.0/24 is directly connected 30 | 5.5.5.0/24 is directly connected 31 | 5.5.6.0/24 via 5.5.5.1 32 | 6.6.6.0/24 via 5.5.5.1 33 | -------------------------------------------------------------------------------- /Programming_Assignments/Routing/data/input.txt: -------------------------------------------------------------------------------- 1 | 67.100.3.8/24 67.100.3.3/24 120.100.3.3/24 120.100.3.5/24 60.80.33.21/24 200.30.5.6/24 200.30.5.7/24 200.30.6.1/24 200.30.6.2/24 200.30.7.1/24 200.30.7.2/24 60.80.33.10/24 2 | ('67.100.3.3/24','120.100.3.3/24','200.30.6.1/24') ('120.100.3.5/24','60.80.33.21/24','200.30.5.6/24') ('200.30.5.7/24','200.30.6.2/24','200.30.7.1/24') 3 | ('67.100.3.8/24','67.100.3.3/24',1) ('120.100.3.3/24','120.100.3.5/24',3) ('200.30.6.1/24','200.30.6.2/24',7) ('200.30.5.6/24','200.30.5.7/24',2) ('60.80.33.21/24','60.80.33.10/24',10) ('200.30.7.1/24','200.30.7.2/24',1) 4 | 2 5 | PATH 67.100.3.8/24 200.30.7.2/24 6 | TABLE ('67.100.3.3/24','120.100.3.3/24','200.30.6.1/24') 7 | -------------------------------------------------------------------------------- /Programming_Assignments/Routing/data/input2.txt: -------------------------------------------------------------------------------- 1 | 67.100.3.8/24 67.100.3.3/24 120.100.3.3/24 120.100.3.5/24 60.80.33.21/24 200.30.5.6/24 200.30.5.7/24 200.30.6.1/24 200.30.6.2/24 200.30.7.1/24 200.30.7.2/24 60.80.33.10/24 2 | ('67.100.3.3/24','120.100.3.3/24','200.30.6.1/24') ('120.100.3.5/24','60.80.33.21/24','200.30.5.6/24') ('200.30.5.7/24','200.30.6.2/24','200.30.7.1/24') 3 | ('67.100.3.8/24','67.100.3.3/24',1) ('120.100.3.3/24','120.100.3.5/24',3) ('200.30.6.1/24','200.30.6.2/24',7) ('200.30.5.6/24','200.30.5.7/24',2) ('60.80.33.21/24','60.80.33.10/24',10) ('200.30.7.1/24','200.30.7.2/24',1) 4 | 2 5 | PATH 200.30.7.2/24 60.80.33.10/24 6 | TABLE ('67.100.3.3/24','120.100.3.3/24','200.30.6.1/24') 7 | -------------------------------------------------------------------------------- /Programming_Assignments/Routing/data/output.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Leo-Adventure/CS305-Computer-Network/f1310a5bec455ee77fe768c79387274949952ed1/Programming_Assignments/Routing/data/output.txt -------------------------------------------------------------------------------- /Programming_Assignments/Routing/data/output1.txt: -------------------------------------------------------------------------------- 1 | 67.100.3.8 67.100.3.3 120.100.3.3 120.100.3.5 200.30.5.6 200.30.5.7 200.30.7.1 200.30.7.2 2 | 120.100.3.0/24 is directly connected 3 | 200.30.5.0/24 via 120.100.3.3 4 | 200.30.6.0/24 is directly connected 5 | 200.30.7.0/24 via 120.100.3.3 6 | 60.80.33.0/24 via 120.100.3.3 7 | 67.100.3.0/24 is directly connected 8 | After 9 | 120.100.3.0/24 is directly connected 10 | 200.30.4.0/22 via 120.100.3.3 11 | 200.30.6.0/24 is directly connected 12 | 60.80.33.0/24 via 120.100.3.3 13 | 67.100.3.0/24 is directly connected 14 | 60.80.33.10 60.80.33.21 200.30.5.6 200.30.5.7 200.30.7.1 200.30.7.2 15 | 120.100.3.0/24 via 200.30.5.7 16 | 200.30.5.0/24 is directly connected 17 | 200.30.6.0/24 is directly connected 18 | 200.30.7.0/24 is directly connected 19 | 60.80.33.0/24 via 200.30.5.7 20 | 67.100.3.0/24 via 200.30.5.7 21 | After 22 | 120.100.3.0/24 via 200.30.5.7 23 | 200.30.5.0/24 is directly connected 24 | 200.30.6.0/24 is directly connected 25 | 200.30.7.0/24 is directly connected 26 | 60.80.33.0/24 via 200.30.5.7 27 | 67.100.3.0/24 via 200.30.5.7 28 | 67.100.3.8 67.100.3.3 120.100.3.3 120.100.3.5 60.80.33.21 60.80.33.10 29 | -------------------------------------------------------------------------------- /Programming_Assignments/Routing/data/output2.txt: -------------------------------------------------------------------------------- 1 | 1.1.1.1 1.1.1.2 2.2.2.1 2.2.2.2 3.3.3.1 3.3.3.2 2 | 1.1.1.1 1.1.1.2 2.2.2.1 2.2.2.2 5.5.6.1 5.5.6.2 6.6.6.1 6.6.6.2 3 | 3.3.3.2 3.3.3.1 5.5.6.1 5.5.6.2 6.6.6.1 6.6.6.2 4 | 1.1.1.0/24 is directly connected 5 | 2.2.2.0/24 is directly connected 6 | 3.3.3.0/24 via 2.2.2.1 7 | 4.4.4.0/24 is directly connected 8 | 5.5.5.0/24 via 2.2.2.1 9 | 5.5.6.0/24 via 2.2.2.1 10 | 6.6.6.0/24 via 2.2.2.1 11 | After 12 | 1.1.1.0/24 is directly connected 13 | 2.2.2.0/24 is directly connected 14 | 3.3.3.0/24 via 2.2.2.1 15 | 4.4.4.0/24 is directly connected 16 | 5.5.4.0/22 via 2.2.2.1 17 | 6.6.6.0/24 via 2.2.2.1 18 | 4.4.4.0/24 is directly connected 19 | 5.5.5.0/24 is directly connected 20 | After 21 | 4.4.4.0/24 is directly connected 22 | 5.5.5.0/24 is directly connected 23 | -------------------------------------------------------------------------------- /Programming_Assignments/Routing/testcase/input1.txt: -------------------------------------------------------------------------------- 1 | 67.100.3.8/24 67.100.3.3/24 120.100.3.3/24 120.100.3.5/24 60.80.33.21/24 200.30.5.6/24 200.30.5.7/24 200.30.6.1/24 200.30.6.2/24 200.30.7.1/24 200.30.7.2/24 60.80.33.10/24 2 | ('67.100.3.3/24','120.100.3.3/24','200.30.6.1/24') ('120.100.3.5/24','60.80.33.21/24','200.30.5.6/24') ('200.30.5.7/24','200.30.6.2/24','200.30.7.1/24') 3 | ('67.100.3.8/24','67.100.3.3/24',1) ('120.100.3.3/24','120.100.3.5/24',3) ('200.30.6.1/24','200.30.6.2/24',7) ('200.30.5.6/24','200.30.5.7/24',2) ('60.80.33.21/24','60.80.33.10/24',10) ('200.30.7.1/24','200.30.7.2/24',1) 4 | 5 5 | PATH 67.100.3.8/24 200.30.7.2/24 6 | TABLE ('67.100.3.3/24','120.100.3.3/24','200.30.6.1/24') 7 | PATH 60.80.33.10/24 200.30.7.2/24 8 | TABLE ('200.30.5.7/24','200.30.6.2/24','200.30.7.1/24') 9 | PATH 67.100.3.8/24 60.80.33.10/24 -------------------------------------------------------------------------------- /Programming_Assignments/Routing/testcase/input2.txt: -------------------------------------------------------------------------------- 1 | 1.1.1.1/24 1.1.1.2/24 2.2.2.1/24 2.2.2.2/24 3.3.3.1/24 3.3.3.2/24 4.4.4.1/24 4.4.4.2/24 5.5.5.1/24 5.5.5.2/24 5.5.6.1/24 5.5.6.2/24 6.6.6.1/24 6.6.6.2/24 2 | ('1.1.1.2/24','2.2.2.1/24','4.4.4.1/24') ('2.2.2.2/24','3.3.3.1/24','5.5.6.1/24') ('5.5.6.2/24','5.5.5.2/24','6.6.6.1/24') ('4.4.4.2/24','5.5.5.1/24') 3 | ('2.2.2.1/24','2.2.2.2/24',2) ('4.4.4.1/24','4.4.4.2/24',7) ('1.1.1.1/24','1.1.1.2/24',1) ('3.3.3.1/24','3.3.3.2/24',1) ('6.6.6.1/24','6.6.6.2/24',1) ('5.5.5.1/24','5.5.5.2/24',2) ('5.5.6.1/24','5.5.6.2/24',1) 4 | 5 5 | PATH 1.1.1.1/24 3.3.3.2/24 6 | PATH 1.1.1.1/24 6.6.6.2/24 7 | PATH 3.3.3.2/24 6.6.6.2/24 8 | TABLE ('1.1.1.2/24','2.2.2.1/24','4.4.4.1/24') 9 | TABLE ('4.4.4.2/24','5.5.5.1/24') -------------------------------------------------------------------------------- /Programming_Assignments/Routing/testcase/output1.txt: -------------------------------------------------------------------------------- 1 | 67.100.3.8 67.100.3.3 120.100.3.3 120.100.3.5 200.30.5.6 200.30.5.7 200.30.7.1 200.30.7.2 2 | 120.100.3.0/24 is directly connected 3 | 200.30.5.0/24 via 120.100.3.3 4 | 200.30.6.0/24 is directly connected 5 | 200.30.7.0/24 via 120.100.3.3 6 | 60.80.33.0/24 via 120.100.3.3 7 | 67.100.3.0/24 is directly connected 8 | After 9 | 120.100.3.0/24 is directly connected 10 | 200.30.4.0/22 via 120.100.3.3 11 | 200.30.6.0/24 is directly connected 12 | 60.80.33.0/24 via 120.100.3.3 13 | 67.100.3.0/24 is directly connected 14 | 60.80.33.10 60.80.33.21 200.30.5.6 200.30.5.7 200.30.7.1 200.30.7.2 15 | 120.100.3.0/24 via 200.30.5.7 16 | 200.30.5.0/24 is directly connected 17 | 200.30.6.0/24 is directly connected 18 | 200.30.7.0/24 is directly connected 19 | 60.80.33.0/24 via 200.30.5.7 20 | 67.100.3.0/24 via 200.30.5.7 21 | After 22 | 120.100.3.0/24 via 200.30.5.7 23 | 200.30.5.0/24 is directly connected 24 | 200.30.6.0/24 is directly connected 25 | 200.30.7.0/24 is directly connected 26 | 60.80.33.0/24 via 200.30.5.7 27 | 67.100.3.0/24 via 200.30.5.7 28 | 67.100.3.8 67.100.3.3 120.100.3.3 120.100.3.5 60.80.33.21 60.80.33.10 -------------------------------------------------------------------------------- /Programming_Assignments/Routing/testcase/output2.txt: -------------------------------------------------------------------------------- 1 | 1.1.1.1 1.1.1.2 2.2.2.1 2.2.2.2 3.3.3.1 3.3.3.2 2 | 1.1.1.1 1.1.1.2 2.2.2.1 2.2.2.2 5.5.6.1 5.5.6.2 6.6.6.1 6.6.6.2 3 | 3.3.3.2 3.3.3.1 5.5.6.1 5.5.6.2 6.6.6.1 6.6.6.2 4 | 1.1.1.0/24 is directly connected 5 | 2.2.2.0/24 is directly connected 6 | 3.3.3.0/24 via 2.2.2.1 7 | 4.4.4.0/24 is directly connected 8 | 5.5.5.0/24 via 2.2.2.1 9 | 5.5.6.0/24 via 2.2.2.1 10 | 6.6.6.0/24 via 2.2.2.1 11 | After 12 | 1.1.1.0/24 is directly connected 13 | 2.2.2.0/24 is directly connected 14 | 3.3.3.0/24 via 2.2.2.1 15 | 4.4.4.0/24 is directly connected 16 | 5.5.4.0/22 via 2.2.2.1 17 | 6.6.6.0/24 via 2.2.2.1 18 | 1.1.1.0/24 via 5.5.5.1 19 | 2.2.2.0/24 via 5.5.5.1 20 | 3.3.3.0/24 via 5.5.5.1 21 | 4.4.4.0/24 is directly connected 22 | 5.5.5.0/24 is directly connected 23 | 5.5.6.0/24 via 5.5.5.1 24 | 6.6.6.0/24 via 5.5.5.1 25 | After 26 | 1.1.1.0/24 via 5.5.5.1 27 | 2.2.2.0/24 via 5.5.5.1 28 | 3.3.3.0/24 via 5.5.5.1 29 | 4.4.4.0/24 is directly connected 30 | 5.5.5.0/24 is directly connected 31 | 5.5.6.0/24 via 5.5.5.1 32 | 6.6.6.0/24 via 5.5.5.1 -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![](https://img.shields.io/apm/l/vim-mode) 2 | 3 | # CS305-Computer-Network 4 | 5 | Lectured by Professor ZhuoZhao LI 6 | 7 | This repository contains the code implemented for lab practise and project of the CS305-Computer-Network of SUSTech. 8 | 9 | | Project/Assignment | Score | 10 | | ------------------ | ------- | 11 | | Local DNS Server | 100/120 | 12 | | Danmuku System | 101/120 | 13 | | Routing Simulation | 100/100 | 14 | | CDN System | 105/120 | 15 | 16 | **Final Score: 97/100(A+)** 17 | 18 | ### 《计算机网络:自顶向下方法》概念整理 19 | 20 | 对于《计算机网络:自顶向下方法》的术语概念整理,见本仓库的 PDF,为本人期末复习所整理,希望能够帮助到每一位学习计网的同学~ 21 | 22 | ## Local DNS Server 23 | 24 | In assignment1, we were asked to implement a local DNS server using Python, the task can be devided into four parts, individually query, reply, cache and multi-thread. Now I have implemented to the cache part. 25 | 26 | I have written detailed comment in the code. 27 | 28 | ## Danmuku System 29 | 30 | In assignment2, we were required to implement a danmuku system using both websocket and HTTP protocol. 31 | 32 | Now the project has finished~ 33 | 34 | ## Routing Simulation 35 | In assignment3, we were required to implemented the routing algorithm(Dijkstra Algorithm) and the routing aggregation algorithm. 36 | In this assignment, I get a proficiency in Python. 37 | 38 | ## Project: CDN System 39 | 40 | In the project, we were required to implemented a CDN System that can adjust the bit rate of a video according to the current bandwidth of the uses. 41 | -------------------------------------------------------------------------------- /Video_CDN_Project/README.md: -------------------------------------------------------------------------------- 1 | ## CS305 Video CDN Project 2 | 3 | [TOC] 4 | 5 | ### Developers and Work Division 6 | 7 | | Developers | Work | 8 | | ----------------- | -------------------------------------------------- | 9 | | @zhangliyuSustech | Compile and Output, Proxy, Danmakus System | 10 | | @ChristinaLee | Log File, Proxy, Bit Rate Adaption, Graph Analysis | 11 | | @MQ_Adventure | DNS, Round-Robin, Interface Beautification, Report | 12 | 13 | ### Proxy Implementation 14 | 15 | #### Arguments 16 | 17 | The function of arguments of the proxy.py is like belows. 18 | 19 | ```wiki 20 | argv[0] is the python file name. 21 | argv[1] is , the path of file that logs the messages. 22 | argv[2] is , [0, 1], in throughput estimate. 23 | argv[3] is , the TCP port your proxy should listen on for accepting connections from your browser. 24 | argv[4] is , UDP port DNS server listens on. 25 | argv[5] is [], proxy should accept an optional argument specifying the port of the web server 26 | from which it should request video chunks. If this argument is not present, 27 | proxy should obtain the web server’s port by querying DNS server. 28 | ``` 29 | 30 | #### Forward Request 31 | 32 | The forwarding instances code is shown as belows. Take the StrobeMediaPlayback.swf request forwarding as an example. 33 | 34 | ```python 35 | @staticmethod 36 | @app.route('/StrobeMediaPlayback.swf') 37 | def query_strobe(): 38 | cookie = request.cookies 39 | cur_client_id = int(cookie.get("ID")) 40 | current_client = ClientSelf.dict_client.get(cur_client_id) 41 | return Response(requests.get(current_client.getURL() + "/StrobeMediaPlayback.swf", headers=ClientSelf.headerSelf)) 42 | 43 | ``` 44 | 45 | #### Strategy to Exit Proxy 46 | 47 | Our strategy to exit the proxy is by entering "quit" into danmakus text field. If the danmakus system receives the "quit" message, it will trigger a process to exit the proxy. The code is shown as belows. 48 | 49 | ```python 50 | danmu = request.stream.read().decode('utf-8') 51 | if danmu == "quit": 52 | shutdown_func = request.environ.get('werkzeug.server.shutdown') 53 | if shutdown_func is None: 54 | raise RuntimeError('Not running werkzeug') 55 | shutdown_func() 56 | return "Shutting down..." 57 | ``` 58 | 59 | ### Video Bit rate Adaptation 60 | 61 | The goal of bit rate adaptation is to choose the best rate for each video chunk. The choice is based on throughput estimation. 62 | 63 | The throughput can be calculated as belows. Assume the $B$ is the length of the video chunk and $t_s$ and $t_f$ is the start time and end time of the process of receiving the chunk from the servers. 64 | $$ 65 | T = \frac{B}{t_f - t_s} 66 | $$ 67 | The current of the throughput of estimate is shown as belows. 68 | $$ 69 | T_{current} = \alpha T_{new} + (1 - \alpha)T_{current} 70 | $$ 71 | The code is shown as belows, and the method is explained in the comment. 72 | 73 | ```python 74 | @staticmethod 75 | @app.route('/vod/Seg-Frag') 76 | def forward_segment(rate, segment, frag): 77 | """ 78 | Here you should change the requested bit rate according to your computation of throughput. 79 | And if the request is for big_buck_bunny.f4m, you should instead request big_buck_bunny_nolist.f4m 80 | for client and leave big_buck_bunny.f4m for the use in proxy. 81 | """ 82 | 83 | cookie = request.cookies 84 | cur_client_id = int(cookie.get("ID")) 85 | current_client = ClientSelf.dict_client.get(cur_client_id) 86 | 87 | # to select a proper bitrate 88 | bound_bitrate = current_client.throughput / 1.5 89 | print(bound_bitrate) 90 | selected_bitrate = 10 91 | 92 | for bps in current_client.bitrate_list: 93 | if bps <= bound_bitrate: 94 | selected_bitrate = bps 95 | 96 | print(selected_bitrate) 97 | 98 | start_time = time.time() 99 | response = requests.get(f'{current_client.getURL()}/vod/{selected_bitrate}Seg{segment}-Frag{frag}', headers=ClientSelf.headerSelf) 100 | end_time = time.time() 101 | KB = float(response.headers['Content-Length']) * 8 / 1024 102 | # record the log message 103 | duration = end_time - start_time 104 | new_throughput = KB / duration 105 | 106 | current_client.throughput = ClientSelf.alpha * new_throughput + (1-ClientSelf.alpha) * current_client.throughput 107 | chunkname = str(segment) + "-" + str(frag) 108 | ClientSelf.record_log(start_time, duration, new_throughput, current_client.throughput, selected_bitrate, current_client.server_port, chunkname) 109 | return Response(response) 110 | # record the log message 111 | ``` 112 | 113 | 114 | 115 | ### DNS Implementation 116 | 117 | #### Read File 118 | 119 | Since the DNS should know which port is open before answering the request, the DNS.py will first read servers file from command line as parameters. 120 | 121 | ```python 122 | file_name = sys.argv[1] 123 | with open(file_name, 'r') as f: 124 | for line in f.readlines(): 125 | port_list.append(line.strip()) 126 | ``` 127 | 128 | Then, the $port\_list$ will contains all the open ports. 129 | 130 | At first, I am not sure whether the port in the file will open for certain, so we also write a method to examine it. The method is shown as belows. 131 | 132 | ```python 133 | # 判断端口是否被占用 134 | def is_open(port, host = '127.0.0.1') -> bool: 135 | s = None 136 | try: 137 | s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 138 | s.settimeout(1) 139 | s.connect((host, int(port))) 140 | return True 141 | except socket.error: 142 | return False 143 | finally: 144 | if s: 145 | s.close() 146 | 147 | ``` 148 | 149 | But after the test, we found that when using `python3 ./netsim.py servers start -s servers/2servers` to launch servers, the port in the port file will be open, so it is no need using the method to check whether the port is open. So we delete the method at last. 150 | 151 | #### Round-Robin 152 | 153 | The principle of Round-Robin algorithm is an arrangement of choosing all elements in a port group equally in some rational order, usually from the front of a list and then starting again from the front of the list and so on. A simple way to think of round robin is that it is about "taking turns." Used as an adjective, round robin becomes "round-robin." 154 | 155 | In our implementation, Round-Robin is like the iteration, each time will return the next element of the port group. When the pointer which indicates the previous port reach the tail of the port group, then it will begin from the front of the group again. 156 | 157 | The implementation code is shown as belows. 158 | 159 | ```python 160 | @staticmethod 161 | @app.route('/dnsRequest') 162 | def makeDnsRerurn(): 163 | global pre_port 164 | # choose file according to the input filename 165 | pre_port = (pre_port + 1) % len(port_list) 166 | return make_response(str(port_list[pre_port])) 167 | ``` 168 | 169 | ### Graph and Analysis 170 | 171 | The graphs we drew and the related analysis are shown as belows. 172 | 173 | **onelink, two servers, alpha = 0.6:** 174 | 175 | Fairness: 176 | 177 | 178 | 179 | 180 | 181 | Smoothness: 182 | 183 | smoothness 184 | 185 | Utilization: 186 | 187 | utilization 188 | 189 | Analysis: During the first 3 events, the fairness presents a state of fluctuation. We can see that the fairness is jumping from 1.0 to 0.7 and from 0.7 to 1.0, which means the network is always trying to keep the fairness. And then the network keeps fairness at 1.0. It is strictly fair. In the smoothness graph, we can also see that during the first 3 events, the graph presents a state of fluctuation. This is the same state as fairness, which is normal. The utilization graph is strange when we first look at it. After analyzing, I think it is reasonable. Any utilization point larger than 100% is the result of decreasing the link bit rate suddenly. As our utilization is depending on the duration and the bit rate, when our duration is not small, the duration*bit rate will not decreases so quickly that makes the point larger than 100%. 190 | 191 | **sharelink, two servers, alpha = 0.6:** 192 | 193 | Fairness: 194 | 195 | 196 | 197 | Smoothness: 198 | 199 | smoothness 200 | 201 | Utilization: 202 | 203 | utilization 204 | 205 | Analysis: Similar to onelink, the network is always trying to make the network fair. The fluctuation in the fairness graph and smoothness graph are mutually verifiable. The utilization is reasonable as I wrote above. 206 | 207 | **twolink, two servers, alpha = 0.1:** 208 | 209 | Fairness: 210 | 211 | 212 | 213 | Smoothness: 214 | 215 | smoothness 216 | 217 | Utilization: 218 | 219 | utilization 220 | 221 | **twolink, two servers, alpha = 0.5:** 222 | 223 | Fairness: 224 | 225 | 226 | 227 | Smoothness: 228 | 229 | smoothness 230 | 231 | Utilization: 232 | 233 | utilization 234 | 235 | **twolink, two servers, alpha = 0.9:** 236 | 237 | Fairness: 238 | 239 | 240 | 241 | Smoothness: 242 | 243 | smoothness 244 | 245 | Utilization: 246 | 247 | utilization 248 | 249 | Analysis: We can see the 3 situation when alpha = 0.1, 0.5, and 0.9. We can see that when alpha equals to 0.5, the fairness, smoothness and utilization are all perfect. We think alpha == 0.5 is a trade-off value. At this value, the network can predict the network condition well. When the value is 0.1, the network is too slow to respond to sudden bit rate changes. So when we suddenly change the bit rate, the network badly responds. When the value is 0.9, the network is too sensitive to the suddenly changed bit rate, which makes the network inclined to fluctuate a lot. The robustness of the network decreases. 250 | 251 | ### Danmakus System Implementation (Bonus) 252 | 253 | By adding the danmakus system, we can add some danmakus into the video. 254 | 255 | The Danmakus system code is shown as belows. 256 | 257 | ```python 258 | @staticmethod 259 | @app.route('/qdanmu') 260 | def qdanmu(): 261 | cookie = request.cookies 262 | cur_client_id = int(cookie.get("ID")) 263 | current_client = ClientSelf.dict_client.get(cur_client_id) 264 | to_return = "" 265 | for ele in current_client.danmulist_topush: 266 | to_return = to_return + str(ele) + "\r\n" 267 | current_client.danmulist_topush = [] 268 | return make_response(to_return) 269 | ``` 270 | 271 | 272 | 273 | #### History danmakus 274 | 275 | When a danmakus is sent by users, then the danmakus will be recorded in a list named ` history_danmu` 276 | 277 | The code is shown as belows. 278 | 279 | ```python 280 | ClientSelf.history_danmu.append(danmu) 281 | ``` 282 | 283 | ### Interface Beautiication (Bonus) 284 | 285 | Changing the HTML code to make the color and size of danmakus to change in random. Then the users will find it comfortable to watch the danmakus. 286 | 287 | ```javascript 288 | function createDanmaku(text) { 289 | var timestamp = Date.parse(new Date()); 290 | timestamp = timestamp % 255; 291 | var time_str_r = timestamp + ""; 292 | var time_str_g = (timestamp + Math.random() * 100) % 255 + ""; 293 | var time_str_b = (timestamp + Math.random() * 200) % 255 + ""; 294 | const jqueryDom = $("
" + text + "
"); 295 | const fontColor = "rgb(" + time_str_r + "," + time_str_g + "," + time_str_b + ")"; 296 | var fsize = (Math.random() * 20 + 20) + ""; 297 | const fontSize = fsize + 30 + "px"; 298 | let top = Math.floor(Math.random() * 400) + "px"; 299 | const left = $(".screen_container").width() + "px"; 300 | jqueryDom.css({ 301 | "position": 'absolute', 302 | "color": fontColor, 303 | "font-size": fontSize, 304 | "left": left, 305 | "top": top, 306 | 307 | }); 308 | ``` 309 | 310 | And We also change the margin color and add background picture, etc to make the system more beautiful. 311 | 312 | ```javascript 313 | body { 314 | position: fixed; 315 | top: 0; 316 | bottom: 0; 317 | left: 0; 318 | width: 100%; 319 | min-width: 1000px; 320 | background-image: url("https://img-qn-3.51miz.com/preview/element/00/01/18/57/E-1185774-ED1A979F.jpg!/quality/90/unsharp/true/compress/true/format/jpg/fh/260"); 321 | background-repeat: no-repeat; 322 | background-size: cover; 323 | background-attachment: fixed; 324 | -webkit-background-size: cover; 325 | -o-background-size: cover; 326 | background-position: center center; 327 | } 328 | ``` 329 | 330 | 331 | 332 | The result page is shown as belows. 333 | 334 | utilization 335 | 336 | ### How to run it 337 | 338 | 启动项目具体操作流程 339 | python3 ./netsim.py servers start -s servers/2servers 340 | python3 dns.py servers/2servers 341 | python3 proxy6.py record.py 0.6 7778 7777 8080 342 | http://127.0.0.1:7778/index.html 343 | 344 | #### 最新的启动项目的流程 345 | python3 netsim.py servers stop -s servers/2servers 346 | python3 netsim.py onelink start 347 | 348 | python3 dns.py topology/onelink/onelink 349 | python3 proxy9.py proxylog1.txt 0.6 7778 7775 350 | python3 proxy9.py proxylog2.txt 0.6 7779 7775 351 | python3 grapher.py serverlog.txt proxylog1.txt proxylog2.txt 352 | python3 netsim.py onelink run -e topology/onelink/onelink.events -l serverlog.txt 353 | (上面这句话可以反复跑) 354 | 355 | #### 最新的twolink启动流程 356 | python3 netsim.py servers stop -s servers/2servers 357 | python3 netsim.py twolink start 358 | 359 | python3 dns.py topology/twolink/twolink 360 | python3 proxy9.py proxylog1.txt 0.6 7778 7775 361 | python3 proxy9.py proxylog2.txt 0.6 7779 7775 362 | python3 netsim.py twolink run -e topology/twolink/twolink.events -l serverlog.txt 363 | python3 grapher.py serverlog.txt proxylog1.txt proxylog2.txt 364 | 365 | #### 最新的sharelink启动流程 366 | python3 netsim.py servers stop -s servers/2servers 367 | python3 netsim.py sharelink start 368 | 369 | python3 dns.py topology/sharelink/sharelink 370 | python3 proxy9.py proxylog1.txt 0.6 7778 7775 371 | python3 proxy9.py proxylog2.txt 0.6 7779 7775 372 | python3 netsim.py sharelink run -e topology/sharelink/sharelink.events -l serverlog.txt 373 | python3 grapher.py serverlog.txt proxylog1.txt proxylog2.txt 374 | -------------------------------------------------------------------------------- /Video_CDN_Project/document/CS305_Video CDN_Project.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Leo-Adventure/CS305-Computer-Network/f1310a5bec455ee77fe768c79387274949952ed1/Video_CDN_Project/document/CS305_Video CDN_Project.pdf -------------------------------------------------------------------------------- /Video_CDN_Project/document/howToRun.txt: -------------------------------------------------------------------------------- 1 | 启动项目具体操作流程 2 | python3 ./netsim.py servers start -s servers/2servers 3 | python3 dns.py servers/2servers 4 | python3 proxy6.py record.py 0.6 7778 7777 8080 5 | http://127.0.0.1:7778/index.html 6 | 7 | # 最新的启动项目的流程 8 | python3 netsim.py servers stop -s servers/2servers 9 | python3 netsim.py onelink start 10 | 11 | python3 dns.py topology/onelink/onelink 12 | python3 proxy9.py proxylog1.txt 0.6 7778 7775 13 | python3 proxy9.py proxylog2.txt 0.6 7779 7775 14 | python3 grapher.py serverlog.txt proxylog1.txt proxylog2.txt 15 | python3 netsim.py onelink run -e topology/onelink/onelink.events -l serverlog.txt 16 | (上面这句话可以反复跑) 17 | 18 | # 最新的twolink启动流程 19 | python3 netsim.py servers stop -s servers/2servers 20 | python3 netsim.py twolink start 21 | 22 | python3 dns.py topology/twolink/twolink 23 | python3 proxy9.py proxylog1.txt 0.6 7778 7775 24 | python3 proxy9.py proxylog2.txt 0.6 7779 7775 25 | python3 netsim.py twolink run -e topology/twolink/twolink.events -l serverlog.txt 26 | python3 grapher.py serverlog.txt proxylog1.txt proxylog2.txt 27 | 28 | # 最新的sharelink启动流程 29 | python3 netsim.py servers stop -s servers/2servers 30 | python3 netsim.py sharelink start 31 | 32 | python3 dns.py topology/sharelink/sharelink 33 | python3 proxy9.py proxylog1.txt 0.6 7778 7775 34 | python3 proxy9.py proxylog2.txt 0.6 7779 7775 35 | python3 netsim.py sharelink run -e topology/sharelink/sharelink.events -l serverlog.txt 36 | python3 grapher.py serverlog.txt proxylog1.txt proxylog2.txt 37 | -------------------------------------------------------------------------------- /Video_CDN_Project/document/计网project小结.md: -------------------------------------------------------------------------------- 1 | ``` 2 | 首先我觉得你需要理解docker端口映射的事情,docker是一个容器,那么他的端口就不是由你的本地能访问到的,那就需要映射 3 | ``` 4 | 5 | ``` 6 | docker run -it -p 7778:7778 -p 7779:7779 -p 8080:8080 -p 8081:8081 project:latest /bin/bash 7 | docker run -it -p 7778:7778 -p 7779:7779 project:latest /bin/bash 8 | docker run -it -p 8080:8080 -p 8081:8081 project:latest /bin/bash 9 | 先准备好环境 10 | python3 ./netsim.py servers start -s servers/2servers 11 | 这个是启动服务器最核心的指令 12 | python3 ./netsim.py servers stop -s servers/2servers 13 | 这个可以停止服务器 14 | http://localhost:8080/index.html 15 | 不加http无法访问(这个问题仅存在ie tag里面) 16 | %systemroot%\system32\f12\IEChooser.exe 17 | 有可能需要添加127.0.0.1替换localhost(这个在docker里面有点问题) 18 | 19 | python3 proxy2.py record.py 0.6 7778 7777 8080 20 | python3 proxy4.py record.py 0.6 7778 7777 8080 21 | 22 | 23 | 启动项目具体操作流程 24 | python3 ./netsim.py servers start -s servers/2servers 25 | python3 dns.py 26 | python3 proxy4.py record.py 0.6 7778 7777 8080 27 | http://127.0.0.1:7778/index.html 28 | 29 | #开启图形化界面调试这个端口是要改变的,没法命令行 30 | /usr/bin/env /usr/bin/python3 /root/.vscode-server/extensions/ms-python.python-2022.6.2/pythonFiles/lib/python/debugpy/launcher 36441 -- /autograder/netsim/proxy4.py record.py 0.6 7778 7777 8080 31 | ``` 32 | 33 | 如果遇到这个错误: 34 | 35 | ![image-20220430153657052](C:\Users\zhangliyu\AppData\Roaming\Typora\typora-user-images\image-20220430153657052.png) 36 | 37 | 请把github clone 的文件 移动到docker镜像里面去 38 | 39 | ``` 40 | docker ps 可以查看image的id 41 | docker cp 拷贝文件 42 | 或者用徐延凯方法也可以 43 | ``` 44 | 45 | vscode可以通过再打开远程窗口的方式更换文件夹,只不过需要在远程资源管理器里面 46 | 47 | ``` 48 | 25版本的firefox还是不行,而且还自动卸载新的firefox,现在暂时卡在ie tag插件edge浏览器能打开,debug准备直接开写 49 | 50 | ``` 51 | 52 | 53 | 54 | ### 具体实现思路 55 | 56 | ![image-20220502175746087](C:\Users\zhangliyu\AppData\Roaming\Typora\typora-user-images\image-20220502175746087.png) 57 | 58 | 我主要想用flask和requests这个2个库去实现,然后完美复刻学姐在腾讯视频里面的这个图的经历 59 | 60 | ``` 61 | 主要的学习文档 62 | https://docs.python-requests.org/zh_CN/latest/search.html?q=get&check_keywords=yes&area=default 63 | 上面是flask的官方文档 64 | https://zhuanlan.zhihu.com/p/137649301 requests是神库,直接调用 65 | 66 | https://dormousehole.readthedocs.io/en/1.1.2/api.html?highlight=request%20arg#flask.Request.args 67 | 上面这个网址是对于request该去拿什么信息的一个访问,实际上后来这个网址没有用上,因为传递信息通过另外的方式完成 68 | 69 | https://www.w3cschool.cn/flask/flask_variable_rules.html 70 | 这个主要是flask路由变量规则可以 71 | 72 | 73 | 74 | ``` 75 | 76 | 然后在实际跑在docker上面可能会遇到没有检测到端口的问题,一定要vscode检测到端口外部才能访问 77 | 78 | 79 | 80 | 现在遇到问题是没法区分客户端,这个问题暂时搁置,因为理论上确实要多进程 81 | 82 | 83 | 84 | ![image-20220503151931943](C:\Users\zhangliyu\AppData\Roaming\Typora\typora-user-images\image-20220503151931943.png) 85 | 86 | ![image-20220503152023133](C:\Users\zhangliyu\AppData\Roaming\Typora\typora-user-images\image-20220503152023133.png) 87 | 88 | flask会遇到外部浏览器不能访问,需要手动开启 89 | 90 | ![image-20220503173205523](C:\Users\zhangliyu\AppData\Roaming\Typora\typora-user-images\image-20220503173205523.png) 91 | 92 | 这个暂时不知道解决办法,只能在vscode开启端口 93 | 94 | 95 | 96 | 97 | 98 | #### 现在发现强行锁清晰度是可以的 99 | 100 | 你请求10返回的是1000flash也是可以解析的,这是一个好消息 101 | 102 | 103 | 104 | 还有就是我在算Throught estimation 的时候其实这个算法是不完备的,因为没有考虑到client到这个proxy之间的时间,然后还有就是多个连接的问题, 105 | 106 | 107 | 108 | 退出服务器可能是abort()函数 109 | 110 | 记录服务器的单独的id应该是session key 111 | 112 | 现在发现TCP每次请求都是不一样的,主要返回回去是close对象的 113 | 114 | 现在要么继续往session key去努力,要么keepalive 115 | 116 | ### vscode 远程文件复制问题 117 | 118 | 本地文件可以打开文件资源管理器,remote可以下载到本机的指定位置 119 | -------------------------------------------------------------------------------- /Video_CDN_Project/graph/onelink_twoservers_06/fairness.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Leo-Adventure/CS305-Computer-Network/f1310a5bec455ee77fe768c79387274949952ed1/Video_CDN_Project/graph/onelink_twoservers_06/fairness.jpg -------------------------------------------------------------------------------- /Video_CDN_Project/graph/onelink_twoservers_06/onelink.events: -------------------------------------------------------------------------------- 1 | # This file contains a list of link change events to execute in the simulated 2 | # network. Columns are as follows: 3 | # 4 | #