use of org.onosproject.net.device.DeviceEvent in project onos by opennetworkinglab.
the class ControlPlaneRedirectManagerTest method testAddDevice.
/**
* Tests adding new Device to a openflow router.
*/
@Test
public void testAddDevice() {
ConnectPoint sw1eth4 = new ConnectPoint(DEVICE_ID, PortNumber.portNumber(4));
List<InterfaceIpAddress> interfaceIpAddresses = new ArrayList<>();
interfaceIpAddresses.add(new InterfaceIpAddress(IpAddress.valueOf("192.168.40.101"), IpPrefix.valueOf("192.168.40.0/24")));
interfaceIpAddresses.add(new InterfaceIpAddress(IpAddress.valueOf("2000::ff"), IpPrefix.valueOf("2000::ff/120")));
Interface sw1Eth4 = new Interface(sw1eth4.deviceId().toString(), sw1eth4, interfaceIpAddresses, MacAddress.valueOf("00:00:00:00:00:04"), VlanId.NONE);
interfaces.add(sw1Eth4);
EasyMock.reset(flowObjectiveService);
setUpFlowObjectiveService();
deviceListener.event(new DeviceEvent(DeviceEvent.Type.DEVICE_AVAILABILITY_CHANGED, dev3));
verify(flowObjectiveService);
}
use of org.onosproject.net.device.DeviceEvent in project onos by opennetworkinglab.
the class DhcpRelayManagerTest method testInstallIgnoreRuleWhenDeviceComesUp.
/**
* Should try install ignore rules when device comes up.
*/
@Test
public void testInstallIgnoreRuleWhenDeviceComesUp() throws IOException {
ObjectMapper om = new ObjectMapper();
JsonNode json = om.readTree(Resources.getResource(CONFIG_FILE_PATH));
IgnoreDhcpConfig config = new IgnoreDhcpConfig();
json = json.path("apps").path(DHCP_RELAY_APP).path(IgnoreDhcpConfig.KEY);
config.init(APP_ID, IgnoreDhcpConfig.KEY, json, om, null);
reset(manager.cfgService, flowObjectiveService, manager.deviceService);
expect(manager.cfgService.getConfig(APP_ID, IgnoreDhcpConfig.class)).andReturn(config).anyTimes();
Device device = createNiceMock(Device.class);
expect(device.is(Pipeliner.class)).andReturn(true).anyTimes();
expect(device.id()).andReturn(DEV_1_ID).anyTimes();
expect(manager.deviceService.getDevice(DEV_1_ID)).andReturn(device).anyTimes();
DeviceEvent event = new DeviceEvent(DeviceEvent.Type.DEVICE_ADDED, device);
Capture<Objective> capturedFromDev1 = newCapture(CaptureType.ALL);
flowObjectiveService.apply(eq(DEV_1_ID), capture(capturedFromDev1));
expectLastCall().times(DHCP_SELECTORS.size());
replay(manager.cfgService, flowObjectiveService, manager.deviceService, device);
manager.deviceListener.event(event);
// Wait until all flow objective events are captured before triggering onSuccess
int expectFlowObjCount = Dhcp4HandlerImpl.DHCP_SELECTORS.size() + Dhcp6HandlerImpl.DHCP_SELECTORS.size();
assertAfter(EVENT_PROCESSING_MS, () -> assertEquals(expectFlowObjCount, capturedFromDev1.getValues().size()));
capturedFromDev1.getValues().forEach(obj -> obj.context().ifPresent(ctx -> ctx.onSuccess(obj)));
assertAfter(EVENT_PROCESSING_MS, () -> assertEquals(1, v4Handler.ignoredVlans.size()));
assertAfter(EVENT_PROCESSING_MS, () -> assertEquals(1, v6Handler.ignoredVlans.size()));
}
use of org.onosproject.net.device.DeviceEvent 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.device.DeviceEvent 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.device.DeviceEvent in project onos by opennetworkinglab.
the class AlarmManagerTest method testRemoveWhenDeviceRemoved.
@Test
public void testRemoveWhenDeviceRemoved() {
providerService.updateAlarmList(DEVICE_ID, ImmutableSet.of(ALARM_B, ALARM_A));
verifyGettingSetsOfAlarms(manager, 2, 2);
validateEvents(AlarmEvent.Type.CREATED, AlarmEvent.Type.CREATED);
Map<Alarm.SeverityLevel, Long> critical2 = new CountsMapBuilder().with(CRITICAL, 2L).create();
assertEquals("A critical should be present", critical2, manager.getAlarmCounts());
assertEquals("A critical should be present", critical2, manager.getAlarmCounts(DEVICE_ID));
deviceService.deviceListener.event(new DeviceEvent(DeviceEvent.Type.DEVICE_REMOVED, device));
Map<Alarm.SeverityLevel, Long> zeroAlarms = new CountsMapBuilder().create();
assertEquals("The counts should be empty for removed device", zeroAlarms, manager.getAlarmCounts(DEVICE_ID));
}
Aggregations