use of org.onosproject.net.host.HostEvent in project trellis-control by opennetworkinglab.
the class HostHandler method processHostUpdatedEventInternal.
private void processHostUpdatedEventInternal(HostEvent event) {
Host host = event.subject();
MacAddress hostMac = host.mac();
VlanId hostVlanId = host.vlan();
EthType hostTpid = host.tpid();
Set<HostLocation> locations = effectiveLocations(host);
Set<IpAddress> prevIps = event.prevSubject().ipAddresses();
Set<IpAddress> newIps = host.ipAddresses();
log.info("Host {}/{} is updated", hostMac, hostVlanId);
locations.forEach(location -> {
Sets.difference(prevIps, newIps).forEach(ip -> {
if (isDoubleTaggedHost(host)) {
processDoubleTaggedRoutingRule(location.deviceId(), location.port(), hostMac, host.innerVlan(), hostVlanId, hostTpid, ip, true);
} else {
processRoutingRule(location.deviceId(), location.port(), hostMac, hostVlanId, ip, true);
}
});
Sets.difference(newIps, prevIps).forEach(ip -> {
if (isDoubleTaggedHost(host)) {
processDoubleTaggedRoutingRule(location.deviceId(), location.port(), hostMac, host.innerVlan(), hostVlanId, hostTpid, ip, false);
} else {
processRoutingRule(location.deviceId(), location.port(), hostMac, hostVlanId, ip, false);
}
});
});
// Use the pair link temporarily before the second location of a dual-homed host shows up.
// This do not affect single-homed hosts since the flow will be blocked in
// processBridgingRule or processRoutingRule due to VLAN or IP mismatch respectively
locations.forEach(location -> srManager.getPairDeviceId(location.deviceId()).ifPresent(pairDeviceId -> {
if (locations.stream().noneMatch(l -> l.deviceId().equals(pairDeviceId))) {
Set<IpAddress> ipsToAdd = Sets.difference(newIps, prevIps);
Set<IpAddress> ipsToRemove = Sets.difference(prevIps, newIps);
srManager.getPairLocalPort(pairDeviceId).ifPresent(pairRemotePort -> {
// NOTE: Since the pairLocalPort is trunk port, use assigned vlan of original port
// when the host is untagged
VlanId vlanId = vlanForPairPort(hostVlanId, location);
if (vlanId == null) {
return;
}
ipsToRemove.forEach(ip -> processRoutingRule(pairDeviceId, pairRemotePort, hostMac, vlanId, ip, true));
ipsToAdd.forEach(ip -> processRoutingRule(pairDeviceId, pairRemotePort, hostMac, vlanId, ip, false));
if (srManager.activeProbing) {
probe(host, location, pairDeviceId, pairRemotePort);
}
});
}
}));
}
use of org.onosproject.net.host.HostEvent in project fabric-tna by stratum.
the class IntManagerTest method testWithHostEvent.
/**
* Test when receving an host event with IP address of the collector.
*/
@Test
public void testWithHostEvent() {
testActivateWithConfig();
Host host = new DefaultHost(new ProviderId("of", "foo"), HostId.hostId("00:00:00:00:00:01/None"), MacAddress.valueOf("00:00:00:00:00:01"), VlanId.NONE, new HostLocation(ConnectPoint.fromString("device:leaf1/1"), 0), ImmutableSet.of(COLLECTOR_IP));
HostListener listener = hostListener.getValue();
CompletableFuture<Void> completableFuture = new CompletableFuture<>();
reset(intProgrammable, netcfgService, deviceService, mastershipService);
expect(netcfgService.getConfig(APP_ID, IntReportConfig.class)).andReturn(INT_CONFIG_1).anyTimes();
expect(intProgrammable.setUpIntConfig(INT_CONFIG_1)).andAnswer(() -> {
completableFuture.complete(null);
return true;
}).once();
expect(deviceService.getAvailableDevices()).andReturn(ImmutableList.of(mockDevice)).anyTimes();
expect(deviceService.isAvailable(DEVICE_ID_1)).andReturn(true).anyTimes();
expect(mastershipService.isLocalMaster(DEVICE_ID_1)).andReturn(true).anyTimes();
replay(intProgrammable, netcfgService, deviceService, mastershipService);
HostEvent hostEvent = new HostEvent(HostEvent.Type.HOST_ADDED, host);
listener.event(hostEvent);
try {
completableFuture.get(1, TimeUnit.SECONDS);
} catch (InterruptedException | ExecutionException | TimeoutException e) {
fail("Didn't get expected call within 1 second.");
}
verifyAll();
}
Aggregations