Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

 Once again if you recompile your code and use byon-push-bits you will update your bundles on the ONOS instances. You should now be able to add and remove networks as well as hosts. Try it out!

Part 4: Network Events

 In order to be able to communicate between ONOS instances we are going to make use of events. These events will be fired by the distributed store and caught by the manager in the peer ONOS instance. At this point the peer manager will notify any local listeners of the network event. 

Ok so let's start by adding a NetworkEvent class.

Code Block
languagejava
public class NetworkEvent extends AbstractEvent<NetworkEvent.Type, String> {

    enum Type {
        NETWORK_ADDED,
        NETWORK_REMOVED,
        NETWORK_UPDATED
    }

    public NetworkEvent(Type type, String subject) {
        super(type, subject);
    }

}


We are also going to need a couple interfaces that will be needed by the listeners and the and the delegates. The listeners are components which have registered to obtain events from this service, these are usually local. A delegate is a neighbouring manager which is receiving events from a neighbouring store for the purpose of either taking action on the store event or notifying listeners. So we are going to add NetworkListener.

Code Block
languagejava
public interface NetworkListener extends EventListener<NetworkEvent> {}

 and a NetworkStoreDelegate interfaces

Code Block
languagejava
public interface NetworkStoreDelegate extends StoreDelegate<NetworkEvent> {}


Of course now if we want the store to be delegate-capable we need to make it extend the Store as shown below.

Code Block
languagejava
public interface NetworkStore extends Store<NetworkEvent, NetworkStoreDelegate> {

And since we changed the interface of the Store we will have to add something to the implementations, namely SimpleNetworkStore. This abstract class is used to define the methods for posting event to it's delegates.

Code Block
       public class SimpleNetworkStore extends AbstractStore<NetworkEvent, NetworkStoreDelegate>


We need to add the following methods to the NetworkService in order to allow components to add and remove listeners.

Code Block
languagejava
    /**
     * Register a listener for network events.
     *
     * @param listener listener
     */
    void addListener(NetworkListener listener);

    /**
     * Unregister a listener for network events.
     *
     * @param listener listener
     */
    void removeListener(NetworkListener listener);