org.onosproject.rest.resources.ModulationWebResource Maven / Gradle / Ivy
/*
* Copyright 2019-present Open Networking Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* This Work is contributed by Sterlite Technologies
*/
package org.onosproject.rest.resources;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import org.onosproject.net.Device;
import org.onosproject.net.Direction;
import org.onosproject.net.ModulationScheme;
import org.onosproject.net.PortNumber;
import org.onosproject.net.behaviour.ModulationConfig;
import org.onosproject.net.device.DeviceService;
import org.onosproject.rest.AbstractWebResource;
import org.slf4j.Logger;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo;
import java.io.IOException;
import java.io.InputStream;
import java.util.Iterator;
import java.util.Map;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.onlab.util.Tools.readTreeFromStream;
import static org.onosproject.net.DeviceId.deviceId;
import static org.slf4j.LoggerFactory.getLogger;
/**
* Query and program flow rules.
*/
@Path("modulation")
public class ModulationWebResource extends AbstractWebResource {
private final Logger log = getLogger(getClass());
@Context
private UriInfo uriInfo;
private static final String DEVICE_NOT_FOUND = "Device is not found";
private static final String APP_ID_NOT_FOUND = "Application Id is not found";
private static final String MODULATIONCONFIG_UNSUPPORTED = "Modulation Config is not supported";
private static final String DEVICES = "modulationConfigDevices";
private static final String DEVICE_ID = "deviceId";
private static final String DEVICE_IDS = "modulationConfigDeviceIds";
private static final String MODULATIONCONFIG_SUPPORTED = "modulationConfigSupported";
private static final String TARGET_MODULATION = "targetModulation";
private static final String TARGET_BITRATE = "targetBitRate";
private static final String JSON_INVALID = "Invalid json input";
private final ObjectMapper mapper = new ObjectMapper();
/**
* Gets all modulation config devices.
* Returns array of all discovered modulation config devices.
*
* @return 200 OK with a collection of devices supporting modulation
*/
@GET
@Produces(MediaType.APPLICATION_JSON)
public Response getModulationSupportedDevices() {
ObjectNode root = mapper().createObjectNode();
ArrayNode deviceIdsNode = root.putArray(DEVICE_IDS);
Iterable devices = get(DeviceService.class).getDevices();
if (devices != null) {
for (Device d : devices) {
if (getModulationConfig(d.id().toString()) != null) {
deviceIdsNode.add(d.id().toString());
}
}
}
return ok(root).build();
}
private ModulationConfig
© 2015 - 2025 Weber Informatics LLC | Privacy Policy