SDN Controller Programming Guide
32
this is PACKET_IN messages; to hear about these, one must register as a
SequencedPacketListener.
Sequenced Packet Listeners – notified when PACKET_IN messages arrive from a datapath.
This mechanism is described in more detail in a following section.
Flow Listeners – notified when FLOW_MOD messages are pushed out to datapaths, or when
flow rules are removed from datapaths (either explicitly, or by timeout).
Group Listeners – notified when GROUP_MOD messages are pushed out to datapaths.
Meter Listeners – notified when METER_MOD messages are pushed out to datapaths.
The following listing shows an example that listen for ECHO_REPLY messages (presumably we
have some other code that is sending ECHO_REQUEST messages), and PORT_STATUS messages.
ECHO_REPLY and PORT_SATUS Example:
private static final Set<MessageType> INTEREST = EnumSet.of(
MessageType.ECHO_REPLY,
MessageType.PORT_STATUS
);
private void initListener() {
cs.addMessageListener(new MyListener(), INTEREST);
}
private class MyListener implements MessageListener {
@Override
public void queueEvent(QueueEvent event) {
log.warn("Message Listener Queue event: {}", event);
}
@Override
public void event(MessageEvent event) {
if (event.type() == OpenflowEventType.MESSAGE_RX) {
OpenflowMessage msg = event.msg();
DataPathId dpid = event.dpid();
switch (msg.getType()) {
case ECHO_REPLY:
handleEchoReply((OfmEchoReply) msg, dpid);
break;
case PORT_STATUS:
handlePortStatus((OfmPortStatus) msg, dpid);
break;
}
}
}
private void handleEchoReply(OfmEchoReply msg, DataPathId dpid) {
...