Professional Documents
Culture Documents
Very Good Material
Very Good Material
11/3/2019 . 1
Block Diagram of the System Kernel
User Program
Kernel Level
System Call Interface
Inter process
Confidentiality MIPv4 Communication
Buffer Cache
Authentication Intra process
MIPv6 Communication
Integrity
character block Scheduler
Scheduler
VoIP & PTT
Nonrepudiation
Support
Memory
Device Driver Management
Access Control
Availability
Hardware Control
Hardware
11/3/2019 . 2
Algorithm Analysis Notations
11/3/2019 . 3
Big O Notation
cg(n)
f(n)
k
Definition: A theoretical measure of the execution of an algorithm,
usually the time or memory needed, given the problem size n, which is
usually the number of items. Informally, saying some equation f(n) =
O(g(n)) means it is less than some constant multiple of g(n).
Formal Definition: f(n) = O(g(n)) means there are positive constants c
and k, such that 0 ≤ f(n) ≤ cg(n) for all n ≥ k. The values of c and k must
be fixed for the function f and must not depend on n.
11/3/2019 . 4
Big ω Notation
f(n)
cg(n)
k
Definition: A theoretical measure of the execution of an algorithm,
usually the time or memory needed, given the problem size n, which is
usually the number of items. Informally, saying some equation f(n) = ω
(g(n)) means g(n) becomes insignificant relative to f(n) as n goes to
infinity.
Formal Definition: f(n) = ω (g(n)) means that for any positive constant
c, there exists a constant k, such that 0 ≤ cg(n) < f(n) for all n ≥ k. The
value of k must not depend on n, but may depend on c.
11/3/2019 . 5
Big Θ Notation
c2g(n) f(n)
c1g(n)
k
Definition: A theoretical measure of the execution of an algorithm,
usually the time or memory needed, given the problem size n, which is
usually the number of items. Informally, saying some equation f(n) = Θ
(g(n)) means it is within a constant multiple of g(n). The equation is read,
"f of n is theta g of n".
Formal Definition: f(n) = Θ (g(n)) means there are positive constants
c1, c2, and k, such that 0 ≤ c1g(n) ≤ f(n) ≤ c2g(n) for all n ≥ k. The values
of c1, c2, and k must be fixed for the function f and must not depend on
n.
11/3/2019 . 6
Process Management
11/3/2019 . 7
Process Definition
11/3/2019 . 8
Process State & Transition
User
Running
Trap/interrupt return
Interrupt/Interrupt
Return
Kernel
Schedule
sleep Process
Wakeup Ready to
Sleep
run
11/3/2019 . 9
Process Structure
text
Data
Stack
11/3/2019 . 10
Data structure for a process
Process table
text
data
stack
memory
11/3/2019 . 11
File System
11/3/2019 . 12
File System Definition
11/3/2019 . 13
File System Architecture for UNIX
tty00 tty01
mike
jim
y
z x
11/3/2019 . 14
File System Layout
User File Descriptor: For each process. identify all open files for
specific process
File table: Shared between all processes in the system . Contains
how many bytes read or written, access rights allowed for the file
11/3/2019 . 16
Intra process communication
11/3/2019 . 17
signals
1. Signals are limited form of IPC that are used to notify a process that a given
event has taken place.
2. Each signal has a unique positive integer representing it as well as a symbolic
name (that is usually defined in the file /usr/include/signal.h.
3. Amount of information that can be conveyed via a signal is very limited
(basically only the signal number).
11/3/2019 . 18
signals (continue)
11/3/2019 . 19
Sending Signals
1. Using the keyboard: the Ctrl-C key causes the operating system to send a
SIGINT signal to the running process
2. From the command line: kill -INT 3333
3. Using system calls:
#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 kill() prototype */
/* first, find my own process ID */
pid_t my_pid = getpid(); /* now that i got my PID, send myself the SIGSTOP signal. */
int rc = kill(my_pid, SIGSTOP);
if (rc != 0) /* unsuccessful */
{
printf ("The \"kill\" system call failed with rc: %d\n", rc);
}
11/3/2019 . 20
Catching Signals
#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 */
/* The signal handler definition. */
void sigintHandler(int sig_num) { /* Register signal handler for SIGINT next time */
signal(SIGINT, sigintHandler); /* Print the message */
printf ("Don't you dare interrupt me\n");
}
/* The main function. */
int main (int argc, char* argv[]) {
/* Register signal handler for SIGINT */
signal(SIGINT, sigintHandler);
/* Go into an infinite loop */
for ( ;; ) pause();
}
11/3/2019 . 21
pipes
Fd[1] Fd[0]
write read
P1 P2
11/3/2019 . 22
Pipes (continue)
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <unistd.h>
int main()
{
int pfds[2];
char buf[30];
if (pipe(pfds) == -1)
{
perror("pipe");
exit(1);
}
printf ("writing to file descriptor #%d\n", pfds[1]);
write(pfds[1], "test", 5);
printf ("reading from file descriptor #%d\n", pfds[0]);
read(pfds[0], buf, 5);
printf ("read \"%s\“ \n", buf);
}
11/3/2019 . 23
message queues
msgsnd msgrcv
P1 P2
11/3/2019 . 24
msgsnd & msgrcv example
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/msg.h>
#define MSGKEY 75
struct msgform{
long msgtype;
char mtext [256];
}
main ()
{
struct msgform msg;
int msgid, pid;
pid = getpid ();
msg.mtext [0] = pid;
msg.mtype = 1;
msgid = msgget (MSGKEY,0777);
msgsend (msgid, &msg,sizeof (int),0);
msgrcv (msgid, &msg,256,pid,0);
}
11/3/2019 . 25
Shared memory example (continue)
Shared memory
strncpy strncpy
P1 P2
11/3/2019 . 26
Shared memory example
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#define SHM_SIZE 1024 /* make it a 1K shared memory segment */
int main (int argc, char *argv[])
{
key_t key;
int shmid;
char *data;
int mode;
/* make the key: */
if ((key = ftok ("shmdemo.c", 'R')) == -1) {
perror("ftok");
exit(1);
}
11/3/2019 . 27
Shared memory (continue)
11/3/2019 . 28
sockets
Fd[1] Fd[0]
write read
P1 P2
11/3/2019 . 29
UDP Socket system calls for client/server
socket socket
connect bind
write read
read write
close
close
11/3/2019 . 30
Conceptual OS Data Structure for UDP socket
Family : PF_INET
File Descriptor Table
One per process Service: SOCK_DGRAM
Local IP: 47.12.121.13
stdin Local port: 5000
stdout
stderr
11/3/2019 . 31
TCP Socket system calls for client/server
Client Side Server Side
socket socket
connect bind
write listen
read accept
close read
write
close
11/3/2019 . 32
Conceptual OS Data Structure for TCP socket
Family : PF_INET
File Descriptor Table
One per process Service: SOCK_STREAM
Local IP: 47.12.121.13
stdin Remote IP: 47.12.121.100
stdout
Local Port: 5000
stderr
Remote Port: 5100
11/3/2019 . 33
UDP/TCP Server
#include <sys/types.h>
#include <sys/socket.h >
#include <netinet/in.h>
#include <arpa/inet.h >
#include <netdb.h >
#include <stdio.h>
#include <unistd.h> /* close() */
#include <string.h> /* memset() */
#define LOCAL_SERVER_PORT 1500
#define MAX_MSG 100
int server (char *protocol,int argc, char *argv[]) {
int sd, rc, n, cliLen;
struct sockaddr_in servAddr;
char msg[MAX_MSG]; /* socket creation */
if (strcmp (protocol, ”udp”) == 0)
sd =socket (AF_INET, SOCK_DGRAM, 0);
else
sd =socket (AF_INET, SOCK_STREAM, 0);
/* bind local server port */
servAddr.sin_family = AF_INET;
servAddr.sin_addr.s_addr = htonl(INADDR_ANY);
servAddr.sin_port = htons(LOCAL_SERVER_PORT);
rc = bind (sd, (struct sockaddr *) &servAddr,sizeof(servAddr));
if (strcmp (protocol, ”udp”) != 0)
listen (sd,5);
return sd;
}
11/3/2019 . 34
UDP/TCP Client
#include <sys/types.h>
#include <sys/socket.h >
#include <netinet/in.h>
#include <arpa/inet.h >
#include <netdb.h >
#include <stdio.h>
#include <unistd.h> /* close() */
#include <string.h> /* memset() */
#define REMOTE_SERVER_PORT 1500
int client (int protocol,int argc, char *argv[]) {
int sd, rc, i;
struct sockaddr_in sin;
struct hostent *h;
/* get server IP address*/
h = gethostbyname(argv[1]);
sin.sin_family = h->h_addrtype; // AF_INET
memcpy ((char *) &sin.sin_addr.s_addr, h->h_addr_list[0], h->h_length);
sin.sin_port = htons(REMOTE_SERVER_PORT);
/* socket creation */
if (strcmp (“udp”, protocol) == 0)
sd = socket(AF_INET,SOCK_DGRAM,0);
else
sd = socket(AF_INET,SOCK_STREAM,0);
if ((rc = connect (sd, (struct sockaddr *) &sin, sizeof(sin))<0)
return -1;
return sd;
}
11/3/2019 . 35
UDP Server
11/3/2019 . 37
Inter process communication protocols
11/3/2019 . 38
Protocol Stack
Application (MIPv4)
Transport (UDP,TCP)
Kernel
Internet Protocol (MIP6,MIPv4,IP4,IP6)
Physical Layer
11/3/2019 . 39
TCP Protocol Procedure
11/3/2019 . 40
TCP- Transport Communication Protocol
11/3/2019 . 41
TCP Connection Opened
User A User B
11/3/2019 . 42
TCP Connection Closed
User A User B
Connection Closed
11/3/2019 . 43
TCP Sliding Window
Initial window
1 2 3 4 5 6 7 8 9 10
Window slides
1 2 3 4 5 6 7 8 9 10
11/3/2019 . 44
TCP Positive Acknowledgement
User A User B
Send Packet 1
Send Packet 2
Send Packet 3
Recv Packet 1
Send ACK1
Recv Packet 2
Send ACK 2
Recv Packet 3
Send ACK 3
Recv Ack 1
Recv Ack 2
Recv Ack 3
11/3/2019 . 45
UDP Protocol
11/3/2019 . 46
User Datagram Protocol (UDP)
p1 p1
p2 p2
Host:: x2.y2.z2.w2
Host:: x1.y1.z1.w1 p3 p3
11/3/2019 . 47
UDP Header
Data
11/3/2019 . 48
UDP Checksum
= If changed or not
11/3/2019 . 49
IP4 Protocol
11/3/2019 . 50
Type of Addresses for IPv4
Unicast Address
11/3/2019 . 51
Type of Addresses for IPv4 (continue)
Broadcast Address
11/3/2019 . 52
Type of Addresses for IPv4 (continue)
Multicast Address
Source IP Address
Destination IP Address
Data
11/3/2019 . 54
TOS field description
11/3/2019 . 55
IPv4 Header Checksum
Destination IP Address
Data
11/3/2019 . 57
Type of Addresses for IPv6
Unicast Address
11/3/2019 . 58
Type of Addresses for IPv6 (continue)
Anycast Address
11/3/2019 . 59
Type of Addresses for IPv6 (continue)
Multicast Address
01234567012345670123456701234567
Version Traffic Class Flow Label
11/3/2019 . 61
Order of Extension Header
IPv6 Header
Hop-By-Hop Processed by all the intermediate Nodes
AH
ESP
for options to be processed only by the final
Destination Header destination of the packet.
Upper Layer Header
e.g. UDP TCP ICMP
11/3/2019 . 62
Routing Header
01234567012345670123456701234567
Type-specific data
11/3/2019 . 63
Routing Header (continue)
01234567012345670123456701234567
Type-specific data
11/3/2019 . 64
Routing Header Routing Type = 0 (continue)
01234567012345670123456701234567
Routing Header
Next Header Hdr Ext Len =0 Segment Left
11/3/2019 . 65
IPv4 vs IPv6
11/3/2019 . 66
Acronym
HA Home Agent
FA Foreign Agent
HoA Home IP Address.
CCoA collocated Care-of Address
FCoA Foreign Agent Care-of Address.
MIPv4 Mobile IP version 4.
MIPv6 Mobile IP version 6.
MN Mobile Node.
CN Correspondent Node.
11/3/2019 . 67
Mobility Problem
Mobile Node
move
電電電
Router
Home Agent 電電
Correspondent Node
11/3/2019 . 68
MIP Conceptual Model
HoA CoA
MN
HA
Interne
t
Visiting Network
Home Network
CN
11/3/2019 . 69
MIPv4
11/3/2019 . 70
MIP4: Protocol Stack
Application (MIPv4)
Transport (UDP,TCP)
Kernel
Internet Protocol (MIP4,IP4)
Physical Layer
11/3/2019 . 71
MIP4:Registration With Home Agent- CCoA –Ref [1]
MN
RRQ
CCoA
RRP
IP4
FA HA
Foreign Network
Home Network
CN
11/3/2019 . 72
MIP4:Forward Traffic-FCoA
MN
CoA
IP4
FA HA
Foreign Network
Home Network
Outer IP Header: 2 CN
•Src = HAIP
•Dst = FCoA 1
IP header
Inner IP header •Src = CNIP
•Src = CNIP •Dst = HoA
•Dst = HoA
11/3/2019 . 73
MIP4:Forward Traffic-Tunneling-CCoA
MN
CCoA
IP4
HA
Foreign Network
Home Network
Outer IP Header: 2 CN
•Src = HAIP
•Dst = CCoA 1
IP header
Inner IP header •Src = CNIP
•Src = CNIP •Dst = HoA
•Dst = HoA
11/3/2019 . 74
MIP4:Reverse Traffic-FCoA
MN
FCoA
IP4
HA
Foreign Network FA Home Network
1 CN
IP header
•Src = HoA
•Dst = CNIP
11/3/2019 . 75
MIP4:Reverse Traffic-CCoA
MN
CCoA
IP4
HA
Foreign Network FA Home Network
IP header 1 CN
•Src = CCoA
•Dst = CNIP
11/3/2019 . 76
MIP4:Reverse Traffic-Tunneling-FCoA
MN
FCoA
IP4
HA
Foreign Network FA Home Network
Outer IP Header: 1 CN
•Src = FCoA
•Dst = HAIP 2
IP header
Inner IP header •Src = HoA
•Src = HoA •Dst = CNIP
•Dst = CNIP
11/3/2019 . 77
MIP4:Reverse Traffic-CCoA
MN
CCoA
IP4
HA
Foreign Network
Home Network
Outer IP Header: 1 CN
•Src = CCoA
•Dst = HAIP 2
IP header
Inner IP header •Src = HoA
•Src = HoA •Dst = CNIP
•Dst = CNIP
11/3/2019 . 78
MIP4:Going Back Home
MN
Agent
Advertisement
Gratuitous ARP
RRQ [lifetime=0]
gratuitous ARP
RRP[lifetime = 0]
IP6
HA
Foreign Network
Home Network
CN
11/3/2019 . 79
MIP4:Security
MN
MN-HA AE
FCoA
MN-FA AE
IP4
FA HA
Foreign Network
Home Network
FA-HA AE
11/3/2019 . 80
MIP4:Authentication Calculation
UDP payload
Message Digest
SPI HMAC_MD5
Auth Type
11/3/2019 . 81
MIP4: Registration With Home Agent-FCoA –Ref [1]
MN
FCoA RRQ(HoA,FCoA,HA)
Gratuitous ARP
IP4
RRP(HoA,FCoA,HA)
FA HA
Foreign Network
Home Network
CN
11/3/2019 . 82
MIP4:Registration With Dynamic HoA Allocation –Ref [3]
MN
FCoA
RRQ(NAI,HoA=?,FCoA,HA)
IP4
RRP(NAI,HoA,FCoA,HA)
FA HA
Foreign Network
Home Network
CN
11/3/2019 . 83
MIP4: Registration With Dynamic HA Allocation –Ref [2]
MN
FCoA
RRQ(NAI,HoA,FCoA,HA=?)
IP4
RRP(NAI,HoA,FCoA,HA)
FA HA
Foreign Network
Home Network
CN
11/3/2019 . 84
MIP4:Registration With Dynamic HA Allocation-Ref [2] (Cont)
MN
RRQ(NAI,HoA,FCoA,HA=?)
FCoA
RRP(NAI,HoA,FCoA,HA=HA2) HA1
RRQ(NAI,HoA,FCoA,HA=HA2)
IP4
Foreign Network
FA RRP(NAI,HoA,FCoA,HA=HA2) HA2
Home Network
CN
11/3/2019 . 85
MIP4:Registration With Dynamic HA & HoA Allocation –Ref [2],[3]
MN
FCoA
RRQ(NAI,HoA=?,FCoA,HA=?)
IP4
RRP(NAI,HoA,FCoA,HA)
FA HA
Foreign Network
Home Network
CN
11/3/2019 . 86
MIPv6
11/3/2019 . 87
Registration With Home Agent
MN HoA
BU
CoA
BA
Interne
t HA
Foreign Network
Home Network
CN
11/3/2019 . 88
Bidirectional Tunneling -Forward Traffic
HoA
MN
CoA
Interne
t HA
Foreign Network
Home Network
Outer IP Header: 2 CN
•Src = HAIP
•Dst = CoA 1
IP header
Inner IP header •Src = CNIP
•Src = CNIP •Dst = HoA
•Dst = HoA
11/3/2019 . 89
Bidirectional Tunneling –Reverse Traffic
HoA
MN
CoA
Interne
t HA
Foreign Network
Home Network
Outer IP Header: 1
•Src = CoA CN
•Dst = HAIP 2
IP header
Inner IP header •Src = HoA
•Src = HoA •Dst = CNIP
•Dst = CNIP
11/3/2019 . 90
Route Optimization-Forward Traffic
HoA
MN
CoA
Interne
t HA
Foreign Network
Home Network
CN
IP Header: 1
2 •Src = CNIP
IP Header:
•Src = CNIP •Dst = CoA
•Dst = HoA Type 2 Routing Header
• HoA
11/3/2019 . 91
Route Optimization-Reverse Traffic
HoA
MN
CoA
Interne
t HA
Foreign Network
Home Network
IP Header:
1 CN
•Src = CoA IP Header: 2
•Dst = CNIP •Src = HoA
Destination Option Header •Dst = CNIP
•Home Address Option with HoA
11/3/2019 . 92
Basic Address Stealing
MN CN Victim
attacker
11/3/2019 . 93
Round Routability
HoA
MN
1 HoTI
2 HoT
CoA
Interne
t HA
Foreign Network 1
Home Network
2
3
4
1
CN
2
11/3/2019 . 94