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);
}
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);
}
}
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);
}
}
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());
}
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);
}
Aggregations