Search in sources :

Example 21 with ItemNotFoundException

use of org.onlab.util.ItemNotFoundException in project onos by opennetworkinglab.

the class ExtensionCriterionSerializer method read.

@Override
public ExtensionCriterion read(Kryo kryo, Input input, Class<ExtensionCriterion> type) {
    ExtensionSelectorType exType = (ExtensionSelectorType) kryo.readClassAndObject(input);
    DeviceId deviceId = (DeviceId) kryo.readClassAndObject(input);
    DriverService driverService = DefaultServiceDirectory.getService(DriverService.class);
    byte[] bytes = (byte[]) kryo.readClassAndObject(input);
    ExtensionSelector selector;
    try {
        DriverHandler handler = new DefaultDriverHandler(new DefaultDriverData(driverService.getDriver(deviceId), deviceId));
        ExtensionSelectorResolver resolver = handler.behaviour(ExtensionSelectorResolver.class);
        selector = resolver.getExtensionSelector(exType);
        selector.deserialize(bytes);
    } catch (ItemNotFoundException | IllegalArgumentException e) {
        selector = new UnresolvedExtensionSelector(bytes, exType);
    }
    return Criteria.extension(selector, deviceId);
}
Also used : UnresolvedExtensionSelector(org.onosproject.net.flow.criteria.UnresolvedExtensionSelector) ExtensionSelector(org.onosproject.net.flow.criteria.ExtensionSelector) DeviceId(org.onosproject.net.DeviceId) DefaultDriverHandler(org.onosproject.net.driver.DefaultDriverHandler) ExtensionSelectorResolver(org.onosproject.net.behaviour.ExtensionSelectorResolver) UnresolvedExtensionSelector(org.onosproject.net.flow.criteria.UnresolvedExtensionSelector) DriverHandler(org.onosproject.net.driver.DriverHandler) DefaultDriverHandler(org.onosproject.net.driver.DefaultDriverHandler) ExtensionSelectorType(org.onosproject.net.flow.criteria.ExtensionSelectorType) DriverService(org.onosproject.net.driver.DriverService) DefaultDriverData(org.onosproject.net.driver.DefaultDriverData) ItemNotFoundException(org.onlab.util.ItemNotFoundException)

Example 22 with ItemNotFoundException

use of org.onlab.util.ItemNotFoundException in project onos by opennetworkinglab.

the class ExtensionInstructionSerializer method read.

@Override
public Instructions.ExtensionInstructionWrapper read(Kryo kryo, Input input, Class<Instructions.ExtensionInstructionWrapper> type) {
    ExtensionTreatmentType exType = (ExtensionTreatmentType) kryo.readClassAndObject(input);
    DeviceId deviceId = (DeviceId) kryo.readClassAndObject(input);
    String driverName = (String) kryo.readClassAndObject(input);
    DriverService driverService = DefaultServiceDirectory.getService(DriverService.class);
    byte[] bytes = (byte[]) kryo.readClassAndObject(input);
    ExtensionTreatment instruction;
    try {
        DriverHandler handler = new DefaultDriverHandler(new DefaultDriverData(driverService.getDriver(driverName), deviceId));
        ExtensionTreatmentResolver resolver = handler.behaviour(ExtensionTreatmentResolver.class);
        instruction = resolver.getExtensionInstruction(exType);
        instruction.deserialize(bytes);
    } catch (ItemNotFoundException | IllegalArgumentException e) {
        instruction = new UnresolvedExtensionTreatment(bytes, exType);
    }
    return Instructions.extension(instruction, deviceId);
}
Also used : DeviceId(org.onosproject.net.DeviceId) DefaultDriverHandler(org.onosproject.net.driver.DefaultDriverHandler) ExtensionTreatmentResolver(org.onosproject.net.behaviour.ExtensionTreatmentResolver) UnresolvedExtensionTreatment(org.onosproject.net.flow.instructions.UnresolvedExtensionTreatment) DriverHandler(org.onosproject.net.driver.DriverHandler) DefaultDriverHandler(org.onosproject.net.driver.DefaultDriverHandler) ExtensionTreatment(org.onosproject.net.flow.instructions.ExtensionTreatment) UnresolvedExtensionTreatment(org.onosproject.net.flow.instructions.UnresolvedExtensionTreatment) ExtensionTreatmentType(org.onosproject.net.flow.instructions.ExtensionTreatmentType) DriverService(org.onosproject.net.driver.DriverService) DefaultDriverData(org.onosproject.net.driver.DefaultDriverData) ItemNotFoundException(org.onlab.util.ItemNotFoundException)

Example 23 with ItemNotFoundException

use of org.onlab.util.ItemNotFoundException in project onos by opennetworkinglab.

the class FlowsWebResource method getFlowByDeviceIdAndFlowId.

/**
 * Gets flow rules. Returns the flow entry specified by the device id and
 * flow rule id.
 *
 * @param deviceId device identifier
 * @param flowId   flow rule identifier
 * @return 200 OK with a collection of flows of given device and flow
 * @onos.rsModel FlowEntries
 */
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("{deviceId}/{flowId}")
public Response getFlowByDeviceIdAndFlowId(@PathParam("deviceId") String deviceId, @PathParam("flowId") long flowId) {
    FlowRuleService service = get(FlowRuleService.class);
    ObjectNode root = mapper().createObjectNode();
    ArrayNode flowsNode = root.putArray(FLOWS);
    Iterable<FlowEntry> flowEntries = service.getFlowEntries(DeviceId.deviceId(deviceId));
    if (flowEntries == null || !flowEntries.iterator().hasNext()) {
        throw new ItemNotFoundException(DEVICE_NOT_FOUND);
    }
    for (FlowEntry entry : flowEntries) {
        if (entry.id().value() == flowId) {
            flowsNode.add(codec(FlowEntry.class).encode(entry, this));
        }
    }
    return ok(root).build();
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) FlowRuleService(org.onosproject.net.flow.FlowRuleService) FlowEntry(org.onosproject.net.flow.FlowEntry) ItemNotFoundException(org.onlab.util.ItemNotFoundException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 24 with ItemNotFoundException

use of org.onlab.util.ItemNotFoundException in project onos by opennetworkinglab.

the class MetricsWebResource method getMetricByName.

/**
 * Gets stats information of a metric. Returns array of all information for the
 * specified metric.
 *
 * @param metricName metric name
 * @return 200 OK with metric information as array
 * @onos.rsModel Metric
 */
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("{metricName}")
public Response getMetricByName(@PathParam("metricName") String metricName) {
    ObjectNode metricNode = root.putObject("metric");
    MetricFilter filter = metricName != null ? (name, metric) -> name.equals(metricName) : MetricFilter.ALL;
    TreeMultimap<String, Metric> matched = listMetrics(service, filter);
    if (matched.isEmpty()) {
        throw new ItemNotFoundException(E_METRIC_NAME_NOT_FOUND);
    }
    matched.asMap().get(metricName).forEach(m -> {
        metricNode.set(metricName, codec(Metric.class).encode(m, this));
    });
    return ok(root).build();
}
Also used : MetricFilter(com.codahale.metrics.MetricFilter) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Metric(com.codahale.metrics.Metric) ItemNotFoundException(org.onlab.util.ItemNotFoundException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 25 with ItemNotFoundException

use of org.onlab.util.ItemNotFoundException in project TFG by mattinelorza.

the class NdpReplyComponent method setUpDevice.

/**
 * Performs setup of the given device by creating a flow rule to generate
 * NDP NA packets for IPv6 addresses associated to the device interfaces.
 *
 * @param deviceId device ID
 */
private void setUpDevice(DeviceId deviceId) {
    // Get this device config from netcfg.json.
    final FabricDeviceConfig config = configService.getConfig(deviceId, FabricDeviceConfig.class);
    if (config == null) {
        // Config not available yet
        throw new ItemNotFoundException("Missing fabricDeviceConfig for " + deviceId);
    }
    // Get this device myStation mac.
    final MacAddress deviceMac = config.myStationMac();
    // Get all interfaces currently configured for the device
    final Collection<Interface> interfaces = interfaceService.getInterfaces().stream().filter(iface -> iface.connectPoint().deviceId().equals(deviceId)).collect(Collectors.toSet());
    if (interfaces.isEmpty()) {
        log.info("{} does not have any IPv6 interface configured", deviceId);
        return;
    }
    // Generate and install flow rules.
    log.info("Adding rules to {} to generate NDP NA for {} IPv6 interfaces...", deviceId, interfaces.size());
    final Collection<FlowRule> flowRules = interfaces.stream().map(this::getIp6Addresses).flatMap(Collection::stream).map(ipv6addr -> buildNdpReplyFlowRule(deviceId, ipv6addr, deviceMac)).collect(Collectors.toSet());
    installRules(flowRules);
}
Also used : NetworkConfigService(org.onosproject.net.config.NetworkConfigService) Interface(org.onosproject.net.intf.Interface) PiActionParamId(org.onosproject.net.pi.model.PiActionParamId) DeviceService(org.onosproject.net.device.DeviceService) LoggerFactory(org.slf4j.LoggerFactory) PiActionParam(org.onosproject.net.pi.runtime.PiActionParam) InterfaceService(org.onosproject.net.intf.InterfaceService) Component(org.osgi.service.component.annotations.Component) FlowRuleService(org.onosproject.net.flow.FlowRuleService) PiCriterion(org.onosproject.net.flow.criteria.PiCriterion) ApplicationId(org.onosproject.core.ApplicationId) Activate(org.osgi.service.component.annotations.Activate) MastershipService(org.onosproject.mastership.MastershipService) Utils(org.onosproject.ngsdn.tutorial.common.Utils) IpAddress(org.onlab.packet.IpAddress) FlowRuleOperations(org.onosproject.net.flow.FlowRuleOperations) Ip6Address(org.onlab.packet.Ip6Address) DeviceListener(org.onosproject.net.device.DeviceListener) Logger(org.slf4j.Logger) FabricDeviceConfig(org.onosproject.ngsdn.tutorial.common.FabricDeviceConfig) Deactivate(org.osgi.service.component.annotations.Deactivate) Collection(java.util.Collection) ItemNotFoundException(org.onlab.util.ItemNotFoundException) PiMatchFieldId(org.onosproject.net.pi.model.PiMatchFieldId) InterfaceIpAddress(org.onosproject.net.host.InterfaceIpAddress) Collectors(java.util.stream.Collectors) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) PiAction(org.onosproject.net.pi.runtime.PiAction) INITIAL_SETUP_DELAY(org.onosproject.ngsdn.tutorial.AppConstants.INITIAL_SETUP_DELAY) FlowRule(org.onosproject.net.flow.FlowRule) DeviceEvent(org.onosproject.net.device.DeviceEvent) MacAddress(org.onlab.packet.MacAddress) DeviceId(org.onosproject.net.DeviceId) Reference(org.osgi.service.component.annotations.Reference) PiActionId(org.onosproject.net.pi.model.PiActionId) FabricDeviceConfig(org.onosproject.ngsdn.tutorial.common.FabricDeviceConfig) Collection(java.util.Collection) FlowRule(org.onosproject.net.flow.FlowRule) MacAddress(org.onlab.packet.MacAddress) Interface(org.onosproject.net.intf.Interface) ItemNotFoundException(org.onlab.util.ItemNotFoundException)

Aggregations

ItemNotFoundException (org.onlab.util.ItemNotFoundException)25 DriverHandler (org.onosproject.net.driver.DriverHandler)9 Path (javax.ws.rs.Path)8 GET (javax.ws.rs.GET)7 Produces (javax.ws.rs.Produces)7 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)6 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)5 FlowRuleService (org.onosproject.net.flow.FlowRuleService)5 ApplicationId (org.onosproject.core.ApplicationId)4 Driver (org.onosproject.net.driver.Driver)4 List (java.util.List)3 Consumes (javax.ws.rs.Consumes)3 DeviceId (org.onosproject.net.DeviceId)3 FlowEntry (org.onosproject.net.flow.FlowEntry)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 ArrayList (java.util.ArrayList)2 POST (javax.ws.rs.POST)2 PathParam (javax.ws.rs.PathParam)2 MediaType (javax.ws.rs.core.MediaType)2 Response (javax.ws.rs.core.Response)2