A Plexus protocol client installs application specific guard/handler procedure pair on the protocol.PacketArrived event. The guard procedure implements a predicate that acts as a packet filter. For example, the guard procedure could be used to filter out ethernet packets that contain ip packets as their payload. The protocol processing functions are implemented by a handler procedure that is attached to the protocol event name. Finally, the guard/handler pair is installed on the protocol event name by calling the protocol.Install function. The following code illustrates how an application can handle IP packets arriving on an Ethernet link.
MODULE EtherIPClient;
IMPORT Ether, EtherPktFormat;
PROCEDURE Init() =
BEGIN
(* Install event handler on Ether.PacketArrived event. *)
EVAL Ether.Install(Ether.PacketArrived,Guard,Handler);
END Init;
The application first installs the guard and handler procedure on the
Ether.PacketArrived event by calling
Ether.Install.
PROCEDURE Guard(packet,curr: Mbuf.T; offset: CARDINAL):BOOLEAN =
BEGIN
WITH etherHeaderBuf = SUBARRAY(Mbuf.Array(packet)^,offset, eth_hdr_len),
etherHeader = VIEW(etherHeaderBuf,NewT)
DO
RETURN etherHeader.type = EtherPktFormat.ETHERTYPE_IP;
END;
END Guard;
The Guard procedure returns true if the type
field indicates that the ether data contains an IP packet. The packet
is contained in a mbuf datastructure.
PROCEDURE Handler(packet,curr: Mbuf.T; offset: CARDINAL):BOOLEAN =
BEGIN
(* Process ether packet that contains an IP packet. *)
END Handler;
BEGIN
END EtherClient;
The Handler procedure is only invoked when the
Guard evaluates to true. It processes the IP packet in an
application specific way.
Marc Fiuczynski