Java Code Examples for org.onosproject.net.config.NetworkConfigService#applyConfig()

The following examples show how to use org.onosproject.net.config.NetworkConfigService#applyConfig() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NetworkConfigWebResource.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Upload specific network configuration for a subjectKey.
 *
 * @param subjectClassKey subjectKey class key
 * @param subjectKey      subjectKey key
 * @param configKey       configuration class key
 * @param request         network configuration JSON rooted at the top node
 * @return 200 OK
 * @throws IOException if unable to parse the request
 */
@POST
@Path("{subjectClassKey}/{subjectKey}/{configKey}")
@Consumes(MediaType.APPLICATION_JSON)
@SuppressWarnings("unchecked")
public Response upload(@PathParam("subjectClassKey") String subjectClassKey,
                       @PathParam("subjectKey") String subjectKey,
                       @PathParam("configKey") String configKey,
                       InputStream request) throws IOException {
    NetworkConfigService service = get(NetworkConfigService.class);
    JsonNode root = readTreeFromStream(mapper(), request);
    SubjectFactory subjectFactory =
            nullIsNotFound(service.getSubjectFactory(subjectClassKey),
                    subjectClassNotValidErrorString(subjectClassKey));
    service.applyConfig(subjectClassKey, subjectFactory.createSubject(subjectKey),
                        configKey, root);
    return Response.ok().build();
}
 
Example 2
Source File: AnnotateDeviceCommand.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
protected void doExecute() {
    NetworkConfigService netcfgService = get(NetworkConfigService.class);
    DeviceId deviceId = DeviceId.deviceId(uri);

    if (key == null) {
        print("[ERROR] Annotation key not specified.");
        return;
    }
    DeviceAnnotationConfig cfg = netcfgService.getConfig(deviceId, DeviceAnnotationConfig.class);
    if (cfg == null) {
        cfg = new DeviceAnnotationConfig(deviceId);
    }
    if (removeCfg) {
        // remove config about entry
        cfg.annotation(key);
    } else {
        // add remove request config
        cfg.annotation(key, value);
    }
    netcfgService.applyConfig(deviceId, DeviceAnnotationConfig.class, cfg.node());
}
 
Example 3
Source File: AnnotateHostCommand.java    From onos with Apache License 2.0 6 votes vote down vote up
@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());
}
 
Example 4
Source File: AddPeerCommand.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
protected void doExecute() {
    peerAddress = IpAddress.valueOf(ip);

    NetworkConfigService configService = get(NetworkConfigService.class);
    CoreService coreService = get(CoreService.class);
    ApplicationId appId = coreService.getAppId(RoutingService.ROUTER_APP_ID);

    BgpConfig config = configService.getConfig(appId, BgpConfig.class);
    if (config == null || config.bgpSpeakers().isEmpty()) {
        print(NO_CONFIGURATION);
        return;
    }

    BgpConfig.BgpSpeakerConfig speaker = config.getSpeakerWithName(name);
    if (speaker == null) {
        print(SPEAKER_NOT_FOUND, name);
        return;
    } else {
        if (speaker.isConnectedToPeer(peerAddress)) {
            return; // Peering already exists.
        }
    }

    InterfaceService interfaceService = get(InterfaceService.class);
    if (interfaceService.getMatchingInterface(peerAddress) == null) {
        print(NO_INTERFACE, ip);
        return;
    }

    addPeerToSpeakerConf(config);
    configService.applyConfig(appId, BgpConfig.class, config.node());

    print(PEER_ADD_SUCCESS);
}
 
Example 5
Source File: RemovePeerCommand.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
protected void doExecute() {
    peerAddress = IpAddress.valueOf(ip);

    NetworkConfigService configService = get(NetworkConfigService.class);
    CoreService coreService = get(CoreService.class);
    ApplicationId appId = coreService.getAppId(RoutingService.ROUTER_APP_ID);

    BgpConfig config = configService.getConfig(appId, BgpConfig.class);
    if (config == null || config.bgpSpeakers().isEmpty()) {
        print(NO_CONFIGURATION);
        return;
    }

    peerAddress = IpAddress.valueOf(ip);

    BgpConfig.BgpSpeakerConfig speaker = config.getSpeakerFromPeer(peerAddress);
    if (speaker == null) {
        print(PEER_NOT_FOUND, ip);
        return;
    }

    removePeerFromSpeakerConf(speaker, config);
    configService.applyConfig(appId, BgpConfig.class, config.node());

    print(PEER_REMOVE_SUCCESS);
}
 
Example 6
Source File: RemoveSpeakerCommand.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
protected void doExecute() {
    NetworkConfigService configService = get(NetworkConfigService.class);
    CoreService coreService = get(CoreService.class);
    ApplicationId appId = coreService.getAppId(RoutingService.ROUTER_APP_ID);

    BgpConfig config = configService.getConfig(appId, BgpConfig.class);
    if (config == null || config.bgpSpeakers().isEmpty()) {
        print(NO_CONFIGURATION);
        return;
    }

    BgpConfig.BgpSpeakerConfig speaker = config.getSpeakerWithName(name);
    if (speaker == null) {
        print(SPEAKER_NOT_FOUND, name);
        return;
    } else {
        if (!speaker.peers().isEmpty()) {
            // Removal not allowed when peer connections exist.
            print(PEERS_EXIST, name);
            return;
        }
    }

    removeSpeakerFromConf(config);
    configService.applyConfig(appId, BgpConfig.class, config.node());

    print(SPEAKER_REMOVE_SUCCESS);
}
 
Example 7
Source File: AddSpeakerCommand.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
protected void doExecute() {
    NetworkConfigService configService = get(NetworkConfigService.class);
    CoreService coreService = get(CoreService.class);
    ApplicationId appId = coreService.getAppId(RoutingService.ROUTER_APP_ID);

    BgpConfig config = configService.addConfig(appId, BgpConfig.class);

    if (name != null) {
        BgpConfig.BgpSpeakerConfig speaker = config.getSpeakerWithName(name);
        if (speaker != null) {
            log.debug("Speaker already exists: {}", name);
            return;
        }
    }

    if (vlanId == null || vlanId.isEmpty()) {
        vlanIdObj = VlanId.NONE;
    } else {
        vlanIdObj = VlanId.vlanId(Short.valueOf(vlanId));
    }

    addSpeakerToConf(config);
    configService.applyConfig(appId, BgpConfig.class, config.node());

    print(SPEAKER_ADD_SUCCESS);
}
 
Example 8
Source File: BlackHoleCommand.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
protected void doExecute() {
    SegmentRoutingService srService = AbstractShellCommand.get(SegmentRoutingService.class);
    NetworkConfigService netcfgService = AbstractShellCommand.get(NetworkConfigService.class);

    SegmentRoutingAppConfig appConfig = netcfgService.getConfig(srService.appId(), SegmentRoutingAppConfig.class);
    if (appConfig == null) {
        JsonNode jsonNode = new ObjectMapper().createObjectNode();
        netcfgService.applyConfig(srService.appId(), SegmentRoutingAppConfig.class, jsonNode);
        appConfig = netcfgService.getConfig(srService.appId(), SegmentRoutingAppConfig.class);
    }

    Set<IpPrefix> blackHoleIps;
    switch (op) {
        case "list":
            appConfig.blackholeIPs().forEach(prefix -> print(prefix.toString()));
            break;
        case "add":
            blackHoleIps = Sets.newConcurrentHashSet(appConfig.blackholeIPs());
            blackHoleIps.add(IpPrefix.valueOf(prefix));
            appConfig.setBalckholeIps(blackHoleIps);
            break;
        case "remove":
            blackHoleIps = Sets.newConcurrentHashSet(appConfig.blackholeIPs());
            blackHoleIps.remove(IpPrefix.valueOf(prefix));
            appConfig.setBalckholeIps(blackHoleIps);
            break;
        default:
            throw new UnsupportedOperationException("Unknown operation " + op);
    }
}