Search in sources :

Example 81 with Link

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));
}
Also used : NetworkResource(org.onosproject.net.NetworkResource) JsonObject(com.eclipsesource.json.JsonObject) FlowRuleIntent(org.onosproject.net.intent.FlowRuleIntent) HostToHostIntent(org.onosproject.net.intent.HostToHostIntent) ConnectivityIntent(org.onosproject.net.intent.ConnectivityIntent) Intent(org.onosproject.net.intent.Intent) PathIntent(org.onosproject.net.intent.PathIntent) PointToPointIntent(org.onosproject.net.intent.PointToPointIntent) MockIntent(org.onosproject.net.intent.IntentTestsMocks.MockIntent) WebTarget(javax.ws.rs.client.WebTarget) Link(org.onosproject.net.Link) DefaultLink(org.onosproject.net.DefaultLink) MockIntent(org.onosproject.net.intent.IntentTestsMocks.MockIntent) HashSet(java.util.HashSet) FlowRuleIntent(org.onosproject.net.intent.FlowRuleIntent) Test(org.junit.Test)

Example 82 with Link

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();
}
Also used : Load(org.onosproject.net.statistic.Load) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) StatisticService(org.onosproject.net.statistic.StatisticService) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) UriBuilder(javax.ws.rs.core.UriBuilder) ConnectPoint(org.onosproject.net.ConnectPoint) Link(org.onosproject.net.Link) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 83 with Link

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;
}
Also used : DeviceId(org.onosproject.net.DeviceId) Instructions(org.onosproject.net.flow.instructions.Instructions) PortCriterion(org.onosproject.net.flow.criteria.PortCriterion) HostId(org.onosproject.net.HostId) ConnectPoint(org.onosproject.net.ConnectPoint) PortCriterion(org.onosproject.net.flow.criteria.PortCriterion) Criterion(org.onosproject.net.flow.criteria.Criterion) PortNumber(org.onosproject.net.PortNumber) FlowEntry(org.onosproject.net.flow.FlowEntry) Link(org.onosproject.net.Link) HashSet(java.util.HashSet)

Example 84 with Link

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;
            }
        });
    }
}
Also used : TopologyVertex(org.onosproject.net.topology.TopologyVertex) DeviceId(org.onosproject.net.DeviceId) ConnectPoint(org.onosproject.net.ConnectPoint) TopologyEdge(org.onosproject.net.topology.TopologyEdge) ElementId(org.onosproject.net.ElementId) DefaultLink(org.onosproject.net.DefaultLink) Link(org.onosproject.net.Link)

Example 85 with Link

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());
                }
            }
        }
    }
}
Also used : Path(org.onosproject.net.Path) DeviceId(org.onosproject.net.DeviceId) Link(org.onosproject.net.Link) ConnectPoint(org.onosproject.net.ConnectPoint)

Aggregations

Link (org.onosproject.net.Link)172 ConnectPoint (org.onosproject.net.ConnectPoint)75 Test (org.junit.Test)66 DefaultLink (org.onosproject.net.DefaultLink)44 Intent (org.onosproject.net.intent.Intent)40 DeviceId (org.onosproject.net.DeviceId)39 TrafficSelector (org.onosproject.net.flow.TrafficSelector)27 FilteredConnectPoint (org.onosproject.net.FilteredConnectPoint)26 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)26 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)26 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)26 LinkCollectionIntent (org.onosproject.net.intent.LinkCollectionIntent)26 FlowRuleIntent (org.onosproject.net.intent.FlowRuleIntent)24 List (java.util.List)23 LinkKey (org.onosproject.net.LinkKey)23 Set (java.util.Set)22 DefaultPath (org.onosproject.net.DefaultPath)20 FlowRule (org.onosproject.net.flow.FlowRule)20 Collectors (java.util.stream.Collectors)19 PathIntent (org.onosproject.net.intent.PathIntent)18