Search in sources :

Example 1 with NetworkResource

use of org.onosproject.net.NetworkResource in project onos by opennetworkinglab.

the class ProtectedTransportIntentCompiler method createFreshProtectedPaths.

/**
 * Creates new protected paths.
 *
 * @param intent    original intention
 * @param did1      identifier of first device
 * @param did2      identifier of second device
 * @return compilation result
 * @throws IntentCompilationException when there's no satisfying path.
 */
private List<Intent> createFreshProtectedPaths(ProtectedTransportIntent intent, DeviceId did1, DeviceId did2) {
    DisjointPath disjointPath = getDisjointPath(intent, did1, did2);
    if (disjointPath == null || disjointPath.backup() == null) {
        log.error("Unable to find disjoint path between {}, {}", did1, did2);
        throw new IntentCompilationException("Unable to find disjoint paths.");
    }
    Path primary = disjointPath.primary();
    Path secondary = disjointPath.backup();
    String fingerprint = intent.key().toString();
    // pick and allocate Vlan to use as S-tag
    Pair<VlanId, VlanId> vlans = allocateEach(intent, primary, secondary, VlanId.class);
    VlanId primaryVlan = vlans.getLeft();
    VlanId secondaryVlan = vlans.getRight();
    // Build edge Intents for head/tail
    // resource for head/tail
    Collection<NetworkResource> oneResources = new ArrayList<>();
    Collection<NetworkResource> twoResources = new ArrayList<>();
    List<TransportEndpointDescription> onePaths = new ArrayList<>();
    onePaths.add(TransportEndpointDescription.builder().withOutput(vlanPort(primary.src(), primaryVlan)).build());
    onePaths.add(TransportEndpointDescription.builder().withOutput(vlanPort(secondary.src(), secondaryVlan)).build());
    List<TransportEndpointDescription> twoPaths = new ArrayList<>();
    twoPaths.add(TransportEndpointDescription.builder().withOutput(vlanPort(primary.dst(), primaryVlan)).build());
    twoPaths.add(TransportEndpointDescription.builder().withOutput(vlanPort(secondary.dst(), secondaryVlan)).build());
    ProtectionEndpointIntent oneIntent = ProtectionEndpointIntent.builder().key(intent.key()).appId(intent.appId()).priority(intent.priority()).resources(oneResources).deviceId(did1).description(buildDescription(onePaths, did2, fingerprint)).build();
    ProtectionEndpointIntent twoIntent = ProtectionEndpointIntent.builder().key(intent.key()).appId(intent.appId()).resources(twoResources).deviceId(did2).description(buildDescription(twoPaths, did1, fingerprint)).build();
    // Build transit intent for primary/secondary path
    Collection<NetworkResource> resources1 = ImmutableList.of(marker("protection1"));
    Collection<NetworkResource> resources2 = ImmutableList.of(marker("protection2"));
    ImmutableList<Intent> result = ImmutableList.<Intent>builder().addAll(createTransitIntent(intent, primary, primaryVlan, resources1)).addAll(createTransitIntent(intent, secondary, secondaryVlan, resources2)).add(oneIntent).add(twoIntent).build();
    log.trace("createFreshProtectedPaths result: {}", result);
    return result;
}
Also used : DefaultPath(org.onosproject.net.DefaultPath) Path(org.onosproject.net.Path) DisjointPath(org.onosproject.net.DisjointPath) ArrayList(java.util.ArrayList) ProtectionEndpointIntent(org.onosproject.net.intent.ProtectionEndpointIntent) ProtectedTransportIntent(org.onosproject.net.intent.ProtectedTransportIntent) Intent(org.onosproject.net.intent.Intent) LinkCollectionIntent(org.onosproject.net.intent.LinkCollectionIntent) ProtectionEndpointIntent(org.onosproject.net.intent.ProtectionEndpointIntent) NetworkResource(org.onosproject.net.NetworkResource) TransportEndpointDescription(org.onosproject.net.behaviour.protection.TransportEndpointDescription) IntentCompilationException(org.onosproject.net.intent.IntentCompilationException) DisjointPath(org.onosproject.net.DisjointPath) VlanId(org.onlab.packet.VlanId)

Example 2 with NetworkResource

use of org.onosproject.net.NetworkResource in project onos by opennetworkinglab.

the class FlowRuleIntentInstaller method createIngressToEgressDeviceList.

/**
 * Create a list of devices ordered from the ingress to the egress of a path.
 * @param resources the resources of the intent
 * @return a list of devices
 */
private List<DeviceId> createIngressToEgressDeviceList(Collection<NetworkResource> resources) {
    List<DeviceId> deviceIds = Lists.newArrayList();
    List<Link> links = Lists.newArrayList();
    for (NetworkResource resource : resources) {
        if (resource instanceof Link) {
            Link linkToAdd = (Link) resource;
            if (linkToAdd.type() != Link.Type.EDGE) {
                links.add(linkToAdd);
            }
        }
    }
    Collections.sort(links, LINK_COMPARATOR);
    int i = 0;
    for (Link orderedLink : links) {
        deviceIds.add(orderedLink.src().deviceId());
        if (i == resources.size() - 1) {
            deviceIds.add(orderedLink.dst().deviceId());
        }
        i++;
    }
    return deviceIds;
}
Also used : NetworkResource(org.onosproject.net.NetworkResource) DeviceId(org.onosproject.net.DeviceId) Link(org.onosproject.net.Link)

Example 3 with NetworkResource

use of org.onosproject.net.NetworkResource in project onos by opennetworkinglab.

the class ObjectiveTrackerTest method testEventLinkDownMatch.

/**
 * Tests an event for a link down where the link matches existing intents.
 *
 * @throws InterruptedException if the latch wait fails.
 */
@Test
public void testEventLinkDownMatch() throws Exception {
    final Link link = link("src", 1, "dst", 2);
    final LinkEvent linkEvent = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link);
    reasons.add(linkEvent);
    final TopologyEvent event = new TopologyEvent(TopologyEvent.Type.TOPOLOGY_CHANGED, topology, reasons);
    final Key key = Key.of(0x333L, APP_ID);
    Collection<NetworkResource> resources = ImmutableSet.of(link);
    tracker.addTrackedResources(key, resources);
    listener.event(event);
    assertThat(delegate.latch.await(WAIT_TIMEOUT_SECONDS, TimeUnit.SECONDS), is(true));
    assertThat(delegate.intentIdsFromEvent, hasSize(1));
    assertThat(delegate.compileAllFailedFromEvent, is(false));
    assertThat(delegate.intentIdsFromEvent.get(0).toString(), equalTo("0x333"));
}
Also used : NetworkResource(org.onosproject.net.NetworkResource) LinkEvent(org.onosproject.net.link.LinkEvent) TopologyEvent(org.onosproject.net.topology.TopologyEvent) Link(org.onosproject.net.Link) Key(org.onosproject.net.intent.Key) Test(org.junit.Test) AbstractIntentTest(org.onosproject.net.intent.AbstractIntentTest)

Example 4 with NetworkResource

use of org.onosproject.net.NetworkResource in project onos by opennetworkinglab.

the class FlowObjectiveIntentInstallerTest method createFlowObjectiveIntents.

/**
 * Creates flow objective Intents.
 *
 * @return the flow objective intents
 */
private List<Intent> createFlowObjectiveIntents() {
    TrafficSelector selector = DefaultTrafficSelector.builder().matchInPort(CP1.port()).build();
    TrafficTreatment treatment = DefaultTrafficTreatment.builder().setOutput(CP2.port()).build();
    FilteringObjective filt = DefaultFilteringObjective.builder().addCondition(selector.getCriterion(Criterion.Type.IN_PORT)).withPriority(DEFAULT_PRIORITY).fromApp(APP_ID).permit().add();
    NextObjective next = DefaultNextObjective.builder().withMeta(selector).addTreatment(treatment).makePermanent().withPriority(DEFAULT_PRIORITY).fromApp(APP_ID).withType(NextObjective.Type.SIMPLE).withId(NEXT_ID_1).add();
    ForwardingObjective fwd = DefaultForwardingObjective.builder().withSelector(selector).fromApp(APP_ID).withPriority(DEFAULT_PRIORITY).makePermanent().withFlag(ForwardingObjective.Flag.SPECIFIC).nextStep(NEXT_ID_1).add();
    List<Objective> objectives = ImmutableList.of(filt, next, fwd);
    List<DeviceId> deviceIds = ImmutableList.of(CP1.deviceId(), CP1.deviceId(), CP1.deviceId());
    List<NetworkResource> resources = ImmutableList.of(CP1.deviceId());
    Intent intent = new FlowObjectiveIntent(APP_ID, KEY1, deviceIds, objectives, resources, RG1);
    return ImmutableList.of(intent);
}
Also used : DefaultNextObjective(org.onosproject.net.flowobjective.DefaultNextObjective) NextObjective(org.onosproject.net.flowobjective.NextObjective) DeviceId(org.onosproject.net.DeviceId) FlowObjectiveIntent(org.onosproject.net.intent.FlowObjectiveIntent) Intent(org.onosproject.net.intent.Intent) ForwardingObjective(org.onosproject.net.flowobjective.ForwardingObjective) DefaultForwardingObjective(org.onosproject.net.flowobjective.DefaultForwardingObjective) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) FlowObjectiveIntent(org.onosproject.net.intent.FlowObjectiveIntent) NetworkResource(org.onosproject.net.NetworkResource) DefaultNextObjective(org.onosproject.net.flowobjective.DefaultNextObjective) ForwardingObjective(org.onosproject.net.flowobjective.ForwardingObjective) NextObjective(org.onosproject.net.flowobjective.NextObjective) DefaultFilteringObjective(org.onosproject.net.flowobjective.DefaultFilteringObjective) FilteringObjective(org.onosproject.net.flowobjective.FilteringObjective) DefaultForwardingObjective(org.onosproject.net.flowobjective.DefaultForwardingObjective) Objective(org.onosproject.net.flowobjective.Objective) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) DefaultFilteringObjective(org.onosproject.net.flowobjective.DefaultFilteringObjective) FilteringObjective(org.onosproject.net.flowobjective.FilteringObjective)

Example 5 with NetworkResource

use of org.onosproject.net.NetworkResource in project onos by opennetworkinglab.

the class FlowRuleIntentInstallerTest method createFlowRuleIntentsNonDisruptive.

/**
 * Generates FlowRuleIntents for testing non-disruptive reallocation.
 *
 * @return the FlowRuleIntents for test
 */
public List<Intent> createFlowRuleIntentsNonDisruptive() {
    Map<ConnectPoint, ConnectPoint> portsAssociation = Maps.newHashMap();
    portsAssociation.put(CP1, CP2);
    portsAssociation.put(CP2_1, CP2_2);
    portsAssociation.put(CP4_2, CP4_1);
    List<FlowRule> flowRules = Lists.newArrayList();
    for (ConnectPoint srcPoint : portsAssociation.keySet()) {
        TrafficSelector selector = DefaultTrafficSelector.builder().matchInPhyPort(srcPoint.port()).build();
        TrafficTreatment treatment = DefaultTrafficTreatment.builder().setOutput(portsAssociation.get(srcPoint).port()).build();
        FlowRule flowRule = DefaultFlowRule.builder().forDevice(srcPoint.deviceId()).withSelector(selector).withTreatment(treatment).fromApp(APP_ID).withPriority(DEFAULT_PRIORITY).makePermanent().build();
        flowRules.add(flowRule);
    }
    List<NetworkResource> resources = ImmutableList.of(S1_S2, S2_S4);
    FlowRuleIntent intent = new FlowRuleIntent(APP_ID, KEY1, flowRules, resources, PathIntent.ProtectionType.PRIMARY, RG1);
    List<Intent> flowRuleIntents = Lists.newArrayList();
    flowRuleIntents.add(intent);
    return flowRuleIntents;
}
Also used : NetworkResource(org.onosproject.net.NetworkResource) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) Intent(org.onosproject.net.intent.Intent) PathIntent(org.onosproject.net.intent.PathIntent) FlowRuleIntent(org.onosproject.net.intent.FlowRuleIntent) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) FlowRule(org.onosproject.net.flow.FlowRule) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) ConnectPoint(org.onosproject.net.ConnectPoint) FlowRuleIntent(org.onosproject.net.intent.FlowRuleIntent)

Aggregations

NetworkResource (org.onosproject.net.NetworkResource)21 Intent (org.onosproject.net.intent.Intent)14 Test (org.junit.Test)11 FlowRuleIntent (org.onosproject.net.intent.FlowRuleIntent)11 PathIntent (org.onosproject.net.intent.PathIntent)11 WebTarget (javax.ws.rs.client.WebTarget)8 HostToHostIntent (org.onosproject.net.intent.HostToHostIntent)8 PointToPointIntent (org.onosproject.net.intent.PointToPointIntent)8 JsonObject (com.eclipsesource.json.JsonObject)7 HashSet (java.util.HashSet)7 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)7 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)7 TrafficSelector (org.onosproject.net.flow.TrafficSelector)7 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)7 ConnectivityIntent (org.onosproject.net.intent.ConnectivityIntent)7 FlowRule (org.onosproject.net.flow.FlowRule)6 MockIntent (org.onosproject.net.intent.IntentTestsMocks.MockIntent)6 DefaultFlowRule (org.onosproject.net.flow.DefaultFlowRule)5 JsonArray (com.eclipsesource.json.JsonArray)3 ConnectPoint (org.onosproject.net.ConnectPoint)3