Elements of A Protocol Implementation: Outline
Elements of A Protocol Implementation: Outline
Implementation
Outline
Service Interface
Process Model
Common Subroutines
Example Protocol
Spring 2001
CS 461
Socket API
Creating a socket
int socket(int domain, int type, int protocol)
domain = PF_INET, PF_UNIX
type = SOCK_STREAM, SOCK_DGRAM, SOCK_RAW
CS 461
Sockets (cont)
Active Open (on client)
int connect(int socket, struct sockaddr *addr,
int addr_len)
Sending/Receiving Messages
int send(int socket, char *msg, int mlen, int flags)
int recv(int socket, char *buf, int blen, int flags)
Spring 2001
CS 461
Protocol-to-Protocol Interface
Configure multiple layers
static versus extensible
Process Model
avoid context switches
Buffer Model
avoid data copies
Spring 2001
CS 461
Configuration
TCP
UDP
IP
ARP
ETH
ICMP
name=tulip;
name=eth protocols=tulip;
name=arp protocols=eth;
name=ip protocols=eth,arp;
name=icmp protocols=ip;
name=udp protocols=ip;
name=tcp protocols=ip;
TUPLIP
Spring 2001
CS 461
Protocol Objects
Active Open
Sessn xOpen(Protl hlp, Protl llp,
Part *participants)
Passive Open
XkReturn xOpenEnable(Protl hlp,Protl llp,
Part *participant)
XkReturn xOpenDone(Protl hlp,
Protl llp,Sessn session,
Part *participants)
Demultiplexing
XkReturn xDemux(Protl hlp, Sessn lls,
Msg *message)
Spring 2001
CS 461
Session Objects
Spring 2001
CS 461
Process Model
(a)
Process-per-Protocol
Spring 2001
(b)
Process-per-Message
CS 461
Message Library
Add header
m
Strip header
m
abcdefg
abcdefg
m
defg
+ hdr = abc
xyzabcdefg
Spring 2001
CS 461
m1
abcdefg
Reassemble messages
abcd
Spring 2001
m2
efg
abc
CS 461
10
Event Library
Scheduling Timeouts & Book-keeping activity
Operations
Event evSchedule(EvFunc function,
void *argument,
int time)
EvCancelReturn evCancel(Event event)
Spring 2001
CS 461
11
Map Library
Demultiplex Packets
Operations
Map mapCreate(int number,int size)
Binding mapBind(Map map,
void *key,
void *id)
XkReturn mapResolve(Map map,
void *key,void **id)
Spring 2001
CS 461
12
Example
static Sessn
aspOpen(Protl self, Protl hlp, Part *p)
{
Sessn
asp_s;
Sessn
lls;
ActiveId key;
ProtlState *pstate = (ProtlState *)self->state;
bzero((char *)&key, sizeof(key));
/* High level protocol must specify both */
/* local and remote ASP port */
key.localport = *((AspPort *) partPop(p[0]));
key.remoteport = *((AspPort *) partPop(p[1]));
/* Assume failure until proven otherwise */
asp_s = XK_FAILURE;
Spring 2001
CS 461
13
}
return asp_s;
Spring 2001
CS 461
14
Spring 2001
CS 461
15
static XkReturn
{
AspHdr
Sessn
ActiveId
PassiveId
ProtlState
Enable
void
Spring 2001
CS 461
16
Spring 2001
CS 461
17
static XkReturn
aspPop(Sessn s, Sessn ds, Msg *msg, void *inHdr)
{
AspHdr
*h = (AspHdr *) inHdr;
/* truncate message to length shown in header */
if ((h->ulen - HLEN) < msgLen(msg))
msgTruncate(msg, (int) h->ulen);
/* pass message up the protocol stack */
return xDemux(xGetUp(s), s, msg);
}
Spring 2001
CS 461
18