Reference Guide

Table Of Contents
print("Match : {}", fs.getMatch());
// Note: this is one area where we need to be cognizant of the version:
if (fs.getVersion() == ProtocolVersion.V_1_0)
print("Actions : {}", fs.getActions());
else
print("Instructions : {}", fs.getInstructions());
}
Sending Messages
Applications may construct and send messages to datapaths via the “send” methods:
send(OpenflowMessage, DataPathId) : MessageFuture
send(List<OpenflowMessage>, DataPathId) : List<MessageFuture>
The returned MessageFuture(s) allow the caller to choose whether to wait synchronously (block
until the outcome of the request is known), or whether to do some other work and then check on
the result of the request later.
When a message is sent to a datapath, the corresponding MessageFuture encapsulates the state
of that request. Initially the future’s result is UNSATISFIED. Once the outcome is determined, the
future is “satisfied” with one of the following results:
SUCCESSthe request was a success; the reply message is available via reply().
SUCCESS_NO_REPLYthe request was a success; there is no associated reply.
OFM_ERRORthe request failed; the datapath issued an error, available via reply().
EXCEPTIONthe request failed due to an exception; available via cause().
TIMEOUT—the request timed-out waiting for a response from the datapath.
The following listing shows a code example that attaches a timestamp payload to an
ECHO_REQUEST message, then retrieves the timestamp payload from the ECHO_REPLY sent back
by the datapath:
ECHO_REQUEST and ECHO_REPLY Example:
private static final ProtocolVersion PV = ProtocolVersion.V_1_3;
private static final int SIZE_OF_LONG = 8;
private static final String E_ECHO_FAILED =
"Failed to send Echo Request: {}";
private static final long REQUEST_TIMEOUT_MS = 5000;
private void latencyTest(DataPathId dpid) {
byte[] timestamp = new byte[SIZE_OF_LONG];
ByteUtils.setLong(timestamp, 0, System.currentTimeMillis());
OpenflowMessage msg = createEchoRequest(timestamp);
try {
MessageFuture future = cs.send(msg, dpid);
future.await(REQUEST_TIMEOUT_MS); // BLOCKS
if (future.isSuccess()) {
long now = System.currentTimeMillis();
long then = retrieveTimestamp(future.reply());
38