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 LabelAllocatorTest method testRandomBehaviorNone.
/**
* To test random behavior. Using NONE optimization
*/
@Test
public void testRandomBehaviorNone() {
// By default Random is the selection behavior used
assertThat(this.allocator.getLabelSelection(), instanceOf(RandomSelection.class));
// It has to be an instance of NONE
assertEquals(this.allocator.getOptLabelSelection(), LabelAllocator.OptimizationBehavior.NONE);
// Filter reservations
this.resourceService.filterAssignment = true;
// We change the available Ids
this.resourceService.availableMplsLabels = ImmutableSet.of(1, 2, 3, 4, 5, 6);
// First allocation on a subset of links
Map<LinkKey, Identifier<?>> allocation = this.allocator.assignLabelToLinks(ImmutableSet.copyOf(links.subList(2, 3)), IntentId.valueOf(idGenerator.getNewId()), EncapsulationType.MPLS);
Identifier<?> id = allocation.get(LinkKey.linkKey(d3p0, d2p1));
// value has to be a MPLS label
assertThat(id, instanceOf(MplsLabel.class));
// value should not be a forbidden value
MplsLabel mplsLabel = (MplsLabel) id;
assertTrue(0 < mplsLabel.toInt() && mplsLabel.toInt() < MplsLabel.MAX_MPLS);
// We test the behavior for MPLS
allocation = this.allocator.assignLabelToLinks(ImmutableSet.copyOf(links.subList(1, 3)), IntentId.valueOf(idGenerator.getNewId()), EncapsulationType.MPLS);
id = allocation.get(LinkKey.linkKey(d1p1, d3p1));
assertThat(id, instanceOf(MplsLabel.class));
mplsLabel = (MplsLabel) id;
assertTrue(0 < mplsLabel.toInt() && mplsLabel.toInt() < MplsLabel.MAX_MPLS);
id = allocation.get(LinkKey.linkKey(d3p0, d2p1));
assertThat(id, instanceOf(MplsLabel.class));
mplsLabel = (MplsLabel) id;
assertTrue(0 < mplsLabel.toInt() && mplsLabel.toInt() < MplsLabel.MAX_MPLS);
}
use of org.onosproject.net.LinkKey in project onos by opennetworkinglab.
the class LabelAllocatorTest method testRandomBehaviorMinSwap.
/**
* To test the random behavior. Using MIN_SWAP optimization
*/
@Test
public void testRandomBehaviorMinSwap() {
// By default Random is the selection behavior used
assertThat(this.allocator.getLabelSelection(), instanceOf(RandomSelection.class));
// Change to MIN_SWAP
this.allocator.setOptLabelSelection(minswap);
assertEquals(this.allocator.getOptLabelSelection(), LabelAllocator.OptimizationBehavior.MIN_SWAP);
// Filter reservations
this.resourceService.filterAssignment = true;
// We change the available Ids
this.resourceService.availableMplsLabels = ImmutableSet.of(1, 2, 3, 4, 5, 6, 7, 8);
// First allocation on a subset of links
Map<LinkKey, Identifier<?>> allocation = this.allocator.assignLabelToLinks(ImmutableSet.copyOf(links2.subList(2, 3)), IntentId.valueOf(idGenerator.getNewId()), EncapsulationType.MPLS);
Identifier<?> id = allocation.get(LinkKey.linkKey(d3p0, d4p1));
// value has to be a MPLS label
assertThat(id, instanceOf(MplsLabel.class));
// value should not be a forbidden value
MplsLabel mplsLabel = (MplsLabel) id;
assertTrue(0 < mplsLabel.toInt() && mplsLabel.toInt() < MplsLabel.MAX_MPLS);
// We test the behavior for MPLS
allocation = this.allocator.assignLabelToLinks(ImmutableSet.copyOf(links2.subList(1, 4)), IntentId.valueOf(idGenerator.getNewId()), EncapsulationType.MPLS);
id = allocation.get(LinkKey.linkKey(d1p1, d3p1));
assertThat(id, instanceOf(MplsLabel.class));
mplsLabel = (MplsLabel) id;
assertTrue(0 < mplsLabel.toInt() && mplsLabel.toInt() < MplsLabel.MAX_MPLS);
id = allocation.get(LinkKey.linkKey(d3p0, d4p1));
assertThat(id, instanceOf(MplsLabel.class));
mplsLabel = (MplsLabel) id;
assertTrue(0 < mplsLabel.toInt() && mplsLabel.toInt() < MplsLabel.MAX_MPLS);
id = allocation.get(LinkKey.linkKey(d4p0, d2p1));
assertThat(id, instanceOf(MplsLabel.class));
mplsLabel = (MplsLabel) id;
assertTrue(0 < mplsLabel.toInt() && mplsLabel.toInt() < MplsLabel.MAX_MPLS);
}
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 ECLinkStore method removeLink.
@Override
public LinkEvent removeLink(ConnectPoint src, ConnectPoint dst) {
final LinkKey linkKey = LinkKey.linkKey(src, dst);
ProviderId primaryProviderId = getBaseProviderId(linkKey);
// Stop if there is no base provider.
if (primaryProviderId == null) {
return null;
}
LinkDescription removedLinkDescription = linkDescriptions.remove(new Provided<>(linkKey, primaryProviderId));
if (removedLinkDescription != null) {
return purgeLinkCache(linkKey);
}
return null;
}
Aggregations