Search in sources :

Example 16 with NetworkConfigService

use of org.onosproject.net.config.NetworkConfigService 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 17 with NetworkConfigService

use of org.onosproject.net.config.NetworkConfigService 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 18 with NetworkConfigService

use of org.onosproject.net.config.NetworkConfigService in project up4 by omec-project.

the class ConfigPscEncap method doExecute.

@Override
protected void doExecute() throws Exception {
    if (enable == null) {
        return;
    }
    NetworkConfigService netCfgService = get(NetworkConfigService.class);
    CoreService coreService = get(CoreService.class);
    ApplicationId appId = coreService.getAppId(APP_NAME);
    Up4Config config = netCfgService.getConfig(appId, Up4Config.class);
    if (config == null) {
        print("No UP4 netcfg has been pushed yet");
        return;
    }
    config.setPscEncap(enable);
    netCfgService.applyConfig(appId, Up4Config.class, config.node());
}
Also used : NetworkConfigService(org.onosproject.net.config.NetworkConfigService) CoreService(org.onosproject.core.CoreService) ApplicationId(org.onosproject.core.ApplicationId) Up4Config(org.omecproject.up4.config.Up4Config)

Example 19 with NetworkConfigService

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

the class ProtectionEndpointIntentInstaller method apply.

@Override
public void apply(IntentOperationContext<ProtectionEndpointIntent> context) {
    Optional<IntentData> toUninstall = context.toUninstall();
    Optional<IntentData> toInstall = context.toInstall();
    List<ProtectionEndpointIntent> uninstallIntents = context.intentsToUninstall();
    List<ProtectionEndpointIntent> installIntents = context.intentsToInstall();
    if (!toInstall.isPresent() && !toUninstall.isPresent()) {
        intentInstallCoordinator.intentInstallSuccess(context);
        return;
    }
    if (toUninstall.isPresent()) {
        IntentData intentData = toUninstall.get();
        trackerService.removeTrackedResources(intentData.key(), intentData.intent().resources());
        uninstallIntents.forEach(installable -> trackerService.removeTrackedResources(intentData.intent().key(), installable.resources()));
    }
    if (toInstall.isPresent()) {
        IntentData intentData = toInstall.get();
        trackerService.addTrackedResources(intentData.key(), intentData.intent().resources());
        installIntents.forEach(installable -> trackerService.addTrackedResources(intentData.key(), installable.resources()));
    }
    List<Stage> stages = new ArrayList<>();
    stages.add(new Stage(uninstallIntents.stream().map(i -> Pair.of(i, REMOVE)).collect(Collectors.toList())));
    stages.add(new Stage(installIntents.stream().map(i -> Pair.of(i, ADD)).collect(Collectors.toList())));
    for (Stage stage : stages) {
        log.debug("applying Stage {}", stage);
        try {
            // wait for stage completion
            stage.apply();
            stage.listeners().forEach(networkConfigService::removeListener);
        } catch (IntentException e) {
            log.error("Stage {} failed, reason: {}", stage, e.toString());
            intentInstallCoordinator.intentInstallFailed(context);
            return;
        }
    }
    // All stage success
    intentInstallCoordinator.intentInstallSuccess(context);
}
Also used : NetworkConfigService(org.onosproject.net.config.NetworkConfigService) NetworkConfigEvent(org.onosproject.net.config.NetworkConfigEvent) TimeoutException(java.util.concurrent.TimeoutException) CompletableFuture(java.util.concurrent.CompletableFuture) IntentData(org.onosproject.net.intent.IntentData) ArrayList(java.util.ArrayList) ADD(org.onosproject.net.intent.IntentInstaller.Direction.ADD) Component(org.osgi.service.component.annotations.Component) Pair(org.apache.commons.lang3.tuple.Pair) Activate(org.osgi.service.component.annotations.Activate) ProtectedTransportEndpointDescription(org.onosproject.net.behaviour.protection.ProtectedTransportEndpointDescription) IntentInstaller(org.onosproject.net.intent.IntentInstaller) ImmutableSet(com.google.common.collect.ImmutableSet) Logger(org.slf4j.Logger) Deactivate(org.osgi.service.component.annotations.Deactivate) IntentExtensionService(org.onosproject.net.intent.IntentExtensionService) Collection(java.util.Collection) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) Set(java.util.Set) IntentOperationContext(org.onosproject.net.intent.IntentOperationContext) ProtectionConfig(org.onosproject.net.behaviour.protection.ProtectionConfig) IntentManager(org.onosproject.net.intent.impl.IntentManager) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) ObjectiveTrackerService(org.onosproject.net.intent.ObjectiveTrackerService) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) IntentException(org.onosproject.net.intent.IntentException) List(java.util.List) REMOVE(org.onosproject.net.intent.IntentInstaller.Direction.REMOVE) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) Optional(java.util.Optional) Reference(org.osgi.service.component.annotations.Reference) DeviceId(org.onosproject.net.DeviceId) IntentInstallCoordinator(org.onosproject.net.intent.IntentInstallCoordinator) NetworkConfigListener(org.onosproject.net.config.NetworkConfigListener) Type(org.onosproject.net.config.NetworkConfigEvent.Type) ProtectionEndpointIntent(org.onosproject.net.intent.ProtectionEndpointIntent) IntentException(org.onosproject.net.intent.IntentException) IntentData(org.onosproject.net.intent.IntentData) ArrayList(java.util.ArrayList) ProtectionEndpointIntent(org.onosproject.net.intent.ProtectionEndpointIntent)

Example 20 with NetworkConfigService

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

the class AnnotateHostCommand method doExecute.

@Override
protected void doExecute() {
    NetworkConfigService netcfgService = get(NetworkConfigService.class);
    HostId hostId = HostId.hostId(uri);
    if (key == null) {
        print("[ERROR] Annotation key not specified.");
        return;
    }
    HostAnnotationConfig cfg = netcfgService.getConfig(hostId, HostAnnotationConfig.class);
    if (cfg == null) {
        cfg = new HostAnnotationConfig(hostId);
    }
    if (removeCfg) {
        // remove config about entry
        cfg.annotation(key);
    } else {
        // add request config
        cfg.annotation(key, value);
    }
    netcfgService.applyConfig(hostId, HostAnnotationConfig.class, cfg.node());
}
Also used : NetworkConfigService(org.onosproject.net.config.NetworkConfigService) HostId(org.onosproject.net.HostId) HostAnnotationConfig(org.onosproject.net.config.basics.HostAnnotationConfig)

Aggregations

NetworkConfigService (org.onosproject.net.config.NetworkConfigService)34 CoreService (org.onosproject.core.CoreService)10 DeviceId (org.onosproject.net.DeviceId)9 ApplicationId (org.onosproject.core.ApplicationId)7 ConnectPoint (org.onosproject.net.ConnectPoint)6 DeviceService (org.onosproject.net.device.DeviceService)6 BgpConfig (org.onosproject.routing.config.BgpConfig)5 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)3 ArrayList (java.util.ArrayList)3 Path (javax.ws.rs.Path)3 Before (org.junit.Before)3 NetworkConfigListener (org.onosproject.net.config.NetworkConfigListener)3 SubjectFactory (org.onosproject.net.config.SubjectFactory)3 BasicDeviceConfig (org.onosproject.net.config.basics.BasicDeviceConfig)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 Optional (java.util.Optional)2 Set (java.util.Set)2 Consumes (javax.ws.rs.Consumes)2 DELETE (javax.ws.rs.DELETE)2 GET (javax.ws.rs.GET)2