PowerPoint ******

ZRE
(ZeroMQ Realtime Exchange
Protocol)
2013.07.04
Contents
•
•
•
•
•
•
•
•
•
Goals
Node Identification and Life-cycle
Node Discovery
Interconnection Model
Protocol Signature
Protocol Grammar
ZRE Commands
ZRE Extension Protocols
Zyre
RFC 2119
• SHALL = MUST
• SHOULD = RECOMMENDED
• MAY = OPTIONAL
Goals
• A way for a set of nodes on a local
network to discover each other
• Track when peers come and go, send
messages to individual peers (unicast),
and send messages to groups of peers
(multicast)
Node Identification and Life-cycle
• A ZRE node represents a source or a
target for messaging.
• A ZRE node is identified by a 16-octet
universally unique identifier (UUID).
• ZRE does not define how a node is
created or destroyed but does assume
that nodes have certain durability.
Node Discovery
Header
Body
‘Z’
‘R’
‘E’
%x01
UUID
Port
1byte
1byte
1byte
Beacon version number
(1byte)
16byte
2byte
• Use UDP IPv4 beacon broadcasts to discover nodes.
• SHALL listen to the ZRE discovery service which is
UDP port XXXX (to be assigned by IANA).
• SHALL broadcast, at regular intervals.
• When a ZRE node receives a beacon from a node that
it does not already know about, it SHALL consider this
to be a new peer.
Interconnection Model
Interconnection Model
SHALL create ZeroMQ ROUTER socket and bind this to an
ephemeral TCP port (in the range %xC000 - %xFFFF)
ROUTER
Node
- SHALL be used for all incoming ZeroMQ
message from other nodes
- SHALL NOT send message to peers via this
socket
Interconnection Model
ROUTER
Node1
Broadcast beacon
ROUTER
Node2
Interconnection Model
ROUTER
Node1
DEALER
connect
ROUTER
Node2
Interconnection Model
ROUTER
Node
- SHALL connect each DEALER sockets to at
most one peer
- MAY disconnect its DEALER socket if the
peer has failed to respond within some time
DEALER
- SHALL be used for all outgoing ZeroMQ messages to a specific peer
- SHALL NOT receive messages on this socket
Interconnection Model
• The sender MAY set a high water mark
(HWM).
• The sender SHOULD set the send timeout
on the socket to zero so that a full send
buffer can be detected and treated as
“peer not responding”
Interconnection Model
• When a node receives a valid message
from an unknown node, it SHALL treat this
as a new peer in the identical fashion as if
a UDP beacon was received from an
unknown node.
Protocol Signature
• Every ZRE message sent by TCP SHALL
start with the ZRE protocol
signature, %xAA %xA1.
ZRE protocol ABNF grammar
ZRE protocol ABNF grammar
ZRE protocol
header %xAA %xA1
sequence number
(2byte)
ipaddr
HELLO header %x01
ess
WHISPER header
%x02
sender mailbox port
status
Headers
number
groups
(1byte) (name=value)…(name=value)
(2byte)
content
(0MQ frame)
SHOUT header %x03 group
conten
t
JOIN header %x04 group status
LEAVE header %x05 group status
PING header %x06
PING-OK header
%x07
HELLO Command
ipaddr
HELLO header %x01
ess
sender mailbox port
status
Headers
number
groups
(1byte) (name=value)…(name=value)
(2byte)
• Each node SHALL start a dialog by
sending HELLO as the first command on
and connection to a peer
• Group status sequence is incremented
each time the peer joins or leaves a group
WHISPER Command
WHISPER
header
%x02
content
(0MQ frame)
• When a node wishes to send a message
to a single peer it SHALL use the
WHISPER command.
SHOUT Command
SHOUT
Header
%x03
group
content
• When a node wishes to send a message
to a set of nodes participating in a group it
SHALL use the SHOUT command.
• SHOUT command is unicast to each peer
JOIN Command
JOIN
header
%x04
group
status
• When a node joins a group it SHALL
broadcast a JOIN command to all its peers.
LEAVE Command
LEAVE
header
%x05
Group
status
• When a node leaves a group it SHALL
broadcast a LEAVE command to all its
peers.
PING Command
PING
header
%x06
• When a node SHOULD send a PING
command to any peer that it has not
received a UDP beacon from within a
certain time (typically five seconds).
PING-OK Command
PING-OK
header
%x07
• When a node receives a PING command it
SHALL reply with a PING-OK command.
ZRE Extension Protocols
• To announce an extension protocol a node
adds a headers field to the HELLO
command, in the form
“service-name=tcp://ipaddress:port”
• ZRE/LOG
• FILEMQ
ZRE/LOG Extension Protocol
• SHALL create a ZeroMQ SUB socket and
bind this to an ephemeral TCP port (in the
range %xC000 - %xFFFF).
• SHALL broadcast its connection endpoint
in the HELLO command.
• Any node wishing to send log data SHALL
create a PUB socket and connect it to this
endpoint.
ZRE/LOG Extension Protocol
Zyre
• An open-source framework for proximitybased peer-to-peer applications
• It uses standard WiFi to connect devices
to each other in real-time.
zre_perf_remote
• Create thread nodes
• No reply any commands
zre_ping
• JOIN -> WHISPER
• Receive WHISPER -> SHOUT
Screenshot
Screenshot
Screenshot