This presentation is used in many places including Vignan, AITAM, This contains both tutorials and hands on training. This presentation explains Unix Internals, Socket programming, both data gram based and IP based concepts are explained with live examples.
Inter-Process Communication (IPC) techniques on Mac OS XHEM DUTT
Inter-process communication (IPC) refers to techniques for exchanging data between processes and threads. Common IPC methods include message passing, synchronization, shared memory, and remote procedure calls. IPC is useful for information sharing, increasing computational speed, modularity, convenience, and privilege separation. Common IPC techniques on Mac OS X include shared memory, Mach ports, sockets, Apple Events, distributed notifications, pasteboards, and distributed objects. Each method has advantages and disadvantages for different use cases.
The document discusses interprocess communication and summarizes the key points about client-server and group communication patterns. It describes the Java API for internet protocols, which provides datagram and stream communication using UDP and TCP. Specifically, it outlines how UDP supports message passing through datagrams, while TCP provides reliable, ordered streams between processes.
This document summarizes a student project on programming Linux device drivers. It discusses the key components of the Linux kernel relevant to device drivers like process management, memory management, and file systems. It also covers different types of devices, loading and unloading kernel modules, and the Linux device model. The project involved creating drivers for both wired and wireless devices and introducing a subdirectory structure for code organization.
The document discusses interprocess communication (IPC) and protocols. It describes different IPC paradigms like message queues, semaphores, and shared memory. It also covers unicast and multicast communication, synchronous vs asynchronous operations, data representation for communication between processes, and examples of protocols like HTTP.
This document discusses interprocess communication and distributed systems. It covers several key topics:
- Application programming interfaces (APIs) for internet protocols like TCP and UDP, which provide building blocks for communication protocols.
- External data representation standards for transmitting objects between processes on different machines.
- Client-server communication models like request-reply that allow processes to invoke methods on remote objects.
- Group communication using multicast to allow a message from one client to be sent to multiple server processes simultaneously.
This document provides an overview of networking concepts including network types, medium access control protocols, TCP/IP protocol suite, addressing, Ethernet frames, ARP, and standards organizations. It begins with an agenda that lists these topics and includes diagrams to illustrate CSMA/CD, the OSI model, TCP/IP encapsulation, and Ethernet encapsulation. Examples are provided for different network devices, addressing formats and protocols.
The document discusses interprocess communication (IPC) and threads. It covers different IPC mechanisms like signals, message passing using pipes, and shared memory. It also covers different threading models including user-level threads managed by libraries, kernel-level threads with a one-to-one mapping to OS threads, and hybrid models. The document outlines the life cycle of a thread and considerations for thread implementation.
This document provides an overview of network protocols in Java. It begins with an introduction to networking concepts like protocols, clients, servers and the internet protocol stack. It then discusses socket programming in Java using TCP and UDP. Examples are provided of a simple TCP client-server application that converts text to uppercase and a UDP client-server that sends and receives datagrams. The document aims to teach how to build networked applications in Java using common network protocols.
Inter-Process Communication (IPC) techniques on Mac OS XHEM DUTT
Inter-process communication (IPC) refers to techniques for exchanging data between processes and threads. Common IPC methods include message passing, synchronization, shared memory, and remote procedure calls. IPC is useful for information sharing, increasing computational speed, modularity, convenience, and privilege separation. Common IPC techniques on Mac OS X include shared memory, Mach ports, sockets, Apple Events, distributed notifications, pasteboards, and distributed objects. Each method has advantages and disadvantages for different use cases.
The document discusses interprocess communication and summarizes the key points about client-server and group communication patterns. It describes the Java API for internet protocols, which provides datagram and stream communication using UDP and TCP. Specifically, it outlines how UDP supports message passing through datagrams, while TCP provides reliable, ordered streams between processes.
This document summarizes a student project on programming Linux device drivers. It discusses the key components of the Linux kernel relevant to device drivers like process management, memory management, and file systems. It also covers different types of devices, loading and unloading kernel modules, and the Linux device model. The project involved creating drivers for both wired and wireless devices and introducing a subdirectory structure for code organization.
The document discusses interprocess communication (IPC) and protocols. It describes different IPC paradigms like message queues, semaphores, and shared memory. It also covers unicast and multicast communication, synchronous vs asynchronous operations, data representation for communication between processes, and examples of protocols like HTTP.
This document discusses interprocess communication and distributed systems. It covers several key topics:
- Application programming interfaces (APIs) for internet protocols like TCP and UDP, which provide building blocks for communication protocols.
- External data representation standards for transmitting objects between processes on different machines.
- Client-server communication models like request-reply that allow processes to invoke methods on remote objects.
- Group communication using multicast to allow a message from one client to be sent to multiple server processes simultaneously.
This document provides an overview of networking concepts including network types, medium access control protocols, TCP/IP protocol suite, addressing, Ethernet frames, ARP, and standards organizations. It begins with an agenda that lists these topics and includes diagrams to illustrate CSMA/CD, the OSI model, TCP/IP encapsulation, and Ethernet encapsulation. Examples are provided for different network devices, addressing formats and protocols.
The document discusses interprocess communication (IPC) and threads. It covers different IPC mechanisms like signals, message passing using pipes, and shared memory. It also covers different threading models including user-level threads managed by libraries, kernel-level threads with a one-to-one mapping to OS threads, and hybrid models. The document outlines the life cycle of a thread and considerations for thread implementation.
This document provides an overview of network protocols in Java. It begins with an introduction to networking concepts like protocols, clients, servers and the internet protocol stack. It then discusses socket programming in Java using TCP and UDP. Examples are provided of a simple TCP client-server application that converts text to uppercase and a UDP client-server that sends and receives datagrams. The document aims to teach how to build networked applications in Java using common network protocols.
DNS maps domain names to IP addresses by using a distributed database and servers. It translates human-friendly domain names like www.example.com to numerical IP addresses like 192.0.2.1 that computers use to locate each other on the network. The DNS database contains resource records that associate domain names with IP addresses and other information. Name servers query the DNS database to resolve domain names and return IP addresses to applications and users.
The document discusses the OSI model and TCP/IP model for computer networking. It describes the seven layers of the OSI model including the physical, data link, network, transport, session, presentation and application layers. It provides details on the functions and responsibilities of each layer. The document also summarizes that the TCP/IP model has five layers and combines the top three layers of the OSI model into one layer.
This document provides an overview of networking concepts including the OSI model layers, network types, and networking devices. It describes the responsibilities and issues handled at each OSI layer, from the physical layer transmitting raw bits to the application layer running application-specific protocols. It also covers topics like addressing schemes, modes of service, and how devices like repeaters, bridges, routers, and gateways operate to connect different network types.
This document discusses network protocols and structure. It defines what a network protocol is and describes some common protocols like Ethernet, Token Ring, FDDI, and ATM. It also discusses different types of network models and structures including local area networks (LANs), personal area networks (PANs), home area networks (HANs), wide area networks (WANs), campus networks, metropolitan area networks, virtual private networks (VPNs), backbone networks, and global area networks (GANs). Finally, it covers different network topologies like bus, star, mesh, and ring topologies.
1) Inter-process communication (IPC) allows processes to communicate and synchronize their actions through message passing.
2) There are two main primitives for message passing - send and receive. Messages have a header and body and can be of fixed or variable size.
3) Message passing can be blocking or non-blocking, where blocking waits for the message and non-blocking continues after sending or receiving.
nterprocess communication (IPC) is a set of programming interfaces that allow a programmer to coordinate activities among different program processes that can run concurrently in an operating system. This allows a program to handle many user requests at the same time. Since even a single user request may result in multiple processes running in the operating system on the user's behalf, the processes need to communicate with each other. The IPC interfaces make this possible. Each IPC method has its own advantages and limitations so it is not unusual for a single program to use all of the IPC methods.
IPC methods include pipes and named pipes; message queueing;semaphores; shared memory; and sockets.
This document provides an overview of various application layer protocols including HTTP, HTTPS, SMTP, POP3, FTP, SFTP, SCP, Telnet, and SSH. It describes each protocol, including what they are used for and how they differ. Some key points:
- HTTP and HTTPS are used to access data on the world wide web, with HTTPS providing encryption for secure transactions.
- SMTP and POP3 are used for email, with SMTP sending messages between servers and POP3 allowing users to receive messages from their inbox.
- FTP and SFTP are used for file transfer, with SFTP encrypting data for security unlike regular FTP. SCP also provides secure file transfer.
- Tel
The document discusses internetworking and how to build an internet from the ground up. It describes how different networking technologies are interconnected through protocols like TCP/IP which allow communication across heterogeneous networks by smoothing out differences. Layered models and protocols are explained, including how packets are routed from one network to another through gateways and fragmented if needed to traverse networks with different maximum transmission units.
The document discusses interprocess communication and distributed systems, noting that distributed systems rely on defined communication protocols like interprocess communication using message passing over networks. It also covers topics like overhead in communication systems, different data storage and transfer formats between systems like XML, and Java object serialization for complex data transfer. Effective communication protocols aim to minimize overhead while maximizing throughput.
The document discusses several internet protocols including:
- IP which delivers data packets between hosts and includes addressing tags through encapsulation.
- TCP/IP which establishes communication between networks and provides host access to the internet.
- Ipv4 and Ipv6 which are internet protocols for carrying data packets with Ipv6 supporting more nodes.
- Early protocols for file retrieval like FTP, Gopher, and Telnet which allowed downloading and using remote files and applications with varying levels of description.
This document provides an overview and outline of lecture 11 of CS 3430: Introduction to Python and Perl at Utah State University. It covers basic network programming concepts like sockets, clients, servers, TCP, UDP and includes code examples for minimal servers and clients. It also discusses handling multiple connections, accessing URLs, opening remote files, getting HTML source, and installing and checking availability of the Python Imaging Library (PIL).
This document provides an overview of CCNA Module 1 on internetworking. It describes the purpose of routers, switches, hubs and other network devices. It also covers networking concepts like collision domains, broadcast domains, and the operation of Ethernet networks using CSMA/CD. The document explains the OSI model layers and compares it to the TCP/IP model. It also discusses common network applications and protocols like TCP, UDP, IP, ARP and ICMP.
This document provides an overview of TCP/IP networking fundamentals. It discusses how TCP/IP works on a layered model with four layers - application, transport, internet and network. The transport layer uses either TCP or UDP, with TCP providing reliable connections and UDP being faster but unreliable. The internet layer is IP which transports datagrams unreliably. Networking concepts like encapsulation, addressing using IP addresses and ports, and protocols like TCP, UDP and IP are explained. Issues like IP addressing classes and subnetting are also covered at a high level.
This document provides an overview of basic networking concepts including protocols, protocol layers, network interconnection, and the Internet. It describes how networks are defined and addressed. The key protocol layers of OSI and TCP/IP models are examined including physical, data link, network, transport, and application layers. Common network types, topologies, and connectivity options are also summarized.
This document provides an overview of a course on computer networking. It discusses the objectives of the course which are to provide students with an understanding of networking concepts, protocols, and technologies. It outlines the various topics that will be covered over the semester including the physical layer, data link layer, network layer, transport layer, and application layer. It also provides guidance on expectations for students including attending lectures, reading assignments, and completing four assignments over the course of the semester.
Processes communicate through interprocess communication (IPC) using two main models: shared memory and message passing. Shared memory allows processes to access the same memory regions, while message passing involves processes exchanging messages through mechanisms like mailboxes, pipes, signals, and sockets. Common IPC techniques include semaphores, shared memory, message queues, and sockets that allow processes to synchronize actions and share data in both blocking and non-blocking ways. Deadlocks can occur if processes form a circular chain while waiting for resources held by other processes.
Interprocess communication (IPC) allows processes to communicate through message passing. There are two main forms of IPC - synchronous which blocks sending and receiving processes, and asynchronous which is non-blocking for sending. IPC uses protocols like TCP and UDP, with TCP providing reliable, ordered streams and UDP providing unreliable datagram delivery. For communication, data must be serialized into a byte sequence and deserialized on the receiving end.
The document discusses fundamentals of computer networking, including definitions of key terms like networks, protocols, and packet switching. It explains networking concepts such as the layered OSI model and TCP/IP stacks. Examples of different types of networking devices, protocols, and technologies are provided such as Ethernet, IP addressing, DNS, WiFi, and Bluetooth.
Fragmentation is the process of splitting large packets into smaller fragments to accommodate networks with smaller maximum transmission unit sizes. This allows packets to travel across multiple networks without being dropped. There are two types of fragmentation: transparent, where fragments are reassembled at exit gateways, and non-transparent, where fragments are treated as individual packets and reassembled only at the destination host, as used in the Internet Protocol. Key challenges include ensuring all fragments are received for reassembly and minimizing overhead from fragmenting and reassembling packets.
The document discusses computer networks and network protocols. It begins with an introduction to network protocols and the Internet protocols. It then provides definitions and explanations of communication protocols, including addressing, transmission modes, and error detection/recovery techniques. It lists and describes common network protocols like TCP/IP, routing protocols, FTP, SMTP, and more. It also discusses the OSI model layers, TCP/IP protocol suite, data encapsulation, protocol data units, protocol assignments to layers, and addresses at each layer.
The document discusses several topics related to computer network architecture and protocols. It begins by defining network architecture as a framework for designing, building, and managing communication networks. It describes the OSI 7-layer model and each of its layers. It also discusses the TCP/IP network architecture, IP addressing formats and classes, TCP and UDP protocols, and serial communication modes like simplex, half-duplex and full-duplex.
DNS maps domain names to IP addresses by using a distributed database and servers. It translates human-friendly domain names like www.example.com to numerical IP addresses like 192.0.2.1 that computers use to locate each other on the network. The DNS database contains resource records that associate domain names with IP addresses and other information. Name servers query the DNS database to resolve domain names and return IP addresses to applications and users.
The document discusses the OSI model and TCP/IP model for computer networking. It describes the seven layers of the OSI model including the physical, data link, network, transport, session, presentation and application layers. It provides details on the functions and responsibilities of each layer. The document also summarizes that the TCP/IP model has five layers and combines the top three layers of the OSI model into one layer.
This document provides an overview of networking concepts including the OSI model layers, network types, and networking devices. It describes the responsibilities and issues handled at each OSI layer, from the physical layer transmitting raw bits to the application layer running application-specific protocols. It also covers topics like addressing schemes, modes of service, and how devices like repeaters, bridges, routers, and gateways operate to connect different network types.
This document discusses network protocols and structure. It defines what a network protocol is and describes some common protocols like Ethernet, Token Ring, FDDI, and ATM. It also discusses different types of network models and structures including local area networks (LANs), personal area networks (PANs), home area networks (HANs), wide area networks (WANs), campus networks, metropolitan area networks, virtual private networks (VPNs), backbone networks, and global area networks (GANs). Finally, it covers different network topologies like bus, star, mesh, and ring topologies.
1) Inter-process communication (IPC) allows processes to communicate and synchronize their actions through message passing.
2) There are two main primitives for message passing - send and receive. Messages have a header and body and can be of fixed or variable size.
3) Message passing can be blocking or non-blocking, where blocking waits for the message and non-blocking continues after sending or receiving.
nterprocess communication (IPC) is a set of programming interfaces that allow a programmer to coordinate activities among different program processes that can run concurrently in an operating system. This allows a program to handle many user requests at the same time. Since even a single user request may result in multiple processes running in the operating system on the user's behalf, the processes need to communicate with each other. The IPC interfaces make this possible. Each IPC method has its own advantages and limitations so it is not unusual for a single program to use all of the IPC methods.
IPC methods include pipes and named pipes; message queueing;semaphores; shared memory; and sockets.
This document provides an overview of various application layer protocols including HTTP, HTTPS, SMTP, POP3, FTP, SFTP, SCP, Telnet, and SSH. It describes each protocol, including what they are used for and how they differ. Some key points:
- HTTP and HTTPS are used to access data on the world wide web, with HTTPS providing encryption for secure transactions.
- SMTP and POP3 are used for email, with SMTP sending messages between servers and POP3 allowing users to receive messages from their inbox.
- FTP and SFTP are used for file transfer, with SFTP encrypting data for security unlike regular FTP. SCP also provides secure file transfer.
- Tel
The document discusses internetworking and how to build an internet from the ground up. It describes how different networking technologies are interconnected through protocols like TCP/IP which allow communication across heterogeneous networks by smoothing out differences. Layered models and protocols are explained, including how packets are routed from one network to another through gateways and fragmented if needed to traverse networks with different maximum transmission units.
The document discusses interprocess communication and distributed systems, noting that distributed systems rely on defined communication protocols like interprocess communication using message passing over networks. It also covers topics like overhead in communication systems, different data storage and transfer formats between systems like XML, and Java object serialization for complex data transfer. Effective communication protocols aim to minimize overhead while maximizing throughput.
The document discusses several internet protocols including:
- IP which delivers data packets between hosts and includes addressing tags through encapsulation.
- TCP/IP which establishes communication between networks and provides host access to the internet.
- Ipv4 and Ipv6 which are internet protocols for carrying data packets with Ipv6 supporting more nodes.
- Early protocols for file retrieval like FTP, Gopher, and Telnet which allowed downloading and using remote files and applications with varying levels of description.
This document provides an overview and outline of lecture 11 of CS 3430: Introduction to Python and Perl at Utah State University. It covers basic network programming concepts like sockets, clients, servers, TCP, UDP and includes code examples for minimal servers and clients. It also discusses handling multiple connections, accessing URLs, opening remote files, getting HTML source, and installing and checking availability of the Python Imaging Library (PIL).
This document provides an overview of CCNA Module 1 on internetworking. It describes the purpose of routers, switches, hubs and other network devices. It also covers networking concepts like collision domains, broadcast domains, and the operation of Ethernet networks using CSMA/CD. The document explains the OSI model layers and compares it to the TCP/IP model. It also discusses common network applications and protocols like TCP, UDP, IP, ARP and ICMP.
This document provides an overview of TCP/IP networking fundamentals. It discusses how TCP/IP works on a layered model with four layers - application, transport, internet and network. The transport layer uses either TCP or UDP, with TCP providing reliable connections and UDP being faster but unreliable. The internet layer is IP which transports datagrams unreliably. Networking concepts like encapsulation, addressing using IP addresses and ports, and protocols like TCP, UDP and IP are explained. Issues like IP addressing classes and subnetting are also covered at a high level.
This document provides an overview of basic networking concepts including protocols, protocol layers, network interconnection, and the Internet. It describes how networks are defined and addressed. The key protocol layers of OSI and TCP/IP models are examined including physical, data link, network, transport, and application layers. Common network types, topologies, and connectivity options are also summarized.
This document provides an overview of a course on computer networking. It discusses the objectives of the course which are to provide students with an understanding of networking concepts, protocols, and technologies. It outlines the various topics that will be covered over the semester including the physical layer, data link layer, network layer, transport layer, and application layer. It also provides guidance on expectations for students including attending lectures, reading assignments, and completing four assignments over the course of the semester.
Processes communicate through interprocess communication (IPC) using two main models: shared memory and message passing. Shared memory allows processes to access the same memory regions, while message passing involves processes exchanging messages through mechanisms like mailboxes, pipes, signals, and sockets. Common IPC techniques include semaphores, shared memory, message queues, and sockets that allow processes to synchronize actions and share data in both blocking and non-blocking ways. Deadlocks can occur if processes form a circular chain while waiting for resources held by other processes.
Interprocess communication (IPC) allows processes to communicate through message passing. There are two main forms of IPC - synchronous which blocks sending and receiving processes, and asynchronous which is non-blocking for sending. IPC uses protocols like TCP and UDP, with TCP providing reliable, ordered streams and UDP providing unreliable datagram delivery. For communication, data must be serialized into a byte sequence and deserialized on the receiving end.
The document discusses fundamentals of computer networking, including definitions of key terms like networks, protocols, and packet switching. It explains networking concepts such as the layered OSI model and TCP/IP stacks. Examples of different types of networking devices, protocols, and technologies are provided such as Ethernet, IP addressing, DNS, WiFi, and Bluetooth.
Fragmentation is the process of splitting large packets into smaller fragments to accommodate networks with smaller maximum transmission unit sizes. This allows packets to travel across multiple networks without being dropped. There are two types of fragmentation: transparent, where fragments are reassembled at exit gateways, and non-transparent, where fragments are treated as individual packets and reassembled only at the destination host, as used in the Internet Protocol. Key challenges include ensuring all fragments are received for reassembly and minimizing overhead from fragmenting and reassembling packets.
The document discusses computer networks and network protocols. It begins with an introduction to network protocols and the Internet protocols. It then provides definitions and explanations of communication protocols, including addressing, transmission modes, and error detection/recovery techniques. It lists and describes common network protocols like TCP/IP, routing protocols, FTP, SMTP, and more. It also discusses the OSI model layers, TCP/IP protocol suite, data encapsulation, protocol data units, protocol assignments to layers, and addresses at each layer.
The document discusses several topics related to computer network architecture and protocols. It begins by defining network architecture as a framework for designing, building, and managing communication networks. It describes the OSI 7-layer model and each of its layers. It also discusses the TCP/IP network architecture, IP addressing formats and classes, TCP and UDP protocols, and serial communication modes like simplex, half-duplex and full-duplex.
The document compares the OSI and TCP/IP models and provides details on each layer of the OSI model.
The key points are:
1) The OSI model is an internationally standardized network architecture consisting of 7 layers, while TCP/IP was developed independently and its layers do not exactly match the OSI layers.
2) Each OSI layer has a specific function, with the physical layer defining physical interfaces, the data link layer handling framing and addressing, the network layer routing packets, and higher layers focusing on reliability and delivering data to applications.
3) TCP/IP uses four types of addresses - physical, logical, port, and application-specific - that correspond to different layers, with physical addresses changing
The document discusses network devices, communication protocols, and related topics. It describes the OSI reference model and TCP/IP model, detailing the layers and functions of each. It provides information on IP addressing, DNS, and gateway addressing. The OSI model has 7 layers including physical, data link, network, transport, session, presentation, and application layers. The TCP/IP model has 4 layers comprising network interface, internet, transport, and application layers.
This document provides an overview of key network terminology and concepts, including:
- Network components like network interface cards, hubs, switches, and cables.
- Network protocols and how they allow different devices to communicate.
- Operating systems' role in managing network resources and enabling sharing.
- The OSI model and what each layer is responsible for in data transmission.
- Common network addressing schemes and protocols like IP, TCP, UDP, and IPv6.
The document discusses the session layer, presentation layer, and application layer of the OSI model. It provides details on the functions and protocols of each layer. It also discusses the layers of the TCP/IP model and how they compare to the OSI model layers. The networking layers allow systems to establish communication sessions, format and encrypt data, and provide services to application processes. Common protocols like TCP, IP, HTTP, and FTP are described.
The document describes the OSI network model, which structures communications functions into a hierarchy of seven layers. Each layer offers services to the higher layers and communicates with corresponding layers in other nodes using agreed protocols. This modular layering reduces network complexity through encapsulation. Data moves down from higher to lower layers at the source, and up from lower to higher layers at the destination.
Chapter 5 introduction to computer communication networksN. A. Sutisna
The document provides an overview of data communication and networking in manufacturing systems. It discusses protocols, layered communication models like the ISO model, and physical network technologies. It introduces the TCP/IP model and motivations for the Internet, including universal connectivity and independence from physical networks. Key topics covered include IP addressing, packet formats, routing between networks, and Ethernet communication.
Internet Technology Lectures
network protocols, TCP/IP Model
Lecturer: Saman M. Almufti / Kurdistan Region, Nawroz University
facebook: https://www.facebook.com/saman.malmufti
YouTube Link:https://youtu.be/JgbAWAc0fDs
This document provides an overview and outline of topics to be covered in a chapter about TCP/IP protocols. The chapter will include: a brief history of the internet and TCP/IP; definitions of protocols and standards; a discussion of standards organizations; how internet standards are developed; and an overview of internet administration. It also previews key topics within each section, such as ARPANET, TCP, standards creation committees, maturity levels of requests for comments, and groups that coordinate internet issues.
This document provides an overview of networking and internetworking concepts. It defines what a network is and some common network protocols like TCP/IP. It discusses how network speed is measured by bit rate and latency. It then covers local area networks, wide area networks, and the internet. The document explains the purpose of networks for file sharing, communication, and remote program execution. It also discusses network messaging and different network service models like the OSI reference model and TCP/IP model. Finally, it provides a simplified example of how the TCP/IP protocol functions to route a packet from a source to destination across multiple routers.
Lesson4.9 d u4l3 hierarchy of open protocolsLexume1
This document explains the hierarchy of protocols that manages the complexity of the internet. It discusses how there are multiple layers of abstraction, with the highest being the application layer which turns binary into visible content through protocols like HTTP and DNS. Lower layers include the transport layer which manages packet transmission through protocols like TCP and UDP, the internet layer which handles routing through IP addresses, and the link layer which connects hardware through technologies like Ethernet and WiFi. The use of open standards across these layers allows for widespread interoperability between different devices and networks on the internet.
TCP/IP is the standard communication protocol on the internet. It is comprised of several layers including application, transport, internet, and link layers. The transport layer includes TCP and UDP which provide connection-oriented and connectionless data transmission respectively. TCP ensures reliable data delivery through features like connections, acknowledgments, and flow control. IPv6 is the latest version of the Internet Protocol which addresses the shortcomings of IPv4 like limited address space. IPv6 features include a larger 128-bit address space, simplified header format, built-in security, and autoconfiguration capabilities.
Here are the key steps to solve this problem:
- Propagation delay = Distance / Speed of light
- Distance = 4 km = 4000 m
- Speed of light = 2 x 10^8 m/sec
- Propagation delay = 4000 m / (2 x 10^8 m/sec) = 20 ms
- Transmit delay = Size of data / Bandwidth
- For transmit delay to equal propagation delay of 20 ms, set:
- Transmit delay = 20 ms
- Size of data = 1 bit (since we want minimum bandwidth)
- 20 ms = 1 bit / Bandwidth
- Bandwidth = 1 bit / 20 ms = 50 Mbps
Therefore, the minimum
The document discusses the history and architecture of the Internet and World Wide Web. It describes how the Internet allows communication through standardized protocols and IP addressing. The World Wide Web was created by Tim Berners-Lee in 1990 using hypertext and HTML. Information is transmitted from browsers to servers through protocols like HTTP and routers direct traffic based on IP addresses. Organizations like ISOC, IETF, and W3C work to manage standards and evolution of the Internet infrastructure.
The document provides an overview of protocol architectures and the TCP/IP protocol stack. It discusses how protocol architectures establish rules for exchanging data between systems using layered protocols. The TCP/IP model is then explained in detail through its five layers - physical, network access, internet, transport and application - and core protocols like IP, TCP and UDP. Key differences between IPv4 and IPv6 are also summarized.
This document contains information about network programming laboratory experiments at the Global Institute of Technology. It includes the syllabus, list of experiments, course objectives, and content beyond the syllabus. The key experiments covered are:
1. Studying different network topologies, LAN equipment, and configurations
2. Writing client and server programs in C using TCP and UDP for tasks like echoing messages and estimating round trip time
3. Simulating routing algorithms like Bellman-Ford in NS2 networking simulation software
The objectives are for students to learn network programming concepts like the OSI model, TCP/IP, and socket programming to implement client-server applications over TCP and UDP.
This document provides information about network programming laboratory experiments at the Global Institute of Technology. It includes:
1. An index listing the syllabus, list of experiments, course objectives and outcomes, additional content, and experiments.
2. The syllabus lists 10 experiments covering topics like network topologies, TCP/IP programming, routing algorithms, and protocols.
3. The list of experiments provides more details on 13 experiments to be performed, covering network devices, client-server programming, chat servers, and simulation of protocols.
The document discusses protocol architecture, TCP/IP, and internet-based applications. It covers:
1. The need for protocol architecture to break communication tasks into modular subtasks and arrange them in a vertical stack to allow for independent development and changes.
2. Key features of protocols including syntax, semantics, and timing to allow peer layers to communicate.
3. TCP/IP as the dominant protocol suite used on the internet, comprising a collection of protocols developed on ARPANET.
4. The layers of the TCP/IP protocol stack including physical, network access, internet, and host-to-host layers with example protocols like IP, TCP, and UDP.
The document summarizes key concepts in internetworking including protocol layering, encapsulation, and different types of network devices like hubs, bridges, and routers. It describes how the Internet Protocol (IP) allows interconnection of different networks by providing a global addressing scheme and best-effort delivery of packets across interconnected networks.
Similar to Introduction to socket programming nbv (20)
In this lecture, I have introduced to Massive Open Online courses. How they are conducted, how xMoocs are different from cMoocs. Also, included list of platforms which are hosting MOOC courses. Also, listed more than 1700 courses along with top 10 MOOC courses of 2017
This PPT discusses about some programming puzzles that are related to Encryption and also it emphasis the need for strengthening bit-wise operators concept.
This is delivered yesterday in our college to enlighten 1st year ECE and EEE students about engineering, engineering principles, how to be a good engineering students, and finally how to grow as a enterpreneur.
Engineering is the application of scientific knowledge and mathematics to solve problems and design solutions that improve lives and benefit society. It involves using principles from various scientific fields like physics, chemistry, biology combined with design, business and other considerations to invent, innovate, build and maintain useful structures, machines, processes and systems. Some key aspects of engineering include identifying societal needs, designing and testing solutions, and producing things in a cost-effective manner to address those needs.
In this talk, I explain 21st century predictions, 21st century challenges, how other nations are readying to face. IOT, sensor developments are instrumental for eScience or data science.
The document discusses the status of technical education in India and proposes ways to improve it for the 21st century. It notes that over 50% of engineering college faculty are recent graduates who see teaching as temporary until they find industry jobs. This results in a lack of experienced teachers and motivation for students. It suggests universities provide refresher courses and teaching methodology training to help recent graduate faculty before they teach. Engaging recent graduates as teaching assistants first could also better prepare them to teach on their own.
This document discusses the need to improve culture at AITAM. It questions who the students, teachers, parents, and management currently are, and what characteristics they should have. The speaker notes issues like students not understanding basic math, going to toilets as a group, and teachers solely focusing on JNTU syllabus. It provides characteristics of great teachers as being prepared, engaging students, caring about them, and communicating with parents. Overall, the speaker calls for stakeholders to work on defining, creating, and continuing a better culture at AITAM.
This presentation is used in a refresher course at Nuzvid. This is one day session of the course. It introduces research avenues in Image Processing and allied areas to faculty participants..
This document provides an overview of digital image processing (DIP) and discusses various topics related to it. It begins with welcoming remarks and introductions. It then discusses key areas of application for image processing like optical character recognition, security, compression, and medical imaging. Some main techniques covered include image acquisition, pre-processing, enhancement, segmentation, feature extraction, classification, and understanding. Application areas like remote sensing, astronomy, security, and OCR are also summarized. The document provides examples and illustrations of different image processing concepts.
This presentation is used in many places including Ambedkar Institute of Technology, Banglore. I was engaging more than 60 faculty members for 5 full days. Both tutorials and hands on training. This presentation explains Unix Internals, Socket programming, both data gram based and IP based concepts are explained with live examples.
This talk is developed to address a refresher course at Yanam for one full day. I have introduced the audience to clustering, both hierarchical and non-hierarchical. Clustering methods such as K-Means, K-Mediods, etc all introduced with live demonstrations.
This document provides an overview of writing OpenMP programs on multi-core machines. It discusses:
1) Why OpenMP is useful for parallel programming and its main components like compiler directives and library routines.
2) Elements of OpenMP like parallel regions, work sharing constructs, data scoping, and synchronization methods.
3) Achieving scalable speedup through techniques like breaking data dependencies, avoiding synchronization overheads, and improving data locality with cache and page placement.
This talk is given at Vizianagaram where many Engineering college faculty were attended. I have introduced developments in multi-core computers along with their architectural developments. Also, I have explained about high performance computing, where these are used. I have introduced the concept of pipelining, Amdahl's law, issues related to pipelining, MIPS architecture.
I have introduced developments in multi-core computers along with their architectural developments. Also, I have explained about high performance computing, where these are used. At the end, openMP is introduced with many ready to run parallel programs.
In this talk, I have explained about feature selection, extraction with emphasis to image processing. Methods such as Principal Component Analysis, Canonical ANalysis are explained with numerical examples.
Aim of this talk is to highlight the importance of statistics in the 21st century because of the availability of variety of sensors, MEMS, Nano-Sensors, E-sensors, IOT.
Tools & Techniques for Commissioning and Maintaining PV Systems W-Animations ...Transcat
Join us for this solutions-based webinar on the tools and techniques for commissioning and maintaining PV Systems. In this session, we'll review the process of building and maintaining a solar array, starting with installation and commissioning, then reviewing operations and maintenance of the system. This course will review insulation resistance testing, I-V curve testing, earth-bond continuity, ground resistance testing, performance tests, visual inspections, ground and arc fault testing procedures, and power quality analysis.
Fluke Solar Application Specialist Will White is presenting on this engaging topic:
Will has worked in the renewable energy industry since 2005, first as an installer for a small east coast solar integrator before adding sales, design, and project management to his skillset. In 2022, Will joined Fluke as a solar application specialist, where he supports their renewable energy testing equipment like IV-curve tracers, electrical meters, and thermal imaging cameras. Experienced in wind power, solar thermal, energy storage, and all scales of PV, Will has primarily focused on residential and small commercial systems. He is passionate about implementing high-quality, code-compliant installation techniques.
AI in customer support Use cases solutions development and implementation.pdfmahaffeycheryld
AI in customer support will integrate with emerging technologies such as augmented reality (AR) and virtual reality (VR) to enhance service delivery. AR-enabled smart glasses or VR environments will provide immersive support experiences, allowing customers to visualize solutions, receive step-by-step guidance, and interact with virtual support agents in real-time. These technologies will bridge the gap between physical and digital experiences, offering innovative ways to resolve issues, demonstrate products, and deliver personalized training and support.
https://www.leewayhertz.com/ai-in-customer-support/#How-does-AI-work-in-customer-support
Blood finder application project report (1).pdfKamal Acharya
Blood Finder is an emergency time app where a user can search for the blood banks as
well as the registered blood donors around Mumbai. This application also provide an
opportunity for the user of this application to become a registered donor for this user have
to enroll for the donor request from the application itself. If the admin wish to make user
a registered donor, with some of the formalities with the organization it can be done.
Specialization of this application is that the user will not have to register on sign-in for
searching the blood banks and blood donors it can be just done by installing the
application to the mobile.
The purpose of making this application is to save the user’s time for searching blood of
needed blood group during the time of the emergency.
This is an android application developed in Java and XML with the connectivity of
SQLite database. This application will provide most of basic functionality required for an
emergency time application. All the details of Blood banks and Blood donors are stored
in the database i.e. SQLite.
This application allowed the user to get all the information regarding blood banks and
blood donors such as Name, Number, Address, Blood Group, rather than searching it on
the different websites and wasting the precious time. This application is effective and
user friendly.
Open Channel Flow: fluid flow with a free surfaceIndrajeet sahu
Open Channel Flow: This topic focuses on fluid flow with a free surface, such as in rivers, canals, and drainage ditches. Key concepts include the classification of flow types (steady vs. unsteady, uniform vs. non-uniform), hydraulic radius, flow resistance, Manning's equation, critical flow conditions, and energy and momentum principles. It also covers flow measurement techniques, gradually varied flow analysis, and the design of open channels. Understanding these principles is vital for effective water resource management and engineering applications.
Supermarket Management System Project Report.pdfKamal Acharya
Supermarket management is a stand-alone J2EE using Eclipse Juno program.
This project contains all the necessary required information about maintaining
the supermarket billing system.
The core idea of this project to minimize the paper work and centralize the
data. Here all the communication is taken in secure manner. That is, in this
application the information will be stored in client itself. For further security the
data base is stored in the back-end oracle and so no intruders can access it.
This study Examines the Effectiveness of Talent Procurement through the Imple...DharmaBanothu
In the world with high technology and fast
forward mindset recruiters are walking/showing interest
towards E-Recruitment. Present most of the HRs of
many companies are choosing E-Recruitment as the best
choice for recruitment. E-Recruitment is being done
through many online platforms like Linkedin, Naukri,
Instagram , Facebook etc. Now with high technology E-
Recruitment has gone through next level by using
Artificial Intelligence too.
Key Words : Talent Management, Talent Acquisition , E-
Recruitment , Artificial Intelligence Introduction
Effectiveness of Talent Acquisition through E-
Recruitment in this topic we will discuss about 4important
and interlinked topics which are
A high-Speed Communication System is based on the Design of a Bi-NoC Router, ...DharmaBanothu
The Network on Chip (NoC) has emerged as an effective
solution for intercommunication infrastructure within System on
Chip (SoC) designs, overcoming the limitations of traditional
methods that face significant bottlenecks. However, the complexity
of NoC design presents numerous challenges related to
performance metrics such as scalability, latency, power
consumption, and signal integrity. This project addresses the
issues within the router's memory unit and proposes an enhanced
memory structure. To achieve efficient data transfer, FIFO buffers
are implemented in distributed RAM and virtual channels for
FPGA-based NoC. The project introduces advanced FIFO-based
memory units within the NoC router, assessing their performance
in a Bi-directional NoC (Bi-NoC) configuration. The primary
objective is to reduce the router's workload while enhancing the
FIFO internal structure. To further improve data transfer speed,
a Bi-NoC with a self-configurable intercommunication channel is
suggested. Simulation and synthesis results demonstrate
guaranteed throughput, predictable latency, and equitable
network access, showing significant improvement over previous
designs
Applications of artificial Intelligence in Mechanical Engineering.pdfAtif Razi
Historically, mechanical engineering has relied heavily on human expertise and empirical methods to solve complex problems. With the introduction of computer-aided design (CAD) and finite element analysis (FEA), the field took its first steps towards digitization. These tools allowed engineers to simulate and analyze mechanical systems with greater accuracy and efficiency. However, the sheer volume of data generated by modern engineering systems and the increasing complexity of these systems have necessitated more advanced analytical tools, paving the way for AI.
AI offers the capability to process vast amounts of data, identify patterns, and make predictions with a level of speed and accuracy unattainable by traditional methods. This has profound implications for mechanical engineering, enabling more efficient design processes, predictive maintenance strategies, and optimized manufacturing operations. AI-driven tools can learn from historical data, adapt to new information, and continuously improve their performance, making them invaluable in tackling the multifaceted challenges of modern mechanical engineering.
This presentation is about Food Delivery Systems and how they are developed using the Software Development Life Cycle (SDLC) and other methods. It explains the steps involved in creating a food delivery app, from planning and designing to testing and launching. The slide also covers different tools and technologies used to make these systems work efficiently.
Digital Twins Computer Networking Paper Presentation.pptxaryanpankaj78
A Digital Twin in computer networking is a virtual representation of a physical network, used to simulate, analyze, and optimize network performance and reliability. It leverages real-time data to enhance network management, predict issues, and improve decision-making processes.
3. A Small Dose of Questions To Know You
Little Briefing about Unix Internals
Recapitulation of What is Internet
Variety of Addresses involved
Socket Concepts
Related System Calls
Simple TCP Client and Server in action
Simple UDP Client and Server in action
What is DNS
4. What is the Difference between Data
Communications and Computer Networks?.
What is firmware?.
Why do we need to split a message?.
Why do we require so many levels of control?
(Is network system is reliable?)
What are physical and logical addresses?.
What is the conceptual difference between
DLL and NLL?.
5. What is fork()?
What is signal?
What is Process and Thread?
What is a device driver?.
What is a daemon?.
What is exec()
What are locks?.
6. A collection of
interconnected networks
Networks: Different depts,
labs, etc.
Router: node that connects
distinct networks
Host: network endpoints
(computer, PDA, light
switch, …)
Together, an independently
administered entity
◦ Enterprise, ISP, etc.
6
Internet[work]
EE ME
CS
7. Many differences
between networks
◦ Address formats
◦ Performance –
bandwidth/latency
◦ Packet size
◦ Loss
rate/pattern/handling
◦ Routing
How to translate
and inter-operate?
7
Internet[work]
802.3 Frame
relay
ATM
8. Internet vs. internet
The Internet: the interconnected set of
networks of the Internet Service Providers
(ISPs) and end-networks, providing data
communications services.
◦ Network of internetworks, and more
◦ About 17,000 different ISP networks make up the
Internet
◦ Many other “end” networks
◦ 100,000,000s of hosts
8
9. Links can be
◦ Wired or wireless
9
Node Link Node
14. Short bursts: buffer
Buffer sizes varies from network to network. So,
fragmentation takes places
What if buffer overflows?
◦ Packets dropped
◦ Sender adjusts rate until load = resources “congestion
control”
14
Problem: Network Overload
Solution: Buffering and Congestion Control
15. 15
Problem: Packet size
Solution: Fragment data across packets
• On Ethernet, max packet is 1.5KB
• Typical web page is 10KB
GETindex.html
GET index.html
16. Implements an
agreement between
parties on how
communication
should take place
16
Friendly greeting
Muttered reply
Destination?
Madison
Thank you
17. Each protocol offers interfaces
◦ One to higher-level protocols on the same end hosts
Expects one from the layers on which it builds
Interface characteristics, e.g. IP service model
◦ A “peer interface” to a counterpart on destinations
Syntax and semantics of communications
(Assumptions about) data formats
Protocols build upon each other
◦ Adds value, improves functionality overall
E.g., a reliable protocol running on top of IP
◦ Reuse, avoid re-writing
E.g., OS provides TCP, so apps don’t have to rewrite
17
18. Protocols are the key to interoperability.
◦ Networks are very heterogenous:
◦ The hardware/software of communicating parties are often
not built by the same vendor
◦ Yet they can communicate because they use the same
protocol
Actually implementations could be different
But must adhere to same specification
Protocols exist at many levels.
◦ Application level protocols
◦ Protocols at the hardware level
18
Ethernet: 3com, etc.
Routers: cisco, juniper etc.
App: Email, AIM, IE etc.
Hardware/link
Network
Application
19. One or more protocols implement the functionality
in a layer
◦ Only horizontal (among peers) and vertical (in a host)
communication
Protocols/layers can be implemented and modified
in isolation
Each layer offers a service to the higher layer, using
the services of the lower layer.
“Peer” layers on different systems communicate via
a protocol.
◦ higher level protocols (e.g. TCP/IP, Appletalk) can run on
multiple lower layers
◦ multiple higher level protocols can share a single physical
network
19
21. 21
FTP HTTP TFTPNV
TCP UDP
IP
NET1 NET2 NETn… Network protocols implemented by a
comb of hw and sw.
Interconnection of n/w technologies
into a single logical n/w
Two transport protocols: provide
logical channels to apps
App protocols
Note: No strict layering.
App writers can define apps that run on any lower level protocols.
22. 22
UDP TCP
Data Link
Physical
Applications
The Hourglass Model
Waist
The waist: minimal, carefully chosen functions.
Facilitates interoperability and rapid evolution
FTP HTTP TFTPNV
TCP UDP
IP
NET1 NET2 NETn…
25. Multiple choices at each layer
How to know which one to pick?
25
FTP HTTP TFTPNV
TCP UDP
IP
NET1 NET2 NETn…
TCP/UDPIP
Many
Networks
26. Multiple
implementations of each
layer
◦ How does the receiver
know what version/module
of a layer to use?
Packet header includes a
demultiplexing field
◦ Used to identify the right
module for next layer
◦ Filled in by the sender
◦ Used by the receiver
Multiplexing occurs at
multiple layers. E.g., IP,
TCP, …
26
IP
TCP
IP
TCP
V/HL TOS Length
ID Flags/Offset
TTL Prot. H. Checksum
Source IP address
Destination IP address
Options..
27. TCP
Reliable – guarantee
delivery
Byte stream – in-order
delivery
Checksum for validity
Setup connection followed
by data transfer
27
Telephone Call
• Guaranteed delivery
• In-order delivery
• Setup connection followed
by conversation
Example TCP applications
Web, Email, Telnet
28. 28
Example UDP applications
Multimedia, voice over IP
UDP
• No guarantee of delivery
• Not necessarily in-order
delivery
• No validity guaranteed
• Must address each
independent packet
Postal Mail
• Unreliable
• Not necessarily in-order
delivery
• Must address each reply
29. 29
no loss
no loss
no loss
loss-tolerant
loss-tolerant
loss-tolerant
no loss
elastic
elastic
elastic
audio: 5Kb-1Mb
video:10Kb-5Mb
same as above
few Kbps
elastic
no
no
no
yes, 100’s msec
yes, few secs
yes, 100’s msec
yes and no
file transfer
e-mail
web documents
real-time audio/
video
stored audio/video
interactive games
financial apps
Application Data loss Bandwidth Time Sensitive
30.
31. Byte Order
Different computers may have different internal representation
of 16 / 32-bit integer (called host byte order).
Examples
Big-Endian byte order (e.g., used by Motorola 68000):
Little-Endian byte order (e.g., used by Intel 80x86):
32. ◦ TCP/IP specifies a network byte order which is the big-
endian byte order.
◦ For some WinSock functions, their arguments (i.e., the
parameters to be passed to these functions) must be
stored in network byte order.
◦ WinSock provides functions to convert between host
byte order and network byte order:
32
33.
34.
35.
36. Processes
36
• A process has
text: machine instructions
(may be shared by other processes)
data
stack
• Process may execute either in user mode or in kernel
mode.
• Process information are stored in two places:
Process table
User table
37. User mode and Kernel mode
37
• At any given instant a computer running the Unix system
is either executing a process or the kernel itself is running
• The computer is in user mode when it is executing
instructions in a user process and it is in kernel mode
when it is executing instructions in the kernel.
• Executing System call ==> User mode to Kernel mode
perform I/O operations
system clock interrupt
38. Process Table
38
• Process table: an entry in process table has the following
information:
process state:
A. running in user mode or kernel mode
B. Ready in memory or Ready but swapped
C. Sleep in memory or sleep and swapped
PID: process id
UID: user id
scheduling information
signals that is sent to the process but not yet handled
a pointer to per-process-region table
• There is a single process table for the entire system
39. User Table (u area)
39
• Each process has only one private user table.
• User table contains information that must be accessible
while the process is in execution.
A pointer to the process table slot
parameters of the current system call, return values
error codes
file descriptors for all open files
current directory and current root
process and file size limits.
• User table is an extension of the process table.
41. Shared Program Text and
Software Libraries
41
• Many programs, such as shell, are often being
executed by several users simultaneously.
• The text (program) part can be shared.
• In order to be shared, a program must be compiled using
a special option that arranges the process image so that
the variable part(data and stack) and the fixed part (text)
are cleanly separated.
• An extension to the idea of sharing text is sharing
libraries.
• Without shared libraries, all the executing programs
contain their own copies.
43. System Call
43
• A process accesses system resources through system call.
• System call for
Process Control:
fork: create a new process
wait: allow a parent process to synchronize its
execution with the exit of a child process.
exec: invoke a new program.
exit: terminate process execution
File system:
File: open, read, write, lseek, close
inode: chdir, chown chmod, stat fstat
others: pipe dup, mount, unmount, link, unlink
44. System call: fork()
44
• fork: the only way for a user to create a process in Unix
operating system.
• The process that invokes fork is called parent process
and the newly created process is called child process.
• The syntax of fork system call:
newpid = fork();
• On return from fork system call, the two processes have
identical copies of their user-level context except for the
return value pid.
• In parent process, newpid = child process id
• In child process, newpid = 0;
45. 45
/* forkEx1.c */
#include <stdio.h>
main()
{
int fpid;
printf("Before forking ...n");
fpid = fork();
if (fpid == 0) {
printf("Child Process fpid=%dn", fpid);
} else {
printf("Parent Process fpid=%dn", fpid);
}
printf("After forking fpid=%dn", fpid);
}
$ cc forkEx1.c -o forkEx1
$ forkEx1
Before forking ...
Child Process fpid=0
After forking fpid=0
Parent Process fpid=14707
After forking fpid=14707
$
46. 46
/* forkEx2.c */
#include <stdio.h>
main()
{
int fpid;
printf("Before forking ...n");
system("ps");
fpid = fork();
system("ps");
printf("After forking
fpid=%dn", fpid);
}
$ forkEx2
Before forking ...
PID TTY TIME CMD
14759 pts/9 0:00 tcsh
14778 pts/9 0:00 sh
14777 pts/9 0:00 forkEx2
PID TTY TIME CMD
14781 pts/9 0:00 sh
14759 pts/9 0:00 tcsh
14782 pts/9 0:00 sh
14780 pts/9 0:00 forkEx2
14777 pts/9 0:00 forkEx2
After forking fpid=14780
$ PID TTY TIME CMD
14781 pts/9 0:00 sh
14759 pts/9 0:00 tcsh
14780 pts/9 0:00 forkEx2
After forking fpid=0
$ ps
PID TTY TIME CMD
14759 pts/9 0:00 tcsh
$
47. System Call: getpid() getppid()
47
• Each process has a unique process id (PID).
• PID is an integer, typically in the range 0 through 65535.
• Kernel assigns the PID when a new process is created.
• Processes can obtain their PID by calling getpid().
• Each process has a parent process and a corresponding
parent process ID.
• Processes can obtain their parent’s PID by calling
getppid().
53. 53
$ cc forkEx4.c -o forkEx4
$ forkEx4
Before forking ...
Parent Process fpid=14980 pid=14979 ppid=14759
Child Process fpid=0 pid=14980 ppid=14979
After forking fpid=0 pid=14980 ppid=14979
After forking fpid=14980 pid=14979 ppid=14759
$
54. System Call: exec()
54
• exec() system call invokes another program by replacing
the current process
• No new process table entry is created for exec() program.
Thus, the total number of processes in the system isn’t
changed.
• Six different exec functions:
execlp, execvp, execl, execv, execle, execve,
(see man page for more detail.)
• exec system call allows a process to choose its successor.
57. 57
/* execEx2.c */
#include <sys/types.h>
#include <unistd.h>
#include <stdio.h>
main()
{
int fpid;
printf("Before execing ...n");
fpid = fork();
if (fpid == 0) {
execl("/bin/date", "date", 0);
}
printf("After exec and fpid=%dn",fpid);
}
$ execEx2
Before execing ...
After exec and fpid=14903
$ Sun May 9 16:47:08 CST 1999
$
58. Handling Signal
58
• A signal is a message from one process to another.
• Signal are sometime called “software interrupt”
• Signals usually occur asynchronously.
• Signals can be sent
A. by one process to anther (or to itself)
B. by the kernel to a process.
• Unix signals are content-free. That is the only thing that
can be said about a signal is “it has arrived or not”
59. Handling Signal
59
• Most signals have predefined meanings:
A. sighup (HangUp): when a terminal is closed, the
hangup signal is sent to every process in control terminal.
B. sigint (interrupt): ask politely a process to terminate.
C. sigquit (quit): ask a process to terminate and produce a
codedump.
D. sigkill (kill): force a process to terminate.
• See signEx1.c
61. 61
$ cc sigEx1.c -o sigEx1
$ sigEx1 &
Before forking ...
Parent Process fpid=14989 pid=14988 ppid=14759
Child Process fpid=0 pid=14989 ppid=14988
$ ps
PID TTY TIME CMD
14988 pts/9 0:00 sigEx1
14759 pts/9 0:01 tcsh
14989 pts/9 0:09 sigEx1
$ kill -9 14989
$ ps
...
62. Scheduling Processes
62
• On a time sharing system, the kernel allocates the CPU to
a process for a period of time (time slice or time quantum)
preempts the process and schedules another one when
time slice expired, and reschedules the process to continue
execution at a later time.
• The scheduler use round-robin with multilevel feedback
algorithm to choose which process to be executed:
A. Kernel allocates the CPU to a process for a time slice.
B. preempts a process that exceeds its time slice.
C. feeds it back into one of the several priority queues.
63. Process Priority
63
swapper
wait for Disk IO
wait for buffer
wait for inode
...
wait for child exit
User level 0
User level 1
User level n
...
Kernel Mode
User Mode
ProcessesPriority Levels
64. Process Scheduling
(Unix System V)
64
• There are 3 processes A, B, C under the following
assumptions:
A. they are created simultaneously with initial priority 60.
B. the clock interrupt the system 60 times per second.
C. these processes make no system call.
D. No other process are ready to run
E. CPU usage calculation: CPU = decay(CPU) = CPU/2
F. Process priority calculation: priority = CPU/2 + 60.
G. Rescheduling Calculation is done once per second.
65. 65
Process A
Priority CPU count
Process B
Priority CPU count
Process C
Priority CPU count
60 0
…
60
75 30
67 15
63 7
…
67
76 33
60 0
60 0
…
60
75 30
67 15
63 7
...
60 0
60 0
60 0
…
60
75 30
67 15
1
2
3
4
0
66. Booting
66
• When the computer is powered on or rebooted, a short
built-in program (maybe store in ROM) reads the first
block or two of the disk into memory. These blocks
contain a loader program, which was placed on the disk
when disk is formatted.
• The loader is started. The loader searches the root
directory for /unix or /root/unix and load the file into
memory
• The kernel starts to execute.
67. The first processes
67
• The kernel initializes its internal data structures:
it constructs linked list of free inodes, regions, page table
• The kernel creates u area and initializes slot 0 of process
table
• Process 0 is created
• Process 0 forks, invoking the fork algorithm directly
from the Kernel. Process 1 is created.
• In kernel mode, Process 1 creates user-level context
(regions) and copy code (/etc/init) to the new region.
• Process 1 calls exec (executes init).
68. init process
68
• The init process is a process dispatcher:spawning
processes, allow users to login.
• Init reads /etc/inittab and spawns getty
• when a user login successfully, getty goes through a login
procedure and execs a login shell.
• Init executes the wait system call, monitoring the death
of its child processes and the death of orphaned processes
by exiting parent.
69. 69
Init fork/exec
a getty progrma
to manage the line
Getty prints
“login:” message and
waits for someone
to login
The login process
prints the
password message,
read the password
then check the password
The shell runs
programs for the
user unitl the
user logs off
When the shell
dies, init wakes up
and fork/exec a
getty for the line
70. File Subsystem
70
• A file system is a collection of files and directories on
a disk or tape in standard UNIX file system format.
• Each UNIX file system contains four major parts:
A. boot block:
B. superblock:
C. i-node table:
D. data block: file storage
71. File System Layout
71
Block 0: bootstrap
Block 1: superblock
Block 2
Block n
...
Block n+1
The last Block
...
Block 2 - n:i-nodes
Block n+1 - last:Files
72. Boot Block
72
• A boot block may contains several physical blocks.
• Note that a physical block contains 512 bytes
(or 1K or 2KB)
• A boot block contains a short loader program for
booting
• It is blank on other file systems.
73. Superblock
73
• Superblock contains key information about a file system
• Superblock information:
A. Size of a file system and status:
label: name of this file system
size: the number of logic blocks
date: the last modification date of super block.
B. information of i-nodes
the number of i-nodes
the number of free i-nodes
C. information of data block: free data blocks.
• The information of a superblock is loaded into memory.
74. I-nodes
74
• i-node: index node (information node)
• i-list: the list of i-nodes
• i-number: the index of i-list.
• The size of an i-node: 64 bytes.
• i-node 0 is reserved.
• i-node 1 is the root directory.
• i-node structure: next page
75. 75
I-node structure
mode
owner
timestamp
Size
Block count
Direct blocks
0-9
Double indirect
Triple indirect
Single indirect
Data block
Data block
Data block
Indirect block
...
Data block
Data block
Data block
...
Indirect block
Indirect block
Indirect block
...
Reference count
76. I-node structure
76
• mode: A. type: file, directory, pipe, symbolic link
B. Access: read/write/execute (owner, group,)
• owner: who own this I-node (file, directory, ...)
• timestamp: creation, modification, access time
• size: the number of bytes
• block count: the number of data blocks
• direct blocks: pointers to the data
• single indirect: pointer to a data block which
pointers to the data blocks (128 data blocks).
• Double indirect: (128*128=16384 data blocks)
• Triple indirect: (128*128*128 data blocks)
77. Data Block
77
• A data block has 512 bytes.
A. Some FS has 1K or 2k bytes per blocks.
B. See blocks size effect (next page)
• A data block may contains data of files or data of
a directory.
• File: a stream of bytes.
• Directory format:
i-# Next size File name pad
80. In-core inode table
80
• UNIX system keeps regular files and directories on block
devices such as disk or tape,
• Such disk space are called physical device address space.
• The kernel deals on a logical level with file system
(logical device address space) rather than with disks.
• Disk driver can transfer logical addresses into physical
device addresses.
• In-core (memory resident) inode table stores the
inode information in kernel space.
81. In-core inode table
81
• An in-core inode contains
A. all the information of inode in disks.
B. status of in-core inode
inode is locked,
inode data changed
file data changed.
C. the logic device number of the file system.
D. inode number
E. reference count
82. File table
82
• The kernel have a global data structure, called file table,
to store information of file access.
• Each entry in file table contains:
A. a pointer to in-core inode table
B. the offset of next read or write in the file
C. access rights (r/w) allowed to the opening process.
D. reference count.
83. User File Descriptor table
83
• Each process has a user file descriptor table to identify
all opened files.
• An entry in user file descriptor table pointer to an entry
of kernel’s global file table.
• Entry 0: standard input
• Entry 1: standard output
• Entry 2: error output
84. System Call: open
84
• open: A process may open a existing file to read or write
• syntax:
fd = open(pathname, mode);
A. pathname is the filename to be opened
B. mode: read/write
• Example
87. System Call: read
87
• read: A process may read an opened file
• syntax:
fd = read(fd, buffer, count);
A. fd: file descriptor
B. buffer: data to be stored in
C. count: the number (count) of byte
• Example
91. System Call: dup
91
• dup: copy a file descriptor into the first free slot of the
user file descriptor table.
• syntax:
newfd = dup(fd);
A. fd: file descriptor
Example
94. System Call: creat
94
• creat: A process may create a new file by creat system
call
• syntax:
fd = write(pathname, mode);
A. pathname: file name
B. mode: read/write
Example
95. System Call: close
95
• close: A process may close a file by close system
call
• syntax:
close(fd);
A. fd: file descriptor
Example
96. System Call: write
96
• write: A process may write data to an opened file
• syntax:
fd = write(fd, buffer, count);
A. fd: file descriptor
B. buffer: data to be stored in
C. count: the number (count) of byte
• Example
98. 98
$ cc creatEx1.c -o creatEx1
$ creatEx1
======
fd1=3 buf1=I am a string
======
$ ls -l testCreat.txt
-rw-rw-rw- 1 cheng staff 50 May 10 20:37 testCreat.txt
$ more testCreat.txt
...
99. System Call: stat/fstat
99
• stat/fstat: A process may query the status of a file (locked)
file type, file owner, access permission. file size, number
of links, inode number, access time.
• syntax:
stat(pathname, statbuffer); fstat(fd, statbuffer);
A. pathname: file name
B. statbuffer: read in data
C. fd: file descriptor
Example
102. System Call: link/unlink
102
• link: hardlink a file to another
• syntax:
link(sourceFile, targetFile); unlink(file)
A. sourceFile targetFile, file: file name
Example:
Lab exercise: write a c program which use link/unlink
system call. Use ls -l to see the reference count.
103. System Call: chdir
103
• chdir: A process may change the current directory
of a processl
• syntax:
chdir(pathname);
A. pathname: file name
Example
106. Signal Description
SIGABRT Process abort signal.
SIGALRM Alarm clock.
SIGFPE Erroneous arithmetic operation.
SIGHUP Hangup.
SIGILL Illegal instruction.
SIGINT Terminal interrupt signal.
SIGKILL Kill (cannot be caught or ignored).
SIGPIPE Write on a pipe with no one to read it.
SIGQUIT Terminal quit signal.
SIGSEGV Invalid memory reference.
SIGTERM Termination signal.
SIGUSR1 User-defined signal 1.
SIGUSR2 User-defined signal 2.
SIGCHLD Child process terminated or stopped.
SIGCONT Continue executing, if stopped.
SIGSTOP Stop executing (cannot be caught or ignored).
SIGTSTP Terminal stop signal.
SIGTTIN Background process attempting read.
SIGTTOU Background process attempting write.
SIGBUS Bus error.
SIGPOLL Pollable event.
SIGPROF Profiling timer expired.
SIGSYS Bad system call.
SIGTRAP Trace/breakpoint trap.
SIGURG High bandwidth data is available at a socket.
SIGVTALRM Virtual timer expired.
SIGXCPU CPU time limit exceeded.
SIGXFSZ File size limit exceeded.
108. #include <stdio.h> /* standard I/O functions */
#include <unistd.h> /* standard unix functions, like getpid() */
#include <sys/types.h> /* various type definitions, like pid_t */
#include <signal.h> /* signal name macros, and the signal() prototype */
/* first, here is the signal handler */
void catch_int(int sig_num)
{
/* re-set the signal handler again to catch_int, for next time */
signal(SIGINT, catch_int);
/* and print the message */
printf("Don't do that");
fflush(stdout);
}
/* and somewhere later in the code.... */
/* set the INT (Ctrl-C) signal handler to 'catch_int' */
signal(SIGINT, catch_int);
/* now, lets get into an infinite loop of doing nothing. */
for ( ;; )
pause();
}
109.
110. Signal sets
Signal sets are data types (structures) to represent multiple signals. The following functions
are used manipulate them.
int sigemptyset(sigset_t *set);
This function initializes the signal set pointed by set variable such that it contains no
signals in it.
int sigfillset(segset_t *set);
This function fills the signal set pointed by set variable such that it contains all signals in it.
int sigaddset(segset_t *set,int signo);
This function adds a signal (with signal number signo) to the signal set pointed by set
variable.
int sigdelset(segset_t *set,int signo);
This function removes a signal (with signal number signo) from the signal set pointed by set
variable.
int issigmember(segset_t *set,int signo);
This function checks a signal (with signal number signo) is in the signal set pointed by set
variable or not.
int sigpending(sigset_t *set);
This function returns the set of signals that are blocked from delivery and currently pending
to the signal set pointed by set variable.
int sigsuspend(sigset_t *set);
This function sets the signal mask of the process to the signal set pointed by set variable.
Also, the process is suspended until a
signal is caught or until a signal occurs that terminates the process.
112. struct sigaction{ void (*sa_handler)();
/*pointer to function or SIG_DFL or SIG_IGN*/
sigset_t sa_mask/ /*additional signal to be blocked during
execution of hander*/
int sa_flags; /*special flags and options*/}
113. #include <stdio.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/msg.h>
int main(int argc, char* argv[]){ /* create a private message queue, with access only to the owner. */
struct msgbuf* msg; struct msgbuf* recv_msg; int rc;
int queue_id = msgget(IPC_PRIVATE, 0600);
if (queue_id == -1) { perror("main: msgget"); exit(1); }
printf("message queue created, queue id '%d'.n", queue_id);
msg = (struct msgbuf*)malloc(sizeof(struct msgbuf)+strlen("hello world"));
msg->mtype = 1;
strcpy(msg->mtext, "hello world");
rc = msgsnd(queue_id, msg, strlen(msg->mtext)+1, 0);
if (rc == -1) { perror("main: msgsnd"); exit(1); }
free(msg);
printf("message placed on the queue successfully.n");
recv_msg = (struct msgbuf*)malloc(sizeof(struct msgbuf)+strlen("hello world"));
rc = msgrcv(queue_id, recv_msg, strlen("hello world")+1, 0, 0);
if (rc == -1) { perror("main: msgrcv"); exit(1); }
printf("msgrcv: received message: mtype '%d'; mtext '%s'n", recv_msg->mtype, recv_msg-
>mtext);
return 0;
117. 11
7
◦ Port numbers are used to identify
“entities” on a host
◦ Port numbers can be
Well-known (port 0-1023)
Dynamic or private (port 1024-65535)
◦ Servers/daemons usually use well-
known ports
Any client can identify the
server/service
HTTP = 80, FTP = 21, Telnet = 23, ...
/etc/service defines well-known ports
◦ Clients usually use dynamic ports
Assigned by the kernel at run time
TCP/UDP
IP
Ethernet Adapter
NTP
daemon
Web
server
port 123 port 80
118. Consider Railway Station
Counter 0: Platform
Tickets
Counter 1: Enquiries
Counter 2: Reservations
----
---
Counter 8: Current
Reservations
119. Each host machine has an IP address
When a packet arrives at a host
11
9
medellin.cs.columbia.edu
(128.59.21.14)
cluster.cs.columbia.edu
(128.59.21.14,
128.59.16.7, 128.59.16.5,
128.59.16.4)
newworld.cs.umass.edu
(128.119.245.93)
120. Transfer file to/from remote host
Client/server model
◦ Client: side that initiates transfer (either to/from remote)
◦ Server: remote host
ftp: RFC 959
ftp server: port 21
file transfer
FTP
server
FTP
user
interface
FTP
client
local file
system
remote file
system
user
at host
121. Ftp client contacts ftp server
at port 21, specifying TCP as
transport protocol
Two parallel TCP connections
opened:
◦ Control: exchange
commands, responses
between client, server.
“out of band control”
◦ Data: file data to/from server
FTP
client
FTP
server
TCP control connection
port 21
TCP data connection
port 20
122. The interface that the OS provides to its
networking subsystem
application layer
transport layer (TCP/UDP)
network layer (IP)
link layer (e.g. ethernet)
physical layer
application layer
transport layer (TCP/UDP)
network layer (IP)
link layer (e.g. ethernet)
physical layer
OS network
stack
Sockets as means for inter-process
communication (IPC)
Client Process Server Process
Socket
OS network
stack
Socket
Internet
Internet
Internet
123. Address the machine on the network
◦ By IP address
Address the process
◦ By the “port”-number
The pair of IP-address + port – makes up a “socket-address”
Connection socket pair
(128.2.194.242:3479, 208.216.181.15:80)
Server
(port 80)
Client
Client socket address
128.2.194.242:3479
Server socket address
208.216.181.15:80
Client host address
128.2.194.242
Server host address
208.216.181.15
Note: 3479 is an
ephemeral port allocated
by the kernel
Note: 80 is a well-known port
associated with Web servers
124. Examples of client programs
◦ Web browsers, ftp, telnet, ssh
How does a client find the server?
◦ The IP address in the server socket address identifies the
host
◦ The (well-known) port in the server socket address
identifies the service, and thus implicitly identifies the
server process that performs that service.
◦ Examples of well known ports
Port 7: Echo server
Port 23: Telnet server
Port 25: Mail server
Port 80: Web server
125. Web server
(port 80)
Client host
Server host 128.2.194.242
Echo server
(port 7)
Service request for
128.2.194.242:80
(i.e., the Web server)
Web server
(port 80)
Echo server
(port 7)
Service request for
128.2.194.242:7
(i.e., the echo server)
Kernel
Kernel
Client
Client
126. Servers are long-running processes
(daemons).
◦ Created at boot-time (typically) by the init process
(process 1)
◦ Run continuously until the machine is turned off.
Each server waits for requests to arrive on a
well-known port associated with a particular
service.
◦ Port 7: echo server
◦ Port 23: telnet server
◦ Port 25: mail server
◦ Port 80: HTTP server
Other applications should choose between 1024 and
65535
See /etc/services for a
comprehensive list of the
services available on a
Linux machine.
127. What is a socket?
◦ To the kernel, a socket is an endpoint of communication.
◦ To an application, a socket is a file descriptor that lets the
application read/write from/to the network.
Remember: All Unix I/O devices, including networks, are
modeled as files.
Clients and servers communicate with each by
reading from and writing to socket descriptors.
The main distinction between regular file I/O and
socket I/O is how the application “opens” the
socket descriptors.
128. Endpoint Address
◦ Generic Endpoint Address
The socket abstraction accommodates many protocol
families.
It supports many address families.
It defines the following generic endpoint address:
( address family, endpoint address in that family )
Data type for generic endpoint address:
◦ TCP/IP Endpoint Address
For TCP/IP, an endpoint address is composed of the
following items:
Address family is AF_INET (Address Family for InterNET).
Endpoint address in that family is composed of an IP
address and a port number.
12
8
129. The IP address identifies a particular computer, while the
port number identifies a particular application running on
that computer.
The TCP/IP endpoint address is a special instance of the
generic one:
Port Number
A port number identifies an application running on a
computer.
When a client program is executed, WinSock randomly
chooses an unused port number for it.
Each server program must have a pre-specified port
number, so that the client can contact the server.
12
9
130. The port number is composed of 16 bits, and its possible
values are used in the following manner:
0 - 1023: For well-known server applications.
1024 - 49151: For user-defined server applications
(typical range to be used is 1024 - 5000).
49152 - 65535: For client programs.
Port numbers for some well-known server applications:
WWW server using TCP: 80
Telnet server using TCP: 23
SMTP (email) server using TCP: 25
SNMP server using UDP: 161.
13
0
131. 131
Unix File Descriptor Table
Descriptor Table
0
1
2
3
4
Data structure for file 0
Data structure for file 1
Data structure for file 2
Standard input
Standard output
Standard error
132. 132
Socket Descriptor Data Structure
Descriptor Table
0
1
2
3
4
Family: PF_INET
Service: SOCK_STREAM
Local IP: 111.22.3.4
Remote IP: 123.45.6.78
Local Port: 2249
Remote Port: 3726
133. Hierarchical vs. flat
◦ Wisconsin / Madison / UW-Campus / Aditya
vs.
Aditya:123-45-6789
◦ Ethernet addresses are flat
What information would routers need to route to Ethernet
addresses?
◦ Hierarchical structure crucial for designing scalable binding from interface
name to route
◦ Route to a general area, then to a specific location
What type of Hierarchy?
◦ How many levels?
◦ Same hierarchy depth for everyone?
Address broken in segments of increasing specificity
◦ Uniform for everybody: needs centralized management
◦ Non-uniform: more flexible, needs careful decentralized management
13
3
134. Fixed length: 32 bits
Total IP address size: 4 billion
Initial class-ful structure (1981)
◦ Class A: 128 networks, 16M hosts
◦ Class B: 16K networks, 64K hosts
◦ Class C: 2M networks, 256 hosts
134
135. 13
5
Network ID Host ID
Network ID Host ID
8 16
Class A
32
0
Class B 10
Class C 110
Multicast AddressesClass D 1110
Reserved for experimentsClass E 1111
24
136. Address would specify prefix for forwarding table
◦ Simple lookup
www.cmu.edu address 128.2.11.43
◦ Class B address – class + network is 128.2
◦ Lookup 128.2 in forwarding table
◦ Prefix – part of address that really matters for routing
Forwarding table contains
◦ List of class+network entries
◦ A few fixed prefix lengths (8/16/24)
Large tables
◦ 2 Million class C networks
13
6
137. Original goal: network part would uniquely identify
a single physical network
Inefficient address space usage
◦ Class A & B networks too big
Also, very few LANs have close to 64K hosts
Easy for networks to (claim to) outgrow class-C
◦ Each physical network must have one network number
Routing table size is too high
Need simple way to reduce the number of network
numbers assigned
◦ Subnetting: Split up single network address ranges
◦ Fizes routing table size problem, partially
137
138. Add another “floating” layer to hierarchy
Variable length subnet masks
◦ Could subnet a class B into several chunks
13
8
Network Host
Network HostSubnet
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 10 0 0 0 0 0 0 0
Subnet
Mask
139. Assume an organization was assigned
address 150.100 (class B)
Assume < 100 hosts per subnet
(department)
How many host bits do we need?
◦ Seven
What is the network mask?
◦ 11111111 11111111 11111111 10000000
◦ 255.255.255.128
13
9
140. 14
0
• Host configured with IP adress and subnet
mask
• Subnet number = IP (AND) Mask
• (Subnet number, subnet mask) Outgoing
I/F
D = destination IP address
For each forwarding table entry (SN, SM OI)
D1 = SM & D
if (D1 == SN)
Deliver on OI
Else
Forward to default router
141. Address space depletion
◦ In danger of running out of classes A and B
◦ Why?
Class C too small for most domains
Very few class A – very careful about giving them out
Class B poses greatest problem
◦ Class B sparsely populated
But people refuse to give it back
14
1
142. Allows arbitrary split between network & host part
of address
◦ Do not use classes to determine network ID
◦ Use common part of address as network number
◦ Allows handing out arbitrary sized chunks of address space
◦ E.g., addresses 192.4.16 - 192.4.31 have the first 20 bits in
common. Thus, we use these 20 bits as the network number
192.4.16/20
Enables more efficient usage of address space (and
router tables)
◦ Use single entry for range in forwarding tables
◦ Combine forwarding entries when possible
14
2
143. Network is allocated 8 contiguous chunks
of 256-host addresses 200.10.0.0 to
200.10.7.255
◦ Allocation uses 3 bits of class C space
◦ Remaining 20 bits are network number, written
as 201.10.0.0/21
Replaces 8 class C routing entries with 1
combined entry
◦ Routing protocols carry prefix with destination
network address
14
3
145. How does an ISP get block of addresses?
◦ From Regional Internet Registries (RIRs)
ARIN (North America, Southern Africa), APNIC (Asia-
Pacific), RIPE (Europe, Northern Africa), LACNIC (South
America)
How about a single host?
◦ Hard-coded by system admin in a file
◦ DHCP: Dynamic Host Configuration Protocol:
dynamically get address: “plug-and-play”
Host broadcasts “DHCP discover” msg
DHCP server responds with “DHCP offer” msg
Host requests IP address: “DHCP request” msg
DHCP server sends address: “DHCP ack” msg
14
5
146. 14
6
Provider is given 201.10.0.0/21
201.10.0.0/22 201.10.4.0/24 201.10.5.0/24 201.10.6.0/23
Provider
CIDR implications:
Longest prefix match
Route aggregation
150. Routing Gets Packet to Correct Local Network
◦ Based on IP address
◦ Router sees that destination address is of local machine
Still Need to Get Packet to Host
◦ Using link-layer protocol
◦ Need to know hardware address
Same Issue for Any Local Communication
◦ Find local machine, given its IP address
15
0
host host host
LAN 1
...
router
WAN
128.2.198.222
128.2.254.36
Destination = 128.2.198.222
151. ◦ Diagrammed for Ethernet (6-byte MAC addresses)
Low-Level Protocol
◦ Operates only within local network
◦ Determines mapping from IP address to hardware (MAC)
address
◦ Mapping determined dynamically
No need to statically configure tables
Only requirement is that each host know its own IP address
15
1
op
Sender MAC address
Sender IP Address
Target MAC address
Target IP Address
• op: Operation
– 1: request
– 2: reply
• Sender
– Host sending ARP
message
• Target
– Intended receiver of
message
152. Requestor
◦ Fills in own IP and MAC address as “sender”
Why include its MAC address?
Mapping
◦ Fills desired host IP address in target IP address
Sending
◦ Send to MAC address ff:ff:ff:ff:ff:ff
Ethernet broadcast
15
2
op
Sender MAC address
Sender IP Address
Target MAC address
Target IP Address
• op: Operation
– 1: request
• Sender
– Host that wants to
determine MAC address
of another machine
• Target
– Other machine
153. Responder becomes “sender”
◦ Fill in own IP and MAC address
◦ Set requestor as target
◦ Send to requestor’s MAC address
15
3
op
Sender MAC address
Sender IP Address
Target MAC address
Target IP Address
• op: Operation
– 2: reply
• Sender
– Host with desired IP
address
• Target
– Original requestor
154. Host 128.2.209.100 when plugged into CS ethernet
Dest 128.2.209.100 routing to same machine
Dest 128.2.0.0 other hosts on same ethernet
Dest 127.0.0.0 special loopback address
Dest 0.0.0.0 default route to rest of Internet
◦ Main CS router: gigrouter.net.cs.cmu.edu (128.2.254.36)
15
4
Destination Gateway Genmask Iface
128.2.209.100 0.0.0.0 255.255.255.255 eth0
128.2.0.0 0.0.0.0 255.255.0.0 eth0
127.0.0.0 0.0.0.0 255.0.0.0 lo
0.0.0.0 128.2.254.36 0.0.0.0 eth0
155.
156. IP address, netmask, gateway, hostname, etc., etc.
◦ Type by hand!!!
IPv4 option 1: RARP (Reverse ARP)
◦ Data-link protocol
Uses ARP format. New opcodes: “Request reverse”, “reply reverse”
◦ Send query: Request-reverse [ether addr], server responds with IP
Used primarily by diskless nodes, when they first initialize, to
find their Internet address
IPv4 option 2: DHCP
◦ Dynamic Host Configuration Protocol
◦ ARP is fine for assigning an IP, but is very limited
◦ DHCP can provide all the info necessary
157. DHCPOFFER
◦ IP addressing information
◦ Boot file/server information (for network booting)
◦ DNS name servers
◦ Lots of other stuff - protocol is extensible; half of the options
reserved for local site definition and use.
DHCPDISCOVER - broadcast
DHCPOFFER
DHCPREQUEST
DHCPACK
158. Lease-based assignment
◦ Clients can renew: Servers really should preserve this
information across client & server reboots.
Provide host configuration information
◦ Not just IP address stuff.
◦ NTP servers, IP config, link layer config,…
Use:
◦ Generic config for desktops/dial-in/etc.
Assign IP address/etc., from pool
◦ Specific config for particular machines
Central configuration management
159. Network Layer
4-
15
9
Goal: allow host to dynamically obtain its IP address from
network server when it joins network
Can renew its lease on address in use
Allows reuse of addresses (only hold address while connected an
“on”)
Support for mobile users who want to join network (more shortly)
DHCP overview:
◦ host broadcasts “DHCP discover” msg [optional]
◦ DHCP server responds with “DHCP offer” msg [optional]
◦ host requests IP address: “DHCP request” msg
◦ DHCP server sends address: “DHCP ack” msg
162. DHCP: more than IP address
DHCP can return more than just allocated IP
address on subnet:
address of first-hop router for client
name and IP address of DNS sever
network mask (indicating network versus host
portion of address)
163. DHCP: example
connecting laptop needs its
IP address, addr of first-
hop router, addr of DNS
server: use DHCP
router
(runs DHCP)
DHCP
UDP
IP
Eth
Phy
DHCP
DHCP
DHCP
DHCP
DHCP
DHCP
UDP
IP
Eth
Phy
DHCP
DHCP
DHCP
DHCPDHCP
DHCP request encapsulated
in UDP, encapsulated in IP,
encapsulated in 802.1
Ethernet
Ethernet frame broadcast
(dest: FFFFFFFFFFFF) on LAN,
received at router running
DHCP server
Ethernet demux’ed to IP
demux’ed, UDP demux’ed to
DHCP
168.1.1.1
164. DCP server formulates
DHCP ACK containing
client’s IP address, IP
address of first-hop
router for client, name &
IP address of DNS server
router
(runs DHCP)
DHCP
UDP
IP
Eth
Phy
DHCP
DHCP
DHCP
DHCP
DHCP
UDP
IP
Eth
Phy
DHCP
DHCP
DHCP
DHCP
DHCP
encapsulation of DHCP
server, frame forwarded
to client, demux’ing up to
DHCP at client
client now knows its IP
address, name and IP
address of DSN server, IP
address of its first-hop
router
DHCP: example
165. DHCP: wireshark
output (home LAN)
Message type: Boot Reply (2)
Hardware type: Ethernet
Hardware address length: 6
Hops: 0
Transaction ID: 0x6b3a11b7
Seconds elapsed: 0
Bootp flags: 0x0000 (Unicast)
Client IP address: 192.168.1.101 (192.168.1.101)
Your (client) IP address: 0.0.0.0 (0.0.0.0)
Next server IP address: 192.168.1.1 (192.168.1.1)
Relay agent IP address: 0.0.0.0 (0.0.0.0)
Client MAC address: Wistron_23:68:8a (00:16:d3:23:68:8a)
Server host name not given
Boot file name not given
Magic cookie: (OK)
Option: (t=53,l=1) DHCP Message Type = DHCP ACK
Option: (t=54,l=4) Server Identifier = 192.168.1.1
Option: (t=1,l=4) Subnet Mask = 255.255.255.0
Option: (t=3,l=4) Router = 192.168.1.1
Option: (6) Domain Name Server
Length: 12; Value: 445747E2445749F244574092;
IP Address: 68.87.71.226;
IP Address: 68.87.73.242;
IP Address: 68.87.64.146
Option: (t=15,l=20) Domain Name = "hsd1.ma.comcast.net."
reply
Message type: Boot Request (1)
Hardware type: Ethernet
Hardware address length: 6
Hops: 0
Transaction ID: 0x6b3a11b7
Seconds elapsed: 0
Bootp flags: 0x0000 (Unicast)
Client IP address: 0.0.0.0 (0.0.0.0)
Your (client) IP address: 0.0.0.0 (0.0.0.0)
Next server IP address: 0.0.0.0 (0.0.0.0)
Relay agent IP address: 0.0.0.0 (0.0.0.0)
Client MAC address: Wistron_23:68:8a (00:16:d3:23:68:8a)
Server host name not given
Boot file name not given
Magic cookie: (OK)
Option: (t=53,l=1) DHCP Message Type = DHCP Request
Option: (61) Client identifier
Length: 7; Value: 010016D323688A;
Hardware type: Ethernet
Client MAC address: Wistron_23:68:8a (00:16:d3:23:68:8a)
Option: (t=50,l=4) Requested IP Address = 192.168.1.101
Option: (t=12,l=5) Host Name = "nomad"
Option: (55) Parameter Request List
Length: 11; Value: 010F03062C2E2F1F21F92B
1 = Subnet Mask; 15 = Domain Name
3 = Router; 6 = Domain Name Server
44 = NetBIOS over TCP/IP Name Server
……
request
166. Serverless (“Stateless”). No manual config at all.
◦ Only configures addressing items, NOT other host things
Use DHCP for such things
Link-local address
◦ 1111 1110 10 :: 64 bit interface ID (usually from Ethernet
addr)
(fe80::/64 prefix)
◦ Uniqueness test (“anyone using this address?”)
◦ Router contact (solicit, or wait for announcement)
Contains globally unique prefix
Usually: Concatenate this prefix with local ID -> globally
unique IPv6 ID
168. Need naming to identify resources
Once identified, resource must be located
How to name resource?
◦ Naming hierarchy
How do we efficiently locate resources?
◦ DNS: name location (IP address)
Challenge: How do we scale these to the
wide area?
16
8
169. Lookup a Central DNS?
Single point of failure
Traffic volume
Distant centralized database
Single point of update
Doesn’t scale!
16
9
170. Why not use /etc/hosts?
Original Name to Address Mapping
◦ Flat namespace
◦ Lookup mapping in /etc/hosts
◦ Downloaded regularly
Count of hosts was increasing: machine per
domain machine per user
◦ Many more downloads
◦ Many more updates
17
0
171. Basically a wide-area distributed database of
name to IP mappings
Goals:
◦ Scalability
◦ Decentralized maintenance
◦ Robustness
◦ Global scope
Names mean the same thing everywhere
◦ Don’t need
Atomicity
Strong consistency
17
1
172. Conceptually, programmers can view the
DNS database as a collection of millions of
host entry structures:
◦ in_addr is a struct consisting of 4-byte IP address
Functions for retrieving host entries from
DNS:
◦ gethostbyname: query key is a DNS host name.
◦ gethostbyaddr: query key is an IP address.
17
2
/* DNS host entry structure */
struct hostent {
char *h_name; /* official domain name of host */
char **h_aliases; /* null-terminated array of domain names */
int h_addrtype; /* host address type (AF_INET) */
int h_length; /* length of an address, in bytes */
char **h_addr_list; /* null-terminated array of in_addr structs */
};
173. 17
3
Identification
No. of Questions
No. of Authority RRs
Questions (variable number of answers)
Answers (variable number of resource records)
Authority (variable number of resource records)
Additional Info (variable number of resource records)
Flags
No. of Answer RRs
No. of Additional RRs
Name, type fields
for a query
RRs in response
to query
Records for
authoritative
servers
Additional
“helpful info that
may be used
12 bytes
174. Identification
◦ Used to match up request/response
Flags
◦ 1-bit to mark query or response
◦ 1-bit to mark authoritative or not
◦ 1-bit to request recursive resolution
◦ 1-bit to indicate support for recursive resolution
17
4
175. FOR IN class:
Type=A
◦ name is hostname
◦ value is IP address
Type=NS
◦ name is domain (e.g. foo.com)
◦ value is name of authoritative
name server for this domain
17
5
RR format: (class, name, value, type, ttl)
• DB contains tuples called resource records (RRs)
– Classes = Internet (IN), Chaosnet (CH), etc.
– Each class defines value associated with type
• Type=CNAME
– name is an alias name for
some “canonical” (the real)
name
– value is canonical name
• Type=MX
– value is hostname of
mailserver associated with
name
176. Different kinds of mappings are possible:
◦ Simple case: 1-1 mapping between domain name and IP
addr:
kittyhawk.cmcl.cs.cmu.edu maps to 128.2.194.242
◦ Multiple domain names maps to the same IP address:
eecs.mit.edu and cs.mit.edu both map to 18.62.1.6
◦ Single domain name maps to multiple IP addresses:
aol.com and www.aol.com map to multiple IP addrs.
◦ Some valid domain names don’t map to any IP address:
for example: cs.wisc.edu
17
6
177. 17
7
root (.)
edunet
org
ukcom
gwu ucb wisc cmu mit
cs ee
wail
• Each node in hierarchy
stores a list of names that
end with same suffix
• Suffix = path up tree
• E.g., given this tree, where
would following be stored:
• Fred.com
• Fred.edu
• Fred.wisc.edu
• Fred.cs.wisc.edu
• Fred.cs.cmu.edu
178. 17
8
root
edunet
org
ukcom
ca
gwu ucb cmu bu mit
cs ece
cmcl
Single node
Subtree
Complete
Tree
• Zone = contiguous section
of name space
• E.g., Complete tree, single
node or subtree
• A zone has an associated
set of name servers
• Must store list of names
and tree links
179. Zones are created by convincing owner
node to create/delegate a subzone
◦ Records within zone store multiple redundant
name servers
◦ Primary/master name server updated manually
◦ Secondary/redundant servers updated by zone
transfer of name space
Zone transfer is a bulk transfer of the “configuration” of a
DNS server – uses TCP to ensure reliability
Example:
◦ CS.WISC.EDU created by WISC.EDU administrators
◦ Who creates WISC.EDU or .EDU?
17
9
180. Responsible for
“root” zone
Approx. 13 root
name servers
worldwide
◦ Currently {a-
m}.root-servers.net
Local name servers
contact root servers
when they cannot
resolve a name
◦ Configured with
well-known root
servers
18
0
181. Each host has a resolver
◦ Typically a library that applications can link to
◦ Resolves contacts name server
◦ Local name servers hand-configured (e.g.
/etc/resolv.conf)
Name servers
◦ Either responsible for some zone or…
◦ Local servers
Do lookup of distant host names for local hosts
Typically answer queries about local zone
18
1
182. Steps for resolving www.wisc.edu
◦ Application calls gethostbyname() (RESOLVER)
◦ Resolver contacts local name server (S1)
◦ S1 queries root server (S2) for (www.wisc.edu)
◦ S2 returns NS record for wisc.edu (S3)
◦ What about A record for S3?
This is what the additional information section is for
(PREFETCHING)
◦ S1 queries S3 for www.wisc.edu
◦ S3 returns A record for www.wisc.edu
Can return multiple A records what does this
mean?
18
2
183. Recursive query:
Server goes out and
searches for more info
(recursive)
Only returns final
answer or “not found”
Iterative query:
Server responds with as
much as it knows
(iterative)
“I don’t know this name,
but ask this server”
Workload impact on
choice?
Local server typically
does recursive
Root/distant server
does iterative
18
3
requesting host
surf.eurecom.fr
gaia.cs.umass.edu
root name server
local name server
dns.eurecom.fr
1
2
3
4
5 6authoritative name
server
dns.cs.umass.edu
intermediate name server
dns.umass.edu
7
8
iterated query
184. Are all servers/names likely to be equally popular?
◦ Why might this be a problem? How can we solve this problem?
DNS responses are cached
◦ Quick response for repeated translations
◦ Other queries may reuse some parts of lookup
NS records for domains
DNS negative queries are cached
◦ Don’t have to repeat past mistakes
◦ E.g. misspellings, search strings in resolv.conf
Cached data periodically times out
◦ Lifetime (TTL) of data controlled by owner of data
◦ TTL passed with every record
18
4
187. DNS servers are replicated
◦ Name service available if ≥ one replica is up
◦ Queries can be load balanced between replicas
UDP used for queries
◦ Need reliability must implement this on top of UDP!
◦ Why not just use TCP?
Try alternate servers on timeout
◦ Exponential backoff when retrying same server
Same identifier for all queries
◦ Don’t care which server responds
18
7
188. Task
◦ Given IP address, find its name
◦ When is this needed?
Method
◦ Maintain separate hierarchy based
on IP names
◦ Write 128.2.194.242 as
242.194.2.128.in-addr.arpa
Why is the address reversed?
Managing
◦ Authority manages IP addresses
assigned to it
◦ E.g., CMU manages name space
2.128.in-addr.arpa
18
8
edu
cmu
cs
kittyhawk
128.2.194.242
cmcl
unnamed root
arpa
in-addr
128
2
194
242
189. Name servers can add additional data to
response
Typically used for prefetching
◦ CNAME/MX/NS typically point to another host name
◦ Responses include address of host referred to in
“additional section”
18
9
190. Generic Top Level Domains (gTLD) = .com,
.net, .org, etc…
Country Code Top Level Domain (ccTLD) =
.us, .ca, .fi, .uk, etc…
Root server ({a-m}.root-servers.net) also
used to cover gTLD domains
◦ Load on root servers was growing quickly!
◦ Moving .com, .net, .org off root servers was
clearly necessary to reduce load done Aug
2000
19
0
191. .info general info
.biz businesses
.aero air-transport industry
.coop business cooperatives
.name individuals
.pro accountants, lawyers, and physicians
.museum museums
Only new one actives so far = .info, .biz,
.name
19
1
192. No centralized caching per site
◦ Each machine runs own caching local server
◦ Why is this a problem?
◦ How many hosts do we need to share cache? recent studies suggest
10-20 hosts
Hit rate for DNS = 80% 1 - (#DNS/#connections)
◦ Is this good or bad?
Most Internet traffic is Web
◦ What does a typical page look like? average of 4-5 imbedded
objects needs 4-5 transfers
◦ This alone accounts for 80% hit rate!
Lower TTLs for A records does not affect performance
DNS performance really relies more on NS-record caching
19
2
193.
194. Socket API
introduced in BSD4.1 UNIX,
1981
explicitly created, used,
released by apps
client/server paradigm
two types of transport
service via socket API:
◦ unreliable datagram
◦ reliable, byte stream-
oriented
19
4
a host-local,
application-created,
OS-controlled interface
(a “door”) into which
application process can
both send and
receive messages
to/from another
application process
socket
Goal: learn how to build client/server application that communicate
using sockets
196. Socket: a door between application process and
end-end-transport protocol (UDP or TCP)
TCP service: reliable transfer of bytes from one
process to another
19
6
process
TCP with
buffers,
variables
socket
controlled by
application
developer
controlled by
operating
system
host or
server
process
TCP with
buffers,
variables
socket
controlled by
application
developer
controlled by
operating
system
host or
server
internet
197. Client must contact server
server process must first
be running
server must have created
socket (door) that
welcomes client’s contact
Client contacts server by:
creating client-local TCP
socket
specifying IP address, port
number of server process
When client creates socket:
client TCP establishes
connection to server TCP
When contacted by client,
server TCP creates new
socket for server process to
communicate with client
◦ allows server to talk with
multiple clients
◦ source port numbers used
to distinguish clients
(more in Chap 3)
19
7
TCP provides reliable, in-order
transfer of bytes (“pipe”)
between client and server
application viewpoint
198. A stream is a sequence of
characters that flow into or
out of a process.
An input stream is attached
to some input source for
the process, eg, keyboard
or socket.
An output stream is
attached to an output
source, eg, monitor or
socket.
19
8
199. Example client-server
app:
1) client reads line from
standard input (inFromUser
stream) , sends to server via
socket (outToServer
stream)
2) server reads line from
socket
3) server converts line to
uppercase, sends back to
client
4) client reads, prints
modified line from socket
(inFromServer stream)
19
9
outToServer
to network from network
inFromServer
inFromUser
keyboard monitor
Process
clientSocket
input
stream
input
stream
output
stream
TCP
socket
Client
process
client TCP
socket
200. 20
0
wait for incoming
connection request
connectionSocket =
welcomeSocket.accept()
create socket,
port=x, for
incoming request:
welcomeSocket =
ServerSocket()
create socket,
connect to hostid, port=x
clientSocket =
Socket()
close
connectionSocket
read reply from
clientSocket
close
clientSocket
Server (running on hostid) Client
send request using
clientSocketread request from
connectionSocket
write reply to
connectionSocket
TCP
connection setup
201. UDP: no “connection” between
client and server
no handshaking
sender explicitly attaches IP
address and port of
destination to each packet
server must extract IP
address, port of sender
from received packet
UDP: transmitted data may be
received out of order, or
lost
20
1
application viewpoint
UDP provides unreliable transfer
of groups of bytes (“datagrams”)
between client and server
202. 20
2
close
clientSocket
Server (running on hostid)
read reply from
clientSocket
create socket,
clientSocket =
DatagramSocket()
Client
Create, address (hostid, port=x,
send datagram request
using clientSocket
create socket,
port=x, for
incoming request:
serverSocket =
DatagramSocket()
read request from
serverSocket
write reply to
serverSocket
specifying client
host address,
port number
203. 20
3
sendPacket
to network from network
receivePacket
inFromUser
keyboard monitor
Process
clientSocket
UDP
packet
input
stream
UDP
packet
UDP
socket
Output: sends
packet (TCP sent
“byte stream”)
Input: receives
packet (TCP
received “byte
stream”)
Client
process
client UDP
socket
204. This contains the protocol specific addressing
information that is passed from the user
process to the kernel and vice versa
Each of the protocols supported by a socket
implementation have their own socket
address structure sockaddr_suffix
Where suffix represents the protocol family
Ex: sockaddr_in – Internet/IPv4 socket address structure
sockaddr_ipx – IPX socket address structure
205. The generic socket address structure
sockaddr
{
address family
protocol specific data
};
The internet/IPv4 socked address structure
sockaddr_in
{
in_family Internet address family
sin_port Transport layer Port Number
in_addr sin_addr IP address;
sin_zero[8] Padding ;
};
207. Byte ordering
◦ Network byte order
◦ Host byte order
◦ htons(l), ntohs(l)
Memory content initialization
◦ memset(buffer,value,buffersize)
Data copying and comparison
◦ memcpy(dest,src,num_of_bytes)
◦ memcmp(buffer1,buffer2,num_of_bytes)
208. IP address notation conversion
◦ Integer notation
◦ Dotted decimal notation
status inet_aton(ddstring_pointer,address_pointer)
Returns 1 on success 0 on error
ddstring_pointer inet_ntoa(address_pointer)
address_pointer inet_addr(ddstring_pointer)
*deprecated
209. sockfd socket(domain, type, protocol)
◦ domain is the protocol/address family AF_INET,AF_IPX..
◦ type is the the type of service SOCK_DGRAM,SOCK_STREAM
…
◦ protocol is the specific protocol that is supported by the
protocol family specified(as param1)
◦ Returns a fresh socket descriptor on success, –1 on error
status close(sockfd)
◦ Flushes(supposed to) the pending I/O to disk
◦ Returns –1 on error
210. status bind(sockfd,ptr_to_sockaddr,sockaddr_size)
◦ Associates the sockaddr with sockfd
◦ The rules for successful binding depend on the protocol
family of the socket(specified during call to socket)
◦ Necessary for receiving connections on STREAM socket
status listen(sockfd,backlog)
◦ Notifies the willingness to accept connections
◦ backlog Maximum number of established connections
yet to be notified to their respective user
processes(calls to accepts)
◦ On unbounded sockets an implicit bind is done with
IN_ADDRANY and a random port as the address and
port parameters respectively
* Above calls return –1 on error
struct sockaddr_in {
unsigned short sin_family; /* address family (always AF_INET) */
unsigned short sin_port; /* port num in network byte order */
struct in_addr sin_addr; /* IP addr in network byte order */
unsigned char sin_zero[8]; /* pad to sizeof(struct sockaddr) */
};
211. connfd accept(sockfd,ptr_to_sockaddr,ptr_to_sockaddr_size)
◦ Blocks till a connection gets established on sockfd and
returns a new file descriptor on which I/O can be
performed with the remote entity
◦ Fills the sockaddr and size parameters with the address
information (and it’s size respectively) of the connecting
entity
◦ bind and listen are assumed to have been called on sockfd
prior to calling accept
status connect(sockfd, ptr_to_sockaddr, sockaddr_size)
◦ Initiates a new connection with the entity addressed by
sockaddr in case of a STREAM socket
◦ Sets the default remote address for I/O in case of DGRAM
socket
* Above calls return –1 on error
212. SEND: int send(int sockfd, const void *msg, int len, int flags);
◦ msg: message you want to send
◦ len: length of the message
◦ flags := 0
◦ returned: the number of bytes actually sent
RECEIVE: int recv(int sockfd, void *buf, int len, unsigned int
flags);
◦ buf: buffer to receive the message
◦ len: length of the buffer (“don’t give me more!”)
◦ flags := 0
◦ returned: the number of bytes received
213. SEND (DGRAM-style): int sendto(int sockfd, const void *msg,
int len, int flags, const struct sockaddr *to, int tolen);
◦ msg: message you want to send
◦ len: length of the message
◦ flags := 0
◦ to: socket address of the remote process
◦ tolen: = sizeof(struct sockaddr)
◦ returned: the number of bytes actually sent
RECEIVE (DGRAM-style): int recvfrom(int sockfd, void *buf, int
len, unsigned int flags, struct sockaddr *from, int *fromlen);
◦ buf: buffer to receive the message
◦ len: length of the buffer (“don’t give me more!”)
◦ from: socket address of the process that sent the data
◦ fromlen:= sizeof(struct sockaddr)
◦ flags := 0
◦ returned: the number of bytes received
CLOSE: close (socketfd);
217. For example: web server
What does a web server
need to do so that a web
client can connect to it?
21
7
TCP
IP
Ethernet Adapter
Web Server
Port 80
TCP Server
218. Since web traffic uses TCP, the web server must create a
socket of type SOCK_STREAM
int fd; /* socket descriptor */
if((fd = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
perror(“socket”);
exit(1);
}
• socket returns an integer (socket descriptor)
• fd < 0 indicates that an error occurred
• AF_INET associates a socket with the Internet protocol family
• SOCK_STREAM selects the TCP protocol
Socket I/O: socket()
219. A socket can be bound to a port
21
9
int fd; /* socket descriptor */
struct sockaddr_in srv; /* used by bind() */
/* create the socket */
srv.sin_family = AF_INET; /* use the Internet addr family */
srv.sin_port = htons(80); /* bind socket ‘fd’ to port 80*/
/* bind: a client may connect to any of my addresses */
srv.sin_addr.s_addr = htonl(INADDR_ANY);
if(bind(fd, (struct sockaddr*) &srv, sizeof(srv)) < 0) {
perror("bind"); exit(1);
}
• Still not quite ready to communicate with a client...
Socket I/O: bind()
220. listen indicates that the server will accept a connection
22
0
int fd; /* socket descriptor */
struct sockaddr_in srv; /* used by bind() */
/* 1) create the socket */
/* 2) bind the socket to a port */
if(listen(fd, 5) < 0) {
perror(“listen”);
exit(1);
}
• Still not quite ready to communicate with a client...
221.
222. accept blocks waiting for a connection
22
2
int fd; /* socket descriptor */
struct sockaddr_in srv; /* used by bind() */
struct sockaddr_in cli; /* used by accept() */
int newfd; /* returned by accept() */
int cli_len = sizeof(cli); /* used by accept() */
/* 1) create the socket */
/* 2) bind the socket to a port */
/* 3) listen on the socket */
newfd = accept(fd, (struct sockaddr*) &cli, &cli_len);
if(newfd < 0) {
perror("accept"); exit(1);
}
• accept returns a new socket (newfd) with the same properties as the
original socket (fd)
• newfd < 0 indicates that an error occurred
223. 22
3
struct sockaddr_in cli; /* used by accept() */
int newfd; /* returned by accept() */
int cli_len = sizeof(cli); /* used by accept() */
newfd = accept(fd, (struct sockaddr*) &cli, &cli_len);
if(newfd < 0) {
perror("accept");
exit(1);
}
• How does the server know which client it is?
• cli.sin_addr.s_addr contains the client’s IP address
• cli.sin_port contains the client’s port number
• Now the server can exchange data with the client by
using read and write on the descriptor newfd.
• Why does accept need to return a new descriptor?
224. read can be used with a socket
read blocks waiting for data from the client but
does not guarantee that sizeof(buf) is read
22
4
int fd; /* socket descriptor */
char buf[512]; /* used by read() */
int nbytes; /* used by read() */
/* 1) create the socket */
/* 2) bind the socket to a port */
/* 3) listen on the socket */
/* 4) accept the incoming connection */
if((nbytes = read(newfd, buf, sizeof(buf))) < 0) {
perror(“read”); exit(1);
}
225. For example: web client
How does a web client
connect to a web server?
22
5
TCP
IP
Ethernet Adapter
2 Web Clients
226. IP Addresses are commonly written as strings (“128.2.35.50”),
but programs deal with IP addresses as integers.
22
6
struct sockaddr_in srv;
srv.sin_addr.s_addr = inet_addr(“128.2.35.50”);
if(srv.sin_addr.s_addr == (in_addr_t) -1) {
fprintf(stderr, "inet_addr failed!n"); exit(1);
}
Converting a numerical address to a string:
struct sockaddr_in srv;
char *t = inet_ntoa(srv.sin_addr);
if(t == 0) {
fprintf(stderr, “inet_ntoa failed!n”); exit(1);
}
Converting strings to numerical address:
227. Gethostbyname provides interface to DNS
Additional useful calls
◦ Gethostbyaddr – returns hostent given sockaddr_in
◦ Getservbyname
Used to get service description (typically port number)
Returns servent based on name
22
7
#include <netdb.h>
struct hostent *hp; /*ptr to host info for remote*/
struct sockaddr_in peeraddr;
char *name = “www.cs.cmu.edu”;
peeraddr.sin_family = AF_INET;
hp = gethostbyname(name)
peeraddr.sin_addr.s_addr = ((struct in_addr*)(hp->h_addr))->s_addr;
228. connect allows a client to connect to a server...
22
8
int fd; /* socket descriptor */
struct sockaddr_in srv; /* used by connect() */
/* create the socket */
/* connect: use the Internet address family */
srv.sin_family = AF_INET;
/* connect: socket ‘fd’ to port 80 */
srv.sin_port = htons(80);
/* connect: connect to IP Address “128.2.35.50” */
srv.sin_addr.s_addr = inet_addr(“128.2.35.50”);
if(connect(fd, (struct sockaddr*) &srv, sizeof(srv)) < 0) {
perror(”connect"); exit(1);
}
229. write can be used with a socket
22
9
int fd; /* socket descriptor */
struct sockaddr_in srv; /* used by connect() */
char buf[512]; /* used by write() */
int nbytes; /* used by write() */
/* 1) create the socket */
/* 2) connect() to the server */
/* Example: A client could “write” a request to a server
*/
if((nbytes = write(fd, buf, sizeof(buf))) < 0) {
perror(“write”);
exit(1);
}
231. Example: C client (TCP)
/* client.c */
void main(int argc, char *argv[])
{
struct sockaddr_in sad; /* structure to hold an IP address */
int clientSocket; /* socket descriptor */
struct hostent *ptrh; /* pointer to a host table entry */
char Sentence[128];
char modifiedSentence[128];
host = argv[1]; port = atoi(argv[2]);
clientSocket = socket(PF_INET, SOCK_STREAM, 0);
memset((char *)&sad,0,sizeof(sad)); /* clear sockaddr structure */
sad.sin_family = AF_INET; /* set family to Internet */
sad.sin_port = htons((u_short)port);
ptrh = gethostbyname(host); /* Convert host name to IP address */
memcpy(&sad.sin_addr, ptrh->h_addr, ptrh->h_length); connect(clientSocket,
(struct sockaddr *)&sad, sizeof(sad));
Create client socket,
connect to server
232. Example: C client (TCP), cont.
gets(Sentence);
n=write(clientSocket, Sentence, strlen(Sentence)+1);
n=read(clientSocket, modifiedSentence, sizeof(modifiedSentence));
printf("FROM SERVER: %sn”,modifiedSentence);
close(clientSocket);
}
Get
input stream
from user
Send line
to server
Read line
from server
Close
connection
233. Example: C server (TCP)
/* server.c */
void main(int argc, char *argv[])
{
struct sockaddr_in sad; /* structure to hold an IP address */
struct sockaddr_in cad;
int welcomeSocket, connectionSocket; /* socket descriptor */
struct hostent *ptrh; /* pointer to a host table entry */
char clientSentence[128];
char capitalizedSentence[128];
port = atoi(argv[1]);
welcomeSocket = socket(PF_INET, SOCK_STREAM, 0);
memset((char *)&sad,0,sizeof(sad)); /* clear sockaddr structure */
sad.sin_family = AF_INET; /* set family to Internet */
sad.sin_addr.s_addr = INADDR_ANY; /* set the local IP address */
sad.sin_port = htons((u_short)port);/* set the port number */
bind(welcomeSocket, (struct sockaddr *)&sad, sizeof(sad));
Create welcoming socket at port
&
Bind a local address
234. Example: C server (TCP), cont
/* Specify the maximum number of clients that can be queued */
listen(welcomeSocket, 10)
while(1) {
connectionSocket=accept(welcomeSocket, (struct sockaddr *)&cad, &alen);
n=read(connectionSocket, clientSentence, sizeof(clientSentence));
/* capitalize Sentence and store the result in capitalizedSentence*/
n=write(connectionSocket, capitalizedSentence, strlen(capitalizedSentence)+1);
close(connectionSocket);
}
}
Write out the result to socket
End of while loop,
loop back and wait for
another client connection
Wait, on welcoming socket
for contact by a client
238. Socket programming with UDP
UDP: no “connection” between
client and server
• no handshaking
• sender explicitly attaches IP
address and port of
destination to each packet
• server must extract IP
address, port of sender from
received packet
UDP: transmitted data may be
received out of order, or lost
application viewpoint
UDP provides unreliable transfer
of groups of bytes (“datagrams”)
between client and server
239. For example: NTP
daemon
What does a UDP server
need to do so that a UDP
client can connect to it?
23
9
UDP
IP
Ethernet Adapter
NTP
daemon
Port 123
240. The UDP server must create a datagram socket…
24
0
int fd; /* socket descriptor */
if((fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
perror(“socket”);
exit(1);
}
• socket returns an integer (socket descriptor)
• fd < 0 indicates that an error occurred
• AF_INET: associates a socket with the Internet protocol family
• SOCK_DGRAM: selects the UDP protocol
241. A socket can be bound to a port
24
1
int fd; /* socket descriptor */
struct sockaddr_in srv; /* used by bind() */
/* create the socket */
/* bind: use the Internet address family */
srv.sin_family = AF_INET;
/* bind: socket ‘fd’ to port 80*/
srv.sin_port = htons(80);
/* bind: a client may connect to any of my addresses */
srv.sin_addr.s_addr = htonl(INADDR_ANY);
if(bind(fd, (struct sockaddr*) &srv, sizeof(srv)) < 0) {
perror("bind"); exit(1);
}
• Now the UDP server is ready to accept packets…
242. read does not provide the client’s address to the UDP server
24
2
int fd; /* socket descriptor */
struct sockaddr_in srv; /* used by bind() */
struct sockaddr_in cli; /* used by recvfrom() */
char buf[512]; /* used by recvfrom() */
int cli_len = sizeof(cli); /* used by recvfrom() */
int nbytes; /* used by recvfrom() */
/* 1) create the socket */
/* 2) bind to the socket */
nbytes = recvfrom(fd, buf, sizeof(buf), 0 /* flags */,
(struct sockaddr*) &cli, &cli_len);
if(nbytes < 0) {
perror(“recvfrom”); exit(1);
}
243. 24
3
nbytes = recvfrom(fd, buf, sizeof(buf), 0 /* flags */,
(struct sockaddr*) cli, &cli_len);
• The actions performed by recvfrom
• returns the number of bytes read (nbytes)
• copies nbytes of data into buf
• returns the address of the client (cli)
• returns the length of cli (cli_len)
• don’t worry about flags
244. How does a UDP client
communicate with a UDP
server?
24
4
TCP
IP
Ethernet Adapter
2 UDP Clients
ports
245. write is not allowed
Notice that the UDP client does not bind a port number
◦ a port number is dynamically assigned when the first sendto is called
24
5
int fd; /* socket descriptor */
struct sockaddr_in srv; /* used by sendto() */
/* 1) create the socket */
/* sendto: send data to IP Address “128.2.35.50” port 80 */
srv.sin_family = AF_INET;
srv.sin_port = htons(80);
srv.sin_addr.s_addr = inet_addr(“128.2.35.50”);
nbytes = sendto(fd, buf, sizeof(buf), 0 /* flags */,
(struct sockaddr*) &srv, sizeof(srv));
if(nbytes < 0) {
perror(“sendto”); exit(1);
}
247. Example: C client (UDP)
/* client.c */
void main(int argc, char *argv[])
{
struct sockaddr_in sad; /* structure to hold an IP address */
int clientSocket; /* socket descriptor */
struct hostent *ptrh; /* pointer to a host table entry */
char Sentence[128];
char modifiedSentence[128];
host = argv[1]; port = atoi(argv[2]);
clientSocket = socket(PF_INET, SOCK_DGRAM, 0);
/* determine the server's address */
memset((char *)&sad,0,sizeof(sad)); /* clear sockaddr structure */
sad.sin_family = AF_INET; /* set family to Internet */
sad.sin_port = htons((u_short)port);
ptrh = gethostbyname(host); /* Convert host name to IP address */
memcpy(&sad.sin_addr, ptrh->h_addr, ptrh->h_length);
Create client socket,
NO connection to server
248. Example: C client (UDP), cont.
gets(Sentence);
addr_len =sizeof(struct sockaddr);
n=sendto(clientSocket, Sentence, strlen(Sentence)+1,
(struct sockaddr *) &sad, addr_len);
n=recvfrom(clientSocket, modifiedSentence, sizeof(modifiedSentence).
(struct sockaddr *) &sad, &addr_len);
printf("FROM SERVER: %sn”,modifiedSentence);
close(clientSocket);
}
Get
input stream
from user
Send line
to server
Read line
from server
Close
connection
249. Example: C server (UDP)
/* server.c */
void main(int argc, char *argv[])
{
struct sockaddr_in sad; /* structure to hold an IP address */
struct sockaddr_in cad;
int serverSocket; /* socket descriptor */
struct hostent *ptrh; /* pointer to a host table entry */
char clientSentence[128];
char capitalizedSentence[128];
port = atoi(argv[1]);
serverSocket = socket(PF_INET, SOCK_DGRAM, 0);
memset((char *)&sad,0,sizeof(sad)); /* clear sockaddr structure */
sad.sin_family = AF_INET; /* set family to Internet */
sad.sin_addr.s_addr = INADDR_ANY; /* set the local IP address */
sad.sin_port = htons((u_short)port);/* set the port number */
bind(serverSocket, (struct sockaddr *)&sad, sizeof(sad));
Create welcoming socket at port
&
Bind a local address
250. How can the UDP server
service multiple ports
simultaneously?
25
0
UDP
IP
Ethernet Adapter
UDP Server
Port 2000Port 3000
251. What problems does this code have?
25
1
int s1; /* socket descriptor 1 */
int s2; /* socket descriptor 2 */
/* 1) create socket s1 */
/* 2) create socket s2 */
/* 3) bind s1 to port 2000 */
/* 4) bind s2 to port 3000 */
while(1) {
recvfrom(s1, buf, sizeof(buf), ...);
/* process buf */
recvfrom(s2, buf, sizeof(buf), ...);
/* process buf */
}
252. client 1 server client 2
call connect
call accept
call read
ret connect
ret accept
call connect
call fgets
User goes
out to lunch
Client 1 blocks
waiting for user
to type in data
Client 2 blocks
waiting to complete
its connection
request until after
lunch!
Server blocks
waiting for
data from
Client 1
Server Flaw
253. Concurrent Servers
client 1 server client 2
call connect
call accept
ret connect
ret accept
call connect
call fgets
User goes
out to lunch
Client 1
blocks
waiting for
user to type
in data
call accept
ret connect
ret accept call fgets
write
write
call read
end read
close
close
call read (don’t block)
call read
254. while (1) {
newsock = (int *)malloc(sizeof (int));
*newsock=accept(sock, (struct sockaddr
*)&from, &fromlen);
if (*newsock < 0) error("Accepting");
printf("A connection has been accepted from
%sn",
inet_ntoa((struct in_addr)from.sin_addr));
retval = pthread_create(&tid, NULL,
ConnectionThread, (void *)newsock);
if (retval != 0) {
error("Error, could not create thread");
}
}
255. /****** ConnectionThread **********/
void *ConnectionThread(void *arg)
{
int sock, n, len;
char buffer[BUFSIZE];
char *msg = "Got your message";
sock = *(int *)arg;
len = strlen(msg);
n = read(sock,buffer,BUFSIZE-1);
while (n > 0) {
buffer[n]='0';
printf("Message is %sn",buffer);
n = write(sock,msg,len);
if (n < len) error("Error writing");
n = read(sock,buffer,BUFSIZE-1);
if (n < 0) error("Error reading");
}
if (close(sock) < 0) error("closing");
pthread_exit(NULL);
return NULL;
}
256. Concurrency
• Threading
– Easier to understand
– Race conditions increase complexity
• Select()
– Explicit control flows, no race conditions
– Explicit control more complicated
• There is no clear winner, but you
MUST use select()…
257. What is select()?
• Monitor multiple descriptors
• How does it work?
– Setup sets of sockets to monitor
– select(): blocking until something
happens
– “Something” could be
• Incoming connection: accept()
• Clients sending data: read()
• Pending data to send: write()
• Timeout
258. Concurrency – Step 1
• Allowing address reuse
• Then we set the sockets to be non-
blocking
int sock, opts=1;
sock = socket(...); // To give you an idea of where the new code goes
setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &opts, sizeof(opts));
if((opts = fcntl(sock, F_GETFL)) < 0) { // Get current options
printf(“Error...n”);
...
}
opts = (opts | O_NONBLOCK); // Don't clobber your old settings
if(fcntl(sock, F_SETFL, opts) < 0) {
printf(“Error...n”);
...
}
bind(...); // To again give you an idea where the new code goes
259. Concurrency – Step 2
• Monitor sockets with select()
– int select(int maxfd, fd_set *readfds, fd_set
*writefds, fd_set *exceptfds, const struct
timespec *timeout);
• maxfd
– max file descriptor + 1
• fd_set: bit vector with FD_SETSIZE bits
– readfds: bit vector of read descriptors to monitor
– writefds: bit vector of write descriptors to
monitor
– exceptfds: set to NULL
• timeout
– how long to wait without activity before
returning
260. What about bit vectors?
• void FD_ZERO(fd_set *fdset);
– clear out all bits
• void FD_SET(int fd, fd_set *fdset);
– set one bit
• void FD_CLR(int fd, fd_set *fdset);
– clear one bit
• int FD_ISSET(int fd, fd_set *fdset);
– test whether fd bit is set
261. The Server
// socket() call and non-blocking code is above this point
if((bind(sockfd, (struct sockaddr *) &saddr, sizeof(saddr)) < 0) { // bind!
printf(“Error bindingn”);
...
}
if(listen(sockfd, 5) < 0) { // listen for incoming connections
printf(“Error listeningn”);
...
}
clen=sizeof(caddr);
// Setup pool.read_set with an FD_ZERO() and FD_SET() for
// your server socket file descriptor. (whatever socket() returned)
while(1) {
pool.ready_set = pool.read_set; // Save the current state
pool.nready = select(pool.maxfd+1, &pool.ready_set, &pool.write_set, NULL, NULL);
if(FD_ISSET(sockfd, &pool.ready_set)) { // Check if there is an incoming conn
isock=accept(sockfd, (struct sockaddr *) &caddr, &clen); // accept it
add_client(isock, &pool); // add the client by the incoming socket fd
}
check_clients(&pool); // check if any data needs to be sent/received from clients
}
...
close(sockfd);
262. What is pool?
typedef struct { /* represents a pool of connected descriptors */
int maxfd; /* largest descriptor in read_set */
fd_set read_set; /* set of all active read descriptors */
fd_set write_set; /* set of all active read descriptors */
fd_set ready_set; /* subset of descriptors ready for reading */
int nready; /* number of ready descriptors from select */
int maxi; /* highwater index into client array */
int clientfd[FD_SETSIZE]; /* set of active descriptors */
rio_t clientrio[FD_SETSIZE]; /* set of active read buffers */
... // ADD WHAT WOULD BE HELPFUL FOR PROJECT1
} pool;
263. What about checking clients?
• The main loop only tests for incoming
connections
– There are other reasons the server wakes up
– Clients are sending data, pending data to
write to buffer, clients closing connections,
etc.
• Store all client file descriptors
– in pool
• Keep the while(1) loop thin
– Delegate to functions
• Come up with your own design
264. maxfds: number of descriptors to be tested
◦ descriptors (0, 1, ... maxfds-1) will be tested
readfds: a set of fds we want to check if data is available
◦ returns a set of fds ready to read
◦ if input argument is NULL, not interested in that condition
writefds: returns a set of fds ready to write
exceptfds: returns a set of fds with exception conditions
26
4
int select(int maxfds, fd_set *readfds, fd_set *writefds,
fd_set *exceptfds, struct timeval *timeout);
FD_CLR(int fd, fd_set *fds); /* clear the bit for fd in fds */
FD_ISSET(int fd, fd_set *fds); /* is the bit for fd in fds? */
FD_SET(int fd, fd_set *fds); /* turn on the bit for fd in fds */
FD_ZERO(fd_set *fds); /* clear all bits in fds */