Search in sources :

Example 1 with BasicHostConfig

use of org.onosproject.net.config.basics.BasicHostConfig 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 2 with BasicHostConfig

use of org.onosproject.net.config.basics.BasicHostConfig 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 3 with BasicHostConfig

use of org.onosproject.net.config.basics.BasicHostConfig 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 4 with BasicHostConfig

use of org.onosproject.net.config.basics.BasicHostConfig in project onos by opennetworkinglab.

the class TopologyViewMessageHandlerBase method hostMessage.

// Produces a host event message to the client.
protected ObjectNode hostMessage(HostEvent event) {
    Host host = event.subject();
    Host prevHost = event.prevSubject();
    String hostType = host.annotations().value(AnnotationKeys.UI_TYPE);
    String connectionType = host.annotations().value(AnnotationKeys.CONNECTION_TYPE);
    String ip = ip(host.ipAddresses());
    ObjectNode payload = objectNode().put("id", host.id().toString()).put("type", isNullOrEmpty(hostType) ? "endstation" : hostType).put("connectionType", isNullOrEmpty(connectionType) ? "wired" : connectionType);
    // set most recent connect point (and previous if we know it)
    payload.set("cp", hostConnect(host.location()));
    if (prevHost != null && prevHost.location() != null) {
        payload.set("prevCp", hostConnect(prevHost.location()));
    }
    // set ALL connect points
    addAllCps(host.locations(), payload);
    payload.set("labels", labels(nameForHost(host), ip, host.mac().toString(), ""));
    payload.set("props", props(host.annotations()));
    BasicHostConfig cfg = get(NetworkConfigService.class).getConfig(host.id(), BasicHostConfig.class);
    if (!addLocation(cfg, payload)) {
        addMetaUi(host.id().toString(), payload);
    }
    String type = HOST_EVENT.get(event.type());
    return JsonUtils.envelope(type, payload);
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) NetworkConfigService(org.onosproject.net.config.NetworkConfigService) Host(org.onosproject.net.Host) TopoUtils.compactLinkString(org.onosproject.ui.topo.TopoUtils.compactLinkString) BasicHostConfig(org.onosproject.net.config.basics.BasicHostConfig)

Aggregations

BasicHostConfig (org.onosproject.net.config.basics.BasicHostConfig)4 IpAddress (org.onlab.packet.IpAddress)3 HostId (org.onosproject.net.HostId)3 HostLocation (org.onosproject.net.HostLocation)3 NetworkConfigService (org.onosproject.net.config.NetworkConfigService)3 Host (org.onosproject.net.Host)2 CustomTopologySimulator (org.onosproject.provider.nil.CustomTopologySimulator)2 NullProviders (org.onosproject.provider.nil.NullProviders)2 TopologySimulator (org.onosproject.provider.nil.TopologySimulator)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 Collections (java.util.Collections)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 EthType (org.onlab.packet.EthType)1 MacAddress (org.onlab.packet.MacAddress)1 VlanId (org.onlab.packet.VlanId)1 ApplicationId (org.onosproject.core.ApplicationId)1 CoreService (org.onosproject.core.CoreService)1 ConnectPoint (org.onosproject.net.ConnectPoint)1 NetworkConfigEvent (org.onosproject.net.config.NetworkConfigEvent)1