Reference Guide

Table Of Contents
Indicate to the sequencer that the packet should be sent (i.e. the PACKET_OUT should be
transmitted back to the source datapath).
During an OBSERVERs event callback, the context can be examined to determine the
outcome of the packet processing.
Once a DIRECTOR invokes the PacketOut.send() method from their callback, the sequencer will
convert the mutable PACKET_OUT message to its immutable form and attempt to send it back to
the datapath. If an error occurs during the send, this fact is recorded in the message context, and
the DIRECTOR’s errorEvent() callback is invoked.
Note that every SPL that registers with the sequencer is guaranteed to see every MessageContext
(subject to their ProtocolId “interest” set).
Here is some sample code that shows how to register as an observer of DNS packets sent to the
controller in PACKET_IN messages:
private static final int OBS_ALTITUDE = 25;
private static final Set<ProtocolId>
OBS_INTEREST = EnumSet.of(ProtocolId.DNS);
private final MyObserver myObserver = new MyObserver();
private void register() {
cs.addPacketListener(myObserver, PacketListenerRole.OBSERVER,
OBS_ALTITUDE, OBS_INTEREST);
}
private static class MyObserver extends SequencedPacketAdapter {
@Override
public void event(MessageContext context) {
Dns dns = context.decodedPacket().get(ProtocolId.DNS);
reportOnDnsPacket(dns, context.srcEvent().dpid());
}
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.
// ...
}
}
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.
41