Thomas Vachuska

Added application ID store; both trivial and distributed variants.

Showing 65 changed files with 651 additions and 157 deletions
...@@ -30,8 +30,8 @@ import org.apache.felix.scr.annotations.Modified; ...@@ -30,8 +30,8 @@ import org.apache.felix.scr.annotations.Modified;
30 import org.apache.felix.scr.annotations.Property; 30 import org.apache.felix.scr.annotations.Property;
31 import org.apache.felix.scr.annotations.Reference; 31 import org.apache.felix.scr.annotations.Reference;
32 import org.apache.felix.scr.annotations.ReferenceCardinality; 32 import org.apache.felix.scr.annotations.ReferenceCardinality;
33 -import org.onlab.onos.ApplicationId; 33 +import org.onlab.onos.core.ApplicationId;
34 -import org.onlab.onos.CoreService; 34 +import org.onlab.onos.core.CoreService;
35 import org.onlab.onos.net.Host; 35 import org.onlab.onos.net.Host;
36 import org.onlab.onos.net.HostId; 36 import org.onlab.onos.net.HostId;
37 import org.onlab.onos.net.Path; 37 import org.onlab.onos.net.Path;
......
...@@ -23,8 +23,8 @@ import org.apache.felix.scr.annotations.Component; ...@@ -23,8 +23,8 @@ import org.apache.felix.scr.annotations.Component;
23 import org.apache.felix.scr.annotations.Deactivate; 23 import org.apache.felix.scr.annotations.Deactivate;
24 import org.apache.felix.scr.annotations.Reference; 24 import org.apache.felix.scr.annotations.Reference;
25 import org.apache.felix.scr.annotations.ReferenceCardinality; 25 import org.apache.felix.scr.annotations.ReferenceCardinality;
26 -import org.onlab.onos.ApplicationId; 26 +import org.onlab.onos.core.ApplicationId;
27 -import org.onlab.onos.CoreService; 27 +import org.onlab.onos.core.CoreService;
28 import org.onlab.onos.net.Host; 28 import org.onlab.onos.net.Host;
29 import org.onlab.onos.net.HostId; 29 import org.onlab.onos.net.HostId;
30 import org.onlab.onos.net.PortNumber; 30 import org.onlab.onos.net.PortNumber;
......
...@@ -27,8 +27,8 @@ import org.apache.felix.scr.annotations.Component; ...@@ -27,8 +27,8 @@ import org.apache.felix.scr.annotations.Component;
27 import org.apache.felix.scr.annotations.Deactivate; 27 import org.apache.felix.scr.annotations.Deactivate;
28 import org.apache.felix.scr.annotations.Reference; 28 import org.apache.felix.scr.annotations.Reference;
29 import org.apache.felix.scr.annotations.ReferenceCardinality; 29 import org.apache.felix.scr.annotations.ReferenceCardinality;
30 -import org.onlab.onos.ApplicationId; 30 +import org.onlab.onos.core.ApplicationId;
31 -import org.onlab.onos.CoreService; 31 +import org.onlab.onos.core.CoreService;
32 import org.onlab.onos.net.Device; 32 import org.onlab.onos.net.Device;
33 import org.onlab.onos.net.Host; 33 import org.onlab.onos.net.Host;
34 import org.onlab.onos.net.device.DeviceService; 34 import org.onlab.onos.net.device.DeviceService;
......
...@@ -30,8 +30,8 @@ import org.apache.felix.scr.annotations.Component; ...@@ -30,8 +30,8 @@ import org.apache.felix.scr.annotations.Component;
30 import org.apache.felix.scr.annotations.Deactivate; 30 import org.apache.felix.scr.annotations.Deactivate;
31 import org.apache.felix.scr.annotations.Reference; 31 import org.apache.felix.scr.annotations.Reference;
32 import org.apache.felix.scr.annotations.ReferenceCardinality; 32 import org.apache.felix.scr.annotations.ReferenceCardinality;
33 -import org.onlab.onos.ApplicationId; 33 +import org.onlab.onos.core.ApplicationId;
34 -import org.onlab.onos.CoreService; 34 +import org.onlab.onos.core.CoreService;
35 import org.onlab.onos.net.ConnectPoint; 35 import org.onlab.onos.net.ConnectPoint;
36 import org.onlab.onos.net.Link; 36 import org.onlab.onos.net.Link;
37 import org.onlab.onos.net.Path; 37 import org.onlab.onos.net.Path;
......
...@@ -27,8 +27,8 @@ import org.apache.felix.scr.annotations.Activate; ...@@ -27,8 +27,8 @@ import org.apache.felix.scr.annotations.Activate;
27 import org.apache.felix.scr.annotations.Deactivate; 27 import org.apache.felix.scr.annotations.Deactivate;
28 import org.apache.felix.scr.annotations.Reference; 28 import org.apache.felix.scr.annotations.Reference;
29 import org.apache.felix.scr.annotations.ReferenceCardinality; 29 import org.apache.felix.scr.annotations.ReferenceCardinality;
30 -import org.onlab.onos.ApplicationId; 30 +import org.onlab.onos.core.ApplicationId;
31 -import org.onlab.onos.CoreService; 31 +import org.onlab.onos.core.CoreService;
32 import org.onlab.onos.net.Device; 32 import org.onlab.onos.net.Device;
33 import org.onlab.onos.net.DeviceId; 33 import org.onlab.onos.net.DeviceId;
34 import org.onlab.onos.net.PortNumber; 34 import org.onlab.onos.net.PortNumber;
......
...@@ -25,8 +25,8 @@ import org.apache.felix.scr.annotations.Component; ...@@ -25,8 +25,8 @@ import org.apache.felix.scr.annotations.Component;
25 import org.apache.felix.scr.annotations.Deactivate; 25 import org.apache.felix.scr.annotations.Deactivate;
26 import org.apache.felix.scr.annotations.Reference; 26 import org.apache.felix.scr.annotations.Reference;
27 import org.apache.felix.scr.annotations.ReferenceCardinality; 27 import org.apache.felix.scr.annotations.ReferenceCardinality;
28 -import org.onlab.onos.ApplicationId; 28 +import org.onlab.onos.core.ApplicationId;
29 -import org.onlab.onos.CoreService; 29 +import org.onlab.onos.core.CoreService;
30 import org.onlab.onos.net.packet.PacketContext; 30 import org.onlab.onos.net.packet.PacketContext;
31 import org.onlab.onos.net.packet.PacketProcessor; 31 import org.onlab.onos.net.packet.PacketProcessor;
32 import org.onlab.onos.net.packet.PacketService; 32 import org.onlab.onos.net.packet.PacketService;
......
...@@ -20,7 +20,7 @@ package org.onlab.onos.sdnip; ...@@ -20,7 +20,7 @@ package org.onlab.onos.sdnip;
20 20
21 import java.util.List; 21 import java.util.List;
22 22
23 -import org.onlab.onos.ApplicationId; 23 +import org.onlab.onos.core.ApplicationId;
24 import org.onlab.onos.net.ConnectPoint; 24 import org.onlab.onos.net.ConnectPoint;
25 import org.onlab.onos.net.flow.DefaultTrafficSelector; 25 import org.onlab.onos.net.flow.DefaultTrafficSelector;
26 import org.onlab.onos.net.flow.DefaultTrafficTreatment; 26 import org.onlab.onos.net.flow.DefaultTrafficTreatment;
......
...@@ -34,7 +34,7 @@ import java.util.concurrent.LinkedBlockingQueue; ...@@ -34,7 +34,7 @@ import java.util.concurrent.LinkedBlockingQueue;
34 import java.util.concurrent.Semaphore; 34 import java.util.concurrent.Semaphore;
35 35
36 import org.apache.commons.lang3.tuple.Pair; 36 import org.apache.commons.lang3.tuple.Pair;
37 -import org.onlab.onos.ApplicationId; 37 +import org.onlab.onos.core.ApplicationId;
38 import org.onlab.onos.net.ConnectPoint; 38 import org.onlab.onos.net.ConnectPoint;
39 import org.onlab.onos.net.Host; 39 import org.onlab.onos.net.Host;
40 import org.onlab.onos.net.flow.DefaultTrafficSelector; 40 import org.onlab.onos.net.flow.DefaultTrafficSelector;
......
...@@ -28,8 +28,8 @@ import org.apache.felix.scr.annotations.Deactivate; ...@@ -28,8 +28,8 @@ import org.apache.felix.scr.annotations.Deactivate;
28 import org.apache.felix.scr.annotations.Reference; 28 import org.apache.felix.scr.annotations.Reference;
29 import org.apache.felix.scr.annotations.ReferenceCardinality; 29 import org.apache.felix.scr.annotations.ReferenceCardinality;
30 import org.apache.felix.scr.annotations.Service; 30 import org.apache.felix.scr.annotations.Service;
31 -import org.onlab.onos.ApplicationId; 31 +import org.onlab.onos.core.ApplicationId;
32 -import org.onlab.onos.CoreService; 32 +import org.onlab.onos.core.CoreService;
33 import org.onlab.onos.net.host.HostService; 33 import org.onlab.onos.net.host.HostService;
34 import org.onlab.onos.net.intent.IntentService; 34 import org.onlab.onos.net.intent.IntentService;
35 import org.onlab.onos.sdnip.bgp.BgpRouteEntry; 35 import org.onlab.onos.sdnip.bgp.BgpRouteEntry;
......
...@@ -23,7 +23,7 @@ import org.easymock.IArgumentMatcher; ...@@ -23,7 +23,7 @@ import org.easymock.IArgumentMatcher;
23 import org.junit.Before; 23 import org.junit.Before;
24 import org.junit.Ignore; 24 import org.junit.Ignore;
25 import org.junit.Test; 25 import org.junit.Test;
26 -import org.onlab.onos.ApplicationId; 26 +import org.onlab.onos.core.ApplicationId;
27 import org.onlab.onos.net.ConnectPoint; 27 import org.onlab.onos.net.ConnectPoint;
28 import org.onlab.onos.net.DeviceId; 28 import org.onlab.onos.net.DeviceId;
29 import org.onlab.onos.net.PortNumber; 29 import org.onlab.onos.net.PortNumber;
......
...@@ -37,7 +37,7 @@ import org.junit.Before; ...@@ -37,7 +37,7 @@ import org.junit.Before;
37 import org.junit.Test; 37 import org.junit.Test;
38 import org.onlab.junit.TestUtils; 38 import org.onlab.junit.TestUtils;
39 import org.onlab.junit.TestUtils.TestUtilsException; 39 import org.onlab.junit.TestUtils.TestUtilsException;
40 -import org.onlab.onos.ApplicationId; 40 +import org.onlab.onos.core.ApplicationId;
41 import org.onlab.onos.net.ConnectPoint; 41 import org.onlab.onos.net.ConnectPoint;
42 import org.onlab.onos.net.DefaultHost; 42 import org.onlab.onos.net.DefaultHost;
43 import org.onlab.onos.net.DeviceId; 43 import org.onlab.onos.net.DeviceId;
......
...@@ -19,7 +19,7 @@ import org.junit.Before; ...@@ -19,7 +19,7 @@ import org.junit.Before;
19 import org.junit.Test; 19 import org.junit.Test;
20 import org.onlab.junit.TestUtils; 20 import org.onlab.junit.TestUtils;
21 import org.onlab.junit.TestUtils.TestUtilsException; 21 import org.onlab.junit.TestUtils.TestUtilsException;
22 -import org.onlab.onos.ApplicationId; 22 +import org.onlab.onos.core.ApplicationId;
23 import org.onlab.onos.net.ConnectPoint; 23 import org.onlab.onos.net.ConnectPoint;
24 import org.onlab.onos.net.DefaultHost; 24 import org.onlab.onos.net.DefaultHost;
25 import org.onlab.onos.net.DeviceId; 25 import org.onlab.onos.net.DeviceId;
......
...@@ -22,8 +22,8 @@ import com.fasterxml.jackson.databind.ObjectMapper; ...@@ -22,8 +22,8 @@ import com.fasterxml.jackson.databind.ObjectMapper;
22 import com.fasterxml.jackson.databind.node.ObjectNode; 22 import com.fasterxml.jackson.databind.node.ObjectNode;
23 import org.apache.karaf.shell.commands.Option; 23 import org.apache.karaf.shell.commands.Option;
24 import org.apache.karaf.shell.console.OsgiCommandSupport; 24 import org.apache.karaf.shell.console.OsgiCommandSupport;
25 -import org.onlab.onos.ApplicationId; 25 +import org.onlab.onos.core.ApplicationId;
26 -import org.onlab.onos.CoreService; 26 +import org.onlab.onos.core.CoreService;
27 import org.onlab.onos.net.Annotations; 27 import org.onlab.onos.net.Annotations;
28 import org.onlab.osgi.DefaultServiceDirectory; 28 import org.onlab.osgi.DefaultServiceDirectory;
29 import org.onlab.osgi.ServiceNotFoundException; 29 import org.onlab.osgi.ServiceNotFoundException;
......
1 +/*
2 + * Licensed to the Apache Software Foundation (ASF) under one
3 + * or more contributor license agreements. See the NOTICE file
4 + * distributed with this work for additional information
5 + * regarding copyright ownership. The ASF licenses this file
6 + * to you under the Apache License, Version 2.0 (the
7 + * "License"); you may not use this file except in compliance
8 + * with the License. You may obtain a copy of the License at
9 + *
10 + * http://www.apache.org/licenses/LICENSE-2.0
11 + *
12 + * Unless required by applicable law or agreed to in writing,
13 + * software distributed under the License is distributed on an
14 + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 + * KIND, either express or implied. See the License for the
16 + * specific language governing permissions and limitations
17 + * under the License.
18 + */
19 +package org.onlab.onos.cli;
20 +
21 +import com.fasterxml.jackson.databind.JsonNode;
22 +import com.fasterxml.jackson.databind.ObjectMapper;
23 +import com.fasterxml.jackson.databind.node.ArrayNode;
24 +import org.apache.karaf.shell.commands.Command;
25 +import org.onlab.onos.core.ApplicationId;
26 +import org.onlab.onos.core.CoreService;
27 +
28 +import java.util.Collections;
29 +import java.util.List;
30 +
31 +import static com.google.common.collect.Lists.newArrayList;
32 +
33 +/**
34 + * Lists application ID information.
35 + */
36 +@Command(scope = "onos", name = "apps",
37 + description = "Lists application ID information")
38 +public class ApplicationIdListCommand extends AbstractShellCommand {
39 +
40 + @Override
41 + protected void execute() {
42 + CoreService service = get(CoreService.class);
43 + List<ApplicationId> ids = newArrayList(service.getAppIds());
44 + Collections.sort(ids, Comparators.APP_ID_COMPARATOR);
45 +
46 + if (outputJson()) {
47 + print("%s", json(ids));
48 + } else {
49 + for (ApplicationId id : ids) {
50 + print("id=%d, name=%s", id.id(), id.name());
51 + }
52 + }
53 + }
54 +
55 + // ApplicationId
56 + private JsonNode json(List<ApplicationId> ids) {
57 + ObjectMapper mapper = new ObjectMapper();
58 + ArrayNode result = mapper.createArrayNode();
59 + for (ApplicationId id : ids) {
60 + result.add(mapper.createObjectNode()
61 + .put("id", id.id())
62 + .put("name", id.name()));
63 + }
64 + return result;
65 + }
66 +
67 +}
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
18 */ 18 */
19 package org.onlab.onos.cli; 19 package org.onlab.onos.cli;
20 20
21 +import org.onlab.onos.core.ApplicationId;
21 import org.onlab.onos.cluster.ControllerNode; 22 import org.onlab.onos.cluster.ControllerNode;
22 import org.onlab.onos.net.Element; 23 import org.onlab.onos.net.Element;
23 import org.onlab.onos.net.ElementId; 24 import org.onlab.onos.net.ElementId;
...@@ -36,6 +37,13 @@ public final class Comparators { ...@@ -36,6 +37,13 @@ public final class Comparators {
36 private Comparators() { 37 private Comparators() {
37 } 38 }
38 39
40 + public static final Comparator<ApplicationId> APP_ID_COMPARATOR = new Comparator<ApplicationId>() {
41 + @Override
42 + public int compare(ApplicationId id1, ApplicationId id2) {
43 + return id1.id() - id2.id();
44 + }
45 + };
46 +
39 public static final Comparator<ElementId> ELEMENT_ID_COMPARATOR = new Comparator<ElementId>() { 47 public static final Comparator<ElementId> ELEMENT_ID_COMPARATOR = new Comparator<ElementId>() {
40 @Override 48 @Override
41 public int compare(ElementId id1, ElementId id2) { 49 public int compare(ElementId id1, ElementId id2) {
......
...@@ -20,7 +20,7 @@ package org.onlab.onos.cli; ...@@ -20,7 +20,7 @@ package org.onlab.onos.cli;
20 20
21 import com.fasterxml.jackson.databind.ObjectMapper; 21 import com.fasterxml.jackson.databind.ObjectMapper;
22 import org.apache.karaf.shell.commands.Command; 22 import org.apache.karaf.shell.commands.Command;
23 -import org.onlab.onos.CoreService; 23 +import org.onlab.onos.core.CoreService;
24 import org.onlab.onos.cluster.ClusterService; 24 import org.onlab.onos.cluster.ClusterService;
25 import org.onlab.onos.net.device.DeviceService; 25 import org.onlab.onos.net.device.DeviceService;
26 import org.onlab.onos.net.flow.FlowRuleService; 26 import org.onlab.onos.net.flow.FlowRuleService;
......
...@@ -25,7 +25,7 @@ import com.fasterxml.jackson.databind.node.ObjectNode; ...@@ -25,7 +25,7 @@ import com.fasterxml.jackson.databind.node.ObjectNode;
25 import com.google.common.collect.Maps; 25 import com.google.common.collect.Maps;
26 import org.apache.karaf.shell.commands.Argument; 26 import org.apache.karaf.shell.commands.Argument;
27 import org.apache.karaf.shell.commands.Command; 27 import org.apache.karaf.shell.commands.Command;
28 -import org.onlab.onos.CoreService; 28 +import org.onlab.onos.core.CoreService;
29 import org.onlab.onos.cli.AbstractShellCommand; 29 import org.onlab.onos.cli.AbstractShellCommand;
30 import org.onlab.onos.cli.Comparators; 30 import org.onlab.onos.cli.Comparators;
31 import org.onlab.onos.net.Device; 31 import org.onlab.onos.net.Device;
......
...@@ -37,9 +37,9 @@ ...@@ -37,9 +37,9 @@
37 </command> 37 </command>
38 <command> 38 <command>
39 <action class="org.onlab.onos.cli.MastersListCommand"/> 39 <action class="org.onlab.onos.cli.MastersListCommand"/>
40 - <completers> 40 + </command>
41 - <ref component-id="clusterIdCompleter"/> 41 + <command>
42 - </completers> 42 + <action class="org.onlab.onos.cli.ApplicationIdListCommand"/>
43 </command> 43 </command>
44 44
45 <command> 45 <command>
......
1 +/*
2 + * Licensed to the Apache Software Foundation (ASF) under one
3 + * or more contributor license agreements. See the NOTICE file
4 + * distributed with this work for additional information
5 + * regarding copyright ownership. The ASF licenses this file
6 + * to you under the Apache License, Version 2.0 (the
7 + * "License"); you may not use this file except in compliance
8 + * with the License. You may obtain a copy of the License at
9 + *
10 + * http://www.apache.org/licenses/LICENSE-2.0
11 + *
12 + * Unless required by applicable law or agreed to in writing,
13 + * software distributed under the License is distributed on an
14 + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 + * KIND, either express or implied. See the License for the
16 + * specific language governing permissions and limitations
17 + * under the License.
18 + */
19 +package org.onlab.onos.core;
20 +
21 +import java.util.Set;
22 +
23 +/**
24 + * Manages application IDs.
25 + */
26 +public interface ApplicationIdStore {
27 +
28 + /**
29 + * Returns the set of currently registered application identifiers.
30 + *
31 + * @return set of application ids
32 + */
33 + Set<ApplicationId> getAppIds();
34 +
35 + /**
36 + * Returns an existing application id from a given id.
37 + * @param id the short value of the id
38 + * @return an application id
39 + */
40 + ApplicationId getAppId(Short id);
41 +
42 + /**
43 + * Registers a new application by its name, which is expected
44 + * to follow the reverse DNS convention, e.g.
45 + * {@code org.flying.circus.app}
46 + *
47 + * @param identifier string identifier
48 + * @return the application id
49 + */
50 + ApplicationId registerApplication(String identifier);
51 +
52 +}
1 -package org.onlab.onos; 1 +package org.onlab.onos.core;
2 +
3 +import java.util.Set;
2 4
3 /** 5 /**
4 * Service for interacting with the core system of the controller. 6 * Service for interacting with the core system of the controller.
...@@ -13,14 +15,11 @@ public interface CoreService { ...@@ -13,14 +15,11 @@ public interface CoreService {
13 Version version(); 15 Version version();
14 16
15 /** 17 /**
16 - * Registers a new application by its name, which is expected 18 + * Returns the set of currently registered application identifiers.
17 - * to follow the reverse DNS convention, e.g.
18 - * {@code org.flying.circus.app}
19 * 19 *
20 - * @param identifier string identifier 20 + * @return set of application ids
21 - * @return the application id
22 */ 21 */
23 - ApplicationId registerApplication(String identifier); 22 + Set<ApplicationId> getAppIds();
24 23
25 /** 24 /**
26 * Returns an existing application id from a given id. 25 * Returns an existing application id from a given id.
...@@ -29,4 +28,14 @@ public interface CoreService { ...@@ -29,4 +28,14 @@ public interface CoreService {
29 */ 28 */
30 ApplicationId getAppId(Short id); 29 ApplicationId getAppId(Short id);
31 30
31 + /**
32 + * Registers a new application by its name, which is expected
33 + * to follow the reverse DNS convention, e.g.
34 + * {@code org.flying.circus.app}
35 + *
36 + * @param identifier string identifier
37 + * @return the application id
38 + */
39 + ApplicationId registerApplication(String identifier);
40 +
32 } 41 }
......
1 -package org.onlab.onos.impl; 1 +package org.onlab.onos.core;
2 -
3 -import org.onlab.onos.ApplicationId;
4 2
5 import java.util.Objects; 3 import java.util.Objects;
6 4
7 import static com.google.common.base.MoreObjects.toStringHelper; 5 import static com.google.common.base.MoreObjects.toStringHelper;
8 6
9 /** 7 /**
10 - * Application id generator class. 8 + * Application identifier.
11 */ 9 */
12 public class DefaultApplicationId implements ApplicationId { 10 public class DefaultApplicationId implements ApplicationId {
13 11
14 private final short id; 12 private final short id;
15 private final String name; 13 private final String name;
16 14
17 - // Ban public construction 15 + /**
18 - protected DefaultApplicationId(Short id, String identifier) { 16 + * Creates a new application ID.
17 + *
18 + * @param id application identifier
19 + * @param name application name
20 + */
21 + public DefaultApplicationId(Short id, String name) {
19 this.id = id; 22 this.id = id;
20 - this.name = identifier; 23 + this.name = name;
24 + }
25 +
26 + // Constructor for serializers.
27 + private DefaultApplicationId() {
28 + this.id = 0;
29 + this.name = null;
21 } 30 }
22 31
23 @Override 32 @Override
......
1 -package org.onlab.onos; 1 +package org.onlab.onos.core;
2 2
3 import java.util.Objects; 3 import java.util.Objects;
4 4
......
1 /** 1 /**
2 * ONOS Core API definitions. 2 * ONOS Core API definitions.
3 */ 3 */
4 -package org.onlab.onos; 4 +package org.onlab.onos.core;
......
...@@ -23,7 +23,7 @@ import static org.slf4j.LoggerFactory.getLogger; ...@@ -23,7 +23,7 @@ import static org.slf4j.LoggerFactory.getLogger;
23 23
24 import java.util.Objects; 24 import java.util.Objects;
25 25
26 -import org.onlab.onos.ApplicationId; 26 +import org.onlab.onos.core.ApplicationId;
27 import org.onlab.onos.net.DeviceId; 27 import org.onlab.onos.net.DeviceId;
28 import org.slf4j.Logger; 28 import org.slf4j.Logger;
29 29
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
18 */ 18 */
19 package org.onlab.onos.net.flow; 19 package org.onlab.onos.net.flow;
20 20
21 -import org.onlab.onos.ApplicationId; 21 +import org.onlab.onos.core.ApplicationId;
22 import org.onlab.onos.net.provider.Provider; 22 import org.onlab.onos.net.provider.Provider;
23 23
24 import com.google.common.util.concurrent.ListenableFuture; 24 import com.google.common.util.concurrent.ListenableFuture;
......
...@@ -20,7 +20,7 @@ package org.onlab.onos.net.flow; ...@@ -20,7 +20,7 @@ package org.onlab.onos.net.flow;
20 20
21 import java.util.concurrent.Future; 21 import java.util.concurrent.Future;
22 22
23 -import org.onlab.onos.ApplicationId; 23 +import org.onlab.onos.core.ApplicationId;
24 import org.onlab.onos.net.DeviceId; 24 import org.onlab.onos.net.DeviceId;
25 25
26 /** 26 /**
......
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
19 package org.onlab.onos.net.intent; 19 package org.onlab.onos.net.intent;
20 20
21 import com.google.common.collect.ImmutableSet; 21 import com.google.common.collect.ImmutableSet;
22 -import org.onlab.onos.ApplicationId; 22 +import org.onlab.onos.core.ApplicationId;
23 import org.onlab.onos.net.Link; 23 import org.onlab.onos.net.Link;
24 import org.onlab.onos.net.NetworkResource; 24 import org.onlab.onos.net.NetworkResource;
25 import org.onlab.onos.net.flow.TrafficSelector; 25 import org.onlab.onos.net.flow.TrafficSelector;
......
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
19 package org.onlab.onos.net.intent; 19 package org.onlab.onos.net.intent;
20 20
21 import com.google.common.base.MoreObjects; 21 import com.google.common.base.MoreObjects;
22 -import org.onlab.onos.ApplicationId; 22 +import org.onlab.onos.core.ApplicationId;
23 import org.onlab.onos.net.HostId; 23 import org.onlab.onos.net.HostId;
24 import org.onlab.onos.net.flow.TrafficSelector; 24 import org.onlab.onos.net.flow.TrafficSelector;
25 import org.onlab.onos.net.flow.TrafficTreatment; 25 import org.onlab.onos.net.flow.TrafficTreatment;
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
18 */ 18 */
19 package org.onlab.onos.net.intent; 19 package org.onlab.onos.net.intent;
20 20
21 -import org.onlab.onos.ApplicationId; 21 +import org.onlab.onos.core.ApplicationId;
22 import org.onlab.onos.net.NetworkResource; 22 import org.onlab.onos.net.NetworkResource;
23 import org.onlab.onos.net.flow.BatchOperationTarget; 23 import org.onlab.onos.net.flow.BatchOperationTarget;
24 24
......
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
19 package org.onlab.onos.net.intent; 19 package org.onlab.onos.net.intent;
20 20
21 import com.google.common.base.MoreObjects; 21 import com.google.common.base.MoreObjects;
22 -import org.onlab.onos.ApplicationId; 22 +import org.onlab.onos.core.ApplicationId;
23 import org.onlab.onos.net.ConnectPoint; 23 import org.onlab.onos.net.ConnectPoint;
24 import org.onlab.onos.net.Link; 24 import org.onlab.onos.net.Link;
25 import org.onlab.onos.net.flow.TrafficSelector; 25 import org.onlab.onos.net.flow.TrafficSelector;
......
...@@ -20,7 +20,7 @@ package org.onlab.onos.net.intent; ...@@ -20,7 +20,7 @@ package org.onlab.onos.net.intent;
20 20
21 import com.google.common.base.MoreObjects; 21 import com.google.common.base.MoreObjects;
22 import com.google.common.collect.Sets; 22 import com.google.common.collect.Sets;
23 -import org.onlab.onos.ApplicationId; 23 +import org.onlab.onos.core.ApplicationId;
24 import org.onlab.onos.net.ConnectPoint; 24 import org.onlab.onos.net.ConnectPoint;
25 import org.onlab.onos.net.flow.TrafficSelector; 25 import org.onlab.onos.net.flow.TrafficSelector;
26 import org.onlab.onos.net.flow.TrafficTreatment; 26 import org.onlab.onos.net.flow.TrafficTreatment;
......
1 package org.onlab.onos.net.intent; 1 package org.onlab.onos.net.intent;
2 2
3 -import org.onlab.onos.ApplicationId; 3 +import org.onlab.onos.core.ApplicationId;
4 import org.onlab.onos.net.ConnectPoint; 4 import org.onlab.onos.net.ConnectPoint;
5 5
6 /** 6 /**
......
...@@ -2,7 +2,7 @@ package org.onlab.onos.net.intent; ...@@ -2,7 +2,7 @@ package org.onlab.onos.net.intent;
2 2
3 import java.util.Collection; 3 import java.util.Collection;
4 4
5 -import org.onlab.onos.ApplicationId; 5 +import org.onlab.onos.core.ApplicationId;
6 import org.onlab.onos.net.ConnectPoint; 6 import org.onlab.onos.net.ConnectPoint;
7 import org.onlab.onos.net.Link; 7 import org.onlab.onos.net.Link;
8 import org.onlab.onos.net.NetworkResource; 8 import org.onlab.onos.net.NetworkResource;
......
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
19 package org.onlab.onos.net.intent; 19 package org.onlab.onos.net.intent;
20 20
21 import com.google.common.base.MoreObjects; 21 import com.google.common.base.MoreObjects;
22 -import org.onlab.onos.ApplicationId; 22 +import org.onlab.onos.core.ApplicationId;
23 import org.onlab.onos.net.Path; 23 import org.onlab.onos.net.Path;
24 import org.onlab.onos.net.flow.TrafficSelector; 24 import org.onlab.onos.net.flow.TrafficSelector;
25 import org.onlab.onos.net.flow.TrafficTreatment; 25 import org.onlab.onos.net.flow.TrafficTreatment;
......
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
19 package org.onlab.onos.net.intent; 19 package org.onlab.onos.net.intent;
20 20
21 import com.google.common.base.MoreObjects; 21 import com.google.common.base.MoreObjects;
22 -import org.onlab.onos.ApplicationId; 22 +import org.onlab.onos.core.ApplicationId;
23 import org.onlab.onos.net.ConnectPoint; 23 import org.onlab.onos.net.ConnectPoint;
24 import org.onlab.onos.net.flow.TrafficSelector; 24 import org.onlab.onos.net.flow.TrafficSelector;
25 import org.onlab.onos.net.flow.TrafficTreatment; 25 import org.onlab.onos.net.flow.TrafficTreatment;
......
...@@ -20,7 +20,7 @@ package org.onlab.onos.net.intent; ...@@ -20,7 +20,7 @@ package org.onlab.onos.net.intent;
20 20
21 import com.google.common.base.MoreObjects; 21 import com.google.common.base.MoreObjects;
22 import com.google.common.collect.Sets; 22 import com.google.common.collect.Sets;
23 -import org.onlab.onos.ApplicationId; 23 +import org.onlab.onos.core.ApplicationId;
24 import org.onlab.onos.net.ConnectPoint; 24 import org.onlab.onos.net.ConnectPoint;
25 import org.onlab.onos.net.flow.TrafficSelector; 25 import org.onlab.onos.net.flow.TrafficSelector;
26 import org.onlab.onos.net.flow.TrafficTreatment; 26 import org.onlab.onos.net.flow.TrafficTreatment;
......
1 package org.onlab.onos; 1 package org.onlab.onos;
2 2
3 +import org.onlab.onos.core.ApplicationId;
4 +
3 import java.util.Objects; 5 import java.util.Objects;
4 6
5 /** 7 /**
......
...@@ -2,9 +2,10 @@ package org.onlab.onos; ...@@ -2,9 +2,10 @@ package org.onlab.onos;
2 2
3 import com.google.common.testing.EqualsTester; 3 import com.google.common.testing.EqualsTester;
4 import org.junit.Test; 4 import org.junit.Test;
5 +import org.onlab.onos.core.Version;
5 6
6 import static org.junit.Assert.*; 7 import static org.junit.Assert.*;
7 -import static org.onlab.onos.Version.version; 8 +import static org.onlab.onos.core.Version.version;
8 9
9 /** 10 /**
10 * Tests of the version descriptor. 11 * Tests of the version descriptor.
......
...@@ -2,7 +2,7 @@ package org.onlab.onos.net.intent; ...@@ -2,7 +2,7 @@ package org.onlab.onos.net.intent;
2 2
3 import java.util.Set; 3 import java.util.Set;
4 4
5 -import org.onlab.onos.ApplicationId; 5 +import org.onlab.onos.core.ApplicationId;
6 import org.onlab.onos.TestApplicationId; 6 import org.onlab.onos.TestApplicationId;
7 import org.onlab.onos.net.ConnectPoint; 7 import org.onlab.onos.net.ConnectPoint;
8 import org.onlab.onos.net.DeviceId; 8 import org.onlab.onos.net.DeviceId;
......
1 -package org.onlab.onos.impl; 1 +package org.onlab.onos.core.impl;
2 2
3 import org.apache.felix.scr.annotations.Activate; 3 import org.apache.felix.scr.annotations.Activate;
4 import org.apache.felix.scr.annotations.Component; 4 import org.apache.felix.scr.annotations.Component;
5 +import org.apache.felix.scr.annotations.Reference;
6 +import org.apache.felix.scr.annotations.ReferenceCardinality;
5 import org.apache.felix.scr.annotations.Service; 7 import org.apache.felix.scr.annotations.Service;
6 -import org.onlab.onos.ApplicationId; 8 +import org.onlab.onos.core.ApplicationId;
7 -import org.onlab.onos.CoreService; 9 +import org.onlab.onos.core.ApplicationIdStore;
8 -import org.onlab.onos.Version; 10 +import org.onlab.onos.core.CoreService;
11 +import org.onlab.onos.core.Version;
9 import org.onlab.util.Tools; 12 import org.onlab.util.Tools;
10 13
11 import java.io.File; 14 import java.io.File;
12 import java.util.List; 15 import java.util.List;
13 -import java.util.Map; 16 +import java.util.Set;
14 -import java.util.concurrent.ConcurrentHashMap; 17 +
15 -import java.util.concurrent.atomic.AtomicInteger; 18 +import static com.google.common.base.Preconditions.checkNotNull;
16 19
17 /** 20 /**
18 * Core service implementation. 21 * Core service implementation.
...@@ -21,15 +24,11 @@ import java.util.concurrent.atomic.AtomicInteger; ...@@ -21,15 +24,11 @@ import java.util.concurrent.atomic.AtomicInteger;
21 @Service 24 @Service
22 public class CoreManager implements CoreService { 25 public class CoreManager implements CoreService {
23 26
24 - private static final AtomicInteger ID_DISPENSER = new AtomicInteger(1);
25 -
26 private static final File VERSION_FILE = new File("../VERSION"); 27 private static final File VERSION_FILE = new File("../VERSION");
27 private static Version version = Version.version("1.0.0-SNAPSHOT"); 28 private static Version version = Version.version("1.0.0-SNAPSHOT");
28 29
29 - private final Map<Short, DefaultApplicationId> appIds = new ConcurrentHashMap<>(); 30 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
30 - private final Map<String, DefaultApplicationId> appIdsByName = new ConcurrentHashMap<>(); 31 + protected ApplicationIdStore applicationIdStore;
31 -
32 - // TODO: work in progress
33 32
34 @Activate 33 @Activate
35 public void activate() { 34 public void activate() {
...@@ -45,20 +44,19 @@ public class CoreManager implements CoreService { ...@@ -45,20 +44,19 @@ public class CoreManager implements CoreService {
45 } 44 }
46 45
47 @Override 46 @Override
47 + public Set<ApplicationId> getAppIds() {
48 + return applicationIdStore.getAppIds();
49 + }
50 +
51 + @Override
48 public ApplicationId getAppId(Short id) { 52 public ApplicationId getAppId(Short id) {
49 - return appIds.get(id); 53 + return applicationIdStore.getAppId(id);
50 } 54 }
51 55
52 @Override 56 @Override
53 public ApplicationId registerApplication(String name) { 57 public ApplicationId registerApplication(String name) {
54 - DefaultApplicationId appId = appIdsByName.get(name); 58 + checkNotNull(name, "Application ID cannot be null");
55 - if (appId == null) { 59 + return applicationIdStore.registerApplication(name);
56 - short id = (short) ID_DISPENSER.getAndIncrement();
57 - appId = new DefaultApplicationId(id, name);
58 - appIds.put(id, appId);
59 - appIdsByName.put(name, appId);
60 - }
61 - return appId;
62 } 60 }
63 61
64 } 62 }
......
1 -package org.onlab.onos.impl; 1 +package org.onlab.onos.core.impl;
2 2
3 import org.apache.felix.scr.annotations.Activate; 3 import org.apache.felix.scr.annotations.Activate;
4 import org.apache.felix.scr.annotations.Component; 4 import org.apache.felix.scr.annotations.Component;
......
1 /** 1 /**
2 * Miscellaneous core system implementations. 2 * Miscellaneous core system implementations.
3 */ 3 */
4 -package org.onlab.onos.impl;
...\ No newline at end of file ...\ No newline at end of file
4 +package org.onlab.onos.core.impl;
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -22,7 +22,7 @@ import org.apache.felix.scr.annotations.Deactivate; ...@@ -22,7 +22,7 @@ import org.apache.felix.scr.annotations.Deactivate;
22 import org.apache.felix.scr.annotations.Reference; 22 import org.apache.felix.scr.annotations.Reference;
23 import org.apache.felix.scr.annotations.ReferenceCardinality; 23 import org.apache.felix.scr.annotations.ReferenceCardinality;
24 import org.apache.felix.scr.annotations.Service; 24 import org.apache.felix.scr.annotations.Service;
25 -import org.onlab.onos.ApplicationId; 25 +import org.onlab.onos.core.ApplicationId;
26 import org.onlab.onos.event.AbstractListenerRegistry; 26 import org.onlab.onos.event.AbstractListenerRegistry;
27 import org.onlab.onos.event.EventDeliveryService; 27 import org.onlab.onos.event.EventDeliveryService;
28 import org.onlab.onos.net.Device; 28 import org.onlab.onos.net.Device;
......
...@@ -9,8 +9,8 @@ import org.apache.felix.scr.annotations.Component; ...@@ -9,8 +9,8 @@ import org.apache.felix.scr.annotations.Component;
9 import org.apache.felix.scr.annotations.Deactivate; 9 import org.apache.felix.scr.annotations.Deactivate;
10 import org.apache.felix.scr.annotations.Reference; 10 import org.apache.felix.scr.annotations.Reference;
11 import org.apache.felix.scr.annotations.ReferenceCardinality; 11 import org.apache.felix.scr.annotations.ReferenceCardinality;
12 -import org.onlab.onos.ApplicationId; 12 +import org.onlab.onos.core.ApplicationId;
13 -import org.onlab.onos.CoreService; 13 +import org.onlab.onos.core.CoreService;
14 import org.onlab.onos.net.DeviceId; 14 import org.onlab.onos.net.DeviceId;
15 import org.onlab.onos.net.Link; 15 import org.onlab.onos.net.Link;
16 import org.onlab.onos.net.PortNumber; 16 import org.onlab.onos.net.PortNumber;
......
...@@ -12,7 +12,7 @@ import org.apache.felix.scr.annotations.Component; ...@@ -12,7 +12,7 @@ import org.apache.felix.scr.annotations.Component;
12 import org.apache.felix.scr.annotations.Deactivate; 12 import org.apache.felix.scr.annotations.Deactivate;
13 import org.apache.felix.scr.annotations.Reference; 13 import org.apache.felix.scr.annotations.Reference;
14 import org.apache.felix.scr.annotations.ReferenceCardinality; 14 import org.apache.felix.scr.annotations.ReferenceCardinality;
15 -import org.onlab.onos.CoreService; 15 +import org.onlab.onos.core.CoreService;
16 import org.onlab.onos.net.ConnectPoint; 16 import org.onlab.onos.net.ConnectPoint;
17 import org.onlab.onos.net.Link; 17 import org.onlab.onos.net.Link;
18 import org.onlab.onos.net.Path; 18 import org.onlab.onos.net.Path;
......
...@@ -10,8 +10,8 @@ import org.apache.felix.scr.annotations.Component; ...@@ -10,8 +10,8 @@ import org.apache.felix.scr.annotations.Component;
10 import org.apache.felix.scr.annotations.Deactivate; 10 import org.apache.felix.scr.annotations.Deactivate;
11 import org.apache.felix.scr.annotations.Reference; 11 import org.apache.felix.scr.annotations.Reference;
12 import org.apache.felix.scr.annotations.ReferenceCardinality; 12 import org.apache.felix.scr.annotations.ReferenceCardinality;
13 -import org.onlab.onos.ApplicationId; 13 +import org.onlab.onos.core.ApplicationId;
14 -import org.onlab.onos.CoreService; 14 +import org.onlab.onos.core.CoreService;
15 import org.onlab.onos.net.ConnectPoint; 15 import org.onlab.onos.net.ConnectPoint;
16 import org.onlab.onos.net.Link; 16 import org.onlab.onos.net.Link;
17 import org.onlab.onos.net.flow.DefaultFlowRule; 17 import org.onlab.onos.net.flow.DefaultFlowRule;
......
...@@ -11,8 +11,8 @@ import org.apache.felix.scr.annotations.Component; ...@@ -11,8 +11,8 @@ import org.apache.felix.scr.annotations.Component;
11 import org.apache.felix.scr.annotations.Deactivate; 11 import org.apache.felix.scr.annotations.Deactivate;
12 import org.apache.felix.scr.annotations.Reference; 12 import org.apache.felix.scr.annotations.Reference;
13 import org.apache.felix.scr.annotations.ReferenceCardinality; 13 import org.apache.felix.scr.annotations.ReferenceCardinality;
14 -import org.onlab.onos.ApplicationId; 14 +import org.onlab.onos.core.ApplicationId;
15 -import org.onlab.onos.CoreService; 15 +import org.onlab.onos.core.CoreService;
16 import org.onlab.onos.net.ConnectPoint; 16 import org.onlab.onos.net.ConnectPoint;
17 import org.onlab.onos.net.Link; 17 import org.onlab.onos.net.Link;
18 import org.onlab.onos.net.flow.DefaultFlowRule; 18 import org.onlab.onos.net.flow.DefaultFlowRule;
......
1 package org.onlab.onos.net.flow.impl; 1 package org.onlab.onos.net.flow.impl;
2 2
3 -import static org.junit.Assert.assertEquals; 3 +import com.google.common.collect.ImmutableList;
4 -import static org.junit.Assert.assertFalse; 4 +import com.google.common.collect.ImmutableMap;
5 -import static org.junit.Assert.assertNotNull; 5 +import com.google.common.collect.Lists;
6 -import static org.junit.Assert.assertTrue; 6 +import com.google.common.collect.Sets;
7 -import static org.junit.Assert.fail; 7 +import com.google.common.util.concurrent.ListenableFuture;
8 -import static org.onlab.onos.net.flow.FlowRuleEvent.Type.RULE_ADDED;
9 -import static org.onlab.onos.net.flow.FlowRuleEvent.Type.RULE_ADD_REQUESTED;
10 -import static org.onlab.onos.net.flow.FlowRuleEvent.Type.RULE_REMOVED;
11 -import static org.onlab.onos.net.flow.FlowRuleEvent.Type.RULE_REMOVE_REQUESTED;
12 -import static org.onlab.onos.net.flow.FlowRuleEvent.Type.RULE_UPDATED;
13 -
14 -import java.util.ArrayList;
15 -import java.util.Arrays;
16 -import java.util.Collections;
17 -import java.util.HashMap;
18 -import java.util.List;
19 -import java.util.Map;
20 -import java.util.Set;
21 -import java.util.concurrent.ExecutionException;
22 -import java.util.concurrent.Executor;
23 -import java.util.concurrent.Future;
24 -import java.util.concurrent.TimeUnit;
25 -import java.util.concurrent.TimeoutException;
26 -
27 import org.junit.After; 8 import org.junit.After;
28 import org.junit.Before; 9 import org.junit.Before;
29 import org.junit.Test; 10 import org.junit.Test;
30 -import org.onlab.onos.ApplicationId; 11 +import org.onlab.onos.core.ApplicationId;
12 +import org.onlab.onos.core.DefaultApplicationId;
31 import org.onlab.onos.event.impl.TestEventDispatcher; 13 import org.onlab.onos.event.impl.TestEventDispatcher;
32 -import org.onlab.onos.impl.DefaultApplicationId;
33 import org.onlab.onos.net.DefaultDevice; 14 import org.onlab.onos.net.DefaultDevice;
34 import org.onlab.onos.net.Device; 15 import org.onlab.onos.net.Device;
35 import org.onlab.onos.net.Device.Type; 16 import org.onlab.onos.net.Device.Type;
...@@ -63,11 +44,21 @@ import org.onlab.onos.net.provider.AbstractProvider; ...@@ -63,11 +44,21 @@ import org.onlab.onos.net.provider.AbstractProvider;
63 import org.onlab.onos.net.provider.ProviderId; 44 import org.onlab.onos.net.provider.ProviderId;
64 import org.onlab.onos.store.trivial.impl.SimpleFlowRuleStore; 45 import org.onlab.onos.store.trivial.impl.SimpleFlowRuleStore;
65 46
66 -import com.google.common.collect.ImmutableList; 47 +import java.util.ArrayList;
67 -import com.google.common.collect.ImmutableMap; 48 +import java.util.Arrays;
68 -import com.google.common.collect.Lists; 49 +import java.util.Collections;
69 -import com.google.common.collect.Sets; 50 +import java.util.HashMap;
70 -import com.google.common.util.concurrent.ListenableFuture; 51 +import java.util.List;
52 +import java.util.Map;
53 +import java.util.Set;
54 +import java.util.concurrent.ExecutionException;
55 +import java.util.concurrent.Executor;
56 +import java.util.concurrent.Future;
57 +import java.util.concurrent.TimeUnit;
58 +import java.util.concurrent.TimeoutException;
59 +
60 +import static org.junit.Assert.*;
61 +import static org.onlab.onos.net.flow.FlowRuleEvent.Type.*;
71 62
72 /** 63 /**
73 * Test codifying the flow rule service & flow rule provider service contracts. 64 * Test codifying the flow rule service & flow rule provider service contracts.
...@@ -75,7 +66,6 @@ import com.google.common.util.concurrent.ListenableFuture; ...@@ -75,7 +66,6 @@ import com.google.common.util.concurrent.ListenableFuture;
75 public class FlowRuleManagerTest { 66 public class FlowRuleManagerTest {
76 67
77 68
78 -
79 private static final ProviderId PID = new ProviderId("of", "foo"); 69 private static final ProviderId PID = new ProviderId("of", "foo");
80 private static final DeviceId DID = DeviceId.deviceId("of:001"); 70 private static final DeviceId DID = DeviceId.deviceId("of:001");
81 private static final int TIMEOUT = 10; 71 private static final int TIMEOUT = 10;
...@@ -106,14 +96,14 @@ public class FlowRuleManagerTest { ...@@ -106,14 +96,14 @@ public class FlowRuleManagerTest {
106 providerService = registry.register(provider); 96 providerService = registry.register(provider);
107 appId = new TestApplicationId((short) 0, "FlowRuleManagerTest"); 97 appId = new TestApplicationId((short) 0, "FlowRuleManagerTest");
108 assertTrue("provider should be registered", 98 assertTrue("provider should be registered",
109 - registry.getProviders().contains(provider.id())); 99 + registry.getProviders().contains(provider.id()));
110 } 100 }
111 101
112 @After 102 @After
113 public void tearDown() { 103 public void tearDown() {
114 registry.unregister(provider); 104 registry.unregister(provider);
115 assertFalse("provider should not be registered", 105 assertFalse("provider should not be registered",
116 - registry.getProviders().contains(provider.id())); 106 + registry.getProviders().contains(provider.id()));
117 service.removeListener(listener); 107 service.removeListener(listener);
118 mgr.deactivate(); 108 mgr.deactivate();
119 mgr.eventDispatcher = null; 109 mgr.eventDispatcher = null;
...@@ -135,7 +125,7 @@ public class FlowRuleManagerTest { ...@@ -135,7 +125,7 @@ public class FlowRuleManagerTest {
135 return rule; 125 return rule;
136 } 126 }
137 127
138 - private void validateEvents(FlowRuleEvent.Type ... events) { 128 + private void validateEvents(FlowRuleEvent.Type... events) {
139 if (events == null) { 129 if (events == null) {
140 assertTrue("events generated", listener.events.isEmpty()); 130 assertTrue("events generated", listener.events.isEmpty());
141 } 131 }
...@@ -148,7 +138,7 @@ public class FlowRuleManagerTest { ...@@ -148,7 +138,7 @@ public class FlowRuleManagerTest {
148 } 138 }
149 139
150 assertEquals("mispredicted number of events", 140 assertEquals("mispredicted number of events",
151 - events.length, listener.events.size()); 141 + events.length, listener.events.size());
152 142
153 listener.events.clear(); 143 listener.events.clear();
154 } 144 }
...@@ -156,10 +146,11 @@ public class FlowRuleManagerTest { ...@@ -156,10 +146,11 @@ public class FlowRuleManagerTest {
156 private int flowCount() { 146 private int flowCount() {
157 return Sets.newHashSet(service.getFlowEntries(DID)).size(); 147 return Sets.newHashSet(service.getFlowEntries(DID)).size();
158 } 148 }
149 +
159 @Test 150 @Test
160 public void getFlowEntries() { 151 public void getFlowEntries() {
161 assertTrue("store should be empty", 152 assertTrue("store should be empty",
162 - Sets.newHashSet(service.getFlowEntries(DID)).isEmpty()); 153 + Sets.newHashSet(service.getFlowEntries(DID)).isEmpty());
163 FlowRule f1 = addFlowRule(1); 154 FlowRule f1 = addFlowRule(1);
164 FlowRule f2 = addFlowRule(2); 155 FlowRule f2 = addFlowRule(2);
165 156
...@@ -206,9 +197,9 @@ public class FlowRuleManagerTest { ...@@ -206,9 +197,9 @@ public class FlowRuleManagerTest {
206 assertEquals("3 rules should exist", 3, flowCount()); 197 assertEquals("3 rules should exist", 3, flowCount());
207 assertTrue("Entries should be pending add.", 198 assertTrue("Entries should be pending add.",
208 validateState(ImmutableMap.of( 199 validateState(ImmutableMap.of(
209 - r1, FlowEntryState.PENDING_ADD, 200 + r1, FlowEntryState.PENDING_ADD,
210 - r2, FlowEntryState.PENDING_ADD, 201 + r2, FlowEntryState.PENDING_ADD,
211 - r3, FlowEntryState.PENDING_ADD))); 202 + r3, FlowEntryState.PENDING_ADD)));
212 } 203 }
213 204
214 @Test 205 @Test
...@@ -231,9 +222,9 @@ public class FlowRuleManagerTest { ...@@ -231,9 +222,9 @@ public class FlowRuleManagerTest {
231 assertEquals("3 rule should exist", 3, flowCount()); 222 assertEquals("3 rule should exist", 3, flowCount());
232 assertTrue("Entries should be pending remove.", 223 assertTrue("Entries should be pending remove.",
233 validateState(ImmutableMap.of( 224 validateState(ImmutableMap.of(
234 - f1, FlowEntryState.PENDING_REMOVE, 225 + f1, FlowEntryState.PENDING_REMOVE,
235 - f2, FlowEntryState.PENDING_REMOVE, 226 + f2, FlowEntryState.PENDING_REMOVE,
236 - f3, FlowEntryState.ADDED))); 227 + f3, FlowEntryState.ADDED)));
237 228
238 mgr.removeFlowRules(f1); 229 mgr.removeFlowRules(f1);
239 assertEquals("3 rule should still exist", 3, flowCount()); 230 assertEquals("3 rule should still exist", 3, flowCount());
...@@ -283,10 +274,10 @@ public class FlowRuleManagerTest { ...@@ -283,10 +274,10 @@ public class FlowRuleManagerTest {
283 providerService.pushFlowMetrics(DID, Lists.newArrayList(fe1, fe2)); 274 providerService.pushFlowMetrics(DID, Lists.newArrayList(fe1, fe2));
284 275
285 assertTrue("Entries should be added.", 276 assertTrue("Entries should be added.",
286 - validateState(ImmutableMap.of( 277 + validateState(ImmutableMap.of(
287 - f1, FlowEntryState.ADDED, 278 + f1, FlowEntryState.ADDED,
288 - f2, FlowEntryState.ADDED, 279 + f2, FlowEntryState.ADDED,
289 - f3, FlowEntryState.PENDING_ADD))); 280 + f3, FlowEntryState.PENDING_ADD)));
290 281
291 validateEvents(RULE_ADD_REQUESTED, RULE_ADD_REQUESTED, RULE_ADD_REQUESTED, 282 validateEvents(RULE_ADD_REQUESTED, RULE_ADD_REQUESTED, RULE_ADD_REQUESTED,
292 RULE_ADDED, RULE_ADDED); 283 RULE_ADDED, RULE_ADDED);
...@@ -361,8 +352,8 @@ public class FlowRuleManagerTest { ...@@ -361,8 +352,8 @@ public class FlowRuleManagerTest {
361 //only check that we are in pending remove. Events and actual remove state will 352 //only check that we are in pending remove. Events and actual remove state will
362 // be set by flowRemoved call. 353 // be set by flowRemoved call.
363 validateState(ImmutableMap.of( 354 validateState(ImmutableMap.of(
364 - f1, FlowEntryState.PENDING_REMOVE, 355 + f1, FlowEntryState.PENDING_REMOVE,
365 - f2, FlowEntryState.PENDING_REMOVE)); 356 + f2, FlowEntryState.PENDING_REMOVE));
366 } 357 }
367 358
368 @Test 359 @Test
...@@ -387,8 +378,8 @@ public class FlowRuleManagerTest { ...@@ -387,8 +378,8 @@ public class FlowRuleManagerTest {
387 Future<CompletedBatchOperation> future = mgr.applyBatch(fbo); 378 Future<CompletedBatchOperation> future = mgr.applyBatch(fbo);
388 assertTrue("Entries in wrong state", 379 assertTrue("Entries in wrong state",
389 validateState(ImmutableMap.of( 380 validateState(ImmutableMap.of(
390 - f1, FlowEntryState.PENDING_REMOVE, 381 + f1, FlowEntryState.PENDING_REMOVE,
391 - f2, FlowEntryState.PENDING_ADD))); 382 + f2, FlowEntryState.PENDING_ADD)));
392 CompletedBatchOperation completed = null; 383 CompletedBatchOperation completed = null;
393 try { 384 try {
394 completed = future.get(); 385 completed = future.get();
...@@ -410,15 +401,15 @@ public class FlowRuleManagerTest { ...@@ -410,15 +401,15 @@ public class FlowRuleManagerTest {
410 mgr.applyFlowRules(f1); 401 mgr.applyFlowRules(f1);
411 402
412 assertTrue("Entries in wrong state", 403 assertTrue("Entries in wrong state",
413 - validateState(ImmutableMap.of( 404 + validateState(ImmutableMap.of(
414 - f1, FlowEntryState.PENDING_ADD))); 405 + f1, FlowEntryState.PENDING_ADD)));
415 406
416 FlowEntry fe1 = new DefaultFlowEntry(f1); 407 FlowEntry fe1 = new DefaultFlowEntry(f1);
417 providerService.pushFlowMetrics(DID, Collections.<FlowEntry>singletonList(fe1)); 408 providerService.pushFlowMetrics(DID, Collections.<FlowEntry>singletonList(fe1));
418 409
419 assertTrue("Entries in wrong state", 410 assertTrue("Entries in wrong state",
420 - validateState(ImmutableMap.of( 411 + validateState(ImmutableMap.of(
421 - f1, FlowEntryState.ADDED))); 412 + f1, FlowEntryState.ADDED)));
422 413
423 414
424 FlowRuleBatchEntry fbe1 = new FlowRuleBatchEntry( 415 FlowRuleBatchEntry fbe1 = new FlowRuleBatchEntry(
...@@ -441,14 +432,13 @@ public class FlowRuleManagerTest { ...@@ -441,14 +432,13 @@ public class FlowRuleManagerTest {
441 */ 432 */
442 assertTrue("Entries in wrong state", 433 assertTrue("Entries in wrong state",
443 validateState(ImmutableMap.of( 434 validateState(ImmutableMap.of(
444 - f2, FlowEntryState.PENDING_REMOVE, 435 + f2, FlowEntryState.PENDING_REMOVE,
445 - f1, FlowEntryState.PENDING_ADD))); 436 + f1, FlowEntryState.PENDING_ADD)));
446 437
447 438
448 } 439 }
449 440
450 441
451 -
452 private static class TestListener implements FlowRuleListener { 442 private static class TestListener implements FlowRuleListener {
453 final List<FlowRuleEvent> events = new ArrayList<>(); 443 final List<FlowRuleEvent> events = new ArrayList<>();
454 444
......
1 package org.onlab.onos.net.intent; 1 package org.onlab.onos.net.intent;
2 2
3 import org.junit.Test; 3 import org.junit.Test;
4 -import org.onlab.onos.ApplicationId; 4 +import org.onlab.onos.core.ApplicationId;
5 import org.onlab.onos.TestApplicationId; 5 import org.onlab.onos.TestApplicationId;
6 import org.onlab.onos.net.HostId; 6 import org.onlab.onos.net.HostId;
7 import org.onlab.onos.net.flow.TrafficSelector; 7 import org.onlab.onos.net.flow.TrafficSelector;
......
...@@ -12,7 +12,7 @@ import java.util.Set; ...@@ -12,7 +12,7 @@ import java.util.Set;
12 12
13 import org.junit.Before; 13 import org.junit.Before;
14 import org.junit.Test; 14 import org.junit.Test;
15 -import org.onlab.onos.ApplicationId; 15 +import org.onlab.onos.core.ApplicationId;
16 import org.onlab.onos.TestApplicationId; 16 import org.onlab.onos.TestApplicationId;
17 import org.onlab.onos.net.ConnectPoint; 17 import org.onlab.onos.net.ConnectPoint;
18 import org.onlab.onos.net.DeviceId; 18 import org.onlab.onos.net.DeviceId;
......
...@@ -2,7 +2,7 @@ package org.onlab.onos.net.intent; ...@@ -2,7 +2,7 @@ package org.onlab.onos.net.intent;
2 2
3 import org.junit.Before; 3 import org.junit.Before;
4 import org.junit.Test; 4 import org.junit.Test;
5 -import org.onlab.onos.ApplicationId; 5 +import org.onlab.onos.core.ApplicationId;
6 import org.onlab.onos.TestApplicationId; 6 import org.onlab.onos.TestApplicationId;
7 import org.onlab.onos.net.ConnectPoint; 7 import org.onlab.onos.net.ConnectPoint;
8 import org.onlab.onos.net.flow.TrafficSelector; 8 import org.onlab.onos.net.flow.TrafficSelector;
......
1 package org.onlab.onos.net.intent; 1 package org.onlab.onos.net.intent;
2 2
3 import org.junit.Test; 3 import org.junit.Test;
4 -import org.onlab.onos.ApplicationId; 4 +import org.onlab.onos.core.ApplicationId;
5 import org.onlab.onos.TestApplicationId; 5 import org.onlab.onos.TestApplicationId;
6 import org.onlab.onos.net.ConnectPoint; 6 import org.onlab.onos.net.ConnectPoint;
7 import org.onlab.onos.net.flow.TrafficSelector; 7 import org.onlab.onos.net.flow.TrafficSelector;
......
...@@ -3,7 +3,7 @@ package org.onlab.onos.net.intent.impl; ...@@ -3,7 +3,7 @@ package org.onlab.onos.net.intent.impl;
3 import org.hamcrest.Matchers; 3 import org.hamcrest.Matchers;
4 import org.junit.Before; 4 import org.junit.Before;
5 import org.junit.Test; 5 import org.junit.Test;
6 -import org.onlab.onos.ApplicationId; 6 +import org.onlab.onos.core.ApplicationId;
7 import org.onlab.onos.TestApplicationId; 7 import org.onlab.onos.TestApplicationId;
8 import org.onlab.onos.net.Host; 8 import org.onlab.onos.net.Host;
9 import org.onlab.onos.net.HostId; 9 import org.onlab.onos.net.HostId;
......
...@@ -2,7 +2,7 @@ package org.onlab.onos.net.intent.impl; ...@@ -2,7 +2,7 @@ package org.onlab.onos.net.intent.impl;
2 2
3 import org.hamcrest.Matchers; 3 import org.hamcrest.Matchers;
4 import org.junit.Test; 4 import org.junit.Test;
5 -import org.onlab.onos.ApplicationId; 5 +import org.onlab.onos.core.ApplicationId;
6 import org.onlab.onos.TestApplicationId; 6 import org.onlab.onos.TestApplicationId;
7 import org.onlab.onos.net.ConnectPoint; 7 import org.onlab.onos.net.ConnectPoint;
8 import org.onlab.onos.net.ElementId; 8 import org.onlab.onos.net.ElementId;
......
...@@ -2,7 +2,7 @@ package org.onlab.onos.net.intent.impl; ...@@ -2,7 +2,7 @@ package org.onlab.onos.net.intent.impl;
2 2
3 import org.hamcrest.Matchers; 3 import org.hamcrest.Matchers;
4 //import org.junit.Test; 4 //import org.junit.Test;
5 -import org.onlab.onos.ApplicationId; 5 +import org.onlab.onos.core.ApplicationId;
6 import org.onlab.onos.TestApplicationId; 6 import org.onlab.onos.TestApplicationId;
7 import org.onlab.onos.net.flow.TrafficSelector; 7 import org.onlab.onos.net.flow.TrafficSelector;
8 import org.onlab.onos.net.flow.TrafficTreatment; 8 import org.onlab.onos.net.flow.TrafficTreatment;
......
1 +/*
2 + * Licensed to the Apache Software Foundation (ASF) under one
3 + * or more contributor license agreements. See the NOTICE file
4 + * distributed with this work for additional information
5 + * regarding copyright ownership. The ASF licenses this file
6 + * to you under the Apache License, Version 2.0 (the
7 + * "License"); you may not use this file except in compliance
8 + * with the License. You may obtain a copy of the License at
9 + *
10 + * http://www.apache.org/licenses/LICENSE-2.0
11 + *
12 + * Unless required by applicable law or agreed to in writing,
13 + * software distributed under the License is distributed on an
14 + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 + * KIND, either express or implied. See the License for the
16 + * specific language governing permissions and limitations
17 + * under the License.
18 + */
19 +package org.onlab.onos.store.core.impl;
20 +
21 +import org.onlab.onos.core.ApplicationId;
22 +import org.onlab.onos.event.AbstractEvent;
23 +
24 +/**
25 + * Application ID event.
26 + */
27 +public class AppIdEvent extends AbstractEvent<AppIdEvent.Type, ApplicationId> {
28 +
29 + public enum Type {
30 + APP_REGISTERED
31 + }
32 +
33 + protected AppIdEvent(Type type, ApplicationId subject) {
34 + super(type, subject);
35 + }
36 +
37 +}
1 +/*
2 + * Licensed to the Apache Software Foundation (ASF) under one
3 + * or more contributor license agreements. See the NOTICE file
4 + * distributed with this work for additional information
5 + * regarding copyright ownership. The ASF licenses this file
6 + * to you under the Apache License, Version 2.0 (the
7 + * "License"); you may not use this file except in compliance
8 + * with the License. You may obtain a copy of the License at
9 + *
10 + * http://www.apache.org/licenses/LICENSE-2.0
11 + *
12 + * Unless required by applicable law or agreed to in writing,
13 + * software distributed under the License is distributed on an
14 + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 + * KIND, either express or implied. See the License for the
16 + * specific language governing permissions and limitations
17 + * under the License.
18 + */
19 +package org.onlab.onos.store.core.impl;
20 +
21 +import org.onlab.onos.store.StoreDelegate;
22 +
23 +/**
24 + * Application ID store delegate.
25 + */
26 +public interface AppIdStoreDelegate extends StoreDelegate<AppIdEvent> {
27 +}
1 +/*
2 + * Licensed to the Apache Software Foundation (ASF) under one
3 + * or more contributor license agreements. See the NOTICE file
4 + * distributed with this work for additional information
5 + * regarding copyright ownership. The ASF licenses this file
6 + * to you under the Apache License, Version 2.0 (the
7 + * "License"); you may not use this file except in compliance
8 + * with the License. You may obtain a copy of the License at
9 + *
10 + * http://www.apache.org/licenses/LICENSE-2.0
11 + *
12 + * Unless required by applicable law or agreed to in writing,
13 + * software distributed under the License is distributed on an
14 + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 + * KIND, either express or implied. See the License for the
16 + * specific language governing permissions and limitations
17 + * under the License.
18 + */
19 +package org.onlab.onos.store.core.impl;
20 +
21 +import com.google.common.collect.ImmutableSet;
22 +import com.hazelcast.core.EntryEvent;
23 +import com.hazelcast.core.EntryListener;
24 +import com.hazelcast.core.IAtomicLong;
25 +import com.hazelcast.core.MapEvent;
26 +import org.apache.felix.scr.annotations.Activate;
27 +import org.apache.felix.scr.annotations.Component;
28 +import org.apache.felix.scr.annotations.Deactivate;
29 +import org.apache.felix.scr.annotations.Service;
30 +import org.onlab.onos.core.ApplicationId;
31 +import org.onlab.onos.core.ApplicationIdStore;
32 +import org.onlab.onos.core.DefaultApplicationId;
33 +import org.onlab.onos.store.hz.AbstractHazelcastStore;
34 +import org.onlab.onos.store.hz.SMap;
35 +import org.onlab.onos.store.serializers.KryoNamespaces;
36 +import org.onlab.onos.store.serializers.KryoSerializer;
37 +import org.onlab.util.KryoNamespace;
38 +
39 +import java.util.Map;
40 +import java.util.Set;
41 +import java.util.concurrent.ConcurrentHashMap;
42 +
43 +/**
44 + * Simple implementation of the application ID registry using in-memory
45 + * structures.
46 + */
47 +@Component(immediate = true)
48 +@Service
49 +public class DistributedApplicationIdStore
50 + extends AbstractHazelcastStore<AppIdEvent, AppIdStoreDelegate>
51 + implements ApplicationIdStore {
52 +
53 + protected IAtomicLong lastAppId;
54 + protected SMap<String, DefaultApplicationId> appIdsByName;
55 +
56 + protected Map<Short, DefaultApplicationId> appIds = new ConcurrentHashMap<>();
57 +
58 +
59 + @Override
60 + @Activate
61 + public void activate() {
62 + super.activate();
63 +
64 + this.serializer = new KryoSerializer() {
65 + @Override
66 + protected void setupKryoPool() {
67 + serializerPool = KryoNamespace.newBuilder()
68 + .register(KryoNamespaces.API)
69 + .build()
70 + .populate(1);
71 + }
72 + };
73 +
74 + lastAppId = theInstance.getAtomicLong("applicationId");
75 +
76 + appIdsByName = new SMap<>(theInstance.<byte[], byte[]>getMap("appIdsByName"), this.serializer);
77 + appIdsByName.addEntryListener((new RemoteAppIdEventHandler()), true);
78 +
79 + primeAppIds();
80 +
81 + log.info("Started");
82 + }
83 +
84 + @Deactivate
85 + public void deactivate() {
86 + log.info("Stopped");
87 + }
88 +
89 + @Override
90 + public Set<ApplicationId> getAppIds() {
91 + return ImmutableSet.<ApplicationId>copyOf(appIds.values());
92 + }
93 +
94 + @Override
95 + public ApplicationId getAppId(Short id) {
96 + ApplicationId appId = appIds.get(id);
97 + if (appId == null) {
98 + primeAppIds();
99 + }
100 + return appId;
101 + }
102 +
103 + private synchronized void primeAppIds() {
104 + for (DefaultApplicationId appId : appIdsByName.values()) {
105 + appIds.put(appId.id(), appId);
106 + }
107 + }
108 +
109 + @Override
110 + public synchronized ApplicationId registerApplication(String name) {
111 + DefaultApplicationId appId = appIdsByName.get(name);
112 + if (appId == null) {
113 + short id = (short) lastAppId.getAndIncrement();
114 + appId = new DefaultApplicationId(id, name);
115 + appIds.put(id, appId);
116 + appIdsByName.put(name, appId);
117 + }
118 + return appId;
119 + }
120 +
121 + private class RemoteAppIdEventHandler implements EntryListener<String, DefaultApplicationId> {
122 + @Override
123 + public void entryAdded(EntryEvent<String, DefaultApplicationId> event) {
124 + DefaultApplicationId appId = event.getValue();
125 + appIds.put(appId.id(), appId);
126 + }
127 +
128 + @Override
129 + public void entryRemoved(EntryEvent<String, DefaultApplicationId> event) {
130 + }
131 +
132 + @Override
133 + public void entryUpdated(EntryEvent<String, DefaultApplicationId> event) {
134 + entryAdded(event);
135 + }
136 +
137 + @Override
138 + public void entryEvicted(EntryEvent<String, DefaultApplicationId> event) {
139 + }
140 +
141 + @Override
142 + public void mapEvicted(MapEvent event) {
143 + }
144 +
145 + @Override
146 + public void mapCleared(MapEvent event) {
147 + }
148 + }
149 +}
1 +/*
2 + * Licensed to the Apache Software Foundation (ASF) under one
3 + * or more contributor license agreements. See the NOTICE file
4 + * distributed with this work for additional information
5 + * regarding copyright ownership. The ASF licenses this file
6 + * to you under the Apache License, Version 2.0 (the
7 + * "License"); you may not use this file except in compliance
8 + * with the License. You may obtain a copy of the License at
9 + *
10 + * http://www.apache.org/licenses/LICENSE-2.0
11 + *
12 + * Unless required by applicable law or agreed to in writing,
13 + * software distributed under the License is distributed on an
14 + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 + * KIND, either express or implied. See the License for the
16 + * specific language governing permissions and limitations
17 + * under the License.
18 + */
19 +
20 +/**
21 + * Implementation of a distributed application ID registry store using Hazelcast.
22 + */
23 +package org.onlab.onos.store.core.impl;
...@@ -15,7 +15,7 @@ import com.google.common.base.MoreObjects.ToStringHelper; ...@@ -15,7 +15,7 @@ import com.google.common.base.MoreObjects.ToStringHelper;
15 15
16 /** 16 /**
17 * A structure that holds node mastership roles associated with a 17 * A structure that holds node mastership roles associated with a
18 - * {@link DeviceId}. This structure needs to be locked through IMap. 18 + * {@link org.onlab.onos.net.DeviceId}. This structure needs to be locked through IMap.
19 */ 19 */
20 final class RoleValue { 20 final class RoleValue {
21 21
......
1 +/*
2 + * Licensed to the Apache Software Foundation (ASF) under one
3 + * or more contributor license agreements. See the NOTICE file
4 + * distributed with this work for additional information
5 + * regarding copyright ownership. The ASF licenses this file
6 + * to you under the Apache License, Version 2.0 (the
7 + * "License"); you may not use this file except in compliance
8 + * with the License. You may obtain a copy of the License at
9 + *
10 + * http://www.apache.org/licenses/LICENSE-2.0
11 + *
12 + * Unless required by applicable law or agreed to in writing,
13 + * software distributed under the License is distributed on an
14 + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 + * KIND, either express or implied. See the License for the
16 + * specific language governing permissions and limitations
17 + * under the License.
18 + */
19 +package org.onlab.onos.store.serializers;
20 +
21 +import com.esotericsoftware.kryo.Kryo;
22 +import com.esotericsoftware.kryo.Serializer;
23 +import com.esotericsoftware.kryo.io.Input;
24 +import com.esotericsoftware.kryo.io.Output;
25 +import org.onlab.onos.core.DefaultApplicationId;
26 +
27 +/**
28 + * Kryo Serializer for {@link org.onlab.onos.core.DefaultApplicationId}.
29 + */
30 +public final class DefaultApplicationIdSerializer extends Serializer<DefaultApplicationId> {
31 +
32 + /**
33 + * Creates {@link org.onlab.onos.core.DefaultApplicationId} serializer instance.
34 + */
35 + public DefaultApplicationIdSerializer() {
36 + // non-null, immutable
37 + super(false, true);
38 + }
39 +
40 + @Override
41 + public void write(Kryo kryo, Output output, DefaultApplicationId object) {
42 + kryo.writeObject(output, object.id());
43 + kryo.writeObject(output, object.name());
44 + }
45 +
46 + @Override
47 + public DefaultApplicationId read(Kryo kryo, Input input, Class<DefaultApplicationId> type) {
48 + short id = kryo.readObject(input, Short.class);
49 + String name = kryo.readObject(input, String.class);
50 + return new DefaultApplicationId(id, name);
51 + }
52 +}
...@@ -7,6 +7,7 @@ import java.util.HashMap; ...@@ -7,6 +7,7 @@ import java.util.HashMap;
7 import java.util.HashSet; 7 import java.util.HashSet;
8 import java.util.LinkedList; 8 import java.util.LinkedList;
9 9
10 +import org.onlab.onos.core.DefaultApplicationId;
10 import org.onlab.onos.cluster.ControllerNode; 11 import org.onlab.onos.cluster.ControllerNode;
11 import org.onlab.onos.cluster.DefaultControllerNode; 12 import org.onlab.onos.cluster.DefaultControllerNode;
12 import org.onlab.onos.cluster.NodeId; 13 import org.onlab.onos.cluster.NodeId;
...@@ -129,6 +130,7 @@ public final class KryoNamespaces { ...@@ -129,6 +130,7 @@ public final class KryoNamespaces {
129 FlowRuleBatchEntry.class, 130 FlowRuleBatchEntry.class,
130 FlowRuleBatchEntry.FlowRuleOperation.class 131 FlowRuleBatchEntry.FlowRuleOperation.class
131 ) 132 )
133 + .register(DefaultApplicationId.class, new DefaultApplicationIdSerializer())
132 .register(URI.class, new URISerializer()) 134 .register(URI.class, new URISerializer())
133 .register(NodeId.class, new NodeIdSerializer()) 135 .register(NodeId.class, new NodeIdSerializer())
134 .register(ProviderId.class, new ProviderIdSerializer()) 136 .register(ProviderId.class, new ProviderIdSerializer())
......
1 +/*
2 + * Licensed to the Apache Software Foundation (ASF) under one
3 + * or more contributor license agreements. See the NOTICE file
4 + * distributed with this work for additional information
5 + * regarding copyright ownership. The ASF licenses this file
6 + * to you under the Apache License, Version 2.0 (the
7 + * "License"); you may not use this file except in compliance
8 + * with the License. You may obtain a copy of the License at
9 + *
10 + * http://www.apache.org/licenses/LICENSE-2.0
11 + *
12 + * Unless required by applicable law or agreed to in writing,
13 + * software distributed under the License is distributed on an
14 + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 + * KIND, either express or implied. See the License for the
16 + * specific language governing permissions and limitations
17 + * under the License.
18 + */
19 +package org.onlab.onos.store.trivial.impl;
20 +
21 +import com.google.common.collect.ImmutableSet;
22 +import org.apache.felix.scr.annotations.Component;
23 +import org.apache.felix.scr.annotations.Service;
24 +import org.onlab.onos.core.ApplicationId;
25 +import org.onlab.onos.core.ApplicationIdStore;
26 +import org.onlab.onos.core.DefaultApplicationId;
27 +
28 +import java.util.Map;
29 +import java.util.Set;
30 +import java.util.concurrent.ConcurrentHashMap;
31 +import java.util.concurrent.atomic.AtomicInteger;
32 +
33 +/**
34 + * Simple implementation of the application ID registry using in-memory
35 + * structures.
36 + */
37 +@Component(immediate = true)
38 +@Service
39 +public class SimpleApplicationIdStore implements ApplicationIdStore {
40 +
41 + private static final AtomicInteger ID_DISPENSER = new AtomicInteger(1);
42 +
43 + private final Map<Short, DefaultApplicationId> appIds = new ConcurrentHashMap<>();
44 + private final Map<String, DefaultApplicationId> appIdsByName = new ConcurrentHashMap<>();
45 +
46 + @Override
47 + public Set<ApplicationId> getAppIds() {
48 + return ImmutableSet.<ApplicationId>copyOf(appIds.values());
49 + }
50 +
51 + @Override
52 + public ApplicationId getAppId(Short id) {
53 + return appIds.get(id);
54 + }
55 +
56 + @Override
57 + public ApplicationId registerApplication(String name) {
58 + DefaultApplicationId appId = appIdsByName.get(name);
59 + if (appId == null) {
60 + short id = (short) ID_DISPENSER.getAndIncrement();
61 + appId = new DefaultApplicationId(id, name);
62 + appIds.put(id, appId);
63 + appIdsByName.put(name, appId);
64 + }
65 + return appId;
66 + }
67 +
68 +}
...@@ -38,7 +38,7 @@ import org.apache.felix.scr.annotations.Component; ...@@ -38,7 +38,7 @@ import org.apache.felix.scr.annotations.Component;
38 import org.apache.felix.scr.annotations.Deactivate; 38 import org.apache.felix.scr.annotations.Deactivate;
39 import org.apache.felix.scr.annotations.Reference; 39 import org.apache.felix.scr.annotations.Reference;
40 import org.apache.felix.scr.annotations.ReferenceCardinality; 40 import org.apache.felix.scr.annotations.ReferenceCardinality;
41 -import org.onlab.onos.ApplicationId; 41 +import org.onlab.onos.core.ApplicationId;
42 import org.onlab.onos.net.DeviceId; 42 import org.onlab.onos.net.DeviceId;
43 import org.onlab.onos.net.flow.BatchOperation; 43 import org.onlab.onos.net.flow.BatchOperation;
44 import org.onlab.onos.net.flow.CompletedBatchOperation; 44 import org.onlab.onos.net.flow.CompletedBatchOperation;
......