Search in sources :

Example 11 with HostEvent

use of org.onosproject.net.host.HostEvent in project trellis-control by opennetworkinglab.

the class RouteHandlerTest method testDualHomedSingleLocationFailSingleLeafPair.

@Test
public void testDualHomedSingleLocationFailSingleLeafPair() {
    srManager.setInfraDeviceIds(List.of());
    testOneDualHomedAddedSingleLeafPair();
    ROUTE_STORE.put(P1, Sets.newHashSet(RR3));
    reset(srManager.deviceConfiguration);
    expect(srManager.deviceConfiguration.getBatchedSubnets(H3D.id())).andReturn(Lists.<Set<IpPrefix>>newArrayList(Sets.newHashSet(P1)));
    srManager.deviceConfiguration.removeSubnet(CP2, P1);
    expectLastCall().once();
    replay(srManager.deviceConfiguration);
    HostEvent he = new HostEvent(HostEvent.Type.HOST_MOVED, H3S, H3D);
    routeHandler.processHostMovedEvent(he);
    // We do not remove the route on CP2. Instead, we let the subnet population overrides it
    assertEquals(2, ROUTING_TABLE.size());
    MockRoutingTableValue rtv1 = ROUTING_TABLE.get(new MockRoutingTableKey(CP1.deviceId(), P1));
    assertEquals(M3, rtv1.macAddress);
    assertEquals(V3, rtv1.vlanId);
    assertEquals(CP1.port(), rtv1.portNumber);
    MockRoutingTableValue rtv2 = ROUTING_TABLE.get(new MockRoutingTableKey(CP2.deviceId(), P1));
    assertEquals(ROUTER_MAC_1, rtv2.macAddress);
    assertEquals(V3, rtv2.vlanId);
    assertEquals(P9, rtv2.portNumber);
    // ECMP route table hasn't changed
    assertEquals(1, SUBNET_TABLE.size());
    assertTrue(SUBNET_TABLE.get(CP1).contains(P1));
    verify(srManager.deviceConfiguration);
}
Also used : IpPrefix(org.onlab.packet.IpPrefix) HostEvent(org.onosproject.net.host.HostEvent) Test(org.junit.Test)

Example 12 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 13 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 14 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 15 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)37 Test (org.junit.Test)29 Host (org.onosproject.net.Host)25 DefaultHost (org.onosproject.net.DefaultHost)22 IpPrefix (org.onlab.packet.IpPrefix)8 List (java.util.List)4 IpAddress (org.onlab.packet.IpAddress)4 MacAddress (org.onlab.packet.MacAddress)4 VplsData (org.onosproject.vpls.api.VplsData)4 Sets (com.google.common.collect.Sets)3 Optional (java.util.Optional)3 Set (java.util.Set)3 CompletableFuture (java.util.concurrent.CompletableFuture)3 ExecutionException (java.util.concurrent.ExecutionException)3 Collectors (java.util.stream.Collectors)3 VlanId (org.onlab.packet.VlanId)3 HostLocation (org.onosproject.net.HostLocation)3 ResolvedRoute (org.onosproject.routeservice.ResolvedRoute)3 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)2 Lists (com.google.common.collect.Lists)2