Search in sources :

Example 1 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 2 with TopologyEvent

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

the class EventsCommand method printEvent.

private void printEvent(Event<?, ?> event) {
    if (event instanceof DeviceEvent) {
        DeviceEvent deviceEvent = (DeviceEvent) event;
        if (event.type().toString().startsWith("PORT")) {
            // Port event
            print("%s %s\t%s/%s [%s]", Tools.defaultOffsetDataTime(event.time()), event.type(), deviceEvent.subject().id(), deviceEvent.port().number(), deviceEvent.port());
        } else {
            // Device event
            print("%s %s\t%s [%s]", Tools.defaultOffsetDataTime(event.time()), event.type(), deviceEvent.subject().id(), deviceEvent.subject());
        }
    } else if (event instanceof MastershipEvent) {
        print("%s %s\t%s [%s]", Tools.defaultOffsetDataTime(event.time()), event.type(), event.subject(), ((MastershipEvent) event).roleInfo());
    } else if (event instanceof LinkEvent) {
        LinkEvent linkEvent = (LinkEvent) event;
        Link link = linkEvent.subject();
        print("%s %s\t%s/%s-%s/%s [%s]", Tools.defaultOffsetDataTime(event.time()), event.type(), link.src().deviceId(), link.src().port(), link.dst().deviceId(), link.dst().port(), link);
    } else if (event instanceof HostEvent) {
        HostEvent hostEvent = (HostEvent) event;
        print("%s %s\t%s [%s->%s]", Tools.defaultOffsetDataTime(event.time()), event.type(), hostEvent.subject().id(), hostEvent.prevSubject(), hostEvent.subject());
    } else if (event instanceof TopologyEvent) {
        TopologyEvent topoEvent = (TopologyEvent) event;
        List<Event> reasons = MoreObjects.firstNonNull(topoEvent.reasons(), ImmutableList.<Event>of());
        Topology topo = topoEvent.subject();
        String summary = String.format("(d=%d,l=%d,c=%d)", topo.deviceCount(), topo.linkCount(), topo.clusterCount());
        print("%s %s%s [%s]", Tools.defaultOffsetDataTime(event.time()), event.type(), summary, reasons.stream().map(e -> e.type()).collect(toList()));
    } else if (event instanceof ClusterEvent) {
        print("%s %s\t%s [%s]", Tools.defaultOffsetDataTime(event.time()), event.type(), ((ClusterEvent) event).subject().id(), event.subject());
    } else {
        // Unknown Event?
        print("%s %s\t%s [%s]", Tools.defaultOffsetDataTime(event.time()), event.type(), event.subject(), event);
    }
}
Also used : DeviceEvent(org.onosproject.net.device.DeviceEvent) HostEvent(org.onosproject.net.host.HostEvent) ClusterEvent(org.onosproject.cluster.ClusterEvent) LinkEvent(org.onosproject.net.link.LinkEvent) MastershipEvent(org.onosproject.mastership.MastershipEvent) TopologyEvent(org.onosproject.net.topology.TopologyEvent) IntentEvent(org.onosproject.net.intent.IntentEvent) LinkEvent(org.onosproject.net.link.LinkEvent) MastershipEvent(org.onosproject.mastership.MastershipEvent) HostEvent(org.onosproject.net.host.HostEvent) Event(org.onosproject.event.Event) TopologyEvent(org.onosproject.net.topology.TopologyEvent) ClusterEvent(org.onosproject.cluster.ClusterEvent) DeviceEvent(org.onosproject.net.device.DeviceEvent) Topology(org.onosproject.net.topology.Topology) Link(org.onosproject.net.Link)

Example 3 with TopologyEvent

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

the class EventsCommand method doExecute.

@Override
protected void doExecute() {
    EventHistoryService eventHistoryService = get(EventHistoryService.class);
    Stream<Event<?, ?>> events = eventHistoryService.history().stream();
    boolean dumpAll = all || !(mastership || device || link || topology || host || cluster || intent);
    if (!dumpAll) {
        Predicate<Event<?, ?>> filter = (defaultIs) -> false;
        if (mastership) {
            filter = filter.or(evt -> evt instanceof MastershipEvent);
        }
        if (device) {
            filter = filter.or(evt -> evt instanceof DeviceEvent);
        }
        if (link) {
            filter = filter.or(evt -> evt instanceof LinkEvent);
        }
        if (topology) {
            filter = filter.or(evt -> evt instanceof TopologyEvent);
        }
        if (host) {
            filter = filter.or(evt -> evt instanceof HostEvent);
        }
        if (cluster) {
            filter = filter.or(evt -> evt instanceof ClusterEvent);
        }
        if (intent) {
            filter = filter.or(evt -> evt instanceof IntentEvent);
        }
        events = events.filter(filter);
    }
    if (maxSize > 0) {
        events = events.limit(maxSize);
    }
    if (outputJson()) {
        ArrayNode jsonEvents = events.map(this::json).collect(toArrayNode());
        printJson(jsonEvents);
    } else {
        events.forEach(this::printEvent);
    }
}
Also used : Tools(org.onlab.util.Tools) IntentEvent(org.onosproject.net.intent.IntentEvent) LinkEvent(org.onosproject.net.link.LinkEvent) Link(org.onosproject.net.Link) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Command(org.apache.karaf.shell.api.action.Command) MastershipEvent(org.onosproject.mastership.MastershipEvent) Topology(org.onosproject.net.topology.Topology) ImmutableList(com.google.common.collect.ImmutableList) HostEvent(org.onosproject.net.host.HostEvent) JsonNode(com.fasterxml.jackson.databind.JsonNode) Collector(java.util.stream.Collector) Event(org.onosproject.event.Event) PrintWriter(java.io.PrintWriter) TopologyEvent(org.onosproject.net.topology.TopologyEvent) ClusterEvent(org.onosproject.cluster.ClusterEvent) Predicate(java.util.function.Predicate) StringWriter(java.io.StringWriter) MoreObjects(com.google.common.base.MoreObjects) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) AbstractShellCommand(org.onosproject.cli.AbstractShellCommand) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) Stream(java.util.stream.Stream) Service(org.apache.karaf.shell.api.action.lifecycle.Service) DeviceEvent(org.onosproject.net.device.DeviceEvent) Option(org.apache.karaf.shell.api.action.Option) DeviceEvent(org.onosproject.net.device.DeviceEvent) MastershipEvent(org.onosproject.mastership.MastershipEvent) TopologyEvent(org.onosproject.net.topology.TopologyEvent) HostEvent(org.onosproject.net.host.HostEvent) ClusterEvent(org.onosproject.cluster.ClusterEvent) LinkEvent(org.onosproject.net.link.LinkEvent) IntentEvent(org.onosproject.net.intent.IntentEvent) LinkEvent(org.onosproject.net.link.LinkEvent) MastershipEvent(org.onosproject.mastership.MastershipEvent) HostEvent(org.onosproject.net.host.HostEvent) Event(org.onosproject.event.Event) TopologyEvent(org.onosproject.net.topology.TopologyEvent) ClusterEvent(org.onosproject.cluster.ClusterEvent) DeviceEvent(org.onosproject.net.device.DeviceEvent) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) IntentEvent(org.onosproject.net.intent.IntentEvent)

Example 4 with TopologyEvent

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

the class VirtualNetworkTopologyProviderTest method testTopologyChanged.

/**
 * Test the topologyChanged() method.
 */
@Test
public void testTopologyChanged() {
    // Initial setup is two clusters of devices/links.
    assertEquals("The cluster count did not match.", 2, topologyService.currentTopology().clusterCount());
    // Adding this link will join the two clusters together.
    List<Event> reasons = new ArrayList<>();
    VirtualLink link = manager.createVirtualLink(virtualNetwork.id(), cp6, cp7);
    virtualNetworkManagerStore.updateLink(link, link.tunnelId(), Link.State.ACTIVE);
    VirtualLink link2 = manager.createVirtualLink(virtualNetwork.id(), cp7, cp6);
    virtualNetworkManagerStore.updateLink(link2, link2.tunnelId(), Link.State.ACTIVE);
    reasons.add(new LinkEvent(LinkEvent.Type.LINK_ADDED, link));
    reasons.add(new LinkEvent(LinkEvent.Type.LINK_ADDED, link2));
    TopologyEvent event = new TopologyEvent(TopologyEvent.Type.TOPOLOGY_CHANGED, topologyService.currentTopology(), reasons);
    topologyProvider.topologyListener.event(event);
    // Wait for the topology changed event, and that the topologyChanged method was called.
    try {
        if (!changed.tryAcquire(MAX_PERMITS, MAX_WAIT_TIME, TimeUnit.SECONDS)) {
            fail("Failed to wait for topology changed event.");
        }
    } catch (InterruptedException e) {
        fail("Semaphore exception." + e.getMessage());
    }
    // Validate that the topology changed method received a single cluster of connect points.
    // This means that the two previous clusters have now joined into a single cluster.
    assertEquals("The cluster count did not match.", 1, this.clusters.size());
    assertEquals("The cluster count did not match.", 1, topologyService.currentTopology().clusterCount());
    // Now remove the virtual link to split it back into two clusters.
    manager.removeVirtualLink(virtualNetwork.id(), link.src(), link.dst());
    manager.removeVirtualLink(virtualNetwork.id(), link2.src(), link2.dst());
    assertEquals("The cluster count did not match.", 2, topologyService.currentTopology().clusterCount());
    reasons = new ArrayList<>();
    reasons.add(new LinkEvent(LinkEvent.Type.LINK_REMOVED, link));
    reasons.add(new LinkEvent(LinkEvent.Type.LINK_REMOVED, link2));
    event = new TopologyEvent(TopologyEvent.Type.TOPOLOGY_CHANGED, topologyService.currentTopology(), reasons);
    topologyProvider.topologyListener.event(event);
    // Wait for the topology changed event, and that the topologyChanged method was called.
    try {
        if (!changed.tryAcquire(MAX_PERMITS, MAX_WAIT_TIME, TimeUnit.SECONDS)) {
            fail("Failed to wait for topology changed event.");
        }
    } catch (InterruptedException e) {
        fail("Semaphore exception." + e.getMessage());
    }
    // Validate that the topology changed method received two clusters of connect points.
    // This means that the single previous clusters has now split into two clusters.
    assertEquals("The cluster count did not match.", 2, this.clusters.size());
}
Also used : LinkEvent(org.onosproject.net.link.LinkEvent) TopologyEvent(org.onosproject.net.topology.TopologyEvent) ArrayList(java.util.ArrayList) LinkEvent(org.onosproject.net.link.LinkEvent) Event(org.onosproject.event.Event) TopologyEvent(org.onosproject.net.topology.TopologyEvent) VirtualLink(org.onosproject.incubator.net.virtual.VirtualLink) Test(org.junit.Test)

Example 5 with TopologyEvent

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

the class ObjectiveTrackerTest method testEventLinkDownMatch.

/**
 * Tests an event for a link down where the link matches existing intents.
 *
 * @throws InterruptedException if the latch wait fails.
 */
@Test
public void testEventLinkDownMatch() throws Exception {
    final Link link = link("src", 1, "dst", 2);
    final LinkEvent linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link);
    reasons.add(linkEvent);
    final TopologyEvent event = new TopologyEvent(TopologyEvent.Type.TOPOLOGY_CHANGED, topology, reasons);
    final Key key = Key.of(0x333L, APP_ID);
    Collection<NetworkResource> resources = ImmutableSet.of(link);
    tracker.addTrackedResources(key, resources);
    listener.event(event);
    assertThat(delegate.latch.await(WAIT_TIMEOUT_SECONDS, TimeUnit.SECONDS), is(true));
    assertThat(delegate.intentIdsFromEvent, hasSize(1));
    assertThat(delegate.compileAllFailedFromEvent, is(false));
    assertThat(delegate.intentIdsFromEvent.get(0).toString(), equalTo("0x333"));
}
Also used : NetworkResource(org.onosproject.net.NetworkResource) LinkEvent(org.onosproject.net.link.LinkEvent) TopologyEvent(org.onosproject.net.topology.TopologyEvent) Link(org.onosproject.net.Link) Key(org.onosproject.net.intent.Key) Test(org.junit.Test) AbstractIntentTest(org.onosproject.net.intent.AbstractIntentTest)

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