use of org.onosproject.net.intent.HostToHostIntent 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;
}
use of org.onosproject.net.intent.HostToHostIntent in project onos by opennetworkinglab.
the class TrafficMonitorBase method addEdgeLinksIfNeeded.
protected Iterable<Link> addEdgeLinksIfNeeded(Intent parentIntent, Collection<Link> links) {
if (parentIntent instanceof HostToHostIntent) {
links = new HashSet<>(links);
HostToHostIntent h2h = (HostToHostIntent) parentIntent;
Host h1 = services.host().getHost(h2h.one());
Host h2 = services.host().getHost(h2h.two());
links.add(createEdgeLink(h1, true));
links.add(createEdgeLink(h2, true));
}
return links;
}
use of org.onosproject.net.intent.HostToHostIntent 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));
}
use of org.onosproject.net.intent.HostToHostIntent in project onos by opennetworkinglab.
the class IntentsResourceTest method testIntentsForApplicationWithDetail.
/**
* Tests the result of the rest api GET when intents are defined and the detail flag is true.
*/
@Test
public void testIntentsForApplicationWithDetail() {
final Intent intent1 = PointToPointIntent.builder().key(Key.of(0, APP_ID)).appId(APP_ID).selector(selector1).treatment(treatment1).filteredIngressPoint(new FilteredConnectPoint(connectPoint1)).filteredEgressPoint(new FilteredConnectPoint(connectPoint2)).build();
final HostToHostIntent intent2 = HostToHostIntent.builder().key(Key.of(1, APP_ID_2)).appId(APP_ID_2).selector(selector2).treatment(treatment2).one(hostId1).two(hostId2).build();
intents.add(intent1);
List<Intent> appIntents1 = new ArrayList<>();
appIntents1.add(intent1);
intents.add(intent2);
List<Intent> appIntents2 = new ArrayList<>();
appIntents2.add(intent2);
expect(mockIntentService.getIntentsByAppId(APP_ID)).andReturn(appIntents1).anyTimes();
expect(mockIntentService.getIntentsByAppId(APP_ID_2)).andReturn(appIntents2).anyTimes();
replay(mockIntentService);
expect(mockCoreService.getAppId(APP_ID.name())).andReturn(APP_ID).anyTimes();
expect(mockCoreService.getAppId(APP_ID_2.name())).andReturn(APP_ID_2).anyTimes();
replay(mockCoreService);
final WebTarget wt = target();
// Verify intents for app_id
final String response1 = wt.path("intents/application/" + APP_ID.name()).queryParam("detail", true).request().get(String.class);
assertThat(response1, containsString("{\"intents\":["));
final JsonObject result1 = Json.parse(response1).asObject();
assertThat(result1, notNullValue());
assertThat(result1.names(), hasSize(1));
assertThat(result1.names().get(0), is("intents"));
final JsonArray jsonIntents1 = result1.get("intents").asArray();
assertThat(jsonIntents1, notNullValue());
assertThat(jsonIntents1.size(), is(1));
assertThat(jsonIntents1, hasIntent(intent1, true));
assertThat(jsonIntents1, is(not(hasIntent(intent2, true))));
// Verify intents for app_id_2
final String response2 = wt.path("intents/application/" + APP_ID_2.name()).queryParam("detail", true).request().get(String.class);
assertThat(response2, containsString("{\"intents\":["));
final JsonObject result2 = Json.parse(response2).asObject();
assertThat(result2, notNullValue());
assertThat(result2.names(), hasSize(1));
assertThat(result2.names().get(0), is("intents"));
final JsonArray jsonIntents2 = result2.get("intents").asArray();
assertThat(jsonIntents2, notNullValue());
assertThat(jsonIntents2.size(), is(1));
assertThat(jsonIntents2, hasIntent(intent2, true));
assertThat(jsonIntents2, is(not(hasIntent(intent1, true))));
}
use of org.onosproject.net.intent.HostToHostIntent in project onos by opennetworkinglab.
the class IntentsListCommand method detailsFormat.
/**
* Returns detailed information text about a specific intent.
*
* @param intent to print
* @param state of intent
* @return detailed information or "" if {@code state} was null
*/
private StringBuilder detailsFormat(Intent intent, IntentState state) {
StringBuilder builder = new StringBuilder();
if (state == null) {
return builder;
}
if (!intent.resources().isEmpty()) {
builder.append('\n').append(format(RESOURCES, intent.resources()));
}
if (intent instanceof ConnectivityIntent) {
ConnectivityIntent ci = (ConnectivityIntent) intent;
if (!ci.selector().criteria().isEmpty()) {
builder.append('\n').append(format(COMMON_SELECTOR, formatSelector(ci.selector())));
}
if (!ci.treatment().allInstructions().isEmpty()) {
builder.append('\n').append(format(TREATMENT, ci.treatment().allInstructions()));
}
if (ci.constraints() != null && !ci.constraints().isEmpty()) {
builder.append('\n').append(format(CONSTRAINTS, ci.constraints()));
}
}
if (intent instanceof HostToHostIntent) {
HostToHostIntent pi = (HostToHostIntent) intent;
builder.append('\n').append(format(SRC + HOST, pi.one()));
builder.append('\n').append(format(DST + HOST, pi.two()));
} else if (intent instanceof PointToPointIntent) {
PointToPointIntent pi = (PointToPointIntent) intent;
builder.append('\n').append(formatFilteredCps(Sets.newHashSet(pi.filteredIngressPoint()), INGRESS));
builder.append('\n').append(formatFilteredCps(Sets.newHashSet(pi.filteredEgressPoint()), EGRESS));
} else if (intent instanceof MultiPointToSinglePointIntent) {
MultiPointToSinglePointIntent pi = (MultiPointToSinglePointIntent) intent;
builder.append('\n').append(formatFilteredCps(pi.filteredIngressPoints(), INGRESS));
builder.append('\n').append(formatFilteredCps(Sets.newHashSet(pi.filteredEgressPoint()), EGRESS));
} else if (intent instanceof SinglePointToMultiPointIntent) {
SinglePointToMultiPointIntent pi = (SinglePointToMultiPointIntent) intent;
builder.append('\n').append(formatFilteredCps(Sets.newHashSet(pi.filteredIngressPoint()), INGRESS));
builder.append('\n').append(formatFilteredCps(pi.filteredEgressPoints(), EGRESS));
} else if (intent instanceof PathIntent) {
PathIntent pi = (PathIntent) intent;
builder.append(format("path=%s, cost=%f", pi.path().links(), pi.path().cost()));
} else if (intent instanceof LinkCollectionIntent) {
LinkCollectionIntent li = (LinkCollectionIntent) intent;
builder.append('\n').append(format("links=%s", li.links()));
builder.append('\n').append(format(CP, li.egressPoints()));
} else if (intent instanceof OpticalCircuitIntent) {
OpticalCircuitIntent ci = (OpticalCircuitIntent) intent;
builder.append('\n').append(format("src=%s, dst=%s", ci.getSrc(), ci.getDst()));
builder.append('\n').append(format("signal type=%s", ci.getSignalType()));
builder.append('\n').append(format("bidirectional=%s", ci.isBidirectional()));
} else if (intent instanceof OpticalConnectivityIntent) {
OpticalConnectivityIntent ci = (OpticalConnectivityIntent) intent;
builder.append('\n').append(format("src=%s, dst=%s", ci.getSrc(), ci.getDst()));
builder.append('\n').append(format("signal type=%s", ci.getSignalType()));
builder.append('\n').append(format("bidirectional=%s", ci.isBidirectional()));
builder.append('\n').append(format("ochSignal=%s", ci.ochSignal()));
} else if (intent instanceof OpticalOduIntent) {
OpticalOduIntent ci = (OpticalOduIntent) intent;
builder.append('\n').append(format("src=%s, dst=%s", ci.getSrc(), ci.getDst()));
builder.append('\n').append(format("signal type=%s", ci.getSignalType()));
builder.append('\n').append(format("bidirectional=%s", ci.isBidirectional()));
}
List<Intent> installable = service.getInstallableIntents(intent.key()).stream().filter(i -> contentFilter.filter(i)).collect(Collectors.toList());
if (showInstallable && installable != null && !installable.isEmpty()) {
builder.append('\n').append(format(INSTALLABLE, installable));
}
return builder;
}
Aggregations