Search in sources :

Example 6 with TopologyEvent

use of org.onosproject.net.topology.TopologyEvent in project onos by opennetworkinglab.

the class TopologyEventsListCommand method doExecute.

@Override
protected void doExecute() {
    TopologyMetricsService service = get(TopologyMetricsService.class);
    if (outputJson()) {
        print("%s", json(service.getEvents()));
    } else {
        for (Event event : service.getEvents()) {
            print(FORMAT_EVENT, event);
            if (event instanceof TopologyEvent) {
                TopologyEvent topologyEvent = (TopologyEvent) event;
                for (Event reason : topologyEvent.reasons()) {
                    print(FORMAT_REASON, reason);
                }
            }
            // Extra empty line for clarity
            print("");
        }
    }
}
Also used : TopologyMetricsService(org.onosproject.metrics.topology.TopologyMetricsService) TopologyEvent(org.onosproject.net.topology.TopologyEvent) TopologyEvent(org.onosproject.net.topology.TopologyEvent) Event(org.onosproject.event.Event)

Example 7 with TopologyEvent

use of org.onosproject.net.topology.TopologyEvent in project onos by opennetworkinglab.

the class DistributedTopologyStore method updateTopology.

@Override
public TopologyEvent updateTopology(ProviderId providerId, GraphDescription graphDescription, List<Event> reasons) {
    // Have the default topology construct self from the description data.
    DefaultTopology newTopology = new DefaultTopology(providerId, graphDescription, this::isBroadcastPoint);
    updateBroadcastPoints(newTopology);
    // Promote the new topology to current and return a ready-to-send event.
    synchronized (this) {
        // already have.
        if (current != null && newTopology.time() < current.time()) {
            return null;
        }
        current = newTopology;
        return new TopologyEvent(TOPOLOGY_CHANGED, current, reasons);
    }
}
Also used : DefaultTopology(org.onosproject.common.DefaultTopology) TopologyEvent(org.onosproject.net.topology.TopologyEvent)

Example 8 with TopologyEvent

use of org.onosproject.net.topology.TopologyEvent in project onos by opennetworkinglab.

the class ObjectiveTrackerTest method testEventNoReasons.

/**
 * Tests an event with no associated reasons.
 *
 * @throws InterruptedException if the latch wait fails.
 */
@Test
public void testEventNoReasons() throws InterruptedException {
    final TopologyEvent event = new TopologyEvent(TopologyEvent.Type.TOPOLOGY_CHANGED, topology, null);
    listener.event(event);
    assertThat(delegate.latch.await(WAIT_TIMEOUT_SECONDS, TimeUnit.SECONDS), is(true));
    assertThat(delegate.intentIdsFromEvent, hasSize(0));
    assertThat(delegate.compileAllFailedFromEvent, is(true));
}
Also used : TopologyEvent(org.onosproject.net.topology.TopologyEvent) Test(org.junit.Test) AbstractIntentTest(org.onosproject.net.intent.AbstractIntentTest)

Example 9 with TopologyEvent

use of org.onosproject.net.topology.TopologyEvent in project onos by opennetworkinglab.

the class ObjectiveTrackerTest method testEventLinkAdded.

/**
 * Tests an event for a link being added.
 *
 * @throws InterruptedException if the latch wait fails.
 */
@Test
public void testEventLinkAdded() throws InterruptedException {
    final Link link = link("src", 1, "dst", 2);
    final LinkEvent linkEvent = new LinkEvent(LinkEvent.Type.LINK_ADDED, link);
    reasons.add(linkEvent);
    final TopologyEvent event = new TopologyEvent(TopologyEvent.Type.TOPOLOGY_CHANGED, topology, reasons);
    listener.event(event);
    assertThat(delegate.latch.await(WAIT_TIMEOUT_SECONDS, TimeUnit.SECONDS), is(true));
    assertThat(delegate.intentIdsFromEvent, hasSize(0));
    assertThat(delegate.compileAllFailedFromEvent, is(true));
}
Also used : LinkEvent(org.onosproject.net.link.LinkEvent) TopologyEvent(org.onosproject.net.topology.TopologyEvent) Link(org.onosproject.net.Link) Test(org.junit.Test) AbstractIntentTest(org.onosproject.net.intent.AbstractIntentTest)

Example 10 with TopologyEvent

use of org.onosproject.net.topology.TopologyEvent in project onos by opennetworkinglab.

the class TopologyEventsListCommand method json.

/**
 * Produces JSON object for a topology event.
 *
 * @param mapper the JSON object mapper to use
 * @param event the topology event with the data
 * @return JSON object for the topology event
 */
private ObjectNode json(ObjectMapper mapper, Event event) {
    ObjectNode result = mapper.createObjectNode();
    result.put("time", event.time()).put("type", event.type().toString()).put("event", event.toString());
    // Add the reasons if a TopologyEvent
    if (event instanceof TopologyEvent) {
        TopologyEvent topologyEvent = (TopologyEvent) event;
        ArrayNode reasons = mapper.createArrayNode();
        for (Event reason : topologyEvent.reasons()) {
            reasons.add(json(mapper, reason));
        }
        result.set("reasons", reasons);
    }
    return result;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) TopologyEvent(org.onosproject.net.topology.TopologyEvent) TopologyEvent(org.onosproject.net.topology.TopologyEvent) Event(org.onosproject.event.Event) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode)

Aggregations

TopologyEvent (org.onosproject.net.topology.TopologyEvent)10 LinkEvent (org.onosproject.net.link.LinkEvent)6 Test (org.junit.Test)5 Event (org.onosproject.event.Event)5 Link (org.onosproject.net.Link)5 AbstractIntentTest (org.onosproject.net.intent.AbstractIntentTest)4 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 ClusterEvent (org.onosproject.cluster.ClusterEvent)2 MastershipEvent (org.onosproject.mastership.MastershipEvent)2 DeviceEvent (org.onosproject.net.device.DeviceEvent)2 HostEvent (org.onosproject.net.host.HostEvent)2 IntentEvent (org.onosproject.net.intent.IntentEvent)2 Topology (org.onosproject.net.topology.Topology)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 MoreObjects (com.google.common.base.MoreObjects)1 ImmutableList (com.google.common.collect.ImmutableList)1 PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1