use of org.onosproject.net.intent.PointToPointIntent in project onos by opennetworkinglab.
the class ConnectivityManager method buildIntents.
/**
* Builds the required intents between the two pairs of connect points and
* IP addresses.
*
* @param portOne the first connect point
* @param ipOne the first IP address
* @param portTwo the second connect point
* @param ipTwo the second IP address
* @return the intents to install
*/
private Collection<PointToPointIntent> buildIntents(ConnectPoint portOne, IpAddress ipOne, ConnectPoint portTwo, IpAddress ipTwo) {
List<PointToPointIntent> intents = new ArrayList<>();
TrafficTreatment treatment = DefaultTrafficTreatment.emptyTreatment();
TrafficSelector selector;
Key key;
byte tcpProtocol;
byte icmpProtocol;
if (ipOne.isIp4()) {
tcpProtocol = IPv4.PROTOCOL_TCP;
icmpProtocol = IPv4.PROTOCOL_ICMP;
} else {
tcpProtocol = IPv6.PROTOCOL_TCP;
icmpProtocol = IPv6.PROTOCOL_ICMP6;
}
// Path from BGP speaker to BGP peer matching source TCP port 179
selector = buildSelector(tcpProtocol, ipOne, ipTwo, BGP_PORT, null);
key = buildKey(ipOne, ipTwo, SUFFIX_SRC);
intents.add(PointToPointIntent.builder().appId(appId).key(key).selector(selector).treatment(treatment).filteredIngressPoint(new FilteredConnectPoint(portOne)).filteredEgressPoint(new FilteredConnectPoint(portTwo)).priority(PRIORITY_OFFSET).build());
// Path from BGP peer to BGP speaker matching destination TCP port 179
selector = buildSelector(tcpProtocol, ipTwo, ipOne, null, BGP_PORT);
key = buildKey(ipTwo, ipOne, SUFFIX_DST);
intents.add(PointToPointIntent.builder().appId(appId).key(key).selector(selector).treatment(treatment).filteredIngressPoint(new FilteredConnectPoint(portTwo)).filteredEgressPoint(new FilteredConnectPoint(portOne)).priority(PRIORITY_OFFSET).build());
// ICMP path from BGP speaker to BGP peer
selector = buildSelector(icmpProtocol, ipOne, ipTwo, null, null);
key = buildKey(ipOne, ipTwo, SUFFIX_ICMP);
intents.add(PointToPointIntent.builder().appId(appId).key(key).selector(selector).treatment(treatment).filteredIngressPoint(new FilteredConnectPoint(portOne)).filteredEgressPoint(new FilteredConnectPoint(portTwo)).priority(PRIORITY_OFFSET).build());
// ICMP path from BGP peer to BGP speaker
selector = buildSelector(icmpProtocol, ipTwo, ipOne, null, null);
key = buildKey(ipTwo, ipOne, SUFFIX_ICMP);
intents.add(PointToPointIntent.builder().appId(appId).key(key).selector(selector).treatment(treatment).filteredIngressPoint(new FilteredConnectPoint(portTwo)).filteredEgressPoint(new FilteredConnectPoint(portOne)).priority(PRIORITY_OFFSET).build());
return intents;
}
use of org.onosproject.net.intent.PointToPointIntent in project onos by opennetworkinglab.
the class IntentCodecTest method intentWithTreatmentSelectorAndConstraints.
/**
* Tests the encoding of an intent with treatment, selector and constraints
* specified.
*/
@Test
public void intentWithTreatmentSelectorAndConstraints() {
ConnectPoint ingress = NetTestTools.connectPoint("ingress", 1);
ConnectPoint egress = NetTestTools.connectPoint("egress", 2);
DeviceId did1 = did("device1");
DeviceId did2 = did("device2");
DeviceId did3 = did("device3");
Lambda ochSignal = Lambda.ochSignal(GridType.DWDM, ChannelSpacing.CHL_100GHZ, 4, 8);
final TrafficSelector selector = DefaultTrafficSelector.builder().matchIPProtocol((byte) 3).matchMplsLabel(MplsLabel.mplsLabel(4)).add(Criteria.matchOchSignalType(OchSignalType.FIXED_GRID)).add(Criteria.matchLambda(ochSignal)).matchEthDst(MacAddress.BROADCAST).matchIPDst(IpPrefix.valueOf("1.2.3.4/24")).build();
final TrafficTreatment treatment = DefaultTrafficTreatment.builder().setMpls(MplsLabel.mplsLabel(44)).setOutput(PortNumber.CONTROLLER).setEthDst(MacAddress.BROADCAST).build();
final List<Constraint> constraints = ImmutableList.of(new BandwidthConstraint(Bandwidth.bps(1.0)), new AnnotationConstraint("key", 33.0), new AsymmetricPathConstraint(), new LatencyConstraint(Duration.ofSeconds(2)), new ObstacleConstraint(did1, did2), new WaypointConstraint(did3));
final PointToPointIntent intent = PointToPointIntent.builder().appId(appId).selector(selector).treatment(treatment).filteredIngressPoint(new FilteredConnectPoint(ingress)).filteredEgressPoint(new FilteredConnectPoint(egress)).constraints(constraints).build();
final JsonCodec<PointToPointIntent> intentCodec = context.codec(PointToPointIntent.class);
assertThat(intentCodec, notNullValue());
final ObjectNode intentJson = intentCodec.encode(intent, context);
assertThat(intentJson, matchesIntent(intent));
}
use of org.onosproject.net.intent.PointToPointIntent in project onos by opennetworkinglab.
the class IntentCodecTest method pointToPointIntent.
/**
* Tests the encoding of a point to point intent.
*/
@Test
public void pointToPointIntent() {
ConnectPoint ingress = NetTestTools.connectPoint("ingress", 1);
ConnectPoint egress = NetTestTools.connectPoint("egress", 2);
final PointToPointIntent intent = PointToPointIntent.builder().appId(appId).selector(emptySelector).treatment(emptyTreatment).filteredIngressPoint(new FilteredConnectPoint(ingress)).filteredEgressPoint(new FilteredConnectPoint(egress)).build();
final JsonCodec<PointToPointIntent> intentCodec = context.codec(PointToPointIntent.class);
assertThat(intentCodec, notNullValue());
final ObjectNode intentJson = intentCodec.encode(intent, context);
assertThat(intentJson, matchesIntent(intent));
}
use of org.onosproject.net.intent.PointToPointIntent in project onos by opennetworkinglab.
the class IntentJsonMatcher method matchPointToPointIntent.
/**
* Matches the JSON representation of a point to point 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 matchPointToPointIntent(JsonNode jsonIntent, Description description) {
final PointToPointIntent pointToPointIntent = (PointToPointIntent) intent;
// check ingress connection
final ConnectPoint ingress = pointToPointIntent.filteredIngressPoint().connectPoint();
final ConnectPointJsonMatcher ingressMatcher = ConnectPointJsonMatcher.matchesConnectPoint(ingress);
final JsonNode jsonIngress = jsonIntent.get("ingressPoint");
final boolean ingressMatches = ingressMatcher.matchesSafely(jsonIngress, description);
if (!ingressMatches) {
description.appendText("ingress was " + jsonIngress);
return false;
}
// check egress connection
final ConnectPoint egress = pointToPointIntent.filteredEgressPoint().connectPoint();
final ConnectPointJsonMatcher egressMatcher = ConnectPointJsonMatcher.matchesConnectPoint(egress);
final JsonNode jsonEgress = jsonIntent.get("egressPoint");
final boolean egressMatches = egressMatcher.matchesSafely(jsonEgress, description);
if (!egressMatches) {
description.appendText("egress was " + jsonEgress);
return false;
}
return true;
}
use of org.onosproject.net.intent.PointToPointIntent 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;
}
}
Aggregations