学年计算机方向课程大二上ics课件24-internet_第1页
学年计算机方向课程大二上ics课件24-internet_第2页
学年计算机方向课程大二上ics课件24-internet_第3页
学年计算机方向课程大二上ics课件24-internet_第4页
学年计算机方向课程大二上ics课件24-internet_第5页
免费预览已结束,剩余40页可下载查看

付费下载

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、roduction to Computer Systems,Peking Universityernetworkingroduction to Computer Systems24th Lecture, Dec. 12, 2013ernetInstructors:Xiangqun Chen,Junlin Lu Guangyu Sun,Xuetao Guan1roduction to Computer Systems,Peking UniversityChapter 11 Networking Programming会上网 懂网络How to set up a network connectio

2、n and a webserver by programming?What is computer network? 基本网络知识erface 基本接口知识SocketWeb server 通过编程架设服务器2roduction to Computer Systems,Peking UniversityOutlineernet and a cnt-server mHost and computer networksNetwork protocolsGlobal IPernetProgrammers view ofernetEvolution ofernet3roduction to Compu

3、ter Systems,Peking Universityernet = web surfing上网:Hao123 Baidu 新浪4roduction to Computer Systems,Peking Universityernet = cnt-server聊天、网游ernet?服务器挂了?5roduction to Computer Systems, Peking UniversityA Cnt-Server Tranion1. Cnds requestCprontsServerResourcepros4. Cnt2. Serverhandles requestses running

4、on hosts3. Server sends responsehandlesresponseNote: cnts and servers are pro有需求有资源、服务the cnt-server(can be the same or different hosts)Most network applications are basem:A servros ane or more cnt prosesServer manages some resourceServrovides service by manipulating resource for cntsServer activate

5、d by request from cnt (vending machineogy)6roduction to Computer Systems,Peking UniversityNetwork for communication betn peers通信、服务: sol network computer networkImplemenion of human society in digital worldCommunication7roduction to Computer Systems,Peking UniversityOutlineernet and a cnt-server mHo

6、st and computer networksNetwork protocolsGlobal IPernetProgrammers view ofernetEvolution ofernet8roduction to Computer Systems,Peking UniversityNetwork Host9roduction to Computer Systems,Peking University人与人之间的网络 计算机网络离得近的人容易成为朋友,形成网络宿舍、班级、院系之间;学校之间;之间家和邻居家、村和邻村、等。层级概念:大的网络 = 小的网络连接而成班级 = 多个宿舍;学校 =

7、多个院系户、村、镇、县、市、省、国家、地球、星系10roduction to Computer Systems,Peking UniversityComputer NetworksA network is a hierarchical system of boxes and wiresanized by geographical proximitySAN (System Area Network) spans cluster or machine roomSwitched Ethernet, Quadrics QSW, LAN (Local Area Network) spans a buil

8、ding or cusEthernet is most prominent exleWAN (Wide Area Network) spans country or worldTypically high-speed po-to-pophone linesAnernetwork (ernet) is anerconnected set ofnetworksThe Global IPernet (uppercase “I”) is the most famous exleof anernet (lowercase “i”)Lets see how anernet is built from th

9、e ground up11roduction to Computer Systems,Peking UniversityLowest Level: Ethernet Segment100 Mb/s100 Mb/shub宿舍邮箱portEthernet segment consists of a collection of hosts connectedby wires (twisted pairs) to a hubLocal: Spans room or floor in a buildingOperations:Hub slavishly copies each bit from each

10、 port toevery othortBridges/routers became chenough to replace the hub12hosthosthostroduction to Computer Systems,Peking UniversityNext Level: Bridged Ethernet SegmentABXbridge100 Mb/s100 Mb/shubhub1 Gb/s楼长分发100 Mb/s100 Mb/shubBridgeYhubCSpans building or cusBridges cleverly learn which hosts are re

11、achable from whichports and then selectively copy frames from port to port13hosthosthosthosthosthosthosthosthosthosthosthostroduction to Computer Systems, Peking UniversityConceptual View of LANsFor simplicity, hubs, bridges, and wires are often shown asa collection of hosts attached to a single wir

12、e:.hosthosthost14roduction to Computer Systems, Peking UniversityNext Level:Multipleernetspatible LANs can be physically connected byspelized computers called routersThe connected networks are called anernet.hosthosthosthosthosthostLAN 1LAN 2routerrouterrouterWANWAN邮局y different,LAN 1 and LAN 2 migh

13、t be completotallypatible(e.g., Ethernet and Wifi, 802.11*, T1-links, DSL, )15roduction to Computer Systems,Peking UniversityLogical Structure of anernethostrouterhostrouterrouterrouterrouterrouterSend packets from source to destination by hopthrough networks数据包经过不同途径、路线邮递、快递在经过不同的途径、路线类似的,交通网络、网络16

14、roduction to Computer Systems,Peking UniversityOutlineernet and a cnt-server mHost and computer networksNetwork protocolsGlobal IPernetProgrammers view ofernetEvolution ofernet17roduction to Computer Systems,Peking UniversityWhat is a protocol?协议 = Pre-agreed rulesCry = 悲伤S = 开心点头 = yes摇头 = noHuman

15、protocols:Whats the time?Specific msgs sentSpecific actions taken when msgs received, or other events18roduction to Computer Systems,Peking UniversityThe Notion of anQuestion: How is iternet Protocolsible to send bits acrosspatible LANs and WANs?我怎么把Solution:寄到非洲某部protocol software running on each h

16、ost and routersmooths out the differenbetn the different networks邮局(因为邮局有的协议、规则)Implements anernet protocol (i.e., set of rules)管理网络中计算机收发数据的行为erns how hosts and routers should cooperate when theytransfer data from network to network 不同计算机协作TCP/IP is the protocol for the global IP类似的,翻译规则,ernet规则19r

17、oduction to Computer Systems, Peking UniversityWhat Does anernet Protocol Do?Provides a naming scheme 命名规则(即设定地址)ernet protocol defines a uniform format for hostAnaddressesEach host (and router) is assignedeast one of theseernet addressest uniquely identifies itProvides a delivery mechanism 投递机制(如邮政

18、投递)Anernet protocol defines a standard transfer unit to bedelivered (packet)Packet consists of header and payloadHeader: contains info such as packet size, source and destination addressesPayload: contains data bits sent from source host20roduction to Computer Systems, Peking UniversityTransferring

19、Data Over anernetLAN1写密信LAN2Host AHost B读密信(1)(8)写地址、贴邮票ernet packet核对地址、拆信(2)(7)LAN1 frame送到邮局邮局分理(3)(6)LAN2 frame(4)(5)中国邮政处理ernet packet header某部邮政处理PH:FH: LAN frame header21Routerprotocol softwaredataPHFH2dataPHFH1LAN2adapterLAN1adapterdataPHFH2dataPHFH1LAN2adapterLAN1adapterdataPHFH2dataPHFH1pr

20、otocol softwareprotocol softwaredatadataservercntroduction to Computer Systems, Peking University有深度的网络问题er a number of important questions:Other IesWe are glossinWhat if different networks have different(segmenion) 数据包大小不同怎么办?um frame sizes?How do routers know where to forward frames? 路由器怎么知道发往何处?H

21、ow are routers informed when the network topology changes?如果网络结构变化,怎么处理?What if packets get lost? 如果数据包丢了,怎么办?These (and other) questions are addressed by the area ofsystems known as computer networking生活中解决不了的,网络也解决不好,如拥堵。22roduction to Computer Systems,Peking UniversityOutlineernet and a cnt-serve

22、r mHost and computer networksNetwork protocolsGlobal IPernetProgrammers view ofernetEvolution ofernet23roduction to Computer Systems,Peking UniversityGlobal IPernetMost famous exle of anernetBasethe TCP/IP protocol familyernet protocol) :邮寄地址IP (Provides basic naming scheme and unreliable delivery c

23、apabilityof packets (datagrams) from host-to-hostUDP (Unreliable Datagrrotocol)Uses IP to provide unreliable datagram delivery frompros-to-prosControl Protocol)一个地址、多个prosTCP (TransmisUses IP to provide reliabover connectionsyte streams from pros-to-prossed via a mix of Unix file I/O and functions f

24、rom theAcerface 套接字接口sockets24roduction to Computer Systems,Peking UniversityHardware and Softwareanizationof anernet ApplicationIE socketsocket25网络I/O写地址、贴邮票roduction to Computer Systems, Peking UniversityBasicernet Componentsernet backbone: 骨干网collection of routers (nationwide or worldwide) connec

25、ted by high-speedpo-to-ponetworkss (IXP): 互联网交换中心ernet Exchange Poroutert connects multipackbones (often referred to as peers)s (NAP)Also called Network Acs PoRegional networks: 区域网smaller backbonest cover smaller geographical areas(e.g., cities or ses)of presence (POP): 入网点Pomachinet is connected t

26、o theerneternet Service Providers (ISPs): 网络服务供应商provide dial-up or direct acs to POPs26roduction to Computer Systems, Peking Universityernet Connection HierarchyPrivateIXPIXPIXP“peering”agreementsbetnColocationsitestwo backbonecompanies often bypass IXPBackboneBackboneBackboneBackbonePOPPOPPOPPOPPO

27、PPOPPOPT3Regional netISPBig BusinessPOPPOPPOPPOPPOPPOPCable modemPgh employeePOPDSLT1T1Small BusinessDC employeeISP (for individuals)27roduction to Computer Systems,Peking UniversityOutlineernet and a cnt-server mHost and computer networksNetwork protocolsGlobal IPernetProgrammers view ofernetEvolut

28、ion ofernet28roduction to Computer Systems,Peking UniversityA Programmers View of theernet如何通过编程把数据包从一个host发给另一个Hosts are mapped to a set of 32-bit IP addresses79数字记不住怎么办?The set of IP addresses is mapped to a set of identifierscalledernetnames79 is mapped to一串数字对应一个名字A propros on ones on anotherern

29、et host can communicate wiernet host over a connection如何建立 connection?29roduction to Computer Systems, Peking UniversityIP Addresses32-bit IP addresses are stored in an IP address structIP addresses are always stored(big-endian byte order)emory in network byte orderTrue in general for anymachine to

30、another.eger transferred in a packet header from oneE.g., the port number used to identify anernet connection.Useful network byte-order converfunctions (“l” = 32 bits, “s” = 16 bits)htonl: convert u htons: convert u ntohl: convert u ntohs: convert u32_t from host to network byte order16_t from host

31、to network byte order 32_t from network to host byte order 16_t from network to host byte order30roduction to Computer Systems, Peking UniversityDotted Decimal NoionBy convention, each byte in a 32-bit IP address is representedby its decimal value and separated byriodIP address: 16进制10进制0 x8002C2F2=

32、42Functions for converting betdotted decimal strings:n binary IP addresses andinet_ntoa: IP address in network byte order dotted decimal stringinet_aton: dotted decimal string IP address in network byte order“n” denotes network represen“a” denotes application represenionion31roduction to Computer Sy

33、stems,Peking UniversityIP Address StructureIP (V4) Address space dividedo classes:240 1 2 381631Class AClass B Class C Class DClass ENetwork ID Written in form w.x.y.z/nn = number of bits in host addressE.g., CMU written as /16,Class B addressB类地址Un-routed (private) IP addresses:/8/12/16320Net IDHos

34、t ID10Net IDHost ID110Net IDHost ID1110Multicast addressfor experiments1111roduction to Computer Systems, Peking UniversityernetNamesunnamed -levelnamesSecond-levelnamesmitcmuberkeleyamazonThird-levelnamescsecewww52icsspgreatwhite0i386-f7733roduction to Computer Systems, Peking UniversityNaming Serv

35、ice (DNS)Theernet maains a mapbetn IP addresses andnames in a huge worldwide distributed database called服务器DNSConceptually, programmers can view the DNS database as a collection ofmillions of host entry structures:Functions for retrieving host entries from DNS:gethostbyname: query key is a DNSgethos

36、tbyaddr: query key is an IP .34roduction to Computer Systems, Peking UniversityProperties of DNS Host EntriesEach host entry is an equivalence class ofnames andIP addresses 每个主机= 若干名字+地址name localhostack address sible:Each hoss a locally definedwhich always maps to the loDifferent kinds

37、of maps areSimple case: one-to-one mapbetnname and IP address: maps to 0Multiplenames mapped to the same IP address:. both map to anMultiplenames mapped to multiple IP addresses:maps to multiple IP addressesSome validnamest map to any IP address:le: 例如抢注个人,但未上线for ex35roduction to Computer Systems,

38、Peking UniversityA Programt Queries DNSchar *argv) /* argv1 is amain(argc,name */char *pp;struct in_addr/*ordotted decimal IP addr */addr;struct hostent *hostp;/* poif (inet_aton(argv1, &addr)erto a DNS host entry structure*/!=0)hostp = Gethostbyaddr(const char *)&addr, sizeof(addr),AF_INET);42to0 x

39、8002C2F2elsehostp = Gethostbyname(argv1);prf(offil hostname: %sn, hostp-h_name);/= hostp-h_aliases; *pp f(alias: %sn, *pp); /pr!=prhost name NULL; pp+)all alias namesfor(pppr= hostp-h_addr_list; *ppfor(pp!= NULL; pp+) addr.s_addr = (struct in_addr *)*pp)-s_addr;pr / prf(address: %sn, inet_ntoa(addr)

40、; all addressesroduction to Computer Systems,Peking UniversityUsing DNS Programlinux ./dnsoffil hostname: address 0linux ./dns 1offil hostname: ANGELSHARK.ICS.CS.CMU.EDUaddress: 1linux ./dnsoffi alias:address: address: address: address:lhostname:903044737roduction to Computer Systems, Peking Univers

41、ityQuerying DIGInformation Groper (dig) provides a scriptabled lineerface to DNSlinux dig +short 0linux dig +short -x 1 ANGELSHARK.ICS.CS.CMU.EDU.linux dig +short 044790338roduction to Computer Systems, Peking Universityernet Connectionsnts and servers communicate by sending streams of bytesC互联网连接?o

42、ver connections:Po-to-po, full-duplex (2-way communication), and reliable.客户端与服务器端之间,双向可靠传输通道仅有IP地址是不够的!IP地址 : 端才能对应到A socket is an endpoof a connection单个pros:sSocket address is an IPaddress:port pairA port is a 16-bitegert identifies a proEphemeral port: Assigned automatically and temporarily on cn

43、twhen cnt makes a connection requestWell-known port: Assoted with some service provided by a server(e.g., port 80 is assoted with Web servers)A connection is uniquely identified by the socket addressesof idpos (socket pair)(cliaddr:cliport, servaddr:servport)39roduction to Computer Systems,Peking Un

44、iversityPutting it all Together:Anatomy of anernet ConnectionServer socket address5:80Cnt socket address42:51213Connection socket pair(42:51213, 5:80)Cnt host address42Server host address540Server(port 80)Cntroduction to Computer Systems,Peking UniversityOutlineernet and a cnt-server mHost and computer networksNetwork protocolsGlobal IPernetProgrammers view ofernetEvolution ofernet41roduction to Computer Systems,Pek

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论