Search in sources :

Example 31 with Key

use of org.onosproject.net.intent.Key in project onos by opennetworkinglab.

the class VplsIntentTest method generateVplsUni.

/**
 * Generates a list of expected mp2sp intents for a given VPLS.
 *
 * @param fcPoints the filtered connect point
 * @param hosts the hosts
 * @param name the name of the VPLS
 * @param encap the encapsulation type
 * @return the list of expected mp2sp intents for the given VPLS
 */
private List<MultiPointToSinglePointIntent> generateVplsUni(Set<FilteredConnectPoint> fcPoints, Set<Host> hosts, String name, EncapsulationType encap) {
    List<MultiPointToSinglePointIntent> intents = Lists.newArrayList();
    hosts.forEach(host -> {
        FilteredConnectPoint hostPoint = getHostPoint(host, fcPoints);
        Set<FilteredConnectPoint> otherPoints = fcPoints.stream().filter(fcp -> !fcp.equals(hostPoint)).collect(Collectors.toSet());
        Key uniKey = buildKey(VplsIntentUtility.PREFIX_UNICAST, host.location(), name, host.mac());
        intents.add(buildUniIntent(uniKey, otherPoints, hostPoint, host, encap));
    });
    return intents;
}
Also used : IntentServiceAdapter(org.onosproject.net.intent.IntentServiceAdapter) MockIdGenerator(org.onosproject.net.intent.MockIdGenerator) Host(org.onosproject.net.Host) Interface(org.onosproject.net.intf.Interface) NONE(org.onosproject.net.EncapsulationType.NONE) VplsData(org.onosproject.vpls.api.VplsData) InterfaceService(org.onosproject.net.intf.InterfaceService) IntentUtils(org.onosproject.net.intent.IntentUtils) SinglePointToMultiPointIntent(org.onosproject.net.intent.SinglePointToMultiPointIntent) ConnectPoint(org.onosproject.net.ConnectPoint) InterfaceListener(org.onosproject.net.intf.InterfaceListener) Lists(com.google.common.collect.Lists) TrafficSelector(org.onosproject.net.flow.TrafficSelector) MultiPointToSinglePointIntent(org.onosproject.net.intent.MultiPointToSinglePointIntent) IntentService(org.onosproject.net.intent.IntentService) After(org.junit.After) Map(java.util.Map) Intent(org.onosproject.net.intent.Intent) EasyMock.replay(org.easymock.EasyMock.replay) EasyMock.createMock(org.easymock.EasyMock.createMock) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) Criterion(org.onosproject.net.flow.criteria.Criterion) Before(org.junit.Before) EasyMock.anyObject(org.easymock.EasyMock.anyObject) ImmutableSet(com.google.common.collect.ImmutableSet) VLAN(org.onosproject.net.EncapsulationType.VLAN) Collection(java.util.Collection) VlanId(org.onlab.packet.VlanId) Set(java.util.Set) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) VplsIntentUtility(org.onosproject.vpls.intent.VplsIntentUtility) EasyMock.expect(org.easymock.EasyMock.expect) Maps(com.google.common.collect.Maps) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) String.format(java.lang.String.format) EasyMock.expectLastCall(org.easymock.EasyMock.expectLastCall) Key(org.onosproject.net.intent.Key) List(java.util.List) EncapsulationType(org.onosproject.net.EncapsulationType) VlanIdCriterion(org.onosproject.net.flow.criteria.VlanIdCriterion) MacAddress(org.onlab.packet.MacAddress) Assert.assertEquals(org.junit.Assert.assertEquals) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint) MultiPointToSinglePointIntent(org.onosproject.net.intent.MultiPointToSinglePointIntent) Key(org.onosproject.net.intent.Key) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint)

Example 32 with Key

use of org.onosproject.net.intent.Key in project onos by opennetworkinglab.

the class TopologyViewMessageHandler method findIntentByPayload.

private Intent findIntentByPayload(ObjectNode payload) {
    Intent intent;
    Key key;
    int appId = Integer.parseInt(string(payload, APP_ID));
    String appName = string(payload, APP_NAME);
    ApplicationId applicId = new DefaultApplicationId(appId, appName);
    String stringKey = string(payload, KEY);
    try {
        // FIXME: If apps use different string key, but they contains
        // same numeric value (e.g. "020", "0x10", "16", "#10")
        // and one intent using long key (e.g. 16L)
        // this function might return wrong intent.
        long longKey = Long.decode(stringKey);
        key = Key.of(longKey, applicId);
        intent = services.intent().getIntent(key);
        if (intent == null) {
            // Intent might using string key, not long key
            key = Key.of(stringKey, applicId);
            intent = services.intent().getIntent(key);
        }
    } catch (NumberFormatException ex) {
        // string key
        key = Key.of(stringKey, applicId);
        intent = services.intent().getIntent(key);
    }
    log.debug("Attempting to select intent by key={}", key);
    return intent;
}
Also used : HostToHostIntent(org.onosproject.net.intent.HostToHostIntent) MultiPointToSinglePointIntent(org.onosproject.net.intent.MultiPointToSinglePointIntent) Intent(org.onosproject.net.intent.Intent) ConnectPoint.fromString(org.onosproject.net.ConnectPoint.fromString) DefaultApplicationId(org.onosproject.core.DefaultApplicationId) ApplicationId(org.onosproject.core.ApplicationId) Key(org.onosproject.net.intent.Key) ConnectPoint(org.onosproject.net.ConnectPoint) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint) DefaultApplicationId(org.onosproject.core.DefaultApplicationId)

Example 33 with Key

use of org.onosproject.net.intent.Key in project onos by opennetworkinglab.

the class VirtualNetworkIntentRemoveCommand method removeIntent.

/**
 * Removes the intent using the specified intentService.
 *
 * @param intentService intent service
 * @param intent        intent
 */
private void removeIntent(IntentService intentService, Intent intent) {
    IntentListener listener = null;
    Key key = intent.key();
    final CountDownLatch withdrawLatch, purgeLatch;
    if (purgeAfterRemove || sync) {
        // set up latch and listener to track uninstall progress
        withdrawLatch = new CountDownLatch(1);
        purgeLatch = purgeAfterRemove ? new CountDownLatch(1) : null;
        listener = (IntentEvent event) -> {
            if (Objects.equals(event.subject().key(), key)) {
                if (event.type() == IntentEvent.Type.WITHDRAWN || event.type() == IntentEvent.Type.FAILED) {
                    withdrawLatch.countDown();
                } else if (purgeLatch != null && purgeAfterRemove && event.type() == IntentEvent.Type.PURGED) {
                    purgeLatch.countDown();
                }
            }
        };
        intentService.addListener(listener);
    } else {
        purgeLatch = null;
        withdrawLatch = null;
    }
    // request the withdraw
    intentService.withdraw(intent);
    if ((purgeAfterRemove || sync) && purgeLatch != null) {
        try {
            // wait for withdraw event
            withdrawLatch.await(5, TimeUnit.SECONDS);
        } catch (InterruptedException e) {
            print("Timed out waiting for intent {} withdraw", key);
        }
        if (purgeAfterRemove && CAN_PURGE.contains(intentService.getIntentState(key))) {
            intentService.purge(intent);
            if (sync) {
                /* TODO
                       Technically, the event comes before map.remove() is called.
                       If we depend on sync and purge working together, we will
                       need to address this.
                    */
                try {
                    purgeLatch.await(5, TimeUnit.SECONDS);
                } catch (InterruptedException e) {
                    print("Timed out waiting for intent {} purge", key);
                }
            }
        }
    }
    if (listener != null) {
        // clean up the listener
        intentService.removeListener(listener);
    }
}
Also used : IntentListener(org.onosproject.net.intent.IntentListener) CountDownLatch(java.util.concurrent.CountDownLatch) Key(org.onosproject.net.intent.Key) IntentEvent(org.onosproject.net.intent.IntentEvent)

Example 34 with Key

use of org.onosproject.net.intent.Key in project onos by opennetworkinglab.

the class VirtualNetworkIntentRemoveCommand method doExecute.

@Override
protected void doExecute() {
    VirtualNetworkService service = get(VirtualNetworkService.class);
    IntentService intentService = service.get(NetworkId.networkId(networkId), IntentService.class);
    CoreService coreService = get(CoreService.class);
    if (purgeAfterRemove || sync) {
        print("Using \"sync\" to remove/purge intents - this may take a while...");
        print("Check \"summary\" to see remove/purge progress.");
    }
    ApplicationId appId = appId();
    if (!isNullOrEmpty(applicationIdString)) {
        appId = coreService.getAppId(applicationIdString);
        if (appId == null) {
            print("Cannot find application Id %s", applicationIdString);
            return;
        }
    }
    if (isNullOrEmpty(keyString)) {
        for (Intent intent : intentService.getIntents()) {
            if (intent.appId().equals(appId)) {
                removeIntent(intentService, intent);
            }
        }
    } else {
        final Key key;
        if (keyString.startsWith("0x")) {
            // The intent uses a LongKey
            keyString = keyString.replaceFirst("0x", "");
            key = Key.of(new BigInteger(keyString, 16).longValue(), appId);
        } else {
            // The intent uses a StringKey
            key = Key.of(keyString, appId);
        }
        Intent intent = intentService.getIntent(key);
        if (intent != null) {
            removeIntent(intentService, intent);
        } else {
            print("Intent not found!");
        }
    }
}
Also used : IntentService(org.onosproject.net.intent.IntentService) VirtualNetworkService(org.onosproject.incubator.net.virtual.VirtualNetworkService) CoreService(org.onosproject.core.CoreService) BigInteger(java.math.BigInteger) Intent(org.onosproject.net.intent.Intent) ApplicationId(org.onosproject.core.ApplicationId) Key(org.onosproject.net.intent.Key)

Example 35 with Key

use of org.onosproject.net.intent.Key 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)

Aggregations

Key (org.onosproject.net.intent.Key)65 FilteredConnectPoint (org.onosproject.net.FilteredConnectPoint)25 Intent (org.onosproject.net.intent.Intent)22 ConnectPoint (org.onosproject.net.ConnectPoint)20 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)19 TrafficSelector (org.onosproject.net.flow.TrafficSelector)19 MultiPointToSinglePointIntent (org.onosproject.net.intent.MultiPointToSinglePointIntent)19 Test (org.junit.Test)15 Constraint (org.onosproject.net.intent.Constraint)15 PointToPointIntent (org.onosproject.net.intent.PointToPointIntent)14 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)12 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)12 SinglePointToMultiPointIntent (org.onosproject.net.intent.SinglePointToMultiPointIntent)12 ApplicationId (org.onosproject.core.ApplicationId)11 IntentService (org.onosproject.net.intent.IntentService)11 ArrayList (java.util.ArrayList)9 HashSet (java.util.HashSet)9 Interface (org.onosproject.net.intf.Interface)9 Set (java.util.Set)8 MacAddress (org.onlab.packet.MacAddress)8