use of org.onosproject.net.Link in project onos by opennetworkinglab.
the class IntentsResourceTest method testIntentInstallables.
/**
* Tests the result of a rest api GET for intent installables.
*/
@Test
public void testIntentInstallables() {
Link link1 = DefaultLink.builder().type(Link.Type.DIRECT).providerId(ProviderId.NONE).src(connectPoint1).dst(connectPoint2).build();
Link link2 = DefaultLink.builder().type(Link.Type.DIRECT).providerId(ProviderId.NONE).src(connectPoint3).dst(connectPoint4).build();
Set<NetworkResource> resources = new HashSet<>();
resources.add(link1);
resources.add(link2);
FlowRuleIntent flowRuleIntent = new FlowRuleIntent(APP_ID, null, new ArrayList<>(), resources, PathIntent.ProtectionType.PRIMARY, null);
Intent intent = new MockIntent(MockIntent.nextId());
Long intentId = intent.id().id();
installableIntents.add(flowRuleIntent);
intents.add(intent);
expect(mockIntentService.getIntent(Key.of(intentId, APP_ID))).andReturn(intent).anyTimes();
expect(mockIntentService.getIntent(Key.of(intentId.toString(), APP_ID))).andReturn(intent).anyTimes();
expect(mockIntentService.getIntent(Key.of(intentId, APP_ID))).andReturn(intent).anyTimes();
expect(mockIntentService.getIntent(Key.of(Long.toHexString(intentId), APP_ID))).andReturn(null).anyTimes();
expect(mockIntentService.getInstallableIntents(intent.key())).andReturn(installableIntents).anyTimes();
replay(mockIntentService);
replay(mockFlowService);
expect(mockCoreService.getAppId(APP_ID.name())).andReturn(APP_ID).anyTimes();
expect(mockCoreService.getAppId(APP_ID.id())).andReturn(APP_ID).anyTimes();
replay(mockCoreService);
final WebTarget wt = target();
// Test get using key string
final String response = wt.path("intents/installables/" + APP_ID.name() + "/" + intentId).request().get(String.class);
final JsonObject result = Json.parse(response).asObject();
assertThat(result.get(INSTALLABLES).asArray(), hasIntent(flowRuleIntent, false));
// Test get using numeric value
final String responseNumeric = wt.path("intents/installables/" + APP_ID.name() + "/" + Long.toHexString(intentId)).request().get(String.class);
final JsonObject resultNumeric = Json.parse(responseNumeric).asObject();
assertThat(resultNumeric.get(INSTALLABLES).asArray(), hasIntent(flowRuleIntent, false));
}
use of org.onosproject.net.Link in project onos by opennetworkinglab.
the class StatisticsWebResource method getLoads.
/**
* Gets load statistics for all links or for a specific link.
*
* @onos.rsModel StatisticsFlowsLink
* @param deviceId (optional) device ID for a specific link
* @param port (optional) port number for a specified link
* @return 200 OK with JSON encoded array of Load objects
*/
@GET
@Path("flows/link")
@Produces(MediaType.APPLICATION_JSON)
public Response getLoads(@QueryParam("device") String deviceId, @QueryParam("port") String port) {
Iterable<Link> links;
if (deviceId == null || port == null) {
links = get(LinkService.class).getLinks();
} else {
ConnectPoint connectPoint = new ConnectPoint(deviceId(deviceId), portNumber(port));
links = get(LinkService.class).getLinks(connectPoint);
}
ObjectNode result = mapper().createObjectNode();
ArrayNode loads = mapper().createArrayNode();
JsonCodec<Load> loadCodec = codec(Load.class);
StatisticService statsService = getService(StatisticService.class);
StreamSupport.stream(Spliterators.spliteratorUnknownSize(links.iterator(), Spliterator.ORDERED), false).forEach(link -> {
ObjectNode loadNode = loadCodec.encode(statsService.load(link), this);
UriBuilder locationBuilder = uriInfo.getBaseUriBuilder().path("links").queryParam("device", link.src().deviceId().toString()).queryParam("port", link.src().port().toString());
loadNode.put("link", locationBuilder.build().toString());
loads.add(loadNode);
});
result.set("loads", loads);
return ok(result).build();
}
use of org.onosproject.net.Link in project onos by opennetworkinglab.
the class FlowAnalyzer method analyzeInstruction.
private boolean analyzeInstruction(Instruction i, FlowEntry flow) {
boolean pointsToLiveEntry = false;
Instructions.OutputInstruction output = (Instructions.OutputInstruction) i;
PortNumber port = output.port();
PortNumber outPort = null;
DeviceId egress = null;
boolean hasHost = false;
ConnectPoint portPt = new ConnectPoint(flow.deviceId(), port);
for (Link l : linkService.getEgressLinks(portPt)) {
if (l.dst().elementId() instanceof DeviceId) {
egress = l.dst().deviceId();
outPort = l.dst().port();
} else if (l.dst().elementId() instanceof HostId) {
// the port leads to a host: therefore it is not a dead link
pointsToLiveEntry = true;
hasHost = true;
}
}
if (!topologyService.isInfrastructure(topologyService.currentTopology(), portPt) && egress == null) {
pointsToLiveEntry = true;
hasHost = true;
}
if (hasHost) {
return pointsToLiveEntry;
}
if (egress == null) {
// the port that the flow instructions tells you to send the packet
// to doesn't exist or is a controller port
label.put(flow, "NA");
return pointsToLiveEntry;
}
Iterable<FlowEntry> dstFlowTable = flowRuleService.getFlowEntries(egress);
Set<Criterion> flowCriteria = flow.selector().criteria();
// filter the criteria in order to remove port dependency
Set<Criterion> filteredCriteria = new HashSet<>();
for (Criterion criterion : flowCriteria) {
if (!(criterion instanceof PortCriterion)) {
filteredCriteria.add(criterion);
}
}
// ensure that the in port is equal to the port that it is coming in from
filteredCriteria.add(Criteria.matchInPort(outPort));
for (FlowEntry entry : dstFlowTable) {
if (ignoredFlows.contains(entry)) {
continue;
}
if (filteredCriteria.containsAll(entry.selector().criteria())) {
dfs(entry);
if (!"Black Hole".equals(label.get(entry))) {
// this entry is "live" i.e not a black hole
pointsToLiveEntry = true;
}
}
}
return pointsToLiveEntry;
}
use of org.onosproject.net.Link in project onos by opennetworkinglab.
the class MockLinkService method addLink.
public void addLink(String device, long port, String device2, long port2) {
ElementId d1;
if (device.charAt(0) == 'H') {
device = device.substring(1, device.length());
d1 = HostId.hostId(device);
} else {
d1 = DeviceId.deviceId(device);
}
ElementId d2;
if (device2.charAt(0) == 'H') {
d2 = HostId.hostId(device2.substring(1, device2.length()));
} else {
d2 = DeviceId.deviceId(device2);
}
ConnectPoint src = new ConnectPoint(d1, PortNumber.portNumber(port));
ConnectPoint dst = new ConnectPoint(d2, PortNumber.portNumber(port2));
Link curLink;
curLink = DefaultLink.builder().src(src).dst(dst).state(ACTIVE).build();
links.add(curLink);
if (d1 instanceof DeviceId && d2 instanceof DeviceId) {
TopologyVertex v1 = () -> (DeviceId) d1, v2 = () -> (DeviceId) d2;
createdGraph.addVertex(v1);
createdGraph.addVertex(v2);
createdGraph.addEdge(new TopologyEdge() {
@Override
public Link link() {
return curLink;
}
@Override
public TopologyVertex src() {
return v1;
}
@Override
public TopologyVertex dst() {
return v2;
}
});
}
}
use of org.onosproject.net.Link in project onos by opennetworkinglab.
the class ReactiveForwarding method backTrackBadNodes.
// Backtracks from link down event to remove flows that lead to blackhole
private void backTrackBadNodes(Set<Path> shortestPaths, DeviceId dstId, SrcDstPair sd) {
for (Path p : shortestPaths) {
List<Link> pathLinks = p.links();
for (int i = 0; i < pathLinks.size(); i = i + 1) {
Link curLink = pathLinks.get(i);
DeviceId curDevice = curLink.src().deviceId();
// skipping the first link because this link's src has already been pruned beforehand
if (i != 0) {
cleanFlowRules(sd, curDevice);
}
Set<Path> pathsFromCurDevice = topologyService.getPaths(topologyService.currentTopology(), curDevice, dstId);
if (pickForwardPathIfPossible(pathsFromCurDevice, curLink.src().port()) != null) {
break;
} else {
if (i + 1 == pathLinks.size()) {
cleanFlowRules(sd, curLink.dst().deviceId());
}
}
}
}
}
Aggregations