Search in sources :

Example 1 with LinkEvent

use of org.onosproject.net.link.LinkEvent 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 2 with LinkEvent

use of org.onosproject.net.link.LinkEvent 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 3 with LinkEvent

use of org.onosproject.net.link.LinkEvent in project onos by opennetworkinglab.

the class MQEventHandlerTest method testUpdateLink.

@Test
public void testUpdateLink() throws Exception {
    Link link = createLink();
    LinkEvent event = new LinkEvent(LINK_UPDATED, link, 123L);
    validateEvent(event, LINK_UPDATED, link, 123L);
}
Also used : LinkEvent(org.onosproject.net.link.LinkEvent) Link(org.onosproject.net.Link) DefaultLink(org.onosproject.net.DefaultLink) AbstractEventTest(org.onosproject.event.AbstractEventTest) Test(org.junit.Test)

Example 4 with LinkEvent

use of org.onosproject.net.link.LinkEvent 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 LinkEvent

use of org.onosproject.net.link.LinkEvent in project onos by opennetworkinglab.

the class SimpleLinkStoreTest method testCreateOrUpdateLinkAncillary.

@Test
public final void testCreateOrUpdateLinkAncillary() {
    ConnectPoint src = new ConnectPoint(DID1, P1);
    ConnectPoint dst = new ConnectPoint(DID2, P2);
    // add Ancillary link
    LinkEvent event = linkStore.createOrUpdateLink(PIDA, new DefaultLinkDescription(src, dst, INDIRECT, A1));
    assertNotNull("Ancillary only link is ignored", event);
    // add Primary link
    LinkEvent event2 = linkStore.createOrUpdateLink(PID, new DefaultLinkDescription(src, dst, INDIRECT, A2));
    assertLink(DID1, P1, DID2, P2, INDIRECT, event2.subject());
    assertAnnotationsEquals(event2.subject().annotations(), A2, A1);
    assertEquals(LINK_UPDATED, event2.type());
    // update link type
    LinkEvent event3 = linkStore.createOrUpdateLink(PID, new DefaultLinkDescription(src, dst, DIRECT, A2));
    assertLink(DID1, P1, DID2, P2, DIRECT, event3.subject());
    assertAnnotationsEquals(event3.subject().annotations(), A2, A1);
    assertEquals(LINK_UPDATED, event3.type());
    // no change
    LinkEvent event4 = linkStore.createOrUpdateLink(PID, new DefaultLinkDescription(src, dst, DIRECT));
    assertNull("No change event expected", event4);
    // update link annotation (Primary)
    LinkEvent event5 = linkStore.createOrUpdateLink(PID, new DefaultLinkDescription(src, dst, DIRECT, A2_2));
    assertLink(DID1, P1, DID2, P2, DIRECT, event5.subject());
    assertAnnotationsEquals(event5.subject().annotations(), A2, A2_2, A1);
    assertEquals(LINK_UPDATED, event5.type());
    // update link annotation (Ancillary)
    LinkEvent event6 = linkStore.createOrUpdateLink(PIDA, new DefaultLinkDescription(src, dst, DIRECT, A1_2));
    assertLink(DID1, P1, DID2, P2, DIRECT, event6.subject());
    assertAnnotationsEquals(event6.subject().annotations(), A2, A2_2, A1, A1_2);
    assertEquals(LINK_UPDATED, event6.type());
    // update link type (Ancillary) : ignored
    LinkEvent event7 = linkStore.createOrUpdateLink(PIDA, new DefaultLinkDescription(src, dst, EDGE));
    assertNull("Ancillary change other than annotation is ignored", event7);
}
Also used : LinkEvent(org.onosproject.net.link.LinkEvent) ConnectPoint(org.onosproject.net.ConnectPoint) DefaultLinkDescription(org.onosproject.net.link.DefaultLinkDescription) Test(org.junit.Test)

Aggregations

LinkEvent (org.onosproject.net.link.LinkEvent)24 Test (org.junit.Test)16 Link (org.onosproject.net.Link)12 ConnectPoint (org.onosproject.net.ConnectPoint)10 DefaultLink (org.onosproject.net.DefaultLink)6 TopologyEvent (org.onosproject.net.topology.TopologyEvent)6 DefaultLinkDescription (org.onosproject.net.link.DefaultLinkDescription)5 LinkKey (org.onosproject.net.LinkKey)4 DeviceEvent (org.onosproject.net.device.DeviceEvent)4 AbstractEventTest (org.onosproject.event.AbstractEventTest)3 Event (org.onosproject.event.Event)3 AbstractIntentTest (org.onosproject.net.intent.AbstractIntentTest)3 ClusterEvent (org.onosproject.cluster.ClusterEvent)2 MastershipEvent (org.onosproject.mastership.MastershipEvent)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 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1