HIGUCHI Yuta

ONOS-3732 Bandwidth resource registration using netcfg.

- Uses netcfg defined value as available resource if defined,
  else uses port speed as available Bandwidth resource

Change-Id: I2dde9a9194025194ed8785b4608f064debab182b
...@@ -113,9 +113,15 @@ public class ResourcesCommand extends AbstractShellCommand { ...@@ -113,9 +113,15 @@ public class ResourcesCommand extends AbstractShellCommand {
113 return; 113 return;
114 } 114 }
115 115
116 +
116 if (resource instanceof ContinuousResource) { 117 if (resource instanceof ContinuousResource) {
118 + String s = ((String) resource.last());
119 + String simpleName = s.substring(s.lastIndexOf('.') + 1);
117 print("%s%s: %f", Strings.repeat(" ", level), 120 print("%s%s: %f", Strings.repeat(" ", level),
118 - resource.last(), 121 + simpleName,
122 + // Note: last() does not return, what we've registered
123 + // following does not work
124 + //((Class<?>) resource.last()).getSimpleName(),
119 ((ContinuousResource) resource).value()); 125 ((ContinuousResource) resource).value());
120 // Continuous resource is terminal node, stop here 126 // Continuous resource is terminal node, stop here
121 return; 127 return;
......
...@@ -191,6 +191,17 @@ public abstract class Config<S> { ...@@ -191,6 +191,17 @@ public abstract class Config<S> {
191 } 191 }
192 192
193 /** 193 /**
194 + * Clears the specified property.
195 + *
196 + * @param name property name
197 + * @return self
198 + */
199 + protected Config<S> clear(String name) {
200 + object.remove(name);
201 + return this;
202 + }
203 +
204 + /**
194 * Sets the specified property as a boolean or clears it if null value given. 205 * Sets the specified property as a boolean or clears it if null value given.
195 * 206 *
196 * @param name property name 207 * @param name property name
...@@ -437,7 +448,38 @@ public abstract class Config<S> { ...@@ -437,7 +448,38 @@ public abstract class Config<S> {
437 */ 448 */
438 protected boolean isNumber(String field, FieldPresence presence, long... minMax) { 449 protected boolean isNumber(String field, FieldPresence presence, long... minMax) {
439 JsonNode node = object.path(field); 450 JsonNode node = object.path(field);
440 - return isValid(node, presence, (node.isLong() || node.isInt()) && 451 + return isValid(node, presence, node.isNumber() &&
452 + (minMax.length > 0 && minMax[0] <= node.asLong() || minMax.length < 1) &&
453 + (minMax.length > 1 && minMax[1] > node.asLong() || minMax.length < 2));
454 + }
455 + /**
456 + * Indicates whether the specified field holds a valid number.
457 + *
458 + * @param field JSON field name
459 + * @param presence specifies if field is optional or mandatory
460 + * @param minMax optional min/max values
461 + * @return true if valid; false otherwise
462 + * @throws IllegalArgumentException if field is present, but not valid
463 + */
464 + protected boolean isNumber(String field, FieldPresence presence, double... minMax) {
465 + JsonNode node = object.path(field);
466 + return isValid(node, presence, node.isNumber() &&
467 + (minMax.length > 0 && minMax[0] <= node.asDouble() || minMax.length < 1) &&
468 + (minMax.length > 1 && minMax[1] > node.asDouble() || minMax.length < 2));
469 + }
470 +
471 + /**
472 + * Indicates whether the specified field holds a valid integer.
473 + *
474 + * @param field JSON field name
475 + * @param presence specifies if field is optional or mandatory
476 + * @param minMax optional min/max values
477 + * @return true if valid; false otherwise
478 + * @throws IllegalArgumentException if field is present, but not valid
479 + */
480 + protected boolean isIntegralNumber(String field, FieldPresence presence, long... minMax) {
481 + JsonNode node = object.path(field);
482 + return isValid(node, presence, node.isIntegralNumber() &&
441 (minMax.length > 0 && minMax[0] <= node.asLong() || minMax.length < 1) && 483 (minMax.length > 0 && minMax[0] <= node.asLong() || minMax.length < 1) &&
442 (minMax.length > 1 && minMax[1] > node.asLong() || minMax.length < 2)); 484 (minMax.length > 1 && minMax[1] > node.asLong() || minMax.length < 2));
443 } 485 }
......
1 +/*
2 + * Copyright 2016 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.net.newresource;
17 +
18 +import static com.google.common.base.Preconditions.checkNotNull;
19 +
20 +import org.onlab.util.Bandwidth;
21 +import org.onosproject.net.ConnectPoint;
22 +import org.onosproject.net.config.Config;
23 +import org.slf4j.Logger;
24 +import org.slf4j.LoggerFactory;
25 +
26 +import com.fasterxml.jackson.databind.JsonNode;
27 +import com.google.common.annotations.Beta;
28 +
29 +/**
30 + * Configuration to specify maximum available bandwidth resource (Capacity) on a port.
31 + */
32 +@Beta
33 +public class BandwidthCapacity extends Config<ConnectPoint> {
34 +
35 + /**
36 + * netcfg ConfigKey for {@link BandwidthCapacity}.
37 + */
38 + public static final String CONFIG_KEY = "bandwidthCapacity";
39 +
40 + // JSON key
41 + private static final String CAPACITY = "capacityMbps";
42 +
43 + private static final Logger log = LoggerFactory.getLogger(BandwidthCapacity.class);
44 +
45 + @Override
46 + public boolean isValid() {
47 + // Open for extension (adding fields) in the future,
48 + // must have CAPACITY field.
49 + return isNumber(CAPACITY, FieldPresence.MANDATORY);
50 + }
51 +
52 + /**
53 + * Sets the Available Bandwidth resource (Capacity).
54 + *
55 + * @param bandwidth value to set.
56 + * @return self
57 + */
58 + public BandwidthCapacity capacity(Bandwidth bandwidth) {
59 + checkNotNull(bandwidth);
60 +
61 + // TODO current Bandwidth API end up value converted to double
62 + setOrClear(CAPACITY, bandwidth.bps());
63 + return this;
64 + }
65 +
66 + /**
67 + * Available Bandwidth resource (Capacity).
68 + *
69 + * @return {@link Bandwidth}
70 + */
71 + public Bandwidth capacity() {
72 + JsonNode v = object.path(CAPACITY);
73 +
74 + if (v.isIntegralNumber()) {
75 +
76 + return Bandwidth.mbps(v.asLong());
77 + } else if (v.isFloatingPointNumber()) {
78 +
79 + return Bandwidth.mbps(v.asDouble());
80 + } else {
81 + log.warn("Unexpected JsonNode for {}: {}", CAPACITY, v);
82 + return Bandwidth.mbps(v.asDouble());
83 + }
84 + }
85 +}
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
16 package org.onosproject.net.newresource; 16 package org.onosproject.net.newresource;
17 17
18 import com.google.common.annotations.Beta; 18 import com.google.common.annotations.Beta;
19 +
19 import org.onosproject.net.DeviceId; 20 import org.onosproject.net.DeviceId;
20 import org.onosproject.net.PortNumber; 21 import org.onosproject.net.PortNumber;
21 22
......
...@@ -18,7 +18,9 @@ package org.onosproject.net.newresource.impl; ...@@ -18,7 +18,9 @@ package org.onosproject.net.newresource.impl;
18 import com.google.common.collect.ImmutableSet; 18 import com.google.common.collect.ImmutableSet;
19 import org.onlab.packet.MplsLabel; 19 import org.onlab.packet.MplsLabel;
20 import org.onlab.packet.VlanId; 20 import org.onlab.packet.VlanId;
21 +import org.onlab.util.Bandwidth;
21 import org.onlab.util.ItemNotFoundException; 22 import org.onlab.util.ItemNotFoundException;
23 +import org.onosproject.net.ConnectPoint;
22 import org.onosproject.net.Device; 24 import org.onosproject.net.Device;
23 import org.onosproject.net.DeviceId; 25 import org.onosproject.net.DeviceId;
24 import org.onosproject.net.OchSignal; 26 import org.onosproject.net.OchSignal;
...@@ -29,17 +31,20 @@ import org.onosproject.net.behaviour.LambdaQuery; ...@@ -29,17 +31,20 @@ import org.onosproject.net.behaviour.LambdaQuery;
29 import org.onosproject.net.behaviour.MplsQuery; 31 import org.onosproject.net.behaviour.MplsQuery;
30 import org.onosproject.net.behaviour.TributarySlotQuery; 32 import org.onosproject.net.behaviour.TributarySlotQuery;
31 import org.onosproject.net.behaviour.VlanQuery; 33 import org.onosproject.net.behaviour.VlanQuery;
34 +import org.onosproject.net.config.NetworkConfigService;
32 import org.onosproject.net.device.DeviceEvent; 35 import org.onosproject.net.device.DeviceEvent;
33 import org.onosproject.net.device.DeviceListener; 36 import org.onosproject.net.device.DeviceListener;
34 import org.onosproject.net.device.DeviceService; 37 import org.onosproject.net.device.DeviceService;
35 import org.onosproject.net.driver.DriverHandler; 38 import org.onosproject.net.driver.DriverHandler;
36 import org.onosproject.net.driver.DriverService; 39 import org.onosproject.net.driver.DriverService;
37 import org.onosproject.net.newresource.ResourceAdminService; 40 import org.onosproject.net.newresource.ResourceAdminService;
41 +import org.onosproject.net.newresource.BandwidthCapacity;
38 import org.onosproject.net.newresource.Resource; 42 import org.onosproject.net.newresource.Resource;
39 import org.slf4j.Logger; 43 import org.slf4j.Logger;
40 import org.slf4j.LoggerFactory; 44 import org.slf4j.LoggerFactory;
41 45
42 import java.util.Collections; 46 import java.util.Collections;
47 +import java.util.Optional;
43 import java.util.Set; 48 import java.util.Set;
44 import java.util.concurrent.ExecutorService; 49 import java.util.concurrent.ExecutorService;
45 import java.util.stream.Collectors; 50 import java.util.stream.Collectors;
...@@ -56,21 +61,25 @@ final class ResourceDeviceListener implements DeviceListener { ...@@ -56,21 +61,25 @@ final class ResourceDeviceListener implements DeviceListener {
56 private final ResourceAdminService adminService; 61 private final ResourceAdminService adminService;
57 private final DeviceService deviceService; 62 private final DeviceService deviceService;
58 private final DriverService driverService; 63 private final DriverService driverService;
64 + private final NetworkConfigService netcfgService;
59 private final ExecutorService executor; 65 private final ExecutorService executor;
60 66
67 +
61 /** 68 /**
62 * Creates an instance with the specified ResourceAdminService and ExecutorService. 69 * Creates an instance with the specified ResourceAdminService and ExecutorService.
63 * 70 *
64 * @param adminService instance invoked to register resources 71 * @param adminService instance invoked to register resources
65 * @param deviceService {@link DeviceService} to be used 72 * @param deviceService {@link DeviceService} to be used
66 * @param driverService {@link DriverService} to be used 73 * @param driverService {@link DriverService} to be used
74 + * @param netcfgService {@link NetworkConfigService} to be used.
67 * @param executor executor used for processing resource registration 75 * @param executor executor used for processing resource registration
68 */ 76 */
69 ResourceDeviceListener(ResourceAdminService adminService, DeviceService deviceService, DriverService driverService, 77 ResourceDeviceListener(ResourceAdminService adminService, DeviceService deviceService, DriverService driverService,
70 - ExecutorService executor) { 78 + NetworkConfigService netcfgService, ExecutorService executor) {
71 this.adminService = checkNotNull(adminService); 79 this.adminService = checkNotNull(adminService);
72 this.deviceService = checkNotNull(deviceService); 80 this.deviceService = checkNotNull(deviceService);
73 this.driverService = checkNotNull(driverService); 81 this.driverService = checkNotNull(driverService);
82 + this.netcfgService = checkNotNull(netcfgService);
74 this.executor = checkNotNull(executor); 83 this.executor = checkNotNull(executor);
75 } 84 }
76 85
...@@ -121,6 +130,15 @@ final class ResourceDeviceListener implements DeviceListener { ...@@ -121,6 +130,15 @@ final class ResourceDeviceListener implements DeviceListener {
121 executor.submit(() -> { 130 executor.submit(() -> {
122 adminService.registerResources(portPath); 131 adminService.registerResources(portPath);
123 132
133 + queryBandwidth(device.id(), port.number())
134 + .map(bw -> portPath.child(Bandwidth.class, bw.bps()))
135 + .map(adminService::registerResources)
136 + .ifPresent(success -> {
137 + if (!success) {
138 + log.error("Failed to register Bandwidth for {}", portPath.id());
139 + }
140 + });
141 +
124 // for VLAN IDs 142 // for VLAN IDs
125 Set<VlanId> vlans = queryVlanIds(device.id(), port.number()); 143 Set<VlanId> vlans = queryVlanIds(device.id(), port.number());
126 if (!vlans.isEmpty()) { 144 if (!vlans.isEmpty()) {
...@@ -160,6 +178,30 @@ final class ResourceDeviceListener implements DeviceListener { ...@@ -160,6 +178,30 @@ final class ResourceDeviceListener implements DeviceListener {
160 executor.submit(() -> adminService.unregisterResources(resource)); 178 executor.submit(() -> adminService.unregisterResources(resource));
161 } 179 }
162 180
181 + /**
182 + * Query bandwidth capacity on a port.
183 + *
184 + * @param did {@link DeviceId}
185 + * @param number {@link PortNumber}
186 + * @return bandwidth capacity
187 + */
188 + private Optional<Bandwidth> queryBandwidth(DeviceId did, PortNumber number) {
189 + // Check and use netcfg first.
190 + ConnectPoint cp = new ConnectPoint(did, number);
191 + BandwidthCapacity config = netcfgService.getConfig(cp, BandwidthCapacity.class);
192 + if (config != null) {
193 + log.trace("Registering configured bandwidth {} for {}/{}", config.capacity(), did, number);
194 + return Optional.of(config.capacity());
195 + }
196 +
197 + // populate bandwidth value, assuming portSpeed == bandwidth
198 + Port port = deviceService.getPort(did, number);
199 + if (port != null) {
200 + return Optional.of(Bandwidth.mbps(port.portSpeed()));
201 + }
202 + return Optional.empty();
203 + }
204 +
163 private Set<OchSignal> queryLambdas(DeviceId did, PortNumber port) { 205 private Set<OchSignal> queryLambdas(DeviceId did, PortNumber port) {
164 try { 206 try {
165 DriverHandler handler = driverService.createHandler(did); 207 DriverHandler handler = driverService.createHandler(did);
......
1 +/*
2 + * Copyright 2016 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.net.newresource.impl;
17 +
18 +import static com.google.common.base.Preconditions.checkArgument;
19 +import static com.google.common.base.Preconditions.checkNotNull;
20 +import static org.onosproject.net.newresource.Resource.continuous;
21 +import static org.slf4j.LoggerFactory.getLogger;
22 +
23 +import java.util.Set;
24 +import java.util.concurrent.ExecutorService;
25 +
26 +import org.onlab.util.Bandwidth;
27 +import org.onosproject.net.ConnectPoint;
28 +import org.onosproject.net.config.NetworkConfigEvent;
29 +import org.onosproject.net.config.NetworkConfigListener;
30 +import org.onosproject.net.config.NetworkConfigService;
31 +import org.onosproject.net.newresource.BandwidthCapacity;
32 +import org.onosproject.net.newresource.ResourceAdminService;
33 +import org.slf4j.Logger;
34 +
35 +import com.google.common.annotations.Beta;
36 +import com.google.common.collect.ImmutableSet;
37 +
38 +// TODO Consider merging this with ResourceDeviceListener.
39 +/**
40 + * Handler for NetworkConfiguration changes.
41 + */
42 +@Beta
43 +final class ResourceNetworkConfigListener implements NetworkConfigListener {
44 +
45 + /**
46 + * Config classes relevant to this listener.
47 + */
48 + private static final Set<Class<?>> CONFIG_CLASSES = ImmutableSet.of(BandwidthCapacity.class);
49 +
50 + private final Logger log = getLogger(getClass());
51 +
52 + private final ResourceAdminService adminService;
53 + private final NetworkConfigService cfgService;
54 + private final ExecutorService executor;
55 +
56 + /**
57 + * Creates an instance of listener.
58 + *
59 + * @param adminService {@link ResourceAdminService}
60 + * @param cfgService {@link NetworkConfigService}
61 + * @param executor Executor to use.
62 + */
63 + ResourceNetworkConfigListener(ResourceAdminService adminService, NetworkConfigService cfgService,
64 + ExecutorService executor) {
65 + this.adminService = checkNotNull(adminService);
66 + this.cfgService = checkNotNull(cfgService);
67 + this.executor = checkNotNull(executor);
68 + }
69 +
70 + @Override
71 + public boolean isRelevant(NetworkConfigEvent event) {
72 + return CONFIG_CLASSES.contains(event.configClass());
73 + }
74 +
75 + @Override
76 + public void event(NetworkConfigEvent event) {
77 + if (event.configClass() == BandwidthCapacity.class) {
78 + executor.submit(() -> {
79 + try {
80 + handleBandwidthCapacity(event);
81 + } catch (Exception e) {
82 + log.error("Exception handling BandwidthCapacity", e);
83 + }
84 + });
85 + }
86 + }
87 +
88 + private void handleBandwidthCapacity(NetworkConfigEvent event) {
89 + checkArgument(event.configClass() == BandwidthCapacity.class);
90 +
91 + ConnectPoint cp = (ConnectPoint) event.subject();
92 + BandwidthCapacity bwCapacity = cfgService.getConfig(cp, BandwidthCapacity.class);
93 +
94 + switch (event.type()) {
95 + case CONFIG_ADDED:
96 + if (!adminService.registerResources(continuous(bwCapacity.capacity().bps(),
97 + cp.deviceId(),
98 + cp.port(), Bandwidth.class))) {
99 + log.info("Failed to register Bandwidth for {}, attempting update", cp);
100 +
101 + // Bandwidth based on port speed, was probably already registered.
102 + // need to update to the valued based on configuration
103 +
104 + if (!updateRegistration(cp, bwCapacity)) {
105 + log.warn("Failed to update Bandwidth for {}", cp);
106 + }
107 + }
108 + break;
109 +
110 + case CONFIG_UPDATED:
111 + if (!updateRegistration(cp, bwCapacity)) {
112 + log.warn("Failed to update Bandwidth for {}", cp);
113 + }
114 + break;
115 +
116 + case CONFIG_REMOVED:
117 + // FIXME Following should be an update to the value based on port speed
118 + if (!adminService.unregisterResources(continuous(0,
119 + cp.deviceId(),
120 + cp.port(),
121 + Bandwidth.class))) {
122 + log.warn("Failed to unregister Bandwidth for {}", cp);
123 + }
124 + break;
125 +
126 + case CONFIG_REGISTERED:
127 + case CONFIG_UNREGISTERED:
128 + // no-op
129 + break;
130 +
131 + default:
132 + break;
133 + }
134 + }
135 +
136 + private boolean updateRegistration(ConnectPoint cp, BandwidthCapacity bwCapacity) {
137 + // FIXME workaround until replace/update semantics become available
138 + // this potentially blows up existing registration
139 + // or end up as no-op
140 + //
141 + // Current code end up in situation like below:
142 + // PortNumber: 2
143 + // MplsLabel: [[16‥240)]
144 + // VlanId: [[0‥4095)]
145 + // Bandwidth: 2000000.000000
146 + // Bandwidth: 20000000.000000
147 + //
148 + // but both unregisterResources(..) and registerResources(..)
149 + // returns true (success)
150 +
151 + if (!adminService.unregisterResources(continuous(0, cp.deviceId(), cp.port(), Bandwidth.class))) {
152 + log.warn("unregisterResources for {} failed", cp);
153 + }
154 + return adminService.registerResources(continuous(bwCapacity.capacity().bps(),
155 + cp.deviceId(),
156 + cp.port(),
157 + Bandwidth.class));
158 + }
159 +
160 +}
...@@ -16,20 +16,31 @@ ...@@ -16,20 +16,31 @@
16 package org.onosproject.net.newresource.impl; 16 package org.onosproject.net.newresource.impl;
17 17
18 import com.google.common.annotations.Beta; 18 import com.google.common.annotations.Beta;
19 +import com.google.common.collect.ImmutableList;
20 +
19 import org.apache.felix.scr.annotations.Activate; 21 import org.apache.felix.scr.annotations.Activate;
20 import org.apache.felix.scr.annotations.Component; 22 import org.apache.felix.scr.annotations.Component;
21 import org.apache.felix.scr.annotations.Deactivate; 23 import org.apache.felix.scr.annotations.Deactivate;
22 import org.apache.felix.scr.annotations.Reference; 24 import org.apache.felix.scr.annotations.Reference;
23 import org.apache.felix.scr.annotations.ReferenceCardinality; 25 import org.apache.felix.scr.annotations.ReferenceCardinality;
26 +import org.onosproject.net.ConnectPoint;
27 +import org.onosproject.net.config.ConfigFactory;
28 +import org.onosproject.net.config.NetworkConfigListener;
29 +import org.onosproject.net.config.NetworkConfigRegistry;
24 import org.onosproject.net.device.DeviceListener; 30 import org.onosproject.net.device.DeviceListener;
25 import org.onosproject.net.device.DeviceService; 31 import org.onosproject.net.device.DeviceService;
26 import org.onosproject.net.driver.DriverService; 32 import org.onosproject.net.driver.DriverService;
33 +import org.onosproject.net.newresource.BandwidthCapacity;
27 import org.onosproject.net.newresource.ResourceAdminService; 34 import org.onosproject.net.newresource.ResourceAdminService;
35 +import org.slf4j.Logger;
28 36
37 +import java.util.List;
29 import java.util.concurrent.ExecutorService; 38 import java.util.concurrent.ExecutorService;
30 import java.util.concurrent.Executors; 39 import java.util.concurrent.Executors;
31 40
32 import static org.onlab.util.Tools.groupedThreads; 41 import static org.onlab.util.Tools.groupedThreads;
42 +import static org.onosproject.net.config.basics.SubjectFactories.CONNECT_POINT_SUBJECT_FACTORY;
43 +import static org.slf4j.LoggerFactory.getLogger;
33 44
34 /** 45 /**
35 * A class registering resources when they are detected. 46 * A class registering resources when they are detected.
...@@ -47,19 +58,52 @@ public final class ResourceRegistrar { ...@@ -47,19 +58,52 @@ public final class ResourceRegistrar {
47 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 58 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
48 protected DeviceService deviceService; 59 protected DeviceService deviceService;
49 60
61 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
62 + protected NetworkConfigRegistry cfgRegistry;
63 +
64 + private final Logger log = getLogger(getClass());
65 +
66 + private final List<ConfigFactory<?, ?>> factories = ImmutableList.of(
67 + new ConfigFactory<ConnectPoint, BandwidthCapacity>(CONNECT_POINT_SUBJECT_FACTORY,
68 + BandwidthCapacity.class, BandwidthCapacity.CONFIG_KEY) {
69 + @Override
70 + public BandwidthCapacity createConfig() {
71 + return new BandwidthCapacity();
72 + }
73 + });
74 +
75 +
50 private DeviceListener deviceListener; 76 private DeviceListener deviceListener;
77 +
51 private final ExecutorService executor = 78 private final ExecutorService executor =
52 Executors.newSingleThreadExecutor(groupedThreads("onos/resource", "registrar")); 79 Executors.newSingleThreadExecutor(groupedThreads("onos/resource", "registrar"));
53 80
81 + private NetworkConfigListener cfgListener;
82 +
54 @Activate 83 @Activate
55 public void activate() { 84 public void activate() {
56 - deviceListener = new ResourceDeviceListener(adminService, deviceService, driverService, executor); 85 + factories.forEach(cfgRegistry::registerConfigFactory);
86 +
87 + cfgListener = new ResourceNetworkConfigListener(adminService, cfgRegistry, executor);
88 + cfgRegistry.addListener(cfgListener);
89 +
90 + deviceListener = new ResourceDeviceListener(adminService, deviceService, driverService, cfgRegistry, executor);
57 deviceService.addListener(deviceListener); 91 deviceService.addListener(deviceListener);
92 +
93 + // TODO Attempt initial registration of existing resources?
94 +
95 + log.info("Started");
58 } 96 }
59 97
60 @Deactivate 98 @Deactivate
61 public void deactivate() { 99 public void deactivate() {
62 deviceService.removeListener(deviceListener); 100 deviceService.removeListener(deviceListener);
101 + cfgRegistry.removeListener(cfgListener);
102 +
63 executor.shutdownNow(); 103 executor.shutdownNow();
104 +
105 + factories.forEach(cfgRegistry::unregisterConfigFactory);
106 +
107 + log.info("Stopped");
64 } 108 }
65 } 109 }
......
1 +{
2 + "ports": {
3 + "of:0000000000000002/1": {
4 + "bandwidthCapacity": {
5 + "capacityMbps": 1
6 + }
7 + },
8 + "of:0000000000000002/2": {
9 + "bandwidthCapacity": {
10 + "capacityMbps": 2.0
11 + }
12 + }
13 + }
14 +}