Merge branch 'master' of ssh://gerrit.onlab.us:29418/onos-next
Showing
45 changed files
with
450 additions
and
216 deletions
... | @@ -23,6 +23,10 @@ | ... | @@ -23,6 +23,10 @@ |
23 | <artifactId>onos-api</artifactId> | 23 | <artifactId>onos-api</artifactId> |
24 | </dependency> | 24 | </dependency> |
25 | <dependency> | 25 | <dependency> |
26 | + <groupId>org.onlab.onos</groupId> | ||
27 | + <artifactId>onlab-osgi</artifactId> | ||
28 | + </dependency> | ||
29 | + <dependency> | ||
26 | <groupId>org.osgi</groupId> | 30 | <groupId>org.osgi</groupId> |
27 | <artifactId>org.osgi.core</artifactId> | 31 | <artifactId>org.osgi.core</artifactId> |
28 | </dependency> | 32 | </dependency> | ... | ... |
1 | package org.onlab.onos.cli; | 1 | package org.onlab.onos.cli; |
2 | 2 | ||
3 | import org.apache.karaf.shell.console.OsgiCommandSupport; | 3 | import org.apache.karaf.shell.console.OsgiCommandSupport; |
4 | -import org.osgi.framework.BundleContext; | 4 | +import org.onlab.osgi.DefaultServiceDirectory; |
5 | -import org.osgi.framework.FrameworkUtil; | 5 | +import org.onlab.osgi.ServiceNotFoundException; |
6 | 6 | ||
7 | /** | 7 | /** |
8 | * Base abstraction of Karaf shell commands. | 8 | * Base abstraction of Karaf shell commands. |
... | @@ -17,8 +17,7 @@ public abstract class AbstractShellCommand extends OsgiCommandSupport { | ... | @@ -17,8 +17,7 @@ public abstract class AbstractShellCommand extends OsgiCommandSupport { |
17 | * @return service implementation | 17 | * @return service implementation |
18 | */ | 18 | */ |
19 | public static <T> T get(Class<T> serviceClass) { | 19 | public static <T> T get(Class<T> serviceClass) { |
20 | - BundleContext bc = FrameworkUtil.getBundle(AbstractShellCommand.class).getBundleContext(); | 20 | + return DefaultServiceDirectory.getService(serviceClass); |
21 | - return bc.getService(bc.getServiceReference(serviceClass)); | ||
22 | } | 21 | } |
23 | 22 | ||
24 | /** | 23 | /** |
... | @@ -41,4 +40,19 @@ public abstract class AbstractShellCommand extends OsgiCommandSupport { | ... | @@ -41,4 +40,19 @@ public abstract class AbstractShellCommand extends OsgiCommandSupport { |
41 | System.err.println(String.format(format, args)); | 40 | System.err.println(String.format(format, args)); |
42 | } | 41 | } |
43 | 42 | ||
43 | + /** | ||
44 | + * Executes this command. | ||
45 | + */ | ||
46 | + protected abstract void execute(); | ||
47 | + | ||
48 | + @Override | ||
49 | + protected Object doExecute() throws Exception { | ||
50 | + try { | ||
51 | + execute(); | ||
52 | + } catch (ServiceNotFoundException e) { | ||
53 | + error(e.getMessage()); | ||
54 | + } | ||
55 | + return null; | ||
56 | + } | ||
57 | + | ||
44 | } | 58 | } | ... | ... |
... | @@ -29,8 +29,8 @@ public class NodesListCommand extends AbstractShellCommand { | ... | @@ -29,8 +29,8 @@ public class NodesListCommand extends AbstractShellCommand { |
29 | }; | 29 | }; |
30 | 30 | ||
31 | @Override | 31 | @Override |
32 | - protected Object doExecute() throws Exception { | 32 | + protected void execute() { |
33 | - ClusterService service = getService(ClusterService.class); | 33 | + ClusterService service = get(ClusterService.class); |
34 | List<ControllerNode> nodes = newArrayList(service.getNodes()); | 34 | List<ControllerNode> nodes = newArrayList(service.getNodes()); |
35 | Collections.sort(nodes, ID_COMPARATOR); | 35 | Collections.sort(nodes, ID_COMPARATOR); |
36 | ControllerNode self = service.getLocalNode(); | 36 | ControllerNode self = service.getLocalNode(); |
... | @@ -39,7 +39,6 @@ public class NodesListCommand extends AbstractShellCommand { | ... | @@ -39,7 +39,6 @@ public class NodesListCommand extends AbstractShellCommand { |
39 | service.getState(node.id()), | 39 | service.getState(node.id()), |
40 | node.equals(self) ? "*" : ""); | 40 | node.equals(self) ? "*" : ""); |
41 | } | 41 | } |
42 | - return null; | ||
43 | } | 42 | } |
44 | 43 | ||
45 | } | 44 | } | ... | ... |
... | @@ -31,7 +31,7 @@ public class ClusterDevicesCommand extends ClustersListCommand { | ... | @@ -31,7 +31,7 @@ public class ClusterDevicesCommand extends ClustersListCommand { |
31 | }; | 31 | }; |
32 | 32 | ||
33 | @Override | 33 | @Override |
34 | - protected Object doExecute() throws Exception { | 34 | + protected void execute() { |
35 | int cid = Integer.parseInt(id); | 35 | int cid = Integer.parseInt(id); |
36 | init(); | 36 | init(); |
37 | TopologyCluster cluster = service.getCluster(topology, clusterId(cid)); | 37 | TopologyCluster cluster = service.getCluster(topology, clusterId(cid)); |
... | @@ -44,8 +44,6 @@ public class ClusterDevicesCommand extends ClustersListCommand { | ... | @@ -44,8 +44,6 @@ public class ClusterDevicesCommand extends ClustersListCommand { |
44 | print("%s", deviceId); | 44 | print("%s", deviceId); |
45 | } | 45 | } |
46 | } | 46 | } |
47 | - | ||
48 | - return null; | ||
49 | } | 47 | } |
50 | 48 | ||
51 | 49 | ... | ... |
... | @@ -20,7 +20,7 @@ public class ClusterLinksCommand extends ClustersListCommand { | ... | @@ -20,7 +20,7 @@ public class ClusterLinksCommand extends ClustersListCommand { |
20 | String id = null; | 20 | String id = null; |
21 | 21 | ||
22 | @Override | 22 | @Override |
23 | - protected Object doExecute() throws Exception { | 23 | + protected void execute() { |
24 | int cid = Integer.parseInt(id); | 24 | int cid = Integer.parseInt(id); |
25 | init(); | 25 | init(); |
26 | TopologyCluster cluster = service.getCluster(topology, clusterId(cid)); | 26 | TopologyCluster cluster = service.getCluster(topology, clusterId(cid)); |
... | @@ -31,7 +31,6 @@ public class ClusterLinksCommand extends ClustersListCommand { | ... | @@ -31,7 +31,6 @@ public class ClusterLinksCommand extends ClustersListCommand { |
31 | print(linkString(link)); | 31 | print(linkString(link)); |
32 | } | 32 | } |
33 | } | 33 | } |
34 | - return null; | ||
35 | } | 34 | } |
36 | 35 | ||
37 | } | 36 | } | ... | ... |
... | @@ -27,7 +27,7 @@ public class ClustersListCommand extends TopologyCommand { | ... | @@ -27,7 +27,7 @@ public class ClustersListCommand extends TopologyCommand { |
27 | }; | 27 | }; |
28 | 28 | ||
29 | @Override | 29 | @Override |
30 | - protected Object doExecute() throws Exception { | 30 | + protected void execute() { |
31 | init(); | 31 | init(); |
32 | List<TopologyCluster> clusters = Lists.newArrayList(service.getClusters(topology)); | 32 | List<TopologyCluster> clusters = Lists.newArrayList(service.getClusters(topology)); |
33 | Collections.sort(clusters, ID_COMPARATOR); | 33 | Collections.sort(clusters, ID_COMPARATOR); |
... | @@ -35,7 +35,6 @@ public class ClustersListCommand extends TopologyCommand { | ... | @@ -35,7 +35,6 @@ public class ClustersListCommand extends TopologyCommand { |
35 | for (TopologyCluster cluster : clusters) { | 35 | for (TopologyCluster cluster : clusters) { |
36 | print(FMT, cluster.id().index(), cluster.deviceCount(), cluster.linkCount()); | 36 | print(FMT, cluster.id().index(), cluster.deviceCount(), cluster.linkCount()); |
37 | } | 37 | } |
38 | - return null; | ||
39 | } | 38 | } |
40 | 39 | ||
41 | } | 40 | } | ... | ... |
... | @@ -35,7 +35,7 @@ public class DevicePortsListCommand extends DevicesListCommand { | ... | @@ -35,7 +35,7 @@ public class DevicePortsListCommand extends DevicesListCommand { |
35 | }; | 35 | }; |
36 | 36 | ||
37 | @Override | 37 | @Override |
38 | - protected Object doExecute() throws Exception { | 38 | + protected void execute() { |
39 | DeviceService service = getService(DeviceService.class); | 39 | DeviceService service = getService(DeviceService.class); |
40 | if (uri == null) { | 40 | if (uri == null) { |
41 | for (Device device : getSortedDevices(service)) { | 41 | for (Device device : getSortedDevices(service)) { |
... | @@ -49,7 +49,6 @@ public class DevicePortsListCommand extends DevicesListCommand { | ... | @@ -49,7 +49,6 @@ public class DevicePortsListCommand extends DevicesListCommand { |
49 | printDevice(service, device); | 49 | printDevice(service, device); |
50 | } | 50 | } |
51 | } | 51 | } |
52 | - return null; | ||
53 | } | 52 | } |
54 | 53 | ||
55 | @Override | 54 | @Override | ... | ... |
... | @@ -18,9 +18,8 @@ public class DeviceRemoveCommand extends AbstractShellCommand { | ... | @@ -18,9 +18,8 @@ public class DeviceRemoveCommand extends AbstractShellCommand { |
18 | String uri = null; | 18 | String uri = null; |
19 | 19 | ||
20 | @Override | 20 | @Override |
21 | - protected Object doExecute() throws Exception { | 21 | + protected void execute() { |
22 | getService(DeviceAdminService.class).removeDevice(DeviceId.deviceId(uri)); | 22 | getService(DeviceAdminService.class).removeDevice(DeviceId.deviceId(uri)); |
23 | - return null; | ||
24 | } | 23 | } |
25 | 24 | ||
26 | } | 25 | } | ... | ... |
... | @@ -23,11 +23,10 @@ public class DeviceRoleCommand extends AbstractShellCommand { | ... | @@ -23,11 +23,10 @@ public class DeviceRoleCommand extends AbstractShellCommand { |
23 | String role = null; | 23 | String role = null; |
24 | 24 | ||
25 | @Override | 25 | @Override |
26 | - protected Object doExecute() throws Exception { | 26 | + protected void execute() { |
27 | MastershipRole mastershipRole = MastershipRole.valueOf(role.toUpperCase()); | 27 | MastershipRole mastershipRole = MastershipRole.valueOf(role.toUpperCase()); |
28 | getService(DeviceAdminService.class).setRole(DeviceId.deviceId(uri), | 28 | getService(DeviceAdminService.class).setRole(DeviceId.deviceId(uri), |
29 | mastershipRole); | 29 | mastershipRole); |
30 | - return null; | ||
31 | } | 30 | } |
32 | 31 | ||
33 | } | 32 | } | ... | ... |
... | @@ -29,12 +29,11 @@ public class DevicesListCommand extends AbstractShellCommand { | ... | @@ -29,12 +29,11 @@ public class DevicesListCommand extends AbstractShellCommand { |
29 | }; | 29 | }; |
30 | 30 | ||
31 | @Override | 31 | @Override |
32 | - protected Object doExecute() throws Exception { | 32 | + protected void execute() { |
33 | DeviceService service = getService(DeviceService.class); | 33 | DeviceService service = getService(DeviceService.class); |
34 | for (Device device : getSortedDevices(service)) { | 34 | for (Device device : getSortedDevices(service)) { |
35 | printDevice(service, device); | 35 | printDevice(service, device); |
36 | } | 36 | } |
37 | - return null; | ||
38 | } | 37 | } |
39 | 38 | ||
40 | /** | 39 | /** | ... | ... |
... | @@ -34,14 +34,13 @@ public class FlowsListCommand extends AbstractShellCommand { | ... | @@ -34,14 +34,13 @@ public class FlowsListCommand extends AbstractShellCommand { |
34 | }; | 34 | }; |
35 | 35 | ||
36 | @Override | 36 | @Override |
37 | - protected Object doExecute() throws Exception { | 37 | + protected void execute() { |
38 | DeviceService deviceService = getService(DeviceService.class); | 38 | DeviceService deviceService = getService(DeviceService.class); |
39 | FlowRuleService service = getService(FlowRuleService.class); | 39 | FlowRuleService service = getService(FlowRuleService.class); |
40 | Map<Device, List<FlowRule>> flows = getSortedFlows(deviceService, service); | 40 | Map<Device, List<FlowRule>> flows = getSortedFlows(deviceService, service); |
41 | for (Device d : deviceService.getDevices()) { | 41 | for (Device d : deviceService.getDevices()) { |
42 | printFlows(d, flows.get(d)); | 42 | printFlows(d, flows.get(d)); |
43 | } | 43 | } |
44 | - return null; | ||
45 | } | 44 | } |
46 | 45 | ||
47 | 46 | ... | ... |
... | @@ -29,12 +29,11 @@ public class HostsListCommand extends AbstractShellCommand { | ... | @@ -29,12 +29,11 @@ public class HostsListCommand extends AbstractShellCommand { |
29 | }; | 29 | }; |
30 | 30 | ||
31 | @Override | 31 | @Override |
32 | - protected Object doExecute() throws Exception { | 32 | + protected void execute() { |
33 | HostService service = getService(HostService.class); | 33 | HostService service = getService(HostService.class); |
34 | for (Host host : getSortedHosts(service)) { | 34 | for (Host host : getSortedHosts(service)) { |
35 | printHost(host); | 35 | printHost(host); |
36 | } | 36 | } |
37 | - return null; | ||
38 | } | 37 | } |
39 | 38 | ||
40 | /** | 39 | /** | ... | ... |
... | @@ -23,14 +23,13 @@ public class LinksListCommand extends AbstractShellCommand { | ... | @@ -23,14 +23,13 @@ public class LinksListCommand extends AbstractShellCommand { |
23 | String uri = null; | 23 | String uri = null; |
24 | 24 | ||
25 | @Override | 25 | @Override |
26 | - protected Object doExecute() throws Exception { | 26 | + protected void execute() { |
27 | LinkService service = getService(LinkService.class); | 27 | LinkService service = getService(LinkService.class); |
28 | Iterable<Link> links = uri != null ? | 28 | Iterable<Link> links = uri != null ? |
29 | service.getDeviceLinks(deviceId(uri)) : service.getLinks(); | 29 | service.getDeviceLinks(deviceId(uri)) : service.getLinks(); |
30 | for (Link link : links) { | 30 | for (Link link : links) { |
31 | print(linkString(link)); | 31 | print(linkString(link)); |
32 | } | 32 | } |
33 | - return null; | ||
34 | } | 33 | } |
35 | 34 | ||
36 | /** | 35 | /** | ... | ... |
... | @@ -29,13 +29,12 @@ public class PathListCommand extends TopologyCommand { | ... | @@ -29,13 +29,12 @@ public class PathListCommand extends TopologyCommand { |
29 | String dst = null; | 29 | String dst = null; |
30 | 30 | ||
31 | @Override | 31 | @Override |
32 | - protected Object doExecute() throws Exception { | 32 | + protected void execute() { |
33 | init(); | 33 | init(); |
34 | Set<Path> paths = service.getPaths(topology, deviceId(src), deviceId(dst)); | 34 | Set<Path> paths = service.getPaths(topology, deviceId(src), deviceId(dst)); |
35 | for (Path path : paths) { | 35 | for (Path path : paths) { |
36 | print(pathString(path)); | 36 | print(pathString(path)); |
37 | } | 37 | } |
38 | - return null; | ||
39 | } | 38 | } |
40 | 39 | ||
41 | /** | 40 | /** | ... | ... |
... | @@ -28,11 +28,10 @@ public class TopologyCommand extends AbstractShellCommand { | ... | @@ -28,11 +28,10 @@ public class TopologyCommand extends AbstractShellCommand { |
28 | } | 28 | } |
29 | 29 | ||
30 | @Override | 30 | @Override |
31 | - protected Object doExecute() throws Exception { | 31 | + protected void execute() { |
32 | init(); | 32 | init(); |
33 | print(FMT, topology.time(), topology.deviceCount(), topology.linkCount(), | 33 | print(FMT, topology.time(), topology.deviceCount(), topology.linkCount(), |
34 | topology.clusterCount(), topology.pathCount()); | 34 | topology.clusterCount(), topology.pathCount()); |
35 | - return null; | ||
36 | } | 35 | } |
37 | 36 | ||
38 | } | 37 | } | ... | ... |
... | @@ -16,7 +16,7 @@ import org.onlab.onos.net.host.HostService; | ... | @@ -16,7 +16,7 @@ import org.onlab.onos.net.host.HostService; |
16 | public class WipeOutCommand extends ClustersListCommand { | 16 | public class WipeOutCommand extends ClustersListCommand { |
17 | 17 | ||
18 | @Override | 18 | @Override |
19 | - protected Object doExecute() throws Exception { | 19 | + protected void execute() { |
20 | DeviceAdminService deviceAdminService = get(DeviceAdminService.class); | 20 | DeviceAdminService deviceAdminService = get(DeviceAdminService.class); |
21 | DeviceService deviceService = get(DeviceService.class); | 21 | DeviceService deviceService = get(DeviceService.class); |
22 | for (Device device : deviceService.getDevices()) { | 22 | for (Device device : deviceService.getDevices()) { |
... | @@ -28,7 +28,6 @@ public class WipeOutCommand extends ClustersListCommand { | ... | @@ -28,7 +28,6 @@ public class WipeOutCommand extends ClustersListCommand { |
28 | for (Host host : hostService.getHosts()) { | 28 | for (Host host : hostService.getHosts()) { |
29 | hostAdminService.removeHost(host.id()); | 29 | hostAdminService.removeHost(host.id()); |
30 | } | 30 | } |
31 | - return null; | ||
32 | } | 31 | } |
33 | 32 | ||
34 | 33 | ... | ... |
... | @@ -37,6 +37,9 @@ public interface MastershipService { | ... | @@ -37,6 +37,9 @@ public interface MastershipService { |
37 | */ | 37 | */ |
38 | MastershipRole requestRoleFor(DeviceId deviceId); | 38 | MastershipRole requestRoleFor(DeviceId deviceId); |
39 | 39 | ||
40 | + // TODO: add facet for requesting a different master than the current one; | ||
41 | + // abandon mastership (due to loss of connection) | ||
42 | + | ||
40 | /** | 43 | /** |
41 | * Adds the specified mastership change listener. | 44 | * Adds the specified mastership change listener. |
42 | * | 45 | * | ... | ... |
... | @@ -2,13 +2,7 @@ package org.onlab.onos.net; | ... | @@ -2,13 +2,7 @@ package org.onlab.onos.net; |
2 | 2 | ||
3 | import static com.google.common.base.MoreObjects.toStringHelper; | 3 | import static com.google.common.base.MoreObjects.toStringHelper; |
4 | 4 | ||
5 | -import java.util.Collections; | ||
6 | import java.util.Objects; | 5 | import java.util.Objects; |
7 | -import java.util.Set; | ||
8 | - | ||
9 | -import org.onlab.packet.IpPrefix; | ||
10 | - | ||
11 | -import com.google.common.collect.ImmutableSet; | ||
12 | 6 | ||
13 | /** | 7 | /** |
14 | * Default port implementation. | 8 | * Default port implementation. |
... | @@ -19,9 +13,6 @@ public class DefaultPort implements Port { | ... | @@ -19,9 +13,6 @@ public class DefaultPort implements Port { |
19 | private final PortNumber number; | 13 | private final PortNumber number; |
20 | private final boolean isEnabled; | 14 | private final boolean isEnabled; |
21 | 15 | ||
22 | - // Attributes | ||
23 | - private final Set<IpPrefix> ipAddresses; | ||
24 | - | ||
25 | /** | 16 | /** |
26 | * Creates a network element attributed to the specified provider. | 17 | * Creates a network element attributed to the specified provider. |
27 | * | 18 | * |
... | @@ -31,24 +22,9 @@ public class DefaultPort implements Port { | ... | @@ -31,24 +22,9 @@ public class DefaultPort implements Port { |
31 | */ | 22 | */ |
32 | public DefaultPort(Element element, PortNumber number, | 23 | public DefaultPort(Element element, PortNumber number, |
33 | boolean isEnabled) { | 24 | boolean isEnabled) { |
34 | - this(element, number, isEnabled, null); | ||
35 | - } | ||
36 | - | ||
37 | - /** | ||
38 | - * Creates a network element attributed to the specified provider. | ||
39 | - * | ||
40 | - * @param element parent network element | ||
41 | - * @param number port number | ||
42 | - * @param isEnabled indicator whether the port is up and active | ||
43 | - * @param ipAddresses set of IP addresses assigned to the port | ||
44 | - */ | ||
45 | - public DefaultPort(Element element, PortNumber number, | ||
46 | - boolean isEnabled, Set<IpPrefix> ipAddresses) { | ||
47 | this.element = element; | 25 | this.element = element; |
48 | this.number = number; | 26 | this.number = number; |
49 | this.isEnabled = isEnabled; | 27 | this.isEnabled = isEnabled; |
50 | - this.ipAddresses = (ipAddresses == null) ? Collections.<IpPrefix>emptySet() : | ||
51 | - ImmutableSet.copyOf(ipAddresses); | ||
52 | } | 28 | } |
53 | 29 | ||
54 | @Override | 30 | @Override |
... | @@ -94,9 +70,4 @@ public class DefaultPort implements Port { | ... | @@ -94,9 +70,4 @@ public class DefaultPort implements Port { |
94 | return element; | 70 | return element; |
95 | } | 71 | } |
96 | 72 | ||
97 | - @Override | ||
98 | - public Set<IpPrefix> ipAddresses() { | ||
99 | - return ipAddresses; | ||
100 | - } | ||
101 | - | ||
102 | } | 73 | } | ... | ... |
1 | package org.onlab.onos.net; | 1 | package org.onlab.onos.net; |
2 | 2 | ||
3 | -import java.util.Set; | ||
4 | - | ||
5 | -import org.onlab.packet.IpPrefix; | ||
6 | 3 | ||
7 | /** | 4 | /** |
8 | * Abstraction of a network port. | 5 | * Abstraction of a network port. |
... | @@ -32,12 +29,4 @@ public interface Port { | ... | @@ -32,12 +29,4 @@ public interface Port { |
32 | 29 | ||
33 | // set of port attributes | 30 | // set of port attributes |
34 | 31 | ||
35 | - /** | ||
36 | - * Returns the set of IP addresses that are logically configured on this | ||
37 | - * port. | ||
38 | - * | ||
39 | - * @return the set of IP addresses configured on the port. The set is empty | ||
40 | - * if no addresses are configured. | ||
41 | - */ | ||
42 | - Set<IpPrefix> ipAddresses(); | ||
43 | } | 32 | } | ... | ... |
... | @@ -15,7 +15,7 @@ public interface DeviceAdminService { | ... | @@ -15,7 +15,7 @@ public interface DeviceAdminService { |
15 | * @param role requested role | 15 | * @param role requested role |
16 | * @deprecated Will be removed in favor of MastershipAdminService.setRole() | 16 | * @deprecated Will be removed in favor of MastershipAdminService.setRole() |
17 | */ | 17 | */ |
18 | - @Deprecated | 18 | +// @Deprecated |
19 | void setRole(DeviceId deviceId, MastershipRole role); | 19 | void setRole(DeviceId deviceId, MastershipRole role); |
20 | 20 | ||
21 | /** | 21 | /** | ... | ... |
1 | package org.onlab.onos.net.host; | 1 | package org.onlab.onos.net.host; |
2 | 2 | ||
3 | +import java.util.Set; | ||
4 | + | ||
5 | +import org.onlab.onos.net.ConnectPoint; | ||
3 | import org.onlab.onos.net.HostId; | 6 | import org.onlab.onos.net.HostId; |
7 | +import org.onlab.packet.IpAddress; | ||
8 | +import org.onlab.packet.MacAddress; | ||
4 | 9 | ||
5 | /** | 10 | /** |
6 | * Service for administering the inventory of end-station hosts. | 11 | * Service for administering the inventory of end-station hosts. |
... | @@ -14,4 +19,42 @@ public interface HostAdminService { | ... | @@ -14,4 +19,42 @@ public interface HostAdminService { |
14 | */ | 19 | */ |
15 | void removeHost(HostId hostId); | 20 | void removeHost(HostId hostId); |
16 | 21 | ||
22 | + /** | ||
23 | + * Binds an IP address and optional MAC address to the given connection | ||
24 | + * point. | ||
25 | + * <p/> | ||
26 | + * This method will overwrite any previously held address information for | ||
27 | + * the connection point. | ||
28 | + * | ||
29 | + * @param ip the IP address to bind to the connection point. This parameter | ||
30 | + * is mandatory and cannot be null. | ||
31 | + * @param mac the optional MAC address to bind to the connection point. Can | ||
32 | + * be set to null if no MAC address needs to be bound. | ||
33 | + * @param connectPoint the connection point to bind the addresses to | ||
34 | + */ | ||
35 | + void bindAddressesToPort(IpAddress ip, MacAddress mac, ConnectPoint connectPoint); | ||
36 | + | ||
37 | + /** | ||
38 | + * Removes all address information for the given connection point. | ||
39 | + * | ||
40 | + * @param connectPoint the connection point to remove address information | ||
41 | + */ | ||
42 | + void unbindAddressesFromPort(ConnectPoint connectPoint); | ||
43 | + | ||
44 | + /** | ||
45 | + * Returns the addresses information for all connection points. | ||
46 | + * | ||
47 | + * @return the set of address bindings for all connection points | ||
48 | + */ | ||
49 | + Set<PortAddresses> getAddressBindings(); | ||
50 | + | ||
51 | + /** | ||
52 | + * Retrieves the addresses that have been bound to the given connection | ||
53 | + * point. | ||
54 | + * | ||
55 | + * @param connectPoint the connection point to retrieve address bindings | ||
56 | + * for | ||
57 | + * @return addresses bound to the port | ||
58 | + */ | ||
59 | + PortAddresses getAddressBindingsForPort(ConnectPoint connectPoint); | ||
17 | } | 60 | } | ... | ... |
... | @@ -6,6 +6,7 @@ import org.onlab.onos.net.ConnectPoint; | ... | @@ -6,6 +6,7 @@ import org.onlab.onos.net.ConnectPoint; |
6 | import org.onlab.onos.net.DeviceId; | 6 | import org.onlab.onos.net.DeviceId; |
7 | import org.onlab.onos.net.Host; | 7 | import org.onlab.onos.net.Host; |
8 | import org.onlab.onos.net.HostId; | 8 | import org.onlab.onos.net.HostId; |
9 | +import org.onlab.packet.IpAddress; | ||
9 | import org.onlab.packet.IpPrefix; | 10 | import org.onlab.packet.IpPrefix; |
10 | import org.onlab.packet.MacAddress; | 11 | import org.onlab.packet.MacAddress; |
11 | import org.onlab.packet.VlanId; | 12 | import org.onlab.packet.VlanId; |
... | @@ -87,7 +88,7 @@ public interface HostService { | ... | @@ -87,7 +88,7 @@ public interface HostService { |
87 | * | 88 | * |
88 | * @param ip IP address of the host to monitor | 89 | * @param ip IP address of the host to monitor |
89 | */ | 90 | */ |
90 | - void monitorIp(IpPrefix ip); | 91 | + void startMonitoringIp(IpAddress ip); |
91 | 92 | ||
92 | /** | 93 | /** |
93 | * Stops the host service from monitoring an IP address. | 94 | * Stops the host service from monitoring an IP address. |
... | @@ -95,7 +96,18 @@ public interface HostService { | ... | @@ -95,7 +96,18 @@ public interface HostService { |
95 | * @param ip IP address to stop monitoring | 96 | * @param ip IP address to stop monitoring |
96 | */ | 97 | */ |
97 | // TODO clients can cancel other client's requests | 98 | // TODO clients can cancel other client's requests |
98 | - void stopMonitoringIp(IpPrefix ip); | 99 | + void stopMonitoringIp(IpAddress ip); |
100 | + | ||
101 | + /** | ||
102 | + * Requests the host service to resolve the MAC address for the given IP | ||
103 | + * address. | ||
104 | + * <p/> | ||
105 | + * This will trigger a notification to the host listeners if the MAC | ||
106 | + * address is found. | ||
107 | + * | ||
108 | + * @param ip IP address to find the MAC address for | ||
109 | + */ | ||
110 | + void requestMac(IpAddress ip); | ||
99 | 111 | ||
100 | /** | 112 | /** |
101 | * Adds the specified host listener. | 113 | * Adds the specified host listener. | ... | ... |
1 | package org.onlab.onos.net.host; | 1 | package org.onlab.onos.net.host; |
2 | 2 | ||
3 | +import java.util.Set; | ||
4 | + | ||
3 | import org.onlab.onos.net.ConnectPoint; | 5 | import org.onlab.onos.net.ConnectPoint; |
4 | import org.onlab.onos.net.DeviceId; | 6 | import org.onlab.onos.net.DeviceId; |
5 | import org.onlab.onos.net.Host; | 7 | import org.onlab.onos.net.Host; |
... | @@ -9,8 +11,6 @@ import org.onlab.packet.IpPrefix; | ... | @@ -9,8 +11,6 @@ import org.onlab.packet.IpPrefix; |
9 | import org.onlab.packet.MacAddress; | 11 | import org.onlab.packet.MacAddress; |
10 | import org.onlab.packet.VlanId; | 12 | import org.onlab.packet.VlanId; |
11 | 13 | ||
12 | -import java.util.Set; | ||
13 | - | ||
14 | /** | 14 | /** |
15 | * Manages inventory of end-station hosts; not intended for direct use. | 15 | * Manages inventory of end-station hosts; not intended for direct use. |
16 | */ | 16 | */ |
... | @@ -98,4 +98,34 @@ public interface HostStore { | ... | @@ -98,4 +98,34 @@ public interface HostStore { |
98 | */ | 98 | */ |
99 | Set<Host> getConnectedHosts(DeviceId deviceId); | 99 | Set<Host> getConnectedHosts(DeviceId deviceId); |
100 | 100 | ||
101 | + /** | ||
102 | + * Updates the address information for a given port. | ||
103 | + * | ||
104 | + * @param addresses the port and address information | ||
105 | + */ | ||
106 | + void updateAddressBindings(PortAddresses addresses); | ||
107 | + | ||
108 | + /** | ||
109 | + * Removes any previously stored address information for a given connection | ||
110 | + * point. | ||
111 | + * | ||
112 | + * @param connectPoint the connection point | ||
113 | + */ | ||
114 | + void removeAddressBindings(ConnectPoint connectPoint); | ||
115 | + | ||
116 | + /** | ||
117 | + * Returns the address bindings stored for all connection points. | ||
118 | + * | ||
119 | + * @return the set of address bindings | ||
120 | + */ | ||
121 | + Set<PortAddresses> getAddressBindings(); | ||
122 | + | ||
123 | + /** | ||
124 | + * Returns the address bindings for a particular connection point. | ||
125 | + * | ||
126 | + * @param connectPoint the connection point to return address information | ||
127 | + * for | ||
128 | + * @return address information for the connection point | ||
129 | + */ | ||
130 | + PortAddresses getAddressBindingsForPort(ConnectPoint connectPoint); | ||
101 | } | 131 | } | ... | ... |
1 | +package org.onlab.onos.net.host; | ||
2 | + | ||
3 | +import org.onlab.onos.net.ConnectPoint; | ||
4 | +import org.onlab.packet.IpAddress; | ||
5 | +import org.onlab.packet.MacAddress; | ||
6 | + | ||
7 | +/** | ||
8 | + * Represents address information bound to a port. | ||
9 | + */ | ||
10 | +public interface PortAddresses { | ||
11 | + | ||
12 | + /** | ||
13 | + * Returns the connection point this address information is bound to. | ||
14 | + * | ||
15 | + * @return the connection point | ||
16 | + */ | ||
17 | + ConnectPoint connectPoint(); | ||
18 | + | ||
19 | + /** | ||
20 | + * Returns the IP address bound to the port. | ||
21 | + * | ||
22 | + * @return the IP address | ||
23 | + */ | ||
24 | + IpAddress ip(); | ||
25 | + | ||
26 | + /** | ||
27 | + * Returns the MAC address bound to the port. | ||
28 | + * | ||
29 | + * @return the MAC address if one is bound, otherwise null | ||
30 | + */ | ||
31 | + MacAddress mac(); | ||
32 | +} |
... | @@ -6,6 +6,7 @@ import org.onlab.onos.net.ConnectPoint; | ... | @@ -6,6 +6,7 @@ import org.onlab.onos.net.ConnectPoint; |
6 | import org.onlab.onos.net.DeviceId; | 6 | import org.onlab.onos.net.DeviceId; |
7 | import org.onlab.onos.net.Host; | 7 | import org.onlab.onos.net.Host; |
8 | import org.onlab.onos.net.HostId; | 8 | import org.onlab.onos.net.HostId; |
9 | +import org.onlab.packet.IpAddress; | ||
9 | import org.onlab.packet.IpPrefix; | 10 | import org.onlab.packet.IpPrefix; |
10 | import org.onlab.packet.MacAddress; | 11 | import org.onlab.packet.MacAddress; |
11 | import org.onlab.packet.VlanId; | 12 | import org.onlab.packet.VlanId; |
... | @@ -55,11 +56,15 @@ public class HostServiceAdapter implements HostService { | ... | @@ -55,11 +56,15 @@ public class HostServiceAdapter implements HostService { |
55 | } | 56 | } |
56 | 57 | ||
57 | @Override | 58 | @Override |
58 | - public void monitorIp(IpPrefix ip) { | 59 | + public void startMonitoringIp(IpAddress ip) { |
59 | } | 60 | } |
60 | 61 | ||
61 | @Override | 62 | @Override |
62 | - public void stopMonitoringIp(IpPrefix ip) { | 63 | + public void stopMonitoringIp(IpAddress ip) { |
64 | + } | ||
65 | + | ||
66 | + @Override | ||
67 | + public void requestMac(IpAddress ip) { | ||
63 | } | 68 | } |
64 | 69 | ||
65 | @Override | 70 | @Override | ... | ... |
1 | +package org.onlab.onos.net.host.impl; | ||
2 | + | ||
3 | +import org.onlab.onos.net.ConnectPoint; | ||
4 | +import org.onlab.onos.net.host.PortAddresses; | ||
5 | +import org.onlab.packet.IpAddress; | ||
6 | +import org.onlab.packet.MacAddress; | ||
7 | + | ||
8 | +public class DefaultPortAddresses implements PortAddresses { | ||
9 | + | ||
10 | + private final ConnectPoint connectPoint; | ||
11 | + private final IpAddress ipAddress; | ||
12 | + private final MacAddress macAddress; | ||
13 | + | ||
14 | + public DefaultPortAddresses(ConnectPoint connectPoint, | ||
15 | + IpAddress ip, MacAddress mac) { | ||
16 | + this.connectPoint = connectPoint; | ||
17 | + this.ipAddress = ip; | ||
18 | + this.macAddress = mac; | ||
19 | + } | ||
20 | + | ||
21 | + @Override | ||
22 | + public ConnectPoint connectPoint() { | ||
23 | + return connectPoint; | ||
24 | + } | ||
25 | + | ||
26 | + @Override | ||
27 | + public IpAddress ip() { | ||
28 | + return ipAddress; | ||
29 | + } | ||
30 | + | ||
31 | + @Override | ||
32 | + public MacAddress mac() { | ||
33 | + return macAddress; | ||
34 | + } | ||
35 | + | ||
36 | +} |
... | @@ -26,8 +26,10 @@ import org.onlab.onos.net.host.HostProviderRegistry; | ... | @@ -26,8 +26,10 @@ import org.onlab.onos.net.host.HostProviderRegistry; |
26 | import org.onlab.onos.net.host.HostProviderService; | 26 | import org.onlab.onos.net.host.HostProviderService; |
27 | import org.onlab.onos.net.host.HostService; | 27 | import org.onlab.onos.net.host.HostService; |
28 | import org.onlab.onos.net.host.HostStore; | 28 | import org.onlab.onos.net.host.HostStore; |
29 | +import org.onlab.onos.net.host.PortAddresses; | ||
29 | import org.onlab.onos.net.provider.AbstractProviderRegistry; | 30 | import org.onlab.onos.net.provider.AbstractProviderRegistry; |
30 | import org.onlab.onos.net.provider.AbstractProviderService; | 31 | import org.onlab.onos.net.provider.AbstractProviderService; |
32 | +import org.onlab.packet.IpAddress; | ||
31 | import org.onlab.packet.IpPrefix; | 33 | import org.onlab.packet.IpPrefix; |
32 | import org.onlab.packet.MacAddress; | 34 | import org.onlab.packet.MacAddress; |
33 | import org.onlab.packet.VlanId; | 35 | import org.onlab.packet.VlanId; |
... | @@ -118,13 +120,18 @@ public class HostManager | ... | @@ -118,13 +120,18 @@ public class HostManager |
118 | } | 120 | } |
119 | 121 | ||
120 | @Override | 122 | @Override |
121 | - public void monitorIp(IpPrefix ip) { | 123 | + public void startMonitoringIp(IpAddress ip) { |
122 | - // TODO pass through to SimpleHostMonitor | 124 | + // TODO pass through to HostMonitor |
123 | } | 125 | } |
124 | 126 | ||
125 | @Override | 127 | @Override |
126 | - public void stopMonitoringIp(IpPrefix ip) { | 128 | + public void stopMonitoringIp(IpAddress ip) { |
127 | - // TODO pass through to SimpleHostMonitor | 129 | + // TODO pass through to HostMonitor |
130 | + } | ||
131 | + | ||
132 | + @Override | ||
133 | + public void requestMac(IpAddress ip) { | ||
134 | + // TODO Auto-generated method stub | ||
128 | } | 135 | } |
129 | 136 | ||
130 | @Override | 137 | @Override |
... | @@ -147,6 +154,27 @@ public class HostManager | ... | @@ -147,6 +154,27 @@ public class HostManager |
147 | } | 154 | } |
148 | } | 155 | } |
149 | 156 | ||
157 | + @Override | ||
158 | + public void bindAddressesToPort(IpAddress ip, MacAddress mac, | ||
159 | + ConnectPoint connectPoint) { | ||
160 | + store.updateAddressBindings(new DefaultPortAddresses(connectPoint, ip, mac)); | ||
161 | + } | ||
162 | + | ||
163 | + @Override | ||
164 | + public void unbindAddressesFromPort(ConnectPoint connectPoint) { | ||
165 | + store.removeAddressBindings(connectPoint); | ||
166 | + } | ||
167 | + | ||
168 | + @Override | ||
169 | + public Set<PortAddresses> getAddressBindings() { | ||
170 | + return store.getAddressBindings(); | ||
171 | + } | ||
172 | + | ||
173 | + @Override | ||
174 | + public PortAddresses getAddressBindingsForPort(ConnectPoint connectPoint) { | ||
175 | + return store.getAddressBindingsForPort(connectPoint); | ||
176 | + } | ||
177 | + | ||
150 | // Personalized host provider service issued to the supplied provider. | 178 | // Personalized host provider service issued to the supplied provider. |
151 | private class InternalHostProviderService | 179 | private class InternalHostProviderService |
152 | extends AbstractProviderService<HostProvider> | 180 | extends AbstractProviderService<HostProvider> | ... | ... |
... | @@ -6,7 +6,6 @@ import java.util.concurrent.TimeUnit; | ... | @@ -6,7 +6,6 @@ import java.util.concurrent.TimeUnit; |
6 | 6 | ||
7 | import org.jboss.netty.util.Timeout; | 7 | import org.jboss.netty.util.Timeout; |
8 | import org.jboss.netty.util.TimerTask; | 8 | import org.jboss.netty.util.TimerTask; |
9 | -import org.onlab.onos.net.Device; | ||
10 | import org.onlab.onos.net.Host; | 9 | import org.onlab.onos.net.Host; |
11 | import org.onlab.onos.net.Port; | 10 | import org.onlab.onos.net.Port; |
12 | import org.onlab.onos.net.device.DeviceService; | 11 | import org.onlab.onos.net.device.DeviceService; |
... | @@ -89,7 +88,7 @@ public class HostMonitor implements TimerTask { | ... | @@ -89,7 +88,7 @@ public class HostMonitor implements TimerTask { |
89 | // else (ip isn't in any configured subnet) | 88 | // else (ip isn't in any configured subnet) |
90 | // send out all non-external edge ports | 89 | // send out all non-external edge ports |
91 | 90 | ||
92 | - for (Device device : deviceService.getDevices()) { | 91 | + /*for (Device device : deviceService.getDevices()) { |
93 | for (Port port : deviceService.getPorts(device.id())) { | 92 | for (Port port : deviceService.getPorts(device.id())) { |
94 | for (IpPrefix ip : port.ipAddresses()) { | 93 | for (IpPrefix ip : port.ipAddresses()) { |
95 | if (ip.contains(targetIp)) { | 94 | if (ip.contains(targetIp)) { |
... | @@ -98,7 +97,7 @@ public class HostMonitor implements TimerTask { | ... | @@ -98,7 +97,7 @@ public class HostMonitor implements TimerTask { |
98 | } | 97 | } |
99 | } | 98 | } |
100 | } | 99 | } |
101 | - } | 100 | + }*/ |
102 | 101 | ||
103 | } | 102 | } |
104 | 103 | ... | ... |
1 | package org.onlab.onos.net.device.impl; | 1 | package org.onlab.onos.net.device.impl; |
2 | 2 | ||
3 | +import com.google.common.collect.Iterables; | ||
4 | +import com.hazelcast.config.Config; | ||
5 | +import com.hazelcast.core.Hazelcast; | ||
3 | import com.hazelcast.core.HazelcastInstance; | 6 | import com.hazelcast.core.HazelcastInstance; |
4 | import org.junit.After; | 7 | import org.junit.After; |
5 | import org.junit.Before; | 8 | import org.junit.Before; |
6 | import org.junit.Test; | 9 | import org.junit.Test; |
7 | import org.onlab.onos.event.Event; | 10 | import org.onlab.onos.event.Event; |
11 | +import org.onlab.onos.event.impl.TestEventDispatcher; | ||
8 | import org.onlab.onos.net.Device; | 12 | import org.onlab.onos.net.Device; |
9 | import org.onlab.onos.net.DeviceId; | 13 | import org.onlab.onos.net.DeviceId; |
10 | import org.onlab.onos.net.MastershipRole; | 14 | import org.onlab.onos.net.MastershipRole; |
... | @@ -23,13 +27,9 @@ import org.onlab.onos.net.device.DeviceService; | ... | @@ -23,13 +27,9 @@ import org.onlab.onos.net.device.DeviceService; |
23 | import org.onlab.onos.net.device.PortDescription; | 27 | import org.onlab.onos.net.device.PortDescription; |
24 | import org.onlab.onos.net.provider.AbstractProvider; | 28 | import org.onlab.onos.net.provider.AbstractProvider; |
25 | import org.onlab.onos.net.provider.ProviderId; | 29 | import org.onlab.onos.net.provider.ProviderId; |
26 | -import org.onlab.onos.event.impl.TestEventDispatcher; | ||
27 | import org.onlab.onos.store.StoreService; | 30 | import org.onlab.onos.store.StoreService; |
28 | import org.onlab.onos.store.device.impl.DistributedDeviceStore; | 31 | import org.onlab.onos.store.device.impl.DistributedDeviceStore; |
29 | - | 32 | +import org.onlab.onos.store.impl.StoreManager; |
30 | -import com.google.common.collect.Iterables; | ||
31 | -import com.hazelcast.config.Config; | ||
32 | -import com.hazelcast.core.Hazelcast; | ||
33 | 33 | ||
34 | import java.util.ArrayList; | 34 | import java.util.ArrayList; |
35 | import java.util.Iterator; | 35 | import java.util.Iterator; |
... | @@ -64,6 +64,7 @@ public class DistributedDeviceManagerTest { | ... | @@ -64,6 +64,7 @@ public class DistributedDeviceManagerTest { |
64 | 64 | ||
65 | private DeviceManager mgr; | 65 | private DeviceManager mgr; |
66 | 66 | ||
67 | + protected StoreManager storeManager; | ||
67 | protected DeviceService service; | 68 | protected DeviceService service; |
68 | protected DeviceAdminService admin; | 69 | protected DeviceAdminService admin; |
69 | protected DeviceProviderRegistry registry; | 70 | protected DeviceProviderRegistry registry; |
... | @@ -89,7 +90,11 @@ public class DistributedDeviceManagerTest { | ... | @@ -89,7 +90,11 @@ public class DistributedDeviceManagerTest { |
89 | config.getNetworkConfig().getJoin() | 90 | config.getNetworkConfig().getJoin() |
90 | .getMulticastConfig() | 91 | .getMulticastConfig() |
91 | .setEnabled(false); | 92 | .setEnabled(false); |
92 | - dstore = new TestDistributedDeviceStore(Hazelcast.newHazelcastInstance(config)); | 93 | + |
94 | + storeManager = new TestStoreManager(Hazelcast.newHazelcastInstance(config)); | ||
95 | + storeManager.activate(); | ||
96 | + | ||
97 | + dstore = new TestDistributedDeviceStore(storeManager); | ||
93 | dstore.activate(); | 98 | dstore.activate(); |
94 | mgr.store = dstore; | 99 | mgr.store = dstore; |
95 | mgr.eventDispatcher = new TestEventDispatcher(); | 100 | mgr.eventDispatcher = new TestEventDispatcher(); |
... | @@ -112,7 +117,7 @@ public class DistributedDeviceManagerTest { | ... | @@ -112,7 +117,7 @@ public class DistributedDeviceManagerTest { |
112 | mgr.deactivate(); | 117 | mgr.deactivate(); |
113 | 118 | ||
114 | dstore.deactivate(); | 119 | dstore.deactivate(); |
115 | - ((TestDistributedDeviceStore) dstore).shutdownHz(); | 120 | + storeManager.deactivate(); |
116 | } | 121 | } |
117 | 122 | ||
118 | private void connectDevice(DeviceId deviceId, String swVersion) { | 123 | private void connectDevice(DeviceId deviceId, String swVersion) { |
... | @@ -282,20 +287,19 @@ public class DistributedDeviceManagerTest { | ... | @@ -282,20 +287,19 @@ public class DistributedDeviceManagerTest { |
282 | } | 287 | } |
283 | 288 | ||
284 | private class TestDistributedDeviceStore extends DistributedDeviceStore { | 289 | private class TestDistributedDeviceStore extends DistributedDeviceStore { |
285 | - public TestDistributedDeviceStore(final HazelcastInstance hazelcastInstance) { | 290 | + public TestDistributedDeviceStore(StoreService storeService) { |
286 | - storeService = new StoreService() { | 291 | + this.storeService = storeService; |
287 | - @Override | ||
288 | - public HazelcastInstance getHazelcastInstance() { | ||
289 | - return hazelcastInstance; | ||
290 | } | 292 | } |
291 | - }; | ||
292 | } | 293 | } |
293 | 294 | ||
294 | - /** | 295 | + private class TestStoreManager extends StoreManager { |
295 | - * Shutdowns the hazelcast instance. | 296 | + TestStoreManager(HazelcastInstance instance) { |
296 | - */ | 297 | + this.instance = instance; |
297 | - public void shutdownHz() { | 298 | + } |
298 | - theInstance.shutdown(); | 299 | + |
300 | + @Override | ||
301 | + public void activate() { | ||
302 | + setupKryoPool(); | ||
299 | } | 303 | } |
300 | } | 304 | } |
301 | } | 305 | } | ... | ... |
... | @@ -15,4 +15,22 @@ public interface StoreService { | ... | @@ -15,4 +15,22 @@ public interface StoreService { |
15 | */ | 15 | */ |
16 | HazelcastInstance getHazelcastInstance(); | 16 | HazelcastInstance getHazelcastInstance(); |
17 | 17 | ||
18 | + /** | ||
19 | + * Serializes the specified object into bytes using one of the | ||
20 | + * pre-registered serializers. | ||
21 | + * | ||
22 | + * @param obj object to be serialized | ||
23 | + * @return serialized bytes | ||
24 | + */ | ||
25 | + public byte[] serialize(final Object obj); | ||
26 | + | ||
27 | + /** | ||
28 | + * Deserializes the specified bytes into an object using one of the | ||
29 | + * pre-registered serializers. | ||
30 | + * | ||
31 | + * @param bytes bytes to be deserialized | ||
32 | + * @return deserialized object | ||
33 | + */ | ||
34 | + public <T> T deserialize(final byte[] bytes); | ||
35 | + | ||
18 | } | 36 | } | ... | ... |
1 | package org.onlab.onos.store.device.impl; | 1 | package org.onlab.onos.store.device.impl; |
2 | 2 | ||
3 | -import static com.google.common.base.Preconditions.checkArgument; | 3 | +import com.google.common.base.Optional; |
4 | -import static com.google.common.base.Preconditions.checkNotNull; | 4 | +import com.google.common.cache.CacheBuilder; |
5 | -import static org.onlab.onos.net.device.DeviceEvent.Type.DEVICE_AVAILABILITY_CHANGED; | 5 | +import com.google.common.cache.CacheLoader; |
6 | -import static org.onlab.onos.net.device.DeviceEvent.Type.DEVICE_MASTERSHIP_CHANGED; | 6 | +import com.google.common.cache.LoadingCache; |
7 | -import static org.onlab.onos.net.device.DeviceEvent.Type.DEVICE_REMOVED; | 7 | +import com.google.common.collect.ImmutableList; |
8 | -import static org.onlab.onos.net.device.DeviceEvent.Type.PORT_ADDED; | 8 | +import com.google.common.collect.ImmutableSet; |
9 | -import static org.onlab.onos.net.device.DeviceEvent.Type.PORT_REMOVED; | 9 | +import com.google.common.collect.ImmutableSet.Builder; |
10 | -import static org.onlab.onos.net.device.DeviceEvent.Type.PORT_UPDATED; | 10 | +import com.hazelcast.core.EntryAdapter; |
11 | -import static org.slf4j.LoggerFactory.getLogger; | 11 | +import com.hazelcast.core.EntryEvent; |
12 | - | 12 | +import com.hazelcast.core.HazelcastInstance; |
13 | -import java.net.URI; | 13 | +import com.hazelcast.core.IMap; |
14 | -import java.util.ArrayList; | 14 | +import com.hazelcast.core.ISet; |
15 | -import java.util.Collections; | 15 | +import com.hazelcast.core.MapEvent; |
16 | -import java.util.HashMap; | ||
17 | -import java.util.HashSet; | ||
18 | -import java.util.Iterator; | ||
19 | -import java.util.List; | ||
20 | -import java.util.Map; | ||
21 | -import java.util.Objects; | ||
22 | -import java.util.Set; | ||
23 | - | ||
24 | import org.apache.felix.scr.annotations.Activate; | 16 | import org.apache.felix.scr.annotations.Activate; |
25 | import org.apache.felix.scr.annotations.Component; | 17 | import org.apache.felix.scr.annotations.Component; |
26 | import org.apache.felix.scr.annotations.Deactivate; | 18 | import org.apache.felix.scr.annotations.Deactivate; |
... | @@ -31,7 +23,6 @@ import org.onlab.onos.net.DefaultDevice; | ... | @@ -31,7 +23,6 @@ import org.onlab.onos.net.DefaultDevice; |
31 | import org.onlab.onos.net.DefaultPort; | 23 | import org.onlab.onos.net.DefaultPort; |
32 | import org.onlab.onos.net.Device; | 24 | import org.onlab.onos.net.Device; |
33 | import org.onlab.onos.net.DeviceId; | 25 | import org.onlab.onos.net.DeviceId; |
34 | -import org.onlab.onos.net.Element; | ||
35 | import org.onlab.onos.net.MastershipRole; | 26 | import org.onlab.onos.net.MastershipRole; |
36 | import org.onlab.onos.net.Port; | 27 | import org.onlab.onos.net.Port; |
37 | import org.onlab.onos.net.PortNumber; | 28 | import org.onlab.onos.net.PortNumber; |
... | @@ -41,24 +32,23 @@ import org.onlab.onos.net.device.DeviceStore; | ... | @@ -41,24 +32,23 @@ import org.onlab.onos.net.device.DeviceStore; |
41 | import org.onlab.onos.net.device.PortDescription; | 32 | import org.onlab.onos.net.device.PortDescription; |
42 | import org.onlab.onos.net.provider.ProviderId; | 33 | import org.onlab.onos.net.provider.ProviderId; |
43 | import org.onlab.onos.store.StoreService; | 34 | import org.onlab.onos.store.StoreService; |
44 | -import org.onlab.util.KryoPool; | 35 | +import org.onlab.onos.store.impl.AbsentInvalidatingLoadingCache; |
45 | import org.slf4j.Logger; | 36 | import org.slf4j.Logger; |
46 | 37 | ||
47 | -import com.google.common.base.Optional; | 38 | +import java.util.ArrayList; |
48 | -import com.google.common.cache.CacheBuilder; | 39 | +import java.util.Collections; |
49 | -import com.google.common.cache.CacheLoader; | 40 | +import java.util.HashMap; |
50 | -import com.google.common.cache.LoadingCache; | 41 | +import java.util.HashSet; |
51 | -import com.google.common.collect.ImmutableList; | 42 | +import java.util.Iterator; |
52 | -import com.google.common.collect.ImmutableSet; | 43 | +import java.util.List; |
53 | -import com.google.common.collect.ImmutableSet.Builder; | 44 | +import java.util.Map; |
54 | -import com.hazelcast.core.EntryAdapter; | 45 | +import java.util.Objects; |
55 | -import com.hazelcast.core.EntryEvent; | 46 | +import java.util.Set; |
56 | -import com.hazelcast.core.HazelcastInstance; | ||
57 | -import com.hazelcast.core.IMap; | ||
58 | -import com.hazelcast.core.ISet; | ||
59 | -import com.hazelcast.core.MapEvent; | ||
60 | 47 | ||
61 | -import de.javakaffee.kryoserializers.URISerializer; | 48 | +import static com.google.common.base.Preconditions.checkArgument; |
49 | +import static com.google.common.base.Preconditions.checkNotNull; | ||
50 | +import static org.onlab.onos.net.device.DeviceEvent.Type.*; | ||
51 | +import static org.slf4j.LoggerFactory.getLogger; | ||
62 | 52 | ||
63 | 53 | ||
64 | /** | 54 | /** |
... | @@ -72,27 +62,6 @@ public class DistributedDeviceStore implements DeviceStore { | ... | @@ -72,27 +62,6 @@ public class DistributedDeviceStore implements DeviceStore { |
72 | 62 | ||
73 | public static final String DEVICE_NOT_FOUND = "Device with ID %s not found"; | 63 | public static final String DEVICE_NOT_FOUND = "Device with ID %s not found"; |
74 | 64 | ||
75 | - // FIXME Slice out types used in common to separate pool/namespace. | ||
76 | - private static final KryoPool POOL = KryoPool.newBuilder() | ||
77 | - .register( | ||
78 | - ArrayList.class, | ||
79 | - HashMap.class, | ||
80 | - | ||
81 | - Device.Type.class, | ||
82 | - | ||
83 | - DefaultDevice.class, | ||
84 | - MastershipRole.class, | ||
85 | - Port.class, | ||
86 | - Element.class | ||
87 | - ) | ||
88 | - .register(URI.class, new URISerializer()) | ||
89 | - .register(ProviderId.class, new ProviderIdSerializer()) | ||
90 | - .register(DeviceId.class, new DeviceIdSerializer()) | ||
91 | - .register(PortNumber.class, new PortNumberSerializer()) | ||
92 | - .register(DefaultPort.class, new DefaultPortSerializer()) | ||
93 | - .build() | ||
94 | - .populate(10); | ||
95 | - | ||
96 | // private IMap<DeviceId, DefaultDevice> cache; | 65 | // private IMap<DeviceId, DefaultDevice> cache; |
97 | private IMap<byte[], byte[]> rawDevices; | 66 | private IMap<byte[], byte[]> rawDevices; |
98 | private LoadingCache<DeviceId, Optional<DefaultDevice>> devices; | 67 | private LoadingCache<DeviceId, Optional<DefaultDevice>> devices; |
... | @@ -126,33 +95,33 @@ public class DistributedDeviceStore implements DeviceStore { | ... | @@ -126,33 +95,33 @@ public class DistributedDeviceStore implements DeviceStore { |
126 | 95 | ||
127 | // TODO decide on Map name scheme to avoid collision | 96 | // TODO decide on Map name scheme to avoid collision |
128 | rawDevices = theInstance.getMap("devices"); | 97 | rawDevices = theInstance.getMap("devices"); |
129 | - devices = new AbsentInvalidatingLoadingCache<DeviceId, DefaultDevice>( | 98 | + devices = new AbsentInvalidatingLoadingCache<>( |
130 | CacheBuilder.newBuilder() | 99 | CacheBuilder.newBuilder() |
131 | .build(new OptionalCacheLoader<DeviceId, DefaultDevice>(rawDevices))); | 100 | .build(new OptionalCacheLoader<DeviceId, DefaultDevice>(rawDevices))); |
132 | // refresh/populate cache based on notification from other instance | 101 | // refresh/populate cache based on notification from other instance |
133 | rawDevices.addEntryListener( | 102 | rawDevices.addEntryListener( |
134 | - new RemoteEventHandler<DeviceId, DefaultDevice>(devices), | 103 | + new RemoteEventHandler<>(devices), |
135 | includeValue); | 104 | includeValue); |
136 | 105 | ||
137 | rawRoles = theInstance.getMap("roles"); | 106 | rawRoles = theInstance.getMap("roles"); |
138 | - roles = new AbsentInvalidatingLoadingCache<DeviceId, MastershipRole>( | 107 | + roles = new AbsentInvalidatingLoadingCache<>( |
139 | CacheBuilder.newBuilder() | 108 | CacheBuilder.newBuilder() |
140 | .build(new OptionalCacheLoader<DeviceId, MastershipRole>(rawRoles))); | 109 | .build(new OptionalCacheLoader<DeviceId, MastershipRole>(rawRoles))); |
141 | // refresh/populate cache based on notification from other instance | 110 | // refresh/populate cache based on notification from other instance |
142 | rawRoles.addEntryListener( | 111 | rawRoles.addEntryListener( |
143 | - new RemoteEventHandler<DeviceId, MastershipRole>(roles), | 112 | + new RemoteEventHandler<>(roles), |
144 | includeValue); | 113 | includeValue); |
145 | 114 | ||
146 | // TODO cache avai | 115 | // TODO cache avai |
147 | availableDevices = theInstance.getSet("availableDevices"); | 116 | availableDevices = theInstance.getSet("availableDevices"); |
148 | 117 | ||
149 | rawDevicePorts = theInstance.getMap("devicePorts"); | 118 | rawDevicePorts = theInstance.getMap("devicePorts"); |
150 | - devicePorts = new AbsentInvalidatingLoadingCache<DeviceId, Map<PortNumber, Port>>( | 119 | + devicePorts = new AbsentInvalidatingLoadingCache<>( |
151 | CacheBuilder.newBuilder() | 120 | CacheBuilder.newBuilder() |
152 | .build(new OptionalCacheLoader<DeviceId, Map<PortNumber, Port>>(rawDevicePorts))); | 121 | .build(new OptionalCacheLoader<DeviceId, Map<PortNumber, Port>>(rawDevicePorts))); |
153 | // refresh/populate cache based on notification from other instance | 122 | // refresh/populate cache based on notification from other instance |
154 | rawDevicePorts.addEntryListener( | 123 | rawDevicePorts.addEntryListener( |
155 | - new RemoteEventHandler<DeviceId, Map<PortNumber, Port>>(devicePorts), | 124 | + new RemoteEventHandler<>(devicePorts), |
156 | includeValue); | 125 | includeValue); |
157 | 126 | ||
158 | } | 127 | } |
... | @@ -181,7 +150,7 @@ public class DistributedDeviceStore implements DeviceStore { | ... | @@ -181,7 +150,7 @@ public class DistributedDeviceStore implements DeviceStore { |
181 | // } | 150 | // } |
182 | 151 | ||
183 | // TODO builder v.s. copyOf. Guava semms to be using copyOf? | 152 | // TODO builder v.s. copyOf. Guava semms to be using copyOf? |
184 | - Builder<Device> builder = ImmutableSet.<Device>builder(); | 153 | + Builder<Device> builder = ImmutableSet.builder(); |
185 | for (Optional<DefaultDevice> e : devices.asMap().values()) { | 154 | for (Optional<DefaultDevice> e : devices.asMap().values()) { |
186 | if (e.isPresent()) { | 155 | if (e.isPresent()) { |
187 | builder.add(e.get()); | 156 | builder.add(e.get()); |
... | @@ -428,16 +397,12 @@ public class DistributedDeviceStore implements DeviceStore { | ... | @@ -428,16 +397,12 @@ public class DistributedDeviceStore implements DeviceStore { |
428 | } | 397 | } |
429 | 398 | ||
430 | // TODO cache serialized DeviceID if we suffer from serialization cost | 399 | // TODO cache serialized DeviceID if we suffer from serialization cost |
431 | - | 400 | + private byte[] serialize(final Object obj) { |
432 | - private static byte[] serialize(final Object obj) { | 401 | + return storeService.serialize(obj); |
433 | - return POOL.serialize(obj); | ||
434 | } | 402 | } |
435 | 403 | ||
436 | - private static <T> T deserialize(final byte[] bytes) { | 404 | + private <T> T deserialize(final byte[] bytes) { |
437 | - if (bytes == null) { | 405 | + return storeService.deserialize(bytes); |
438 | - return null; | ||
439 | - } | ||
440 | - return POOL.deserialize(bytes); | ||
441 | } | 406 | } |
442 | 407 | ||
443 | /** | 408 | /** |
... | @@ -446,7 +411,7 @@ public class DistributedDeviceStore implements DeviceStore { | ... | @@ -446,7 +411,7 @@ public class DistributedDeviceStore implements DeviceStore { |
446 | * @param <K> IMap key type after deserialization | 411 | * @param <K> IMap key type after deserialization |
447 | * @param <V> IMap value type after deserialization | 412 | * @param <V> IMap value type after deserialization |
448 | */ | 413 | */ |
449 | - public static final class RemoteEventHandler<K, V> extends | 414 | + public final class RemoteEventHandler<K, V> extends |
450 | EntryAdapter<byte[], byte[]> { | 415 | EntryAdapter<byte[], byte[]> { |
451 | 416 | ||
452 | private LoadingCache<K, Optional<V>> cache; | 417 | private LoadingCache<K, Optional<V>> cache; |
... | @@ -468,14 +433,13 @@ public class DistributedDeviceStore implements DeviceStore { | ... | @@ -468,14 +433,13 @@ public class DistributedDeviceStore implements DeviceStore { |
468 | 433 | ||
469 | @Override | 434 | @Override |
470 | public void entryUpdated(EntryEvent<byte[], byte[]> event) { | 435 | public void entryUpdated(EntryEvent<byte[], byte[]> event) { |
471 | - cache.put(POOL.<K>deserialize(event.getKey()), | 436 | + cache.put(storeService.<K>deserialize(event.getKey()), |
472 | - Optional.of(POOL.<V>deserialize( | 437 | + Optional.of(storeService.<V>deserialize(event.getValue()))); |
473 | - event.getValue()))); | ||
474 | } | 438 | } |
475 | 439 | ||
476 | @Override | 440 | @Override |
477 | public void entryRemoved(EntryEvent<byte[], byte[]> event) { | 441 | public void entryRemoved(EntryEvent<byte[], byte[]> event) { |
478 | - cache.invalidate(POOL.<DeviceId>deserialize(event.getKey())); | 442 | + cache.invalidate(storeService.<DeviceId>deserialize(event.getKey())); |
479 | } | 443 | } |
480 | 444 | ||
481 | @Override | 445 | @Override |
... | @@ -491,7 +455,7 @@ public class DistributedDeviceStore implements DeviceStore { | ... | @@ -491,7 +455,7 @@ public class DistributedDeviceStore implements DeviceStore { |
491 | * @param <K> IMap key type after deserialization | 455 | * @param <K> IMap key type after deserialization |
492 | * @param <V> IMap value type after deserialization | 456 | * @param <V> IMap value type after deserialization |
493 | */ | 457 | */ |
494 | - public static final class OptionalCacheLoader<K, V> extends | 458 | + public final class OptionalCacheLoader<K, V> extends |
495 | CacheLoader<K, Optional<V>> { | 459 | CacheLoader<K, Optional<V>> { |
496 | 460 | ||
497 | private IMap<byte[], byte[]> rawMap; | 461 | private IMap<byte[], byte[]> rawMap; |
... | @@ -507,7 +471,7 @@ public class DistributedDeviceStore implements DeviceStore { | ... | @@ -507,7 +471,7 @@ public class DistributedDeviceStore implements DeviceStore { |
507 | 471 | ||
508 | @Override | 472 | @Override |
509 | public Optional<V> load(K key) throws Exception { | 473 | public Optional<V> load(K key) throws Exception { |
510 | - byte[] keyBytes = serialize(key); | 474 | + byte[] keyBytes = storeService.serialize(key); |
511 | byte[] valBytes = rawMap.get(keyBytes); | 475 | byte[] valBytes = rawMap.get(keyBytes); |
512 | if (valBytes == null) { | 476 | if (valBytes == null) { |
513 | return Optional.absent(); | 477 | return Optional.absent(); | ... | ... |
... | @@ -2,14 +2,33 @@ package org.onlab.onos.store.impl; | ... | @@ -2,14 +2,33 @@ package org.onlab.onos.store.impl; |
2 | 2 | ||
3 | import com.hazelcast.core.Hazelcast; | 3 | import com.hazelcast.core.Hazelcast; |
4 | import com.hazelcast.core.HazelcastInstance; | 4 | import com.hazelcast.core.HazelcastInstance; |
5 | +import de.javakaffee.kryoserializers.URISerializer; | ||
5 | import org.apache.felix.scr.annotations.Activate; | 6 | import org.apache.felix.scr.annotations.Activate; |
6 | import org.apache.felix.scr.annotations.Component; | 7 | import org.apache.felix.scr.annotations.Component; |
7 | import org.apache.felix.scr.annotations.Deactivate; | 8 | import org.apache.felix.scr.annotations.Deactivate; |
8 | import org.apache.felix.scr.annotations.Service; | 9 | import org.apache.felix.scr.annotations.Service; |
10 | +import org.onlab.onos.net.DefaultDevice; | ||
11 | +import org.onlab.onos.net.DefaultPort; | ||
12 | +import org.onlab.onos.net.Device; | ||
13 | +import org.onlab.onos.net.DeviceId; | ||
14 | +import org.onlab.onos.net.Element; | ||
15 | +import org.onlab.onos.net.MastershipRole; | ||
16 | +import org.onlab.onos.net.Port; | ||
17 | +import org.onlab.onos.net.PortNumber; | ||
18 | +import org.onlab.onos.net.provider.ProviderId; | ||
9 | import org.onlab.onos.store.StoreService; | 19 | import org.onlab.onos.store.StoreService; |
20 | +import org.onlab.onos.store.serializers.DefaultPortSerializer; | ||
21 | +import org.onlab.onos.store.serializers.DeviceIdSerializer; | ||
22 | +import org.onlab.onos.store.serializers.PortNumberSerializer; | ||
23 | +import org.onlab.onos.store.serializers.ProviderIdSerializer; | ||
24 | +import org.onlab.util.KryoPool; | ||
10 | import org.slf4j.Logger; | 25 | import org.slf4j.Logger; |
11 | import org.slf4j.LoggerFactory; | 26 | import org.slf4j.LoggerFactory; |
12 | 27 | ||
28 | +import java.net.URI; | ||
29 | +import java.util.ArrayList; | ||
30 | +import java.util.HashMap; | ||
31 | + | ||
13 | /** | 32 | /** |
14 | * Auxiliary bootstrap of distributed store. | 33 | * Auxiliary bootstrap of distributed store. |
15 | */ | 34 | */ |
... | @@ -20,15 +39,45 @@ public class StoreManager implements StoreService { | ... | @@ -20,15 +39,45 @@ public class StoreManager implements StoreService { |
20 | private final Logger log = LoggerFactory.getLogger(getClass()); | 39 | private final Logger log = LoggerFactory.getLogger(getClass()); |
21 | 40 | ||
22 | protected HazelcastInstance instance; | 41 | protected HazelcastInstance instance; |
42 | + private KryoPool serializerPool; | ||
43 | + | ||
23 | 44 | ||
24 | @Activate | 45 | @Activate |
25 | public void activate() { | 46 | public void activate() { |
26 | instance = Hazelcast.newHazelcastInstance(); | 47 | instance = Hazelcast.newHazelcastInstance(); |
48 | + setupKryoPool(); | ||
27 | log.info("Started"); | 49 | log.info("Started"); |
28 | } | 50 | } |
29 | 51 | ||
52 | + /** | ||
53 | + * Sets up the common serialzers pool. | ||
54 | + */ | ||
55 | + protected void setupKryoPool() { | ||
56 | + // FIXME Slice out types used in common to separate pool/namespace. | ||
57 | + serializerPool = KryoPool.newBuilder() | ||
58 | + .register( | ||
59 | + ArrayList.class, | ||
60 | + HashMap.class, | ||
61 | + | ||
62 | + Device.Type.class, | ||
63 | + | ||
64 | + DefaultDevice.class, | ||
65 | + MastershipRole.class, | ||
66 | + Port.class, | ||
67 | + Element.class | ||
68 | + ) | ||
69 | + .register(URI.class, new URISerializer()) | ||
70 | + .register(ProviderId.class, new ProviderIdSerializer()) | ||
71 | + .register(DeviceId.class, new DeviceIdSerializer()) | ||
72 | + .register(PortNumber.class, new PortNumberSerializer()) | ||
73 | + .register(DefaultPort.class, new DefaultPortSerializer()) | ||
74 | + .build() | ||
75 | + .populate(10); | ||
76 | + } | ||
77 | + | ||
30 | @Deactivate | 78 | @Deactivate |
31 | public void deactivate() { | 79 | public void deactivate() { |
80 | + instance.shutdown(); | ||
32 | log.info("Stopped"); | 81 | log.info("Stopped"); |
33 | } | 82 | } |
34 | 83 | ||
... | @@ -36,4 +85,19 @@ public class StoreManager implements StoreService { | ... | @@ -36,4 +85,19 @@ public class StoreManager implements StoreService { |
36 | public HazelcastInstance getHazelcastInstance() { | 85 | public HazelcastInstance getHazelcastInstance() { |
37 | return instance; | 86 | return instance; |
38 | } | 87 | } |
88 | + | ||
89 | + | ||
90 | + @Override | ||
91 | + public byte[] serialize(final Object obj) { | ||
92 | + return serializerPool.serialize(obj); | ||
93 | + } | ||
94 | + | ||
95 | + @Override | ||
96 | + public <T> T deserialize(final byte[] bytes) { | ||
97 | + if (bytes == null) { | ||
98 | + return null; | ||
99 | + } | ||
100 | + return serializerPool.deserialize(bytes); | ||
101 | + } | ||
102 | + | ||
39 | } | 103 | } | ... | ... |
1 | -package org.onlab.onos.store.device.impl; | 1 | +package org.onlab.onos.store.serializers; |
2 | - | ||
3 | -import java.util.ArrayList; | ||
4 | -import java.util.Collection; | ||
5 | 2 | ||
6 | import org.onlab.onos.net.DefaultPort; | 3 | import org.onlab.onos.net.DefaultPort; |
7 | import org.onlab.onos.net.Element; | 4 | import org.onlab.onos.net.Element; |
8 | import org.onlab.onos.net.PortNumber; | 5 | import org.onlab.onos.net.PortNumber; |
9 | -import org.onlab.packet.IpPrefix; | ||
10 | 6 | ||
11 | import com.esotericsoftware.kryo.Kryo; | 7 | import com.esotericsoftware.kryo.Kryo; |
12 | import com.esotericsoftware.kryo.Serializer; | 8 | import com.esotericsoftware.kryo.Serializer; |
13 | import com.esotericsoftware.kryo.io.Input; | 9 | import com.esotericsoftware.kryo.io.Input; |
14 | import com.esotericsoftware.kryo.io.Output; | 10 | import com.esotericsoftware.kryo.io.Output; |
15 | -import com.esotericsoftware.kryo.serializers.CollectionSerializer; | ||
16 | -import com.google.common.collect.ImmutableSet; | ||
17 | 11 | ||
18 | // TODO move to util, etc. | 12 | // TODO move to util, etc. |
19 | /** | 13 | /** |
... | @@ -22,10 +16,6 @@ import com.google.common.collect.ImmutableSet; | ... | @@ -22,10 +16,6 @@ import com.google.common.collect.ImmutableSet; |
22 | public final class DefaultPortSerializer extends | 16 | public final class DefaultPortSerializer extends |
23 | Serializer<DefaultPort> { | 17 | Serializer<DefaultPort> { |
24 | 18 | ||
25 | - private final CollectionSerializer ipAddrSerializer | ||
26 | - = new CollectionSerializer(IpPrefix.class, | ||
27 | - new IpPrefixSerializer(), false); | ||
28 | - | ||
29 | /** | 19 | /** |
30 | * Default constructor. | 20 | * Default constructor. |
31 | */ | 21 | */ |
... | @@ -39,8 +29,6 @@ public final class DefaultPortSerializer extends | ... | @@ -39,8 +29,6 @@ public final class DefaultPortSerializer extends |
39 | kryo.writeClassAndObject(output, object.element()); | 29 | kryo.writeClassAndObject(output, object.element()); |
40 | kryo.writeObject(output, object.number()); | 30 | kryo.writeObject(output, object.number()); |
41 | output.writeBoolean(object.isEnabled()); | 31 | output.writeBoolean(object.isEnabled()); |
42 | - kryo.writeObject(output, object.ipAddresses(), | ||
43 | - ipAddrSerializer); | ||
44 | } | 32 | } |
45 | 33 | ||
46 | @Override | 34 | @Override |
... | @@ -49,11 +37,7 @@ public final class DefaultPortSerializer extends | ... | @@ -49,11 +37,7 @@ public final class DefaultPortSerializer extends |
49 | Element element = (Element) kryo.readClassAndObject(input); | 37 | Element element = (Element) kryo.readClassAndObject(input); |
50 | PortNumber number = kryo.readObject(input, PortNumber.class); | 38 | PortNumber number = kryo.readObject(input, PortNumber.class); |
51 | boolean isEnabled = input.readBoolean(); | 39 | boolean isEnabled = input.readBoolean(); |
52 | - @SuppressWarnings("unchecked") | ||
53 | - Collection<IpPrefix> ipAddresses = kryo.readObject( | ||
54 | - input, ArrayList.class, ipAddrSerializer); | ||
55 | 40 | ||
56 | - return new DefaultPort(element, number, isEnabled, | 41 | + return new DefaultPort(element, number, isEnabled); |
57 | - ImmutableSet.copyOf(ipAddresses)); | ||
58 | } | 42 | } |
59 | } | 43 | } | ... | ... |
... | @@ -24,15 +24,16 @@ import org.onlab.onos.net.HostId; | ... | @@ -24,15 +24,16 @@ import org.onlab.onos.net.HostId; |
24 | import org.onlab.onos.net.host.HostDescription; | 24 | import org.onlab.onos.net.host.HostDescription; |
25 | import org.onlab.onos.net.host.HostEvent; | 25 | import org.onlab.onos.net.host.HostEvent; |
26 | import org.onlab.onos.net.host.HostStore; | 26 | import org.onlab.onos.net.host.HostStore; |
27 | +import org.onlab.onos.net.host.PortAddresses; | ||
27 | import org.onlab.onos.net.provider.ProviderId; | 28 | import org.onlab.onos.net.provider.ProviderId; |
28 | import org.onlab.packet.IpPrefix; | 29 | import org.onlab.packet.IpPrefix; |
29 | import org.onlab.packet.MacAddress; | 30 | import org.onlab.packet.MacAddress; |
30 | import org.onlab.packet.VlanId; | 31 | import org.onlab.packet.VlanId; |
32 | +import org.slf4j.Logger; | ||
31 | 33 | ||
32 | import com.google.common.collect.HashMultimap; | 34 | import com.google.common.collect.HashMultimap; |
33 | import com.google.common.collect.ImmutableSet; | 35 | import com.google.common.collect.ImmutableSet; |
34 | import com.google.common.collect.Multimap; | 36 | import com.google.common.collect.Multimap; |
35 | -import org.slf4j.Logger; | ||
36 | 37 | ||
37 | /** | 38 | /** |
38 | * Manages inventory of end-station hosts using trivial in-memory | 39 | * Manages inventory of end-station hosts using trivial in-memory |
... | @@ -50,6 +51,9 @@ public class SimpleHostStore implements HostStore { | ... | @@ -50,6 +51,9 @@ public class SimpleHostStore implements HostStore { |
50 | // Hosts tracked by their location | 51 | // Hosts tracked by their location |
51 | private final Multimap<ConnectPoint, Host> locations = HashMultimap.create(); | 52 | private final Multimap<ConnectPoint, Host> locations = HashMultimap.create(); |
52 | 53 | ||
54 | + private final Map<ConnectPoint, PortAddresses> portAddresses = | ||
55 | + new ConcurrentHashMap<>(); | ||
56 | + | ||
53 | @Activate | 57 | @Activate |
54 | public void activate() { | 58 | public void activate() { |
55 | log.info("Started"); | 59 | log.info("Started"); |
... | @@ -192,4 +196,24 @@ public class SimpleHostStore implements HostStore { | ... | @@ -192,4 +196,24 @@ public class SimpleHostStore implements HostStore { |
192 | return hostset; | 196 | return hostset; |
193 | } | 197 | } |
194 | 198 | ||
199 | + @Override | ||
200 | + public void updateAddressBindings(PortAddresses addresses) { | ||
201 | + portAddresses.put(addresses.connectPoint(), addresses); | ||
202 | + } | ||
203 | + | ||
204 | + @Override | ||
205 | + public void removeAddressBindings(ConnectPoint connectPoint) { | ||
206 | + portAddresses.remove(connectPoint); | ||
207 | + } | ||
208 | + | ||
209 | + @Override | ||
210 | + public Set<PortAddresses> getAddressBindings() { | ||
211 | + return new HashSet<>(portAddresses.values()); | ||
212 | + } | ||
213 | + | ||
214 | + @Override | ||
215 | + public PortAddresses getAddressBindingsForPort(ConnectPoint connectPoint) { | ||
216 | + return portAddresses.get(connectPoint); | ||
217 | + } | ||
218 | + | ||
195 | } | 219 | } | ... | ... |
... | @@ -172,6 +172,11 @@ | ... | @@ -172,6 +172,11 @@ |
172 | </dependency> | 172 | </dependency> |
173 | <dependency> | 173 | <dependency> |
174 | <groupId>org.onlab.onos</groupId> | 174 | <groupId>org.onlab.onos</groupId> |
175 | + <artifactId>onlab-osgi</artifactId> | ||
176 | + <version>${project.version}</version> | ||
177 | + </dependency> | ||
178 | + <dependency> | ||
179 | + <groupId>org.onlab.onos</groupId> | ||
175 | <artifactId>onlab-junit</artifactId> | 180 | <artifactId>onlab-junit</artifactId> |
176 | <version>1.0.0-SNAPSHOT</version> | 181 | <version>1.0.0-SNAPSHOT</version> |
177 | <scope>test</scope> | 182 | <scope>test</scope> | ... | ... |
... | @@ -46,7 +46,8 @@ alias gui='open http://localhost:8181/onos/tvue' | ... | @@ -46,7 +46,8 @@ alias gui='open http://localhost:8181/onos/tvue' |
46 | # Test related conveniences | 46 | # Test related conveniences |
47 | 47 | ||
48 | # SSH to a specified ONOS instance | 48 | # SSH to a specified ONOS instance |
49 | -alias sshctl=onos-ssh | 49 | +alias sshctl='onos-ssh' |
50 | +alias sshnet='onos-ssh $OCN' | ||
50 | 51 | ||
51 | # Applies the settings in the specified cell file or lists current cell definition | 52 | # Applies the settings in the specified cell file or lists current cell definition |
52 | # if no cell file is given. | 53 | # if no cell file is given. |
... | @@ -62,6 +63,7 @@ function cell { | ... | @@ -62,6 +63,7 @@ function cell { |
62 | env | egrep "ONOS_CELL" | 63 | env | egrep "ONOS_CELL" |
63 | env | egrep "OCI" | 64 | env | egrep "OCI" |
64 | env | egrep "OC[0-9]+" | sort | 65 | env | egrep "OC[0-9]+" | sort |
66 | + env | egrep "OCN" | ||
65 | fi | 67 | fi |
66 | } | 68 | } |
67 | 69 | ... | ... |
... | @@ -6,6 +6,6 @@ | ... | @@ -6,6 +6,6 @@ |
6 | [ ! -d "$ONOS_ROOT" ] && echo "ONOS_ROOT is not defined" >&2 && exit 1 | 6 | [ ! -d "$ONOS_ROOT" ] && echo "ONOS_ROOT is not defined" >&2 && exit 1 |
7 | . $ONOS_ROOT/tools/build/envDefaults | 7 | . $ONOS_ROOT/tools/build/envDefaults |
8 | 8 | ||
9 | -for node in $(env | sort | egrep "OC[0-9]+" | cut -d= -f2); do | 9 | +for node in $(env | sort | egrep "OC[0-9N]+" | cut -d= -f2); do |
10 | printf "%s: " $node; ssh -n -o PasswordAuthentication=no $ONOS_USER@$node date | 10 | printf "%s: " $node; ssh -n -o PasswordAuthentication=no $ONOS_USER@$node date |
11 | done | 11 | done |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
1 | -# Default virtual box ONOS instances 1,2 & 3 | 1 | +# Default virtual box ONOS instances 1,2 & ONOS mininet box |
2 | 2 | ||
3 | export OC1="192.168.56.101" | 3 | export OC1="192.168.56.101" |
4 | export OC2="192.168.56.102" | 4 | export OC2="192.168.56.102" |
5 | -export OC3="192.168.56.103" | 5 | + |
6 | +export OCN="192.168.56.103" | ||
6 | 7 | ||
7 | 8 | ... | ... |
... | @@ -7,8 +7,15 @@ import org.osgi.framework.FrameworkUtil; | ... | @@ -7,8 +7,15 @@ import org.osgi.framework.FrameworkUtil; |
7 | * Default implementation of the service directory using OSGi framework utilities. | 7 | * Default implementation of the service directory using OSGi framework utilities. |
8 | */ | 8 | */ |
9 | public class DefaultServiceDirectory implements ServiceDirectory { | 9 | public class DefaultServiceDirectory implements ServiceDirectory { |
10 | - @Override | 10 | + |
11 | - public <T> T get(Class<T> serviceClass) { | 11 | + /** |
12 | + * Returns the reference to the implementation of the specified service. | ||
13 | + * | ||
14 | + * @param serviceClass service class | ||
15 | + * @param <T> type of service | ||
16 | + * @return service implementation | ||
17 | + */ | ||
18 | + public static <T> T getService(Class<T> serviceClass) { | ||
12 | BundleContext bc = FrameworkUtil.getBundle(serviceClass).getBundleContext(); | 19 | BundleContext bc = FrameworkUtil.getBundle(serviceClass).getBundleContext(); |
13 | T impl = bc.getService(bc.getServiceReference(serviceClass)); | 20 | T impl = bc.getService(bc.getServiceReference(serviceClass)); |
14 | if (impl == null) { | 21 | if (impl == null) { |
... | @@ -16,4 +23,10 @@ public class DefaultServiceDirectory implements ServiceDirectory { | ... | @@ -16,4 +23,10 @@ public class DefaultServiceDirectory implements ServiceDirectory { |
16 | } | 23 | } |
17 | return impl; | 24 | return impl; |
18 | } | 25 | } |
26 | + | ||
27 | + @Override | ||
28 | + public <T> T get(Class<T> serviceClass) { | ||
29 | + return getService(serviceClass); | ||
30 | + } | ||
31 | + | ||
19 | } | 32 | } | ... | ... |
-
Please register or login to post a comment