Search in sources :

Example 61 with Key

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

the class ConnectivityManager method deletel3.

/**
 * Delete all the flows between the Peer being deleted and the Route Servers
 * to kill the BGP sessions. It uses the keys to retrive the previous intents
 * and withdraw them.
 *
 * @param peer The Peer being deleted.
 */
private void deletel3(Peer peer) {
    List<Key> keys = new LinkedList<>();
    IpAddress ipTwo = IpAddress.valueOf(peer.getIpAddress());
    for (Peer server : castorStore.getServers()) {
        IpAddress ipOne = IpAddress.valueOf(server.getIpAddress());
        keys.add(buildKey(ipOne, ipTwo, SUFFIX_SRC));
        keys.add(buildKey(ipTwo, ipOne, SUFFIX_DST));
        keys.add(buildKey(ipOne, ipTwo, SUFFIX_ICMP));
        keys.add(buildKey(ipTwo, ipOne, SUFFIX_ICMP));
    }
    for (Key keyDel : keys) {
        PointToPointIntent intent = castorStore.getPeerIntents().get(keyDel);
        intentSynchronizer.withdraw(intent);
        castorStore.removePeerIntent(keyDel);
    }
}
Also used : PointToPointIntent(org.onosproject.net.intent.PointToPointIntent) IpAddress(org.onlab.packet.IpAddress) Key(org.onosproject.net.intent.Key) LinkedList(java.util.LinkedList)

Example 62 with Key

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

the class IntentSynchronizer method synchronizeIntents.

private void synchronizeIntents() {
    Map<Key, Intent> serviceIntents = new HashMap<>();
    intentService.getIntents().forEach(i -> {
        if (i.appId().equals(appId)) {
            serviceIntents.put(i.key(), i);
        }
    });
    List<Intent> intentsToAdd = new LinkedList<>();
    List<Intent> intentsToRemove = new LinkedList<>();
    for (Intent localIntent : intents.values()) {
        Intent serviceIntent = serviceIntents.remove(localIntent.key());
        if (serviceIntent == null) {
            intentsToAdd.add(localIntent);
        } else {
            IntentState state = intentService.getIntentState(serviceIntent.key());
            if (!IntentUtils.intentsAreEqual(serviceIntent, localIntent) || state == null || state == IntentState.WITHDRAW_REQ || state == IntentState.WITHDRAWING || state == IntentState.WITHDRAWN) {
                intentsToAdd.add(localIntent);
            }
        }
    }
    for (Intent serviceIntent : serviceIntents.values()) {
        IntentState state = intentService.getIntentState(serviceIntent.key());
        if (state != null && state != IntentState.WITHDRAW_REQ && state != IntentState.WITHDRAWING && state != IntentState.WITHDRAWN) {
            intentsToRemove.add(serviceIntent);
        }
    }
    log.debug("Intent Synchronizer: submitting {}, withdrawing {}", intentsToAdd.size(), intentsToRemove.size());
    // Withdraw Intents
    for (Intent intent : intentsToRemove) {
        intentService.withdraw(intent);
        log.trace("Intent Synchronizer: withdrawing intent: {}", intent);
    }
    if (!isElectedLeader) {
        log.debug("Intent Synchronizer: cannot withdraw intents: " + "not elected leader anymore");
        isActivatedLeader = false;
        return;
    }
    // Add Intents
    for (Intent intent : intentsToAdd) {
        intentService.submit(intent);
        log.trace("Intent Synchronizer: submitting intent: {}", intent);
    }
    if (!isElectedLeader) {
        log.debug("Intent Synchronizer: cannot submit intents: " + "not elected leader anymore");
        isActivatedLeader = false;
        return;
    }
    if (isElectedLeader) {
        // Allow push of Intents
        isActivatedLeader = true;
    } else {
        isActivatedLeader = false;
    }
    log.debug("Intent synchronization completed");
}
Also used : IntentState(org.onosproject.net.intent.IntentState) HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Intent(org.onosproject.net.intent.Intent) Key(org.onosproject.net.intent.Key) LinkedList(java.util.LinkedList)

Example 63 with Key

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

the class StartMonitorCommand method doExecute.

@Override
protected void doExecute() {
    imrService = get(IntentMonitorAndRerouteService.class);
    intentService = get(IntentService.class);
    if (appId != null && appName != null) {
        if (key != null) {
            /*
                Intent key might be a StringKey or a LongKey, but in any case is
                provided via CLI as a string. To solve only ambiguity we check if
                "--longkey" CLI parameter has been set.
                 */
            if (treatAsLongKey) {
                try {
                    Key intentKeyLong = Key.of(Integer.decode(key), new DefaultApplicationId(appId, appName));
                    for (Intent intent : intentService.getIntents()) {
                        if (intent.key().equals(intentKeyLong)) {
                            imrService.startMonitorIntent(intentKeyLong);
                            print("Started monitoring of intent with LongKey %s", intentKeyLong);
                            return;
                        }
                    }
                    imrService.startMonitorIntent(intentKeyLong);
                    print("Started monitoring of intent with LongKey %s, even if not yet submitted", intentKeyLong);
                } catch (NumberFormatException nfe) {
                    print("\"%s\" is not a valid LongKey", key);
                }
            } else {
                Key intentKeyString = Key.of(key, new DefaultApplicationId(appId, appName));
                for (Intent intent : intentService.getIntents()) {
                    if (intent.key().equals(intentKeyString)) {
                        imrService.startMonitorIntent(intentKeyString);
                        print("Started monitoring of intent with StringKey %s", intentKeyString);
                        return;
                    }
                }
                imrService.startMonitorIntent(intentKeyString);
                print("Started monitoring of intent with StringKey %s, even if not yet submitted", intentKeyString);
            }
        } else {
            intentService.getIntents().forEach(i -> {
                if (i.appId().equals(new DefaultApplicationId(appId, appName))) {
                    imrService.startMonitorIntent(i.key());
                    print("Started monitoring of intent with Key %s", i.key());
                }
            });
        }
    }
}
Also used : IntentService(org.onosproject.net.intent.IntentService) IntentMonitorAndRerouteService(org.onosproject.imr.IntentMonitorAndRerouteService) Intent(org.onosproject.net.intent.Intent) Key(org.onosproject.net.intent.Key) DefaultApplicationId(org.onosproject.core.DefaultApplicationId)

Example 64 with Key

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

the class ImrWebResource method getIntentsStats.

/**
 * Get the statistics of a specific monitored intent.
 * Shows all the flow entries of the specific intent
 *
 * @onos.rsModel intentStatsGet
 * @param id Application ID
 * @param name Application Name
 * @param intentK Intent Key
 * @return 200 OK
 */
@GET
@Path("intentStats/{id}/{name}/{intentKey}")
@Produces(MediaType.APPLICATION_JSON)
public Response getIntentsStats(@PathParam("id") short id, @PathParam("name") String name, @PathParam("intentKey") String intentK) {
    ObjectNode root = mapper.createObjectNode();
    imrService = get(IntentMonitorAndRerouteService.class);
    ApplicationId appId = new DefaultApplicationId(id, name);
    Key intentKey = Key.of(intentK, appId);
    root.putArray("statistics").addAll(getJsonNodesIntentStats(imrService.getStats(appId, intentKey)));
    return ok(root).build();
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) IntentMonitorAndRerouteService(org.onosproject.imr.IntentMonitorAndRerouteService) DefaultApplicationId(org.onosproject.core.DefaultApplicationId) ApplicationId(org.onosproject.core.ApplicationId) DefaultApplicationId(org.onosproject.core.DefaultApplicationId) Key(org.onosproject.net.intent.Key) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 65 with Key

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

the class IntentMonitorAndRerouteManager method getStats.

@Override
public Map<ApplicationId, Map<Key, List<FlowEntry>>> getStats(ApplicationId appId) {
    checkNotNull(appId);
    // TODO: is there a better way to get statistics?
    Map<ApplicationId, Map<Key, List<FlowEntry>>> currentStatistics = new HashMap<>();
    currentStatistics.put(appId, new HashMap<>());
    if (monitoredIntents.containsKey(appId)) {
        Set<Key> keySet = monitoredIntents.get(appId).keySet();
        for (Key intentKey : keySet) {
            List<FlowEntry> flowEntries = getStats(intentKey);
            currentStatistics.get(appId).put(intentKey, flowEntries);
        }
    }
    return currentStatistics;
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ApplicationId(org.onosproject.core.ApplicationId) ConsistentMap(org.onosproject.store.service.ConsistentMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) FlowEntry(org.onosproject.net.flow.FlowEntry) Key(org.onosproject.net.intent.Key)

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