use of org.onosproject.net.intent.HostToHostIntent in project onos by opennetworkinglab.
the class IntentJsonMatcher method matchConnectivityIntent.
/**
* Matches the JSON representation of a connectivity intent. Calls the
* matcher for the connectivity intent subtype.
*
* @param jsonIntent JSON representation of the intent
* @param description Description object used for recording errors
* @return true if the JSON matches the intent, false otherwise
*/
private boolean matchConnectivityIntent(JsonNode jsonIntent, Description description) {
final ConnectivityIntent connectivityIntent = (ConnectivityIntent) intent;
// check selector
final JsonNode jsonSelector = jsonIntent.get("selector");
final TrafficSelector selector = connectivityIntent.selector();
final Set<Criterion> criteria = selector.criteria();
final JsonNode jsonCriteria = jsonSelector.get("criteria");
if (jsonCriteria.size() != criteria.size()) {
description.appendText("size of criteria array is " + Integer.toString(jsonCriteria.size()));
return false;
}
for (Criterion criterion : criteria) {
boolean criterionFound = false;
for (int criterionIndex = 0; criterionIndex < jsonCriteria.size(); criterionIndex++) {
final CriterionJsonMatcher criterionMatcher = CriterionJsonMatcher.matchesCriterion(criterion);
if (criterionMatcher.matches(jsonCriteria.get(criterionIndex))) {
criterionFound = true;
break;
}
}
if (!criterionFound) {
description.appendText("criterion not found " + criterion.toString());
return false;
}
}
// check treatment
final JsonNode jsonTreatment = jsonIntent.get("treatment");
final TrafficTreatment treatment = connectivityIntent.treatment();
final List<Instruction> instructions = treatment.immediate();
final JsonNode jsonInstructions = jsonTreatment.get("instructions");
if (jsonInstructions.size() != instructions.size()) {
description.appendText("size of instructions array is " + Integer.toString(jsonInstructions.size()));
return false;
}
for (Instruction instruction : instructions) {
boolean instructionFound = false;
for (int instructionIndex = 0; instructionIndex < jsonInstructions.size(); instructionIndex++) {
final InstructionJsonMatcher instructionMatcher = InstructionJsonMatcher.matchesInstruction(instruction);
if (instructionMatcher.matches(jsonInstructions.get(instructionIndex))) {
instructionFound = true;
break;
}
}
if (!instructionFound) {
description.appendText("instruction not found " + instruction.toString());
return false;
}
}
// Check constraints
final JsonNode jsonConstraints = jsonIntent.get("constraints");
if (connectivityIntent.constraints() != null) {
if (connectivityIntent.constraints().size() != jsonConstraints.size()) {
description.appendText("constraints array size was " + Integer.toString(jsonConstraints.size()));
return false;
}
for (final Constraint constraint : connectivityIntent.constraints()) {
boolean constraintFound = false;
for (int constraintIndex = 0; constraintIndex < jsonConstraints.size(); constraintIndex++) {
final JsonNode value = jsonConstraints.get(constraintIndex);
if (matchConstraint(constraint, value)) {
constraintFound = true;
}
}
if (!constraintFound) {
final String constraintString = constraint.toString();
description.appendText("constraint missing " + constraintString);
return false;
}
}
} else if (jsonConstraints.size() != 0) {
description.appendText("constraint array not empty");
return false;
}
if (connectivityIntent instanceof HostToHostIntent) {
return matchHostToHostIntent(jsonIntent, description);
} else if (connectivityIntent instanceof PointToPointIntent) {
return matchPointToPointIntent(jsonIntent, description);
} else {
description.appendText("class of connectivity intent is unknown");
return false;
}
}
use of org.onosproject.net.intent.HostToHostIntent in project onos by opennetworkinglab.
the class IntentJsonMatcher method matchHostToHostIntent.
/**
* Matches the JSON representation of a host to host intent.
*
* @param jsonIntent JSON representation of the intent
* @param description Description object used for recording errors
* @return true if the JSON matches the intent, false otherwise
*/
private boolean matchHostToHostIntent(JsonNode jsonIntent, Description description) {
final HostToHostIntent hostToHostIntent = (HostToHostIntent) intent;
// check host one
final String host1 = hostToHostIntent.one().toString();
final String jsonHost1 = jsonIntent.get("one").asText();
if (!host1.equals(jsonHost1)) {
description.appendText("host one was " + jsonHost1);
return false;
}
// check host 2
final String host2 = hostToHostIntent.two().toString();
final String jsonHost2 = jsonIntent.get("two").asText();
if (!host2.equals(jsonHost2)) {
description.appendText("host two was " + jsonHost2);
return false;
}
return true;
}
use of org.onosproject.net.intent.HostToHostIntent in project onos by opennetworkinglab.
the class HostToHostIntentCompiler method createLinkCollectionIntent.
private Intent createLinkCollectionIntent(Path path, Host src, Host dst, HostToHostIntent intent) {
// Try to allocate bandwidth
List<ConnectPoint> pathCPs = path.links().stream().flatMap(l -> Stream.of(l.src(), l.dst())).collect(Collectors.toList());
allocateBandwidth(intent, pathCPs);
Link ingressLink = path.links().get(0);
Link egressLink = path.links().get(path.links().size() - 1);
FilteredConnectPoint ingressPoint = getFilteredPointFromLink(ingressLink);
FilteredConnectPoint egressPoint = getFilteredPointFromLink(egressLink);
TrafficSelector selector = builder(intent.selector()).matchEthSrc(src.mac()).matchEthDst(dst.mac()).build();
/*
* The path contains also the edge links, these are not necessary
* for the LinkCollectionIntent.
*/
Set<Link> coreLinks = path.links().stream().filter(link -> !link.type().equals(EDGE)).collect(Collectors.toSet());
return LinkCollectionIntent.builder().key(intent.key()).appId(intent.appId()).selector(selector).treatment(intent.treatment()).links(coreLinks).filteredIngressPoints(ImmutableSet.of(ingressPoint)).filteredEgressPoints(ImmutableSet.of(egressPoint)).applyTreatmentOnEgress(true).constraints(intent.constraints()).priority(intent.priority()).resourceGroup(intent.resourceGroup()).build();
}
use of org.onosproject.net.intent.HostToHostIntent in project onos by opennetworkinglab.
the class HostToHostIntentCompilerTest method testSingleLongPathCompilation.
/**
* Tests a pair of hosts with 8 hops between them.
*/
@Test
public void testSingleLongPathCompilation() {
HostToHostIntent intent = makeIntent(HOST_ONE, HOST_TWO);
assertThat(intent, is(notNullValue()));
String[] hops = { HOST_ONE, S1, S2, S3, S4, S5, S6, S7, S8, HOST_TWO };
HostToHostIntentCompiler compiler = makeCompiler(hops);
assertThat(compiler, is(notNullValue()));
List<Intent> result = compiler.compile(intent, null);
assertThat(result, is(Matchers.notNullValue()));
assertThat(result, hasSize(2));
Intent forwardIntent = result.get(0);
assertThat(forwardIntent instanceof LinkCollectionIntent, is(true));
Intent reverseIntent = result.get(1);
assertThat(reverseIntent instanceof LinkCollectionIntent, is(true));
LinkCollectionIntent forwardLCIntent = (LinkCollectionIntent) forwardIntent;
Set<Link> links = forwardLCIntent.links();
assertThat(links, hasSize(7));
Set<FilteredConnectPoint> ingressPoints = ImmutableSet.of(new FilteredConnectPoint(new ConnectPoint(DID_S1, PORT_1)));
assertThat(forwardLCIntent.filteredIngressPoints(), is(ingressPoints));
assertThat(links, linksHasPath(S1, S2));
assertThat(links, linksHasPath(S2, S3));
assertThat(links, linksHasPath(S3, S4));
assertThat(links, linksHasPath(S4, S5));
assertThat(links, linksHasPath(S5, S6));
assertThat(links, linksHasPath(S6, S7));
assertThat(links, linksHasPath(S7, S8));
Set<FilteredConnectPoint> egressPoints = ImmutableSet.of(new FilteredConnectPoint(new ConnectPoint(DID_S8, PORT_2)));
assertThat(forwardLCIntent.filteredEgressPoints(), is(egressPoints));
LinkCollectionIntent reverseLCIntent = (LinkCollectionIntent) reverseIntent;
links = reverseLCIntent.links();
assertThat(reverseLCIntent.links(), hasSize(7));
ingressPoints = ImmutableSet.of(new FilteredConnectPoint(new ConnectPoint(DID_S8, PORT_2)));
assertThat(reverseLCIntent.filteredIngressPoints(), is(ingressPoints));
assertThat(links, linksHasPath(S2, S1));
assertThat(links, linksHasPath(S3, S2));
assertThat(links, linksHasPath(S4, S3));
assertThat(links, linksHasPath(S5, S4));
assertThat(links, linksHasPath(S6, S5));
assertThat(links, linksHasPath(S7, S6));
assertThat(links, linksHasPath(S8, S7));
egressPoints = ImmutableSet.of(new FilteredConnectPoint(new ConnectPoint(DID_S1, PORT_1)));
assertThat(reverseLCIntent.filteredEgressPoints(), is(egressPoints));
assertThat("key is inherited", result.stream().map(Intent::key).collect(Collectors.toList()), everyItem(is(intent.key())));
}
use of org.onosproject.net.intent.HostToHostIntent in project onos by opennetworkinglab.
the class HostToHostIntentCompilerTest method testBandwidthConstrainedIntentAllocation.
/**
* Tests if bandwidth resources get allocated correctly.
*/
@Test
public void testBandwidthConstrainedIntentAllocation() {
final double bpsTotal = 1000.0;
final double bpsToReserve = 100.0;
ContinuousResource resourceSw1P1 = Resources.continuous(DID_S1, PORT_1, Bandwidth.class).resource(bpsToReserve);
ContinuousResource resourceSw1P2 = Resources.continuous(DID_S1, PORT_2, Bandwidth.class).resource(bpsToReserve);
ContinuousResource resourceSw2P1 = Resources.continuous(DID_S2, PORT_1, Bandwidth.class).resource(bpsToReserve);
ContinuousResource resourceSw2P2 = Resources.continuous(DID_S2, PORT_2, Bandwidth.class).resource(bpsToReserve);
ContinuousResource resourceSw3P1 = Resources.continuous(DID_S3, PORT_1, Bandwidth.class).resource(bpsToReserve);
ContinuousResource resourceSw3P2 = Resources.continuous(DID_S3, PORT_2, Bandwidth.class).resource(bpsToReserve);
String[] hops = { HOST_ONE, S1, S2, S3, HOST_TWO };
final ResourceService resourceService = MockResourceService.makeCustomBandwidthResourceService(bpsTotal);
final List<Constraint> constraints = Collections.singletonList(new BandwidthConstraint(Bandwidth.bps(bpsToReserve)));
final HostToHostIntent intent = makeIntent(HOST_ONE, HOST_TWO, constraints);
HostToHostIntentCompiler compiler = makeCompiler(hops, resourceService);
compiler.compile(intent, null);
Key intentKey = intent.key();
ResourceAllocation rAOne = new ResourceAllocation(resourceSw1P1, intentKey);
ResourceAllocation rATwo = new ResourceAllocation(resourceSw1P2, intentKey);
ResourceAllocation rAThree = new ResourceAllocation(resourceSw2P1, intentKey);
ResourceAllocation rAFour = new ResourceAllocation(resourceSw2P2, intentKey);
ResourceAllocation rAFive = new ResourceAllocation(resourceSw3P1, intentKey);
ResourceAllocation rASix = new ResourceAllocation(resourceSw3P2, intentKey);
Set<ResourceAllocation> expectedresourceAllocations = ImmutableSet.of(rAOne, rATwo, rAThree, rAFour, rAFive, rASix);
Set<ResourceAllocation> resourceAllocations = ImmutableSet.copyOf(resourceService.getResourceAllocations(intentKey));
assertThat(resourceAllocations, hasSize(6));
assertEquals(expectedresourceAllocations, resourceAllocations);
}
Aggregations