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);
}
}
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");
}
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());
}
});
}
}
}
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();
}
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;
}
Aggregations