NP&ACN
NP&ACN
NP&ACN
struct sockaddr_in {
uint8_t sin_len; /* length of structure(16) */
sa_family_t sin_family; /* AF_INET */
in_port_t sin_port; /* 16bit TCP or UDP port number */ /*network byte ordered*/
struct sockaddr_in6 {
uint8_t sin6_len; /* length of structure(24) */
sa_family_t sin6_family; /* AF_INET6*/
in_port_t sin6_port; /* Transport layer port# */ /*network byte ordered*/
uint32_t sin6_flowinfo; /* priority & flow label */ /*network byte ordered*/
struct in6_addr sin6_addr; /* IPv6 address */ /*network byte ordered*/
}; /* included in <netinet/in.h> */
const char *inet_ntop(int family, const void *addrptr, char *strpt, size_t len);
/* return : pointer to result if OK, NULL onerror */
/* len : size of the destination */
/* binary value to a string value */
Dr. Ramakrishna M, Dept. of I&CT, MIT, MAHE, Manipal
Dr. Ramakrishna M, Dept. of I&CT, MIT, MAHE, Manipal
Elementary Socket Functions
Dr. Ramakrishna M
socket socket
Operating Operating
System System
Dr. Ramakrishna M, Dept. of I&CT, MIT, MAHE, Manipal
Two Types of Application Processes
Communication
• Datagram Socket (UDP)
• Collection of messages
• Best effort
• Connectionless
Process Process
A B
port X port Y Port Number
TCP/UDP Protocol
Host Address
IP
Ethernet Adapter
“Site Dr.
under construction
Ramakrishna M, Dept. of I&CT, MIT,”
MAHE, Manipal
Client-Server Communication
• Client “sometimes on” • Server is “always on”
• Initiates a request to the server • Handles services requests from
when interested many client hosts
• E.g., Web browser on your laptop • E.g., Web server for the
or cell phone www.cnn.com Web site
• Doesn’t communicate directly • Doesn’t initiate contact with the
with other clients clients
• Needs to know server’s address • Needs fixed, known address
• Server Process
• process that waits to be contacted
Connect to server
Accept connection
Send response
Dr. Ramakrishna M, Dept. of I&CT, MIT, MAHE, Manipal Receive response
Client-Server Communication
Stream Sockets (TCP): Connection-oriented
BIND
SOCKET
LISTEN
CONNECT
SEND RECEIVE
SEND
RECEIVE
Send response
Receive response
SEND
RECEIVE
SEND
CLOSE
#include "unp.h"
ssize_t readn(int filedes, void *buff, size_t nbytes);
ssize_t writen(int filedes, const void *buff, size_t nbytes);
ssize_t readline(int filedes, void *buff, size_t maxlen);
/*All return: number of bytes read or written, –1 on error*/
1 #include "unp.h"
2 ssize_t /* Write "n" bytes to a descriptor. */
3 writen(int fd, const void *vptr, size_t n)
4 {
5 size_t nleft;
6 ssize_t nwritten;
7 const char *ptr;
8 ptr = vptr;
9 nleft = n;
10 while (nleft > 0) {
11 if ( (nwritten = write(fd, ptr, nleft)) <= 0) {
12 if (nwritten < 0 && errno == EINTR)
13 nwritten = 0; /* and call write() again */
14 else
15 return (-1); /* error */
16 }
17 nleft -= nwritten;
18 ptr += nwritten;
19 }
20 return (n);
21 } Dr. Ramakrishna M, Dept. of I&CT, MIT, MAHE, Manipal
1 # include "unp.h"
2 static int read_cnt;
3 static char *read_ptr;
4 static char read_buf[MAXLINE];
5 static ssize_t
6 my_read(int fd, char *ptr)
7 {
8 if (read_cnt <= 0) {
9 again:
10 if ( (read_cnt = read(fd, read_buf, sizeof(read_buf))) < 0) {
11 if (errno == EINTR)
12 goto again;
13 return (-1);
14 } else if (read_cnt == 0)
15 return (0);
16 read_ptr = read_buf;
17 }
18 read_cnt--;
19 *ptr = *read_ptr++;
20 return (1);
21 } Dr. Ramakrishna M, Dept. of I&CT, MIT, MAHE, Manipal
22 ssize_t
23 readline(int fd, void *vptr, size_t maxlen)
24 {
25 ssize_t n, rc;
26 char c, *ptr;
27 ptr = vptr;
28 for (n = 1; n < maxlen; n++) {
29 if ( (rc = my_read(fd, &c)) == 1) {
30 *ptr++ = c;
31 if (c == '\n')
32 break; /* newline is stored, like fgets() */
33 } else if (rc == 0) {
34 *ptr = 0;
35 return (n - 1); /* EOF, n - 1 bytes were read */
36 } else
37 return (-1); /* error, errno set by read() */
38 }
39 *ptr = 0; /* null terminate like fgets() */
40 return (n);
41 }
bind() “well-known”
port
listen()
Client
accept()
socket()
(Block until connection) “Handshake”
connect()
Data (request)
send()
recv()
Data (reply)
send()
recv()
close()
close()
Dr. Ramakrishna M, Dept. of I&CT, MIT, MAHE, Manipal
connect()
• int connect(int sockfd, const struct sockaddr *servaddr, socklen_t
addrlen);
• Connect to the server
• sockfd is socket descriptor from socket()
• servaddr is a pointer to a structure with:
• port number and IP address
• must be specified (unlike bind())
• addrlen is length of structure
• client doesn’t need bind()
• OS will pick ephemeral port
• returns socket descriptor if ok, -1 on error
• Return error
• ETIMEOUT : no response from server
• RST : server process is not running
• EHOSTUNREACH : client’s SYN unreachable
from some intermediate router.
recvfrom() socket()
(Block until receive datagram) Data (request)
sendto()
sendto() recvfrom()
Data (reply)
- No “handshake” close()
- No simultaneous close
- No fork()/spawn() for M,
Dr. Ramakrishna concurrent servers!
Dept. of I&CT, MIT, MAHE, Manipal
Sending and Receiving
• int recvfrom(int sockfd, void *buff, size_t
mbytes, int flags, struct sockaddr *from,
socklen_t *addrlen);
#include <unistd.h>
int execl(const char *pathname, const char *arg(), …/*(char *) 0*/);
int execv(const char *pathname, char *const argv[]);
int execle(const char *pathname, const char *arg());
int execve(const char *pathname, char *const argv[], char *const envp[]);
int execlp(const char *filename, const char *arg());
int execvp(const char *filename, char *const argv[]);
int flags;
if ( (flags = fcntl(fd, F_GETFL, 0) ) < 0)
error_sys (“F_GETFL error”);
application
code
UDP
call return
request
resolver local other
code name name
UDP server servers
reply
resolver resolver functions:
configuration gethostbyname/gethostbyaddr
files name server: BIND
(Berkeley Internet Name Domain)
static hosts files (DNS alternatives):
/etc/hosts
resolver configuration file (specifies name server IPs):
/etc/resolv.conf
Dr. Ramakrishna M, Dept. of I&CT, MIT, MAHE, Manipal
gethostbyname Function
performs a DNS query for an A record or a AAAA record
#include <netdb.h>
struct hostent *gethostbyname (const char *hostname);
returns: nonnull pointer if OK, NULL on error with h_errno set
struct hostent {
char *h_name; /* official (canonical) name of host */
char **h_aliases; /* ptr to array of ptrs to alias names */
int h_addrtype; /* host addr type: AF_INET or AF_INET6 */
int h_length; /* length of address: 4 or 16 */
char **h_addr_list; /* ptr to array of ptrs with IPv4/IPv6 addrs */
};
#define h_addr h_addr_list[0] /* first address in list */
in/6_addr { }
IP addr #1
in/6_addr { }
IP addr #2
NULL in/6_addr { }
IP addr #3
RES_USE_INET6 option
off on
gethostbyname A record AAAA record
(host) or A record returning
IPv4-mapped IPv6 addr
gethostbyname2 A record A record returning
(host, AF_INET) IPv4-mapped IPv6 addr
gethostbyname2 AAAA record AAAA record
(host, AF_INET6)
TCP UDP
IPv4 mapped
Address IPv4 IPv6
returned by
accept or
recvfrom
IPv4 IPv6
IPv4 Dr.datagram
Ramakrishna M, Dept. of I&CT, MIT, IPv6 datagram
MAHE, Manipal
IPv6 client, IPv4 server
• IPv4 server start on an IPv4 only host and create an IPv4 listening
socket
• IPv6 client start, call gethostbyname. IPv4 mapped IPv6 address is
returned.
• Using IPv4 datagram
TCP UDP
IPv4 IPv6
IPv4 Dr.datagram
Ramakrishna M, Dept. of I&CT, MIT, IPv6 datagram
MAHE, Manipal
IPv6 Address Testing Macros
• There are small class of IPv6 application that must know whether they
are talking to an IPv4 peer.
• These application need to know if the peer’s address is an IPv4-
mapped IPv6 address.
• Twelve macro defined
int af;
socklen_t clilen;
struct sockaddr_int6 cli; /* IPv6 struct */
struct hostent *ptr;
af = AF_INT6;
setsockopt(STDIN_FILENO, IPPROTO_IPV6, IPV6_ADDRFORM, &af, sizeof(af));
clilen = sizeof(cli);
getpeername(0, &cli, &clilen);
ptr = gethostbyaddr(&cli.sin6_addr, 16, AF_INET);
Dr. Ramakrishna M, Dept. of I&CT, MIT, MAHE, Manipal
• setsockopt => change the Address format of socket from IPv4 to IPv6.
• Return value is AF_INET or AF_INET6
• getpeername =>return an IPv4-mapped IPv6 address
#include <netdb.h>
struct hostent *gethostbyaddr (const char *addr, size_t len, int family);
returns: nonnull pointer if OK, NULL on error with h_errno set
• Since a daemon does not have a controlling terminal, it needs some way to
output message when something happens, either normal informational
messages, or emergency messages that need to be handled by an
administrator.
• We could send log messages to the syslogd daemon from our daemons by
creating a Unix domain datagram socket and sending our messages to the
pathname that the daemon has bound, but an easier interface is the syslog
function.
#include <syslog.h>
void syslog(int priority, const char *message, . . . );
#include <syslog.h>
void openlog(const char *ident, int options, int facility);
void closelog(void);
listen()
For each service listed in the
/etc/inetd.conf file
select()
for readability
accpet()
( if TCP socket)
fork()
parent child
setgid()
setuid()
( if user not root)
exec() server
Multicast
FF00::/8
• Scope is a 4-bit field used to define the range of the multicast packet.
• Scope (partial list):
• 0 Reserved
• 1 Interface-Local scope
• 2 Link-Local scope
• 5 Site-Local scope
• 8 Organization-Local
scope
• E Global scope
• Flag
• 0 - Permanent, well-known multicast address assigned by IANA.
• Includes both assigned and solicited-node multicast addresses.
• 1 - Non-permanently-assigned, “dynamically" assigned multicast
address.
• An example might be FF18::CAFE:1234, used for a multicast
application with organizational scope.
• The API support for multicasting requires only five new socket options.
• Figure 19.7
#include “unp.h”
int mcast_join(int sockfd, const struct sockaddr *addr, socklen_t salen, const char
*ifname, u_int ifindex);
int mcast_leave(int sockfd, const struct sockaddr *addr, socklen_t salen);
int mcast_set_if(int sockfd, const char *ifname, u_int ifindex);
int mcast_set_loop(int sockfd, int flag);
int mcast_set_ttl(int sockfd, int ttl);
All above return :0 if ok, -1 on error
int mcast_get_if(int sockfd);
return : nonnegative interface index if OK, -1 error
int mcast_get_loop(int sockfd);
return : current loopback flag if OK, -1 error
int mcast_get_ttl(int sockfd);
return : current TTL or hop limit if OK, -1 error
• Sites on Mbone
• run sdp program
• receives these announcements
• provides an interactive user interface that displays the information
• lets user send announcements
• A sample program
• only receives these session announcements to show an example of a simple
multicast receiving program
Dr. Ramakrishna M, Dept. of I&CT, MIT, MAHE, Manipal
The program receiving the periodic SAP/SDP announcements
#include "unp.h"
#define SAP_NAME "sap.mcast.net" /* default group name and port */
#define SAP_PORT "9875"
void loop(int, socklen_t);
int main(int argc, char **argv)
{
int sockfd;
const int on = 1;
socklen_t salen;
struct sockaddr *sa;
if (argc == 1)
sockfd = Udp_client(SAP_NAME, SAP_PORT, (void **) &sa, &salen);
else if (argc == 4)
sockfd = Udp_client(argv[1], argv[2], (void **) &sa, &salen);
else err_quit("usage: mysdr <mcast-addr> <port#> <interface-name>");
Setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on));
Bind(sockfd, sa, salen);
Mcast_join(sockfd, sa, salen, (argc == 4) ? argv[3] : NULL, 0);
loop(sockfd, salen); /* receive and print */
exit(0);
}
void
recv_all(int recvfd, socklen_t salen)
{
int n;
char line[MAXLINE+1];
socklen_t len;
struct sockaddr *safrom;
safrom = Malloc(salen);
for ( ; ; ) {
len = salen;
n = Recvfrom(recvfd, line, MAXLINE, 0, safrom, &len);
Courtesy: http://www.cs.wisc.edu/~pb/640/multicast.ppt
S S
R R
R R
A B D F
C E
R R
Receiver 1 Receiver 2
Dr. Ramakrishna M, Dept. of I&CT, MIT, MAHE, Manipal
Shared distribution tree
Source S1
Notation: (*, G)
* = all sources
G = Group
Shared Root
A B D F S2
C E
R R
Receiver 1 Receiver 2
Dr. Ramakrishna M, Dept. of I&CT, MIT, MAHE, Manipal
Source tree characteristics
• Source tree
• More memory O (G x S ) in routers
• Optimal path from source to receiver, minimizes delay
• Good for
• Small number of senders, many receivers such as radio broadcasting
application
S Source
DF
R1
Receiver 1
S datagram
Source
DF
R1
Receiver 1
S datagram
Source
IGMP DVMRP-Prune
DF
R1
Receiver 1
S datagram
Source
DF X
Y
R1
Receiver 1
S datagram
Source
IGMP DVMRP-Graft
DF X
Y
R1
R2
Receiver 1
Receiver 2
Dr. Ramakrishna M, Dept. of I&CT, MIT, MAHE, Manipal
DVMRP (4)
New branch source tree
S datagram
Source
IGMP DVMRP-Graft
DF X
Y
R1
R2
Receiver 1
Receiver 2
Dr. Ramakrishna M, Dept. of I&CT, MIT, MAHE, Manipal
Internet Group
Management Protocol
Objectives
Upon completion you will be able to:
Teleconferencing
Distance Learning
Dissemination of News
Message Format
Joining a Group
Leaving a Group
Monitoring Membership
Solution
The events occur in this sequence:
a. Time 12: The timer for 228.42.0.0 in host A expires and a
membership report is sent, which is received by the router and every
host including host B which cancels its timer for 228.42.0.0.
Note that if each host had sent a report for every group in its
list, there would have been seven reports; with this strategy
only four reports are sent.
S Source
A B
G
C D F
E I
R1
R2
Receiver 1
Receiver 2
Dr. Ramakrishna M, Dept. of I&CT, MIT, MAHE, Manipal
PIM-DM(2)
prune non-RPF p2p link
S IGMP PIM-Prune
Source
A B
G
C D F
E I
R1
R2
Receiver 1
Receiver 2
Dr. Ramakrishna M, Dept. of I&CT, MIT, MAHE, Manipal
PIM-DM(3)
C and D Assert to Determine
Forwarder for the LAN, C Wins
S IGMP PIM-Assert
Source
with its own IP address
A B
G
C D F
E I
R1
R2
Receiver 1
Receiver 2
Dr. Ramakrishna M, Dept. of I&CT, MIT, MAHE, Manipal
PIM-DM(4)
I, E, G send Prune
H send Join to override G’s Prune
S IGMP PIM-Prune
Source
IGMP PIM-Join
A B
G
C D F
E I
R1
R2
Receiver 1
Receiver 2
Dr. Ramakrishna M, Dept. of I&CT, MIT, MAHE, Manipal
PIM-DM(5)
I Gets Pruned E’s Prune is Ignored (since R1 is a receiver)
G’s Prune is Overridden (due to new receiver R2)
S Source
A B
G
C D F
E I
R1
R2
Receiver 1
Receiver 2
Dr. Ramakrishna M, Dept. of I&CT, MIT, MAHE, Manipal
PIM-DM(6) New Receiver, I send Graft
S IGMP PIM-Graft
Source
A B
G
C D F
E I
R1
R2
Receiver 1
R3 Receiver 2
Dr. Ramakrishna M, Dept. of I&CT, MIT, MAHE, Manipal
Receiver 3
PIM-DM(6) new branch
S IGMP PIM-Graft
Source
A B
G
C D F
E I
R1
R2
Receiver 1
R3 Receiver 2
Dr. Ramakrishna M, Dept. of I&CT, MIT, MAHE, Manipal
Receiver 3
Raw Sockets
Dr. Ramakrishna M
struct iovec {
void * iov_base; // starting address of buffer
size_t iov_len; // size of buffer
};
Socket ( AF_INET,
SOCK_STREAM, Identify TCP
IPPROTO_TCP) Socket Type
Socket ( AF_INET,
SOCK_RAW, Identify IP
IPPROTO_ICMP) Socket Type
Socket ( AF_PACKET,
SOCK_RAW, Identify Ethernet
htons(ETH_P_IP)) Socket Type
• * More later
Calling population
• Queueing models provide the analyst with a powerful tool for designing and evaluating
the performance of queueing systems.
• Typical measures of system performance
• Server utilization, length of waiting lines, and delays of customers
• For relatively simple systems: compute mathematically
• For realistic models of complex systems: simulation is usually required
• Unlimited capacity, e.g., concert ticket sales with no limit on the number of
people allowed to wait to purchase tickets.
• The total arrival process is the superposition of the arrival times of all customers.
• One important application of finite models is the machine-repair problem. Machines
are the customers and runtime is time to failure. When a machine fails, it “arrives” at
the queueing system and remains there until it is served. Time to failure is
chracterized by exponential, Weibull and Gamma distributions.
Assumption:Allways
sufficient supply of
raw material.
Dr. Ramakrishna M, Dept. of I&CT, MIT, MAHE, Manipal
Optical Links
Dr. Ramakrishna M
SONET
Metro Metro
Network Network
transport network
PON
Access Access Access Access
Network Network Network Network
Bandwidth
Dr. Ramakrishna M, Dept. of I&CT, MIT, MAHE, Manipal
Optical Fiber Core Cladding
Distortion
Loss of Energy
Optical Amplifier
Shape Distortion
Dispersion Compensation Unit (DCU) Phase Variation
t t
Loss of Timing (Jitter)
Optical-Electrical-Optical (OEO) cross-connect
Optical
sourceDr. Ramakrishna M, Dept. of I&CT, MIT, MAHE, Manipal
Dr. Ramakrishna M, Dept. of I&CT, MIT, MAHE, Manipal
• A link is characterized by (B,L) where
• B: bitrate (bps)
• L: Max. Distance for which BER <10^(-12)
• To build a communication system that can transmit BT bps over a
distance LT kms using (B,L) optical links, we need BT/B parallel
systems each with LT/L links in series.
• Thus we need (BT X LT) / (B x L) optical links.
TCP UDP
IP
MPS
MPLS
PPP FR ATM Ethernet DWDM
Physical
Label-A1 Label-B1
Label-A2 Label-B2
Label-A3 Label-B3
Label-A4 Label-B4
IP Label Label IP
Routing Switching Switching Routing
R1 --- E0 172.16.1.0
S1 6
R2 6 S0 172.16.1.0
S2 11
R3 11 S0 172.16.1.0
S3 7
R4 7 S1 172.16.1.0
E0 --
Note: the label switch path is unidirectional.
Q: create LFIB for R4 => R3 => R2 => R1
Dr. Ramakrishna M, Dept. of I&CT, MIT, MAHE, Manipal
Label Encapsulation
• Label information can be carried in a packet in a variety of ways:
• A small, shim label header inserted between the Layer 2 and network layer
headers.
• As part of the Layer 2 header, if the Layer 2 header provides adequate
semantics (such as ATM).
• As part of the network layer header (future, such as IPv6).
• In general, MPLS can be implemented over any media type, including point-
to-point, Ethernet, Frame Relay, and ATM links. The label-forwarding
component is independent of the network layer protocol.
• Combine Cable TV, telephone and data networks : Fiber to the curb
Dr. Ramakrishna M, Dept. of I&CT, MIT, MAHE, Manipal
WDM
λ1 λ1
T R
T R
λn λn
MUX
DEMUX
• Hence one wavelength may carry Analog TV signals, other can carry IP
packets.
1 T
R
λn λn
N
R T
λn λn
• A virtual light path must be created that spans several links joined by
cross connects.
4
2
B
D
Receiver Sensitivity 300 photons per bit 1000 photons per bit Approx. 1000 photons per bit
Admission
Control
(To accept or reject a
flow based on flow Core
specifications)
Flow
Session
Descriptor
Information
required to identify QoS in
packets belonging to Filter Spec Flow Spec terms of
a flow Bandwidth,
Delay
Field Description
Phop Address of previous hop RSVP capable node that
forwards the Path message
Sender Template Sender IP address and optionally sender port
Sender Tspec Sender’s Traffic Characteristics
Adspec Information used to advertise end to end path to
receivers
Ex: Video
conferencing
Overload !!
LER 1 LER 4 IP
IP Overload !!
IP L IP L
Forward to IP L
LSR 2
LSR 3
LSR 4 LSR 2 LSR 3
LSR X
E1 E1
E3 E3
E1 E2 E2
E2
192.168.3.0 -- E1 10 E3 10 E1 30 E2 30 E3 -- E1 192.168.4.0
-- E2 20 E3 20 E1 40 E2 40 E3 -- E2
LSP
uni-direction
10 E3 -- E1 30 E2 10 E1 -- E1 30 E3
20 E3 -- E1 40 E2 20 E1 -- E2 40 E3
uni-direction LSP
VPN_B VPN_A
10.2.0.0 10.1.0.0
VPN_A
11.6.0.0 VPN_B
10.3.0.0
VPN_B
10.1.0.0
Ref: Chapter 16 :William Stallings Data and Computer Communications 7th Edition