Search in sources :

Example 1 with LinkKey

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

the class OpticalOduIntentCompiler method compile.

@Override
public List<Intent> compile(OpticalOduIntent intent, List<Intent> installable) {
    // Check if ports are OduClt ports
    ConnectPoint src = intent.getSrc();
    ConnectPoint dst = intent.getDst();
    Port srcPort = deviceService.getPort(src.deviceId(), src.port());
    Port dstPort = deviceService.getPort(dst.deviceId(), dst.port());
    checkArgument(srcPort instanceof OduCltPort);
    checkArgument(dstPort instanceof OduCltPort);
    log.debug("Compiling optical ODU intent between {} and {}", src, dst);
    // Release of intent resources here is only a temporary solution for handling the
    // case of recompiling due to intent restoration (when intent state is FAILED).
    // TODO: try to release intent resources in IntentManager.
    resourceService.release(intent.key());
    // Check OduClt ports availability
    Resource srcPortResource = Resources.discrete(src.deviceId(), src.port()).resource();
    Resource dstPortResource = Resources.discrete(dst.deviceId(), dst.port()).resource();
    // If ports are not available, compilation fails
    if (!Stream.of(srcPortResource, dstPortResource).allMatch(resourceService::isAvailable)) {
        throw new OpticalIntentCompilationException("Ports for the intent are not available. Intent: " + intent);
    }
    List<Resource> intentResources = new ArrayList<>();
    intentResources.add(srcPortResource);
    intentResources.add(dstPortResource);
    // Calculate available light paths
    Set<Path> paths = getOpticalPaths(intent);
    if (paths.isEmpty()) {
        throw new OpticalIntentCompilationException("Unable to find suitable lightpath for intent " + intent);
    }
    // Use first path that can be successfully reserved
    for (Path path : paths) {
        // Find available Tributary Slots on both directions of path
        Map<LinkKey, Set<TributarySlot>> slotsMap = findAvailableTributarySlots(intent, path);
        if (slotsMap.isEmpty()) {
            continue;
        }
        List<Resource> tributarySlotResources = convertToResources(slotsMap);
        if (!tributarySlotResources.stream().allMatch(resourceService::isAvailable)) {
            continue;
        }
        intentResources.addAll(tributarySlotResources);
        allocateResources(intent, intentResources);
        List<FlowRule> rules = new LinkedList<>();
        // Create rules for forward and reverse path
        rules = createRules(intent, intent.getSrc(), intent.getDst(), path, slotsMap, false);
        if (intent.isBidirectional()) {
            rules.addAll(createRules(intent, intent.getDst(), intent.getSrc(), path, slotsMap, true));
        }
        return Collections.singletonList(new FlowRuleIntent(appId, intent.key(), rules, ImmutableSet.copyOf(path.links()), PathIntent.ProtectionType.PRIMARY, intent.resourceGroup()));
    }
    throw new OpticalIntentCompilationException("Unable to find suitable lightpath for intent " + intent);
}
Also used : Path(org.onosproject.net.Path) LinkKey(org.onosproject.net.LinkKey) ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) Port(org.onosproject.net.Port) OduCltPort(org.onosproject.net.optical.OduCltPort) OtuPort(org.onosproject.net.optical.OtuPort) OduCltPort(org.onosproject.net.optical.OduCltPort) Resource(org.onosproject.net.resource.Resource) ArrayList(java.util.ArrayList) ConnectPoint(org.onosproject.net.ConnectPoint) LinkedList(java.util.LinkedList) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) FlowRule(org.onosproject.net.flow.FlowRule) FlowRuleIntent(org.onosproject.net.intent.FlowRuleIntent)

Example 2 with LinkKey

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

the class OpticalOduIntentCompiler method findAvailableTributarySlots.

/**
 * Find available TributarySlots across path.
 *
 * @param intent
 * @param path path in OTU topology
 * @return Map of Linkey and Set of available TributarySlots on its ports
 */
private Map<LinkKey, Set<TributarySlot>> findAvailableTributarySlots(OpticalOduIntent intent, Path path) {
    Set<LinkKey> linkRequest = Sets.newHashSetWithExpectedSize(path.links().size());
    for (int i = 0; i < path.links().size(); i++) {
        LinkKey link = linkKey(path.links().get(i));
        linkRequest.add(link);
    }
    return findTributarySlots(intent, linkRequest);
}
Also used : LinkKey(org.onosproject.net.LinkKey) ConnectPoint(org.onosproject.net.ConnectPoint)

Example 3 with LinkKey

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

the class ConfigureLinkCommand method doExecute.

@Override
protected void doExecute() {
    DeviceService deviceService = get(DeviceService.class);
    NetworkConfigService netCfgService = get(NetworkConfigService.class);
    ConnectPoint srcCp = ConnectPoint.deviceConnectPoint(src);
    if (deviceService.getPort(srcCp) == null) {
        print("[ERROR] %s does not exist", srcCp);
        return;
    }
    ConnectPoint dstCp = ConnectPoint.deviceConnectPoint(dst);
    if (deviceService.getPort(dstCp) == null) {
        print("[ERROR] %s does not exist", dstCp);
        return;
    }
    LinkKey link = linkKey(srcCp, dstCp);
    if (remove) {
        netCfgService.removeConfig(link, BasicLinkConfig.class);
        return;
    }
    Long bw = Optional.ofNullable(bandwidth).map(Long::valueOf).orElse(null);
    Link.Type linkType = Link.Type.valueOf(type);
    BasicLinkConfig cfg = netCfgService.addConfig(link, BasicLinkConfig.class);
    cfg.isAllowed(!disallow);
    cfg.isBidirectional(!isUniDi);
    cfg.type(linkType);
    if (bw != null) {
        cfg.bandwidth(bw);
    }
    cfg.apply();
}
Also used : LinkKey(org.onosproject.net.LinkKey) NetworkConfigService(org.onosproject.net.config.NetworkConfigService) DeviceService(org.onosproject.net.device.DeviceService) ConnectPoint(org.onosproject.net.ConnectPoint) Link(org.onosproject.net.Link) BasicLinkConfig(org.onosproject.net.config.basics.BasicLinkConfig)

Example 4 with LinkKey

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

the class BiLinkMap method add.

/**
 * Adds the given link to our collection, returning the corresponding
 * bi-link (creating one if needed necessary).
 *
 * @param link the link to add to the collection
 * @return the corresponding bi-link wrapper
 */
public B add(Link link) {
    LinkKey key = TopoUtils.canonicalLinkKey(checkNotNull(link));
    B blink = map.get(key);
    if (blink == null) {
        // no bi-link yet exists for this link
        blink = create(key, link);
        map.put(key, blink);
    } else {
        // we have a bi-link for this link.
        if (!blink.one().equals(link)) {
            blink.setOther(link);
        }
    }
    return blink;
}
Also used : LinkKey(org.onosproject.net.LinkKey)

Example 5 with LinkKey

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

the class BasicLinkConfigTest method testConstruction.

/**
 * Tests construction, setters and getters of a BasicLinkConfig object.
 */
@Test
public void testConstruction() {
    BasicLinkConfig config = new BasicLinkConfig();
    ConfigApplyDelegate delegate = configApply -> {
    };
    ObjectMapper mapper = new ObjectMapper();
    LinkKey linkKey = LinkKey.linkKey(NetTestTools.connectPoint("device1", 1), NetTestTools.connectPoint("device2", 2));
    config.init(linkKey, "KEY", JsonNodeFactory.instance.objectNode(), mapper, delegate);
    config.bandwidth(BANDWIDTH).jitter(JITTER).delay(DELAY).loss(LOSS).availability(AVAILABILITY).flapping(FLAPPING).isDurable(FALSE).metric(METRIC).type(Link.Type.DIRECT).latency(LATENCY).isBidirectional(FALSE).isMetered(TRUE).tier(TIER).meteredUsage(METERED_USAGE);
    assertThat(config.bandwidth(), is(BANDWIDTH));
    assertThat(config.jitter(), is(JITTER));
    assertThat(config.delay(), is(DELAY));
    assertThat(config.loss(), is(LOSS));
    assertThat(config.availability(), is(AVAILABILITY));
    assertThat(config.flapping(), is(FLAPPING));
    assertThat(config.isDurable(), is(FALSE));
    assertThat(config.metric(), is(METRIC));
    assertThat(config.type(), is(Link.Type.DIRECT));
    assertThat(config.latency(), is(LATENCY));
    assertThat(config.isBidirectional(), is(FALSE));
    assertThat(config.isValid(), is(true));
    assertThat(config.isMetered(), is(TRUE));
    assertThat(config.tier(), is(TIER));
    assertThat(config.meteredUsage(), is(METERED_USAGE));
}
Also used : FALSE(java.lang.Boolean.FALSE) NetTestTools(org.onosproject.net.NetTestTools) JsonNodeFactory(com.fasterxml.jackson.databind.node.JsonNodeFactory) ConfigApplyDelegate(org.onosproject.net.config.ConfigApplyDelegate) Duration(java.time.Duration) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test) Matchers.is(org.hamcrest.Matchers.is) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Link(org.onosproject.net.Link) TRUE(java.lang.Boolean.TRUE) LinkKey(org.onosproject.net.LinkKey) LinkKey(org.onosproject.net.LinkKey) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ConfigApplyDelegate(org.onosproject.net.config.ConfigApplyDelegate) Test(org.junit.Test)

Aggregations

LinkKey (org.onosproject.net.LinkKey)61 Test (org.junit.Test)34 ConnectPoint (org.onosproject.net.ConnectPoint)31 Link (org.onosproject.net.Link)23 Identifier (org.onlab.util.Identifier)14 DeviceId (org.onosproject.net.DeviceId)9 Set (java.util.Set)7 MplsLabel (org.onlab.packet.MplsLabel)7 VlanId (org.onlab.packet.VlanId)7 LinkDescription (org.onosproject.net.link.LinkDescription)7 LinkEvent (org.onosproject.net.link.LinkEvent)7 DefaultLinkDescription (org.onosproject.net.link.DefaultLinkDescription)6 ProviderId (org.onosproject.net.provider.ProviderId)6 HashMap (java.util.HashMap)5 Map (java.util.Map)5 FirstFitSelection (org.onosproject.net.resource.impl.LabelAllocator.FirstFitSelection)5 RandomSelection (org.onosproject.net.resource.impl.LabelAllocator.RandomSelection)5 FilteredConnectPoint (org.onosproject.net.FilteredConnectPoint)4 NetworkConfigService (org.onosproject.net.config.NetworkConfigService)4 BasicLinkConfig (org.onosproject.net.config.basics.BasicLinkConfig)4