aos lab 12: network communication
TRANSCRIPT
![Page 1: AOS Lab 12: Network Communication](https://reader033.vdocuments.mx/reader033/viewer/2022052618/554f3db9b4c905471e8b4b8e/html5/thumbnails/1.jpg)
Lab 12: Network CommunicationAdvanced Operating Systems
Zubair Nabi
April 24, 2013
![Page 2: AOS Lab 12: Network Communication](https://reader033.vdocuments.mx/reader033/viewer/2022052618/554f3db9b4c905471e8b4b8e/html5/thumbnails/2.jpg)
Introduction
• In *nix systems, the networking infrastructure abstracts awaymany network architectures
• Each network architecture consists of• Network-communication protocols• The protocol family• Conventions of naming end-points• The address family or address format• Additional facilities
• Network facilities are accessed through the socket abstraction
![Page 3: AOS Lab 12: Network Communication](https://reader033.vdocuments.mx/reader033/viewer/2022052618/554f3db9b4c905471e8b4b8e/html5/thumbnails/3.jpg)
Introduction
• In *nix systems, the networking infrastructure abstracts awaymany network architectures
• Each network architecture consists of• Network-communication protocols
• The protocol family• Conventions of naming end-points• The address family or address format• Additional facilities
• Network facilities are accessed through the socket abstraction
![Page 4: AOS Lab 12: Network Communication](https://reader033.vdocuments.mx/reader033/viewer/2022052618/554f3db9b4c905471e8b4b8e/html5/thumbnails/4.jpg)
Introduction
• In *nix systems, the networking infrastructure abstracts awaymany network architectures
• Each network architecture consists of• Network-communication protocols• The protocol family
• Conventions of naming end-points• The address family or address format• Additional facilities
• Network facilities are accessed through the socket abstraction
![Page 5: AOS Lab 12: Network Communication](https://reader033.vdocuments.mx/reader033/viewer/2022052618/554f3db9b4c905471e8b4b8e/html5/thumbnails/5.jpg)
Introduction
• In *nix systems, the networking infrastructure abstracts awaymany network architectures
• Each network architecture consists of• Network-communication protocols• The protocol family• Conventions of naming end-points
• The address family or address format• Additional facilities
• Network facilities are accessed through the socket abstraction
![Page 6: AOS Lab 12: Network Communication](https://reader033.vdocuments.mx/reader033/viewer/2022052618/554f3db9b4c905471e8b4b8e/html5/thumbnails/6.jpg)
Introduction
• In *nix systems, the networking infrastructure abstracts awaymany network architectures
• Each network architecture consists of• Network-communication protocols• The protocol family• Conventions of naming end-points• The address family or address format
• Additional facilities
• Network facilities are accessed through the socket abstraction
![Page 7: AOS Lab 12: Network Communication](https://reader033.vdocuments.mx/reader033/viewer/2022052618/554f3db9b4c905471e8b4b8e/html5/thumbnails/7.jpg)
Introduction
• In *nix systems, the networking infrastructure abstracts awaymany network architectures
• Each network architecture consists of• Network-communication protocols• The protocol family• Conventions of naming end-points• The address family or address format• Additional facilities
• Network facilities are accessed through the socket abstraction
![Page 8: AOS Lab 12: Network Communication](https://reader033.vdocuments.mx/reader033/viewer/2022052618/554f3db9b4c905471e8b4b8e/html5/thumbnails/8.jpg)
Introduction
• In *nix systems, the networking infrastructure abstracts awaymany network architectures
• Each network architecture consists of• Network-communication protocols• The protocol family• Conventions of naming end-points• The address family or address format• Additional facilities
• Network facilities are accessed through the socket abstraction
![Page 9: AOS Lab 12: Network Communication](https://reader033.vdocuments.mx/reader033/viewer/2022052618/554f3db9b4c905471e8b4b8e/html5/thumbnails/9.jpg)
Network Subsystem
Consists of three layers:
1 Transport layer: In charge of sockets-amenable addressingstructure and protocol mechanisms, such as ordering, reliability,etc.
2 Network layer: Responsible for delivery of data across thenetwork (must maintain a routing database)
3 Link layer: Responsible for shipping messages between hostsconnected to a common transmission medium
![Page 10: AOS Lab 12: Network Communication](https://reader033.vdocuments.mx/reader033/viewer/2022052618/554f3db9b4c905471e8b4b8e/html5/thumbnails/10.jpg)
Network Subsystem
Consists of three layers:
1 Transport layer: In charge of sockets-amenable addressingstructure and protocol mechanisms, such as ordering, reliability,etc.
2 Network layer: Responsible for delivery of data across thenetwork (must maintain a routing database)
3 Link layer: Responsible for shipping messages between hostsconnected to a common transmission medium
![Page 11: AOS Lab 12: Network Communication](https://reader033.vdocuments.mx/reader033/viewer/2022052618/554f3db9b4c905471e8b4b8e/html5/thumbnails/11.jpg)
Network Subsystem
Consists of three layers:
1 Transport layer: In charge of sockets-amenable addressingstructure and protocol mechanisms, such as ordering, reliability,etc.
2 Network layer: Responsible for delivery of data across thenetwork (must maintain a routing database)
3 Link layer: Responsible for shipping messages between hostsconnected to a common transmission medium
![Page 12: AOS Lab 12: Network Communication](https://reader033.vdocuments.mx/reader033/viewer/2022052618/554f3db9b4c905471e8b4b8e/html5/thumbnails/12.jpg)
Network Subsystem (2)
• The layering is just logical layering
• The network service itself might choose to use more or fewerlayers based on its requirements
• For instance, raw sockets use a null implementation at one ormore layers
• Similarly, tunneling of one protocol through another requiresadditional implementations of multiple layers
![Page 13: AOS Lab 12: Network Communication](https://reader033.vdocuments.mx/reader033/viewer/2022052618/554f3db9b4c905471e8b4b8e/html5/thumbnails/13.jpg)
Network Subsystem (2)
• The layering is just logical layering
• The network service itself might choose to use more or fewerlayers based on its requirements
• For instance, raw sockets use a null implementation at one ormore layers
• Similarly, tunneling of one protocol through another requiresadditional implementations of multiple layers
![Page 14: AOS Lab 12: Network Communication](https://reader033.vdocuments.mx/reader033/viewer/2022052618/554f3db9b4c905471e8b4b8e/html5/thumbnails/14.jpg)
Network Subsystem (2)
• The layering is just logical layering
• The network service itself might choose to use more or fewerlayers based on its requirements
• For instance, raw sockets use a null implementation at one ormore layers
• Similarly, tunneling of one protocol through another requiresadditional implementations of multiple layers
![Page 15: AOS Lab 12: Network Communication](https://reader033.vdocuments.mx/reader033/viewer/2022052618/554f3db9b4c905471e8b4b8e/html5/thumbnails/15.jpg)
Network Subsystem (2)
• The layering is just logical layering
• The network service itself might choose to use more or fewerlayers based on its requirements
• For instance, raw sockets use a null implementation at one ormore layers
• Similarly, tunneling of one protocol through another requiresadditional implementations of multiple layers
![Page 16: AOS Lab 12: Network Communication](https://reader033.vdocuments.mx/reader033/viewer/2022052618/554f3db9b4c905471e8b4b8e/html5/thumbnails/16.jpg)
Memory Management
• Memory management for communication protocols is differentthan regular entities as memory is required in widely varying sizes
• A special-purpose memory-management facility exists for IPCand networking systems
• The unit of allocation is an mbuf (skbuff in Linux), which is128 bytes long with 100 or 108 bytes reserved for data
• A chain of mbufs can be linked together (m_next) to hold anarbitrary quantity of data
• For instance, a chain of mbufs is used to represent packets bynetwork protocols
![Page 17: AOS Lab 12: Network Communication](https://reader033.vdocuments.mx/reader033/viewer/2022052618/554f3db9b4c905471e8b4b8e/html5/thumbnails/17.jpg)
Memory Management
• Memory management for communication protocols is differentthan regular entities as memory is required in widely varying sizes
• A special-purpose memory-management facility exists for IPCand networking systems
• The unit of allocation is an mbuf (skbuff in Linux), which is128 bytes long with 100 or 108 bytes reserved for data
• A chain of mbufs can be linked together (m_next) to hold anarbitrary quantity of data
• For instance, a chain of mbufs is used to represent packets bynetwork protocols
![Page 18: AOS Lab 12: Network Communication](https://reader033.vdocuments.mx/reader033/viewer/2022052618/554f3db9b4c905471e8b4b8e/html5/thumbnails/18.jpg)
Memory Management
• Memory management for communication protocols is differentthan regular entities as memory is required in widely varying sizes
• A special-purpose memory-management facility exists for IPCand networking systems
• The unit of allocation is an mbuf (skbuff in Linux), which is128 bytes long with 100 or 108 bytes reserved for data
• A chain of mbufs can be linked together (m_next) to hold anarbitrary quantity of data
• For instance, a chain of mbufs is used to represent packets bynetwork protocols
![Page 19: AOS Lab 12: Network Communication](https://reader033.vdocuments.mx/reader033/viewer/2022052618/554f3db9b4c905471e8b4b8e/html5/thumbnails/19.jpg)
Memory Management
• Memory management for communication protocols is differentthan regular entities as memory is required in widely varying sizes
• A special-purpose memory-management facility exists for IPCand networking systems
• The unit of allocation is an mbuf (skbuff in Linux), which is128 bytes long with 100 or 108 bytes reserved for data
• A chain of mbufs can be linked together (m_next) to hold anarbitrary quantity of data
• For instance, a chain of mbufs is used to represent packets bynetwork protocols
![Page 20: AOS Lab 12: Network Communication](https://reader033.vdocuments.mx/reader033/viewer/2022052618/554f3db9b4c905471e8b4b8e/html5/thumbnails/20.jpg)
Memory Management
• Memory management for communication protocols is differentthan regular entities as memory is required in widely varying sizes
• A special-purpose memory-management facility exists for IPCand networking systems
• The unit of allocation is an mbuf (skbuff in Linux), which is128 bytes long with 100 or 108 bytes reserved for data
• A chain of mbufs can be linked together (m_next) to hold anarbitrary quantity of data
• For instance, a chain of mbufs is used to represent packets bynetwork protocols
![Page 21: AOS Lab 12: Network Communication](https://reader033.vdocuments.mx/reader033/viewer/2022052618/554f3db9b4c905471e8b4b8e/html5/thumbnails/21.jpg)
mbuf
![Page 22: AOS Lab 12: Network Communication](https://reader033.vdocuments.mx/reader033/viewer/2022052618/554f3db9b4c905471e8b4b8e/html5/thumbnails/22.jpg)
Data Flow
• Socket-to-network-subsystem• Calls the transport-layer modules that support the socket
abstraction
• Typically started by system calls
• Network-subsystem-to-socket• Flows up the stack and is placed in the receive queue of the
destination socket• Asynchronously received and added to the per-protocol input
message queue
![Page 23: AOS Lab 12: Network Communication](https://reader033.vdocuments.mx/reader033/viewer/2022052618/554f3db9b4c905471e8b4b8e/html5/thumbnails/23.jpg)
Data Flow
• Socket-to-network-subsystem• Calls the transport-layer modules that support the socket
abstraction• Typically started by system calls
• Network-subsystem-to-socket• Flows up the stack and is placed in the receive queue of the
destination socket• Asynchronously received and added to the per-protocol input
message queue
![Page 24: AOS Lab 12: Network Communication](https://reader033.vdocuments.mx/reader033/viewer/2022052618/554f3db9b4c905471e8b4b8e/html5/thumbnails/24.jpg)
Data Flow
• Socket-to-network-subsystem• Calls the transport-layer modules that support the socket
abstraction• Typically started by system calls
• Network-subsystem-to-socket• Flows up the stack and is placed in the receive queue of the
destination socket
• Asynchronously received and added to the per-protocol inputmessage queue
![Page 25: AOS Lab 12: Network Communication](https://reader033.vdocuments.mx/reader033/viewer/2022052618/554f3db9b4c905471e8b4b8e/html5/thumbnails/25.jpg)
Data Flow
• Socket-to-network-subsystem• Calls the transport-layer modules that support the socket
abstraction• Typically started by system calls
• Network-subsystem-to-socket• Flows up the stack and is placed in the receive queue of the
destination socket• Asynchronously received and added to the per-protocol input
message queue
![Page 26: AOS Lab 12: Network Communication](https://reader033.vdocuments.mx/reader033/viewer/2022052618/554f3db9b4c905471e8b4b8e/html5/thumbnails/26.jpg)
Upwards Dataflow
![Page 27: AOS Lab 12: Network Communication](https://reader033.vdocuments.mx/reader033/viewer/2022052618/554f3db9b4c905471e8b4b8e/html5/thumbnails/27.jpg)
Network Protocols
• Defined by a set of conventions, including packet formats, states,and state transitions
• Each communication-protocol module implements a particularprotocol and is made up of a collection of procedures and privatedata structures
• The external interface of a module is described by aprotocol-switch structure
• This interface is used by the socket layer for all interaction• The address of this structure is present within the socket’sso_proto field
• Each time a socket is created the protocol is selected based onthe type of socket (pr_type)
• Also in charge of mbuf storage management
![Page 28: AOS Lab 12: Network Communication](https://reader033.vdocuments.mx/reader033/viewer/2022052618/554f3db9b4c905471e8b4b8e/html5/thumbnails/28.jpg)
Network Protocols
• Defined by a set of conventions, including packet formats, states,and state transitions
• Each communication-protocol module implements a particularprotocol and is made up of a collection of procedures and privatedata structures
• The external interface of a module is described by aprotocol-switch structure
• This interface is used by the socket layer for all interaction• The address of this structure is present within the socket’sso_proto field
• Each time a socket is created the protocol is selected based onthe type of socket (pr_type)
• Also in charge of mbuf storage management
![Page 29: AOS Lab 12: Network Communication](https://reader033.vdocuments.mx/reader033/viewer/2022052618/554f3db9b4c905471e8b4b8e/html5/thumbnails/29.jpg)
Network Protocols
• Defined by a set of conventions, including packet formats, states,and state transitions
• Each communication-protocol module implements a particularprotocol and is made up of a collection of procedures and privatedata structures
• The external interface of a module is described by aprotocol-switch structure
• This interface is used by the socket layer for all interaction• The address of this structure is present within the socket’sso_proto field
• Each time a socket is created the protocol is selected based onthe type of socket (pr_type)
• Also in charge of mbuf storage management
![Page 30: AOS Lab 12: Network Communication](https://reader033.vdocuments.mx/reader033/viewer/2022052618/554f3db9b4c905471e8b4b8e/html5/thumbnails/30.jpg)
Network Protocols
• Defined by a set of conventions, including packet formats, states,and state transitions
• Each communication-protocol module implements a particularprotocol and is made up of a collection of procedures and privatedata structures
• The external interface of a module is described by aprotocol-switch structure
• This interface is used by the socket layer for all interaction
• The address of this structure is present within the socket’sso_proto field
• Each time a socket is created the protocol is selected based onthe type of socket (pr_type)
• Also in charge of mbuf storage management
![Page 31: AOS Lab 12: Network Communication](https://reader033.vdocuments.mx/reader033/viewer/2022052618/554f3db9b4c905471e8b4b8e/html5/thumbnails/31.jpg)
Network Protocols
• Defined by a set of conventions, including packet formats, states,and state transitions
• Each communication-protocol module implements a particularprotocol and is made up of a collection of procedures and privatedata structures
• The external interface of a module is described by aprotocol-switch structure
• This interface is used by the socket layer for all interaction• The address of this structure is present within the socket’sso_proto field
• Each time a socket is created the protocol is selected based onthe type of socket (pr_type)
• Also in charge of mbuf storage management
![Page 32: AOS Lab 12: Network Communication](https://reader033.vdocuments.mx/reader033/viewer/2022052618/554f3db9b4c905471e8b4b8e/html5/thumbnails/32.jpg)
Network Protocols
• Defined by a set of conventions, including packet formats, states,and state transitions
• Each communication-protocol module implements a particularprotocol and is made up of a collection of procedures and privatedata structures
• The external interface of a module is described by aprotocol-switch structure
• This interface is used by the socket layer for all interaction• The address of this structure is present within the socket’sso_proto field
• Each time a socket is created the protocol is selected based onthe type of socket (pr_type)
• Also in charge of mbuf storage management
![Page 33: AOS Lab 12: Network Communication](https://reader033.vdocuments.mx/reader033/viewer/2022052618/554f3db9b4c905471e8b4b8e/html5/thumbnails/33.jpg)
Network Protocols
• Defined by a set of conventions, including packet formats, states,and state transitions
• Each communication-protocol module implements a particularprotocol and is made up of a collection of procedures and privatedata structures
• The external interface of a module is described by aprotocol-switch structure
• This interface is used by the socket layer for all interaction• The address of this structure is present within the socket’sso_proto field
• Each time a socket is created the protocol is selected based onthe type of socket (pr_type)
• Also in charge of mbuf storage management
![Page 34: AOS Lab 12: Network Communication](https://reader033.vdocuments.mx/reader033/viewer/2022052618/554f3db9b4c905471e8b4b8e/html5/thumbnails/34.jpg)
Network Interfaces
• Each interface defines a link-layer path through which messagescan be sent and received
• Typically, a hardware device is represented by this interface• The loopback interface is in software which is used to route
traffic to local sockets
• Also in charge of encapsulation and decapsulation of link-layerprotocol headers
• Typically implemented as a separate layer that is shared byvarious hardware drivers
• The selection of the interface is taken care of by the network-layerprotocol
• Represented by an ifnet structure
![Page 35: AOS Lab 12: Network Communication](https://reader033.vdocuments.mx/reader033/viewer/2022052618/554f3db9b4c905471e8b4b8e/html5/thumbnails/35.jpg)
Network Interfaces
• Each interface defines a link-layer path through which messagescan be sent and received
• Typically, a hardware device is represented by this interface
• The loopback interface is in software which is used to routetraffic to local sockets
• Also in charge of encapsulation and decapsulation of link-layerprotocol headers
• Typically implemented as a separate layer that is shared byvarious hardware drivers
• The selection of the interface is taken care of by the network-layerprotocol
• Represented by an ifnet structure
![Page 36: AOS Lab 12: Network Communication](https://reader033.vdocuments.mx/reader033/viewer/2022052618/554f3db9b4c905471e8b4b8e/html5/thumbnails/36.jpg)
Network Interfaces
• Each interface defines a link-layer path through which messagescan be sent and received
• Typically, a hardware device is represented by this interface• The loopback interface is in software which is used to route
traffic to local sockets
• Also in charge of encapsulation and decapsulation of link-layerprotocol headers
• Typically implemented as a separate layer that is shared byvarious hardware drivers
• The selection of the interface is taken care of by the network-layerprotocol
• Represented by an ifnet structure
![Page 37: AOS Lab 12: Network Communication](https://reader033.vdocuments.mx/reader033/viewer/2022052618/554f3db9b4c905471e8b4b8e/html5/thumbnails/37.jpg)
Network Interfaces
• Each interface defines a link-layer path through which messagescan be sent and received
• Typically, a hardware device is represented by this interface• The loopback interface is in software which is used to route
traffic to local sockets
• Also in charge of encapsulation and decapsulation of link-layerprotocol headers
• Typically implemented as a separate layer that is shared byvarious hardware drivers
• The selection of the interface is taken care of by the network-layerprotocol
• Represented by an ifnet structure
![Page 38: AOS Lab 12: Network Communication](https://reader033.vdocuments.mx/reader033/viewer/2022052618/554f3db9b4c905471e8b4b8e/html5/thumbnails/38.jpg)
Network Interfaces
• Each interface defines a link-layer path through which messagescan be sent and received
• Typically, a hardware device is represented by this interface• The loopback interface is in software which is used to route
traffic to local sockets
• Also in charge of encapsulation and decapsulation of link-layerprotocol headers
• Typically implemented as a separate layer that is shared byvarious hardware drivers
• The selection of the interface is taken care of by the network-layerprotocol
• Represented by an ifnet structure
![Page 39: AOS Lab 12: Network Communication](https://reader033.vdocuments.mx/reader033/viewer/2022052618/554f3db9b4c905471e8b4b8e/html5/thumbnails/39.jpg)
Network Interfaces
• Each interface defines a link-layer path through which messagescan be sent and received
• Typically, a hardware device is represented by this interface• The loopback interface is in software which is used to route
traffic to local sockets
• Also in charge of encapsulation and decapsulation of link-layerprotocol headers
• Typically implemented as a separate layer that is shared byvarious hardware drivers
• The selection of the interface is taken care of by the network-layerprotocol
• Represented by an ifnet structure
![Page 40: AOS Lab 12: Network Communication](https://reader033.vdocuments.mx/reader033/viewer/2022052618/554f3db9b4c905471e8b4b8e/html5/thumbnails/40.jpg)
Network Interfaces
• Each interface defines a link-layer path through which messagescan be sent and received
• Typically, a hardware device is represented by this interface• The loopback interface is in software which is used to route
traffic to local sockets
• Also in charge of encapsulation and decapsulation of link-layerprotocol headers
• Typically implemented as a separate layer that is shared byvarious hardware drivers
• The selection of the interface is taken care of by the network-layerprotocol
• Represented by an ifnet structure
![Page 41: AOS Lab 12: Network Communication](https://reader033.vdocuments.mx/reader033/viewer/2022052618/554f3db9b4c905471e8b4b8e/html5/thumbnails/41.jpg)
Socket-to-Protocol Interface
• Enabled by two routines: 1) User request, pr_usrreq() and2) Control output, pr_ctloutput()
• These methods are present in the protocol-switch table for eachprotocol
• Control-output: Implements getsockopt and setsockoptsystem calls
• User-request: Implements all other operations
![Page 42: AOS Lab 12: Network Communication](https://reader033.vdocuments.mx/reader033/viewer/2022052618/554f3db9b4c905471e8b4b8e/html5/thumbnails/42.jpg)
Socket-to-Protocol Interface
• Enabled by two routines: 1) User request, pr_usrreq() and2) Control output, pr_ctloutput()
• These methods are present in the protocol-switch table for eachprotocol
• Control-output: Implements getsockopt and setsockoptsystem calls
• User-request: Implements all other operations
![Page 43: AOS Lab 12: Network Communication](https://reader033.vdocuments.mx/reader033/viewer/2022052618/554f3db9b4c905471e8b4b8e/html5/thumbnails/43.jpg)
Socket-to-Protocol Interface
• Enabled by two routines: 1) User request, pr_usrreq() and2) Control output, pr_ctloutput()
• These methods are present in the protocol-switch table for eachprotocol
• Control-output: Implements getsockopt and setsockoptsystem calls
• User-request: Implements all other operations
![Page 44: AOS Lab 12: Network Communication](https://reader033.vdocuments.mx/reader033/viewer/2022052618/554f3db9b4c905471e8b4b8e/html5/thumbnails/44.jpg)
Socket-to-Protocol Interface
• Enabled by two routines: 1) User request, pr_usrreq() and2) Control output, pr_ctloutput()
• These methods are present in the protocol-switch table for eachprotocol
• Control-output: Implements getsockopt and setsockoptsystem calls
• User-request: Implements all other operations
![Page 45: AOS Lab 12: Network Communication](https://reader033.vdocuments.mx/reader033/viewer/2022052618/554f3db9b4c905471e8b4b8e/html5/thumbnails/45.jpg)
Protocol-to-Network-Interface Interface
• Lowest layer in the protocol family must interact with one or moreinterfaces to send and receive packets
• Obviously a routing decision must have already chosen theoutgoing interface
![Page 46: AOS Lab 12: Network Communication](https://reader033.vdocuments.mx/reader033/viewer/2022052618/554f3db9b4c905471e8b4b8e/html5/thumbnails/46.jpg)
Protocol-to-Network-Interface Interface
• Lowest layer in the protocol family must interact with one or moreinterfaces to send and receive packets
• Obviously a routing decision must have already chosen theoutgoing interface
![Page 47: AOS Lab 12: Network Communication](https://reader033.vdocuments.mx/reader033/viewer/2022052618/554f3db9b4c905471e8b4b8e/html5/thumbnails/47.jpg)
Code: Packet Sending
error = (*ifp->if_output)(ifp, m, dst, rt);
struct ifnet *ifp;struct mbuf *m;struct sockaddr *dst;struct rtentry *rt;
![Page 48: AOS Lab 12: Network Communication](https://reader033.vdocuments.mx/reader033/viewer/2022052618/554f3db9b4c905471e8b4b8e/html5/thumbnails/48.jpg)
Packet Sending
• Packet m is transmitted to destination dst via interface ifp
• Steps:• Validation of the destination address• Queuing of the packet on the send queue• If the interface is not busy, using an interrupt-driven routine to
transmit the packet
• The link-layer address is chosen by ARP in case of Ethernet
![Page 49: AOS Lab 12: Network Communication](https://reader033.vdocuments.mx/reader033/viewer/2022052618/554f3db9b4c905471e8b4b8e/html5/thumbnails/49.jpg)
Packet Sending
• Packet m is transmitted to destination dst via interface ifp• Steps:
• Validation of the destination address
• Queuing of the packet on the send queue• If the interface is not busy, using an interrupt-driven routine to
transmit the packet
• The link-layer address is chosen by ARP in case of Ethernet
![Page 50: AOS Lab 12: Network Communication](https://reader033.vdocuments.mx/reader033/viewer/2022052618/554f3db9b4c905471e8b4b8e/html5/thumbnails/50.jpg)
Packet Sending
• Packet m is transmitted to destination dst via interface ifp• Steps:
• Validation of the destination address• Queuing of the packet on the send queue
• If the interface is not busy, using an interrupt-driven routine totransmit the packet
• The link-layer address is chosen by ARP in case of Ethernet
![Page 51: AOS Lab 12: Network Communication](https://reader033.vdocuments.mx/reader033/viewer/2022052618/554f3db9b4c905471e8b4b8e/html5/thumbnails/51.jpg)
Packet Sending
• Packet m is transmitted to destination dst via interface ifp• Steps:
• Validation of the destination address• Queuing of the packet on the send queue• If the interface is not busy, using an interrupt-driven routine to
transmit the packet
• The link-layer address is chosen by ARP in case of Ethernet
![Page 52: AOS Lab 12: Network Communication](https://reader033.vdocuments.mx/reader033/viewer/2022052618/554f3db9b4c905471e8b4b8e/html5/thumbnails/52.jpg)
Packet Sending
• Packet m is transmitted to destination dst via interface ifp• Steps:
• Validation of the destination address• Queuing of the packet on the send queue• If the interface is not busy, using an interrupt-driven routine to
transmit the packet
• The link-layer address is chosen by ARP in case of Ethernet
![Page 53: AOS Lab 12: Network Communication](https://reader033.vdocuments.mx/reader033/viewer/2022052618/554f3db9b4c905471e8b4b8e/html5/thumbnails/53.jpg)
Packet Receiving
• Incoming packets are queued in the corresponding protocol’sinput packet queue
• A software interrupt is posted to initiate network-layer processing
![Page 54: AOS Lab 12: Network Communication](https://reader033.vdocuments.mx/reader033/viewer/2022052618/554f3db9b4c905471e8b4b8e/html5/thumbnails/54.jpg)
Packet Receiving
• Incoming packets are queued in the corresponding protocol’sinput packet queue
• A software interrupt is posted to initiate network-layer processing
![Page 55: AOS Lab 12: Network Communication](https://reader033.vdocuments.mx/reader033/viewer/2022052618/554f3db9b4c905471e8b4b8e/html5/thumbnails/55.jpg)
Code: Packet Receiving
if (IF_QFULL(&ipintrq)) {IF_DROP(&ipintrq);ifp->if_iqdrops++;m_freem(m);
} else {schednetisr(NETISR_IP);IF_ENQUEUE(&ipintrq, m)
}
![Page 56: AOS Lab 12: Network Communication](https://reader033.vdocuments.mx/reader033/viewer/2022052618/554f3db9b4c905471e8b4b8e/html5/thumbnails/56.jpg)
Routing
• The routing system has two components; one within the kerneland one in user-space
• The routing mechanism is present within the kernel while routingpolicies are defined in user-space
• The routing mechanism involves a table lookup to get a first-hopfor a given destination
• Routing policies include components that help in choosingfirst-hop routes
![Page 57: AOS Lab 12: Network Communication](https://reader033.vdocuments.mx/reader033/viewer/2022052618/554f3db9b4c905471e8b4b8e/html5/thumbnails/57.jpg)
Routing
• The routing system has two components; one within the kerneland one in user-space
• The routing mechanism is present within the kernel while routingpolicies are defined in user-space
• The routing mechanism involves a table lookup to get a first-hopfor a given destination
• Routing policies include components that help in choosingfirst-hop routes
![Page 58: AOS Lab 12: Network Communication](https://reader033.vdocuments.mx/reader033/viewer/2022052618/554f3db9b4c905471e8b4b8e/html5/thumbnails/58.jpg)
Routing
• The routing system has two components; one within the kerneland one in user-space
• The routing mechanism is present within the kernel while routingpolicies are defined in user-space
• The routing mechanism involves a table lookup to get a first-hopfor a given destination
• Routing policies include components that help in choosingfirst-hop routes
![Page 59: AOS Lab 12: Network Communication](https://reader033.vdocuments.mx/reader033/viewer/2022052618/554f3db9b4c905471e8b4b8e/html5/thumbnails/59.jpg)
Routing
• The routing system has two components; one within the kerneland one in user-space
• The routing mechanism is present within the kernel while routingpolicies are defined in user-space
• The routing mechanism involves a table lookup to get a first-hopfor a given destination
• Routing policies include components that help in choosingfirst-hop routes
![Page 60: AOS Lab 12: Network Communication](https://reader033.vdocuments.mx/reader033/viewer/2022052618/554f3db9b4c905471e8b4b8e/html5/thumbnails/60.jpg)
Kernel Routing Mechanism
• Implements a routing table for first/next hop lookup
• Two distinct portions:1 A data structure with routing entries, one per specific route2 A lookup algorithm to locate the correct route for each possible
destination
• Each destination is represented by a sockaddr structure• Routes are either:
1 Host or network2 Direct or indirect
![Page 61: AOS Lab 12: Network Communication](https://reader033.vdocuments.mx/reader033/viewer/2022052618/554f3db9b4c905471e8b4b8e/html5/thumbnails/61.jpg)
Kernel Routing Mechanism
• Implements a routing table for first/next hop lookup• Two distinct portions:
1 A data structure with routing entries, one per specific route
2 A lookup algorithm to locate the correct route for each possibledestination
• Each destination is represented by a sockaddr structure• Routes are either:
1 Host or network2 Direct or indirect
![Page 62: AOS Lab 12: Network Communication](https://reader033.vdocuments.mx/reader033/viewer/2022052618/554f3db9b4c905471e8b4b8e/html5/thumbnails/62.jpg)
Kernel Routing Mechanism
• Implements a routing table for first/next hop lookup• Two distinct portions:
1 A data structure with routing entries, one per specific route2 A lookup algorithm to locate the correct route for each possible
destination
• Each destination is represented by a sockaddr structure• Routes are either:
1 Host or network2 Direct or indirect
![Page 63: AOS Lab 12: Network Communication](https://reader033.vdocuments.mx/reader033/viewer/2022052618/554f3db9b4c905471e8b4b8e/html5/thumbnails/63.jpg)
Kernel Routing Mechanism
• Implements a routing table for first/next hop lookup• Two distinct portions:
1 A data structure with routing entries, one per specific route2 A lookup algorithm to locate the correct route for each possible
destination
• Each destination is represented by a sockaddr structure
• Routes are either:1 Host or network2 Direct or indirect
![Page 64: AOS Lab 12: Network Communication](https://reader033.vdocuments.mx/reader033/viewer/2022052618/554f3db9b4c905471e8b4b8e/html5/thumbnails/64.jpg)
Kernel Routing Mechanism
• Implements a routing table for first/next hop lookup• Two distinct portions:
1 A data structure with routing entries, one per specific route2 A lookup algorithm to locate the correct route for each possible
destination
• Each destination is represented by a sockaddr structure• Routes are either:
1 Host or network
2 Direct or indirect
![Page 65: AOS Lab 12: Network Communication](https://reader033.vdocuments.mx/reader033/viewer/2022052618/554f3db9b4c905471e8b4b8e/html5/thumbnails/65.jpg)
Kernel Routing Mechanism
• Implements a routing table for first/next hop lookup• Two distinct portions:
1 A data structure with routing entries, one per specific route2 A lookup algorithm to locate the correct route for each possible
destination
• Each destination is represented by a sockaddr structure• Routes are either:
1 Host or network2 Direct or indirect
![Page 66: AOS Lab 12: Network Communication](https://reader033.vdocuments.mx/reader033/viewer/2022052618/554f3db9b4c905471e8b4b8e/html5/thumbnails/66.jpg)
User-space Routing Policies
• Policies add, delete, or modify kernel routing table entries
• A number of routing policies exist, including the RoutingInformation Protocol (RIP)
![Page 67: AOS Lab 12: Network Communication](https://reader033.vdocuments.mx/reader033/viewer/2022052618/554f3db9b4c905471e8b4b8e/html5/thumbnails/67.jpg)
User-space Routing Policies
• Policies add, delete, or modify kernel routing table entries
• A number of routing policies exist, including the RoutingInformation Protocol (RIP)
![Page 68: AOS Lab 12: Network Communication](https://reader033.vdocuments.mx/reader033/viewer/2022052618/554f3db9b4c905471e8b4b8e/html5/thumbnails/68.jpg)
Protocol Control Blocks
• For each TCP or UDP socket, an Internet protocol control block(inpcb) is created to hold address, ports, routing information,and pointers to any additional data structures
• TCP in addition creates a TCP control block (tcpcb) to holdimplementation-specific information
• TCP and UDP protocol modules each have a private doublylinked list of inpcbs
• Common routines are used by the modules to manipulate theselists
• Traffic is multiplexed by the IP layer on the basis of the protocolidentifier in the protocol and passed on to the individual transportprotocol
• Each protocol is then responsible for passing a direct message tothe appropriate socket
![Page 69: AOS Lab 12: Network Communication](https://reader033.vdocuments.mx/reader033/viewer/2022052618/554f3db9b4c905471e8b4b8e/html5/thumbnails/69.jpg)
Protocol Control Blocks
• For each TCP or UDP socket, an Internet protocol control block(inpcb) is created to hold address, ports, routing information,and pointers to any additional data structures
• TCP in addition creates a TCP control block (tcpcb) to holdimplementation-specific information
• TCP and UDP protocol modules each have a private doublylinked list of inpcbs
• Common routines are used by the modules to manipulate theselists
• Traffic is multiplexed by the IP layer on the basis of the protocolidentifier in the protocol and passed on to the individual transportprotocol
• Each protocol is then responsible for passing a direct message tothe appropriate socket
![Page 70: AOS Lab 12: Network Communication](https://reader033.vdocuments.mx/reader033/viewer/2022052618/554f3db9b4c905471e8b4b8e/html5/thumbnails/70.jpg)
Protocol Control Blocks
• For each TCP or UDP socket, an Internet protocol control block(inpcb) is created to hold address, ports, routing information,and pointers to any additional data structures
• TCP in addition creates a TCP control block (tcpcb) to holdimplementation-specific information
• TCP and UDP protocol modules each have a private doublylinked list of inpcbs
• Common routines are used by the modules to manipulate theselists
• Traffic is multiplexed by the IP layer on the basis of the protocolidentifier in the protocol and passed on to the individual transportprotocol
• Each protocol is then responsible for passing a direct message tothe appropriate socket
![Page 71: AOS Lab 12: Network Communication](https://reader033.vdocuments.mx/reader033/viewer/2022052618/554f3db9b4c905471e8b4b8e/html5/thumbnails/71.jpg)
Protocol Control Blocks
• For each TCP or UDP socket, an Internet protocol control block(inpcb) is created to hold address, ports, routing information,and pointers to any additional data structures
• TCP in addition creates a TCP control block (tcpcb) to holdimplementation-specific information
• TCP and UDP protocol modules each have a private doublylinked list of inpcbs
• Common routines are used by the modules to manipulate theselists
• Traffic is multiplexed by the IP layer on the basis of the protocolidentifier in the protocol and passed on to the individual transportprotocol
• Each protocol is then responsible for passing a direct message tothe appropriate socket
![Page 72: AOS Lab 12: Network Communication](https://reader033.vdocuments.mx/reader033/viewer/2022052618/554f3db9b4c905471e8b4b8e/html5/thumbnails/72.jpg)
Protocol Control Blocks
• For each TCP or UDP socket, an Internet protocol control block(inpcb) is created to hold address, ports, routing information,and pointers to any additional data structures
• TCP in addition creates a TCP control block (tcpcb) to holdimplementation-specific information
• TCP and UDP protocol modules each have a private doublylinked list of inpcbs
• Common routines are used by the modules to manipulate theselists
• Traffic is multiplexed by the IP layer on the basis of the protocolidentifier in the protocol and passed on to the individual transportprotocol
• Each protocol is then responsible for passing a direct message tothe appropriate socket
![Page 73: AOS Lab 12: Network Communication](https://reader033.vdocuments.mx/reader033/viewer/2022052618/554f3db9b4c905471e8b4b8e/html5/thumbnails/73.jpg)
Protocol Control Blocks
• For each TCP or UDP socket, an Internet protocol control block(inpcb) is created to hold address, ports, routing information,and pointers to any additional data structures
• TCP in addition creates a TCP control block (tcpcb) to holdimplementation-specific information
• TCP and UDP protocol modules each have a private doublylinked list of inpcbs
• Common routines are used by the modules to manipulate theselists
• Traffic is multiplexed by the IP layer on the basis of the protocolidentifier in the protocol and passed on to the individual transportprotocol
• Each protocol is then responsible for passing a direct message tothe appropriate socket
![Page 74: AOS Lab 12: Network Communication](https://reader033.vdocuments.mx/reader033/viewer/2022052618/554f3db9b4c905471e8b4b8e/html5/thumbnails/74.jpg)
Today’s task
• Design a network subsystem for xv6
![Page 75: AOS Lab 12: Network Communication](https://reader033.vdocuments.mx/reader033/viewer/2022052618/554f3db9b4c905471e8b4b8e/html5/thumbnails/75.jpg)
Reading(s)
• Chapter 12 and 13 from “The Design and Implementation of the4.4BSD Operating System” by Marshall Kirk McKusick, KeithBostic, Michael J. Karels, and John S. Quarterman.