Search in sources :

Example 21 with EncapsulationConstraint

use of org.onosproject.net.intent.constraint.EncapsulationConstraint in project onos by opennetworkinglab.

the class PathIntentCompilerTest method testVlanEncapCompileSingleHopDirectVlan.

/**
 * Tests the compilation behavior of the path intent compiler in case of
 * VLAN {@link EncapsulationType} encapsulation constraint {@link EncapsulationConstraint}
 * and single-hop-direct-link scenario. Ingress VLAN. Egress VLAN.
 */
@Test
public void testVlanEncapCompileSingleHopDirectVlan() {
    sut.activate();
    List<Intent> compiled = sut.compile(singleHopDirectIntentVlan, Collections.emptyList());
    assertThat(compiled, hasSize(1));
    Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules();
    assertThat(rules, hasSize(1));
    FlowRule rule = rules.stream().filter(x -> x.deviceId().equals(d2p4.deviceId())).findFirst().get();
    verifyIdAndPriority(rule, d2p4.deviceId());
    assertThat(rule.selector(), is(DefaultTrafficSelector.builder().matchInPort(d2p4.port()).matchVlanId(ingressVlan).build()));
    assertThat(rule.treatment(), is(DefaultTrafficTreatment.builder().setVlanId(egressVlan).setOutput(d2p5.port()).build()));
    Set<L2ModificationInstruction.ModVlanIdInstruction> vlanMod = rule.treatment().allInstructions().stream().filter(treat -> treat instanceof L2ModificationInstruction.ModVlanIdInstruction).map(x -> (L2ModificationInstruction.ModVlanIdInstruction) x).collect(Collectors.toSet());
    assertThat(rule.treatment().allInstructions().stream().filter(treat -> treat instanceof L2ModificationInstruction.ModVlanIdInstruction).collect(Collectors.toSet()), hasSize(1));
    assertThat(vlanMod.iterator().next().vlanId(), is(egressVlan));
    assertThat(rule.treatment().allInstructions().stream().filter(treat -> treat instanceof L2ModificationInstruction.ModVlanHeaderInstruction).collect(Collectors.toSet()), hasSize(0));
    sut.deactivate();
}
Also used : DIRECT(org.onosproject.net.Link.Type.DIRECT) Arrays(java.util.Arrays) DefaultEdgeLink.createEdgeLink(org.onosproject.net.DefaultEdgeLink.createEdgeLink) TestApplicationId(org.onosproject.TestApplicationId) CoreService(org.onosproject.core.CoreService) Link(org.onosproject.net.Link) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) ConnectPoint(org.onosproject.net.ConnectPoint) EncapsulationConstraint(org.onosproject.net.intent.constraint.EncapsulationConstraint) Ethernet(org.onlab.packet.Ethernet) TrafficSelector(org.onosproject.net.flow.TrafficSelector) ImmutableList(com.google.common.collect.ImmutableList) INDIRECT(org.onosproject.net.Link.Type.INDIRECT) ComponentConfigAdapter(org.onosproject.cfg.ComponentConfigAdapter) ApplicationId(org.onosproject.core.ApplicationId) DefaultPath(org.onosproject.net.DefaultPath) L2ModificationInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction) Intent(org.onosproject.net.intent.Intent) OrderingComparison.greaterThan(org.hamcrest.number.OrderingComparison.greaterThan) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) MockResourceService(org.onosproject.net.resource.MockResourceService) Before(org.junit.Before) DefaultLink(org.onosproject.net.DefaultLink) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) PathIntent(org.onosproject.net.intent.PathIntent) Instructions(org.onosproject.net.flow.instructions.Instructions) FlowRuleIntent(org.onosproject.net.intent.FlowRuleIntent) MplsLabel(org.onlab.packet.MplsLabel) IntentExtensionService(org.onosproject.net.intent.IntentExtensionService) Collection(java.util.Collection) VlanId(org.onlab.packet.VlanId) Set(java.util.Set) Matchers(org.hamcrest.Matchers) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) ProviderId(org.onosproject.net.provider.ProviderId) EasyMock(org.easymock.EasyMock) AbstractIntentTest(org.onosproject.net.intent.AbstractIntentTest) Collectors(java.util.stream.Collectors) List(java.util.List) EncapsulationType(org.onosproject.net.EncapsulationType) NetTestTools(org.onosproject.net.NetTestTools) FlowRule(org.onosproject.net.flow.FlowRule) ScalarWeight(org.onlab.graph.ScalarWeight) DeviceId(org.onosproject.net.DeviceId) Collections(java.util.Collections) Intent(org.onosproject.net.intent.Intent) PathIntent(org.onosproject.net.intent.PathIntent) FlowRuleIntent(org.onosproject.net.intent.FlowRuleIntent) L2ModificationInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction) FlowRule(org.onosproject.net.flow.FlowRule) FlowRuleIntent(org.onosproject.net.intent.FlowRuleIntent) Test(org.junit.Test) AbstractIntentTest(org.onosproject.net.intent.AbstractIntentTest)

Example 22 with EncapsulationConstraint

use of org.onosproject.net.intent.constraint.EncapsulationConstraint in project onos by opennetworkinglab.

the class VirtualNetworkIntentManagerTest method testCreateAndRemoveIntent.

/**
 * Tests the submit(), withdraw(), and purge() methods.
 */
@Test
public void testCreateAndRemoveIntent() {
    VirtualNetwork virtualNetwork = setupVirtualNetworkTopology();
    Key intentKey = Key.of("test", APP_ID);
    List<Constraint> constraints = new ArrayList<>();
    constraints.add(new EncapsulationConstraint(EncapsulationType.VLAN));
    VirtualNetworkIntent virtualIntent = VirtualNetworkIntent.builder().networkId(virtualNetwork.id()).key(intentKey).appId(APP_ID).ingressPoint(cp1).egressPoint(cp5).constraints(constraints).build();
    // Test the submit() method.
    vnetIntentService.submit(virtualIntent);
    // Wait for the both intents to go into an INSTALLED state.
    try {
        if (!created.tryAcquire(MAX_PERMITS, MAX_WAIT_TIME, TimeUnit.SECONDS)) {
            fail("Failed to wait for intent to get installed.");
        }
    } catch (InterruptedException e) {
        fail("Semaphore exception during intent installation." + e.getMessage());
    }
    // Test the getIntentState() method
    assertEquals("The intent state did not match as expected.", IntentState.INSTALLED, vnetIntentService.getIntentState(virtualIntent.key()));
    // Test the withdraw() method.
    vnetIntentService.withdraw(virtualIntent);
    // Wait for the both intents to go into a WITHDRAWN state.
    try {
        if (!withdrawn.tryAcquire(MAX_PERMITS, MAX_WAIT_TIME, TimeUnit.SECONDS)) {
            fail("Failed to wait for intent to get withdrawn.");
        }
    } catch (InterruptedException e) {
        fail("Semaphore exception during intent withdrawal." + e.getMessage());
    }
    // Test the getIntentState() method
    assertEquals("The intent state did not match as expected.", IntentState.WITHDRAWN, vnetIntentService.getIntentState(virtualIntent.key()));
    // Test the purge() method.
    vnetIntentService.purge(virtualIntent);
    // Wait for the both intents to be removed/purged.
    try {
        if (!purged.tryAcquire(MAX_PERMITS, MAX_WAIT_TIME, TimeUnit.SECONDS)) {
            fail("Failed to wait for intent to get purged.");
        }
    } catch (InterruptedException e) {
        fail("Semaphore exception during intent purging." + e.getMessage());
    }
}
Also used : VirtualNetwork(org.onosproject.incubator.net.virtual.VirtualNetwork) EncapsulationConstraint(org.onosproject.net.intent.constraint.EncapsulationConstraint) Constraint(org.onosproject.net.intent.Constraint) EncapsulationConstraint(org.onosproject.net.intent.constraint.EncapsulationConstraint) ArrayList(java.util.ArrayList) VirtualNetworkIntent(org.onosproject.incubator.net.virtual.VirtualNetworkIntent) Key(org.onosproject.net.intent.Key) Test(org.junit.Test)

Example 23 with EncapsulationConstraint

use of org.onosproject.net.intent.constraint.EncapsulationConstraint in project onos by opennetworkinglab.

the class ConnectivityIntentCommand method buildConstraints.

/**
 * Builds the constraint list for this command based on the command line
 * parameters.
 *
 * @return List of constraint objects describing the constraints requested
 */
protected List<Constraint> buildConstraints() {
    final List<Constraint> constraints = new LinkedList<>();
    // Check for a bandwidth specification
    if (!isNullOrEmpty(bandwidthString)) {
        Bandwidth bandwidth;
        try {
            bandwidth = Bandwidth.bps(Long.parseLong(bandwidthString));
        // when the string can't be parsed as long, then try to parse as double
        } catch (NumberFormatException e) {
            bandwidth = Bandwidth.bps(Double.parseDouble(bandwidthString));
        }
        constraints.add(new BandwidthConstraint(bandwidth));
    }
    // Check for partial failure specification
    if (partial) {
        constraints.add(new PartialFailureConstraint());
    }
    // Check for encapsulation specification
    if (!isNullOrEmpty(encapsulationString)) {
        final EncapsulationType encapType = EncapsulationType.valueOf(encapsulationString);
        constraints.add(new EncapsulationConstraint(encapType));
    }
    // Check for hashed path selection
    if (hashedPathSelection) {
        constraints.add(new HashedPathSelectionConstraint());
    }
    // Check for domain processing
    if (domains) {
        constraints.add(DomainConstraint.domain());
    }
    // Check for a latency specification
    if (!isNullOrEmpty(latConstraint)) {
        try {
            long lat = Long.parseLong(latConstraint);
            constraints.add(new LatencyConstraint(Duration.of(lat, ChronoUnit.NANOS)));
        } catch (NumberFormatException e) {
            double lat = Double.parseDouble(latConstraint);
            constraints.add(new LatencyConstraint(Duration.of((long) lat, ChronoUnit.NANOS)));
        }
    }
    return constraints;
}
Also used : EncapsulationConstraint(org.onosproject.net.intent.constraint.EncapsulationConstraint) PartialFailureConstraint(org.onosproject.net.intent.constraint.PartialFailureConstraint) EncapsulationType(org.onosproject.net.EncapsulationType) HashedPathSelectionConstraint(org.onosproject.net.intent.constraint.HashedPathSelectionConstraint) DomainConstraint(org.onosproject.net.intent.constraint.DomainConstraint) EncapsulationConstraint(org.onosproject.net.intent.constraint.EncapsulationConstraint) PartialFailureConstraint(org.onosproject.net.intent.constraint.PartialFailureConstraint) Constraint(org.onosproject.net.intent.Constraint) BandwidthConstraint(org.onosproject.net.intent.constraint.BandwidthConstraint) LatencyConstraint(org.onosproject.net.intent.constraint.LatencyConstraint) HashedPathSelectionConstraint(org.onosproject.net.intent.constraint.HashedPathSelectionConstraint) Bandwidth(org.onlab.util.Bandwidth) LatencyConstraint(org.onosproject.net.intent.constraint.LatencyConstraint) LinkedList(java.util.LinkedList) BandwidthConstraint(org.onosproject.net.intent.constraint.BandwidthConstraint)

Example 24 with EncapsulationConstraint

use of org.onosproject.net.intent.constraint.EncapsulationConstraint in project onos by opennetworkinglab.

the class SdnIpFib method setEncap.

/**
 * Sets an encapsulation constraint to the intent builder given.
 *
 * @param builder the intent builder
 * @param constraints the existing intent constraints
 * @param encap the encapsulation type to be set
 */
private static void setEncap(ConnectivityIntent.Builder builder, List<Constraint> constraints, EncapsulationType encap) {
    // Constraints might be an immutable list, so a new modifiable list
    // is created
    List<Constraint> newConstraints = new ArrayList<>(constraints);
    // Remove any encapsulation constraint if already in the list
    constraints.stream().filter(c -> c instanceof EncapsulationConstraint).forEach(c -> newConstraints.remove(c));
    // constraint should be added to the list
    if (!encap.equals(NONE)) {
        newConstraints.add(new EncapsulationConstraint(encap));
    }
    // Submit new constraint list as immutable list
    builder.constraints(ImmutableList.copyOf(newConstraints));
}
Also used : NetworkConfigService(org.onosproject.net.config.NetworkConfigService) Interface(org.onosproject.net.intf.Interface) CoreService(org.onosproject.core.CoreService) NONE(org.onosproject.net.EncapsulationType.NONE) NetworkConfigEvent(org.onosproject.net.config.NetworkConfigEvent) LoggerFactory(org.slf4j.LoggerFactory) RouteEvent(org.onosproject.routeservice.RouteEvent) InterfaceService(org.onosproject.net.intf.InterfaceService) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) ConnectPoint(org.onosproject.net.ConnectPoint) EncapsulationConstraint(org.onosproject.net.intent.constraint.EncapsulationConstraint) ArrayList(java.util.ArrayList) Ethernet(org.onlab.packet.Ethernet) InterfaceListener(org.onosproject.net.intf.InterfaceListener) Component(org.osgi.service.component.annotations.Component) TrafficSelector(org.onosproject.net.flow.TrafficSelector) ImmutableList(com.google.common.collect.ImmutableList) MultiPointToSinglePointIntent(org.onosproject.net.intent.MultiPointToSinglePointIntent) Map(java.util.Map) ApplicationId(org.onosproject.core.ApplicationId) PartialFailureConstraint(org.onosproject.net.intent.constraint.PartialFailureConstraint) Activate(org.osgi.service.component.annotations.Activate) IntentSynchronizationService(org.onosproject.intentsync.IntentSynchronizationService) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) IpAddress(org.onlab.packet.IpAddress) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) RouteService(org.onosproject.routeservice.RouteService) SdnIpConfig(org.onosproject.sdnip.config.SdnIpConfig) Logger(org.slf4j.Logger) Deactivate(org.osgi.service.component.annotations.Deactivate) VlanId(org.onlab.packet.VlanId) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) InterfaceEvent(org.onosproject.net.intf.InterfaceEvent) Sets(com.google.common.collect.Sets) Constraint(org.onosproject.net.intent.Constraint) RouteListener(org.onosproject.routeservice.RouteListener) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) Key(org.onosproject.net.intent.Key) List(java.util.List) EncapsulationType(org.onosproject.net.EncapsulationType) ConnectivityIntent(org.onosproject.net.intent.ConnectivityIntent) MacAddress(org.onlab.packet.MacAddress) Reference(org.osgi.service.component.annotations.Reference) ResolvedRoute(org.onosproject.routeservice.ResolvedRoute) NetworkConfigListener(org.onosproject.net.config.NetworkConfigListener) IpPrefix(org.onlab.packet.IpPrefix) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint) EncapsulationConstraint(org.onosproject.net.intent.constraint.EncapsulationConstraint) EncapsulationConstraint(org.onosproject.net.intent.constraint.EncapsulationConstraint) PartialFailureConstraint(org.onosproject.net.intent.constraint.PartialFailureConstraint) Constraint(org.onosproject.net.intent.Constraint) ArrayList(java.util.ArrayList)

Aggregations

EncapsulationConstraint (org.onosproject.net.intent.constraint.EncapsulationConstraint)24 ConnectPoint (org.onosproject.net.ConnectPoint)16 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)16 TrafficSelector (org.onosproject.net.flow.TrafficSelector)16 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)16 ImmutableList (com.google.common.collect.ImmutableList)15 EncapsulationType (org.onosproject.net.EncapsulationType)15 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)15 Intent (org.onosproject.net.intent.Intent)15 List (java.util.List)14 Set (java.util.Set)14 VlanId (org.onlab.packet.VlanId)13 ApplicationId (org.onosproject.core.ApplicationId)13 CoreService (org.onosproject.core.CoreService)13 ArrayList (java.util.ArrayList)12 DeviceId (org.onosproject.net.DeviceId)12 Test (org.junit.Test)11 Ethernet (org.onlab.packet.Ethernet)11 Collectors (java.util.stream.Collectors)9 Collection (java.util.Collection)8