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