Intro to Networking & Network programming Computer networking is based on packet-switching - The packet switching idea came along mid-60s - The state-of-art then was circuit switching (telephone networks) Packet-switching Classical circuit-switching transmits information transmits voice in analog form in digital form store-n-forward packets establish circuits a packet: array of bytes |___packet header__|___ pay load_______| Example networks: Ethernet (a local area wired network, e.g. connecting computers in a lab, dorm) Wifi (a local area wireless network) wifi(or ethernet) switch (stores and forward packets) / \ / \ host host Each computer has a unique 48-bit address (MAC address) Parts of the wifi header contains a MAC header that contains the source and destination MAC address, (protocol) type (specifying what kind of protocol packet is stored at payload) dst MAC, src MAC, type, payload How to make different types of networks inter-operate with each other? host host host host | | | | _switch switch_____ | router cicles of networks with routers, routers connect with each other if router were to translate every network to every other network, the translation logic would be O(n^2). The solution: the internet protocol, the hourglass HTTP, SMTP, IPP, DNS, TCP, UDP, ICMP IP ethernet, wifi, cellular, cable modem, etc. What does IP do? * defines a naming scheme: IP address (IPv4 addresses are four bytes) - IP addresses are hierarchical: a network prefix + a host suffix e.g. 216.165.108.10/24 - routers only care about how to route to a specific network, not host * routers route a packet to its destination IP address - best effort (no guaranteed delivery) IP header fields protocol, src-IP, dst-IP,... TCP (transmit control protocol): * a reliable byte stream * between two processes * with flow control and congestion control (send as much as possible without causing excessive loss) TCP header fields source-port, dst-port, seq-no, acknowledge-no, ... a tcp-connection is uniquely identified by the quadruple: src-ip, src-port, dst-ip, dst-port UDP * unreliable datagram * between two processes DNS: domain name service * provides a mapping between human readable names * the mappings are stored in a huge worldwide distributed database consisting of many DNS servers DNS names are hierarchical . (i.e. the root) / | \ gov edu com uk jp cn io tv .... / | \ \ nsf cs \ news \ www - lookups start at the top (13 root dns servers known to everyone) - given a name, root dns servers tells which first level dns servers to lookup next. - and so on - lookup results are cached until a specified expiration time. ---------------------- Network programming client/server-style interaction server / | \ client client client client <--user code | TCP/IP <--kernel code | network <-- h/w adaptor