Ask is moving to Stack Overflow and Serverfault.com! Please use the "opendaylight" tag on either of these sites. This site is now in Read-Only mode

0

How to register to receive packet-ins?

asked 2017-08-07 09:19:25 -0700

sofs gravatar image

updated 2017-08-07 09:20:16 -0700

I'm developing an app and I need to register to mdsal to receive packet-ins. I'm aware that I can do this using blueprint but I'm not sure how to do it.

Can someone help me?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2017-08-20 06:35:12 -0700

VincentJahjah gravatar image

updated 2017-08-24 18:56:53 -0700

I find most useful to look into code examples for these kinds of questions.

Here, the class is registered to receive arp packets. You can see how he iteratively unpacks the layers of protocols, and how he dispatches the packet afterwards to analyze the ARP traffic. Note that ArpPacketHandler implements ArpPacketListener, hence the more specific "ARP" packets registration. ArpPacketListener is defined in the "PacketHandler" project of l2switch along with other protocol-specific listeners.

Here, the class is configured to receive packets in general. Note that this class implements PacketProcessingListener.

If you look for the blueprint files of these projects, you see something like this:

<reference id="notificationProviderService"
interface="org.opendaylight.controller.sal.binding.api.NotificationProviderService" />
...
  <odl:rpc-service id="packetHandlerService"
interface="org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketProcessingService" />

  <bean id="arpHandlerProvider"
    class="org.opendaylight.l2switch.arphandler.core.ArpHandlerProvider"
    init-method="init" destroy-method="close">
    <argument ref="notificationProviderService" />
    ...
    <argument ref="packetHandlerService" />
    ...
  </bean>

This method uses a provider which then instantiates all of the other classes using the services (instead of directly injecting the sources inside the class). If you look inside the provider for arphandler, you'll see the following:

private Registration listenerRegistration = null, floodTopoListenerReg = null, floodInvListenerReg = null, topoNodeListenerReg = null;

private final NotificationProviderService notificationService;
...
private final PacketProcessingService packetProcessingService;
...

public ArpHandlerProvider(..., final NotificationProviderService notificationProviderService, ..., final PacketProcessingService packetProcessingService, ...) {
    this.notificationService = notificationProviderService;
    ...
    this.packetProcessingService = packetProcessingService;
    ...
}

public void init() {
    ...
    // Setup PacketDispatcher
    PacketDispatcher packetDispatcher = new PacketDispatcher();
    ..
    packetDispatcher.setPacketProcessingService(packetProcessingService);

    // Setup ArpPacketHandler
    ArpPacketHandler arpPacketHandler = new ArpPacketHandler(packetDispatcher);

    // Register ArpPacketHandler
    this.listenerRegistration = notificationService.registerNotificationListener(arpPacketHandler);
}
public void close() throws Exception {
    if(listenerRegistration != null) {
        listenerRegistration.close();
    }
    ...
}

As you can see, the notificationProviderService is used to register classes to certain events, and the packetHandlerService is used to provide tools to handle these packets. Note that ArpPacketHandler does not know how to process packets; it only gets notified when a new packet is received. The functionality for handling the packet is delegated to another class: ArpPacketDispatcher.

edit flag offensive delete publish link more
Login/Signup to Answer

Question Tools

Follow
1 follower

Stats

Asked: 2017-08-07 09:19:25 -0700

Seen: 50 times

Last updated: Aug 24