SDN Controller Programming Guide
37
reportOnDnsPacket(dns, context.srcEvent().dpid());
return false;
}
private void reportOnDnsPacket(Dns dns, DataPathId dpid) {
// Since packet processing (this thread) is fast-path,
// queue the report task onto a separate thread, then return.
// ...
}
@Override
public void errorEvent(ErrorEvent event) {
// Never gets called for Observers
}
}
Note that event processing should happen as fast as possible, since this is key to the performance
of the controller. In the example above, it is suggested that the task of reporting on the DNS
packet is submitted to a queue to be processed in a separate thread, so as not to hold up the
main IO-Loop.
Message Context
The MessageContext is the object which maintains the state of processing a PACKET_IN message,
and the formulation of the PACKET_OUT message to be returned to the source datapath. When a
PACKET_IN message is received by the controller, several things happen:
A new MessageContext is created
The PACKET_IN message event is attached
The packet data (if there is any) is decoded and the Packet model attached
A mutable PACKET_OUT message is created and attached (with appropriate fields set)
The MessageContext is passed from listener to listener down the processing chain
The MessageContext provides the following methods:
srcEvent() – returns the message event (immutable) containing the PACKET_IN message
received from the datapath.
getVersion() – returns the protocol version of the datapath / OpenFlow message.
decodedPacket() – returns the network packet model (immutable) of the decoded packet data.
getProtocols() – returns an array of protocol IDs for the protocol layers in the decoded packet.
packetOut() returns the PacketOut API, through which actions may be applied to the
PACKET_OUT message under construction.
getCompletedPacketOut() – returns the PACKET_OUT message (immutable) that was sent
back to the datapath.
addHint(Hint) – adds a hint to the message context.
getHints() – returns the list of hints attached to the context.