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