學年計算機方向課程大二上ics課件24-internet_第1頁
學年計算機方向課程大二上ics課件24-internet_第2頁
學年計算機方向課程大二上ics課件24-internet_第3頁
學年計算機方向課程大二上ics課件24-internet_第4頁
學年計算機方向課程大二上ics課件24-internet_第5頁
已閱讀5頁,還剩40頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)

文檔簡介

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會上網(wǎng) 懂網(wǎng)絡(luò)How to set up a network connectio

2、n and a webserver by programming?What is computer network? 基本網(wǎng)絡(luò)知識erface 基本接口知識SocketWeb server 通過編程架設(shè)服務(wù)器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上網(wǎng):Hao123 Baidu 新浪4roduction to Computer Systems,Peking Universityernet = cnt-server聊天、網(wǎng)游ernet?服務(wù)器掛了?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有需求有資源、服務(wù)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通信、服務(wù): 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人與人之間的網(wǎng)絡(luò) 計算機網(wǎng)絡(luò)離得近的人容易成為朋友,形成網(wǎng)絡(luò)宿舍、班級、院系之間;學校之間;之間家和鄰居家、村和鄰村、等。層級概念:大的網(wǎng)絡(luò) = 小的網(wǎng)絡(luò)連接而成班級 = 多個宿舍;學校 =

7、多個院系戶、村、鎮(zhèn)、縣、市、省、國家、地球、星系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樓長分發(fā)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數(shù)據(jù)包經(jīng)過不同途徑、路線郵遞、快遞在經(jīng)過不同的途徑、路線類似的,交通網(wǎng)絡(luò)、網(wǎng)絡(luò)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?協(xié)議 = 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郵局(因為郵局有的協(xié)議、規(guī)則)Implements anernet protocol (i.e., set of rules)管理網(wǎng)絡(luò)中計算機收發(fā)數(shù)據(jù)的行為erns how hosts and routers should cooperate when theytransfer data from network to network 不同計算機協(xié)作TCP/IP is the protocol for the global IP類似的,翻譯規(guī)則,ernet規(guī)則19r

17、oduction to Computer Systems, Peking UniversityWhat Does anernet Protocol Do?Provides a naming scheme 命名規(guī)則(即設(shè)定地址)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有深度的網(wǎng)絡(luò)問題er a number of important questions:Other IesWe are glossinWhat if different networks have different(segmenion) 數(shù)據(jù)包大小不同怎么辦?um frame sizes?How do routers know where to forward frames? 路由器怎么知道發(fā)往何處?H

21、ow are routers informed when the network topology changes?如果網(wǎng)絡(luò)結(jié)構(gòu)變化,怎么處理?What if packets get lost? 如果數(shù)據(jù)包丟了,怎么辦?These (and other) questions are addressed by the area ofsystems known as computer networking生活中解決不了的,網(wǎng)絡(luò)也解決不好,如擁堵。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網(wǎng)絡(luò)I/O寫地址、貼郵票roduction to Computer Systems, Peking UniversityBasicernet Componentsernet backbone: 骨干網(wǎng)collection of routers (nationwide or worldwide) connec

25、ted by high-speedpo-to-ponetworkss (IXP): 互聯(lián)網(wǎng)交換中心ernet Exchange Poroutert connects multipackbones (often referred to as peers)s (NAP)Also called Network Acs PoRegional networks: 區(qū)域網(wǎng)smaller backbonest cover smaller geographical areas(e.g., cities or ses)of presence (POP): 入網(wǎng)點Pomachinet is connected t

26、o theerneternet Service Providers (ISPs): 網(wǎng)絡(luò)服務(wù)供應(yīng)商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如何通過編程把數(shù)據(jù)包從一個host發(fā)給另一個Hosts are mapped to a set of 32-bit IP addresses79數(shù)字記不住怎么辦?The set of IP addresses is mapped to a set of identifierscalledernetnames79 is mapped to一串數(shù)字對應(yīng)一個名字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(fā)” = 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服務(wù)器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互聯(lián)網(wǎng)連接?o

42、ver connections:Po-to-po, full-duplex (2-way communication), and reliable.客戶端與服務(wù)器端之間,雙向可靠傳輸通道僅有IP地址是不夠的!IP地址 : 端才能對應(yīng)到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. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
  • 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論