Committed by
Gerrit Code Review
update to ONOS-2078 branch
Change-Id: I0632a2a205c04674d150fe7c20ae50844c56fde9
Showing
1 changed file
with
47 additions
and
3 deletions
| ... | @@ -19,8 +19,12 @@ import org.apache.commons.lang3.tuple.Pair; | ... | @@ -19,8 +19,12 @@ import org.apache.commons.lang3.tuple.Pair; |
| 19 | import org.apache.felix.scr.annotations.Activate; | 19 | import org.apache.felix.scr.annotations.Activate; |
| 20 | import org.apache.felix.scr.annotations.Component; | 20 | import org.apache.felix.scr.annotations.Component; |
| 21 | import org.apache.felix.scr.annotations.Deactivate; | 21 | import org.apache.felix.scr.annotations.Deactivate; |
| 22 | +import org.apache.felix.scr.annotations.Modified; | ||
| 23 | +import org.apache.felix.scr.annotations.Property; | ||
| 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.onlab.util.Tools; | ||
| 27 | +import org.onosproject.cfg.ComponentConfigService; | ||
| 24 | import org.onosproject.core.ApplicationId; | 28 | import org.onosproject.core.ApplicationId; |
| 25 | import org.onosproject.core.CoreService; | 29 | import org.onosproject.core.CoreService; |
| 26 | import org.onosproject.net.AnnotationKeys; | 30 | import org.onosproject.net.AnnotationKeys; |
| ... | @@ -47,11 +51,13 @@ import org.onosproject.net.intent.OpticalConnectivityIntent; | ... | @@ -47,11 +51,13 @@ import org.onosproject.net.intent.OpticalConnectivityIntent; |
| 47 | import org.onosproject.net.intent.impl.IntentCompilationException; | 51 | import org.onosproject.net.intent.impl.IntentCompilationException; |
| 48 | import org.onosproject.net.resource.device.DeviceResourceService; | 52 | import org.onosproject.net.resource.device.DeviceResourceService; |
| 49 | import org.onosproject.net.resource.link.LinkResourceAllocations; | 53 | import org.onosproject.net.resource.link.LinkResourceAllocations; |
| 54 | +import org.osgi.service.component.ComponentContext; | ||
| 50 | import org.slf4j.Logger; | 55 | import org.slf4j.Logger; |
| 51 | import org.slf4j.LoggerFactory; | 56 | import org.slf4j.LoggerFactory; |
| 52 | 57 | ||
| 53 | import java.util.Arrays; | 58 | import java.util.Arrays; |
| 54 | import java.util.Collections; | 59 | import java.util.Collections; |
| 60 | +import java.util.Dictionary; | ||
| 55 | import java.util.HashSet; | 61 | import java.util.HashSet; |
| 56 | import java.util.LinkedList; | 62 | import java.util.LinkedList; |
| 57 | import java.util.List; | 63 | import java.util.List; |
| ... | @@ -67,6 +73,16 @@ public class OpticalCircuitIntentCompiler implements IntentCompiler<OpticalCircu | ... | @@ -67,6 +73,16 @@ public class OpticalCircuitIntentCompiler implements IntentCompiler<OpticalCircu |
| 67 | 73 | ||
| 68 | private static final Logger log = LoggerFactory.getLogger(OpticalCircuitIntentCompiler.class); | 74 | private static final Logger log = LoggerFactory.getLogger(OpticalCircuitIntentCompiler.class); |
| 69 | 75 | ||
| 76 | + private static final int DEFAULT_MAX_CAPACITY = 10; | ||
| 77 | + | ||
| 78 | + @Property(name = "maxCapacity", intValue = DEFAULT_MAX_CAPACITY, | ||
| 79 | + label = "Maximum utilization of an optical connection.") | ||
| 80 | + | ||
| 81 | + private int maxCapacity = DEFAULT_MAX_CAPACITY; | ||
| 82 | + | ||
| 83 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
| 84 | + protected ComponentConfigService cfgService; | ||
| 85 | + | ||
| 70 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 86 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 71 | protected IntentExtensionService intentManager; | 87 | protected IntentExtensionService intentManager; |
| 72 | 88 | ||
| ... | @@ -84,15 +100,44 @@ public class OpticalCircuitIntentCompiler implements IntentCompiler<OpticalCircu | ... | @@ -84,15 +100,44 @@ public class OpticalCircuitIntentCompiler implements IntentCompiler<OpticalCircu |
| 84 | 100 | ||
| 85 | private ApplicationId appId; | 101 | private ApplicationId appId; |
| 86 | 102 | ||
| 103 | + @Modified | ||
| 104 | + public void modified(ComponentContext context) { | ||
| 105 | + Dictionary properties = context.getProperties(); | ||
| 106 | + | ||
| 107 | + //TODO for reduction check if the new capacity is smaller than the size of the current mapping | ||
| 108 | + String propertyString = Tools.get(properties, "maxCapacity"); | ||
| 109 | + | ||
| 110 | + //Ignore if propertyString is empty | ||
| 111 | + if (!propertyString.isEmpty()) { | ||
| 112 | + try { | ||
| 113 | + int temp = Integer.parseInt(propertyString); | ||
| 114 | + //Ensure value is non-negative but allow zero as a way to shutdown the link | ||
| 115 | + if (temp >= 0) { | ||
| 116 | + maxCapacity = temp; | ||
| 117 | + } | ||
| 118 | + } catch (NumberFormatException e) { | ||
| 119 | + //Malformed arguments lead to no change of value (user should be notified of error) | ||
| 120 | + log.error("The value '{}' for maxCapacity was not parsable as an integer.", propertyString, e); | ||
| 121 | + } | ||
| 122 | + } else { | ||
| 123 | + //Notify of empty value but do not return (other properties will also go in this function) | ||
| 124 | + log.error("The value for maxCapacity was set to an empty value."); | ||
| 125 | + } | ||
| 126 | + | ||
| 127 | + } | ||
| 128 | + | ||
| 87 | @Activate | 129 | @Activate |
| 88 | - public void activate() { | 130 | + public void activate(ComponentContext context) { |
| 89 | appId = coreService.registerApplication("org.onosproject.net.intent"); | 131 | appId = coreService.registerApplication("org.onosproject.net.intent"); |
| 90 | intentManager.registerCompiler(OpticalCircuitIntent.class, this); | 132 | intentManager.registerCompiler(OpticalCircuitIntent.class, this); |
| 133 | + cfgService.registerProperties(getClass()); | ||
| 134 | + modified(context); | ||
| 91 | } | 135 | } |
| 92 | 136 | ||
| 93 | @Deactivate | 137 | @Deactivate |
| 94 | public void deactivate() { | 138 | public void deactivate() { |
| 95 | intentManager.unregisterCompiler(OpticalCircuitIntent.class); | 139 | intentManager.unregisterCompiler(OpticalCircuitIntent.class); |
| 140 | + cfgService.unregisterProperties(getClass(), false); | ||
| 96 | } | 141 | } |
| 97 | 142 | ||
| 98 | @Override | 143 | @Override |
| ... | @@ -180,8 +225,7 @@ public class OpticalCircuitIntentCompiler implements IntentCompiler<OpticalCircu | ... | @@ -180,8 +225,7 @@ public class OpticalCircuitIntentCompiler implements IntentCompiler<OpticalCircu |
| 180 | return true; | 225 | return true; |
| 181 | } | 226 | } |
| 182 | 227 | ||
| 183 | - // TODO: hardcoded 80% utilization | 228 | + return mapping.size() < maxCapacity; |
| 184 | - return mapping.size() < 8; | ||
| 185 | } | 229 | } |
| 186 | 230 | ||
| 187 | private boolean isAllowed(OpticalCircuitIntent circuitIntent, OpticalConnectivityIntent connIntent) { | 231 | private boolean isAllowed(OpticalCircuitIntent circuitIntent, OpticalConnectivityIntent connIntent) { | ... | ... |
-
Please register or login to post a comment