Search in sources :

Example 21 with HostLocation

use of org.onosproject.net.HostLocation in project onos by opennetworkinglab.

the class CreateNullHost method getLocations.

private Set<HostLocation> getLocations(CustomTopologySimulator sim, String deviceNames) throws NoLocationException {
    ImmutableSet.Builder<HostLocation> locations = ImmutableSet.builder();
    String[] csv = deviceNames.split(",");
    for (String s : csv) {
        HostLocation loc = findAvailablePort(sim.deviceId(s));
        if (loc == null) {
            throw new NoLocationException(deviceNames);
        }
        locations.add(requireNonNull(findAvailablePort(sim.deviceId(s))));
    }
    return locations.build();
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) HostLocation(org.onosproject.net.HostLocation)

Example 22 with HostLocation

use of org.onosproject.net.HostLocation in project onos by opennetworkinglab.

the class CreateNullHost method doExecute.

@Override
protected void doExecute() {
    NullProviders service = get(NullProviders.class);
    NetworkConfigService cfgService = get(NetworkConfigService.class);
    TopologySimulator simulator = service.currentSimulator();
    if (!validateSimulator(simulator) || !validateLocType(locType)) {
        return;
    }
    CustomTopologySimulator sim = (CustomTopologySimulator) simulator;
    HostId id = sim.nextHostId();
    Set<HostLocation> locations;
    try {
        locations = getLocations(sim, deviceNames);
    } catch (NoLocationException e) {
        error("\u001B[1;31mHost not created - no location (free port) available on %s\u001B[0m", e.getMessage());
        return;
    }
    Set<IpAddress> ips = getIps(hostIps);
    BasicHostConfig cfg = cfgService.addConfig(id, BasicHostConfig.class);
    setUiCoordinates(cfg, locType, latOrY, longOrX);
    Tools.delay(10);
    sim.createHost(id, locations, ips);
}
Also used : TopologySimulator(org.onosproject.provider.nil.TopologySimulator) CustomTopologySimulator(org.onosproject.provider.nil.CustomTopologySimulator) NetworkConfigService(org.onosproject.net.config.NetworkConfigService) HostLocation(org.onosproject.net.HostLocation) NullProviders(org.onosproject.provider.nil.NullProviders) IpAddress(org.onlab.packet.IpAddress) CustomTopologySimulator(org.onosproject.provider.nil.CustomTopologySimulator) HostId(org.onosproject.net.HostId) BasicHostConfig(org.onosproject.net.config.basics.BasicHostConfig)

Example 23 with HostLocation

use of org.onosproject.net.HostLocation in project onos by opennetworkinglab.

the class CreateNullHosts method doExecute.

@Override
protected void doExecute() {
    NullProviders service = get(NullProviders.class);
    NetworkConfigService cfgService = get(NetworkConfigService.class);
    TopologySimulator simulator = service.currentSimulator();
    if (!validateSimulator(simulator)) {
        return;
    }
    CustomTopologySimulator sim = (CustomTopologySimulator) simulator;
    List<ConnectPoint> points = findAvailablePorts(sim.deviceId(deviceName));
    String pattern = hostIpPattern.replace("*", "%d");
    double yStep = rowGap / hostsPerRow;
    double y = gridY;
    double x = gridX - (colGap * (hostsPerRow - 1)) / 2;
    for (int h = 0; h < hostCount; h++) {
        HostLocation location = new HostLocation(points.get(h), System.currentTimeMillis());
        IpAddress ip = IpAddress.valueOf(String.format(pattern, h));
        HostId id = sim.nextHostId();
        if (gridY != NONE) {
            BasicHostConfig cfg = cfgService.addConfig(id, BasicHostConfig.class);
            setUiCoordinates(cfg, GRID, y, x);
            if (((h + 1) % hostsPerRow) == 0) {
                x = gridX - (colGap * (hostsPerRow - 1)) / 2;
            } else {
                x += colGap;
                y += yStep;
            }
        }
        Tools.delay(10);
        sim.createHost(id, location, ip);
    }
}
Also used : NetworkConfigService(org.onosproject.net.config.NetworkConfigService) CustomTopologySimulator(org.onosproject.provider.nil.CustomTopologySimulator) HostId(org.onosproject.net.HostId) ConnectPoint(org.onosproject.net.ConnectPoint) ConnectPoint(org.onosproject.net.ConnectPoint) BasicHostConfig(org.onosproject.net.config.basics.BasicHostConfig) TopologySimulator(org.onosproject.provider.nil.TopologySimulator) CustomTopologySimulator(org.onosproject.provider.nil.CustomTopologySimulator) HostLocation(org.onosproject.net.HostLocation) NullProviders(org.onosproject.provider.nil.NullProviders) IpAddress(org.onlab.packet.IpAddress)

Example 24 with HostLocation

use of org.onosproject.net.HostLocation in project onos by opennetworkinglab.

the class NetworkConfigHostProvider method readInitialConfig.

private void readInitialConfig() {
    networkConfigRegistry.getSubjects(HostId.class).forEach(hostId -> {
        MacAddress mac = hostId.mac();
        VlanId vlan = hostId.vlanId();
        BasicHostConfig hostConfig = networkConfigRegistry.getConfig(hostId, BasicHostConfig.class);
        Set<IpAddress> ipAddresses = hostConfig.ipAddresses();
        Set<HostLocation> locs = hostConfig.locations();
        if (locs != null) {
            Set<HostLocation> locations = locs.stream().map(hostLocation -> new HostLocation(hostLocation, System.currentTimeMillis())).collect(Collectors.toSet());
            // auxLocations allows to be null
            Set<HostLocation> auxLocations = hostConfig.auxLocations();
            if (auxLocations != null) {
                auxLocations = auxLocations.stream().map(auxLocation -> new HostLocation(auxLocation, System.currentTimeMillis())).collect(Collectors.toSet());
            }
            VlanId innerVlan = hostConfig.innerVlan();
            EthType outerTpid = hostConfig.outerTpid();
            addHost(mac, vlan, locations, auxLocations, ipAddresses, innerVlan, outerTpid);
        } else {
            log.warn("Host {} configuration {} is missing locations", hostId, hostConfig);
        }
    });
}
Also used : NetworkConfigRegistry(org.onosproject.net.config.NetworkConfigRegistry) HostLocation(org.onosproject.net.HostLocation) HostProviderRegistry(org.onosproject.net.host.HostProviderRegistry) Host(org.onosproject.net.Host) CoreService(org.onosproject.core.CoreService) NetworkConfigEvent(org.onosproject.net.config.NetworkConfigEvent) LoggerFactory(org.slf4j.LoggerFactory) HostProviderService(org.onosproject.net.host.HostProviderService) Component(org.osgi.service.component.annotations.Component) DefaultHostDescription(org.onosproject.net.host.DefaultHostDescription) ApplicationId(org.onosproject.core.ApplicationId) BasicHostConfig(org.onosproject.net.config.basics.BasicHostConfig) Activate(org.osgi.service.component.annotations.Activate) HostId(org.onosproject.net.HostId) IpAddress(org.onlab.packet.IpAddress) AbstractProvider(org.onosproject.net.provider.AbstractProvider) Logger(org.slf4j.Logger) Deactivate(org.osgi.service.component.annotations.Deactivate) HostProvider(org.onosproject.net.host.HostProvider) VlanId(org.onlab.packet.VlanId) Set(java.util.Set) ProviderId(org.onosproject.net.provider.ProviderId) Collectors(java.util.stream.Collectors) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) EthType(org.onlab.packet.EthType) MacAddress(org.onlab.packet.MacAddress) Reference(org.osgi.service.component.annotations.Reference) HostDescription(org.onosproject.net.host.HostDescription) NetworkConfigListener(org.onosproject.net.config.NetworkConfigListener) Collections(java.util.Collections) EthType(org.onlab.packet.EthType) HostLocation(org.onosproject.net.HostLocation) IpAddress(org.onlab.packet.IpAddress) HostId(org.onosproject.net.HostId) MacAddress(org.onlab.packet.MacAddress) VlanId(org.onlab.packet.VlanId) BasicHostConfig(org.onosproject.net.config.basics.BasicHostConfig)

Example 25 with HostLocation

use of org.onosproject.net.HostLocation in project onos by opennetworkinglab.

the class DefaultHostProbingProvider method processEvent.

@Override
public void processEvent(HostProbingEvent event) {
    probeEventHandler.execute(() -> {
        log.debug("Receiving HostProbingEvent {}", event);
        HostProbe hostProbe = event.subject();
        switch(event.type()) {
            case PROBE_REQUESTED:
                // Do nothing
                break;
            case PROBE_TIMEOUT:
                // Retry probe until PROBE_FAIL
                // TODO Only retry DISCOVER probes
                probeHostInternal(hostProbe, hostProbe.connectPoint(), hostProbe.mode(), hostProbe.probeMac(), hostProbe.retry());
                break;
            case PROBE_FAIL:
                // Remove this location if this is a verify probe.
                if (hostProbe.mode() == ProbeMode.VERIFY) {
                    ConnectPoint oldConnectPoint = hostProbe.connectPoint();
                    if (!oldConnectPoint.port().hasName()) {
                        oldConnectPoint = translateSwitchPort(oldConnectPoint);
                    }
                    providerService.removeLocationFromHost(hostProbe.id(), new HostLocation(oldConnectPoint, 0L));
                }
                break;
            case PROBE_COMPLETED:
                // Add this location if this is a discover probe.
                if (hostProbe.mode() == ProbeMode.DISCOVER) {
                    ConnectPoint newConnectPoint = hostProbe.connectPoint();
                    if (!newConnectPoint.port().hasName()) {
                        newConnectPoint = translateSwitchPort(newConnectPoint);
                    }
                    providerService.addLocationToHost(hostProbe.id(), new HostLocation(newConnectPoint, System.currentTimeMillis()));
                }
                break;
            default:
                log.warn("Unknown HostProbingEvent type: {}", event.type());
        }
    });
}
Also used : HostProbe(org.onosproject.net.host.HostProbe) HostLocation(org.onosproject.net.HostLocation) ConnectPoint(org.onosproject.net.ConnectPoint)

Aggregations

HostLocation (org.onosproject.net.HostLocation)52 IpAddress (org.onlab.packet.IpAddress)29 MacAddress (org.onlab.packet.MacAddress)25 VlanId (org.onlab.packet.VlanId)22 HostId (org.onosproject.net.HostId)22 Host (org.onosproject.net.Host)19 ConnectPoint (org.onosproject.net.ConnectPoint)15 Test (org.junit.Test)14 DefaultHost (org.onosproject.net.DefaultHost)14 DeviceId (org.onosproject.net.DeviceId)12 HostDescription (org.onosproject.net.host.HostDescription)11 ProviderId (org.onosproject.net.provider.ProviderId)11 Set (java.util.Set)10 DefaultHostDescription (org.onosproject.net.host.DefaultHostDescription)10 Logger (org.slf4j.Logger)8 ImmutableSet (com.google.common.collect.ImmutableSet)7 Collectors (java.util.stream.Collectors)7 PortNumber (org.onosproject.net.PortNumber)7 DeviceEvent (org.onosproject.net.device.DeviceEvent)7 HostService (org.onosproject.net.host.HostService)7