Search in sources :

Example 36 with HostEvent

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);
                }
            });
        }
    }));
}
Also used : HostLocation(org.onosproject.net.HostLocation) Tools(org.onlab.util.Tools) Host(org.onosproject.net.Host) PredictableExecutor(org.onlab.util.PredictableExecutor) PortNumber(org.onosproject.net.PortNumber) LoggerFactory(org.slf4j.LoggerFactory) Tools.groupedThreads(org.onlab.util.Tools.groupedThreads) CompletableFuture(java.util.concurrent.CompletableFuture) HostService(org.onosproject.net.host.HostService) ConnectPoint(org.onosproject.net.ConnectPoint) HashSet(java.util.HashSet) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) Lists(com.google.common.collect.Lists) PhasedRecoveryService(org.onosproject.segmentrouting.phasedrecovery.api.PhasedRecoveryService) HostEvent(org.onosproject.net.host.HostEvent) IpAddress(org.onlab.packet.IpAddress) Logger(org.slf4j.Logger) VlanId(org.onlab.packet.VlanId) Set(java.util.Set) Phase(org.onosproject.segmentrouting.phasedrecovery.api.Phase) ProbeMode(org.onosproject.net.host.ProbeMode) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) EthType(org.onlab.packet.EthType) List(java.util.List) Objective(org.onosproject.net.flowobjective.Objective) Optional(java.util.Optional) MacAddress(org.onlab.packet.MacAddress) DeviceId(org.onosproject.net.DeviceId) IpPrefix(org.onlab.packet.IpPrefix) EthType(org.onlab.packet.EthType) HashSet(java.util.HashSet) Set(java.util.Set) HostLocation(org.onosproject.net.HostLocation) Host(org.onosproject.net.Host) IpAddress(org.onlab.packet.IpAddress) MacAddress(org.onlab.packet.MacAddress) VlanId(org.onlab.packet.VlanId)

Example 37 with HostEvent

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();
}
Also used : ProviderId(org.onosproject.net.provider.ProviderId) Host(org.onosproject.net.Host) DefaultHost(org.onosproject.net.DefaultHost) HostListener(org.onosproject.net.host.HostListener) TestUtils.getIntReportConfig(org.stratumproject.fabric.tna.utils.TestUtils.getIntReportConfig) DefaultHost(org.onosproject.net.DefaultHost) HostEvent(org.onosproject.net.host.HostEvent) CompletableFuture(java.util.concurrent.CompletableFuture) HostLocation(org.onosproject.net.HostLocation) ExecutionException(java.util.concurrent.ExecutionException) TimeoutException(java.util.concurrent.TimeoutException) 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