use of org.onosproject.net.intent.Key in project onos by opennetworkinglab.
the class IntentsDiagnosisCommand method checkP2PFlowRuleIntent.
private void checkP2PFlowRuleIntent(PointToPointIntent intent, FlowRuleIntent installable, ServiceRefs svcRefs) {
final Map<DeviceId, DeviceOnIntent> devs = createDevicesOnP2PIntent(intent, installable);
boolean errorOccurred = false;
// checking the number of links & CPs in P2P intent
for (DeviceOnIntent dev : devs.values()) {
if (dev.getIngressLinks().size() > 1) {
error("MULTIPLE NUMBER OF INGRESS LINKs on " + dev.deviceId() + ": " + dev.getIngressLinks());
errorOccurred = true;
}
if (dev.getIngressCps().size() > 1) {
error("MULTIPLE NUMBER OF INGRESS CONNECT POINTs on " + dev.deviceId() + ": " + dev.getIngressCps());
errorOccurred = true;
}
if (dev.getEgressLinks().size() > 1) {
error("MULTIPLE NUMBER OF EGRESS LINKs: on " + dev.deviceId() + ": " + dev.getEgressLinks());
errorOccurred = true;
}
if (dev.getEgressCps().size() > 1) {
error("MULTIPLE NUMBER OF EGRESS CONNECT POINTs: on " + dev.deviceId() + ": " + dev.getEgressCps());
errorOccurred = true;
}
}
ConnectPoint startCp = intent.filteredIngressPoint().connectPoint();
DeviceOnIntent startDev = devs.get(startCp.deviceId());
if (startDev == null) {
error("STARTING CONNECT POINT DEVICE: " + startCp.deviceId() + " is not on intent");
errorOccurred = true;
}
ConnectPoint endCp = intent.filteredEgressPoint().connectPoint();
DeviceOnIntent endDev = devs.get(endCp.deviceId());
if (endDev == null) {
error("END CONNECT POINT DEVICE: " + endCp.deviceId() + " is not on intent");
errorOccurred = true;
}
if (!errorOccurred) {
// Per device checking with path-order
DeviceOnIntent dev = startDev;
int i = 0;
for (; i < MAX_INTENT_PATH; i++) {
perDeviceChecking(dev, svcRefs);
// P2P intent has only 1 egress CP
ConnectPoint egressCp = dev.getEgressCps().stream().findFirst().orElse(null);
if (egressCp != null && Objects.equals(endCp, egressCp)) {
break;
}
// P2P intent has only 1 egress link
Link egressLink = dev.getEgressLinks().stream().findFirst().orElse(null);
if (egressLink == null) {
error("INVALID EGRESS LINK & CONNECT POINT for: " + dev);
errorOccurred = true;
break;
}
if (Objects.equals(egressLink.dst(), endCp)) {
break;
}
// P2P intent only 1 ingress link
dev = devs.values().stream().filter(nextDev -> Objects.equals(egressLink, nextDev.getIngressLinks().stream().findFirst().orElse(null))).findAny().orElse(null);
if (dev == null) {
error("FAILED TO FIND NEXT DEV for: " + dev + ", LINK: " + egressLink);
errorOccurred = true;
break;
}
}
if (i == MAX_INTENT_PATH) {
error("MAX INTENT PATH WAS EXCEEDED");
errorOccurred = true;
}
}
if (errorOccurred) {
// Installable checking
dump("");
dump("ERROR OCCURRED. DO PER FLOW CHECKING");
perFlowRuleChecking(installable, svcRefs);
}
if (svcRefs.workPartitionService.isMine(intent.key(), Key::hash)) {
checkIntentsByLink(installable, svcRefs);
}
}
use of org.onosproject.net.intent.Key in project onos by opennetworkinglab.
the class IntentCleanup method event.
@Override
public void event(IntentEvent event) {
// TODO we might consider using the timer to back off for subsequent retries
if (enabled && event.type() == IntentEvent.Type.CORRUPT) {
Key key = event.subject().key();
if (store.isMaster(key)) {
IntentData data = store.getIntentData(event.subject().key());
resubmitCorrupt(data, true);
}
}
}
use of org.onosproject.net.intent.Key in project onos by opennetworkinglab.
the class ObjectiveTracker method trackIntent.
@Override
public void trackIntent(IntentData intentData) {
// NOTE: This will be called for intents that are being added to the store
// locally (i.e. every intent update)
Key key = intentData.key();
Intent intent = intentData.intent();
boolean isLocal = intentService.isLocal(key);
boolean isInstalled = intentData.state() == INSTALLING || intentData.state() == INSTALLED;
List<Intent> installables = intentData.installables();
if (log.isTraceEnabled()) {
log.trace("intent {}, old: {}, new: {}, installableCount: {}, resourceCount: {}", key, intentsByDevice.values().contains(key), isLocal && isInstalled, installables.size(), intent.resources().size() + installables.stream().mapToLong(i -> i.resources().size()).sum());
}
if (isNullOrEmpty(installables) && intentData.state() == INSTALLED) {
log.warn("Intent {} is INSTALLED with no installables", key);
}
// then when installing and when installed)
if (isLocal && isInstalled) {
addTrackedResources(key, intent.resources());
for (Intent installable : installables) {
addTrackedResources(key, installable.resources());
}
// FIXME check all resources against current topo service(s); recompile if necessary
} else {
removeTrackedResources(key, intent.resources());
for (Intent installable : installables) {
removeTrackedResources(key, installable.resources());
}
}
}
use of org.onosproject.net.intent.Key in project onos by opennetworkinglab.
the class PointToPointIntentCompilerTest method testKeyRGBandwidthConstrainedIntentAllocation.
/**
* Tests if bandwidth resources get allocated correctly using groups.
* An intent asks to allocate bandwidth using the intent key as a reference.
* Then, the intent is submitted with the same key and a group set.
* Previous allocations should be released and new resources should be
* allocated using the group.
*/
@Test
public void testKeyRGBandwidthConstrainedIntentAllocation() {
final double bpsTotal = 1000.0;
String[] hops = { S1, S2, S3 };
final ResourceService resourceService = MockResourceService.makeCustomBandwidthResourceService(bpsTotal);
final List<Constraint> constraints = Collections.singletonList(new BandwidthConstraint(Bandwidth.bps(BPS_TO_RESERVE)));
final PointToPointIntent intent = makeIntent(new ConnectPoint(DID_1, PORT_1), new ConnectPoint(DID_3, PORT_2), constraints);
PointToPointIntentCompiler compiler = makeCompiler(hops, resourceService);
compiler.compile(intent, null);
Key intentKey = intent.key();
ResourceGroup resourceGroup = ResourceGroup.of(100);
final PointToPointIntent newIntent = makeIntent(intentKey, new ConnectPoint(DID_1, PORT_1), new ConnectPoint(DID_3, PORT_2), constraints, resourceGroup);
compiler.compile(newIntent, null);
ResourceAllocation rAOne = new ResourceAllocation(RESOURCE_SW1_P1, resourceGroup);
ResourceAllocation rATwo = new ResourceAllocation(RESOURCE_SW1_P2, resourceGroup);
ResourceAllocation rAThree = new ResourceAllocation(RESOURCE_SW2_P1, resourceGroup);
ResourceAllocation rAFour = new ResourceAllocation(RESOURCE_SW2_P2, resourceGroup);
ResourceAllocation rAFive = new ResourceAllocation(RESOURCE_SW3_P1, resourceGroup);
ResourceAllocation rASix = new ResourceAllocation(RESOURCE_SW3_P2, resourceGroup);
Set<ResourceAllocation> expectedresourceAllocations = ImmutableSet.of(rAOne, rATwo, rAThree, rAFour, rAFive, rASix);
Set<ResourceAllocation> resourceAllocations = ImmutableSet.copyOf(resourceService.getResourceAllocations(resourceGroup));
assertThat(resourceAllocations, hasSize(6));
assertEquals(expectedresourceAllocations, resourceAllocations);
}
use of org.onosproject.net.intent.Key in project onos by opennetworkinglab.
the class VirtualNetworkIntentManagerTest method testCreateAndRemoveIntent.
/**
* Tests the submit(), withdraw(), and purge() methods.
*/
@Test
public void testCreateAndRemoveIntent() {
VirtualNetwork virtualNetwork = setupVirtualNetworkTopology();
Key intentKey = Key.of("test", APP_ID);
List<Constraint> constraints = new ArrayList<>();
constraints.add(new EncapsulationConstraint(EncapsulationType.VLAN));
VirtualNetworkIntent virtualIntent = VirtualNetworkIntent.builder().networkId(virtualNetwork.id()).key(intentKey).appId(APP_ID).ingressPoint(cp1).egressPoint(cp5).constraints(constraints).build();
// Test the submit() method.
vnetIntentService.submit(virtualIntent);
// Wait for the both intents to go into an INSTALLED state.
try {
if (!created.tryAcquire(MAX_PERMITS, MAX_WAIT_TIME, TimeUnit.SECONDS)) {
fail("Failed to wait for intent to get installed.");
}
} catch (InterruptedException e) {
fail("Semaphore exception during intent installation." + e.getMessage());
}
// Test the getIntentState() method
assertEquals("The intent state did not match as expected.", IntentState.INSTALLED, vnetIntentService.getIntentState(virtualIntent.key()));
// Test the withdraw() method.
vnetIntentService.withdraw(virtualIntent);
// Wait for the both intents to go into a WITHDRAWN state.
try {
if (!withdrawn.tryAcquire(MAX_PERMITS, MAX_WAIT_TIME, TimeUnit.SECONDS)) {
fail("Failed to wait for intent to get withdrawn.");
}
} catch (InterruptedException e) {
fail("Semaphore exception during intent withdrawal." + e.getMessage());
}
// Test the getIntentState() method
assertEquals("The intent state did not match as expected.", IntentState.WITHDRAWN, vnetIntentService.getIntentState(virtualIntent.key()));
// Test the purge() method.
vnetIntentService.purge(virtualIntent);
// Wait for the both intents to be removed/purged.
try {
if (!purged.tryAcquire(MAX_PERMITS, MAX_WAIT_TIME, TimeUnit.SECONDS)) {
fail("Failed to wait for intent to get purged.");
}
} catch (InterruptedException e) {
fail("Semaphore exception during intent purging." + e.getMessage());
}
}
Aggregations