use of org.onosproject.net.intent.PointToPointIntent in project onos by opennetworkinglab.
the class TopoIntentFilter method getIntents.
// Produces a list of intents that target all selected hosts, devices, links or connect points.
private List<Intent> getIntents(Set<Host> hosts, Set<Device> devices, Set<Link> links, Set<ConnectPoint> edgePoints, Iterable<Intent> sourceIntents) {
List<Intent> intents = new ArrayList<>();
if (hosts.isEmpty() && devices.isEmpty() && links.isEmpty()) {
return intents;
}
Set<OpticalConnectivityIntent> opticalIntents = new HashSet<>();
// Search through all intents and see if they are relevant to our search.
for (Intent intent : sourceIntents) {
if (intentService.getIntentState(intent.key()) == INSTALLED) {
boolean isRelevant = false;
if (intent instanceof HostToHostIntent) {
isRelevant = isIntentRelevantToHosts((HostToHostIntent) intent, hosts) && isIntentRelevantToDevices(intent, devices) && isIntentRelevantToLinks(intent, links);
} else if (intent instanceof PointToPointIntent) {
isRelevant = isIntentRelevant((PointToPointIntent) intent, edgePoints) && isIntentRelevantToDevices(intent, devices) && isIntentRelevantToLinks(intent, links);
} else if (intent instanceof MultiPointToSinglePointIntent) {
isRelevant = isIntentRelevant((MultiPointToSinglePointIntent) intent, edgePoints) && isIntentRelevantToDevices(intent, devices) && isIntentRelevantToLinks(intent, links);
} else if (intent instanceof OpticalConnectivityIntent) {
opticalIntents.add((OpticalConnectivityIntent) intent);
}
if (isRelevant) {
intents.add(intent);
}
}
}
// packet-level ones.
for (OpticalConnectivityIntent intent : opticalIntents) {
if (isIntentRelevant(intent, intents) && isIntentRelevantToDevices(intent, devices)) {
intents.add(intent);
}
}
return intents;
}
use of org.onosproject.net.intent.PointToPointIntent in project onos by opennetworkinglab.
the class IntentsResourceTest method testIntentsArrayWithoutDetail.
/**
* Tests the result of the rest api GET when intents are defined and the detail flag is false.
*/
@Test
public void testIntentsArrayWithoutDetail() {
replay(mockIntentService);
final PointToPointIntent intent1 = PointToPointIntent.builder().appId(APP_ID).selector(selector1).treatment(treatment1).filteredIngressPoint(new FilteredConnectPoint(connectPoint1)).filteredEgressPoint(new FilteredConnectPoint(connectPoint2)).build();
final HashSet<NetworkResource> resources = new HashSet<>();
resources.add(new MockResource(1));
resources.add(new MockResource(2));
resources.add(new MockResource(3));
final HostToHostIntent intent2 = HostToHostIntent.builder().appId(APP_ID).selector(selector2).treatment(treatment2).one(hostId1).two(hostId2).build();
intents.add(intent1);
intents.add(intent2);
final WebTarget wt = target();
final String response = wt.path("intents").queryParam("detail", false).request().get(String.class);
assertThat(response, containsString("{\"intents\":["));
final JsonObject result = Json.parse(response).asObject();
assertThat(result, notNullValue());
assertThat(result.names(), hasSize(1));
assertThat(result.names().get(0), is("intents"));
final JsonArray jsonIntents = result.get("intents").asArray();
assertThat(jsonIntents, notNullValue());
assertThat(jsonIntents, hasIntent(intent1, false));
}
use of org.onosproject.net.intent.PointToPointIntent in project onos by opennetworkinglab.
the class VbngManager method srcMatchIntentGenerator.
/**
* PointToPointIntent Generator.
* <p>
* The intent will match the source IP address in packet, rewrite the
* source IP address, and rewrite the destination MAC address.
* </p>
*
* @param srcIpAddress the source IP address in packet to match
* @param newSrcIpAddress the new source IP address to set
* @param dstMacAddress the destination MAC address to set
* @param dstConnectPoint the egress point
* @param srcConnectPoint the ingress point
* @return a PointToPointIntent
*/
private PointToPointIntent srcMatchIntentGenerator(IpAddress srcIpAddress, IpAddress newSrcIpAddress, MacAddress dstMacAddress, ConnectPoint dstConnectPoint, ConnectPoint srcConnectPoint) {
checkNotNull(srcIpAddress);
checkNotNull(newSrcIpAddress);
checkNotNull(dstMacAddress);
checkNotNull(dstConnectPoint);
checkNotNull(srcConnectPoint);
TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
selector.matchEthType(Ethernet.TYPE_IPV4);
selector.matchIPSrc(IpPrefix.valueOf(srcIpAddress, IpPrefix.MAX_INET_MASK_LENGTH));
TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder();
treatment.setEthDst(dstMacAddress);
treatment.setIpSrc(newSrcIpAddress);
Key key = Key.of(srcIpAddress.toString() + "MatchSrc", appId);
PointToPointIntent intent = PointToPointIntent.builder().appId(appId).key(key).selector(selector.build()).treatment(treatment.build()).filteredEgressPoint(new FilteredConnectPoint(dstConnectPoint)).filteredIngressPoint(new FilteredConnectPoint(srcConnectPoint)).build();
log.info("Generated a PointToPointIntent for traffic from local host " + ": {}", intent);
return intent;
}
use of org.onosproject.net.intent.PointToPointIntent in project onos by opennetworkinglab.
the class VbngManager method dstMatchIntentGenerator.
/**
* PointToPointIntent Generator.
* <p>
* The intent will match the destination IP address in packet, rewrite the
* destination IP address, and rewrite the destination MAC address.
* </p>
*
* @param dstIpAddress the destination IP address in packet to match
* @param newDstIpAddress the new destination IP address to set
* @param dstMacAddress the destination MAC address to set
* @param dstConnectPoint the egress point
* @param srcConnectPoint the ingress point
* @return a PointToPointIntent
*/
private PointToPointIntent dstMatchIntentGenerator(IpAddress dstIpAddress, IpAddress newDstIpAddress, MacAddress dstMacAddress, ConnectPoint dstConnectPoint, ConnectPoint srcConnectPoint) {
checkNotNull(dstIpAddress);
checkNotNull(newDstIpAddress);
checkNotNull(dstMacAddress);
checkNotNull(dstConnectPoint);
checkNotNull(srcConnectPoint);
TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
selector.matchEthType(Ethernet.TYPE_IPV4);
selector.matchIPDst(IpPrefix.valueOf(dstIpAddress, IpPrefix.MAX_INET_MASK_LENGTH));
TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder();
treatment.setEthDst(dstMacAddress);
treatment.setIpDst(newDstIpAddress);
Key key = Key.of(newDstIpAddress.toString() + "MatchDst", appId);
PointToPointIntent intent = PointToPointIntent.builder().appId(appId).key(key).selector(selector.build()).treatment(treatment.build()).filteredEgressPoint(new FilteredConnectPoint(dstConnectPoint)).filteredIngressPoint(new FilteredConnectPoint(srcConnectPoint)).build();
log.info("Generated a PointToPointIntent for traffic to local host " + ": {}", intent);
return intent;
}
use of org.onosproject.net.intent.PointToPointIntent in project onos by opennetworkinglab.
the class VbngManager method setupForwardingPaths.
/**
* Sets up forwarding paths in both two directions between host configured
* with private IP and next hop.
*
* @param privateIp the private IP address of a local host
* @param publicIp the public IP address assigned for the private IP address
* @param hostMacAddress the MAC address for the IP address
* @param hostName the host name for the IP address
*/
private boolean setupForwardingPaths(IpAddress privateIp, IpAddress publicIp, MacAddress hostMacAddress, String hostName) {
checkNotNull(privateIp);
checkNotNull(publicIp);
checkNotNull(hostMacAddress);
checkNotNull(hostName);
if (nextHopIpAddress == null) {
log.warn("Did not find next hop IP address");
return false;
}
// we will do nothing and directly return.
if (p2pIntentsFromHost.containsKey(privateIp) && p2pIntentsToHost.containsKey(privateIp)) {
return true;
}
Host nextHopHost = null;
if (!hostService.getHostsByIp(nextHopIpAddress).isEmpty()) {
nextHopHost = hostService.getHostsByIp(nextHopIpAddress).iterator().next();
} else {
hostService.startMonitoringIp(nextHopIpAddress);
if (hostService.getHostsByIp(privateIp).isEmpty()) {
hostService.startMonitoringIp(privateIp);
}
return false;
}
ConnectPoint nextHopConnectPoint = new ConnectPoint(nextHopHost.location().elementId(), nextHopHost.location().port());
ConnectPoint localHostConnectPoint = nodeToPort.get(hostName);
// private IP
if (!p2pIntentsFromHost.containsKey(privateIp)) {
PointToPointIntent toNextHopIntent = srcMatchIntentGenerator(privateIp, publicIp, nextHopHost.mac(), nextHopConnectPoint, localHostConnectPoint);
p2pIntentsFromHost.put(privateIp, toNextHopIntent);
intentService.submit(toNextHopIntent);
}
// private IP
if (!p2pIntentsToHost.containsKey(privateIp)) {
PointToPointIntent toLocalHostIntent = dstMatchIntentGenerator(publicIp, privateIp, hostMacAddress, localHostConnectPoint, nextHopConnectPoint);
p2pIntentsToHost.put(privateIp, toLocalHostIntent);
intentService.submit(toLocalHostIntent);
}
return true;
}
Aggregations