Search in sources :

Example 16 with Device

use of org.onosproject.net.Device in project TFG by mattinelorza.

the class Ipv6RoutingComponent method setUpSpineRoutes.

/**
 * Insert routing rules on the given spine switch, matching on leaf
 * interface subnets and forwarding packets to the corresponding leaf.
 *
 * @param spineId the spine device ID
 */
private void setUpSpineRoutes(DeviceId spineId) {
    log.info("Adding up spine routes on {}...", spineId);
    for (Device device : deviceService.getDevices()) {
        if (isSpine(device.id())) {
            // We only need routes to leaf switches. Ignore spines.
            continue;
        }
        final DeviceId leafId = device.id();
        final MacAddress leafMac = getMyStationMac(leafId);
        final Set<Ip6Prefix> subnetsToRoute = getInterfaceIpv6Prefixes(leafId);
        // Since we're here, we also add a route for SRv6 (Exercise 7), to
        // forward packets with IPv6 dst the SID of a leaf switch.
        final Ip6Address leafSid = getDeviceSid(leafId);
        subnetsToRoute.add(Ip6Prefix.valueOf(leafSid, 128));
        // Create a group with only one member.
        int groupId = macToGroupId(leafMac);
        GroupDescription group = createNextHopGroup(groupId, Collections.singleton(leafMac), spineId);
        List<FlowRule> flowRules = subnetsToRoute.stream().map(subnet -> createRoutingRule(spineId, subnet, groupId)).collect(Collectors.toList());
        insertInOrder(group, flowRules);
    }
}
Also used : Ip6Prefix(org.onlab.packet.Ip6Prefix) GroupDescription(org.onosproject.net.group.GroupDescription) NetworkConfigService(org.onosproject.net.config.NetworkConfigService) Interface(org.onosproject.net.intf.Interface) PiActionParamId(org.onosproject.net.pi.model.PiActionParamId) PortNumber(org.onosproject.net.PortNumber) DeviceService(org.onosproject.net.device.DeviceService) LoggerFactory(org.slf4j.LoggerFactory) PiActionParam(org.onosproject.net.pi.runtime.PiActionParam) Link(org.onosproject.net.Link) FlowRuleService(org.onosproject.net.flow.FlowRuleService) PiCriterion(org.onosproject.net.flow.criteria.PiCriterion) ApplicationId(org.onosproject.core.ApplicationId) MastershipService(org.onosproject.mastership.MastershipService) PiTableAction(org.onosproject.net.pi.runtime.PiTableAction) Ip6Address(org.onlab.packet.Ip6Address) Device(org.onosproject.net.Device) Deactivate(org.osgi.service.component.annotations.Deactivate) FabricDeviceConfig(org.onosproject.ngsdn.tutorial.common.FabricDeviceConfig) Collection(java.util.Collection) Set(java.util.Set) ItemNotFoundException(org.onlab.util.ItemNotFoundException) InterfaceIpAddress(org.onosproject.net.host.InterfaceIpAddress) Collectors(java.util.stream.Collectors) LinkListener(org.onosproject.net.link.LinkListener) List(java.util.List) INITIAL_SETUP_DELAY(org.onosproject.ngsdn.tutorial.AppConstants.INITIAL_SETUP_DELAY) FlowRule(org.onosproject.net.flow.FlowRule) DeviceEvent(org.onosproject.net.device.DeviceEvent) LinkService(org.onosproject.net.link.LinkService) Optional(java.util.Optional) DeviceId(org.onosproject.net.DeviceId) GroupDescription(org.onosproject.net.group.GroupDescription) PiActionProfileGroupId(org.onosproject.net.pi.runtime.PiActionProfileGroupId) IpPrefix(org.onlab.packet.IpPrefix) Host(org.onosproject.net.Host) LinkEvent(org.onosproject.net.link.LinkEvent) HostListener(org.onosproject.net.host.HostListener) InterfaceService(org.onosproject.net.intf.InterfaceService) HostService(org.onosproject.net.host.HostService) Component(org.osgi.service.component.annotations.Component) Lists(com.google.common.collect.Lists) HostEvent(org.onosproject.net.host.HostEvent) Activate(org.osgi.service.component.annotations.Activate) Utils(org.onosproject.ngsdn.tutorial.common.Utils) IpAddress(org.onlab.packet.IpAddress) DeviceListener(org.onosproject.net.device.DeviceListener) Logger(org.slf4j.Logger) GroupService(org.onosproject.net.group.GroupService) PiMatchFieldId(org.onosproject.net.pi.model.PiMatchFieldId) Ip6Prefix(org.onlab.packet.Ip6Prefix) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) Streams.stream(com.google.common.collect.Streams.stream) PiAction(org.onosproject.net.pi.runtime.PiAction) MacAddress(org.onlab.packet.MacAddress) Reference(org.osgi.service.component.annotations.Reference) Collections(java.util.Collections) PiActionId(org.onosproject.net.pi.model.PiActionId) Ip6Address(org.onlab.packet.Ip6Address) Device(org.onosproject.net.Device) DeviceId(org.onosproject.net.DeviceId) FlowRule(org.onosproject.net.flow.FlowRule) MacAddress(org.onlab.packet.MacAddress)

Example 17 with Device

use of org.onosproject.net.Device in project TFG by mattinelorza.

the class Ipv6RoutingComponent method setUpLeafRoutes.

/**
 * Insert routing rules on the given leaf switch, matching on interface
 * subnets associated to other leaves and forwarding packets the spines
 * using ECMP.
 *
 * @param leafId the leaf device ID
 */
private void setUpLeafRoutes(DeviceId leafId) {
    log.info("Setting up leaf routes: {}", leafId);
    // Get the set of subnets (interface IPv6 prefixes) associated to other
    // leafs but not this one.
    Set<Ip6Prefix> subnetsToRouteViaSpines = stream(deviceService.getDevices()).map(Device::id).filter(this::isLeaf).filter(deviceId -> !deviceId.equals(leafId)).map(this::getInterfaceIpv6Prefixes).flatMap(Collection::stream).collect(Collectors.toSet());
    // Get myStationMac address of all spines.
    Set<MacAddress> spineMacs = stream(deviceService.getDevices()).map(Device::id).filter(this::isSpine).map(this::getMyStationMac).collect(Collectors.toSet());
    // Create an ECMP group to distribute traffic across all spines.
    final int groupId = DEFAULT_ECMP_GROUP_ID;
    final GroupDescription ecmpGroup = createNextHopGroup(groupId, spineMacs, leafId);
    // Generate a flow rule for each subnet pointing to the ECMP group.
    List<FlowRule> flowRules = subnetsToRouteViaSpines.stream().map(subnet -> createRoutingRule(leafId, subnet, groupId)).collect(Collectors.toList());
    insertInOrder(ecmpGroup, flowRules);
    // Since we're here, we also add a route for SRv6 (Exercise 7), to
    // forward packets with IPv6 dst the SID of a spine switch, in this case
    // using a single-member group.
    stream(deviceService.getDevices()).map(Device::id).filter(this::isSpine).forEach(spineId -> {
        MacAddress spineMac = getMyStationMac(spineId);
        Ip6Address spineSid = getDeviceSid(spineId);
        int spineGroupId = macToGroupId(spineMac);
        GroupDescription group = createNextHopGroup(spineGroupId, Collections.singleton(spineMac), leafId);
        FlowRule routingRule = createRoutingRule(leafId, Ip6Prefix.valueOf(spineSid, 128), spineGroupId);
        insertInOrder(group, Collections.singleton(routingRule));
    });
}
Also used : Ip6Prefix(org.onlab.packet.Ip6Prefix) NetworkConfigService(org.onosproject.net.config.NetworkConfigService) Interface(org.onosproject.net.intf.Interface) PiActionParamId(org.onosproject.net.pi.model.PiActionParamId) PortNumber(org.onosproject.net.PortNumber) DeviceService(org.onosproject.net.device.DeviceService) LoggerFactory(org.slf4j.LoggerFactory) PiActionParam(org.onosproject.net.pi.runtime.PiActionParam) Link(org.onosproject.net.Link) FlowRuleService(org.onosproject.net.flow.FlowRuleService) PiCriterion(org.onosproject.net.flow.criteria.PiCriterion) ApplicationId(org.onosproject.core.ApplicationId) MastershipService(org.onosproject.mastership.MastershipService) PiTableAction(org.onosproject.net.pi.runtime.PiTableAction) Ip6Address(org.onlab.packet.Ip6Address) Device(org.onosproject.net.Device) Deactivate(org.osgi.service.component.annotations.Deactivate) FabricDeviceConfig(org.onosproject.ngsdn.tutorial.common.FabricDeviceConfig) Collection(java.util.Collection) Set(java.util.Set) ItemNotFoundException(org.onlab.util.ItemNotFoundException) InterfaceIpAddress(org.onosproject.net.host.InterfaceIpAddress) Collectors(java.util.stream.Collectors) LinkListener(org.onosproject.net.link.LinkListener) List(java.util.List) INITIAL_SETUP_DELAY(org.onosproject.ngsdn.tutorial.AppConstants.INITIAL_SETUP_DELAY) FlowRule(org.onosproject.net.flow.FlowRule) DeviceEvent(org.onosproject.net.device.DeviceEvent) LinkService(org.onosproject.net.link.LinkService) Optional(java.util.Optional) DeviceId(org.onosproject.net.DeviceId) GroupDescription(org.onosproject.net.group.GroupDescription) PiActionProfileGroupId(org.onosproject.net.pi.runtime.PiActionProfileGroupId) IpPrefix(org.onlab.packet.IpPrefix) Host(org.onosproject.net.Host) LinkEvent(org.onosproject.net.link.LinkEvent) HostListener(org.onosproject.net.host.HostListener) InterfaceService(org.onosproject.net.intf.InterfaceService) HostService(org.onosproject.net.host.HostService) Component(org.osgi.service.component.annotations.Component) Lists(com.google.common.collect.Lists) HostEvent(org.onosproject.net.host.HostEvent) Activate(org.osgi.service.component.annotations.Activate) Utils(org.onosproject.ngsdn.tutorial.common.Utils) IpAddress(org.onlab.packet.IpAddress) DeviceListener(org.onosproject.net.device.DeviceListener) Logger(org.slf4j.Logger) GroupService(org.onosproject.net.group.GroupService) PiMatchFieldId(org.onosproject.net.pi.model.PiMatchFieldId) Ip6Prefix(org.onlab.packet.Ip6Prefix) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) Streams.stream(com.google.common.collect.Streams.stream) PiAction(org.onosproject.net.pi.runtime.PiAction) MacAddress(org.onlab.packet.MacAddress) Reference(org.osgi.service.component.annotations.Reference) Collections(java.util.Collections) PiActionId(org.onosproject.net.pi.model.PiActionId) GroupDescription(org.onosproject.net.group.GroupDescription) Ip6Address(org.onlab.packet.Ip6Address) Device(org.onosproject.net.Device) FlowRule(org.onosproject.net.flow.FlowRule) MacAddress(org.onlab.packet.MacAddress)

Example 18 with Device

use of org.onosproject.net.Device in project onos by opennetworkinglab.

the class VirtualNetworkTopologyManager method currentTopology.

@Override
public Topology currentTopology() {
    Iterable<Device> devices = manager.getVirtualDevices(networkId()).stream().collect(Collectors.toSet());
    Iterable<Link> links = manager.getVirtualLinks(networkId()).stream().collect(Collectors.toSet());
    DefaultGraphDescription graph = new DefaultGraphDescription(System.nanoTime(), System.currentTimeMillis(), devices, links);
    return new DefaultTopology(PID, graph);
}
Also used : DefaultTopology(org.onosproject.common.DefaultTopology) Device(org.onosproject.net.Device) DefaultGraphDescription(org.onosproject.net.topology.DefaultGraphDescription) Link(org.onosproject.net.Link)

Example 19 with Device

use of org.onosproject.net.Device in project onos by opennetworkinglab.

the class VirtualFlowsListCommand method doExecute.

@Override
protected void doExecute() {
    CoreService coreService = get(CoreService.class);
    VirtualNetworkService vnetservice = get(VirtualNetworkService.class);
    DeviceService deviceService = vnetservice.get(NetworkId.networkId(networkId), DeviceService.class);
    FlowRuleService service = vnetservice.get(NetworkId.networkId(networkId), FlowRuleService.class);
    contentFilter = new StringFilter(filter, StringFilter.Strategy.AND);
    compilePredicate();
    SortedMap<Device, List<FlowEntry>> flows = getSortedFlows(deviceService, service);
    if (outputJson()) {
        print("%s", json(flows.keySet(), flows));
    } else {
        flows.forEach((device, flow) -> printFlows(device, flow, coreService));
    }
}
Also used : VirtualNetworkService(org.onosproject.incubator.net.virtual.VirtualNetworkService) Device(org.onosproject.net.Device) DeviceService(org.onosproject.net.device.DeviceService) CoreService(org.onosproject.core.CoreService) StringFilter(org.onlab.util.StringFilter) ArrayList(java.util.ArrayList) List(java.util.List) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) FlowRuleService(org.onosproject.net.flow.FlowRuleService)

Example 20 with Device

use of org.onosproject.net.Device in project onos by opennetworkinglab.

the class VirtualFlowsListCommand method json.

/**
 * Produces a JSON array of flows grouped by the each device.
 *
 * @param devices     collection of devices to group flow by
 * @param flows       collection of flows per each device
 * @return JSON array
 */
private JsonNode json(Iterable<Device> devices, Map<Device, List<FlowEntry>> flows) {
    ObjectMapper mapper = new ObjectMapper();
    ArrayNode result = mapper.createArrayNode();
    for (Device device : devices) {
        result.add(json(mapper, device, flows.get(device)));
    }
    return result;
}
Also used : Device(org.onosproject.net.Device) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

Device (org.onosproject.net.Device)350 DeviceService (org.onosproject.net.device.DeviceService)112 DeviceId (org.onosproject.net.DeviceId)108 Port (org.onosproject.net.Port)64 ConnectPoint (org.onosproject.net.ConnectPoint)63 List (java.util.List)54 PortNumber (org.onosproject.net.PortNumber)52 DefaultDevice (org.onosproject.net.DefaultDevice)50 Test (org.junit.Test)43 Set (java.util.Set)41 Link (org.onosproject.net.Link)41 Logger (org.slf4j.Logger)41 DeviceEvent (org.onosproject.net.device.DeviceEvent)40 TrafficSelector (org.onosproject.net.flow.TrafficSelector)35 ArrayList (java.util.ArrayList)34 Optional (java.util.Optional)33 Collectors (java.util.stream.Collectors)33 Map (java.util.Map)32 IpAddress (org.onlab.packet.IpAddress)32 ApplicationId (org.onosproject.core.ApplicationId)31