Search in sources :

Example 46 with Key

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

the class IntentsDiagnosisCommand method checkP2PFlowRuleIntent.

private void checkP2PFlowRuleIntent(PointToPointIntent intent, FlowRuleIntent installable, ServiceRefs svcRefs) {
    final Map<DeviceId, DeviceOnIntent> devs = createDevicesOnP2PIntent(intent, installable);
    boolean errorOccurred = false;
    // checking the number of links & CPs in P2P intent
    for (DeviceOnIntent dev : devs.values()) {
        if (dev.getIngressLinks().size() > 1) {
            error("MULTIPLE NUMBER OF INGRESS LINKs on " + dev.deviceId() + ": " + dev.getIngressLinks());
            errorOccurred = true;
        }
        if (dev.getIngressCps().size() > 1) {
            error("MULTIPLE NUMBER OF INGRESS CONNECT POINTs on " + dev.deviceId() + ": " + dev.getIngressCps());
            errorOccurred = true;
        }
        if (dev.getEgressLinks().size() > 1) {
            error("MULTIPLE NUMBER OF EGRESS LINKs: on " + dev.deviceId() + ": " + dev.getEgressLinks());
            errorOccurred = true;
        }
        if (dev.getEgressCps().size() > 1) {
            error("MULTIPLE NUMBER OF EGRESS CONNECT POINTs: on " + dev.deviceId() + ": " + dev.getEgressCps());
            errorOccurred = true;
        }
    }
    ConnectPoint startCp = intent.filteredIngressPoint().connectPoint();
    DeviceOnIntent startDev = devs.get(startCp.deviceId());
    if (startDev == null) {
        error("STARTING CONNECT POINT DEVICE: " + startCp.deviceId() + " is not on intent");
        errorOccurred = true;
    }
    ConnectPoint endCp = intent.filteredEgressPoint().connectPoint();
    DeviceOnIntent endDev = devs.get(endCp.deviceId());
    if (endDev == null) {
        error("END CONNECT POINT DEVICE: " + endCp.deviceId() + " is not on intent");
        errorOccurred = true;
    }
    if (!errorOccurred) {
        // Per device checking with path-order
        DeviceOnIntent dev = startDev;
        int i = 0;
        for (; i < MAX_INTENT_PATH; i++) {
            perDeviceChecking(dev, svcRefs);
            // P2P intent has only 1 egress CP
            ConnectPoint egressCp = dev.getEgressCps().stream().findFirst().orElse(null);
            if (egressCp != null && Objects.equals(endCp, egressCp)) {
                break;
            }
            // P2P intent has only 1 egress link
            Link egressLink = dev.getEgressLinks().stream().findFirst().orElse(null);
            if (egressLink == null) {
                error("INVALID EGRESS LINK & CONNECT POINT for: " + dev);
                errorOccurred = true;
                break;
            }
            if (Objects.equals(egressLink.dst(), endCp)) {
                break;
            }
            // P2P intent only 1 ingress link
            dev = devs.values().stream().filter(nextDev -> Objects.equals(egressLink, nextDev.getIngressLinks().stream().findFirst().orElse(null))).findAny().orElse(null);
            if (dev == null) {
                error("FAILED TO FIND NEXT DEV for: " + dev + ", LINK: " + egressLink);
                errorOccurred = true;
                break;
            }
        }
        if (i == MAX_INTENT_PATH) {
            error("MAX INTENT PATH WAS EXCEEDED");
            errorOccurred = true;
        }
    }
    if (errorOccurred) {
        // Installable checking
        dump("");
        dump("ERROR OCCURRED. DO PER FLOW CHECKING");
        perFlowRuleChecking(installable, svcRefs);
    }
    if (svcRefs.workPartitionService.isMine(intent.key(), Key::hash)) {
        checkIntentsByLink(installable, svcRefs);
    }
}
Also used : PortStatistics(org.onosproject.net.device.PortStatistics) DeviceService(org.onosproject.net.device.DeviceService) FlowEntry(org.onosproject.net.flow.FlowEntry) HashMap(java.util.HashMap) DefaultDevice(org.onosproject.net.DefaultDevice) AnnotationKeys(org.onosproject.net.AnnotationKeys) Link(org.onosproject.net.Link) Command(org.apache.karaf.shell.api.action.Command) ConnectPoint(org.onosproject.net.ConnectPoint) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) FlowRuleService(org.onosproject.net.flow.FlowRuleService) IntentService(org.onosproject.net.intent.IntentService) Port(org.onosproject.net.Port) Map(java.util.Map) Intent(org.onosproject.net.intent.Intent) WorkPartitionService(org.onosproject.net.intent.WorkPartitionService) LinkKey(org.onosproject.net.LinkKey) FlowRuleIntent(org.onosproject.net.intent.FlowRuleIntent) ImmutableSet(com.google.common.collect.ImmutableSet) Device(org.onosproject.net.Device) Collection(java.util.Collection) MoreObjects(com.google.common.base.MoreObjects) Set(java.util.Set) Argument(org.apache.karaf.shell.api.action.Argument) Streams(com.google.common.collect.Streams) Field(java.lang.reflect.Field) SetMultimap(com.google.common.collect.SetMultimap) FlowStatisticService(org.onosproject.net.statistic.FlowStatisticService) ObjectiveTrackerService(org.onosproject.net.intent.ObjectiveTrackerService) Objects(java.util.Objects) AbstractShellCommand(org.onosproject.cli.AbstractShellCommand) Key(org.onosproject.net.intent.Key) List(java.util.List) Stream(java.util.stream.Stream) PointToPointIntent(org.onosproject.net.intent.PointToPointIntent) FlowRule(org.onosproject.net.flow.FlowRule) Service(org.apache.karaf.shell.api.action.lifecycle.Service) Completion(org.apache.karaf.shell.api.action.Completion) Option(org.apache.karaf.shell.api.action.Option) DeviceId(org.onosproject.net.DeviceId) DeviceId(org.onosproject.net.DeviceId) ConnectPoint(org.onosproject.net.ConnectPoint) ConnectPoint(org.onosproject.net.ConnectPoint) Link(org.onosproject.net.Link) LinkKey(org.onosproject.net.LinkKey) Key(org.onosproject.net.intent.Key)

Example 47 with Key

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

the class IntentCleanup method event.

@Override
public void event(IntentEvent event) {
    // TODO we might consider using the timer to back off for subsequent retries
    if (enabled && event.type() == IntentEvent.Type.CORRUPT) {
        Key key = event.subject().key();
        if (store.isMaster(key)) {
            IntentData data = store.getIntentData(event.subject().key());
            resubmitCorrupt(data, true);
        }
    }
}
Also used : IntentData(org.onosproject.net.intent.IntentData) Key(org.onosproject.net.intent.Key)

Example 48 with Key

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

the class ObjectiveTracker method trackIntent.

@Override
public void trackIntent(IntentData intentData) {
    // NOTE: This will be called for intents that are being added to the store
    // locally (i.e. every intent update)
    Key key = intentData.key();
    Intent intent = intentData.intent();
    boolean isLocal = intentService.isLocal(key);
    boolean isInstalled = intentData.state() == INSTALLING || intentData.state() == INSTALLED;
    List<Intent> installables = intentData.installables();
    if (log.isTraceEnabled()) {
        log.trace("intent {}, old: {}, new: {}, installableCount: {}, resourceCount: {}", key, intentsByDevice.values().contains(key), isLocal && isInstalled, installables.size(), intent.resources().size() + installables.stream().mapToLong(i -> i.resources().size()).sum());
    }
    if (isNullOrEmpty(installables) && intentData.state() == INSTALLED) {
        log.warn("Intent {} is INSTALLED with no installables", key);
    }
    // then when installing and when installed)
    if (isLocal && isInstalled) {
        addTrackedResources(key, intent.resources());
        for (Intent installable : installables) {
            addTrackedResources(key, installable.resources());
        }
    // FIXME check all resources against current topo service(s); recompile if necessary
    } else {
        removeTrackedResources(key, intent.resources());
        for (Intent installable : installables) {
            removeTrackedResources(key, installable.resources());
        }
    }
}
Also used : TopologyChangeDelegate(org.onosproject.net.intent.TopologyChangeDelegate) PortNumber(org.onosproject.net.PortNumber) DeviceService(org.onosproject.net.device.DeviceService) Tools.groupedThreads(org.onlab.util.Tools.groupedThreads) ElementId(org.onosproject.net.ElementId) TopologyService(org.onosproject.net.topology.TopologyService) Link(org.onosproject.net.Link) ResourceService(org.onosproject.net.resource.ResourceService) Tools.isNullOrEmpty(org.onlab.util.Tools.isNullOrEmpty) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) LINK_REMOVED(org.onosproject.net.link.LinkEvent.Type.LINK_REMOVED) HashMultimap(com.google.common.collect.HashMultimap) Executors.newScheduledThreadPool(java.util.concurrent.Executors.newScheduledThreadPool) INSTALLING(org.onosproject.net.intent.IntentState.INSTALLING) WorkPartitionService(org.onosproject.net.intent.WorkPartitionService) Event(org.onosproject.event.Event) LinkKey(org.onosproject.net.LinkKey) TopologyEvent(org.onosproject.net.topology.TopologyEvent) ImmutableSet(com.google.common.collect.ImmutableSet) Deactivate(org.osgi.service.component.annotations.Deactivate) Collection(java.util.Collection) Set(java.util.Set) NetworkResource(org.onosproject.net.NetworkResource) Executors.newSingleThreadExecutor(java.util.concurrent.Executors.newSingleThreadExecutor) ReferencePolicy(org.osgi.service.component.annotations.ReferencePolicy) INSTALLED(org.onosproject.net.intent.IntentState.INSTALLED) Key(org.onosproject.net.intent.Key) List(java.util.List) DeviceEvent(org.onosproject.net.device.DeviceEvent) DeviceId(org.onosproject.net.DeviceId) LinkEvent(org.onosproject.net.link.LinkEvent) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) WorkPartitionEvent(org.onosproject.net.intent.WorkPartitionEvent) HostListener(org.onosproject.net.host.HostListener) HostService(org.onosproject.net.host.HostService) IntentData(org.onosproject.net.intent.IntentData) HashSet(java.util.HashSet) Component(org.osgi.service.component.annotations.Component) IntentService(org.onosproject.net.intent.IntentService) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) Intent(org.onosproject.net.intent.Intent) HostEvent(org.onosproject.net.host.HostEvent) Activate(org.osgi.service.component.annotations.Activate) LinkKey.linkKey(org.onosproject.net.LinkKey.linkKey) HostId(org.onosproject.net.HostId) ExecutorService(java.util.concurrent.ExecutorService) Multimaps.synchronizedSetMultimap(com.google.common.collect.Multimaps.synchronizedSetMultimap) LINK_UPDATED(org.onosproject.net.link.LinkEvent.Type.LINK_UPDATED) DeviceListener(org.onosproject.net.device.DeviceListener) Logger(org.slf4j.Logger) ResourceEvent(org.onosproject.net.resource.ResourceEvent) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) SetMultimap(com.google.common.collect.SetMultimap) ObjectiveTrackerService(org.onosproject.net.intent.ObjectiveTrackerService) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) TimeUnit(java.util.concurrent.TimeUnit) ResourceListener(org.onosproject.net.resource.ResourceListener) WorkPartitionEventListener(org.onosproject.net.intent.WorkPartitionEventListener) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) Reference(org.osgi.service.component.annotations.Reference) Collections(java.util.Collections) TopologyListener(org.onosproject.net.topology.TopologyListener) Intent(org.onosproject.net.intent.Intent) LinkKey(org.onosproject.net.LinkKey) Key(org.onosproject.net.intent.Key) LinkKey.linkKey(org.onosproject.net.LinkKey.linkKey)

Example 49 with Key

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

the class PointToPointIntentCompilerTest method testKeyRGBandwidthConstrainedIntentAllocation.

/**
 * Tests if bandwidth resources get allocated correctly using groups.
 * An intent asks to allocate bandwidth using the intent key as a reference.
 * Then, the intent is submitted with the same key and a group set.
 * Previous allocations should be released and new resources should be
 * allocated using the group.
 */
@Test
public void testKeyRGBandwidthConstrainedIntentAllocation() {
    final double bpsTotal = 1000.0;
    String[] hops = { S1, S2, S3 };
    final ResourceService resourceService = MockResourceService.makeCustomBandwidthResourceService(bpsTotal);
    final List<Constraint> constraints = Collections.singletonList(new BandwidthConstraint(Bandwidth.bps(BPS_TO_RESERVE)));
    final PointToPointIntent intent = makeIntent(new ConnectPoint(DID_1, PORT_1), new ConnectPoint(DID_3, PORT_2), constraints);
    PointToPointIntentCompiler compiler = makeCompiler(hops, resourceService);
    compiler.compile(intent, null);
    Key intentKey = intent.key();
    ResourceGroup resourceGroup = ResourceGroup.of(100);
    final PointToPointIntent newIntent = makeIntent(intentKey, new ConnectPoint(DID_1, PORT_1), new ConnectPoint(DID_3, PORT_2), constraints, resourceGroup);
    compiler.compile(newIntent, null);
    ResourceAllocation rAOne = new ResourceAllocation(RESOURCE_SW1_P1, resourceGroup);
    ResourceAllocation rATwo = new ResourceAllocation(RESOURCE_SW1_P2, resourceGroup);
    ResourceAllocation rAThree = new ResourceAllocation(RESOURCE_SW2_P1, resourceGroup);
    ResourceAllocation rAFour = new ResourceAllocation(RESOURCE_SW2_P2, resourceGroup);
    ResourceAllocation rAFive = new ResourceAllocation(RESOURCE_SW3_P1, resourceGroup);
    ResourceAllocation rASix = new ResourceAllocation(RESOURCE_SW3_P2, resourceGroup);
    Set<ResourceAllocation> expectedresourceAllocations = ImmutableSet.of(rAOne, rATwo, rAThree, rAFour, rAFive, rASix);
    Set<ResourceAllocation> resourceAllocations = ImmutableSet.copyOf(resourceService.getResourceAllocations(resourceGroup));
    assertThat(resourceAllocations, hasSize(6));
    assertEquals(expectedresourceAllocations, resourceAllocations);
}
Also used : Constraint(org.onosproject.net.intent.Constraint) BandwidthConstraint(org.onosproject.net.intent.constraint.BandwidthConstraint) ResourceService(org.onosproject.net.resource.ResourceService) MockResourceService(org.onosproject.net.resource.MockResourceService) PointToPointIntent(org.onosproject.net.intent.PointToPointIntent) ConnectPoint(org.onosproject.net.ConnectPoint) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint) ResourceAllocation(org.onosproject.net.resource.ResourceAllocation) Key(org.onosproject.net.intent.Key) ResourceGroup(org.onosproject.net.ResourceGroup) BandwidthConstraint(org.onosproject.net.intent.constraint.BandwidthConstraint) Test(org.junit.Test) AbstractIntentTest(org.onosproject.net.intent.AbstractIntentTest)

Example 50 with Key

use of org.onosproject.net.intent.Key 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)

Aggregations

Key (org.onosproject.net.intent.Key)65 FilteredConnectPoint (org.onosproject.net.FilteredConnectPoint)25 Intent (org.onosproject.net.intent.Intent)22 ConnectPoint (org.onosproject.net.ConnectPoint)20 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)19 TrafficSelector (org.onosproject.net.flow.TrafficSelector)19 MultiPointToSinglePointIntent (org.onosproject.net.intent.MultiPointToSinglePointIntent)19 Test (org.junit.Test)15 Constraint (org.onosproject.net.intent.Constraint)15 PointToPointIntent (org.onosproject.net.intent.PointToPointIntent)14 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)12 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)12 SinglePointToMultiPointIntent (org.onosproject.net.intent.SinglePointToMultiPointIntent)12 ApplicationId (org.onosproject.core.ApplicationId)11 IntentService (org.onosproject.net.intent.IntentService)11 ArrayList (java.util.ArrayList)9 HashSet (java.util.HashSet)9 Interface (org.onosproject.net.intf.Interface)9 Set (java.util.Set)8 MacAddress (org.onlab.packet.MacAddress)8