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);
}
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);
}
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();
}
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();
}
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);
}
Aggregations