org.onlab.util.ItemNotFoundException Java Examples

The following examples show how to use org.onlab.util.ItemNotFoundException. 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: FlowsWebResource.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Gets flow entries of a device. Returns array of all flow rules for the
 * specified device.
 *
 * @param deviceId device identifier
 * @return 200 OK with a collection of flows of given device
 * @onos.rsModel FlowEntries
 */
@GET
@Produces(MediaType.APPLICATION_JSON)
// TODO: we need to add "/device" suffix to the path to differentiate with appId
@Path("{deviceId}")
public Response getFlowByDeviceId(@PathParam("deviceId") String deviceId) {
    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) {
        flowsNode.add(codec(FlowEntry.class).encode(entry, this));
    }
    return ok(root).build();
}
 
Example #2
Source File: MappingsWebResource.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Gets mapping entries of a device. Returns array of all mappings for the
 * specified device.
 *
 * @param deviceId device identifier
 * @param type     mapping store type
 * @return 200 OK with a collection of mappings of given device
 *
 * @onos.rsModel MappingEntries
 */
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("{deviceId}/{type}")
public Response getMappingsByDeviceId(@PathParam("deviceId") String deviceId,
                                      @PathParam("type") String type) {
    Device device = deviceService.getDevice(DeviceId.deviceId(deviceId));

    if (device == null) {
        throw new ItemNotFoundException(DEVICE_NOT_FOUND);
    }

    final Iterable<MappingEntry> mappingEntries =
            mappingService.getMappingEntries(getTypeEnum(type), device.id());
    if (mappingEntries == null || !mappingEntries.iterator().hasNext()) {
        return ok(root).build();
    }

    for (final MappingEntry entry : mappingEntries) {
        mappingsNode.add(codec(MappingEntry.class).encode(entry, this));
    }
    return ok(root).build();
}
 
Example #3
Source File: AlarmManagerTest.java    From onos with Apache License 2.0 6 votes vote down vote up
@Test
public void testGettersWhenNoAlarms() {

    assertTrue("No alarms should be present", manager.getAlarms().isEmpty());
    assertTrue("No active alarms should be present", manager.getActiveAlarms().isEmpty());
    assertTrue("The map should be empty per unknown device",
               manager.getAlarmCounts(DeviceId.NONE).keySet().isEmpty());
    assertTrue("The counts should be empty", manager.getAlarmCounts().keySet().isEmpty());

    assertEquals("Incorrect number of alarms for unknown device",
                 0, manager.getAlarms(DeviceId.NONE).size());
    assertEquals("Incorrect number of major alarms for unknown device",
                 0, manager.getAlarms(Alarm.SeverityLevel.MAJOR).size());

    exception.expect(NullPointerException.class);
    manager.getAlarm(null);

    exception.expect(ItemNotFoundException.class);
    manager.getAlarm(AlarmId.alarmId(DEVICE_ID, "unique_3"));
}
 
Example #4
Source File: AlarmManager.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
public Alarm updateBookkeepingFields(AlarmId id, boolean clear, boolean isAcknowledged,
                                     String assignedUser) {
    checkNotNull(id, "Alarm id is null");
    Alarm found = store.getAlarm(id);
    if (found == null) {
        throw new ItemNotFoundException("Alarm with id " + id + " found");
    }
    long now = System.currentTimeMillis();
    DefaultAlarm.Builder alarmBuilder = new DefaultAlarm.Builder(found).withTimeUpdated(now);
    if (found.cleared() != clear) {
        alarmBuilder.clear().withTimeCleared(now);
    }
    if (found.acknowledged() != isAcknowledged) {
        alarmBuilder.withAcknowledged(isAcknowledged);
    }
    if (assignedUser != null && !found.assignedUser().equals(assignedUser)) {
        alarmBuilder.withAssignedUser(assignedUser);
    }
    DefaultAlarm updated = alarmBuilder.build();
    store.createOrUpdateAlarm(updated);
    return updated;
}
 
Example #5
Source File: ResourceDeviceListener.java    From onos with Apache License 2.0 6 votes vote down vote up
private Set<OchSignal> queryLambdas(DeviceId did, PortNumber port) {
    try {
        DriverHandler handler = driverService.createHandler(did);
        if (handler == null || !handler.hasBehaviour(LambdaQuery.class)) {
            return Collections.emptySet();
        }
        LambdaQuery query = handler.behaviour(LambdaQuery.class);
        if (query != null) {
            return query.queryLambdas(port).stream()
                    .flatMap(ResourceDeviceListener::toResourceGrid)
                    .collect(ImmutableSet.toImmutableSet());
        } else {
            return Collections.emptySet();
        }
    } catch (ItemNotFoundException e) {
        return Collections.emptySet();
    }
}
 
Example #6
Source File: ResourceDeviceListener.java    From onos with Apache License 2.0 6 votes vote down vote up
private Set<VlanId> queryVlanIds(DeviceId device, PortNumber port) {
    try {
        DriverHandler handler = driverService.createHandler(device);
        if (handler == null || !handler.hasBehaviour(VlanQuery.class)) {
            return ImmutableSet.of();
        }

        VlanQuery query = handler.behaviour(VlanQuery.class);
        if (query == null) {
            return ImmutableSet.of();
        }
        return query.queryVlanIds(port);
    } catch (ItemNotFoundException e) {
        return ImmutableSet.of();
    }
}
 
Example #7
Source File: ResourceDeviceListener.java    From onos with Apache License 2.0 6 votes vote down vote up
private Set<MplsLabel> queryMplsLabels(DeviceId device, PortNumber port) {
    try {
        DriverHandler handler = driverService.createHandler(device);
        if (handler == null || !handler.hasBehaviour(MplsQuery.class)) {
            return ImmutableSet.of();
        }

        MplsQuery query = handler.behaviour(MplsQuery.class);
        if (query == null) {
            return ImmutableSet.of();
        }
        return query.queryMplsLabels(port);
    } catch (ItemNotFoundException e) {
        return ImmutableSet.of();
    }
}
 
Example #8
Source File: NetconfSessionMinaImpl.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Get the list of the netconf client capabilities from device driver property.
 *
 * @param deviceId the deviceID for which to recover the capabilities from the driver.
 * @return the String list of clientCapability property, or null if it is not configured
 */
public Set<String> getClientCapabilites(DeviceId deviceId) {
    Set<String> capabilities = new LinkedHashSet<>();
    DriverService driverService = directory.get(DriverService.class);
    try {
        Driver driver = driverService.getDriver(deviceId);
        if (driver == null) {
            return capabilities;
        }
        String clientCapabilities = driver.getProperty(NETCONF_CLIENT_CAPABILITY);
        if (clientCapabilities == null) {
            return capabilities;
        }
        String[] textStr = clientCapabilities.split("\\|");
        capabilities.addAll(Arrays.asList(textStr));
        return capabilities;
    } catch (ItemNotFoundException e) {
        log.warn("Driver for device {} currently not available", deviceId);
        return capabilities;
    }
}
 
Example #9
Source File: FlowsWebResource.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Removes flow rule. Removes the specified flow rule.
 *
 * @param deviceId device identifier
 * @param flowId   flow rule identifier
 * @return 204 NO CONTENT
 */
@DELETE
@Path("{deviceId}/{flowId}")
public Response deleteFlowByDeviceIdAndFlowId(@PathParam("deviceId") String deviceId,
                                              @PathParam("flowId") long flowId) {
    FlowRuleService service = get(FlowRuleService.class);
    Iterable<FlowEntry> flowEntries =
            service.getFlowEntries(DeviceId.deviceId(deviceId));

    if (!flowEntries.iterator().hasNext()) {
        throw new ItemNotFoundException(DEVICE_NOT_FOUND);
    }

    StreamSupport.stream(flowEntries.spliterator(), false)
            .filter(entry -> entry.id().value() == flowId)
            .forEach(service::removeFlowRules);
    return Response.noContent().build();
}
 
Example #10
Source File: FlowsWebResource.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * 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();
}
 
Example #11
Source File: MetricsWebResource.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * 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();
}
 
Example #12
Source File: ResourceDeviceListener.java    From onos with Apache License 2.0 6 votes vote down vote up
private Set<TributarySlot> queryTributarySlots(DeviceId device, PortNumber port) {
    try {
        DriverHandler handler = driverService.createHandler(device);
        if (handler == null || !handler.hasBehaviour(TributarySlotQuery.class)) {
            return Collections.emptySet();
        }
        TributarySlotQuery query = handler.behaviour(TributarySlotQuery.class);
        if (query != null) {
            return query.queryTributarySlots(port);
        } else {
            return Collections.emptySet();
        }
    } catch (ItemNotFoundException e) {
        return Collections.emptySet();
    }
}
 
Example #13
Source File: DriverManager.java    From onos with Apache License 2.0 6 votes vote down vote up
private Driver getPipeconfMergedDriver(DeviceId deviceId) {
    PiPipeconfId pipeconfId = pipeconfService.ofDevice(deviceId).orElse(null);
    if (pipeconfId == null) {
        log.warn("Missing pipeconf for {}, cannot produce a pipeconf merged driver",
                  deviceId);
        return null;
    }
    String mergedDriverName = pipeconfService.getMergedDriver(deviceId, pipeconfId);
    if (mergedDriverName == null) {
        log.warn("Unable to get pipeconf merged driver for {} and {}",
                 deviceId, pipeconfId);
        return null;
    }
    try {
        return getDriver(mergedDriverName);
    } catch (ItemNotFoundException e) {
        log.warn("Specified pipeconf merged driver {} for {} not found",
                 mergedDriverName, deviceId);
        return null;
    }
}
 
Example #14
Source File: PacketManager.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Pushes a packet request flow rule to all devices.
 *
 * @param request the packet request
 */
private void pushToAllDevices(PacketRequest request) {
    log.debug("Pushing packet request {} to all devices", request);
    for (Device device : deviceService.getDevices()) {
        try {
            Driver driver = driverService.getDriver(device.id());
            if (driver != null &&
                    Boolean.parseBoolean(driver.getProperty(SUPPORT_PACKET_REQUEST_PROPERTY))) {
                pushRule(device, request);
            }
        } catch (ItemNotFoundException e) {
            log.warn("Device driver not found for {}; not processing packet request {}",
                     device.id(), request);
        }
    }
}
 
Example #15
Source File: DomainIntentManager.java    From onos with Apache License 2.0 6 votes vote down vote up
private DomainIntentConfigurable initDomainIntentDriver(DeviceId deviceId) {

        // Attempt to lookup the handler in the cache
        DriverHandler handler = driverHandlers.get(deviceId);
        if (handler == null) {
            try {
                // Otherwise create it and if it has DomainIntentConfig behaviour, cache it
                handler = driverService.createHandler(deviceId);

                if (!handler.driver().hasBehaviour(DomainIntentConfigurable.class)) {
                    log.warn("DomainIntentConfig behaviour not supported for device {}",
                            deviceId);
                    return null;
                }
            } catch (ItemNotFoundException e) {
                log.warn("No applicable driver for device {}", deviceId);
                return null;
            }
            driverHandlers.put(deviceId, handler);
        }
        // Always (re)initialize the pipeline behaviour
        log.info("Driver {} bound to device {} ... initializing driver",
                handler.driver().name(), deviceId);

        return handler.behaviour(DomainIntentConfigurable.class);
    }
 
Example #16
Source File: ExtensionCriterionSerializer.java    From onos with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example #17
Source File: ExtensionInstructionSerializer.java    From onos with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example #18
Source File: FlowObjectiveCompositionManager.java    From onos with Apache License 2.0 5 votes vote down vote up
private void setupPipelineHandler(DeviceId deviceId) {
    // Attempt to lookup the handler in the cache
    DriverHandler handler = driverHandlers.get(deviceId);
    if (handler == null) {
        try {
            // Otherwise create it and if it has pipeline behaviour, cache it
            handler = driverService.createHandler(deviceId);
            if (!handler.driver().hasBehaviour(Pipeliner.class)) {
                log.warn("Pipeline behaviour not supported for device {}",
                        deviceId);
                return;
            }
        } catch (ItemNotFoundException e) {
            log.warn("No applicable driver for device {}", deviceId);
            return;
        }

        driverHandlers.put(deviceId, handler);
    }

    // Always (re)initialize the pipeline behaviour
    log.info("Driver {} bound to device {} ... initializing driver",
            handler.driver().name(), deviceId);
    Pipeliner pipeliner = handler.behaviour(Pipeliner.class);
    pipeliner.init(deviceId, context);
    pipeliners.putIfAbsent(deviceId, pipeliner);
}
 
Example #19
Source File: NdpReplyComponent.java    From ngsdn-tutorial with Apache License 2.0 5 votes vote down vote up
/**
 * 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);
}
 
Example #20
Source File: FlowObjectiveManager.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Creates and initialize {@link Pipeliner}.
 * <p>
 * Note: Expected to be called under per-Device lock.
 *      e.g., {@code pipeliners}' Map#compute family methods
 *
 * @param deviceId Device to initialize pipeliner
 * @return {@link Pipeliner} instance or null
 */
private Pipeliner initPipelineHandler(DeviceId deviceId) {
    start = now();

    // Attempt to lookup the handler in the cache
    DriverHandler handler = driverHandlers.get(deviceId);
    cTime = now();

    if (handler == null) {
        try {
            // Otherwise create it and if it has pipeline behaviour, cache it
            handler = driverService.createHandler(deviceId);
            dTime = now();
            if (!handler.driver().hasBehaviour(Pipeliner.class)) {
                log.debug("Pipeline behaviour not supported for device {}",
                         deviceId);
                return null;
            }
        } catch (ItemNotFoundException e) {
            log.warn("No applicable driver for device {}", deviceId);
            return null;
        }

        driverHandlers.put(deviceId, handler);
        eTime = now();
    }

    // Always (re)initialize the pipeline behaviour
    log.info("Driver {} bound to device {} ... initializing driver",
             handler.driver().name(), deviceId);
    hTime = now();
    Pipeliner pipeliner = handler.behaviour(Pipeliner.class);
    hbTime = now();
    pipeliner.init(deviceId, context);
    stopWatch();
    return pipeliner;
}
 
Example #21
Source File: DriverManager.java    From onos with Apache License 2.0 5 votes vote down vote up
private Driver lookupDriver(String driverName) {
    if (driverName != null) {
        try {
            return getDriver(driverName);
        } catch (ItemNotFoundException e) {
            log.warn("Specified driver {} not found, falling back.", driverName);
        }
    }
    return null;
}
 
Example #22
Source File: PiPipeconfManager.java    From onos with Apache License 2.0 5 votes vote down vote up
private Driver getDriver(String name) {
    try {
        return driverAdminService.getDriver(name);
    } catch (ItemNotFoundException e) {
        return null;
    }
}
 
Example #23
Source File: PiPipeconfManagerTest.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public Driver getDriver(String driverName) {
    if (driverName.equals(BASE_DRIVER)) {
        return baseDriver;
    }
    throw new ItemNotFoundException("Driver not found");
}
 
Example #24
Source File: AbstractProjectableModel.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Locates the driver to be used by this entity.
 * <p>
 * The default implementation derives the driver based on the {@code driver}
 * annotation value.
 *
 * @return driver for alternate projections of this model entity or null
 * if no driver is expected or driver is not found
 */
protected Driver locateDriver() {
    Annotations annotations = annotations();
    String driverName = annotations != null ? annotations.value(AnnotationKeys.DRIVER) : null;
    if (driverName != null) {
        try {
            return driverService.getDriver(driverName);
        } catch (ItemNotFoundException e) {
            log.warn("Driver {} not found.", driverName);
        }
    }
    return null;
}
 
Example #25
Source File: DefaultDevice.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
protected Driver locateDriver() {
    try {
        return driverService().getDriver(id());
    } catch (ItemNotFoundException e) {
        return null;
    }
}
 
Example #26
Source File: TenantWebResource.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Get the matching tenant identifier from existing tenant identifiers in system.
 *
 * @param vnetAdminSvc virtual network administration service
 * @param tidIn        tenant identifier
 * @return TenantId
 */
protected static TenantId getExistingTenantId(VirtualNetworkAdminService vnetAdminSvc,
                                            TenantId tidIn) {
    return vnetAdminSvc
            .getTenantIds()
            .stream()
            .filter(tenantId -> tenantId.equals(tidIn))
            .findFirst()
            .orElseThrow(() -> new ItemNotFoundException(TENANTID_NOT_FOUND));
}
 
Example #27
Source File: Ipv6RoutingComponent.java    From onos-p4-tutorial with Apache License 2.0 5 votes vote down vote up
/**
 * Gets Srv6 SID for the given device.
 *
 * @param deviceId the device ID
 * @return SID for the device
 */
private Ip6Address getDeviceSid(DeviceId deviceId) {
    return getDeviceConfig(deviceId)
            .map(Srv6DeviceConfig::mySid)
            .orElseThrow(() -> new ItemNotFoundException(
                    "Missing mySid config for " + deviceId));
}
 
Example #28
Source File: NdpReplyComponent.java    From ngsdn-tutorial with Apache License 2.0 5 votes vote down vote up
/**
 * 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);
}
 
Example #29
Source File: NdpReplyComponent.java    From onos-p4-tutorial with Apache License 2.0 5 votes vote down vote up
private void setUpDevice(DeviceId deviceId) {
    Srv6DeviceConfig config = configService.getConfig(deviceId, Srv6DeviceConfig.class);
    if (config == null) {
        // Config not available yet
        throw new ItemNotFoundException("Missing Srv6Config for " + deviceId);
    }

    final MacAddress deviceMac = config.myStationMac();

    // Get all interface 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;
    }

    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(iaddr -> buildNdpReplyFlowRule(deviceId, deviceMac, iaddr))
            .collect(Collectors.toSet());

    installRules(flowRules);
}
 
Example #30
Source File: Ipv6RoutingComponent.java    From onos-p4-tutorial with Apache License 2.0 5 votes vote down vote up
/**
 * Gets Srv6 SID for the given device.
 *
 * @param deviceId the device ID
 * @return SID for the device
 */
private Ip6Address getDeviceSid(DeviceId deviceId) {
    return getDeviceConfig(deviceId)
            .map(Srv6DeviceConfig::mySid)
            .orElseThrow(() -> new ItemNotFoundException(
                    "Missing mySid config for " + deviceId));
}