use of org.onosproject.net.intent.ConnectivityIntent in project onos by opennetworkinglab.
the class IntentMonitorAndRerouteManager method startMonitorIntent.
@Override
public synchronized boolean startMonitorIntent(Key intentKey) {
checkNotNull(intentKey, "Intent Key must not be null");
log.debug("Start Monitor Intent: {}", intentKey.toString());
toBeMonitoredIntents.add(intentKey);
// Check if the requested intent is already present in the intent manager
Intent installedIntent = intentService.getIntent(intentKey);
if (!allowedIntent(installedIntent)) {
return false;
}
// Check if the intent that is present in the intent subsystem is already installed
if (intentService.getIntentState(intentKey) == IntentState.INSTALLED) {
storeMonitoredIntent((ConnectivityIntent) installedIntent);
}
return true;
}
use of org.onosproject.net.intent.ConnectivityIntent in project onos by opennetworkinglab.
the class IntentMonitorAndRerouteManager method applyPath.
@Override
public boolean applyPath(Route route) {
checkNotNull(route, "Route to apply must be not null");
checkNotNull(route.appId(), "Application id must be not null");
checkNotNull(route.key(), "Intent key to apply must be not null");
checkNotNull(route.paths(), "New path must be not null");
checkArgument(route.paths().size() >= 1);
ApplicationId appId = route.appId();
Key key = route.key();
// check if the app and the intent key are monitored
if (!monitoredIntents.containsKey(appId)) {
return false;
}
if (!monitoredIntents.get(appId).containsKey(key)) {
return false;
}
// TODO: now we manage only the unsplittable routing
Path currentPath = route.paths().stream().max(Comparator.comparing(Path::weight)).get();
// in this case remove them from the list
if (currentPath.path().get(0) instanceof HostId) {
currentPath.path().remove(0);
}
if (currentPath.path().get(currentPath.path().size() - 1) instanceof HostId) {
currentPath.path().remove(currentPath.path().size() - 1);
}
List<Link> links = createPathFromDeviceList(currentPath.path());
// Generate the new Link collection intent, if not possible it will return the old intent
ConnectivityIntent intent = generateLinkCollectionIntent(links, key, appId);
storeMonitoredIntent(intent);
intentService.submit(intent);
return true;
}
use of org.onosproject.net.intent.ConnectivityIntent in project onos by opennetworkinglab.
the class IntentMonitorAndRerouteManager method generateLinkCollectionIntent.
/**
* Generates a new {@Link LinkCollectionIntent} applying the new path.
* @param links List of links of the new path.
* @param intentKey Key of the intent you want to re-route.
* @param appId Application id that submits initially the intent.
* @return The new intent, if not possibile it will return the old intent already installed.
*/
private ConnectivityIntent generateLinkCollectionIntent(List<Link> links, Key intentKey, ApplicationId appId) {
checkNotNull(links);
checkNotNull(appId);
// Gets the oldIntent already installed
ConnectivityIntent oldIntent = monitoredIntents.get(appId).get(intentKey);
// Flush the statistics of the currently installed intent
flushIntentStatStore(intentKey);
// get the connect point of the old intent
// Left element of the Pair is the ingress, right one is the egress
Pair<Set<FilteredConnectPoint>, Set<FilteredConnectPoint>> cpPair = extractEndConnectPoints(oldIntent);
if (cpPair == null) {
return oldIntent;
}
// Now generate the new intent
LinkCollectionIntent newIntent = LinkCollectionIntent.builder().appId(oldIntent.appId()).key(intentKey).selector(oldIntent.selector()).filteredIngressPoints(ImmutableSet.copyOf(cpPair.getLeft())).filteredEgressPoints(ImmutableSet.copyOf(cpPair.getRight())).treatment(oldIntent.treatment()).priority(oldIntent.priority()).constraints(oldIntent.constraints()).links(ImmutableSet.copyOf(links)).applyTreatmentOnEgress(true).build();
return newIntent;
}
use of org.onosproject.net.intent.ConnectivityIntent in project onos by opennetworkinglab.
the class ConnectivityIntentCodec method encode.
@Override
public ObjectNode encode(ConnectivityIntent intent, CodecContext context) {
checkNotNull(intent, "Connectivity intent cannot be null");
final JsonCodec<Intent> intentCodec = context.codec(Intent.class);
final ObjectNode result = intentCodec.encode(intent, context);
if (intent.selector() != null) {
final JsonCodec<TrafficSelector> selectorCodec = context.codec(TrafficSelector.class);
result.set(SELECTOR, selectorCodec.encode(intent.selector(), context));
}
if (intent.treatment() != null) {
final JsonCodec<TrafficTreatment> treatmentCodec = context.codec(TrafficTreatment.class);
result.set(TREATMENT, treatmentCodec.encode(intent.treatment(), context));
}
result.put(IntentCodec.PRIORITY, intent.priority());
if (intent.constraints() != null) {
final ArrayNode jsonConstraints = result.putArray(CONSTRAINTS);
if (intent.constraints() != null) {
final JsonCodec<Constraint> constraintCodec = context.codec(Constraint.class);
for (final Constraint constraint : intent.constraints()) {
final ObjectNode constraintNode = constraintCodec.encode(constraint, context);
jsonConstraints.add(constraintNode);
}
}
}
return result;
}
use of org.onosproject.net.intent.ConnectivityIntent in project onos by opennetworkinglab.
the class HostToHostIntentCodec method encode.
@Override
public ObjectNode encode(HostToHostIntent intent, CodecContext context) {
checkNotNull(intent, "Host to host intent cannot be null");
final JsonCodec<ConnectivityIntent> connectivityIntentCodec = context.codec(ConnectivityIntent.class);
final ObjectNode result = connectivityIntentCodec.encode(intent, context);
final String one = intent.one().toString();
final String two = intent.two().toString();
result.put(ONE, one);
result.put(TWO, two);
return result;
}
Aggregations