Networking & Network File System
CS-446/646
C. Papachristos
Robotic Workers (RoboWork) Lab
University of Nevada, Reno
Networking Overview
Networking Overview
Computer Networking
Goal
CS446/646 C. Papachristos
Networking Overview
Networking Overview
CS446/646 C. Papachristos
Open Systems Interconnection (OSI) Model | Transmission Control Protocol /Internet Protocol (TCP/IP) Model |
Application | Applications (FTP, SMTP, HTTP, etc.) |
Presentation | |
Session | |
Transport | TCP (Host-to-Host) |
Network | IP |
Data Link | Network access (usually Ethernet) |
Physical |
… also UDP, SCTP
Networking Overview
CS446/646 C. Papachristos
Networking Overview
Data Link Layer – Indirect Connectivity
Role: Definition of Format of data (Packet) on the Network (Device MAC Addresses, Switches)
CS446/646 C. Papachristos
Networking Overview
Data Link Layer : Ethernet
Role: Definition of Format of data (Packet) on the Network (Device MAC Addresses, Switches)
CS446/646 C. Papachristos
Networking Overview
Network Layer : Internet Protocol (IP) Suite
Role: Handles Routing, Logical Addressing (Host IP Addresses, Routers)
CS446/646 C. Papachristos
Networking Overview
Transport Layer : UDP and TCP
Role: Management of End-to-End communication (TCP, UDP)
UDP – User Datagram Protocol
TCP – Transmission Control Protocol
CS446/646 C. Papachristos
Networking Overview
Fundamental Principles: Packet-Switching & Layering
Packet-Switching
Layering
CS446/646 C. Papachristos
Networking Overview
Fundamental Principle: Encapsulation
CS446/646 C. Papachristos
Note:�Term “Packet” is somewhat loosely used sometimes.�More formal term:�
TCP PDU: “Segment”
IP PDU: “Packet”
Ethernet PDU: “Frame”
App PDU: “Message”
Systems Issues
TCP: Unreliability of IP
Note: This is entirely handled by an OS that runs at the End-Nodes
Naïve Approach: Wait for Ack for each Packet
Problems?
CS446/646 C. Papachristos
Systems Issues
TCP: Performance Limitations & Bandwidth-Delay
CS446/646 C. Papachristos
Systems Issues
CS446/646 C. Papachristos
Note:�Term “TCP Packet” is both informal and formal usage. In more precise terminology “Segment” refers to the TCP Protocol Data Unit (PDU), “Packet�/Datagram” to the IP PDU, and “Frame” to the Data Link Layer PDU.
UDP uses “Datagrams” as its PDU for connectionless communication.
Systems Issues
TCP: Implementation OS issues
C. Papachristos
OS Networking Facilities
CS446/646 C. Papachristos
OS Networking Facilities
Socket Naming
CS446/646 C. Papachristos
OS Networking Facilities
System Calls for using TCP
Client
Create a Socket – Obtain a Socket File Descriptor
sockfd = socket(domain, type, protocol);
Assign it a (Protocol-specific sockaddr* ) Address *
bind(sockfd, sockaddr, addrlen);
Connect to listening Socket
connect(sockfd, sockaddr, addrlen);
* This call to bind() is optional; connect() can bind to all�Interfaces and pick some high-numbered Port.�Used if Server restricts Clients to use specific Port (/range), or if�Client with multiple NICs wishes to use specific Address for its traffic.
CS446/646 C. Papachristos
Server
Create a Socket – Obtain a Socket File Descriptor
sockfd = socket(domain, type, protocol);
Assign it a (Protocol-specific sockaddr* ) Address
bind(sockfd, sockaddr, addrlen);
Mark Socket as passive – i.e. listening for Clients
listen(sockfd, backlog);
Accept Connection (can Block if none pending on Queue)
accept(sockfd, sockaddr, addrlen);
…
…
…
… return, Socket ESTABLISHED
Note: Using sockaddr* allows different types of Proto-col-specific structs to be passed (start of struct is Protocol family type information (sa_family_t), rest is Protocol-specific data (char sa_data[])
OS Networking Facilities
System Calls for using UDP
New System Calls for sending individual Packets:
Note: Must send/get Peer Address with each Packet
Alternatively:
CS446/646 C. Papachristos
OS Networking Facilities
Uses of Connected Mode UDP Sockets
CS446/646 C. Papachristos
Implementing Networking in the Kernel
Sockets Implementation (Part I)
CS446/646 C. Papachristos
Implementing Networking in the Kernel
mbuf Details
C. Papachristos
Implementing Networking in the Kernel
Adding/Deleting Data with mbufs
CS446/646 C. Papachristos
Implementing Networking in the Kernel
mbuf Utility Functions
mbuf * m_copym(mbuf * m, int off, int len, int wait);
void m_adj(struct mbuf * mp, int len);
mbuf * m_pullup(struct mbuf * m, int len);
CS446/646 C. Papachristos
Implementing Networking in the Kernel
Sockets Implementation (Part II)
Each struct socket holds associated data:
CS446/646 C. Papachristos
Note: In the Linux Kernel, struct socket is a higher-level data structure for Socket functionalities (e.g. for System Calls), and struct sock is an imple-mentation of Address Family AF_INET (IPv4 Protocol)
Implementing Networking in the Kernel
Protocol Handler: protosw Structure (Linux equivalent: proto_ops)
CS446/646 C. Papachristos
Implementing Networking in the Kernel
protosw Interface Functions (Note: Function Pointers)
CS446/646 C. Papachristos
Implementing Networking in the Kernel
Network Interface Cards (NICs)
CS446/646 C. Papachristos
Implementing Networking in the Kernel
NIC Input Handling
1) NIC Driver figures out Protocol from incoming Packet
2) Enqueue Packet for appropriate Protocol Handler
3) Posts “Soft Interrupt” for Protocol-Layer processing
CS446/646 C. Papachristos
Implementing Networking in the Kernel
Additional OS Responsibility: Routing
Note: Addressing (requires IP & MAC Address – discovered through ARP) is not the same as Routing
CS446/646 C. Papachristos
Network File Systems
Network File System (NFS)
Advantages:
Disadvantages
CS446/646 C. Papachristos
Network File Systems
NFS version 2 [Sandberg]
CS446/646 C. Papachristos
Network File Systems
NFS Implementation
C. Papachristos
Network File Systems
NFS Stateless Operation
Designed for “Stateless Operation”
* Why mostly?
CS446/646 C. Papachristos
Network File Systems
NFS version 3
CS446/646 C. Papachristos
Network File Systems
Prelude: NFS v3 File Handles
CS446/646 C. Papachristos
struct nfs_fh3 {
/* XDR notation for variable-length array with 0-64 opaque bytes: */
opaque data<NFS3_FHSIZE>; /* NFS3_FHSIZE defined as 64 */
};
Network File Systems
Prelude: NFS v3 File Attributes
CS446/646 C. Papachristos
struct fattr3 {
ftype3 type;
uint32 mode;
uint32 nlink;
uint32 uid;
uint32 gid;
uint64 size;
uint64 used;
specdata3 rdev;
uint64 fsid;
uint64 fileid;
nfstime3 atime;
nfstime3 mtime;
nfstime3 ctime;
};
struct post_op_attr {
bool_t attributes_follow;
union {
fattr3 attributes;
} post_op_attr_u;
};
Note: An XDR Discriminated union (RPC Data Description Language)
union post_op_attr switch (bool attributes_follow) {
case TRUE:
fattr3 attributes;
case FALSE:
void;
};
Network File Systems
NFS v3 Lookup
CS446/646 C. Papachristos
struct diropargs3 {
nfs_fh3 dir;
filename3 name;
};
struct LOOKUP3resok {
nfs_fh3 object;
post_op_attr obj_attributes;
post_op_attr dir_attributes;
};
union LOOKUP3res switch (nfsstat3 status) {
case NFS3_OK:
LOOKUP3resok resok;
default:
LOOKUP3resfail resfail;
};
struct LOOKUP3resfail {
post_op_attr dir_attributes;
};
struct LOOKUP3args {
diropargs3 what;
};
Need this:
Network File Systems
NFS v3 Create
union createhow3 switch (createmode3 mode) {
case UNCHECKED:
case GUARDED:
sattr3 obj_attributes;
case EXCLUSIVE:
createverf3 verf;
};
struct CREATE3args {
diropargs3 where;
createhow3 how;
};
enum createmode3 {
UNCHECKED = 0,
GUARDED = 1,
EXCLUSIVE = 2
};
Need this
too:
C. Papachristos
Network File Systems
NFS v3 Read
CS446/646 C. Papachristos
struct READ3args {
nfs_fh3 file;
uint64 offset;
uint32 count;
};
union READ3res switch (nfsstat3 status) {
case NFS3_OK:
READ3resok resok;
default:
READ3resfail resfail;
};
struct READ3resok {
post_op_attr file_attributes;
uint32 count;
bool eof;
opaque data<>;
};
struct READ3resfail {
post_op_attr file_attributes;
};
Network File Systems
NFS v3 Data Caching
Data Caching Algorithm:
CS446/646 C. Papachristos
Network File Systems
C. Papachristos
Network File Systems
NFS v2 Write
struct writeargs {
fhandle file;
unsigned beginoffset;
unsigned offset;
unsigned totalcount;
opaque data<NFS_MAXDATA>;
};
union attrstat switch (stat status) {
case NFS_OK:
fattr attributes;
default:
void;
};
Need this:
CS446/646 C. Papachristos
Network File Systems
NFS v2 Write Race Condition
C. Papachristos
Report back mtime due to A’s write A1
Report back mtime due to A’s write A2
Report back mtime due to B’s write B1
Network File Systems
NFS v3 Write
Two goals for NFS v3 write:
struct WRITE3args {
nfs_fh3 file;
uint64 offset;
uint32 count;
stable_how stable;
opaque data<>;
};
enum stable_how {
UNSTABLE = 0,
DATA_SYNC = 1,
FILE_SYNC = 2
};
union WRITE3res switch (nfsstat3 status)
{
case NFS3_OK:
WRITE3resok resok;
default:
WRITE3resfail resfail;
};
struct WRITE3resok {
wcc_data file_wcc;
count3 count;
stable_how committed;
writeverf3 verf;
};
struct WRITE3resfail {
wcc_data file_wcc;
};
Need this
too:
CS446/646 C. Papachristos
Network File Systems
NFS v3 Write Results
union WRITE3res switch (nfsstat3 status)
{
case NFS3_OK:
WRITE3resok resok;
default:
WRITE3resfail resfail;
};
struct WRITE3resok {
wcc_data file_wcc;
count3 count;
stable_how committed;
writeverf3 verf;
};
struct WRITE3resfail {
wcc_data file_wcc;
};
CS446/646 C. Papachristos
struct wcc_data {
wcc_attr * before;
post_op_attr after;
};
struct wcc_attr {
uint64 size;
nfstime3 mtime;
nfstime3 ctime;
};
Network File Systems
NFS v3 Data Caching after a Write
CS446/646 C. Papachristos
Network File Systems
NFS v3 Write Stability
CS446/646 C. Papachristos
Network File Systems
NFS v3 Commit Operation
CS446/646 C. Papachristos
struct COMMIT3args {
nfs_fh3 file;
uint64 offset;
uint32 count;
};
Network File Systems
NFS v3 Attribute Caching
Note: No OPEN/CLOSE�RPCs, NFS is Stateless
CS446/646 C. Papachristos
Time for Questions !
CS-446/646
CS446/646 C. Papachristos