Search in sources :

Example 16 with Bandwidth

use of org.onlab.util.Bandwidth 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 17 with Bandwidth

use of org.onlab.util.Bandwidth in project onos by opennetworkinglab.

the class LinkPropsTopovMessageHandler method getBandwidth.

/**
 * Gets the links connected to the highlighted device.
 * Creates a ContinuousResource object for each link
 * and gets the bandwidth of the link from the query
 * and sets the label of the link as the bandwidth value.
 */
private Highlights getBandwidth(Set<Link> links, DeviceId devId) {
    LpLinkMap linkMap = new LpLinkMap();
    Highlights highlights = new Highlights();
    if (links != null) {
        log.debug("Processing {} links", links.size());
        links.forEach(linkMap::add);
        PortNumber portnum = PortNumber.portNumber((int) links.iterator().next().src().port().toLong());
        for (LpLink dlink : linkMap.biLinks()) {
            DiscreteResourceId parent = Resources.discrete(devId, portnum).id();
            ContinuousResource continuousResource = (ContinuousResource) resourceQueryService.getAvailableResources(parent, Bandwidth.class).iterator().next();
            double availBandwidth = continuousResource.value();
            dlink.makeImportant().setLabel(Double.toString(availBandwidth) + " bytes/s");
            highlights.add(dlink.highlight(null));
        }
    } else {
        log.debug("No egress links found for device {}", devId);
    }
    return highlights;
}
Also used : Highlights(org.onosproject.ui.topo.Highlights) Bandwidth(org.onlab.util.Bandwidth) DiscreteResourceId(org.onosproject.net.resource.DiscreteResourceId) PortNumber(org.onosproject.net.PortNumber) ContinuousResource(org.onosproject.net.resource.ContinuousResource)

Example 18 with Bandwidth

use of org.onlab.util.Bandwidth in project onos by opennetworkinglab.

the class OpticalPathProvisioner method updateBandwidthUsage.

/**
 * Updates usage information of bandwidth based on connectivity which is established.
 * @param connectivity Optical connectivity
 */
private void updateBandwidthUsage(OpticalConnectivity connectivity) {
    if (NO_BW_REQUIREMENT.equals(connectivity.bandwidth())) {
        // no bandwidth requirement, nothing to allocate.
        return;
    }
    OpticalConnectivityId connectivityId = connectivity.id();
    List<Link> links = connectivity.links();
    List<Resource> resources = links.stream().flatMap(l -> Stream.of(l.src(), l.dst())).filter(cp -> !isTransportLayer(deviceService.getDevice(cp.deviceId()).type())).map(cp -> Resources.continuous(cp.deviceId(), cp.port(), Bandwidth.class).resource(connectivity.bandwidth().bps())).collect(Collectors.toList());
    log.debug("allocating bandwidth for {} : {}", connectivityId, resources);
    List<ResourceAllocation> allocations = resourceService.allocate(connectivityId, resources);
    if (allocations.isEmpty()) {
        log.warn("Failed to allocate bandwidth {} to {}", connectivity.bandwidth().bps(), resources);
    // TODO any recovery?
    }
    log.debug("Done allocating bandwidth for {}", connectivityId);
}
Also used : ConsistentMap(org.onosproject.store.service.ConsistentMap) NetworkConfigService(org.onosproject.net.config.NetworkConfigService) AtomicCounter(org.onosproject.store.service.AtomicCounter) CoreService(org.onosproject.core.CoreService) DeviceService(org.onosproject.net.device.DeviceService) LoggerFactory(org.slf4j.LoggerFactory) TopologyService(org.onosproject.net.topology.TopologyService) Link(org.onosproject.net.Link) ResourceService(org.onosproject.net.resource.ResourceService) ConnectPoint(org.onosproject.net.ConnectPoint) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) OpticalCircuitIntent(org.onosproject.net.intent.OpticalCircuitIntent) StorageService(org.onosproject.store.service.StorageService) Pair(org.apache.commons.lang3.tuple.Pair) MAX_PATHS_DEFAULT(org.onosproject.newoptical.OsgiPropertyConstants.MAX_PATHS_DEFAULT) Port(org.onosproject.net.Port) Duration(java.time.Duration) Map(java.util.Map) ApplicationId(org.onosproject.core.ApplicationId) OchPort(org.onosproject.net.optical.OchPort) KryoNamespaces(org.onosproject.store.serializers.KryoNamespaces) MastershipService(org.onosproject.mastership.MastershipService) LinkKey(org.onosproject.net.LinkKey) Serializer(org.onosproject.store.service.Serializer) AbstractListenerManager(org.onosproject.event.AbstractListenerManager) Device(org.onosproject.net.Device) Deactivate(org.osgi.service.component.annotations.Deactivate) Bandwidth(org.onlab.util.Bandwidth) Resources(org.onosproject.net.resource.Resources) Collection(java.util.Collection) Set(java.util.Set) Resource(org.onosproject.net.resource.Resource) OpticalPathEvent(org.onosproject.newoptical.api.OpticalPathEvent) Collectors(java.util.stream.Collectors) ResourceAllocation(org.onosproject.net.resource.ResourceAllocation) Objects(java.util.Objects) Versioned(org.onosproject.store.service.Versioned) Key(org.onosproject.net.intent.Key) LinkListener(org.onosproject.net.link.LinkListener) List(java.util.List) OduCltPort(org.onosproject.net.optical.OduCltPort) Stream(java.util.stream.Stream) IntentListener(org.onosproject.net.intent.IntentListener) TopologyVertex(org.onosproject.net.topology.TopologyVertex) Entry(java.util.Map.Entry) ListenerTracker(org.onosproject.event.ListenerTracker) LinkService(org.onosproject.net.link.LinkService) Optional(java.util.Optional) ClusterService(org.onosproject.cluster.ClusterService) Path(org.onosproject.net.Path) DeviceId(org.onosproject.net.DeviceId) Dictionary(java.util.Dictionary) TopologyEdge(org.onosproject.net.topology.TopologyEdge) Tools(org.onlab.util.Tools) IntentEvent(org.onosproject.net.intent.IntentEvent) BasicLinkConfig(org.onosproject.net.config.basics.BasicLinkConfig) LinkEvent(org.onosproject.net.link.LinkEvent) ComponentContext(org.osgi.service.component.ComponentContext) HashMap(java.util.HashMap) OpticalPathService(org.onosproject.newoptical.api.OpticalPathService) KryoNamespace(org.onlab.util.KryoNamespace) MapEventListener(org.onosproject.store.service.MapEventListener) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Component(org.osgi.service.component.annotations.Component) ImmutableList(com.google.common.collect.ImmutableList) IntentService(org.onosproject.net.intent.IntentService) Intent(org.onosproject.net.intent.Intent) Activate(org.osgi.service.component.annotations.Activate) LinkedList(java.util.LinkedList) LinkKey.linkKey(org.onosproject.net.LinkKey.linkKey) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) MAX_PATHS(org.onosproject.newoptical.OsgiPropertyConstants.MAX_PATHS) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) OpticalConnectivityId(org.onosproject.newoptical.api.OpticalConnectivityId) Beta(com.google.common.annotations.Beta) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) DefaultEdgeWeigher(org.onlab.graph.DefaultEdgeWeigher) OpticalPathListener(org.onosproject.newoptical.api.OpticalPathListener) DistributedSet(org.onosproject.store.service.DistributedSet) Weight(org.onlab.graph.Weight) OpticalDeviceServiceView.opticalView(org.onosproject.net.optical.device.OpticalDeviceServiceView.opticalView) MapEvent(org.onosproject.store.service.MapEvent) Modified(org.osgi.service.component.annotations.Modified) BandwidthCapacity(org.onosproject.net.config.basics.BandwidthCapacity) LinkWeigher(org.onosproject.net.topology.LinkWeigher) Reference(org.osgi.service.component.annotations.Reference) ScalarWeight(org.onlab.graph.ScalarWeight) OpticalConnectivityIntent(org.onosproject.net.intent.OpticalConnectivityIntent) ContinuousResource(org.onosproject.net.resource.ContinuousResource) Collections(java.util.Collections) OpticalConnectivityId(org.onosproject.newoptical.api.OpticalConnectivityId) Bandwidth(org.onlab.util.Bandwidth) Resource(org.onosproject.net.resource.Resource) ContinuousResource(org.onosproject.net.resource.ContinuousResource) Link(org.onosproject.net.Link) ResourceAllocation(org.onosproject.net.resource.ResourceAllocation)

Example 19 with Bandwidth

use of org.onlab.util.Bandwidth in project onos by opennetworkinglab.

the class OpticalConnectivityTest method testLinkEstablishedByCircuitIntent.

/**
 * Checks that isAllRealizingLink(Not)Established works for OpticalCircuitIntent.
 */
@Test
public void testLinkEstablishedByCircuitIntent() {
    // Mock 7-nodes linear topology
    ConnectPoint cp12 = createConnectPoint(1, 2);
    ConnectPoint cp21 = createConnectPoint(2, 1);
    ConnectPoint cp22 = createConnectPoint(2, 2);
    ConnectPoint cp31 = createConnectPoint(3, 1);
    ConnectPoint cp32 = createConnectPoint(3, 2);
    ConnectPoint cp41 = createConnectPoint(4, 1);
    ConnectPoint cp42 = createConnectPoint(4, 2);
    ConnectPoint cp51 = createConnectPoint(5, 1);
    ConnectPoint cp52 = createConnectPoint(5, 2);
    ConnectPoint cp61 = createConnectPoint(6, 1);
    ConnectPoint cp62 = createConnectPoint(6, 2);
    ConnectPoint cp71 = createConnectPoint(7, 1);
    Link link1 = createLink(cp12, cp21);
    Link link2 = createLink(cp22, cp31);
    Link link3 = createLink(cp32, cp41);
    Link link4 = createLink(cp42, cp51);
    Link link5 = createLink(cp52, cp61);
    Link link6 = createLink(cp62, cp71);
    List<Link> links = Stream.of(link1, link2, link3, link4, link5, link6).collect(Collectors.toList());
    // Mocks 2 intents to create Och connectivity
    OpticalCircuitIntent circuitIntent1 = createCircuitIntent(cp21, cp32);
    PacketLinkRealizedByOptical ochLink1 = PacketLinkRealizedByOptical.create(cp12, cp41, circuitIntent1);
    OpticalCircuitIntent circuitIntent2 = createCircuitIntent(cp51, cp62);
    PacketLinkRealizedByOptical ochLink2 = PacketLinkRealizedByOptical.create(cp42, cp71, circuitIntent2);
    Set<PacketLinkRealizedByOptical> plinks = ImmutableSet.of(ochLink1, ochLink2);
    Bandwidth bandwidth = Bandwidth.bps(100);
    Duration latency = Duration.ofMillis(10);
    OpticalConnectivityId cid = OpticalConnectivityId.of(1L);
    OpticalConnectivity oc1 = new OpticalConnectivity(cid, links, bandwidth, latency, plinks, Collections.emptySet());
    assertTrue(oc1.isAllRealizingLinkNotEstablished());
    assertFalse(oc1.isAllRealizingLinkEstablished());
    // Sets link realized by circuitIntent1 to be established
    OpticalConnectivity oc2 = oc1.setLinkEstablished(cp12, cp41, true);
    assertFalse(oc2.isAllRealizingLinkNotEstablished());
    assertFalse(oc2.isAllRealizingLinkEstablished());
    // Sets link realized by circuitIntent2 to be established
    OpticalConnectivity oc3 = oc2.setLinkEstablished(cp42, cp71, true);
    assertFalse(oc3.isAllRealizingLinkNotEstablished());
    assertTrue(oc3.isAllRealizingLinkEstablished());
}
Also used : OpticalConnectivityId(org.onosproject.newoptical.api.OpticalConnectivityId) Bandwidth(org.onlab.util.Bandwidth) Duration(java.time.Duration) ConnectPoint(org.onosproject.net.ConnectPoint) OpticalCircuitIntent(org.onosproject.net.intent.OpticalCircuitIntent) Link(org.onosproject.net.Link) DefaultLink(org.onosproject.net.DefaultLink) Test(org.junit.Test)

Example 20 with Bandwidth

use of org.onlab.util.Bandwidth in project onos by opennetworkinglab.

the class OpticalPathProvisionerTest method testSetupPath.

/**
 * Checks setupPath method works.
 */
@Test
public void testSetupPath() {
    Bandwidth bandwidth = Bandwidth.bps(100);
    Duration latency = Duration.ofMillis(10);
    List<Link> links = Stream.of(LINK1, LINK2, LINK3, LINK4, LINK5, LINK6).collect(Collectors.toList());
    Path path = new DefaultPath(PROVIDER_ID, links, new ScalarWeight(0));
    OpticalConnectivityId cid = target.setupPath(path, bandwidth, latency);
    assertNotNull(cid);
    // Checks intents are installed as expected
    assertEquals(1, intentService.submitted.size());
    assertEquals(OpticalConnectivityIntent.class, intentService.submitted.get(0).getClass());
    OpticalConnectivityIntent connIntent = (OpticalConnectivityIntent) intentService.submitted.get(0);
    assertEquals(CP31, connIntent.getSrc());
    assertEquals(CP52, connIntent.getDst());
}
Also used : DefaultPath(org.onosproject.net.DefaultPath) Path(org.onosproject.net.Path) OpticalConnectivityId(org.onosproject.newoptical.api.OpticalConnectivityId) Bandwidth(org.onlab.util.Bandwidth) OpticalConnectivityIntent(org.onosproject.net.intent.OpticalConnectivityIntent) Duration(java.time.Duration) DefaultPath(org.onosproject.net.DefaultPath) DefaultLink(org.onosproject.net.DefaultLink) Link(org.onosproject.net.Link) ScalarWeight(org.onlab.graph.ScalarWeight) Test(org.junit.Test)

Aggregations

Bandwidth (org.onlab.util.Bandwidth)24 Test (org.junit.Test)15 OpticalConnectivityId (org.onosproject.newoptical.api.OpticalConnectivityId)14 Duration (java.time.Duration)12 ConnectPoint (org.onosproject.net.ConnectPoint)10 Link (org.onosproject.net.Link)6 DefaultLink (org.onosproject.net.DefaultLink)5 Key (org.onosproject.net.intent.Key)5 OpticalConnectivityIntent (org.onosproject.net.intent.OpticalConnectivityIntent)5 ContinuousResource (org.onosproject.net.resource.ContinuousResource)5 Path (org.onosproject.net.Path)4 Constraint (org.onosproject.net.intent.Constraint)4 BandwidthConstraint (org.onosproject.net.intent.constraint.BandwidthConstraint)4 ResourceAllocation (org.onosproject.net.resource.ResourceAllocation)4 ResourceService (org.onosproject.net.resource.ResourceService)4 List (java.util.List)3 AbstractIntentTest (org.onosproject.net.intent.AbstractIntentTest)3 MockResourceService (org.onosproject.net.resource.MockResourceService)3 ImmutableList (com.google.common.collect.ImmutableList)2 ArrayList (java.util.ArrayList)2