jcc
Committed by Gerrit Code Review

【ONOS-1223】【ONOS-1870】the implements of label resource APIs.it include

commands
used to test
if there is any bug,LabelResourceManager,LabelResourceStore using
copycat,and junit test code.
the distribution strategy is that the master of devices handle all the
requests if applied label belongs to it.except for query request.
label store uses copycat instead of hazelcast to keep strong consistency

Change-Id: I77bde6a96f33098063573d37ed1ba787ae21973f
1 +package org.onosproject.cli.net;
2 +
3 +import java.util.Collection;
4 +import java.util.Iterator;
5 +
6 +import org.apache.karaf.shell.commands.Argument;
7 +import org.apache.karaf.shell.commands.Command;
8 +import org.onosproject.cli.AbstractShellCommand;
9 +import org.onosproject.net.resource.DefaultLabelResource;
10 +import org.onosproject.net.resource.LabelResource;
11 +import org.onosproject.net.resource.LabelResourceService;
12 +
13 +@Command(scope = "onos", name = "apply-global-label-resource-pool",
14 + description = "Apply global labels from global resource pool")
15 +public class ApplyGlobalLabelResourceCommand extends AbstractShellCommand {
16 + @Argument(index = 0, name = "applyNum",
17 + description = "Applying number means how many labels applications want to use.",
18 + required = true, multiValued = false)
19 + String applyNum = null;
20 +
21 + private static final String FMT = "deviceid=%s, labelresourceid=%s";
22 +
23 + @Override
24 + protected void execute() {
25 + LabelResourceService lrs = get(LabelResourceService.class);
26 + Collection<LabelResource> result =
27 + lrs.applyFromGlobalPool(Long.parseLong(applyNum));
28 + if (result.size() > 0) {
29 + for (Iterator<LabelResource> iterator = result.iterator(); iterator
30 + .hasNext();) {
31 + DefaultLabelResource defaultLabelResource = (DefaultLabelResource) iterator
32 + .next();
33 + print(FMT, defaultLabelResource.deviceId().toString(),
34 + defaultLabelResource.labelResourceId().toString());
35 + }
36 + }
37 + }
38 +
39 +}
1 +package org.onosproject.cli.net;
2 +
3 +import java.util.Collection;
4 +import java.util.Iterator;
5 +
6 +import org.apache.karaf.shell.commands.Argument;
7 +import org.apache.karaf.shell.commands.Command;
8 +import org.onosproject.cli.AbstractShellCommand;
9 +import org.onosproject.net.DeviceId;
10 +import org.onosproject.net.resource.DefaultLabelResource;
11 +import org.onosproject.net.resource.LabelResource;
12 +import org.onosproject.net.resource.LabelResourceService;
13 +
14 +@Command(scope = "onos", name = "apply-label-resource-pool",
15 + description = "Apply label resource from device pool by specific device id")
16 +public class ApplyLabelResourceCommand extends AbstractShellCommand {
17 + @Argument(index = 0, name = "deviceId",
18 + description = "Device identity",
19 + required = true, multiValued = false)
20 + String deviceId = null;
21 + @Argument(index = 1, name = "applyNum",
22 + description = "Applying number means how many labels applications want to use.",
23 + required = true, multiValued = false)
24 + String applyNum = null;
25 +
26 + private static final String FMT = "deviceid=%s, labelresourceid=%s";
27 +
28 + @Override
29 + protected void execute() {
30 + LabelResourceService lrs = get(LabelResourceService.class);
31 + Collection<LabelResource> result = lrs.applyFromDevicePool(DeviceId
32 + .deviceId(deviceId), Long.parseLong(applyNum));
33 + if (result.size() > 0) {
34 + for (Iterator<LabelResource> iterator = result.iterator(); iterator
35 + .hasNext();) {
36 + DefaultLabelResource defaultLabelResource = (DefaultLabelResource) iterator
37 + .next();
38 + print(FMT, defaultLabelResource.deviceId().toString(),
39 + defaultLabelResource.labelResourceId().toString());
40 + }
41 + }
42 + }
43 +
44 +}
1 +package org.onosproject.cli.net;
2 +
3 +import org.apache.karaf.shell.commands.Argument;
4 +import org.apache.karaf.shell.commands.Command;
5 +import org.onosproject.cli.AbstractShellCommand;
6 +import org.onosproject.net.resource.LabelResourceAdminService;
7 +import org.onosproject.net.resource.LabelResourceId;
8 +
9 +/**
10 + * create label resource pool by specific device id.
11 + */
12 +@Command(scope = "onos", name = "create-global-label-resource-pool",
13 +description = "Creates global label resource pool.")
14 +public class CreateGlobalLabelResourcePoolCommand extends AbstractShellCommand {
15 + @Argument(index = 0, name = "beginLabel",
16 + description = "The first label of global label resource pool.",
17 + required = true, multiValued = false)
18 + String beginLabel = null;
19 + @Argument(index = 1, name = "endLabel",
20 + description = "The last label of global label resource pool.",
21 + required = true, multiValued = false)
22 + String endLabel = null;
23 +
24 + @Override
25 + protected void execute() {
26 + LabelResourceAdminService lrs = get(LabelResourceAdminService.class);
27 + lrs.createGlobalPool(LabelResourceId.labelResourceId(Long
28 + .parseLong(beginLabel)), LabelResourceId.labelResourceId(Long
29 + .parseLong(endLabel)));
30 + }
31 +
32 +}
1 +package org.onosproject.cli.net;
2 +
3 +import org.apache.karaf.shell.commands.Argument;
4 +import org.apache.karaf.shell.commands.Command;
5 +import org.onosproject.cli.AbstractShellCommand;
6 +import org.onosproject.net.DeviceId;
7 +import org.onosproject.net.resource.LabelResourceAdminService;
8 +import org.onosproject.net.resource.LabelResourceId;
9 +
10 +/**
11 + * create label resource pool by specific device id.
12 + */
13 +@Command(scope = "onos", name = "create-label-resource-pool",
14 + description = "Creates label resource pool by a specific device id")
15 +public class CreateLabelResourcePoolCommand extends AbstractShellCommand {
16 + @Argument(index = 0, name = "deviceId", description = "Device identity", required = true, multiValued = false)
17 + String deviceId = null;
18 + @Argument(index = 1, name = "beginLabel",
19 + description = "The first label of global label resource pool.", required = true, multiValued = false)
20 + String beginLabel = null;
21 + @Argument(index = 2, name = "endLabel",
22 + description = "The last label of global label resource pool.", required = true, multiValued = false)
23 + String endLabel = null;
24 +
25 + @Override
26 + protected void execute() {
27 + LabelResourceAdminService lrs = get(LabelResourceAdminService.class);
28 + lrs.createDevicePool(DeviceId.deviceId(deviceId), LabelResourceId
29 + .labelResourceId(Long.parseLong(beginLabel)), LabelResourceId
30 + .labelResourceId(Long.parseLong(endLabel)));
31 + }
32 +
33 +}
1 +package org.onosproject.cli.net;
2 +
3 +import org.apache.karaf.shell.commands.Command;
4 +import org.onosproject.cli.AbstractShellCommand;
5 +import org.onosproject.net.resource.LabelResourceAdminService;
6 +
7 +@Command(scope = "onos", name = "destroy-global-label-resource-pool",
8 +description = "Destroys global label resource pool")
9 +public class DestroyGlobalLabelResourcePoolCommand extends AbstractShellCommand {
10 + @Override
11 + protected void execute() {
12 + LabelResourceAdminService lrs = get(LabelResourceAdminService.class);
13 + lrs.destroyGlobalPool();
14 + }
15 +
16 +}
1 +package org.onosproject.cli.net;
2 +
3 +import org.apache.karaf.shell.commands.Argument;
4 +import org.apache.karaf.shell.commands.Command;
5 +import org.onosproject.cli.AbstractShellCommand;
6 +import org.onosproject.net.DeviceId;
7 +import org.onosproject.net.resource.LabelResourceAdminService;
8 +
9 +@Command(scope = "onos", name = "destroy-label-resource-pool",
10 + description = "Destroys label resource pool by a specific device id")
11 +public class DestroyLabelResourcePoolCommand extends AbstractShellCommand {
12 + @Argument(index = 0, name = "deviceId", description = "Device identity", required = true, multiValued = false)
13 + String deviceId = null;
14 +
15 + @Override
16 + protected void execute() {
17 + LabelResourceAdminService lrs = get(LabelResourceAdminService.class);
18 + lrs.destroyDevicePool(DeviceId.deviceId(deviceId));
19 + }
20 +
21 +}
1 +package org.onosproject.cli.net;
2 +
3 +import org.apache.karaf.shell.commands.Command;
4 +import org.onosproject.cli.AbstractShellCommand;
5 +import org.onosproject.net.resource.LabelResourcePool;
6 +import org.onosproject.net.resource.LabelResourceService;
7 +
8 +@Command(scope = "onos", name = "get-global-label-resource-pool",
9 + description = "Gets global label resource pool information.")
10 +public class GetGlobalLabelResourceCommand extends AbstractShellCommand {
11 + private static final String FMT = "deviceid=%s, beginLabel=%s,"
12 + + "endLabel=%s, totalNum=%s, usedNum=%s, currentUsedMaxLabelId=%s,"
13 + + "releaseLabelIds=%s";
14 +
15 + @Override
16 + protected void execute() {
17 + LabelResourceService lrs = get(LabelResourceService.class);
18 + LabelResourcePool pool = lrs.getGlobalLabelResourcePool();
19 + if (pool != null) {
20 + print(FMT, pool.deviceId().toString(), pool.beginLabel(),
21 + pool.endLabel(), pool.totalNum(), pool.usedNum(),
22 + pool.currentUsedMaxLabelId(), pool.releaseLabelId()
23 + .toString());
24 + }
25 + }
26 +
27 +}
1 +package org.onosproject.cli.net;
2 +
3 +import org.apache.karaf.shell.commands.Argument;
4 +import org.apache.karaf.shell.commands.Command;
5 +import org.onosproject.cli.AbstractShellCommand;
6 +import org.onosproject.net.DeviceId;
7 +import org.onosproject.net.resource.LabelResourcePool;
8 +import org.onosproject.net.resource.LabelResourceService;
9 +
10 +@Command(scope = "onos", name = "get-label-resource-pool",
11 + description = "Gets label resource pool information by a specific device id")
12 +public class GetLabelResourceCommand extends AbstractShellCommand {
13 + @Argument(index = 0, name = "deviceId",
14 + description = "Device identity", required = true, multiValued = false)
15 + String deviceId = null;
16 + private static final String FMT = "deviceid=%s, beginLabel=%s,"
17 + + "endLabel=%s, totalNum=%s, usedNum=%s, currentUsedMaxLabelId=%s,"
18 + + "releaseLabelIds=%s";
19 +
20 + @Override
21 + protected void execute() {
22 + LabelResourceService lrs = get(LabelResourceService.class);
23 + LabelResourcePool pool = lrs.getDeviceLabelResourcePool(DeviceId
24 + .deviceId(deviceId));
25 + if (pool != null) {
26 + print(FMT, pool.deviceId().toString(), pool.beginLabel(),
27 + pool.endLabel(), pool.totalNum(), pool.usedNum(),
28 + pool.currentUsedMaxLabelId(), pool.releaseLabelId()
29 + .toString());
30 + } else {
31 + print(FMT, deviceId, null, null, null, null, null, null);
32 + }
33 + }
34 +
35 +}
1 +package org.onosproject.cli.net;
2 +
3 +import java.util.HashSet;
4 +import java.util.Set;
5 +
6 +import org.apache.karaf.shell.commands.Argument;
7 +import org.apache.karaf.shell.commands.Command;
8 +import org.onosproject.cli.AbstractShellCommand;
9 +import org.onosproject.net.resource.LabelResourceId;
10 +import org.onosproject.net.resource.LabelResourceService;
11 +
12 +@Command(scope = "onos", name = "release-global-label-resource-pool",
13 +description = "Releases labels to global label resource pool.")
14 +public class ReleaseGlobalLabelResourceCommand extends AbstractShellCommand {
15 + @Argument(index = 0, name = "releaseLabelIds",
16 + description = "Represents for the label ids that are released. They are splited by dot symbol",
17 + required = true, multiValued = false)
18 + String releaseLabelIds = null;
19 +
20 + @Override
21 + protected void execute() {
22 + LabelResourceService lrs = get(LabelResourceService.class);
23 + Set<LabelResourceId> release = new HashSet<LabelResourceId>();
24 + String[] labelIds = releaseLabelIds.split(",");
25 + LabelResourceId resource = null;
26 + for (int i = 0; i < labelIds.length; i++) {
27 + resource = LabelResourceId.labelResourceId(Long.parseLong(labelIds[i]));
28 + release.add(resource);
29 + }
30 + lrs.releaseToGlobalPool(release);
31 + }
32 +
33 +}
1 +package org.onosproject.cli.net;
2 +
3 +import org.apache.karaf.shell.commands.Argument;
4 +import org.apache.karaf.shell.commands.Command;
5 +import org.onosproject.cli.AbstractShellCommand;
6 +import org.onosproject.net.DeviceId;
7 +import org.onosproject.net.resource.DefaultLabelResource;
8 +import org.onosproject.net.resource.LabelResource;
9 +import org.onosproject.net.resource.LabelResourceId;
10 +import org.onosproject.net.resource.LabelResourceService;
11 +
12 +import com.google.common.collect.ArrayListMultimap;
13 +import com.google.common.collect.Multimap;
14 +
15 +@Command(scope = "onos", name = "release-label-resource-pool",
16 +description = "Releases label ids to label resource pool by a specific device id")
17 +public class ReleaseLabelResourceCommand extends AbstractShellCommand {
18 + @Argument(index = 0, name = "deviceId",
19 + description = "Device identity",
20 + required = true, multiValued = false)
21 + String deviceId = null;
22 + @Argument(index = 1, name = "releaseLabelIds",
23 + description = "Represents for the label ids that are released. They are splited by dot symbol",
24 + required = true, multiValued = false)
25 + String releaseLabelIds = null;
26 +
27 + @Override
28 + protected void execute() {
29 + LabelResourceService lrs = get(LabelResourceService.class);
30 + Multimap<DeviceId, LabelResource> map = ArrayListMultimap
31 + .create();
32 + String[] labelIds = releaseLabelIds.split(",");
33 + DefaultLabelResource resource = null;
34 + for (int i = 0; i < labelIds.length; i++) {
35 + resource = new DefaultLabelResource(
36 + DeviceId.deviceId(deviceId),
37 + LabelResourceId.labelResourceId(Long
38 + .parseLong(labelIds[i])));
39 + map.put(DeviceId.deviceId(deviceId), resource);
40 + }
41 + lrs.releaseToDevicePool(map);
42 + }
43 +
44 +}
...@@ -38,7 +38,6 @@ ...@@ -38,7 +38,6 @@
38 <ref component-id="cfgCommandCompleter"/> 38 <ref component-id="cfgCommandCompleter"/>
39 <ref component-id="componentNameCompleter"/> 39 <ref component-id="componentNameCompleter"/>
40 <ref component-id="componentPropertyNameCompleter"/> 40 <ref component-id="componentPropertyNameCompleter"/>
41 - <null/>
42 </completers> 41 </completers>
43 </command> 42 </command>
44 43
...@@ -67,7 +66,6 @@ ...@@ -67,7 +66,6 @@
67 <action class="org.onosproject.cli.net.DriversListCommand"/> 66 <action class="org.onosproject.cli.net.DriversListCommand"/>
68 <completers> 67 <completers>
69 <ref component-id="driverNameCompleter"/> 68 <ref component-id="driverNameCompleter"/>
70 - <null/>
71 </completers> 69 </completers>
72 </command> 70 </command>
73 71
...@@ -78,14 +76,12 @@ ...@@ -78,14 +76,12 @@
78 <action class="org.onosproject.cli.net.DevicePortsListCommand"/> 76 <action class="org.onosproject.cli.net.DevicePortsListCommand"/>
79 <completers> 77 <completers>
80 <ref component-id="deviceIdCompleter"/> 78 <ref component-id="deviceIdCompleter"/>
81 - <null/>
82 </completers> 79 </completers>
83 </command> 80 </command>
84 <command> 81 <command>
85 <action class="org.onosproject.cli.net.DeviceRemoveCommand"/> 82 <action class="org.onosproject.cli.net.DeviceRemoveCommand"/>
86 <completers> 83 <completers>
87 <ref component-id="deviceIdCompleter"/> 84 <ref component-id="deviceIdCompleter"/>
88 - <null/>
89 </completers> 85 </completers>
90 </command> 86 </command>
91 <command> 87 <command>
...@@ -94,14 +90,12 @@ ...@@ -94,14 +90,12 @@
94 <ref component-id="deviceIdCompleter"/> 90 <ref component-id="deviceIdCompleter"/>
95 <ref component-id="nodeIdCompleter"/> 91 <ref component-id="nodeIdCompleter"/>
96 <ref component-id="roleCompleter"/> 92 <ref component-id="roleCompleter"/>
97 - <null/>
98 </completers> 93 </completers>
99 </command> 94 </command>
100 <command> 95 <command>
101 <action class="org.onosproject.cli.net.AnnotateDeviceCommand"/> 96 <action class="org.onosproject.cli.net.AnnotateDeviceCommand"/>
102 <completers> 97 <completers>
103 <ref component-id="deviceIdCompleter"/> 98 <ref component-id="deviceIdCompleter"/>
104 - <null/>
105 </completers> 99 </completers>
106 </command> 100 </command>
107 101
...@@ -109,7 +103,6 @@ ...@@ -109,7 +103,6 @@
109 <action class="org.onosproject.cli.net.LinksListCommand"/> 103 <action class="org.onosproject.cli.net.LinksListCommand"/>
110 <completers> 104 <completers>
111 <ref component-id="deviceIdCompleter"/> 105 <ref component-id="deviceIdCompleter"/>
112 - <null/>
113 </completers> 106 </completers>
114 </command> 107 </command>
115 108
...@@ -121,7 +114,6 @@ ...@@ -121,7 +114,6 @@
121 <completers> 114 <completers>
122 <ref component-id="deviceIdCompleter"/> 115 <ref component-id="deviceIdCompleter"/>
123 <ref component-id="deviceIdCompleter"/> 116 <ref component-id="deviceIdCompleter"/>
124 - <null/>
125 </completers> 117 </completers>
126 </command> 118 </command>
127 119
...@@ -133,7 +125,6 @@ ...@@ -133,7 +125,6 @@
133 <completers> 125 <completers>
134 <ref component-id="appIdWithIntentNameCompleter"/> 126 <ref component-id="appIdWithIntentNameCompleter"/>
135 <ref component-id="intentIdCompleter"/> 127 <ref component-id="intentIdCompleter"/>
136 - <null/>
137 </completers> 128 </completers>
138 </command> 129 </command>
139 <command> 130 <command>
...@@ -141,7 +132,6 @@ ...@@ -141,7 +132,6 @@
141 <completers> 132 <completers>
142 <ref component-id="hostIdCompleter"/> 133 <ref component-id="hostIdCompleter"/>
143 <ref component-id="hostIdCompleter"/> 134 <ref component-id="hostIdCompleter"/>
144 - <null/>
145 </completers> 135 </completers>
146 <optional-completers> 136 <optional-completers>
147 <entry key="-t" value-ref="ethTypeCompleter"/> 137 <entry key="-t" value-ref="ethTypeCompleter"/>
...@@ -157,7 +147,6 @@ ...@@ -157,7 +147,6 @@
157 <completers> 147 <completers>
158 <ref component-id="connectPointCompleter"/> 148 <ref component-id="connectPointCompleter"/>
159 <ref component-id="connectPointCompleter"/> 149 <ref component-id="connectPointCompleter"/>
160 - <null/>
161 </completers> 150 </completers>
162 <optional-completers> 151 <optional-completers>
163 <entry key="-t" value-ref="ethTypeCompleter"/> 152 <entry key="-t" value-ref="ethTypeCompleter"/>
...@@ -173,7 +162,6 @@ ...@@ -173,7 +162,6 @@
173 <completers> 162 <completers>
174 <ref component-id="connectPointCompleter"/> 163 <ref component-id="connectPointCompleter"/>
175 <ref component-id="connectPointCompleter"/> 164 <ref component-id="connectPointCompleter"/>
176 - <null/>
177 </completers> 165 </completers>
178 <optional-completers> 166 <optional-completers>
179 <entry key="-a" value-ref="allAppNameCompleter"/> 167 <entry key="-a" value-ref="allAppNameCompleter"/>
...@@ -219,7 +207,6 @@ ...@@ -219,7 +207,6 @@
219 <ref component-id="connectPointCompleter"/> 207 <ref component-id="connectPointCompleter"/>
220 <ref component-id="connectPointCompleter"/> 208 <ref component-id="connectPointCompleter"/>
221 <ref component-id="nullCompleter"/> 209 <ref component-id="nullCompleter"/>
222 - <null/>
223 </completers> 210 </completers>
224 </command> 211 </command>
225 <command> 212 <command>
...@@ -228,14 +215,12 @@ ...@@ -228,14 +215,12 @@
228 <ref component-id="connectPointCompleter"/> 215 <ref component-id="connectPointCompleter"/>
229 <ref component-id="connectPointCompleter"/> 216 <ref component-id="connectPointCompleter"/>
230 <ref component-id="nullCompleter"/> 217 <ref component-id="nullCompleter"/>
231 - <null/>
232 </completers> 218 </completers>
233 </command> 219 </command>
234 <command> 220 <command>
235 <action class="org.onosproject.cli.net.RandomIntentCommand"/> 221 <action class="org.onosproject.cli.net.RandomIntentCommand"/>
236 <completers> 222 <completers>
237 <ref component-id="nullCompleter"/> 223 <ref component-id="nullCompleter"/>
238 - <null/>
239 </completers> 224 </completers>
240 </command> 225 </command>
241 <command> 226 <command>
...@@ -243,7 +228,6 @@ ...@@ -243,7 +228,6 @@
243 <completers> 228 <completers>
244 <ref component-id="connectPointCompleter"/> 229 <ref component-id="connectPointCompleter"/>
245 <ref component-id="connectPointCompleter"/> 230 <ref component-id="connectPointCompleter"/>
246 - <null/>
247 </completers> 231 </completers>
248 </command> 232 </command>
249 <command> 233 <command>
...@@ -251,7 +235,6 @@ ...@@ -251,7 +235,6 @@
251 <completers> 235 <completers>
252 <ref component-id="connectPointCompleter"/> 236 <ref component-id="connectPointCompleter"/>
253 <ref component-id="connectPointCompleter"/> 237 <ref component-id="connectPointCompleter"/>
254 - <null/>
255 </completers> 238 </completers>
256 </command> 239 </command>
257 <command> 240 <command>
...@@ -281,14 +264,12 @@ ...@@ -281,14 +264,12 @@
281 <action class="org.onosproject.cli.net.ClusterDevicesCommand"/> 264 <action class="org.onosproject.cli.net.ClusterDevicesCommand"/>
282 <completers> 265 <completers>
283 <ref component-id="clusterIdCompleter"/> 266 <ref component-id="clusterIdCompleter"/>
284 - <null/>
285 </completers> 267 </completers>
286 </command> 268 </command>
287 <command> 269 <command>
288 <action class="org.onosproject.cli.net.ClusterLinksCommand"/> 270 <action class="org.onosproject.cli.net.ClusterLinksCommand"/>
289 <completers> 271 <completers>
290 <ref component-id="clusterIdCompleter"/> 272 <ref component-id="clusterIdCompleter"/>
291 - <null/>
292 </completers> 273 </completers>
293 </command> 274 </command>
294 275
...@@ -299,7 +280,6 @@ ...@@ -299,7 +280,6 @@
299 <action class="org.onosproject.cli.net.HostRemoveCommand"/> 280 <action class="org.onosproject.cli.net.HostRemoveCommand"/>
300 <completers> 281 <completers>
301 <ref component-id="hostIdCompleter"/> 282 <ref component-id="hostIdCompleter"/>
302 - <null/>
303 </completers> 283 </completers>
304 </command> 284 </command>
305 <command> 285 <command>
...@@ -319,7 +299,6 @@ ...@@ -319,7 +299,6 @@
319 <completers> 299 <completers>
320 <ref component-id="flowRuleStatusCompleter"/> 300 <ref component-id="flowRuleStatusCompleter"/>
321 <ref component-id="deviceIdCompleter"/> 301 <ref component-id="deviceIdCompleter"/>
322 - <null/>
323 </completers> 302 </completers>
324 </command> 303 </command>
325 304
...@@ -338,7 +317,6 @@ ...@@ -338,7 +317,6 @@
338 <completers> 317 <completers>
339 <ref component-id="connectPointCompleter"/> 318 <ref component-id="connectPointCompleter"/>
340 <ref component-id="connectPointCompleter"/> 319 <ref component-id="connectPointCompleter"/>
341 - <null/>
342 </completers> 320 </completers>
343 <optional-completers> 321 <optional-completers>
344 <entry key="-t" value-ref="ethTypeCompleter"/> 322 <entry key="-t" value-ref="ethTypeCompleter"/>
...@@ -349,6 +327,37 @@ ...@@ -349,6 +327,37 @@
349 <entry key="-a" value-ref="allAppNameCompleter"/> 327 <entry key="-a" value-ref="allAppNameCompleter"/>
350 </optional-completers> 328 </optional-completers>
351 </command> 329 </command>
330 +
331 + <command>
332 + <action class="org.onosproject.cli.net.GetGlobalLabelResourceCommand"/>
333 + </command>
334 + <command>
335 + <action class="org.onosproject.cli.net.GetLabelResourceCommand"/>
336 + </command>
337 + <command>
338 + <action class="org.onosproject.cli.net.CreateGlobalLabelResourcePoolCommand"/>
339 + </command>
340 + <command>
341 + <action class="org.onosproject.cli.net.CreateLabelResourcePoolCommand"/>
342 + </command>
343 + <command>
344 + <action class="org.onosproject.cli.net.DestroyGlobalLabelResourcePoolCommand"/>
345 + </command>
346 + <command>
347 + <action class="org.onosproject.cli.net.DestroyGlobalLabelResourcePoolCommand"/>
348 + </command>
349 + <command>
350 + <action class="org.onosproject.cli.net.ReleaseGlobalLabelResourceCommand"/>
351 + </command>
352 + <command>
353 + <action class="org.onosproject.cli.net.ReleaseLabelResourceCommand"/>
354 + </command>
355 + <command>
356 + <action class="org.onosproject.cli.net.ApplyGlobalLabelResourceCommand"/>
357 + </command>
358 + <command>
359 + <action class="org.onosproject.cli.net.ApplyLabelResourceCommand"/>
360 + </command>
352 </command-bundle> 361 </command-bundle>
353 362
354 <bean id="appCommandCompleter" class="org.onosproject.cli.app.ApplicationCommandCompleter"/> 363 <bean id="appCommandCompleter" class="org.onosproject.cli.app.ApplicationCommandCompleter"/>
......
1 +package org.onosproject.net.resource;
2 +
3 +import org.junit.Test;
4 +import org.onosproject.event.AbstractEventTest;
5 +
6 +import com.google.common.testing.EqualsTester;
7 +
8 +/**
9 + * Tests of default label resource.
10 + */
11 +public class DefaultLabelResourceTest extends AbstractEventTest {
12 +
13 + @Test
14 + public void testEquality() {
15 + String deviceId1 = "of:001";
16 + String deviceId2 = "of:002";
17 + long labelResourceId1 = 100;
18 + long labelResourceId2 = 200;
19 + DefaultLabelResource h1 = new DefaultLabelResource(deviceId1,
20 + labelResourceId1);
21 + DefaultLabelResource h2 = new DefaultLabelResource(deviceId1,
22 + labelResourceId1);
23 + DefaultLabelResource h3 = new DefaultLabelResource(deviceId2,
24 + labelResourceId2);
25 + DefaultLabelResource h4 = new DefaultLabelResource(deviceId2,
26 + labelResourceId2);
27 +
28 + new EqualsTester().addEqualityGroup(h1, h2).addEqualityGroup(h3, h4)
29 + .testEquals();
30 + }
31 +}
1 +package org.onosproject.net.resource;
2 +
3 +import org.junit.Test;
4 +import org.onosproject.event.AbstractEventTest;
5 +
6 +import com.google.common.testing.EqualsTester;
7 +
8 +/**
9 + * Tests of the label resource pool.
10 + */
11 +public class LabelResourcePoolTest extends AbstractEventTest {
12 +
13 + @Test
14 + public void testEquality() {
15 + LabelResourcePool h1 = new LabelResourcePool("of:001", 0, 100);
16 + LabelResourcePool h2 = new LabelResourcePool("of:001", 0, 100);
17 + LabelResourcePool h3 = new LabelResourcePool("of:002", 0, 100);
18 + LabelResourcePool h4 = new LabelResourcePool("of:002", 0, 100);
19 + new EqualsTester().addEqualityGroup(h1, h2).addEqualityGroup(h3, h4)
20 + .testEquals();
21 + }
22 +
23 +}
1 +package org.onosproject.net.resource;
2 +
3 +import java.util.Collections;
4 +
5 +import org.junit.Test;
6 +import org.onosproject.event.AbstractEventTest;
7 +import org.onosproject.net.DeviceId;
8 +
9 +import com.google.common.collect.ImmutableSet;
10 +import com.google.common.testing.EqualsTester;
11 +
12 +/**
13 + * Tests of the label resource request.
14 + */
15 +public class LabelResourceRequestTest extends AbstractEventTest {
16 +
17 + @Test
18 + public void testEquality() {
19 + DeviceId deviceId1 = DeviceId.deviceId("of:0001");
20 + DeviceId deviceId2 = DeviceId.deviceId("of:0002");
21 + long apply = 2;
22 + ImmutableSet<LabelResource> releaseCollection = ImmutableSet
23 + .copyOf(Collections.emptySet());
24 + LabelResourceRequest h1 = new LabelResourceRequest(
25 + deviceId1,
26 + LabelResourceRequest.Type.APPLY,
27 + apply, null);
28 + LabelResourceRequest h2 = new LabelResourceRequest(
29 + deviceId1,
30 + LabelResourceRequest.Type.APPLY,
31 + apply, null);
32 + LabelResourceRequest h3 = new LabelResourceRequest(
33 + deviceId2,
34 + LabelResourceRequest.Type.RELEASE,
35 + 0, releaseCollection);
36 + LabelResourceRequest h4 = new LabelResourceRequest(
37 + deviceId2,
38 + LabelResourceRequest.Type.RELEASE,
39 + 0, releaseCollection);
40 +
41 + new EqualsTester().addEqualityGroup(h1, h2).addEqualityGroup(h3, h4)
42 + .testEquals();
43 + }
44 +}
1 +package org.onosproject.net.resource.impl;
2 +
3 +import static org.slf4j.LoggerFactory.getLogger;
4 +
5 +import java.util.Collection;
6 +import java.util.Set;
7 +
8 +import org.apache.felix.scr.annotations.Activate;
9 +import org.apache.felix.scr.annotations.Component;
10 +import org.apache.felix.scr.annotations.Deactivate;
11 +import org.apache.felix.scr.annotations.Reference;
12 +import org.apache.felix.scr.annotations.ReferenceCardinality;
13 +import org.apache.felix.scr.annotations.Service;
14 +import org.onosproject.event.AbstractListenerRegistry;
15 +import org.onosproject.event.EventDeliveryService;
16 +import org.onosproject.net.Device;
17 +import org.onosproject.net.DeviceId;
18 +import org.onosproject.net.device.DeviceEvent;
19 +import org.onosproject.net.device.DeviceEvent.Type;
20 +import org.onosproject.net.device.DeviceListener;
21 +import org.onosproject.net.device.DeviceService;
22 +import org.onosproject.net.provider.AbstractProviderRegistry;
23 +import org.onosproject.net.provider.AbstractProviderService;
24 +import org.onosproject.net.resource.LabelResource;
25 +import org.onosproject.net.resource.LabelResourceAdminService;
26 +import org.onosproject.net.resource.LabelResourceDelegate;
27 +import org.onosproject.net.resource.LabelResourceEvent;
28 +import org.onosproject.net.resource.LabelResourceId;
29 +import org.onosproject.net.resource.LabelResourceListener;
30 +import org.onosproject.net.resource.LabelResourcePool;
31 +import org.onosproject.net.resource.LabelResourceProvider;
32 +import org.onosproject.net.resource.LabelResourceProviderRegistry;
33 +import org.onosproject.net.resource.LabelResourceProviderService;
34 +import org.onosproject.net.resource.LabelResourceService;
35 +import org.onosproject.net.resource.LabelResourceStore;
36 +import org.slf4j.Logger;
37 +import static com.google.common.base.Preconditions.checkNotNull;
38 +import static com.google.common.base.Preconditions.checkArgument;
39 +
40 +import com.google.common.collect.Multimap;
41 +
42 +/**
43 + * provides implementation of the label resource NB &amp; SB APIs.
44 + *
45 + */
46 +@Component(immediate = true)
47 +@Service
48 +public class LabelResourceManager
49 + extends
50 + AbstractProviderRegistry<LabelResourceProvider, LabelResourceProviderService>
51 + implements LabelResourceService, LabelResourceAdminService,
52 + LabelResourceProviderRegistry {
53 + private final Logger log = getLogger(getClass());
54 + private final LabelResourceDelegate delegate = new InternalLabelResourceDelegate();
55 +
56 + private final AbstractListenerRegistry<LabelResourceEvent, LabelResourceListener> listenerRegistry
57 + = new AbstractListenerRegistry<>();
58 +
59 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
60 + protected LabelResourceStore store;
61 +
62 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
63 + protected EventDeliveryService eventDispatcher;
64 +
65 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
66 + protected DeviceService deviceService;
67 +
68 + private DeviceListener deviceListener = new InternalDeviceListener();
69 +
70 + @Activate
71 + public void activate() {
72 + store.setDelegate(delegate);
73 + eventDispatcher.addSink(LabelResourceEvent.class, listenerRegistry);
74 + deviceService.addListener(deviceListener);
75 + log.info("Started");
76 +
77 + }
78 +
79 + @Deactivate
80 + public void deactivate() {
81 + deviceService.removeListener(deviceListener);
82 + store.unsetDelegate(delegate);
83 + eventDispatcher.removeSink(LabelResourceEvent.class);
84 + log.info("Stopped");
85 + }
86 +
87 + @Override
88 + public boolean createDevicePool(DeviceId deviceId,
89 + LabelResourceId beginLabel,
90 + LabelResourceId endLabel) {
91 + checkNotNull(deviceId, "deviceId is not null");
92 + checkNotNull(beginLabel, "beginLabel is not null");
93 + checkNotNull(endLabel, "beginLabel is not null");
94 + checkArgument(beginLabel.labelId() < 0 || endLabel.labelId() < 0,
95 + "The value of beginLabel and the value of endLabel must be both positive number.");
96 + checkArgument(beginLabel.labelId() > endLabel.labelId(),
97 + "The value of endLabel must be greater than the value of endLabel.");
98 + return store.createDevicePool(deviceId, beginLabel, endLabel);
99 + }
100 +
101 + @Override
102 + public boolean createGlobalPool(LabelResourceId beginLabel,
103 + LabelResourceId endLabel) {
104 + checkNotNull(beginLabel, "beginLabel is not null");
105 + checkNotNull(endLabel, "beginLabel is not null");
106 + checkArgument(beginLabel.labelId() < 0 || endLabel.labelId() < 0,
107 + "The value of beginLabel and the value of endLabel must be both positive number.");
108 + checkArgument(beginLabel.labelId() > endLabel.labelId(),
109 + "The value of endLabel must be greater than the value of endLabel.");
110 + return store.createGlobalPool(beginLabel, endLabel);
111 + }
112 +
113 + @Override
114 + public boolean destroyDevicePool(DeviceId deviceId) {
115 + checkNotNull(deviceId, "deviceId is not null");
116 + return store.destroyDevicePool(deviceId);
117 + }
118 +
119 + @Override
120 + public boolean destroyGlobalPool() {
121 + return store.destroyGlobalPool();
122 + }
123 +
124 + @Override
125 + public Collection<LabelResource> applyFromDevicePool(DeviceId deviceId,
126 + long applyNum) {
127 + checkNotNull(deviceId, "deviceId is not null");
128 + checkNotNull(applyNum, "applyNum is not null");
129 + return store.applyFromDevicePool(deviceId, applyNum);
130 + }
131 +
132 + @Override
133 + public Collection<LabelResource> applyFromGlobalPool(long applyNum) {
134 + checkNotNull(applyNum, "applyNum is not null");
135 + return store.applyFromGlobalPool(applyNum);
136 + }
137 +
138 + @Override
139 + public boolean releaseToDevicePool(Multimap<DeviceId, LabelResource> release) {
140 + checkNotNull(release, "release is not null");
141 + return store.releaseToDevicePool(release);
142 + }
143 +
144 + @Override
145 + public boolean releaseToGlobalPool(Set<LabelResourceId> release) {
146 + checkNotNull(release, "release is not null");
147 + return store.releaseToGlobalPool(release);
148 + }
149 +
150 + @Override
151 + public boolean isDevicePoolFull(DeviceId deviceId) {
152 + checkNotNull(deviceId, "deviceId is not null");
153 + return store.isDevicePoolFull(deviceId);
154 + }
155 +
156 + @Override
157 + public boolean isGlobalPoolFull() {
158 + return store.isGlobalPoolFull();
159 + }
160 +
161 + @Override
162 + public long getFreeNumOfDevicePool(DeviceId deviceId) {
163 + checkNotNull(deviceId, "deviceId is not null");
164 + return store.getFreeNumOfDevicePool(deviceId);
165 + }
166 +
167 + @Override
168 + public long getFreeNumOfGlobalPool() {
169 + return store.getFreeNumOfGlobalPool();
170 + }
171 +
172 + @Override
173 + public LabelResourcePool getDeviceLabelResourcePool(DeviceId deviceId) {
174 + checkNotNull(deviceId, "deviceId is not null");
175 + return store.getDeviceLabelResourcePool(deviceId);
176 + }
177 +
178 + @Override
179 + public LabelResourcePool getGlobalLabelResourcePool() {
180 + return store.getGlobalLabelResourcePool();
181 + }
182 +
183 + @Override
184 + public void addListener(LabelResourceListener listener) {
185 + listenerRegistry.addListener(listener);
186 + }
187 +
188 + @Override
189 + public void removeListener(LabelResourceListener listener) {
190 + listenerRegistry.removeListener(listener);
191 +
192 + }
193 +
194 + private void post(LabelResourceEvent event) {
195 + if (event != null) {
196 + eventDispatcher.post(event);
197 + }
198 + }
199 +
200 + private class InternalLabelResourceDelegate
201 + implements LabelResourceDelegate {
202 +
203 + @Override
204 + public void notify(LabelResourceEvent event) {
205 + post(event);
206 + }
207 +
208 + }
209 +
210 + private class InternalDeviceListener implements DeviceListener {
211 +
212 + @Override
213 + public void event(DeviceEvent event) {
214 + Device device = event.subject();
215 + if (Type.DEVICE_REMOVED.equals(event.type())) {
216 + destroyDevicePool(device.id());
217 + }
218 + }
219 + }
220 +
221 + private class InternalLabelResourceProviderService
222 + extends AbstractProviderService<LabelResourceProvider>
223 + implements LabelResourceProviderService {
224 +
225 + protected InternalLabelResourceProviderService(LabelResourceProvider provider) {
226 + super(provider);
227 + }
228 +
229 + @Override
230 + public void deviceLabelResourcePoolDetected(DeviceId deviceId,
231 + LabelResourceId beginLabel,
232 + LabelResourceId endLabel) {
233 + checkNotNull(deviceId, "deviceId is not null");
234 + checkNotNull(beginLabel, "beginLabel is not null");
235 + checkNotNull(endLabel, "endLabel is not null");
236 + createDevicePool(deviceId, beginLabel, endLabel);
237 + }
238 +
239 + @Override
240 + public void deviceLabelResourcePoolDestroyed(DeviceId deviceId) {
241 + checkNotNull(deviceId, "deviceId is not null");
242 + destroyDevicePool(deviceId);
243 + }
244 +
245 + }
246 +
247 + @Override
248 + protected LabelResourceProviderService createProviderService(LabelResourceProvider provider) {
249 + return new InternalLabelResourceProviderService(provider);
250 + }
251 +}
1 +package org.onosproject.store.resource.impl;
2 +
3 +import org.onosproject.store.cluster.messaging.MessageSubject;
4 +
5 +public final class LabelResourceMessageSubjects {
6 +
7 + private LabelResourceMessageSubjects() {
8 + }
9 + public static final MessageSubject LABEL_POOL_CREATED
10 + = new MessageSubject("label-resource-pool-created");
11 + public static final MessageSubject LABEL_POOL_DESTROYED
12 + = new MessageSubject("label-resource-pool-destroyed");
13 + public static final MessageSubject LABEL_POOL_APPLY
14 + = new MessageSubject("label-resource-pool-apply");
15 + public static final MessageSubject LABEL_POOL_RELEASE
16 + = new MessageSubject("label-resource-pool-release");
17 +}