Search in sources :

Example 1 with HostEvent

use of org.onosproject.net.host.HostEvent in project onos by opennetworkinglab.

the class RouteManagerTest method testAsyncRouteAdd.

/**
 * Tests adding a route entry where the HostService does not immediately
 * know the MAC address of the next hop, but this is learnt later.
 */
@Test
public void testAsyncRouteAdd() {
    Route route = new Route(Route.Source.STATIC, V4_PREFIX1, V4_NEXT_HOP1);
    // 2nd route for the same nexthop
    Route route2 = new Route(Route.Source.STATIC, V4_PREFIX2, V4_NEXT_HOP2);
    // 3rd route with no valid nexthop
    Route route3 = new Route(Route.Source.STATIC, V6_PREFIX1, V6_NEXT_HOP1);
    // Host service will reply with no hosts when asked
    reset(hostService);
    expect(hostService.getHostsByIp(anyObject(IpAddress.class))).andReturn(Collections.emptySet()).anyTimes();
    hostService.startMonitoringIp(V4_NEXT_HOP1);
    hostService.startMonitoringIp(V4_NEXT_HOP2);
    hostService.startMonitoringIp(V6_NEXT_HOP1);
    expectLastCall().anyTimes();
    replay(hostService);
    // Initially when we add the route, no route event will be sent because
    // the host is not known
    replay(routeListener);
    routeManager.update(Lists.newArrayList(route, route2, route3));
    verify(routeListener);
    // Now when we send the event, we expect the FIB update to be sent
    reset(routeListener);
    ResolvedRoute resolvedRoute = new ResolvedRoute(route, MAC1);
    routeListener.event(event(RouteEvent.Type.ROUTE_ADDED, resolvedRoute, null, Sets.newHashSet(resolvedRoute), null));
    ResolvedRoute resolvedRoute2 = new ResolvedRoute(route2, MAC1);
    routeListener.event(event(RouteEvent.Type.ROUTE_ADDED, resolvedRoute2, null, Sets.newHashSet(resolvedRoute2), null));
    replay(routeListener);
    Host host = createHost(MAC1, Lists.newArrayList(V4_NEXT_HOP1, V4_NEXT_HOP2));
    // Set up the host service with a host
    reset(hostService);
    expect(hostService.getHostsByIp(V4_NEXT_HOP1)).andReturn(Collections.singleton(host)).anyTimes();
    hostService.startMonitoringIp(V4_NEXT_HOP1);
    expect(hostService.getHostsByIp(V4_NEXT_HOP2)).andReturn(Collections.singleton(host)).anyTimes();
    hostService.startMonitoringIp(V4_NEXT_HOP2);
    expectLastCall().anyTimes();
    replay(hostService);
    // Send in the host event
    hostListener.event(new HostEvent(HostEvent.Type.HOST_ADDED, host));
    verify(routeListener);
}
Also used : HostEvent(org.onosproject.net.host.HostEvent) Host(org.onosproject.net.Host) DefaultHost(org.onosproject.net.DefaultHost) ResolvedRoute(org.onosproject.routeservice.ResolvedRoute) Route(org.onosproject.routeservice.Route) ResolvedRoute(org.onosproject.routeservice.ResolvedRoute) Test(org.junit.Test)

Example 2 with HostEvent

use of org.onosproject.net.host.HostEvent 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 HostEvent

use of org.onosproject.net.host.HostEvent 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 HostEvent

use of org.onosproject.net.host.HostEvent in project onos by opennetworkinglab.

the class VplsManagerTest method hostAddEventTest.

/**
 * Trigger host event listener by HOST_ADDED event.
 */
@Test
public void hostAddEventTest() {
    VplsData vplsData = vplsManager.createVpls(VPLS1, NONE);
    vplsManager.addInterface(vplsData, V100H1);
    HostEvent hostEvent = new HostEvent(HostEvent.Type.HOST_ADDED, V100HOST1);
    hostService.postHostEvent(hostEvent);
    vplsData = vplsStore.getVpls(VPLS1);
    assertEquals(UPDATING, vplsData.state());
}
Also used : HostEvent(org.onosproject.net.host.HostEvent) VplsData(org.onosproject.vpls.api.VplsData) Test(org.junit.Test)

Example 5 with HostEvent

use of org.onosproject.net.host.HostEvent in project onos by opennetworkinglab.

the class VplsManagerTest method testRemoveHost.

/**
 * Removes hosts from a VPLS.
 */
@Test
public void testRemoveHost() {
    VplsData vplsData = VplsData.of(VPLS1, NONE);
    vplsData.addInterface(V100H1);
    vplsData.state(ADDED);
    vplsStore.addVpls(vplsData);
    HostEvent hostEvent = new HostEvent(HostEvent.Type.HOST_REMOVED, V100HOST1);
    hostService.postHostEvent(hostEvent);
    vplsData = vplsStore.getVpls(VPLS1);
    assertNotNull(vplsData);
    assertEquals(vplsData.state(), UPDATING);
}
Also used : HostEvent(org.onosproject.net.host.HostEvent) VplsData(org.onosproject.vpls.api.VplsData) Test(org.junit.Test)

Aggregations

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