Search in sources :

Example 1 with FabricDeviceConfig

use of org.onosproject.ngsdn.tutorial.common.FabricDeviceConfig in project TFG by mattinelorza.

the class Srv6SidCompleter method complete.

@Override
public int complete(Session session, CommandLine commandLine, List<String> candidates) {
    DeviceService deviceService = AbstractShellCommand.get(DeviceService.class);
    NetworkConfigService netCfgService = AbstractShellCommand.get(NetworkConfigService.class);
    // Delegate string completer
    StringsCompleter delegate = new StringsCompleter();
    SortedSet<String> strings = delegate.getStrings();
    stream(deviceService.getDevices()).map(d -> netCfgService.getConfig(d.id(), FabricDeviceConfig.class)).filter(Objects::nonNull).map(FabricDeviceConfig::mySid).filter(Objects::nonNull).forEach(sid -> strings.add(sid.toString()));
    // Now let the completer do the work for figuring out what to offer.
    return delegate.complete(session, commandLine, candidates);
}
Also used : NetworkConfigService(org.onosproject.net.config.NetworkConfigService) StringsCompleter(org.apache.karaf.shell.support.completers.StringsCompleter) DeviceService(org.onosproject.net.device.DeviceService) FabricDeviceConfig(org.onosproject.ngsdn.tutorial.common.FabricDeviceConfig)

Example 2 with FabricDeviceConfig

use of org.onosproject.ngsdn.tutorial.common.FabricDeviceConfig 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

NetworkConfigService (org.onosproject.net.config.NetworkConfigService)2 DeviceService (org.onosproject.net.device.DeviceService)2 FabricDeviceConfig (org.onosproject.ngsdn.tutorial.common.FabricDeviceConfig)2 Collection (java.util.Collection)1 Collectors (java.util.stream.Collectors)1 StringsCompleter (org.apache.karaf.shell.support.completers.StringsCompleter)1 Ip6Address (org.onlab.packet.Ip6Address)1 IpAddress (org.onlab.packet.IpAddress)1 MacAddress (org.onlab.packet.MacAddress)1 ItemNotFoundException (org.onlab.util.ItemNotFoundException)1 ApplicationId (org.onosproject.core.ApplicationId)1 MastershipService (org.onosproject.mastership.MastershipService)1 DeviceId (org.onosproject.net.DeviceId)1 DeviceEvent (org.onosproject.net.device.DeviceEvent)1 DeviceListener (org.onosproject.net.device.DeviceListener)1 FlowRule (org.onosproject.net.flow.FlowRule)1 FlowRuleOperations (org.onosproject.net.flow.FlowRuleOperations)1 FlowRuleService (org.onosproject.net.flow.FlowRuleService)1 PiCriterion (org.onosproject.net.flow.criteria.PiCriterion)1 InterfaceIpAddress (org.onosproject.net.host.InterfaceIpAddress)1