Search in sources :

Example 26 with PointToPointIntent

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;
}
Also used : HostToHostIntent(org.onosproject.net.intent.HostToHostIntent) ArrayList(java.util.ArrayList) PointToPointIntent(org.onosproject.net.intent.PointToPointIntent) OpticalConnectivityIntent(org.onosproject.net.intent.OpticalConnectivityIntent) FlowObjectiveIntent(org.onosproject.net.intent.FlowObjectiveIntent) MultiPointToSinglePointIntent(org.onosproject.net.intent.MultiPointToSinglePointIntent) Intent(org.onosproject.net.intent.Intent) PathIntent(org.onosproject.net.intent.PathIntent) FlowRuleIntent(org.onosproject.net.intent.FlowRuleIntent) HostToHostIntent(org.onosproject.net.intent.HostToHostIntent) LinkCollectionIntent(org.onosproject.net.intent.LinkCollectionIntent) PointToPointIntent(org.onosproject.net.intent.PointToPointIntent) OpticalConnectivityIntent(org.onosproject.net.intent.OpticalConnectivityIntent) MultiPointToSinglePointIntent(org.onosproject.net.intent.MultiPointToSinglePointIntent) HashSet(java.util.HashSet)

Example 27 with PointToPointIntent

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));
}
Also used : NetworkResource(org.onosproject.net.NetworkResource) JsonArray(com.eclipsesource.json.JsonArray) HostToHostIntent(org.onosproject.net.intent.HostToHostIntent) PointToPointIntent(org.onosproject.net.intent.PointToPointIntent) JsonObject(com.eclipsesource.json.JsonObject) WebTarget(javax.ws.rs.client.WebTarget) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 28 with PointToPointIntent

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;
}
Also used : PointToPointIntent(org.onosproject.net.intent.PointToPointIntent) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) Key(org.onosproject.net.intent.Key) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint)

Example 29 with PointToPointIntent

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;
}
Also used : PointToPointIntent(org.onosproject.net.intent.PointToPointIntent) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) Key(org.onosproject.net.intent.Key) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint)

Example 30 with PointToPointIntent

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;
}
Also used : PointToPointIntent(org.onosproject.net.intent.PointToPointIntent) Host(org.onosproject.net.Host) ConnectPoint(org.onosproject.net.ConnectPoint) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint)

Aggregations

PointToPointIntent (org.onosproject.net.intent.PointToPointIntent)48 FilteredConnectPoint (org.onosproject.net.FilteredConnectPoint)28 ConnectPoint (org.onosproject.net.ConnectPoint)24 Intent (org.onosproject.net.intent.Intent)19 Test (org.junit.Test)18 AbstractIntentTest (org.onosproject.net.intent.AbstractIntentTest)16 LinkCollectionIntent (org.onosproject.net.intent.LinkCollectionIntent)16 TrafficSelector (org.onosproject.net.flow.TrafficSelector)13 Key (org.onosproject.net.intent.Key)13 ArrayList (java.util.ArrayList)12 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)12 Link (org.onosproject.net.Link)11 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)11 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)11 Constraint (org.onosproject.net.intent.Constraint)11 FlowRuleIntent (org.onosproject.net.intent.FlowRuleIntent)10 BandwidthConstraint (org.onosproject.net.intent.constraint.BandwidthConstraint)10 PathIntent (org.onosproject.net.intent.PathIntent)8 MockResourceService (org.onosproject.net.resource.MockResourceService)8 ResourceService (org.onosproject.net.resource.ResourceService)8