Week 12.b CS3650 03/27 2024 https://naizhengtan.github.io/24spring/ 1. packet switching 2. IP 3. DNS 4. socket programming ------ 1. Packet switching * circuit switching [show circuit switching for telephone in early days: https://www.youtube.com/watch?v=aYkh6BrsPpQ&list=PPSV&ab_channel=May-StringerHouse ] * Question: think of using circuit switching for today's Internet services, like Google, facebook, tiktok. What will happen? (1) this connection would be idle most of the time (2) for every new web server you want to connect to, you would have to wait to setup a new connection (3) if any of the links on the electrical connection between your browser and the server failed, the connection would be unusable. * packet switching [draw packets switching] Host A | +---[packet]--> ---------------+ | p | p | ...| ---[link]---> +---[packet]--> ---------------+ | buffer Host B * then, how about packet switching? (1) best-effort network, so no worries about the idleness [draw the figure of traffic requirement vs. time] (2) each packet has a header of information of the destination, so no worries of setting up a connection (3) if a link (or router) failed, packets could simply be detoured along a different network path, as long as the network is still connected * what does a packet look like? say, visiting www.google.com: +----------------------------+ | +------------------------+ | e | +-------------------+ | t | | +-------------+ | h | | | +------+ | e | ip | tcp | http | data | | r | | | +------+ | n | | +-------------+ | e | +-------------------+ | t +------------------------+ +----------------------------+ * the connection between packet switching and the layered model http <-> application tcp <-> transport ip <-> routing ethernet <-> link&physical * Where are the layers implemented? * Application layer is implemented in apps: browser, Skype, Facebook, etc. * TCP/UDP (transport layer): they are implemented in your operating system’s kernel. * IP (routing layer): the end hosts need to participate in the routing layer because they insert the source and destination addresses. Unlike the top two layers, the routers and gateways also need to implement and understand the IP protocol because they need to forward data from one network to another. * Link&physical layers: hardware on end hosts and routers 2. IP addresses * Q: have you heard of IPs? What do IPs look like? When did you encounter them? * IP addresses: identifying hosts on the Internet * 32-bit number in Internet Protocol version 4. Use quad dot notation. * Two kinds of IP addresses: public and private * Public IPs: An IP that can be routed to (router can find a path to this IP). ** E.g., a server that needs to be on a well-known IP address. * Private IPs: For devices on a private network ** a laptop at home. ** machines at Northeastern network ** Allows us to reuse same addresses in different independent networks. ** Solution to IP address exhaustion. ** But, doesn't make sense to routers on the global Internet; they can't route to it. For instance, can't easily use laptop as a server ** Analogy: Room numbers only make sense within a building, building address is global * Allotment: ** IANA (Internet Assigned Numbers Authority) controls public IPs ** Self-assign private IP so long as it's in a few designated ranges (192.168.*.*, 10.*.*.*, 172.16.*.*--172.31.**) ** localhost: 127.0.0.1 * What if a host on a private IP network needs to get to the outside world? ** Example: Laptop wants to reach www.google.com ** A device called a network-address translator (NAT) translates between these two addresses ** Typically, one public address for many private addresses [DEMO: Type IP address into Google to find out your public IP address.] * Private IPs are an example of hierarchy: ** Allows us to scale to a large number of hosts ** More examples of hierarchy in routing layer section. Q: how much do you want to pay for a public IP? [aws price: $0.005/hr, that is $3.6/month] Q: how many ips one can freely use in a 172.16.*.*? [asnwer: 2^16] 3. DNS: Domain Name System Q: if IPs are used for locating machine, how come I don't know it when using Internet? * Human-readable analogue of IP addresses * Hierarchical structure: Top-level domain (.com, .net, .org, etc.) subdomains (google, nyu) * Question: How do we map domain names to IP addresses? * What's the dumbest way to do this: a single mapping file ** This is how it worked before 1984. What do you think this file was called? HOSTS.TXT ** A few 100 hosts on the Internet then ** Call up operator at SRI to get yourself added to it. ** Get HOSTS.TXT over the Internet by asking your friend for it :) [show HOSTS.TXT in 1974] * Clearly unsustainable as the Internet grew. ** DNS evolved as an automated solution to this problem. ** Think of it as a globally available hash table / dictionary. * How does DNS organize? ** Hierarchy of servers similar to the domain name hierarchy: --> root server (logically just one, physically replicated) --> TLD servers (one each for .com, .org, etc.) --> authoritative servers (one each for FB, Google, NYU) --> local server (provided as a convenience, outside the hierarchy) * Deja vu? You saw a very similar problem two weeks ago about hierarchical file systems. Analogy: machine <-> file ip <-> inode number DNS servers <-> dirs root DNS server <-> "/" inode DNS <-> hierarchical file system ** Q: So how do you lookup www.google.com --> Start at your local DNS server. --> If it already has the IP address, it returns it, you're done. --> Otherwise, start at root DNS server and go downwards. [DEMO: dig www.google.com and use ip to access google maps] 4. socket programming * a quick intro to "port number" * motivation: if two processes locate on the same machine, how does a packet distinguish them? * port number (16bits) < 1024 are reserved for well-known services http: 80, ssh: 22, etc. * How do applications talk to the network? * The Socket programming interface (been around since 1983. Great example of longevity.) * There are UDP and TCP. For simplicity, we will only work with TCP. * a toy example A client sends "hello world!" to a server. [see handout] [server] [client] | | fd = socket(...) fd = socket(...) bind(fd,...) | listen(fd,...) | | | new_fd = accept(fd,...) +--connect(fd,...) | / | |<------------------+ | |------------------------->| | | new_fd <====================> fd * discuss topics in order: (1) sending and receiving data to and from an established socket (2a) establishing sockets for server (2b) establishing sockets for client (3) a toy client-server example [start from here next time] [Acknowledgment: Anirudh Sivaraman]