Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  1. Registration phase
    A new resource is detected by ONOS, the resource needs to be registered to Resource Service subsystem so that the subsystem can track the resource utilization. This phase is nomally handled by ONOS framework side (ResourceRegistrar), not by application developer, but you can register resources for your specific purpose.
  2. Allocation phase
    Resource Service subsystem can allocate a registered resource to a resource consumer. The allocation method supports multiple resource allocations at a time as a single transaction. 
  3. Release phase
    When we don't need to use a resource anymore, we can release the resource allocation. Similar to the allocation method, the release method also supports transaction.
  4. Unregistration phase
    When ONOS detects a registered resource being gone, ResourceRegistrar takes care of the resource unregistration.

Code examples

Code Block
languagejava
ResourceService resourceService = ...;

ResourceConsumer consumer = IntentId.valueOf(1);
DeviceId device = DeviceId.deviceId("foo");
PortNumber port = PortNumber.portNumber(1);
VlanId vlan = VlanId.vlanId((short) 100);

// create a VLAN ID resource on port 1 on device "foo"
DiscreteResource vlanRes = Resources.discrete(device, port, vlan).resource();

// create a bandwidth resource representing 1000bps on port 1 on device "foo"
ContinuousResource bandwidthRes = Resources.continuous(device, port, Bandwidth.class).resource(1000);

// allocate the VLAN ID resource, then release it
resourceService.allocate(consumer, vlanRes).ifPresent(alloc -> resourceService.release(alloc));

// allocate the bandwidth resource, then release it
resourceService.allocate(consumer, bandwidthRes).ifPresent(alloc -> resourceService.release(alloc));

// create a discrete resource ID
Resources.discrete(device, port).id();

// create a continuous resource ID
Resources.continuous(device, port, Bandwidth.class).id();

...