pankaj

Merge branch 'master' of ssh://gerrit.onlab.us:29418/onos-next

Showing 120 changed files with 1170 additions and 790 deletions
...@@ -28,8 +28,10 @@ ...@@ -28,8 +28,10 @@
28 <dependency> 28 <dependency>
29 <groupId>com.fasterxml.jackson.core</groupId> 29 <groupId>com.fasterxml.jackson.core</groupId>
30 <artifactId>jackson-annotations</artifactId> 30 <artifactId>jackson-annotations</artifactId>
31 - <version>2.4.2</version> 31 + </dependency>
32 - <scope>provided</scope> 32 + <dependency>
33 + <groupId>org.onlab.onos</groupId>
34 + <artifactId>onlab-misc</artifactId>
33 </dependency> 35 </dependency>
34 </dependencies> 36 </dependencies>
35 37
......
...@@ -41,5 +41,17 @@ ...@@ -41,5 +41,17 @@
41 <groupId>org.apache.karaf.shell</groupId> 41 <groupId>org.apache.karaf.shell</groupId>
42 <artifactId>org.apache.karaf.shell.console</artifactId> 42 <artifactId>org.apache.karaf.shell.console</artifactId>
43 </dependency> 43 </dependency>
44 + <dependency>
45 + <groupId>org.onlab.onos</groupId>
46 + <artifactId>onlab-misc</artifactId>
47 + </dependency>
48 + <dependency>
49 + <groupId>com.google.guava</groupId>
50 + <artifactId>guava</artifactId>
51 + </dependency>
52 + <dependency>
53 + <groupId>org.osgi</groupId>
54 + <artifactId>org.osgi.core</artifactId>
55 + </dependency>
44 </dependencies> 56 </dependencies>
45 </project> 57 </project>
......
...@@ -170,10 +170,6 @@ public class ReactiveForwarding { ...@@ -170,10 +170,6 @@ public class ReactiveForwarding {
170 // We don't yet support bufferids in the flowservice so packet out first. 170 // We don't yet support bufferids in the flowservice so packet out first.
171 packetOut(context, portNumber); 171 packetOut(context, portNumber);
172 172
173 - if (true) {
174 - return;
175 - }
176 -
177 // Install the flow rule to handle this type of message from now on. 173 // Install the flow rule to handle this type of message from now on.
178 Ethernet inPkt = context.inPacket().parsed(); 174 Ethernet inPkt = context.inPacket().parsed();
179 TrafficSelector.Builder builder = DefaultTrafficSelector.builder(); 175 TrafficSelector.Builder builder = DefaultTrafficSelector.builder();
......
...@@ -16,4 +16,14 @@ ...@@ -16,4 +16,14 @@
16 16
17 <description>ONOS simple Mobility app</description> 17 <description>ONOS simple Mobility app</description>
18 18
19 + <dependencies>
20 + <dependency>
21 + <groupId>com.google.guava</groupId>
22 + <artifactId>guava</artifactId>
23 + </dependency>
24 + <dependency>
25 + <groupId>org.onlab.onos</groupId>
26 + <artifactId>onlab-misc</artifactId>
27 + </dependency>
28 + </dependencies>
19 </project> 29 </project>
......
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
24 <module>mobility</module> 24 <module>mobility</module>
25 <module>proxyarp</module> 25 <module>proxyarp</module>
26 <module>config</module> 26 <module>config</module>
27 + <module>sdnip</module>
27 </modules> 28 </modules>
28 29
29 <properties> 30 <properties>
......
1 +<?xml version="1.0" encoding="UTF-8"?>
2 +<project xmlns="http://maven.apache.org/POM/4.0.0"
3 + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4 + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
5 + <modelVersion>4.0.0</modelVersion>
6 +
7 + <parent>
8 + <groupId>org.onlab.onos</groupId>
9 + <artifactId>onos-apps</artifactId>
10 + <version>1.0.0-SNAPSHOT</version>
11 + <relativePath>../pom.xml</relativePath>
12 + </parent>
13 +
14 + <artifactId>onos-app-sdnip</artifactId>
15 + <packaging>bundle</packaging>
16 +
17 + <description>SDN-IP peering application</description>
18 +
19 + <dependencies>
20 + <dependency>
21 + <groupId>org.codehaus.jackson</groupId>
22 + <artifactId>jackson-core-asl</artifactId>
23 + </dependency>
24 + <dependency>
25 + <groupId>org.codehaus.jackson</groupId>
26 + <artifactId>jackson-mapper-asl</artifactId>
27 + </dependency>
28 + <dependency>
29 + <groupId>com.fasterxml.jackson.core</groupId>
30 + <artifactId>jackson-annotations</artifactId>
31 + <version>2.4.2</version>
32 + <scope>provided</scope>
33 + </dependency>
34 + </dependencies>
35 +
36 +</project>
1 +package org.onlab.onos.sdnip;
2 +
3 +import static org.slf4j.LoggerFactory.getLogger;
4 +
5 +import org.apache.felix.scr.annotations.Activate;
6 +import org.apache.felix.scr.annotations.Component;
7 +import org.apache.felix.scr.annotations.Deactivate;
8 +import org.slf4j.Logger;
9 +
10 +/**
11 + * Placeholder SDN-IP component.
12 + */
13 +@Component(immediate = true)
14 +public class SdnIp {
15 +
16 + private final Logger log = getLogger(getClass());
17 +
18 + @Activate
19 + protected void activate() {
20 + log.debug("SDN-IP started");
21 + }
22 +
23 + @Deactivate
24 + protected void deactivate() {
25 + log.info("Stopped");
26 + }
27 +}
1 +/**
2 + * SDN-IP peering application.
3 + */
4 +package org.onlab.onos.sdnip;
...\ No newline at end of file ...\ No newline at end of file
...@@ -141,7 +141,7 @@ public class TopologyResource extends BaseResource { ...@@ -141,7 +141,7 @@ public class TopologyResource extends BaseResource {
141 private ObjectNode json(ObjectMapper mapper, ElementId id, int group, 141 private ObjectNode json(ObjectMapper mapper, ElementId id, int group,
142 String label, boolean isOnline) { 142 String label, boolean isOnline) {
143 return mapper.createObjectNode() 143 return mapper.createObjectNode()
144 - .put("name", id.uri().toString()) 144 + .put("name", id.toString())
145 .put("label", label) 145 .put("label", label)
146 .put("group", group) 146 .put("group", group)
147 .put("online", isOnline); 147 .put("online", isOnline);
...@@ -202,7 +202,7 @@ public class TopologyResource extends BaseResource { ...@@ -202,7 +202,7 @@ public class TopologyResource extends BaseResource {
202 // Returns a formatted string for the element associated with the given 202 // Returns a formatted string for the element associated with the given
203 // connection point. 203 // connection point.
204 private static String id(ConnectPoint cp) { 204 private static String id(ConnectPoint cp) {
205 - return cp.elementId().uri().toString(); 205 + return cp.elementId().toString();
206 } 206 }
207 207
208 } 208 }
......
1 /** 1 /**
2 - * REST resources for the sample topology viewer application. 2 + * Sample topology viewer application.
3 */ 3 */
4 package org.onlab.onos.tvue; 4 package org.onlab.onos.tvue;
......
...@@ -21,14 +21,14 @@ public final class Comparators { ...@@ -21,14 +21,14 @@ public final class Comparators {
21 public static final Comparator<ElementId> ELEMENT_ID_COMPARATOR = new Comparator<ElementId>() { 21 public static final Comparator<ElementId> ELEMENT_ID_COMPARATOR = new Comparator<ElementId>() {
22 @Override 22 @Override
23 public int compare(ElementId id1, ElementId id2) { 23 public int compare(ElementId id1, ElementId id2) {
24 - return id1.uri().toString().compareTo(id2.uri().toString()); 24 + return id1.toString().compareTo(id2.toString());
25 } 25 }
26 }; 26 };
27 27
28 public static final Comparator<Element> ELEMENT_COMPARATOR = new Comparator<Element>() { 28 public static final Comparator<Element> ELEMENT_COMPARATOR = new Comparator<Element>() {
29 @Override 29 @Override
30 public int compare(Element e1, Element e2) { 30 public int compare(Element e1, Element e2) {
31 - return e1.id().uri().toString().compareTo(e2.id().uri().toString()); 31 + return e1.id().toString().compareTo(e2.id().toString());
32 } 32 }
33 }; 33 };
34 34
......
1 package org.onlab.onos.cli; 1 package org.onlab.onos.cli;
2 2
3 import com.google.common.collect.Lists; 3 import com.google.common.collect.Lists;
4 -
5 import org.apache.karaf.shell.commands.Command; 4 import org.apache.karaf.shell.commands.Command;
6 import org.onlab.onos.cluster.ClusterService; 5 import org.onlab.onos.cluster.ClusterService;
7 import org.onlab.onos.cluster.ControllerNode; 6 import org.onlab.onos.cluster.ControllerNode;
7 +import org.onlab.onos.cluster.MastershipService;
8 import org.onlab.onos.net.DeviceId; 8 import org.onlab.onos.net.DeviceId;
9 -import org.onlab.onos.net.device.DeviceMastershipService;
10 9
11 import java.util.Collections; 10 import java.util.Collections;
12 import java.util.List; 11 import java.util.List;
...@@ -23,7 +22,7 @@ public class MastersListCommand extends AbstractShellCommand { ...@@ -23,7 +22,7 @@ public class MastersListCommand extends AbstractShellCommand {
23 @Override 22 @Override
24 protected void execute() { 23 protected void execute() {
25 ClusterService service = get(ClusterService.class); 24 ClusterService service = get(ClusterService.class);
26 - DeviceMastershipService mastershipService = get(DeviceMastershipService.class); 25 + MastershipService mastershipService = get(MastershipService.class);
27 List<ControllerNode> nodes = newArrayList(service.getNodes()); 26 List<ControllerNode> nodes = newArrayList(service.getNodes());
28 Collections.sort(nodes, Comparators.NODE_COMPARATOR); 27 Collections.sort(nodes, Comparators.NODE_COMPARATOR);
29 ControllerNode self = service.getLocalNode(); 28 ControllerNode self = service.getLocalNode();
......
...@@ -22,8 +22,10 @@ public class SummaryCommand extends AbstractShellCommand { ...@@ -22,8 +22,10 @@ public class SummaryCommand extends AbstractShellCommand {
22 protected void execute() { 22 protected void execute() {
23 TopologyService topologyService = get(TopologyService.class); 23 TopologyService topologyService = get(TopologyService.class);
24 Topology topology = topologyService.currentTopology(); 24 Topology topology = topologyService.currentTopology();
25 - print("version=%s, nodes=%d, devices=%d, links=%d, hosts=%d, clusters=%s, paths=%d, flows=%d, intents=%d", 25 + print("node=%s, version=%s",
26 - get(CoreService.class).version().toString(), 26 + get(ClusterService.class).getLocalNode().ip(),
27 + get(CoreService.class).version().toString());
28 + print("nodes=%d, devices=%d, links=%d, hosts=%d, clusters=%s, paths=%d, flows=%d, intents=%d",
27 get(ClusterService.class).getNodes().size(), 29 get(ClusterService.class).getNodes().size(),
28 get(DeviceService.class).getDeviceCount(), 30 get(DeviceService.class).getDeviceCount(),
29 get(LinkService.class).getLinkCount(), 31 get(LinkService.class).getLinkCount(),
......
...@@ -3,9 +3,9 @@ package org.onlab.onos.cli.net; ...@@ -3,9 +3,9 @@ package org.onlab.onos.cli.net;
3 import org.apache.karaf.shell.commands.Argument; 3 import org.apache.karaf.shell.commands.Argument;
4 import org.apache.karaf.shell.commands.Command; 4 import org.apache.karaf.shell.commands.Command;
5 import org.onlab.onos.cli.AbstractShellCommand; 5 import org.onlab.onos.cli.AbstractShellCommand;
6 +import org.onlab.onos.cluster.MastershipAdminService;
6 import org.onlab.onos.cluster.NodeId; 7 import org.onlab.onos.cluster.NodeId;
7 import org.onlab.onos.net.MastershipRole; 8 import org.onlab.onos.net.MastershipRole;
8 -import org.onlab.onos.net.device.DeviceMastershipAdminService;
9 9
10 import static org.onlab.onos.net.DeviceId.deviceId; 10 import static org.onlab.onos.net.DeviceId.deviceId;
11 11
...@@ -30,7 +30,7 @@ public class DeviceRoleCommand extends AbstractShellCommand { ...@@ -30,7 +30,7 @@ public class DeviceRoleCommand extends AbstractShellCommand {
30 30
31 @Override 31 @Override
32 protected void execute() { 32 protected void execute() {
33 - DeviceMastershipAdminService service = get(DeviceMastershipAdminService.class); 33 + MastershipAdminService service = get(MastershipAdminService.class);
34 MastershipRole mastershipRole = MastershipRole.valueOf(role.toUpperCase()); 34 MastershipRole mastershipRole = MastershipRole.valueOf(role.toUpperCase());
35 service.setRole(new NodeId(node), deviceId(uri), mastershipRole); 35 service.setRole(new NodeId(node), deviceId(uri), mastershipRole);
36 } 36 }
......
1 -package org.onlab.onos.net.device; 1 +package org.onlab.onos.cluster;
2 2
3 -import org.onlab.onos.cluster.NodeId;
4 import org.onlab.onos.net.DeviceId; 3 import org.onlab.onos.net.DeviceId;
5 import org.onlab.onos.net.MastershipRole; 4 import org.onlab.onos.net.MastershipRole;
6 5
7 /** 6 /**
8 * Service for administering the inventory of device masterships. 7 * Service for administering the inventory of device masterships.
9 */ 8 */
10 -public interface DeviceMastershipAdminService { 9 +public interface MastershipAdminService {
11 10
12 /** 11 /**
13 * Applies the current mastership role for the specified device. 12 * Applies the current mastership role for the specified device.
......
1 -package org.onlab.onos.net.device; 1 +package org.onlab.onos.cluster;
2 2
3 -import org.onlab.onos.cluster.NodeId;
4 import org.onlab.onos.event.AbstractEvent; 3 import org.onlab.onos.event.AbstractEvent;
5 import org.onlab.onos.net.DeviceId; 4 import org.onlab.onos.net.DeviceId;
6 5
7 /** 6 /**
8 * Describes a device mastership event. 7 * Describes a device mastership event.
9 */ 8 */
10 -public class DeviceMastershipEvent extends AbstractEvent<DeviceMastershipEvent.Type, DeviceId> { 9 +public class MastershipEvent extends AbstractEvent<MastershipEvent.Type, DeviceId> {
11 10
12 //do we worry about explicitly setting slaves/equals? probably not, 11 //do we worry about explicitly setting slaves/equals? probably not,
13 //to keep it simple 12 //to keep it simple
...@@ -31,7 +30,7 @@ public class DeviceMastershipEvent extends AbstractEvent<DeviceMastershipEvent.T ...@@ -31,7 +30,7 @@ public class DeviceMastershipEvent extends AbstractEvent<DeviceMastershipEvent.T
31 * @param device event device subject 30 * @param device event device subject
32 * @param master master ID subject 31 * @param master master ID subject
33 */ 32 */
34 - public DeviceMastershipEvent(Type type, DeviceId device, NodeId master) { 33 + public MastershipEvent(Type type, DeviceId device, NodeId master) {
35 super(type, device); 34 super(type, device);
36 this.master = master; 35 this.master = master;
37 } 36 }
...@@ -45,7 +44,7 @@ public class DeviceMastershipEvent extends AbstractEvent<DeviceMastershipEvent.T ...@@ -45,7 +44,7 @@ public class DeviceMastershipEvent extends AbstractEvent<DeviceMastershipEvent.T
45 * @param master master ID subject 44 * @param master master ID subject
46 * @param time occurrence time 45 * @param time occurrence time
47 */ 46 */
48 - public DeviceMastershipEvent(Type type, DeviceId device, NodeId master, long time) { 47 + public MastershipEvent(Type type, DeviceId device, NodeId master, long time) {
49 super(type, device, time); 48 super(type, device, time);
50 this.master = master; 49 this.master = master;
51 } 50 }
......
1 -package org.onlab.onos.net.device; 1 +package org.onlab.onos.cluster;
2 2
3 import org.onlab.onos.event.EventListener; 3 import org.onlab.onos.event.EventListener;
4 4
5 /** 5 /**
6 * Entity capable of receiving device mastership-related events. 6 * Entity capable of receiving device mastership-related events.
7 */ 7 */
8 -public interface DeviceMastershipListener extends EventListener<DeviceMastershipEvent> { 8 +public interface MastershipListener extends EventListener<MastershipEvent> {
9 } 9 }
......
1 -package org.onlab.onos.net.device; 1 +package org.onlab.onos.cluster;
2 2
3 import java.util.Set; 3 import java.util.Set;
4 4
5 -import org.onlab.onos.cluster.NodeId;
6 import org.onlab.onos.net.DeviceId; 5 import org.onlab.onos.net.DeviceId;
7 import org.onlab.onos.net.MastershipRole; 6 import org.onlab.onos.net.MastershipRole;
8 7
...@@ -12,7 +11,7 @@ import org.onlab.onos.net.MastershipRole; ...@@ -12,7 +11,7 @@ import org.onlab.onos.net.MastershipRole;
12 * determining mastership, but is not responsible for actually applying it 11 * determining mastership, but is not responsible for actually applying it
13 * to the devices; this falls on the device service. 12 * to the devices; this falls on the device service.
14 */ 13 */
15 -public interface DeviceMastershipService { 14 +public interface MastershipService {
16 15
17 /** 16 /**
18 * Returns the role of the local node for the specified device, without 17 * Returns the role of the local node for the specified device, without
...@@ -63,20 +62,20 @@ public interface DeviceMastershipService { ...@@ -63,20 +62,20 @@ public interface DeviceMastershipService {
63 * 62 *
64 * @return the MastershipTermService for this mastership manager 63 * @return the MastershipTermService for this mastership manager
65 */ 64 */
66 - DeviceMastershipTermService requestTermService(); 65 + MastershipTermService requestTermService();
67 66
68 /** 67 /**
69 * Adds the specified mastership change listener. 68 * Adds the specified mastership change listener.
70 * 69 *
71 * @param listener the mastership listener 70 * @param listener the mastership listener
72 */ 71 */
73 - void addListener(DeviceMastershipListener listener); 72 + void addListener(MastershipListener listener);
74 73
75 /** 74 /**
76 * Removes the specified mastership change listener. 75 * Removes the specified mastership change listener.
77 * 76 *
78 * @param listener the mastership listener 77 * @param listener the mastership listener
79 */ 78 */
80 - void removeListener(DeviceMastershipListener listener); 79 + void removeListener(MastershipListener listener);
81 80
82 } 81 }
......
1 -package org.onlab.onos.net.device; 1 +package org.onlab.onos.cluster;
2 2
3 import java.util.Set; 3 import java.util.Set;
4 4
5 -import org.onlab.onos.cluster.NodeId;
6 import org.onlab.onos.net.DeviceId; 5 import org.onlab.onos.net.DeviceId;
7 import org.onlab.onos.net.MastershipRole; 6 import org.onlab.onos.net.MastershipRole;
8 import org.onlab.onos.store.Store; 7 import org.onlab.onos.store.Store;
...@@ -11,7 +10,7 @@ import org.onlab.onos.store.Store; ...@@ -11,7 +10,7 @@ import org.onlab.onos.store.Store;
11 * Manages inventory of mastership roles for devices, across controller 10 * Manages inventory of mastership roles for devices, across controller
12 * instances; not intended for direct use. 11 * instances; not intended for direct use.
13 */ 12 */
14 -public interface DeviceMastershipStore extends Store<DeviceMastershipEvent, DeviceMastershipStoreDelegate> { 13 +public interface MastershipStore extends Store<MastershipEvent, MastershipStoreDelegate> {
15 14
16 // three things to map: NodeId, DeviceId, MastershipRole 15 // three things to map: NodeId, DeviceId, MastershipRole
17 16
...@@ -55,7 +54,7 @@ public interface DeviceMastershipStore extends Store<DeviceMastershipEvent, Devi ...@@ -55,7 +54,7 @@ public interface DeviceMastershipStore extends Store<DeviceMastershipEvent, Devi
55 * @param deviceId device identifier 54 * @param deviceId device identifier
56 * @return a mastership event 55 * @return a mastership event
57 */ 56 */
58 - DeviceMastershipEvent setMaster(NodeId nodeId, DeviceId deviceId); 57 + MastershipEvent setMaster(NodeId nodeId, DeviceId deviceId);
59 58
60 /** 59 /**
61 * Returns the current master and number of past mastership hand-offs 60 * Returns the current master and number of past mastership hand-offs
...@@ -64,7 +63,7 @@ public interface DeviceMastershipStore extends Store<DeviceMastershipEvent, Devi ...@@ -64,7 +63,7 @@ public interface DeviceMastershipStore extends Store<DeviceMastershipEvent, Devi
64 * @param deviceId the device identifier 63 * @param deviceId the device identifier
65 * @return the current master's ID and the term value for device, or null 64 * @return the current master's ID and the term value for device, or null
66 */ 65 */
67 - DeviceMastershipTerm getTermFor(DeviceId deviceId); 66 + MastershipTerm getTermFor(DeviceId deviceId);
68 67
69 /** 68 /**
70 * Sets a controller instance's mastership role to STANDBY for a device. 69 * Sets a controller instance's mastership role to STANDBY for a device.
...@@ -75,7 +74,7 @@ public interface DeviceMastershipStore extends Store<DeviceMastershipEvent, Devi ...@@ -75,7 +74,7 @@ public interface DeviceMastershipStore extends Store<DeviceMastershipEvent, Devi
75 * @param deviceId device to revoke mastership role for 74 * @param deviceId device to revoke mastership role for
76 * @return a mastership event 75 * @return a mastership event
77 */ 76 */
78 - DeviceMastershipEvent setStandby(NodeId nodeId, DeviceId deviceId); 77 + MastershipEvent setStandby(NodeId nodeId, DeviceId deviceId);
79 78
80 /** 79 /**
81 * Allows a controller instance to give up its current role for a device. 80 * Allows a controller instance to give up its current role for a device.
...@@ -86,6 +85,6 @@ public interface DeviceMastershipStore extends Store<DeviceMastershipEvent, Devi ...@@ -86,6 +85,6 @@ public interface DeviceMastershipStore extends Store<DeviceMastershipEvent, Devi
86 * @param deviceId device to revoke mastership role for 85 * @param deviceId device to revoke mastership role for
87 * @return a mastership event 86 * @return a mastership event
88 */ 87 */
89 - DeviceMastershipEvent relinquishRole(NodeId nodeId, DeviceId deviceId); 88 + MastershipEvent relinquishRole(NodeId nodeId, DeviceId deviceId);
90 89
91 } 90 }
......
1 -package org.onlab.onos.net.device; 1 +package org.onlab.onos.cluster;
2 2
3 import org.onlab.onos.store.StoreDelegate; 3 import org.onlab.onos.store.StoreDelegate;
4 4
5 /** 5 /**
6 - * DeviceMastership store delegate abstraction. 6 + * Mastership store delegate abstraction.
7 */ 7 */
8 -public interface DeviceMastershipStoreDelegate extends StoreDelegate<DeviceMastershipEvent> { 8 +public interface MastershipStoreDelegate extends StoreDelegate<MastershipEvent> {
9 } 9 }
......
1 -package org.onlab.onos.net.device; 1 +package org.onlab.onos.cluster;
2 2
3 import java.util.Objects; 3 import java.util.Objects;
4 4
5 -import org.onlab.onos.cluster.NodeId; 5 +public final class MastershipTerm {
6 -
7 -public final class DeviceMastershipTerm {
8 6
9 private final NodeId master; 7 private final NodeId master;
10 private final int termNumber; 8 private final int termNumber;
11 9
12 - private DeviceMastershipTerm(NodeId master, int term) { 10 + private MastershipTerm(NodeId master, int term) {
13 this.master = master; 11 this.master = master;
14 this.termNumber = term; 12 this.termNumber = term;
15 } 13 }
16 14
17 - public static DeviceMastershipTerm of(NodeId master, int term) { 15 + public static MastershipTerm of(NodeId master, int term) {
18 - return new DeviceMastershipTerm(master, term); 16 + return new MastershipTerm(master, term);
19 } 17 }
20 18
21 public NodeId master() { 19 public NodeId master() {
...@@ -36,8 +34,8 @@ public final class DeviceMastershipTerm { ...@@ -36,8 +34,8 @@ public final class DeviceMastershipTerm {
36 if (this == other) { 34 if (this == other) {
37 return true; 35 return true;
38 } 36 }
39 - if (other instanceof DeviceMastershipTerm) { 37 + if (other instanceof MastershipTerm) {
40 - DeviceMastershipTerm that = (DeviceMastershipTerm) other; 38 + MastershipTerm that = (MastershipTerm) other;
41 if (!this.master.equals(that.master)) { 39 if (!this.master.equals(that.master)) {
42 return false; 40 return false;
43 } 41 }
......
1 -package org.onlab.onos.net.device; 1 +package org.onlab.onos.cluster;
2 2
3 import org.onlab.onos.net.DeviceId; 3 import org.onlab.onos.net.DeviceId;
4 4
...@@ -6,7 +6,7 @@ import org.onlab.onos.net.DeviceId; ...@@ -6,7 +6,7 @@ import org.onlab.onos.net.DeviceId;
6 /** 6 /**
7 * Service to obtain mastership term information. 7 * Service to obtain mastership term information.
8 */ 8 */
9 -public interface DeviceMastershipTermService { 9 +public interface MastershipTermService {
10 10
11 // TBD: manage/increment per device mastership change 11 // TBD: manage/increment per device mastership change
12 // or increment on any change 12 // or increment on any change
...@@ -16,5 +16,5 @@ public interface DeviceMastershipTermService { ...@@ -16,5 +16,5 @@ public interface DeviceMastershipTermService {
16 * @param deviceId the identifier of the device 16 * @param deviceId the identifier of the device
17 * @return current master's term. 17 * @return current master's term.
18 */ 18 */
19 - DeviceMastershipTerm getMastershipTerm(DeviceId deviceId); 19 + MastershipTerm getMastershipTerm(DeviceId deviceId);
20 } 20 }
......
1 package org.onlab.onos.net; 1 package org.onlab.onos.net;
2 2
3 import java.net.URI; 3 import java.net.URI;
4 +import java.util.Objects;
4 5
5 /** 6 /**
6 * Immutable representation of a device identity. 7 * Immutable representation of a device identity.
7 */ 8 */
8 public final class DeviceId extends ElementId { 9 public final class DeviceId extends ElementId {
9 10
11 + /**
12 + * Represents either no device, or an unspecified device.
13 + */
14 + public static final DeviceId NONE = deviceId("none:none");
15 +
16 + private final URI uri;
17 + private final String str;
18 +
10 // Public construction is prohibited 19 // Public construction is prohibited
11 private DeviceId(URI uri) { 20 private DeviceId(URI uri) {
12 - super(uri); 21 + this.uri = uri;
22 + this.str = uri.toString();
23 + }
24 +
25 +
26 + // Default constructor for serialization
27 + protected DeviceId() {
28 + this.uri = null;
29 + this.str = null;
13 } 30 }
14 31
15 /** 32 /**
...@@ -30,4 +47,36 @@ public final class DeviceId extends ElementId { ...@@ -30,4 +47,36 @@ public final class DeviceId extends ElementId {
30 return deviceId(URI.create(string)); 47 return deviceId(URI.create(string));
31 } 48 }
32 49
50 + /**
51 + * Returns the backing URI.
52 + *
53 + * @return backing URI
54 + */
55 + public URI uri() {
56 + return uri;
57 + }
58 +
59 + @Override
60 + public int hashCode() {
61 + return Objects.hash(str);
62 + }
63 +
64 + @Override
65 + public boolean equals(Object obj) {
66 + if (this == obj) {
67 + return true;
68 + }
69 + if (obj instanceof DeviceId) {
70 + final DeviceId that = (DeviceId) obj;
71 + return this.getClass() == that.getClass() &&
72 + Objects.equals(this.str, that.str);
73 + }
74 + return false;
75 + }
76 +
77 + @Override
78 + public String toString() {
79 + return str;
80 + }
81 +
33 } 82 }
......
1 package org.onlab.onos.net; 1 package org.onlab.onos.net;
2 2
3 -import java.net.URI;
4 -import java.util.Objects;
5 -
6 /** 3 /**
7 * Immutable representation of a network element identity. 4 * Immutable representation of a network element identity.
8 */ 5 */
9 public abstract class ElementId { 6 public abstract class ElementId {
10 -
11 - private final URI uri;
12 - private final String str;
13 -
14 - // Default constructor for serialization
15 - protected ElementId() {
16 - this.uri = null;
17 - this.str = null;
18 - }
19 -
20 - /**
21 - * Creates an element identifier using the supplied URI.
22 - *
23 - * @param uri backing URI
24 - */
25 - protected ElementId(URI uri) {
26 - this.uri = uri;
27 - this.str = uri.toString();
28 - }
29 -
30 - /**
31 - * Returns the backing URI.
32 - *
33 - * @return backing URI
34 - */
35 - public URI uri() {
36 - return uri;
37 - }
38 -
39 - @Override
40 - public int hashCode() {
41 - return Objects.hash(str);
42 - }
43 -
44 - @Override
45 - public boolean equals(Object obj) {
46 - if (this == obj) {
47 - return true;
48 - }
49 - if (obj instanceof ElementId) {
50 - final ElementId that = (ElementId) obj;
51 - return this.getClass() == that.getClass() &&
52 - Objects.equals(this.str, that.str);
53 - }
54 - return false;
55 - }
56 -
57 - @Override
58 - public String toString() {
59 - return str;
60 - }
61 -
62 } 7 }
......
...@@ -3,44 +3,69 @@ package org.onlab.onos.net; ...@@ -3,44 +3,69 @@ package org.onlab.onos.net;
3 import org.onlab.packet.MacAddress; 3 import org.onlab.packet.MacAddress;
4 import org.onlab.packet.VlanId; 4 import org.onlab.packet.VlanId;
5 5
6 -import java.net.URI; 6 +import java.util.Objects;
7 +
8 +import static com.google.common.base.Preconditions.checkArgument;
7 9
8 /** 10 /**
9 * Immutable representation of a host identity. 11 * Immutable representation of a host identity.
10 */ 12 */
11 public final class HostId extends ElementId { 13 public final class HostId extends ElementId {
12 14
13 - private static final String NIC = "nic";
14 -
15 /** 15 /**
16 * Represents either no host, or an unspecified host; used for creating 16 * Represents either no host, or an unspecified host; used for creating
17 * open ingress/egress edge links. 17 * open ingress/egress edge links.
18 */ 18 */
19 - public static final HostId NONE = hostId(NIC + ":none-0"); 19 + public static final HostId NONE = new HostId(MacAddress.ZERO, VlanId.NONE);
20 +
21 + private static final int MAC_LENGTH = 17;
22 + private static final int MIN_ID_LENGTH = 19;
23 +
24 + private final MacAddress mac;
25 + private final VlanId vlanId;
20 26
21 // Public construction is prohibited 27 // Public construction is prohibited
22 - private HostId(URI uri) { 28 + private HostId(MacAddress mac, VlanId vlanId) {
23 - super(uri); 29 + this.mac = mac;
30 + this.vlanId = vlanId;
31 + }
32 +
33 + // Default constructor for serialization
34 + private HostId() {
35 + this.mac = null;
36 + this.vlanId = null;
24 } 37 }
25 38
26 /** 39 /**
27 - * Creates a device id using the supplied URI. 40 + * Returns the host MAC address.
28 * 41 *
29 - * @param uri device URI 42 + * @return MAC address
30 - * @return host identifier 43 + */
44 + public MacAddress mac() {
45 + return mac;
46 + }
47 +
48 + /**
49 + * Returns the host MAC address.
50 + *
51 + * @return MAC address
31 */ 52 */
32 - public static HostId hostId(URI uri) { 53 + public VlanId vlanId() {
33 - return new HostId(uri); 54 + return vlanId;
34 } 55 }
35 56
36 /** 57 /**
37 - * Creates a device id using the supplied URI string. 58 + * Creates a device id using the supplied ID string.
38 * 59 *
39 * @param string device URI string 60 * @param string device URI string
40 * @return host identifier 61 * @return host identifier
41 */ 62 */
42 public static HostId hostId(String string) { 63 public static HostId hostId(String string) {
43 - return hostId(URI.create(string)); 64 + checkArgument(string.length() >= MIN_ID_LENGTH,
65 + "Host ID must be at least %s characters", MIN_ID_LENGTH);
66 + MacAddress mac = MacAddress.valueOf(string.substring(0, MAC_LENGTH));
67 + VlanId vlanId = VlanId.vlanId(Short.parseShort(string.substring(MAC_LENGTH + 1)));
68 + return new HostId(mac, vlanId);
44 } 69 }
45 70
46 /** 71 /**
...@@ -51,7 +76,7 @@ public final class HostId extends ElementId { ...@@ -51,7 +76,7 @@ public final class HostId extends ElementId {
51 * @return host identifier 76 * @return host identifier
52 */ 77 */
53 public static HostId hostId(MacAddress mac, VlanId vlanId) { 78 public static HostId hostId(MacAddress mac, VlanId vlanId) {
54 - return hostId(NIC + ":" + mac + "-" + vlanId); 79 + return new HostId(mac, vlanId);
55 } 80 }
56 81
57 /** 82 /**
...@@ -64,4 +89,26 @@ public final class HostId extends ElementId { ...@@ -64,4 +89,26 @@ public final class HostId extends ElementId {
64 return hostId(mac, VlanId.vlanId(VlanId.UNTAGGED)); 89 return hostId(mac, VlanId.vlanId(VlanId.UNTAGGED));
65 } 90 }
66 91
92 + public String toString() {
93 + return mac + "/" + vlanId;
94 + }
95 +
96 + @Override
97 + public int hashCode() {
98 + return Objects.hash(mac, vlanId);
99 + }
100 +
101 + @Override
102 + public boolean equals(Object obj) {
103 + if (this == obj) {
104 + return true;
105 + }
106 + if (obj instanceof HostId) {
107 + final HostId other = (HostId) obj;
108 + return Objects.equals(this.mac, other.mac) &&
109 + Objects.equals(this.vlanId, other.vlanId);
110 + }
111 + return false;
112 + }
113 +
67 } 114 }
......
1 package org.onlab.onos.net; 1 package org.onlab.onos.net;
2 2
3 +import static org.onlab.onos.net.PortNumber.P0;
4 +
3 /** 5 /**
4 * Representation of a network edge location where an end-station host is 6 * Representation of a network edge location where an end-station host is
5 * connected. 7 * connected.
6 */ 8 */
7 public class HostLocation extends ConnectPoint { 9 public class HostLocation extends ConnectPoint {
8 10
11 + /**
12 + * Represents a no location or an unknown location.
13 + */
14 + public static final HostLocation NONE = new HostLocation(DeviceId.NONE, P0, 0L);
15 +
9 // Note that time is explicitly excluded from the notion of equality. 16 // Note that time is explicitly excluded from the notion of equality.
10 private final long time; 17 private final long time;
11 18
......
1 +package org.onlab.onos.net;
2 +
3 +/**
4 + * Representation of a network resource.
5 + */
6 +public interface NetworkResource {
7 +}
...@@ -4,6 +4,8 @@ import org.onlab.onos.net.AbstractDescription; ...@@ -4,6 +4,8 @@ import org.onlab.onos.net.AbstractDescription;
4 import org.onlab.onos.net.PortNumber; 4 import org.onlab.onos.net.PortNumber;
5 import org.onlab.onos.net.SparseAnnotations; 5 import org.onlab.onos.net.SparseAnnotations;
6 6
7 +import com.google.common.base.MoreObjects;
8 +
7 /** 9 /**
8 * Default implementation of immutable port description. 10 * Default implementation of immutable port description.
9 */ 11 */
...@@ -48,6 +50,15 @@ public class DefaultPortDescription extends AbstractDescription ...@@ -48,6 +50,15 @@ public class DefaultPortDescription extends AbstractDescription
48 return isEnabled; 50 return isEnabled;
49 } 51 }
50 52
53 + @Override
54 + public String toString() {
55 + return MoreObjects.toStringHelper(getClass())
56 + .add("number", number)
57 + .add("isEnabled", isEnabled)
58 + .add("annotations", annotations())
59 + .toString();
60 + }
61 +
51 // default constructor for serialization 62 // default constructor for serialization
52 private DefaultPortDescription() { 63 private DefaultPortDescription() {
53 this.number = null; 64 this.number = null;
......
1 package org.onlab.onos.net.host; 1 package org.onlab.onos.net.host;
2 2
3 -import com.google.common.collect.ImmutableSet;
4 import org.onlab.onos.net.AbstractDescription; 3 import org.onlab.onos.net.AbstractDescription;
5 import org.onlab.onos.net.HostLocation; 4 import org.onlab.onos.net.HostLocation;
6 import org.onlab.onos.net.SparseAnnotations; 5 import org.onlab.onos.net.SparseAnnotations;
...@@ -8,9 +7,6 @@ import org.onlab.packet.IpPrefix; ...@@ -8,9 +7,6 @@ import org.onlab.packet.IpPrefix;
8 import org.onlab.packet.MacAddress; 7 import org.onlab.packet.MacAddress;
9 import org.onlab.packet.VlanId; 8 import org.onlab.packet.VlanId;
10 9
11 -import java.util.HashSet;
12 -import java.util.Set;
13 -
14 import static com.google.common.base.MoreObjects.toStringHelper; 10 import static com.google.common.base.MoreObjects.toStringHelper;
15 11
16 /** 12 /**
...@@ -22,7 +18,7 @@ public class DefaultHostDescription extends AbstractDescription ...@@ -22,7 +18,7 @@ public class DefaultHostDescription extends AbstractDescription
22 private final MacAddress mac; 18 private final MacAddress mac;
23 private final VlanId vlan; 19 private final VlanId vlan;
24 private final HostLocation location; 20 private final HostLocation location;
25 - private final Set<IpPrefix> ips; 21 + private final IpPrefix ip;
26 22
27 /** 23 /**
28 * Creates a host description using the supplied information. 24 * Creates a host description using the supplied information.
...@@ -35,7 +31,7 @@ public class DefaultHostDescription extends AbstractDescription ...@@ -35,7 +31,7 @@ public class DefaultHostDescription extends AbstractDescription
35 public DefaultHostDescription(MacAddress mac, VlanId vlan, 31 public DefaultHostDescription(MacAddress mac, VlanId vlan,
36 HostLocation location, 32 HostLocation location,
37 SparseAnnotations... annotations) { 33 SparseAnnotations... annotations) {
38 - this(mac, vlan, location, new HashSet<IpPrefix>(), annotations); 34 + this(mac, vlan, location, null, annotations);
39 } 35 }
40 36
41 /** 37 /**
...@@ -44,17 +40,17 @@ public class DefaultHostDescription extends AbstractDescription ...@@ -44,17 +40,17 @@ public class DefaultHostDescription extends AbstractDescription
44 * @param mac host MAC address 40 * @param mac host MAC address
45 * @param vlan host VLAN identifier 41 * @param vlan host VLAN identifier
46 * @param location host location 42 * @param location host location
47 - * @param ips of host IP addresses 43 + * @param ip host IP address
48 * @param annotations optional key/value annotations map 44 * @param annotations optional key/value annotations map
49 */ 45 */
50 public DefaultHostDescription(MacAddress mac, VlanId vlan, 46 public DefaultHostDescription(MacAddress mac, VlanId vlan,
51 - HostLocation location, Set<IpPrefix> ips, 47 + HostLocation location, IpPrefix ip,
52 SparseAnnotations... annotations) { 48 SparseAnnotations... annotations) {
53 super(annotations); 49 super(annotations);
54 this.mac = mac; 50 this.mac = mac;
55 this.vlan = vlan; 51 this.vlan = vlan;
56 this.location = location; 52 this.location = location;
57 - this.ips = new HashSet<>(ips); 53 + this.ip = ip;
58 } 54 }
59 55
60 @Override 56 @Override
...@@ -73,8 +69,8 @@ public class DefaultHostDescription extends AbstractDescription ...@@ -73,8 +69,8 @@ public class DefaultHostDescription extends AbstractDescription
73 } 69 }
74 70
75 @Override 71 @Override
76 - public Set<IpPrefix> ipAddresses() { 72 + public IpPrefix ipAddress() {
77 - return ImmutableSet.copyOf(ips); 73 + return ip;
78 } 74 }
79 75
80 @Override 76 @Override
...@@ -83,7 +79,7 @@ public class DefaultHostDescription extends AbstractDescription ...@@ -83,7 +79,7 @@ public class DefaultHostDescription extends AbstractDescription
83 .add("mac", mac) 79 .add("mac", mac)
84 .add("vlan", vlan) 80 .add("vlan", vlan)
85 .add("location", location) 81 .add("location", location)
86 - .add("ipAddresses", ips) 82 + .add("ipAddress", ip)
87 .toString(); 83 .toString();
88 } 84 }
89 85
......
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.Description; 3 import org.onlab.onos.net.Description;
6 import org.onlab.onos.net.HostLocation; 4 import org.onlab.onos.net.HostLocation;
7 import org.onlab.packet.IpPrefix; 5 import org.onlab.packet.IpPrefix;
...@@ -35,10 +33,10 @@ public interface HostDescription extends Description { ...@@ -35,10 +33,10 @@ public interface HostDescription extends Description {
35 HostLocation location(); 33 HostLocation location();
36 34
37 /** 35 /**
38 - * Returns zero or more IP address(es) associated with this host's MAC. 36 + * Returns the IP address associated with this host's MAC.
39 * 37 *
40 - * @return a set of IP addresses. 38 + * @return host IP address
41 */ 39 */
42 - Set<IpPrefix> ipAddresses(); 40 + IpPrefix ipAddress();
43 41
44 } 42 }
......
1 package org.onlab.onos.store; 1 package org.onlab.onos.store;
2 2
3 +import org.onlab.onos.cluster.MastershipTerm;
3 import org.onlab.onos.net.DeviceId; 4 import org.onlab.onos.net.DeviceId;
4 -import org.onlab.onos.net.device.DeviceMastershipTerm;
5 5
6 //TODO: Consider renaming to DeviceClockProviderService? 6 //TODO: Consider renaming to DeviceClockProviderService?
7 /** 7 /**
...@@ -16,5 +16,5 @@ public interface ClockProviderService { ...@@ -16,5 +16,5 @@ public interface ClockProviderService {
16 * @param deviceId device identifier. 16 * @param deviceId device identifier.
17 * @param term mastership term. 17 * @param term mastership term.
18 */ 18 */
19 - public void setMastershipTerm(DeviceId deviceId, DeviceMastershipTerm term); 19 + public void setMastershipTerm(DeviceId deviceId, MastershipTerm term);
20 } 20 }
......
1 +package org.onlab.onos;
2 +
3 +import java.util.Objects;
4 +
5 +/**
6 + * Test application ID.
7 + */
8 +public class TestApplicationId implements ApplicationId {
9 +
10 + private final String name;
11 + private final short id;
12 +
13 + public TestApplicationId(String name) {
14 + this.name = name;
15 + this.id = (short) Objects.hash(name);
16 + }
17 +
18 + public static ApplicationId create(String name) {
19 + return new TestApplicationId(name);
20 + }
21 +
22 + @Override
23 + public short id() {
24 + return id;
25 + }
26 +
27 + @Override
28 + public String name() {
29 + return name;
30 + }
31 +}
...@@ -2,16 +2,13 @@ package org.onlab.onos.cluster; ...@@ -2,16 +2,13 @@ package org.onlab.onos.cluster;
2 2
3 import org.onlab.onos.net.DeviceId; 3 import org.onlab.onos.net.DeviceId;
4 import org.onlab.onos.net.MastershipRole; 4 import org.onlab.onos.net.MastershipRole;
5 -import org.onlab.onos.net.device.DeviceMastershipListener;
6 -import org.onlab.onos.net.device.DeviceMastershipService;
7 -import org.onlab.onos.net.device.DeviceMastershipTermService;
8 5
9 import java.util.Set; 6 import java.util.Set;
10 7
11 /** 8 /**
12 * Test adapter for mastership service. 9 * Test adapter for mastership service.
13 */ 10 */
14 -public class MastershipServiceAdapter implements DeviceMastershipService { 11 +public class MastershipServiceAdapter implements MastershipService {
15 @Override 12 @Override
16 public MastershipRole getLocalRole(DeviceId deviceId) { 13 public MastershipRole getLocalRole(DeviceId deviceId) {
17 return null; 14 return null;
...@@ -37,15 +34,15 @@ public class MastershipServiceAdapter implements DeviceMastershipService { ...@@ -37,15 +34,15 @@ public class MastershipServiceAdapter implements DeviceMastershipService {
37 } 34 }
38 35
39 @Override 36 @Override
40 - public void addListener(DeviceMastershipListener listener) { 37 + public void addListener(MastershipListener listener) {
41 } 38 }
42 39
43 @Override 40 @Override
44 - public void removeListener(DeviceMastershipListener listener) { 41 + public void removeListener(MastershipListener listener) {
45 } 42 }
46 43
47 @Override 44 @Override
48 - public DeviceMastershipTermService requestTermService() { 45 + public MastershipTermService requestTermService() {
49 return null; 46 return null;
50 } 47 }
51 } 48 }
......
...@@ -3,7 +3,6 @@ package org.onlab.onos.cluster; ...@@ -3,7 +3,6 @@ package org.onlab.onos.cluster;
3 import static org.junit.Assert.assertEquals; 3 import static org.junit.Assert.assertEquals;
4 4
5 import org.junit.Test; 5 import org.junit.Test;
6 -import org.onlab.onos.net.device.DeviceMastershipTerm;
7 6
8 import com.google.common.testing.EqualsTester; 7 import com.google.common.testing.EqualsTester;
9 8
...@@ -12,10 +11,10 @@ public class MastershipTermTest { ...@@ -12,10 +11,10 @@ public class MastershipTermTest {
12 private static final NodeId N1 = new NodeId("foo"); 11 private static final NodeId N1 = new NodeId("foo");
13 private static final NodeId N2 = new NodeId("bar"); 12 private static final NodeId N2 = new NodeId("bar");
14 13
15 - private static final DeviceMastershipTerm TERM1 = DeviceMastershipTerm.of(N1, 0); 14 + private static final MastershipTerm TERM1 = MastershipTerm.of(N1, 0);
16 - private static final DeviceMastershipTerm TERM2 = DeviceMastershipTerm.of(N2, 1); 15 + private static final MastershipTerm TERM2 = MastershipTerm.of(N2, 1);
17 - private static final DeviceMastershipTerm TERM3 = DeviceMastershipTerm.of(N2, 1); 16 + private static final MastershipTerm TERM3 = MastershipTerm.of(N2, 1);
18 - private static final DeviceMastershipTerm TERM4 = DeviceMastershipTerm.of(N1, 1); 17 + private static final MastershipTerm TERM4 = MastershipTerm.of(N1, 1);
19 18
20 @Test 19 @Test
21 public void basics() { 20 public void basics() {
...@@ -25,7 +24,7 @@ public class MastershipTermTest { ...@@ -25,7 +24,7 @@ public class MastershipTermTest {
25 24
26 @Test 25 @Test
27 public void testEquality() { 26 public void testEquality() {
28 - new EqualsTester().addEqualityGroup(DeviceMastershipTerm.of(N1, 0), TERM1) 27 + new EqualsTester().addEqualityGroup(MastershipTerm.of(N1, 0), TERM1)
29 .addEqualityGroup(TERM2, TERM3) 28 .addEqualityGroup(TERM2, TERM3)
30 .addEqualityGroup(TERM4); 29 .addEqualityGroup(TERM4);
31 } 30 }
......
...@@ -45,15 +45,18 @@ public class AbstractEventAccumulatorTest { ...@@ -45,15 +45,18 @@ public class AbstractEventAccumulatorTest {
45 public void timeTrigger() { 45 public void timeTrigger() {
46 TestAccumulator accumulator = new TestAccumulator(); 46 TestAccumulator accumulator = new TestAccumulator();
47 accumulator.add(new TestEvent(FOO, "a")); 47 accumulator.add(new TestEvent(FOO, "a"));
48 - delay(40); 48 + delay(30);
49 assertTrue("should not have fired yet", accumulator.batch.isEmpty()); 49 assertTrue("should not have fired yet", accumulator.batch.isEmpty());
50 accumulator.add(new TestEvent(FOO, "b")); 50 accumulator.add(new TestEvent(FOO, "b"));
51 - delay(40); 51 + delay(30);
52 assertTrue("should not have fired yet", accumulator.batch.isEmpty()); 52 assertTrue("should not have fired yet", accumulator.batch.isEmpty());
53 accumulator.add(new TestEvent(FOO, "c")); 53 accumulator.add(new TestEvent(FOO, "c"));
54 - delay(40); 54 + delay(30);
55 + assertTrue("should not have fired yet", accumulator.batch.isEmpty());
56 + accumulator.add(new TestEvent(FOO, "d"));
57 + delay(30);
55 assertFalse("should have fired", accumulator.batch.isEmpty()); 58 assertFalse("should have fired", accumulator.batch.isEmpty());
56 - assertEquals("incorrect batch", "abc", accumulator.batch); 59 + assertEquals("incorrect batch", "abcd", accumulator.batch);
57 } 60 }
58 61
59 @Test 62 @Test
......
...@@ -18,8 +18,8 @@ public class DefaultEdgeLinkTest { ...@@ -18,8 +18,8 @@ public class DefaultEdgeLinkTest {
18 18
19 private static final ProviderId PID = new ProviderId("of", "foo"); 19 private static final ProviderId PID = new ProviderId("of", "foo");
20 private static final DeviceId DID1 = deviceId("of:foo"); 20 private static final DeviceId DID1 = deviceId("of:foo");
21 - private static final HostId HID1 = hostId("nic:foobar"); 21 + private static final HostId HID1 = hostId("00:00:00:00:00:01/-1");
22 - private static final HostId HID2 = hostId("nic:barfoo"); 22 + private static final HostId HID2 = hostId("00:00:00:00:00:01/-1");
23 private static final PortNumber P0 = portNumber(0); 23 private static final PortNumber P0 = portNumber(0);
24 private static final PortNumber P1 = portNumber(1); 24 private static final PortNumber P1 = portNumber(1);
25 25
...@@ -35,12 +35,8 @@ public class DefaultEdgeLinkTest { ...@@ -35,12 +35,8 @@ public class DefaultEdgeLinkTest {
35 EdgeLink l4 = new DefaultEdgeLink(PID, cp(HID2, P0), 35 EdgeLink l4 = new DefaultEdgeLink(PID, cp(HID2, P0),
36 new HostLocation(DID1, P1, 123L), false); 36 new HostLocation(DID1, P1, 123L), false);
37 37
38 - EdgeLink l5 = new DefaultEdgeLink(PID, cp(HID1, P0),
39 - new HostLocation(DID1, P1, 123L), false);
40 -
41 new EqualsTester().addEqualityGroup(l1, l2) 38 new EqualsTester().addEqualityGroup(l1, l2)
42 .addEqualityGroup(l3, l4) 39 .addEqualityGroup(l3, l4)
43 - .addEqualityGroup(l5)
44 .testEquals(); 40 .testEquals();
45 } 41 }
46 42
......
...@@ -8,7 +8,7 @@ import static org.onlab.onos.net.DeviceId.deviceId; ...@@ -8,7 +8,7 @@ import static org.onlab.onos.net.DeviceId.deviceId;
8 /** 8 /**
9 * Test of the device identifier. 9 * Test of the device identifier.
10 */ 10 */
11 -public class DeviceIdTest extends ElementIdTest { 11 +public class DeviceIdTest {
12 12
13 @Test 13 @Test
14 public void basics() { 14 public void basics() {
......
1 -package org.onlab.onos.net;
2 -
3 -import com.google.common.testing.EqualsTester;
4 -import org.junit.Test;
5 -
6 -import java.net.URI;
7 -
8 -import static org.junit.Assert.assertEquals;
9 -
10 -/**
11 - * Test of the network element identifier.
12 - */
13 -public class ElementIdTest {
14 -
15 - private static class FooId extends ElementId {
16 - public FooId(URI uri) {
17 - super(uri);
18 - }
19 - }
20 -
21 - public static URI uri(String str) {
22 - return URI.create(str);
23 - }
24 -
25 - @Test
26 - public void basics() {
27 - new EqualsTester()
28 - .addEqualityGroup(new FooId(uri("of:foo")),
29 - new FooId(uri("of:foo")))
30 - .addEqualityGroup(new FooId(uri("of:bar")))
31 - .testEquals();
32 - assertEquals("wrong uri", uri("ofcfg:foo"),
33 - new FooId(uri("ofcfg:foo")).uri());
34 - }
35 -
36 -}
...@@ -11,20 +11,18 @@ import static org.onlab.onos.net.HostId.hostId; ...@@ -11,20 +11,18 @@ import static org.onlab.onos.net.HostId.hostId;
11 /** 11 /**
12 * Test for the host identifier. 12 * Test for the host identifier.
13 */ 13 */
14 -public class HostIdTest extends ElementIdTest { 14 +public class HostIdTest {
15 15
16 private static final MacAddress MAC1 = MacAddress.valueOf("00:11:00:00:00:01"); 16 private static final MacAddress MAC1 = MacAddress.valueOf("00:11:00:00:00:01");
17 private static final MacAddress MAC2 = MacAddress.valueOf("00:22:00:00:00:02"); 17 private static final MacAddress MAC2 = MacAddress.valueOf("00:22:00:00:00:02");
18 private static final VlanId VLAN1 = VlanId.vlanId((short) 11); 18 private static final VlanId VLAN1 = VlanId.vlanId((short) 11);
19 private static final VlanId VLAN2 = VlanId.vlanId((short) 22); 19 private static final VlanId VLAN2 = VlanId.vlanId((short) 22);
20 20
21 - @Override
22 @Test 21 @Test
23 public void basics() { 22 public void basics() {
24 new EqualsTester() 23 new EqualsTester()
25 - .addEqualityGroup(hostId("nic:00:11:00:00:00:01-11"), 24 + .addEqualityGroup(hostId(MAC1, VLAN1), hostId(MAC1, VLAN1))
26 - hostId(MAC1, VLAN1)) 25 + .addEqualityGroup(hostId(MAC2, VLAN2), hostId(MAC2, VLAN2))
27 - .addEqualityGroup(hostId(MAC2, VLAN2))
28 .testEquals(); 26 .testEquals();
29 } 27 }
30 28
......
...@@ -31,7 +31,7 @@ public final class NetTestTools { ...@@ -31,7 +31,7 @@ public final class NetTestTools {
31 31
32 // Short-hand for producing a host id from a string 32 // Short-hand for producing a host id from a string
33 public static HostId hid(String id) { 33 public static HostId hid(String id) {
34 - return hostId("nic:" + id); 34 + return hostId(id);
35 } 35 }
36 36
37 // Crates a new device with the specified id 37 // Crates a new device with the specified id
......
...@@ -10,9 +10,8 @@ import com.google.common.testing.EqualsTester; ...@@ -10,9 +10,8 @@ import com.google.common.testing.EqualsTester;
10 /** 10 /**
11 * Test of the port number. 11 * Test of the port number.
12 */ 12 */
13 -public class PortNumberTest extends ElementIdTest { 13 +public class PortNumberTest {
14 14
15 - @Override
16 @Test 15 @Test
17 public void basics() { 16 public void basics() {
18 new EqualsTester() 17 new EqualsTester()
......
1 package org.onlab.onos.net.host; 1 package org.onlab.onos.net.host;
2 2
3 -import static org.junit.Assert.assertEquals;
4 -import static org.junit.Assert.assertTrue;
5 -
6 -import java.util.Set;
7 -
8 import org.junit.Test; 3 import org.junit.Test;
9 import org.onlab.onos.net.DeviceId; 4 import org.onlab.onos.net.DeviceId;
10 import org.onlab.onos.net.HostLocation; 5 import org.onlab.onos.net.HostLocation;
...@@ -13,7 +8,8 @@ import org.onlab.packet.IpPrefix; ...@@ -13,7 +8,8 @@ import org.onlab.packet.IpPrefix;
13 import org.onlab.packet.MacAddress; 8 import org.onlab.packet.MacAddress;
14 import org.onlab.packet.VlanId; 9 import org.onlab.packet.VlanId;
15 10
16 -import com.google.common.collect.Sets; 11 +import static org.junit.Assert.assertEquals;
12 +import static org.junit.Assert.assertTrue;
17 13
18 /** 14 /**
19 * Test for the default host description. 15 * Test for the default host description.
...@@ -22,24 +18,22 @@ public class DefualtHostDecriptionTest { ...@@ -22,24 +18,22 @@ public class DefualtHostDecriptionTest {
22 18
23 private static final MacAddress MAC = MacAddress.valueOf("00:00:11:00:00:01"); 19 private static final MacAddress MAC = MacAddress.valueOf("00:00:11:00:00:01");
24 private static final VlanId VLAN = VlanId.vlanId((short) 10); 20 private static final VlanId VLAN = VlanId.vlanId((short) 10);
21 + private static final IpPrefix IP = IpPrefix.valueOf("10.0.0.1");
22 +
25 private static final HostLocation LOC = new HostLocation( 23 private static final HostLocation LOC = new HostLocation(
26 DeviceId.deviceId("of:foo"), 24 DeviceId.deviceId("of:foo"),
27 PortNumber.portNumber(100), 25 PortNumber.portNumber(100),
28 123L 26 123L
29 ); 27 );
30 - private static final Set<IpPrefix> IPS = Sets.newHashSet(
31 - IpPrefix.valueOf("10.0.0.1"),
32 - IpPrefix.valueOf("10.0.0.2")
33 - );
34 28
35 @Test 29 @Test
36 public void basics() { 30 public void basics() {
37 HostDescription host = 31 HostDescription host =
38 - new DefaultHostDescription(MAC, VLAN, LOC, IPS); 32 + new DefaultHostDescription(MAC, VLAN, LOC, IP);
39 assertEquals("incorrect mac", MAC, host.hwAddress()); 33 assertEquals("incorrect mac", MAC, host.hwAddress());
40 assertEquals("incorrect vlan", VLAN, host.vlan()); 34 assertEquals("incorrect vlan", VLAN, host.vlan());
41 assertEquals("incorrect location", LOC, host.location()); 35 assertEquals("incorrect location", LOC, host.location());
42 - assertTrue("incorrect ip's", IPS.equals(host.ipAddresses())); 36 + assertEquals("incorrect ip's", IP, host.ipAddress());
43 assertTrue("incorrect toString", host.toString().contains("vlan=10")); 37 assertTrue("incorrect toString", host.toString().contains("vlan=10"));
44 } 38 }
45 39
......
...@@ -14,25 +14,25 @@ import org.apache.felix.scr.annotations.Service; ...@@ -14,25 +14,25 @@ import org.apache.felix.scr.annotations.Service;
14 import org.onlab.onos.cluster.ClusterEvent; 14 import org.onlab.onos.cluster.ClusterEvent;
15 import org.onlab.onos.cluster.ClusterEventListener; 15 import org.onlab.onos.cluster.ClusterEventListener;
16 import org.onlab.onos.cluster.ClusterService; 16 import org.onlab.onos.cluster.ClusterService;
17 +import org.onlab.onos.cluster.MastershipAdminService;
18 +import org.onlab.onos.cluster.MastershipEvent;
19 +import org.onlab.onos.cluster.MastershipListener;
20 +import org.onlab.onos.cluster.MastershipService;
21 +import org.onlab.onos.cluster.MastershipStore;
22 +import org.onlab.onos.cluster.MastershipStoreDelegate;
23 +import org.onlab.onos.cluster.MastershipTerm;
24 +import org.onlab.onos.cluster.MastershipTermService;
17 import org.onlab.onos.cluster.NodeId; 25 import org.onlab.onos.cluster.NodeId;
18 import org.onlab.onos.event.AbstractListenerRegistry; 26 import org.onlab.onos.event.AbstractListenerRegistry;
19 import org.onlab.onos.event.EventDeliveryService; 27 import org.onlab.onos.event.EventDeliveryService;
20 import org.onlab.onos.net.DeviceId; 28 import org.onlab.onos.net.DeviceId;
21 import org.onlab.onos.net.MastershipRole; 29 import org.onlab.onos.net.MastershipRole;
22 -import org.onlab.onos.net.device.DeviceMastershipAdminService;
23 -import org.onlab.onos.net.device.DeviceMastershipEvent;
24 -import org.onlab.onos.net.device.DeviceMastershipListener;
25 -import org.onlab.onos.net.device.DeviceMastershipService;
26 -import org.onlab.onos.net.device.DeviceMastershipStore;
27 -import org.onlab.onos.net.device.DeviceMastershipStoreDelegate;
28 -import org.onlab.onos.net.device.DeviceMastershipTerm;
29 -import org.onlab.onos.net.device.DeviceMastershipTermService;
30 import org.slf4j.Logger; 30 import org.slf4j.Logger;
31 31
32 @Component(immediate = true) 32 @Component(immediate = true)
33 @Service 33 @Service
34 public class MastershipManager 34 public class MastershipManager
35 -implements DeviceMastershipService, DeviceMastershipAdminService { 35 +implements MastershipService, MastershipAdminService {
36 36
37 private static final String NODE_ID_NULL = "Node ID cannot be null"; 37 private static final String NODE_ID_NULL = "Node ID cannot be null";
38 private static final String DEVICE_ID_NULL = "Device ID cannot be null"; 38 private static final String DEVICE_ID_NULL = "Device ID cannot be null";
...@@ -40,13 +40,13 @@ implements DeviceMastershipService, DeviceMastershipAdminService { ...@@ -40,13 +40,13 @@ implements DeviceMastershipService, DeviceMastershipAdminService {
40 40
41 private final Logger log = getLogger(getClass()); 41 private final Logger log = getLogger(getClass());
42 42
43 - protected final AbstractListenerRegistry<DeviceMastershipEvent, DeviceMastershipListener> 43 + protected final AbstractListenerRegistry<MastershipEvent, MastershipListener>
44 listenerRegistry = new AbstractListenerRegistry<>(); 44 listenerRegistry = new AbstractListenerRegistry<>();
45 45
46 - private final DeviceMastershipStoreDelegate delegate = new InternalDelegate(); 46 + private final MastershipStoreDelegate delegate = new InternalDelegate();
47 47
48 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 48 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
49 - protected DeviceMastershipStore store; 49 + protected MastershipStore store;
50 50
51 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 51 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
52 protected EventDeliveryService eventDispatcher; 52 protected EventDeliveryService eventDispatcher;
...@@ -58,7 +58,7 @@ implements DeviceMastershipService, DeviceMastershipAdminService { ...@@ -58,7 +58,7 @@ implements DeviceMastershipService, DeviceMastershipAdminService {
58 58
59 @Activate 59 @Activate
60 public void activate() { 60 public void activate() {
61 - eventDispatcher.addSink(DeviceMastershipEvent.class, listenerRegistry); 61 + eventDispatcher.addSink(MastershipEvent.class, listenerRegistry);
62 clusterService.addListener(clusterListener); 62 clusterService.addListener(clusterListener);
63 store.setDelegate(delegate); 63 store.setDelegate(delegate);
64 log.info("Started"); 64 log.info("Started");
...@@ -66,7 +66,7 @@ implements DeviceMastershipService, DeviceMastershipAdminService { ...@@ -66,7 +66,7 @@ implements DeviceMastershipService, DeviceMastershipAdminService {
66 66
67 @Deactivate 67 @Deactivate
68 public void deactivate() { 68 public void deactivate() {
69 - eventDispatcher.removeSink(DeviceMastershipEvent.class); 69 + eventDispatcher.removeSink(MastershipEvent.class);
70 clusterService.removeListener(clusterListener); 70 clusterService.removeListener(clusterListener);
71 store.unsetDelegate(delegate); 71 store.unsetDelegate(delegate);
72 log.info("Stopped"); 72 log.info("Stopped");
...@@ -78,7 +78,7 @@ implements DeviceMastershipService, DeviceMastershipAdminService { ...@@ -78,7 +78,7 @@ implements DeviceMastershipService, DeviceMastershipAdminService {
78 checkNotNull(deviceId, DEVICE_ID_NULL); 78 checkNotNull(deviceId, DEVICE_ID_NULL);
79 checkNotNull(role, ROLE_NULL); 79 checkNotNull(role, ROLE_NULL);
80 80
81 - DeviceMastershipEvent event = null; 81 + MastershipEvent event = null;
82 if (role.equals(MastershipRole.MASTER)) { 82 if (role.equals(MastershipRole.MASTER)) {
83 event = store.setMaster(nodeId, deviceId); 83 event = store.setMaster(nodeId, deviceId);
84 } else { 84 } else {
...@@ -98,7 +98,7 @@ implements DeviceMastershipService, DeviceMastershipAdminService { ...@@ -98,7 +98,7 @@ implements DeviceMastershipService, DeviceMastershipAdminService {
98 98
99 @Override 99 @Override
100 public void relinquishMastership(DeviceId deviceId) { 100 public void relinquishMastership(DeviceId deviceId) {
101 - DeviceMastershipEvent event = null; 101 + MastershipEvent event = null;
102 event = store.relinquishRole( 102 event = store.relinquishRole(
103 clusterService.getLocalNode().id(), deviceId); 103 clusterService.getLocalNode().id(), deviceId);
104 104
...@@ -127,18 +127,18 @@ implements DeviceMastershipService, DeviceMastershipAdminService { ...@@ -127,18 +127,18 @@ implements DeviceMastershipService, DeviceMastershipAdminService {
127 127
128 128
129 @Override 129 @Override
130 - public DeviceMastershipTermService requestTermService() { 130 + public MastershipTermService requestTermService() {
131 return new InternalMastershipTermService(); 131 return new InternalMastershipTermService();
132 } 132 }
133 133
134 @Override 134 @Override
135 - public void addListener(DeviceMastershipListener listener) { 135 + public void addListener(MastershipListener listener) {
136 checkNotNull(listener); 136 checkNotNull(listener);
137 listenerRegistry.addListener(listener); 137 listenerRegistry.addListener(listener);
138 } 138 }
139 139
140 @Override 140 @Override
141 - public void removeListener(DeviceMastershipListener listener) { 141 + public void removeListener(MastershipListener listener) {
142 checkNotNull(listener); 142 checkNotNull(listener);
143 listenerRegistry.removeListener(listener); 143 listenerRegistry.removeListener(listener);
144 } 144 }
...@@ -146,16 +146,16 @@ implements DeviceMastershipService, DeviceMastershipAdminService { ...@@ -146,16 +146,16 @@ implements DeviceMastershipService, DeviceMastershipAdminService {
146 // FIXME: provide wiring to allow events to be triggered by changes within the store 146 // FIXME: provide wiring to allow events to be triggered by changes within the store
147 147
148 // Posts the specified event to the local event dispatcher. 148 // Posts the specified event to the local event dispatcher.
149 - private void post(DeviceMastershipEvent event) { 149 + private void post(MastershipEvent event) {
150 if (event != null && eventDispatcher != null) { 150 if (event != null && eventDispatcher != null) {
151 eventDispatcher.post(event); 151 eventDispatcher.post(event);
152 } 152 }
153 } 153 }
154 154
155 - private class InternalMastershipTermService implements DeviceMastershipTermService { 155 + private class InternalMastershipTermService implements MastershipTermService {
156 156
157 @Override 157 @Override
158 - public DeviceMastershipTerm getMastershipTerm(DeviceId deviceId) { 158 + public MastershipTerm getMastershipTerm(DeviceId deviceId) {
159 return store.getTermFor(deviceId); 159 return store.getTermFor(deviceId);
160 } 160 }
161 161
...@@ -181,10 +181,10 @@ implements DeviceMastershipService, DeviceMastershipAdminService { ...@@ -181,10 +181,10 @@ implements DeviceMastershipService, DeviceMastershipAdminService {
181 181
182 } 182 }
183 183
184 - public class InternalDelegate implements DeviceMastershipStoreDelegate { 184 + public class InternalDelegate implements MastershipStoreDelegate {
185 185
186 @Override 186 @Override
187 - public void notify(DeviceMastershipEvent event) { 187 + public void notify(MastershipEvent event) {
188 log.info("dispatching mastership event {}", event); 188 log.info("dispatching mastership event {}", event);
189 eventDispatcher.post(event); 189 eventDispatcher.post(event);
190 } 190 }
......
...@@ -13,6 +13,11 @@ import org.apache.felix.scr.annotations.Reference; ...@@ -13,6 +13,11 @@ 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.apache.felix.scr.annotations.Service; 14 import org.apache.felix.scr.annotations.Service;
15 import org.onlab.onos.cluster.ClusterService; 15 import org.onlab.onos.cluster.ClusterService;
16 +import org.onlab.onos.cluster.MastershipEvent;
17 +import org.onlab.onos.cluster.MastershipListener;
18 +import org.onlab.onos.cluster.MastershipService;
19 +import org.onlab.onos.cluster.MastershipTermService;
20 +import org.onlab.onos.cluster.MastershipTerm;
16 import org.onlab.onos.cluster.NodeId; 21 import org.onlab.onos.cluster.NodeId;
17 import org.onlab.onos.event.AbstractListenerRegistry; 22 import org.onlab.onos.event.AbstractListenerRegistry;
18 import org.onlab.onos.event.EventDeliveryService; 23 import org.onlab.onos.event.EventDeliveryService;
...@@ -31,11 +36,6 @@ import org.onlab.onos.net.device.DeviceProviderService; ...@@ -31,11 +36,6 @@ import org.onlab.onos.net.device.DeviceProviderService;
31 import org.onlab.onos.net.device.DeviceService; 36 import org.onlab.onos.net.device.DeviceService;
32 import org.onlab.onos.net.device.DeviceStore; 37 import org.onlab.onos.net.device.DeviceStore;
33 import org.onlab.onos.net.device.DeviceStoreDelegate; 38 import org.onlab.onos.net.device.DeviceStoreDelegate;
34 -import org.onlab.onos.net.device.DeviceMastershipEvent;
35 -import org.onlab.onos.net.device.DeviceMastershipListener;
36 -import org.onlab.onos.net.device.DeviceMastershipService;
37 -import org.onlab.onos.net.device.DeviceMastershipTerm;
38 -import org.onlab.onos.net.device.DeviceMastershipTermService;
39 import org.onlab.onos.net.device.PortDescription; 39 import org.onlab.onos.net.device.PortDescription;
40 import org.onlab.onos.net.provider.AbstractProviderRegistry; 40 import org.onlab.onos.net.provider.AbstractProviderRegistry;
41 import org.onlab.onos.net.provider.AbstractProviderService; 41 import org.onlab.onos.net.provider.AbstractProviderService;
...@@ -64,7 +64,7 @@ public class DeviceManager ...@@ -64,7 +64,7 @@ public class DeviceManager
64 64
65 private final DeviceStoreDelegate delegate = new InternalStoreDelegate(); 65 private final DeviceStoreDelegate delegate = new InternalStoreDelegate();
66 66
67 - private final DeviceMastershipListener mastershipListener = new InternalMastershipListener(); 67 + private final MastershipListener mastershipListener = new InternalMastershipListener();
68 68
69 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 69 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
70 protected DeviceStore store; 70 protected DeviceStore store;
...@@ -76,9 +76,9 @@ public class DeviceManager ...@@ -76,9 +76,9 @@ public class DeviceManager
76 protected ClusterService clusterService; 76 protected ClusterService clusterService;
77 77
78 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 78 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
79 - protected DeviceMastershipService mastershipService; 79 + protected MastershipService mastershipService;
80 80
81 - protected DeviceMastershipTermService termService; 81 + protected MastershipTermService termService;
82 82
83 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 83 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
84 protected ClockProviderService clockProviderService; 84 protected ClockProviderService clockProviderService;
...@@ -209,7 +209,7 @@ public class DeviceManager ...@@ -209,7 +209,7 @@ public class DeviceManager
209 return; 209 return;
210 } 210 }
211 211
212 - DeviceMastershipTerm term = mastershipService.requestTermService() 212 + MastershipTerm term = mastershipService.requestTermService()
213 .getMastershipTerm(deviceId); 213 .getMastershipTerm(deviceId);
214 if (!term.master().equals(clusterService.getLocalNode().id())) { 214 if (!term.master().equals(clusterService.getLocalNode().id())) {
215 // lost mastership after requestRole told this instance was MASTER. 215 // lost mastership after requestRole told this instance was MASTER.
...@@ -320,16 +320,16 @@ public class DeviceManager ...@@ -320,16 +320,16 @@ public class DeviceManager
320 } 320 }
321 321
322 // Intercepts mastership events 322 // Intercepts mastership events
323 - private class InternalMastershipListener implements DeviceMastershipListener { 323 + private class InternalMastershipListener implements MastershipListener {
324 324
325 @Override 325 @Override
326 - public void event(DeviceMastershipEvent event) { 326 + public void event(MastershipEvent event) {
327 final DeviceId did = event.subject(); 327 final DeviceId did = event.subject();
328 if (isAvailable(did)) { 328 if (isAvailable(did)) {
329 final NodeId myNodeId = clusterService.getLocalNode().id(); 329 final NodeId myNodeId = clusterService.getLocalNode().id();
330 330
331 if (myNodeId.equals(event.master())) { 331 if (myNodeId.equals(event.master())) {
332 - DeviceMastershipTerm term = termService.getMastershipTerm(did); 332 + MastershipTerm term = termService.getMastershipTerm(did);
333 333
334 if (term.master().equals(myNodeId)) { 334 if (term.master().equals(myNodeId)) {
335 // only set the new term if I am the master 335 // only set the new term if I am the master
......
...@@ -168,7 +168,6 @@ public class HostManager ...@@ -168,7 +168,6 @@ public class HostManager
168 checkNotNull(hostId, HOST_ID_NULL); 168 checkNotNull(hostId, HOST_ID_NULL);
169 HostEvent event = store.removeHost(hostId); 169 HostEvent event = store.removeHost(hostId);
170 if (event != null) { 170 if (event != null) {
171 - log.info("Host {} administratively removed", hostId);
172 post(event); 171 post(event);
173 } 172 }
174 } 173 }
...@@ -214,7 +213,6 @@ public class HostManager ...@@ -214,7 +213,6 @@ public class HostManager
214 HostEvent event = store.createOrUpdateHost(provider().id(), hostId, 213 HostEvent event = store.createOrUpdateHost(provider().id(), hostId,
215 hostDescription); 214 hostDescription);
216 if (event != null) { 215 if (event != null) {
217 - log.debug("Host {} detected", hostId);
218 post(event); 216 post(event);
219 } 217 }
220 } 218 }
...@@ -225,7 +223,6 @@ public class HostManager ...@@ -225,7 +223,6 @@ public class HostManager
225 checkValidity(); 223 checkValidity();
226 HostEvent event = store.removeHost(hostId); 224 HostEvent event = store.removeHost(hostId);
227 if (event != null) { 225 if (event != null) {
228 - log.debug("Host {} vanished", hostId);
229 post(event); 226 post(event);
230 } 227 }
231 } 228 }
......
...@@ -22,9 +22,9 @@ import org.onlab.onos.net.Link; ...@@ -22,9 +22,9 @@ import org.onlab.onos.net.Link;
22 import org.onlab.onos.net.Path; 22 import org.onlab.onos.net.Path;
23 import org.onlab.onos.net.PortNumber; 23 import org.onlab.onos.net.PortNumber;
24 import org.onlab.onos.net.host.HostService; 24 import org.onlab.onos.net.host.HostService;
25 -import org.onlab.onos.net.topology.PathService;
26 import org.onlab.onos.net.provider.ProviderId; 25 import org.onlab.onos.net.provider.ProviderId;
27 import org.onlab.onos.net.topology.LinkWeight; 26 import org.onlab.onos.net.topology.LinkWeight;
27 +import org.onlab.onos.net.topology.PathService;
28 import org.onlab.onos.net.topology.Topology; 28 import org.onlab.onos.net.topology.Topology;
29 import org.onlab.onos.net.topology.TopologyService; 29 import org.onlab.onos.net.topology.TopologyService;
30 import org.slf4j.Logger; 30 import org.slf4j.Logger;
...@@ -33,7 +33,6 @@ import java.util.List; ...@@ -33,7 +33,6 @@ import java.util.List;
33 import java.util.Set; 33 import java.util.Set;
34 34
35 import static com.google.common.base.Preconditions.checkNotNull; 35 import static com.google.common.base.Preconditions.checkNotNull;
36 -import static org.onlab.onos.net.DeviceId.deviceId;
37 import static org.slf4j.LoggerFactory.getLogger; 36 import static org.slf4j.LoggerFactory.getLogger;
38 37
39 /** 38 /**
...@@ -162,8 +161,8 @@ public class PathManager implements PathService { ...@@ -162,8 +161,8 @@ public class PathManager implements PathService {
162 // edge link since the src or dst are really an infrastructure device. 161 // edge link since the src or dst are really an infrastructure device.
163 private static class NotHost extends DefaultEdgeLink implements EdgeLink { 162 private static class NotHost extends DefaultEdgeLink implements EdgeLink {
164 NotHost() { 163 NotHost() {
165 - super(PID, new ConnectPoint(HostId.hostId("nic:none"), P0), 164 + super(PID, new ConnectPoint(HostId.NONE, P0),
166 - new HostLocation(deviceId("none:none"), P0, 0L), false); 165 + new HostLocation(DeviceId.NONE, P0, 0L), false);
167 } 166 }
168 } 167 }
169 } 168 }
......
...@@ -10,11 +10,11 @@ import org.onlab.onos.cluster.ClusterService; ...@@ -10,11 +10,11 @@ import org.onlab.onos.cluster.ClusterService;
10 import org.onlab.onos.cluster.ControllerNode; 10 import org.onlab.onos.cluster.ControllerNode;
11 import org.onlab.onos.cluster.ControllerNode.State; 11 import org.onlab.onos.cluster.ControllerNode.State;
12 import org.onlab.onos.cluster.DefaultControllerNode; 12 import org.onlab.onos.cluster.DefaultControllerNode;
13 +import org.onlab.onos.cluster.MastershipService;
14 +import org.onlab.onos.cluster.MastershipTermService;
13 import org.onlab.onos.cluster.NodeId; 15 import org.onlab.onos.cluster.NodeId;
14 import org.onlab.onos.event.impl.TestEventDispatcher; 16 import org.onlab.onos.event.impl.TestEventDispatcher;
15 import org.onlab.onos.net.DeviceId; 17 import org.onlab.onos.net.DeviceId;
16 -import org.onlab.onos.net.device.DeviceMastershipService;
17 -import org.onlab.onos.net.device.DeviceMastershipTermService;
18 import org.onlab.onos.store.trivial.impl.SimpleMastershipStore; 18 import org.onlab.onos.store.trivial.impl.SimpleMastershipStore;
19 import org.onlab.packet.IpPrefix; 19 import org.onlab.packet.IpPrefix;
20 20
...@@ -34,7 +34,7 @@ public class MastershipManagerTest { ...@@ -34,7 +34,7 @@ public class MastershipManagerTest {
34 private static final DeviceId DEV_OTHER = DeviceId.deviceId("of:2"); 34 private static final DeviceId DEV_OTHER = DeviceId.deviceId("of:2");
35 35
36 private MastershipManager mgr; 36 private MastershipManager mgr;
37 - protected DeviceMastershipService service; 37 + protected MastershipService service;
38 38
39 @Before 39 @Before
40 public void setUp() { 40 public void setUp() {
...@@ -120,7 +120,7 @@ public class MastershipManagerTest { ...@@ -120,7 +120,7 @@ public class MastershipManagerTest {
120 120
121 @Test 121 @Test
122 public void termService() { 122 public void termService() {
123 - DeviceMastershipTermService ts = mgr.requestTermService(); 123 + MastershipTermService ts = mgr.requestTermService();
124 124
125 //term = 0 for both 125 //term = 0 for both
126 mgr.setRole(NID_LOCAL, DEV_MASTER, MASTER); 126 mgr.setRole(NID_LOCAL, DEV_MASTER, MASTER);
......
...@@ -11,6 +11,8 @@ import org.onlab.onos.cluster.ClusterService; ...@@ -11,6 +11,8 @@ import org.onlab.onos.cluster.ClusterService;
11 import org.onlab.onos.cluster.ControllerNode; 11 import org.onlab.onos.cluster.ControllerNode;
12 import org.onlab.onos.cluster.DefaultControllerNode; 12 import org.onlab.onos.cluster.DefaultControllerNode;
13 import org.onlab.onos.cluster.MastershipServiceAdapter; 13 import org.onlab.onos.cluster.MastershipServiceAdapter;
14 +import org.onlab.onos.cluster.MastershipTerm;
15 +import org.onlab.onos.cluster.MastershipTermService;
14 import org.onlab.onos.cluster.NodeId; 16 import org.onlab.onos.cluster.NodeId;
15 import org.onlab.onos.cluster.ControllerNode.State; 17 import org.onlab.onos.cluster.ControllerNode.State;
16 import org.onlab.onos.event.Event; 18 import org.onlab.onos.event.Event;
...@@ -30,8 +32,6 @@ import org.onlab.onos.net.device.DeviceProvider; ...@@ -30,8 +32,6 @@ import org.onlab.onos.net.device.DeviceProvider;
30 import org.onlab.onos.net.device.DeviceProviderRegistry; 32 import org.onlab.onos.net.device.DeviceProviderRegistry;
31 import org.onlab.onos.net.device.DeviceProviderService; 33 import org.onlab.onos.net.device.DeviceProviderService;
32 import org.onlab.onos.net.device.DeviceService; 34 import org.onlab.onos.net.device.DeviceService;
33 -import org.onlab.onos.net.device.DeviceMastershipTerm;
34 -import org.onlab.onos.net.device.DeviceMastershipTermService;
35 import org.onlab.onos.net.device.PortDescription; 35 import org.onlab.onos.net.device.PortDescription;
36 import org.onlab.onos.net.provider.AbstractProvider; 36 import org.onlab.onos.net.provider.AbstractProvider;
37 import org.onlab.onos.net.provider.ProviderId; 37 import org.onlab.onos.net.provider.ProviderId;
...@@ -290,12 +290,12 @@ public class DeviceManagerTest { ...@@ -290,12 +290,12 @@ public class DeviceManagerTest {
290 } 290 }
291 291
292 @Override 292 @Override
293 - public DeviceMastershipTermService requestTermService() { 293 + public MastershipTermService requestTermService() {
294 - return new DeviceMastershipTermService() { 294 + return new MastershipTermService() {
295 @Override 295 @Override
296 - public DeviceMastershipTerm getMastershipTerm(DeviceId deviceId) { 296 + public MastershipTerm getMastershipTerm(DeviceId deviceId) {
297 // FIXME: just returning something not null 297 // FIXME: just returning something not null
298 - return DeviceMastershipTerm.of(NID_LOCAL, 1); 298 + return MastershipTerm.of(NID_LOCAL, 1);
299 } 299 }
300 }; 300 };
301 } 301 }
...@@ -339,7 +339,7 @@ public class DeviceManagerTest { ...@@ -339,7 +339,7 @@ public class DeviceManagerTest {
339 ClockProviderService { 339 ClockProviderService {
340 340
341 @Override 341 @Override
342 - public void setMastershipTerm(DeviceId deviceId, DeviceMastershipTerm term) { 342 + public void setMastershipTerm(DeviceId deviceId, MastershipTerm term) {
343 // TODO Auto-generated method stub 343 // TODO Auto-generated method stub
344 } 344 }
345 } 345 }
......
...@@ -58,8 +58,6 @@ public class HostManagerTest { ...@@ -58,8 +58,6 @@ public class HostManagerTest {
58 58
59 private static final IpPrefix IP1 = IpPrefix.valueOf("10.0.0.1"); 59 private static final IpPrefix IP1 = IpPrefix.valueOf("10.0.0.1");
60 private static final IpPrefix IP2 = IpPrefix.valueOf("10.0.0.2"); 60 private static final IpPrefix IP2 = IpPrefix.valueOf("10.0.0.2");
61 - private static final Set<IpPrefix> IPSET1 = Sets.newHashSet(IP1);
62 - private static final Set<IpPrefix> IPSET2 = Sets.newHashSet(IP2);
63 61
64 private static final DeviceId DID1 = DeviceId.deviceId("of:001"); 62 private static final DeviceId DID1 = DeviceId.deviceId("of:001");
65 private static final DeviceId DID2 = DeviceId.deviceId("of:002"); 63 private static final DeviceId DID2 = DeviceId.deviceId("of:002");
...@@ -109,8 +107,8 @@ public class HostManagerTest { ...@@ -109,8 +107,8 @@ public class HostManagerTest {
109 } 107 }
110 108
111 private void detect(HostId hid, MacAddress mac, VlanId vlan, 109 private void detect(HostId hid, MacAddress mac, VlanId vlan,
112 - HostLocation loc, Set<IpPrefix> ips) { 110 + HostLocation loc, IpPrefix ip) {
113 - HostDescription descr = new DefaultHostDescription(mac, vlan, loc, ips); 111 + HostDescription descr = new DefaultHostDescription(mac, vlan, loc, ip);
114 providerService.hostDetected(hid, descr); 112 providerService.hostDetected(hid, descr);
115 assertNotNull("host should be found", mgr.getHost(hid)); 113 assertNotNull("host should be found", mgr.getHost(hid));
116 } 114 }
...@@ -130,26 +128,26 @@ public class HostManagerTest { ...@@ -130,26 +128,26 @@ public class HostManagerTest {
130 assertNull("host shouldn't be found", mgr.getHost(HID1)); 128 assertNull("host shouldn't be found", mgr.getHost(HID1));
131 129
132 // host addition 130 // host addition
133 - detect(HID1, MAC1, VLAN1, LOC1, IPSET1); 131 + detect(HID1, MAC1, VLAN1, LOC1, IP1);
134 assertEquals("exactly one should be found", 1, mgr.getHostCount()); 132 assertEquals("exactly one should be found", 1, mgr.getHostCount());
135 - detect(HID2, MAC2, VLAN2, LOC2, IPSET1); 133 + detect(HID2, MAC2, VLAN2, LOC2, IP1);
136 assertEquals("two hosts should be found", 2, mgr.getHostCount()); 134 assertEquals("two hosts should be found", 2, mgr.getHostCount());
137 validateEvents(HOST_ADDED, HOST_ADDED); 135 validateEvents(HOST_ADDED, HOST_ADDED);
138 136
139 // host motion 137 // host motion
140 - detect(HID1, MAC1, VLAN1, LOC2, IPSET1); 138 + detect(HID1, MAC1, VLAN1, LOC2, IP1);
141 validateEvents(HOST_MOVED); 139 validateEvents(HOST_MOVED);
142 assertEquals("only two hosts should be found", 2, mgr.getHostCount()); 140 assertEquals("only two hosts should be found", 2, mgr.getHostCount());
143 141
144 // host update 142 // host update
145 - detect(HID1, MAC1, VLAN1, LOC2, IPSET2); 143 + detect(HID1, MAC1, VLAN1, LOC2, IP2);
146 validateEvents(HOST_UPDATED); 144 validateEvents(HOST_UPDATED);
147 assertEquals("only two hosts should be found", 2, mgr.getHostCount()); 145 assertEquals("only two hosts should be found", 2, mgr.getHostCount());
148 } 146 }
149 147
150 @Test 148 @Test
151 public void hostVanished() { 149 public void hostVanished() {
152 - detect(HID1, MAC1, VLAN1, LOC1, IPSET1); 150 + detect(HID1, MAC1, VLAN1, LOC1, IP1);
153 providerService.hostVanished(HID1); 151 providerService.hostVanished(HID1);
154 validateEvents(HOST_ADDED, HOST_REMOVED); 152 validateEvents(HOST_ADDED, HOST_REMOVED);
155 153
...@@ -157,7 +155,7 @@ public class HostManagerTest { ...@@ -157,7 +155,7 @@ public class HostManagerTest {
157 } 155 }
158 156
159 private void validateHosts( 157 private void validateHosts(
160 - String msg, Iterable<Host> hosts, HostId ... ids) { 158 + String msg, Iterable<Host> hosts, HostId... ids) {
161 Set<HostId> hids = Sets.newHashSet(ids); 159 Set<HostId> hids = Sets.newHashSet(ids);
162 for (Host h : hosts) { 160 for (Host h : hosts) {
163 assertTrue(msg, hids.remove(h.id())); 161 assertTrue(msg, hids.remove(h.id()));
...@@ -167,8 +165,8 @@ public class HostManagerTest { ...@@ -167,8 +165,8 @@ public class HostManagerTest {
167 165
168 @Test 166 @Test
169 public void getHosts() { 167 public void getHosts() {
170 - detect(HID1, MAC1, VLAN1, LOC1, IPSET1); 168 + detect(HID1, MAC1, VLAN1, LOC1, IP1);
171 - detect(HID2, MAC2, VLAN1, LOC2, IPSET2); 169 + detect(HID2, MAC2, VLAN1, LOC2, IP2);
172 170
173 validateHosts("host not properly stored", mgr.getHosts(), HID1, HID2); 171 validateHosts("host not properly stored", mgr.getHosts(), HID1, HID2);
174 validateHosts("can't get hosts by VLAN", mgr.getHostsByVlan(VLAN1), HID1, HID2); 172 validateHosts("can't get hosts by VLAN", mgr.getHostsByVlan(VLAN1), HID1, HID2);
......
...@@ -65,47 +65,48 @@ public class PathManagerTest { ...@@ -65,47 +65,48 @@ public class PathManagerTest {
65 @Test 65 @Test
66 public void infraToEdge() { 66 public void infraToEdge() {
67 DeviceId src = did("src"); 67 DeviceId src = did("src");
68 - HostId dst = hid("dst"); 68 + HostId dst = hid("12:34:56:78:90:ab/1");
69 fakeTopoMgr.paths.add(createPath("src", "middle", "edge")); 69 fakeTopoMgr.paths.add(createPath("src", "middle", "edge"));
70 - fakeHostMgr.hosts.put(dst, host("dst", "edge")); 70 + fakeHostMgr.hosts.put(dst, host("12:34:56:78:90:ab/1", "edge"));
71 Set<Path> paths = service.getPaths(src, dst); 71 Set<Path> paths = service.getPaths(src, dst);
72 validatePaths(paths, 1, 3, src, dst); 72 validatePaths(paths, 1, 3, src, dst);
73 } 73 }
74 74
75 @Test 75 @Test
76 public void edgeToInfra() { 76 public void edgeToInfra() {
77 - HostId src = hid("src"); 77 + HostId src = hid("12:34:56:78:90:ab/1");
78 DeviceId dst = did("dst"); 78 DeviceId dst = did("dst");
79 fakeTopoMgr.paths.add(createPath("edge", "middle", "dst")); 79 fakeTopoMgr.paths.add(createPath("edge", "middle", "dst"));
80 - fakeHostMgr.hosts.put(src, host("src", "edge")); 80 + fakeHostMgr.hosts.put(src, host("12:34:56:78:90:ab/1", "edge"));
81 Set<Path> paths = service.getPaths(src, dst); 81 Set<Path> paths = service.getPaths(src, dst);
82 validatePaths(paths, 1, 3, src, dst); 82 validatePaths(paths, 1, 3, src, dst);
83 } 83 }
84 84
85 @Test 85 @Test
86 public void edgeToEdge() { 86 public void edgeToEdge() {
87 - HostId src = hid("src"); 87 + HostId src = hid("12:34:56:78:90:ab/1");
88 - HostId dst = hid("dst"); 88 + HostId dst = hid("12:34:56:78:90:ef/1");
89 fakeTopoMgr.paths.add(createPath("srcEdge", "middle", "dstEdge")); 89 fakeTopoMgr.paths.add(createPath("srcEdge", "middle", "dstEdge"));
90 - fakeHostMgr.hosts.put(src, host("src", "srcEdge")); 90 + fakeHostMgr.hosts.put(src, host("12:34:56:78:90:ab/1", "srcEdge"));
91 - fakeHostMgr.hosts.put(dst, host("dst", "dstEdge")); 91 + fakeHostMgr.hosts.put(dst, host("12:34:56:78:90:ef/1", "dstEdge"));
92 Set<Path> paths = service.getPaths(src, dst); 92 Set<Path> paths = service.getPaths(src, dst);
93 validatePaths(paths, 1, 4, src, dst); 93 validatePaths(paths, 1, 4, src, dst);
94 } 94 }
95 95
96 @Test 96 @Test
97 public void edgeToEdgeDirect() { 97 public void edgeToEdgeDirect() {
98 - HostId src = hid("src"); 98 + HostId src = hid("12:34:56:78:90:ab/1");
99 - HostId dst = hid("dst"); 99 + HostId dst = hid("12:34:56:78:90:ef/1");
100 - fakeHostMgr.hosts.put(src, host("src", "edge")); 100 + fakeHostMgr.hosts.put(src, host("12:34:56:78:90:ab/1", "edge"));
101 - fakeHostMgr.hosts.put(dst, host("dst", "edge")); 101 + fakeHostMgr.hosts.put(dst, host("12:34:56:78:90:ef/1", "edge"));
102 Set<Path> paths = service.getPaths(src, dst); 102 Set<Path> paths = service.getPaths(src, dst);
103 validatePaths(paths, 1, 2, src, dst); 103 validatePaths(paths, 1, 2, src, dst);
104 } 104 }
105 105
106 @Test 106 @Test
107 public void noEdge() { 107 public void noEdge() {
108 - Set<Path> paths = service.getPaths(hid("src"), hid("dst")); 108 + Set<Path> paths = service.getPaths(hid("12:34:56:78:90:ab/1"),
109 + hid("12:34:56:78:90:ef/1"));
109 assertTrue("there should be no paths", paths.isEmpty()); 110 assertTrue("there should be no paths", paths.isEmpty());
110 } 111 }
111 112
......
...@@ -134,11 +134,11 @@ public class TopologyManagerTest { ...@@ -134,11 +134,11 @@ public class TopologyManagerTest {
134 service.isInfrastructure(topology, new ConnectPoint(did("a"), portNumber(3)))); 134 service.isInfrastructure(topology, new ConnectPoint(did("a"), portNumber(3))));
135 135
136 // One of these cannot be a broadcast point... or we have a loop... 136 // One of these cannot be a broadcast point... or we have a loop...
137 - assertFalse("should not be broadcast point", 137 +// assertFalse("should not be broadcast point",
138 - service.isBroadcastPoint(topology, new ConnectPoint(did("a"), portNumber(1))) && 138 +// service.isBroadcastPoint(topology, new ConnectPoint(did("a"), portNumber(1))) &&
139 - service.isBroadcastPoint(topology, new ConnectPoint(did("b"), portNumber(1))) && 139 +// service.isBroadcastPoint(topology, new ConnectPoint(did("b"), portNumber(1))) &&
140 - service.isBroadcastPoint(topology, new ConnectPoint(did("c"), portNumber(1))) && 140 +// service.isBroadcastPoint(topology, new ConnectPoint(did("c"), portNumber(1))) &&
141 - service.isBroadcastPoint(topology, new ConnectPoint(did("d"), portNumber(1)))); 141 +// service.isBroadcastPoint(topology, new ConnectPoint(did("d"), portNumber(1))));
142 assertTrue("should be broadcast point", 142 assertTrue("should be broadcast point",
143 service.isBroadcastPoint(topology, new ConnectPoint(did("a"), portNumber(3)))); 143 service.isBroadcastPoint(topology, new ConnectPoint(did("a"), portNumber(3))));
144 } 144 }
......
...@@ -54,8 +54,13 @@ ...@@ -54,8 +54,13 @@
54 <artifactId>org.apache.felix.scr.annotations</artifactId> 54 <artifactId>org.apache.felix.scr.annotations</artifactId>
55 </dependency> 55 </dependency>
56 <dependency> 56 <dependency>
57 - <groupId>de.javakaffee</groupId> 57 + <groupId>com.google.guava</groupId>
58 - <artifactId>kryo-serializers</artifactId> 58 + <artifactId>guava-testlib</artifactId>
59 + <scope>test</scope>
60 + </dependency>
61 + <dependency>
62 + <groupId>org.apache.commons</groupId>
63 + <artifactId>commons-lang3</artifactId>
59 </dependency> 64 </dependency>
60 </dependencies> 65 </dependencies>
61 66
......
...@@ -6,7 +6,6 @@ import java.io.IOException; ...@@ -6,7 +6,6 @@ import java.io.IOException;
6 import java.util.Set; 6 import java.util.Set;
7 import java.util.Timer; 7 import java.util.Timer;
8 import java.util.TimerTask; 8 import java.util.TimerTask;
9 -
10 import org.apache.felix.scr.annotations.Activate; 9 import org.apache.felix.scr.annotations.Activate;
11 import org.apache.felix.scr.annotations.Component; 10 import org.apache.felix.scr.annotations.Component;
12 import org.apache.felix.scr.annotations.Deactivate; 11 import org.apache.felix.scr.annotations.Deactivate;
...@@ -24,8 +23,10 @@ import org.onlab.onos.store.cluster.messaging.ClusterCommunicationService; ...@@ -24,8 +23,10 @@ import org.onlab.onos.store.cluster.messaging.ClusterCommunicationService;
24 import org.onlab.onos.store.cluster.messaging.ClusterMessage; 23 import org.onlab.onos.store.cluster.messaging.ClusterMessage;
25 import org.onlab.onos.store.cluster.messaging.ClusterMessageHandler; 24 import org.onlab.onos.store.cluster.messaging.ClusterMessageHandler;
26 import org.onlab.onos.store.cluster.messaging.MessageSubject; 25 import org.onlab.onos.store.cluster.messaging.MessageSubject;
26 +import org.onlab.onos.store.serializers.ClusterMessageSerializer;
27 import org.onlab.onos.store.serializers.KryoPoolUtil; 27 import org.onlab.onos.store.serializers.KryoPoolUtil;
28 import org.onlab.onos.store.serializers.KryoSerializer; 28 import org.onlab.onos.store.serializers.KryoSerializer;
29 +import org.onlab.onos.store.serializers.MessageSubjectSerializer;
29 import org.onlab.util.KryoPool; 30 import org.onlab.util.KryoPool;
30 import org.onlab.netty.Endpoint; 31 import org.onlab.netty.Endpoint;
31 import org.onlab.netty.Message; 32 import org.onlab.netty.Message;
......
1 -package org.onlab.onos.store.common.impl;
2 -
3 -import java.util.Map;
4 -
5 -import org.onlab.onos.cluster.NodeId;
6 -import org.onlab.onos.store.Timestamp;
7 -
8 -import com.google.common.collect.ImmutableMap;
9 -
10 -/**
11 - * Anti-Entropy advertisement message.
12 - * <p>
13 - * Message to advertise the information this node holds.
14 - *
15 - * @param <ID> ID type
16 - */
17 -public class AntiEntropyAdvertisement<ID> {
18 -
19 - private final NodeId sender;
20 - private final ImmutableMap<ID, Timestamp> advertisement;
21 -
22 - /**
23 - * Creates anti-entropy advertisement message.
24 - *
25 - * @param sender sender of this message
26 - * @param advertisement timestamp information of the data sender holds
27 - */
28 - public AntiEntropyAdvertisement(NodeId sender, Map<ID, Timestamp> advertisement) {
29 - this.sender = sender;
30 - this.advertisement = ImmutableMap.copyOf(advertisement);
31 - }
32 -
33 - public NodeId sender() {
34 - return sender;
35 - }
36 -
37 - public ImmutableMap<ID, Timestamp> advertisement() {
38 - return advertisement;
39 - }
40 -
41 - // Default constructor for serializer
42 - protected AntiEntropyAdvertisement() {
43 - this.sender = null;
44 - this.advertisement = null;
45 - }
46 -}
1 -package org.onlab.onos.store.common.impl;
2 -
3 -import java.util.Map;
4 -import java.util.Set;
5 -
6 -import org.onlab.onos.cluster.NodeId;
7 -import org.onlab.onos.store.VersionedValue;
8 -
9 -import com.google.common.collect.ImmutableMap;
10 -import com.google.common.collect.ImmutableSet;
11 -
12 -/**
13 - * Anti-Entropy reply message.
14 - * <p>
15 - * Message to send in reply to advertisement or another reply.
16 - * Suggest to the sender about the more up-to-date data this node has,
17 - * and request for more recent data that the receiver has.
18 - */
19 -public class AntiEntropyReply<ID, V extends VersionedValue<?>> {
20 -
21 - private final NodeId sender;
22 - private final ImmutableMap<ID, V> suggestion;
23 - private final ImmutableSet<ID> request;
24 -
25 - /**
26 - * Creates a reply to anti-entropy message.
27 - *
28 - * @param sender sender of this message
29 - * @param suggestion collection of more recent values, sender had
30 - * @param request Collection of identifiers
31 - */
32 - public AntiEntropyReply(NodeId sender,
33 - Map<ID, V> suggestion,
34 - Set<ID> request) {
35 - this.sender = sender;
36 - this.suggestion = ImmutableMap.copyOf(suggestion);
37 - this.request = ImmutableSet.copyOf(request);
38 - }
39 -
40 - public NodeId sender() {
41 - return sender;
42 - }
43 -
44 - /**
45 - * Returns collection of values, which the recipient of this reply is likely
46 - * to be missing or has outdated version.
47 - *
48 - * @return
49 - */
50 - public ImmutableMap<ID, V> suggestion() {
51 - return suggestion;
52 - }
53 -
54 - /**
55 - * Returns collection of identifier to request.
56 - *
57 - * @return collection of identifier to request
58 - */
59 - public ImmutableSet<ID> request() {
60 - return request;
61 - }
62 -
63 - /**
64 - * Checks if reply contains any suggestion or request.
65 - *
66 - * @return true if nothing is suggested and requested
67 - */
68 - public boolean isEmpty() {
69 - return suggestion.isEmpty() && request.isEmpty();
70 - }
71 -
72 - // Default constructor for serializer
73 - protected AntiEntropyReply() {
74 - this.sender = null;
75 - this.suggestion = null;
76 - this.request = null;
77 - }
78 -}
1 +package org.onlab.onos.store.common.impl;
2 +
3 +import org.onlab.onos.cluster.ControllerNode;
4 +import org.onlab.onos.cluster.NodeId;
5 +
6 +import com.google.common.base.Function;
7 +
8 +/**
9 + * Function to convert ControllerNode to NodeId.
10 + */
11 +public final class ControllerNodeToNodeId
12 + implements Function<ControllerNode, NodeId> {
13 +
14 + private static final ControllerNodeToNodeId INSTANCE = new ControllerNodeToNodeId();
15 +
16 + @Override
17 + public NodeId apply(ControllerNode input) {
18 + return input.id();
19 + }
20 +
21 + public static ControllerNodeToNodeId toNodeId() {
22 + return INSTANCE;
23 + }
24 +}
...@@ -13,7 +13,7 @@ import com.google.common.collect.ComparisonChain; ...@@ -13,7 +13,7 @@ import com.google.common.collect.ComparisonChain;
13 * Default implementation of Timestamp. 13 * Default implementation of Timestamp.
14 * TODO: Better documentation. 14 * TODO: Better documentation.
15 */ 15 */
16 -public final class DeviceMastershipBasedTimestamp implements Timestamp { 16 +public final class MastershipBasedTimestamp implements Timestamp {
17 17
18 private final int termNumber; 18 private final int termNumber;
19 private final int sequenceNumber; 19 private final int sequenceNumber;
...@@ -24,16 +24,16 @@ public final class DeviceMastershipBasedTimestamp implements Timestamp { ...@@ -24,16 +24,16 @@ public final class DeviceMastershipBasedTimestamp implements Timestamp {
24 * @param termNumber the mastership termNumber 24 * @param termNumber the mastership termNumber
25 * @param sequenceNumber the sequenceNumber number within the termNumber 25 * @param sequenceNumber the sequenceNumber number within the termNumber
26 */ 26 */
27 - public DeviceMastershipBasedTimestamp(int termNumber, int sequenceNumber) { 27 + public MastershipBasedTimestamp(int termNumber, int sequenceNumber) {
28 this.termNumber = termNumber; 28 this.termNumber = termNumber;
29 this.sequenceNumber = sequenceNumber; 29 this.sequenceNumber = sequenceNumber;
30 } 30 }
31 31
32 @Override 32 @Override
33 public int compareTo(Timestamp o) { 33 public int compareTo(Timestamp o) {
34 - checkArgument(o instanceof DeviceMastershipBasedTimestamp, 34 + checkArgument(o instanceof MastershipBasedTimestamp,
35 "Must be MastershipBasedTimestamp", o); 35 "Must be MastershipBasedTimestamp", o);
36 - DeviceMastershipBasedTimestamp that = (DeviceMastershipBasedTimestamp) o; 36 + MastershipBasedTimestamp that = (MastershipBasedTimestamp) o;
37 37
38 return ComparisonChain.start() 38 return ComparisonChain.start()
39 .compare(this.termNumber, that.termNumber) 39 .compare(this.termNumber, that.termNumber)
...@@ -51,10 +51,10 @@ public final class DeviceMastershipBasedTimestamp implements Timestamp { ...@@ -51,10 +51,10 @@ public final class DeviceMastershipBasedTimestamp implements Timestamp {
51 if (this == obj) { 51 if (this == obj) {
52 return true; 52 return true;
53 } 53 }
54 - if (!(obj instanceof DeviceMastershipBasedTimestamp)) { 54 + if (!(obj instanceof MastershipBasedTimestamp)) {
55 return false; 55 return false;
56 } 56 }
57 - DeviceMastershipBasedTimestamp that = (DeviceMastershipBasedTimestamp) obj; 57 + MastershipBasedTimestamp that = (MastershipBasedTimestamp) obj;
58 return Objects.equals(this.termNumber, that.termNumber) && 58 return Objects.equals(this.termNumber, that.termNumber) &&
59 Objects.equals(this.sequenceNumber, that.sequenceNumber); 59 Objects.equals(this.sequenceNumber, that.sequenceNumber);
60 } 60 }
...@@ -87,7 +87,7 @@ public final class DeviceMastershipBasedTimestamp implements Timestamp { ...@@ -87,7 +87,7 @@ public final class DeviceMastershipBasedTimestamp implements Timestamp {
87 87
88 // Default constructor for serialization 88 // Default constructor for serialization
89 @Deprecated 89 @Deprecated
90 - protected DeviceMastershipBasedTimestamp() { 90 + protected MastershipBasedTimestamp() {
91 this.termNumber = -1; 91 this.termNumber = -1;
92 this.sequenceNumber = -1; 92 this.sequenceNumber = -1;
93 } 93 }
......
1 -package org.onlab.onos.store; 1 +package org.onlab.onos.store.common.impl;
2 2
3 import static com.google.common.base.Preconditions.checkNotNull; 3 import static com.google.common.base.Preconditions.checkNotNull;
4 4
5 import java.util.Objects; 5 import java.util.Objects;
6 6
7 +import org.onlab.onos.store.Timestamp;
8 +
7 import com.google.common.base.MoreObjects; 9 import com.google.common.base.MoreObjects;
8 10
9 /** 11 /**
...@@ -28,6 +30,7 @@ public final class Timestamped<T> { ...@@ -28,6 +30,7 @@ public final class Timestamped<T> {
28 30
29 /** 31 /**
30 * Returns the value. 32 * Returns the value.
33 + *
31 * @return value 34 * @return value
32 */ 35 */
33 public T value() { 36 public T value() {
...@@ -36,6 +39,7 @@ public final class Timestamped<T> { ...@@ -36,6 +39,7 @@ public final class Timestamped<T> {
36 39
37 /** 40 /**
38 * Returns the time stamp. 41 * Returns the time stamp.
42 + *
39 * @return time stamp 43 * @return time stamp
40 */ 44 */
41 public Timestamp timestamp() { 45 public Timestamp timestamp() {
...@@ -49,7 +53,16 @@ public final class Timestamped<T> { ...@@ -49,7 +53,16 @@ public final class Timestamped<T> {
49 * @return true if this instance is newer. 53 * @return true if this instance is newer.
50 */ 54 */
51 public boolean isNewer(Timestamped<T> other) { 55 public boolean isNewer(Timestamped<T> other) {
52 - return this.timestamp.compareTo(checkNotNull(other).timestamp()) > 0; 56 + return isNewer(checkNotNull(other).timestamp());
57 + }
58 +
59 + /**
60 + * Tests if this timestamp is newer thatn the specified timestamp.
61 + * @param timestamp to compare agains
62 + * @return true if this instance is newer
63 + */
64 + public boolean isNewer(Timestamp timestamp) {
65 + return this.timestamp.compareTo(checkNotNull(timestamp)) > 0;
53 } 66 }
54 67
55 @Override 68 @Override
......
1 -package org.onlab.onos.store.device.impl;
2 -
3 -import java.util.Collection;
4 -import java.util.HashMap;
5 -import java.util.Map;
6 -
7 -import org.onlab.onos.cluster.NodeId;
8 -import org.onlab.onos.net.Device;
9 -import org.onlab.onos.net.DeviceId;
10 -import org.onlab.onos.store.Timestamp;
11 -import org.onlab.onos.store.VersionedValue;
12 -import org.onlab.onos.store.common.impl.AntiEntropyAdvertisement;
13 -
14 -// TODO DeviceID needs to be changed to something like (ProviderID, DeviceID)
15 -// TODO: Handle Port as part of these messages, or separate messages for Ports?
16 -
17 -public class DeviceAntiEntropyAdvertisement
18 - extends AntiEntropyAdvertisement<DeviceId> {
19 -
20 -
21 - public DeviceAntiEntropyAdvertisement(NodeId sender,
22 - Map<DeviceId, Timestamp> advertisement) {
23 - super(sender, advertisement);
24 - }
25 -
26 - // May need to add ProviderID, etc.
27 - public static DeviceAntiEntropyAdvertisement create(
28 - NodeId self,
29 - Collection<VersionedValue<Device>> localValues) {
30 -
31 - Map<DeviceId, Timestamp> ads = new HashMap<>(localValues.size());
32 - for (VersionedValue<Device> e : localValues) {
33 - ads.put(e.entity().id(), e.timestamp());
34 - }
35 - return new DeviceAntiEntropyAdvertisement(self, ads);
36 - }
37 -
38 - // For serializer
39 - protected DeviceAntiEntropyAdvertisement() {}
40 -}
1 -package org.onlab.onos.store.device.impl;
2 -
3 -import java.util.Collection;
4 -import java.util.HashMap;
5 -import java.util.HashSet;
6 -import java.util.Map;
7 -import java.util.Set;
8 -
9 -import org.onlab.onos.cluster.NodeId;
10 -import org.onlab.onos.net.Device;
11 -import org.onlab.onos.net.DeviceId;
12 -import org.onlab.onos.store.Timestamp;
13 -import org.onlab.onos.store.VersionedValue;
14 -import org.onlab.onos.store.common.impl.AntiEntropyReply;
15 -
16 -import com.google.common.collect.ImmutableMap;
17 -import com.google.common.collect.ImmutableSet;
18 -
19 -public class DeviceAntiEntropyReply
20 - extends AntiEntropyReply<DeviceId, VersionedValue<Device>> {
21 -
22 -
23 - public DeviceAntiEntropyReply(NodeId sender,
24 - Map<DeviceId, VersionedValue<Device>> suggestion,
25 - Set<DeviceId> request) {
26 - super(sender, suggestion, request);
27 - }
28 -
29 - /**
30 - * Creates a reply to Anti-Entropy advertisement.
31 - *
32 - * @param advertisement to respond to
33 - * @param self node identifier representing local node
34 - * @param localValues local values held on this node
35 - * @return reply message
36 - */
37 - public static DeviceAntiEntropyReply reply(
38 - DeviceAntiEntropyAdvertisement advertisement,
39 - NodeId self,
40 - Collection<VersionedValue<Device>> localValues
41 - ) {
42 -
43 - ImmutableMap<DeviceId, Timestamp> ads = advertisement.advertisement();
44 -
45 - ImmutableMap.Builder<DeviceId, VersionedValue<Device>>
46 - sug = ImmutableMap.builder();
47 -
48 - Set<DeviceId> req = new HashSet<>(ads.keySet());
49 -
50 - for (VersionedValue<Device> e : localValues) {
51 - final DeviceId id = e.entity().id();
52 - final Timestamp local = e.timestamp();
53 - final Timestamp theirs = ads.get(id);
54 - if (theirs == null) {
55 - // they don't have it, suggest
56 - sug.put(id, e);
57 - // don't need theirs
58 - req.remove(id);
59 - } else if (local.compareTo(theirs) < 0) {
60 - // they got older one, suggest
61 - sug.put(id, e);
62 - // don't need theirs
63 - req.remove(id);
64 - } else if (local.equals(theirs)) {
65 - // same, don't need theirs
66 - req.remove(id);
67 - }
68 - }
69 -
70 - return new DeviceAntiEntropyReply(self, sug.build(), req);
71 - }
72 -
73 - /**
74 - * Creates a reply to request for values held locally.
75 - *
76 - * @param requests message containing the request
77 - * @param self node identifier representing local node
78 - * @param localValues local valeds held on this node
79 - * @return reply message
80 - */
81 - public static DeviceAntiEntropyReply reply(
82 - DeviceAntiEntropyReply requests,
83 - NodeId self,
84 - Map<DeviceId, VersionedValue<Device>> localValues
85 - ) {
86 -
87 - Set<DeviceId> reqs = requests.request();
88 -
89 - Map<DeviceId, VersionedValue<Device>> requested = new HashMap<>(reqs.size());
90 - for (DeviceId id : reqs) {
91 - final VersionedValue<Device> value = localValues.get(id);
92 - if (value != null) {
93 - requested.put(id, value);
94 - }
95 - }
96 -
97 - Set<DeviceId> empty = ImmutableSet.of();
98 - return new DeviceAntiEntropyReply(self, requested, empty);
99 - }
100 -
101 - // For serializer
102 - protected DeviceAntiEntropyReply() {}
103 -}
...@@ -10,12 +10,12 @@ import org.apache.felix.scr.annotations.Activate; ...@@ -10,12 +10,12 @@ import org.apache.felix.scr.annotations.Activate;
10 import org.apache.felix.scr.annotations.Component; 10 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.Service; 12 import org.apache.felix.scr.annotations.Service;
13 +import org.onlab.onos.cluster.MastershipTerm;
13 import org.onlab.onos.net.DeviceId; 14 import org.onlab.onos.net.DeviceId;
14 -import org.onlab.onos.net.device.DeviceMastershipTerm;
15 import org.onlab.onos.store.ClockProviderService; 15 import org.onlab.onos.store.ClockProviderService;
16 import org.onlab.onos.store.ClockService; 16 import org.onlab.onos.store.ClockService;
17 import org.onlab.onos.store.Timestamp; 17 import org.onlab.onos.store.Timestamp;
18 -import org.onlab.onos.store.common.impl.DeviceMastershipBasedTimestamp; 18 +import org.onlab.onos.store.common.impl.MastershipBasedTimestamp;
19 import org.slf4j.Logger; 19 import org.slf4j.Logger;
20 20
21 /** 21 /**
...@@ -29,7 +29,7 @@ public class DeviceClockManager implements ClockService, ClockProviderService { ...@@ -29,7 +29,7 @@ public class DeviceClockManager implements ClockService, ClockProviderService {
29 29
30 // TODO: Implement per device ticker that is reset to 0 at the beginning of a new term. 30 // TODO: Implement per device ticker that is reset to 0 at the beginning of a new term.
31 private final AtomicInteger ticker = new AtomicInteger(0); 31 private final AtomicInteger ticker = new AtomicInteger(0);
32 - private ConcurrentMap<DeviceId, DeviceMastershipTerm> deviceMastershipTerms = new ConcurrentHashMap<>(); 32 + private ConcurrentMap<DeviceId, MastershipTerm> deviceMastershipTerms = new ConcurrentHashMap<>();
33 33
34 @Activate 34 @Activate
35 public void activate() { 35 public void activate() {
...@@ -43,15 +43,15 @@ public class DeviceClockManager implements ClockService, ClockProviderService { ...@@ -43,15 +43,15 @@ public class DeviceClockManager implements ClockService, ClockProviderService {
43 43
44 @Override 44 @Override
45 public Timestamp getTimestamp(DeviceId deviceId) { 45 public Timestamp getTimestamp(DeviceId deviceId) {
46 - DeviceMastershipTerm term = deviceMastershipTerms.get(deviceId); 46 + MastershipTerm term = deviceMastershipTerms.get(deviceId);
47 if (term == null) { 47 if (term == null) {
48 throw new IllegalStateException("Requesting timestamp for a deviceId without mastership"); 48 throw new IllegalStateException("Requesting timestamp for a deviceId without mastership");
49 } 49 }
50 - return new DeviceMastershipBasedTimestamp(term.termNumber(), ticker.incrementAndGet()); 50 + return new MastershipBasedTimestamp(term.termNumber(), ticker.incrementAndGet());
51 } 51 }
52 52
53 @Override 53 @Override
54 - public void setMastershipTerm(DeviceId deviceId, DeviceMastershipTerm term) { 54 + public void setMastershipTerm(DeviceId deviceId, MastershipTerm term) {
55 deviceMastershipTerms.put(deviceId, term); 55 deviceMastershipTerms.put(deviceId, term);
56 } 56 }
57 } 57 }
......
1 +package org.onlab.onos.store.device.impl;
2 +
3 +import static com.google.common.base.Preconditions.checkNotNull;
4 +import static org.onlab.onos.net.DefaultAnnotations.union;
5 +
6 +import java.util.Collections;
7 +import java.util.Map;
8 +import java.util.concurrent.ConcurrentHashMap;
9 +import java.util.concurrent.ConcurrentMap;
10 +
11 +import org.onlab.onos.net.PortNumber;
12 +import org.onlab.onos.net.SparseAnnotations;
13 +import org.onlab.onos.net.device.DefaultDeviceDescription;
14 +import org.onlab.onos.net.device.DefaultPortDescription;
15 +import org.onlab.onos.net.device.DeviceDescription;
16 +import org.onlab.onos.net.device.PortDescription;
17 +import org.onlab.onos.store.Timestamp;
18 +import org.onlab.onos.store.common.impl.Timestamped;
19 +
20 +/*
21 + * Collection of Description of a Device and Ports, given from a Provider.
22 + */
23 +class DeviceDescriptions {
24 +
25 + private volatile Timestamped<DeviceDescription> deviceDesc;
26 +
27 + private final ConcurrentMap<PortNumber, Timestamped<PortDescription>> portDescs;
28 +
29 + public DeviceDescriptions(Timestamped<DeviceDescription> desc) {
30 + this.deviceDesc = checkNotNull(desc);
31 + this.portDescs = new ConcurrentHashMap<>();
32 + }
33 +
34 + public Timestamp getLatestTimestamp() {
35 + Timestamp latest = deviceDesc.timestamp();
36 + for (Timestamped<PortDescription> desc : portDescs.values()) {
37 + if (desc.timestamp().compareTo(latest) > 0) {
38 + latest = desc.timestamp();
39 + }
40 + }
41 + return latest;
42 + }
43 +
44 + public Timestamped<DeviceDescription> getDeviceDesc() {
45 + return deviceDesc;
46 + }
47 +
48 + public Timestamped<PortDescription> getPortDesc(PortNumber number) {
49 + return portDescs.get(number);
50 + }
51 +
52 + public Map<PortNumber, Timestamped<PortDescription>> getPortDescs() {
53 + return Collections.unmodifiableMap(portDescs);
54 + }
55 +
56 + /**
57 + * Puts DeviceDescription, merging annotations as necessary.
58 + *
59 + * @param newDesc new DeviceDescription
60 + */
61 + public synchronized void putDeviceDesc(Timestamped<DeviceDescription> newDesc) {
62 + Timestamped<DeviceDescription> oldOne = deviceDesc;
63 + Timestamped<DeviceDescription> newOne = newDesc;
64 + if (oldOne != null) {
65 + SparseAnnotations merged = union(oldOne.value().annotations(),
66 + newDesc.value().annotations());
67 + newOne = new Timestamped<DeviceDescription>(
68 + new DefaultDeviceDescription(newDesc.value(), merged),
69 + newDesc.timestamp());
70 + }
71 + deviceDesc = newOne;
72 + }
73 +
74 + /**
75 + * Puts PortDescription, merging annotations as necessary.
76 + *
77 + * @param newDesc new PortDescription
78 + */
79 + public synchronized void putPortDesc(Timestamped<PortDescription> newDesc) {
80 + Timestamped<PortDescription> oldOne = portDescs.get(newDesc.value().portNumber());
81 + Timestamped<PortDescription> newOne = newDesc;
82 + if (oldOne != null) {
83 + SparseAnnotations merged = union(oldOne.value().annotations(),
84 + newDesc.value().annotations());
85 + newOne = new Timestamped<PortDescription>(
86 + new DefaultPortDescription(newDesc.value(), merged),
87 + newDesc.timestamp());
88 + }
89 + portDescs.put(newOne.value().portNumber(), newOne);
90 + }
91 +}
...@@ -2,6 +2,7 @@ package org.onlab.onos.store.device.impl; ...@@ -2,6 +2,7 @@ package org.onlab.onos.store.device.impl;
2 2
3 import org.onlab.onos.store.cluster.messaging.MessageSubject; 3 import org.onlab.onos.store.cluster.messaging.MessageSubject;
4 4
5 +// TODO: add prefix to assure uniqueness.
5 /** 6 /**
6 * MessageSubjects used by GossipDeviceStore peer-peer communication. 7 * MessageSubjects used by GossipDeviceStore peer-peer communication.
7 */ 8 */
...@@ -14,4 +15,8 @@ public final class GossipDeviceStoreMessageSubjects { ...@@ -14,4 +15,8 @@ public final class GossipDeviceStoreMessageSubjects {
14 public static final MessageSubject DEVICE_REMOVED = new MessageSubject("peer-device-removed"); 15 public static final MessageSubject DEVICE_REMOVED = new MessageSubject("peer-device-removed");
15 public static final MessageSubject PORT_UPDATE = new MessageSubject("peer-port-update"); 16 public static final MessageSubject PORT_UPDATE = new MessageSubject("peer-port-update");
16 public static final MessageSubject PORT_STATUS_UPDATE = new MessageSubject("peer-port-status-update"); 17 public static final MessageSubject PORT_STATUS_UPDATE = new MessageSubject("peer-port-status-update");
18 +
19 + public static final MessageSubject DEVICE_ADVERTISE = new MessageSubject("peer-device-advertisements");
20 + // to be used with 3-way anti-entropy process
21 + public static final MessageSubject DEVICE_REQUEST = new MessageSubject("peer-device-request");
17 } 22 }
......
1 +package org.onlab.onos.store.device.impl;
2 +
3 +import static com.google.common.base.Preconditions.checkNotNull;
4 +
5 +import org.apache.commons.lang3.concurrent.ConcurrentException;
6 +import org.apache.commons.lang3.concurrent.ConcurrentInitializer;
7 +import org.onlab.onos.net.device.DeviceDescription;
8 +import org.onlab.onos.store.common.impl.Timestamped;
9 +
10 +// FIXME: consider removing this class
11 +public final class InitDeviceDescs
12 + implements ConcurrentInitializer<DeviceDescriptions> {
13 +
14 + private final Timestamped<DeviceDescription> deviceDesc;
15 +
16 + public InitDeviceDescs(Timestamped<DeviceDescription> deviceDesc) {
17 + this.deviceDesc = checkNotNull(deviceDesc);
18 + }
19 + @Override
20 + public DeviceDescriptions get() throws ConcurrentException {
21 + return new DeviceDescriptions(deviceDesc);
22 + }
23 +}
...\ No newline at end of file ...\ No newline at end of file
...@@ -3,7 +3,9 @@ package org.onlab.onos.store.device.impl; ...@@ -3,7 +3,9 @@ package org.onlab.onos.store.device.impl;
3 import org.onlab.onos.net.DeviceId; 3 import org.onlab.onos.net.DeviceId;
4 import org.onlab.onos.net.device.DeviceDescription; 4 import org.onlab.onos.net.device.DeviceDescription;
5 import org.onlab.onos.net.provider.ProviderId; 5 import org.onlab.onos.net.provider.ProviderId;
6 -import org.onlab.onos.store.Timestamped; 6 +import org.onlab.onos.store.common.impl.Timestamped;
7 +
8 +import com.google.common.base.MoreObjects;
7 9
8 /** 10 /**
9 * Information published by GossipDeviceStore to notify peers of a device 11 * Information published by GossipDeviceStore to notify peers of a device
...@@ -36,6 +38,15 @@ public class InternalDeviceEvent { ...@@ -36,6 +38,15 @@ public class InternalDeviceEvent {
36 return deviceDescription; 38 return deviceDescription;
37 } 39 }
38 40
41 + @Override
42 + public String toString() {
43 + return MoreObjects.toStringHelper(getClass())
44 + .add("providerId", providerId)
45 + .add("deviceId", deviceId)
46 + .add("deviceDescription", deviceDescription)
47 + .toString();
48 + }
49 +
39 // for serializer 50 // for serializer
40 protected InternalDeviceEvent() { 51 protected InternalDeviceEvent() {
41 this.providerId = null; 52 this.providerId = null;
......
...@@ -3,7 +3,7 @@ package org.onlab.onos.store.device.impl; ...@@ -3,7 +3,7 @@ package org.onlab.onos.store.device.impl;
3 import org.onlab.onos.net.DeviceId; 3 import org.onlab.onos.net.DeviceId;
4 import org.onlab.onos.net.device.DeviceDescription; 4 import org.onlab.onos.net.device.DeviceDescription;
5 import org.onlab.onos.net.provider.ProviderId; 5 import org.onlab.onos.net.provider.ProviderId;
6 -import org.onlab.onos.store.Timestamped; 6 +import org.onlab.onos.store.common.impl.Timestamped;
7 7
8 import com.esotericsoftware.kryo.Kryo; 8 import com.esotericsoftware.kryo.Kryo;
9 import com.esotericsoftware.kryo.Serializer; 9 import com.esotericsoftware.kryo.Serializer;
......
...@@ -3,6 +3,8 @@ package org.onlab.onos.store.device.impl; ...@@ -3,6 +3,8 @@ package org.onlab.onos.store.device.impl;
3 import org.onlab.onos.net.DeviceId; 3 import org.onlab.onos.net.DeviceId;
4 import org.onlab.onos.store.Timestamp; 4 import org.onlab.onos.store.Timestamp;
5 5
6 +import com.google.common.base.MoreObjects;
7 +
6 /** 8 /**
7 * Information published by GossipDeviceStore to notify peers of a device 9 * Information published by GossipDeviceStore to notify peers of a device
8 * going offline. 10 * going offline.
...@@ -30,6 +32,14 @@ public class InternalDeviceOfflineEvent { ...@@ -30,6 +32,14 @@ public class InternalDeviceOfflineEvent {
30 return timestamp; 32 return timestamp;
31 } 33 }
32 34
35 + @Override
36 + public String toString() {
37 + return MoreObjects.toStringHelper(getClass())
38 + .add("deviceId", deviceId)
39 + .add("timestamp", timestamp)
40 + .toString();
41 + }
42 +
33 // for serializer 43 // for serializer
34 @SuppressWarnings("unused") 44 @SuppressWarnings("unused")
35 private InternalDeviceOfflineEvent() { 45 private InternalDeviceOfflineEvent() {
......
...@@ -3,6 +3,8 @@ package org.onlab.onos.store.device.impl; ...@@ -3,6 +3,8 @@ package org.onlab.onos.store.device.impl;
3 import org.onlab.onos.net.DeviceId; 3 import org.onlab.onos.net.DeviceId;
4 import org.onlab.onos.store.Timestamp; 4 import org.onlab.onos.store.Timestamp;
5 5
6 +import com.google.common.base.MoreObjects;
7 +
6 /** 8 /**
7 * Information published by GossipDeviceStore to notify peers of a device 9 * Information published by GossipDeviceStore to notify peers of a device
8 * being administratively removed. 10 * being administratively removed.
...@@ -30,6 +32,14 @@ public class InternalDeviceRemovedEvent { ...@@ -30,6 +32,14 @@ public class InternalDeviceRemovedEvent {
30 return timestamp; 32 return timestamp;
31 } 33 }
32 34
35 + @Override
36 + public String toString() {
37 + return MoreObjects.toStringHelper(getClass())
38 + .add("deviceId", deviceId)
39 + .add("timestamp", timestamp)
40 + .toString();
41 + }
42 +
33 // for serializer 43 // for serializer
34 @SuppressWarnings("unused") 44 @SuppressWarnings("unused")
35 private InternalDeviceRemovedEvent() { 45 private InternalDeviceRemovedEvent() {
......
...@@ -5,7 +5,9 @@ import java.util.List; ...@@ -5,7 +5,9 @@ import java.util.List;
5 import org.onlab.onos.net.DeviceId; 5 import org.onlab.onos.net.DeviceId;
6 import org.onlab.onos.net.device.PortDescription; 6 import org.onlab.onos.net.device.PortDescription;
7 import org.onlab.onos.net.provider.ProviderId; 7 import org.onlab.onos.net.provider.ProviderId;
8 -import org.onlab.onos.store.Timestamped; 8 +import org.onlab.onos.store.common.impl.Timestamped;
9 +
10 +import com.google.common.base.MoreObjects;
9 11
10 /** 12 /**
11 * Information published by GossipDeviceStore to notify peers of a port 13 * Information published by GossipDeviceStore to notify peers of a port
...@@ -38,6 +40,15 @@ public class InternalPortEvent { ...@@ -38,6 +40,15 @@ public class InternalPortEvent {
38 return portDescriptions; 40 return portDescriptions;
39 } 41 }
40 42
43 + @Override
44 + public String toString() {
45 + return MoreObjects.toStringHelper(getClass())
46 + .add("providerId", providerId)
47 + .add("deviceId", deviceId)
48 + .add("portDescriptions", portDescriptions)
49 + .toString();
50 + }
51 +
41 // for serializer 52 // for serializer
42 protected InternalPortEvent() { 53 protected InternalPortEvent() {
43 this.providerId = null; 54 this.providerId = null;
......
...@@ -5,7 +5,7 @@ import java.util.List; ...@@ -5,7 +5,7 @@ import java.util.List;
5 import org.onlab.onos.net.DeviceId; 5 import org.onlab.onos.net.DeviceId;
6 import org.onlab.onos.net.device.PortDescription; 6 import org.onlab.onos.net.device.PortDescription;
7 import org.onlab.onos.net.provider.ProviderId; 7 import org.onlab.onos.net.provider.ProviderId;
8 -import org.onlab.onos.store.Timestamped; 8 +import org.onlab.onos.store.common.impl.Timestamped;
9 9
10 import com.esotericsoftware.kryo.Kryo; 10 import com.esotericsoftware.kryo.Kryo;
11 import com.esotericsoftware.kryo.Serializer; 11 import com.esotericsoftware.kryo.Serializer;
......
...@@ -3,7 +3,9 @@ package org.onlab.onos.store.device.impl; ...@@ -3,7 +3,9 @@ package org.onlab.onos.store.device.impl;
3 import org.onlab.onos.net.DeviceId; 3 import org.onlab.onos.net.DeviceId;
4 import org.onlab.onos.net.device.PortDescription; 4 import org.onlab.onos.net.device.PortDescription;
5 import org.onlab.onos.net.provider.ProviderId; 5 import org.onlab.onos.net.provider.ProviderId;
6 -import org.onlab.onos.store.Timestamped; 6 +import org.onlab.onos.store.common.impl.Timestamped;
7 +
8 +import com.google.common.base.MoreObjects;
7 9
8 /** 10 /**
9 * Information published by GossipDeviceStore to notify peers of a port 11 * Information published by GossipDeviceStore to notify peers of a port
...@@ -36,6 +38,15 @@ public class InternalPortStatusEvent { ...@@ -36,6 +38,15 @@ public class InternalPortStatusEvent {
36 return portDescription; 38 return portDescription;
37 } 39 }
38 40
41 + @Override
42 + public String toString() {
43 + return MoreObjects.toStringHelper(getClass())
44 + .add("providerId", providerId)
45 + .add("deviceId", deviceId)
46 + .add("portDescription", portDescription)
47 + .toString();
48 + }
49 +
39 // for serializer 50 // for serializer
40 protected InternalPortStatusEvent() { 51 protected InternalPortStatusEvent() {
41 this.providerId = null; 52 this.providerId = null;
......
...@@ -3,7 +3,7 @@ package org.onlab.onos.store.device.impl; ...@@ -3,7 +3,7 @@ package org.onlab.onos.store.device.impl;
3 import org.onlab.onos.net.DeviceId; 3 import org.onlab.onos.net.DeviceId;
4 import org.onlab.onos.net.device.PortDescription; 4 import org.onlab.onos.net.device.PortDescription;
5 import org.onlab.onos.net.provider.ProviderId; 5 import org.onlab.onos.net.provider.ProviderId;
6 -import org.onlab.onos.store.Timestamped; 6 +import org.onlab.onos.store.common.impl.Timestamped;
7 7
8 import com.esotericsoftware.kryo.Kryo; 8 import com.esotericsoftware.kryo.Kryo;
9 import com.esotericsoftware.kryo.Serializer; 9 import com.esotericsoftware.kryo.Serializer;
...@@ -35,6 +35,7 @@ public class InternalPortStatusEventSerializer extends Serializer<InternalPortSt ...@@ -35,6 +35,7 @@ public class InternalPortStatusEventSerializer extends Serializer<InternalPortSt
35 Class<InternalPortStatusEvent> type) { 35 Class<InternalPortStatusEvent> type) {
36 ProviderId providerId = (ProviderId) kryo.readClassAndObject(input); 36 ProviderId providerId = (ProviderId) kryo.readClassAndObject(input);
37 DeviceId deviceId = (DeviceId) kryo.readClassAndObject(input); 37 DeviceId deviceId = (DeviceId) kryo.readClassAndObject(input);
38 + @SuppressWarnings("unchecked")
38 Timestamped<PortDescription> portDescription = (Timestamped<PortDescription>) kryo.readClassAndObject(input); 39 Timestamped<PortDescription> portDescription = (Timestamped<PortDescription>) kryo.readClassAndObject(input);
39 40
40 return new InternalPortStatusEvent(providerId, deviceId, portDescription); 41 return new InternalPortStatusEvent(providerId, deviceId, portDescription);
......
1 +package org.onlab.onos.store.device.impl.peermsg;
2 +
3 +import static com.google.common.base.Preconditions.checkNotNull;
4 +
5 +import java.util.Map;
6 +
7 +import org.onlab.onos.cluster.NodeId;
8 +import org.onlab.onos.net.DeviceId;
9 +import org.onlab.onos.store.Timestamp;
10 +
11 +
12 +/**
13 + * Device Advertisement message.
14 + */
15 +public class DeviceAntiEntropyAdvertisement {
16 +
17 + private final NodeId sender;
18 + private final Map<DeviceFragmentId, Timestamp> deviceFingerPrints;
19 + private final Map<PortFragmentId, Timestamp> portFingerPrints;
20 + private final Map<DeviceId, Timestamp> offline;
21 +
22 +
23 + public DeviceAntiEntropyAdvertisement(NodeId sender,
24 + Map<DeviceFragmentId, Timestamp> devices,
25 + Map<PortFragmentId, Timestamp> ports,
26 + Map<DeviceId, Timestamp> offline) {
27 + this.sender = checkNotNull(sender);
28 + this.deviceFingerPrints = checkNotNull(devices);
29 + this.portFingerPrints = checkNotNull(ports);
30 + this.offline = checkNotNull(offline);
31 + }
32 +
33 + public NodeId sender() {
34 + return sender;
35 + }
36 +
37 + public Map<DeviceFragmentId, Timestamp> deviceFingerPrints() {
38 + return deviceFingerPrints;
39 + }
40 +
41 + public Map<PortFragmentId, Timestamp> ports() {
42 + return portFingerPrints;
43 + }
44 +
45 + public Map<DeviceId, Timestamp> offline() {
46 + return offline;
47 + }
48 +
49 + // For serializer
50 + @SuppressWarnings("unused")
51 + private DeviceAntiEntropyAdvertisement() {
52 + this.sender = null;
53 + this.deviceFingerPrints = null;
54 + this.portFingerPrints = null;
55 + this.offline = null;
56 + }
57 +}
1 +package org.onlab.onos.store.device.impl.peermsg;
2 +
3 +import static com.google.common.base.Preconditions.checkNotNull;
4 +
5 +import java.util.Collection;
6 +
7 +import org.onlab.onos.cluster.NodeId;
8 +
9 +/**
10 + * Message to request for other peers information.
11 + */
12 +public class DeviceAntiEntropyRequest {
13 +
14 + private final NodeId sender;
15 + private final Collection<DeviceFragmentId> devices;
16 + private final Collection<PortFragmentId> ports;
17 +
18 + public DeviceAntiEntropyRequest(NodeId sender,
19 + Collection<DeviceFragmentId> devices,
20 + Collection<PortFragmentId> ports) {
21 +
22 + this.sender = checkNotNull(sender);
23 + this.devices = checkNotNull(devices);
24 + this.ports = checkNotNull(ports);
25 + }
26 +
27 + public NodeId sender() {
28 + return sender;
29 + }
30 +
31 + public Collection<DeviceFragmentId> devices() {
32 + return devices;
33 + }
34 +
35 + public Collection<PortFragmentId> ports() {
36 + return ports;
37 + }
38 +
39 + // For serializer
40 + @SuppressWarnings("unused")
41 + private DeviceAntiEntropyRequest() {
42 + this.sender = null;
43 + this.devices = null;
44 + this.ports = null;
45 + }
46 +}
1 +package org.onlab.onos.store.device.impl.peermsg;
2 +
3 +import java.util.Objects;
4 +
5 +import org.onlab.onos.net.DeviceId;
6 +import org.onlab.onos.net.provider.ProviderId;
7 +
8 +import com.google.common.base.MoreObjects;
9 +
10 +/**
11 + * Identifier for DeviceDesctiption from a Provider.
12 + */
13 +public final class DeviceFragmentId {
14 + public final ProviderId providerId;
15 + public final DeviceId deviceId;
16 +
17 + public DeviceFragmentId(DeviceId deviceId, ProviderId providerId) {
18 + this.providerId = providerId;
19 + this.deviceId = deviceId;
20 + }
21 +
22 + @Override
23 + public int hashCode() {
24 + return Objects.hash(providerId, deviceId);
25 + }
26 +
27 + @Override
28 + public boolean equals(Object obj) {
29 + if (this == obj) {
30 + return true;
31 + }
32 + if (!(obj instanceof DeviceFragmentId)) {
33 + return false;
34 + }
35 + DeviceFragmentId that = (DeviceFragmentId) obj;
36 + return Objects.equals(this.deviceId, that.deviceId) &&
37 + Objects.equals(this.providerId, that.providerId);
38 + }
39 +
40 + @Override
41 + public String toString() {
42 + return MoreObjects.toStringHelper(getClass())
43 + .add("providerId", providerId)
44 + .add("deviceId", deviceId)
45 + .toString();
46 + }
47 +
48 + // for serializer
49 + @SuppressWarnings("unused")
50 + private DeviceFragmentId() {
51 + this.providerId = null;
52 + this.deviceId = null;
53 + }
54 +}
...\ No newline at end of file ...\ No newline at end of file
1 +package org.onlab.onos.store.device.impl.peermsg;
2 +
3 +import java.util.Objects;
4 +
5 +import org.onlab.onos.net.DeviceId;
6 +import org.onlab.onos.net.PortNumber;
7 +import org.onlab.onos.net.provider.ProviderId;
8 +
9 +import com.google.common.base.MoreObjects;
10 +
11 +/**
12 + * Identifier for PortDescription from a Provider.
13 + */
14 +public final class PortFragmentId {
15 + public final ProviderId providerId;
16 + public final DeviceId deviceId;
17 + public final PortNumber portNumber;
18 +
19 + public PortFragmentId(DeviceId deviceId, ProviderId providerId,
20 + PortNumber portNumber) {
21 + this.providerId = providerId;
22 + this.deviceId = deviceId;
23 + this.portNumber = portNumber;
24 + }
25 +
26 + @Override
27 + public int hashCode() {
28 + return Objects.hash(providerId, deviceId, portNumber);
29 + };
30 +
31 + @Override
32 + public boolean equals(Object obj) {
33 + if (this == obj) {
34 + return true;
35 + }
36 + if (!(obj instanceof PortFragmentId)) {
37 + return false;
38 + }
39 + PortFragmentId that = (PortFragmentId) obj;
40 + return Objects.equals(this.deviceId, that.deviceId) &&
41 + Objects.equals(this.portNumber, that.portNumber) &&
42 + Objects.equals(this.providerId, that.providerId);
43 + }
44 +
45 + @Override
46 + public String toString() {
47 + return MoreObjects.toStringHelper(getClass())
48 + .add("providerId", providerId)
49 + .add("deviceId", deviceId)
50 + .add("portNumber", portNumber)
51 + .toString();
52 + }
53 +
54 + // for serializer
55 + @SuppressWarnings("unused")
56 + private PortFragmentId() {
57 + this.providerId = null;
58 + this.deviceId = null;
59 + this.portNumber = null;
60 + }
61 +}
...\ No newline at end of file ...\ No newline at end of file
1 +/**
2 + * Structure and utilities used for inter-Node messaging.
3 + */
4 +package org.onlab.onos.store.device.impl.peermsg;
1 package org.onlab.onos.store.host.impl; 1 package org.onlab.onos.store.host.impl;
2 2
3 -import static org.onlab.onos.net.host.HostEvent.Type.HOST_ADDED; 3 +import com.google.common.collect.HashMultimap;
4 -import static org.onlab.onos.net.host.HostEvent.Type.HOST_MOVED; 4 +import com.google.common.collect.ImmutableSet;
5 -import static org.onlab.onos.net.host.HostEvent.Type.HOST_REMOVED; 5 +import com.google.common.collect.Multimap;
6 -import static org.onlab.onos.net.host.HostEvent.Type.HOST_UPDATED; 6 +import com.google.common.collect.Sets;
7 -import static org.slf4j.LoggerFactory.getLogger;
8 -
9 -import java.util.Collections;
10 -import java.util.HashSet;
11 -import java.util.Map;
12 -import java.util.Set;
13 -import java.util.concurrent.ConcurrentHashMap;
14 -
15 import org.apache.felix.scr.annotations.Activate; 7 import org.apache.felix.scr.annotations.Activate;
16 import org.apache.felix.scr.annotations.Component; 8 import org.apache.felix.scr.annotations.Component;
17 import org.apache.felix.scr.annotations.Deactivate; 9 import org.apache.felix.scr.annotations.Deactivate;
18 import org.apache.felix.scr.annotations.Service; 10 import org.apache.felix.scr.annotations.Service;
11 +import org.onlab.onos.net.Annotations;
19 import org.onlab.onos.net.ConnectPoint; 12 import org.onlab.onos.net.ConnectPoint;
20 import org.onlab.onos.net.DefaultHost; 13 import org.onlab.onos.net.DefaultHost;
21 import org.onlab.onos.net.DeviceId; 14 import org.onlab.onos.net.DeviceId;
22 import org.onlab.onos.net.Host; 15 import org.onlab.onos.net.Host;
23 import org.onlab.onos.net.HostId; 16 import org.onlab.onos.net.HostId;
17 +import org.onlab.onos.net.HostLocation;
24 import org.onlab.onos.net.host.HostDescription; 18 import org.onlab.onos.net.host.HostDescription;
25 import org.onlab.onos.net.host.HostEvent; 19 import org.onlab.onos.net.host.HostEvent;
26 import org.onlab.onos.net.host.HostStore; 20 import org.onlab.onos.net.host.HostStore;
...@@ -33,10 +27,13 @@ import org.onlab.packet.MacAddress; ...@@ -33,10 +27,13 @@ import org.onlab.packet.MacAddress;
33 import org.onlab.packet.VlanId; 27 import org.onlab.packet.VlanId;
34 import org.slf4j.Logger; 28 import org.slf4j.Logger;
35 29
36 -import com.google.common.collect.HashMultimap; 30 +import java.util.HashSet;
37 -import com.google.common.collect.ImmutableSet; 31 +import java.util.Map;
38 -import com.google.common.collect.Multimap; 32 +import java.util.Set;
39 -import com.google.common.collect.Sets; 33 +import java.util.concurrent.ConcurrentHashMap;
34 +
35 +import static org.onlab.onos.net.host.HostEvent.Type.*;
36 +import static org.slf4j.LoggerFactory.getLogger;
40 37
41 /** 38 /**
42 * Manages inventory of end-station hosts using trivial in-memory 39 * Manages inventory of end-station hosts using trivial in-memory
...@@ -46,13 +43,13 @@ import com.google.common.collect.Sets; ...@@ -46,13 +43,13 @@ import com.google.common.collect.Sets;
46 @Component(immediate = true) 43 @Component(immediate = true)
47 @Service 44 @Service
48 public class DistributedHostStore 45 public class DistributedHostStore
49 -extends AbstractStore<HostEvent, HostStoreDelegate> 46 + extends AbstractStore<HostEvent, HostStoreDelegate>
50 -implements HostStore { 47 + implements HostStore {
51 48
52 private final Logger log = getLogger(getClass()); 49 private final Logger log = getLogger(getClass());
53 50
54 // Host inventory 51 // Host inventory
55 - private final Map<HostId, Host> hosts = new ConcurrentHashMap<>(); 52 + private final Map<HostId, StoredHost> hosts = new ConcurrentHashMap<>(2000000, 0.75f, 16);
56 53
57 // Hosts tracked by their location 54 // Hosts tracked by their location
58 private final Multimap<ConnectPoint, Host> locations = HashMultimap.create(); 55 private final Multimap<ConnectPoint, Host> locations = HashMultimap.create();
...@@ -73,7 +70,7 @@ implements HostStore { ...@@ -73,7 +70,7 @@ implements HostStore {
73 @Override 70 @Override
74 public HostEvent createOrUpdateHost(ProviderId providerId, HostId hostId, 71 public HostEvent createOrUpdateHost(ProviderId providerId, HostId hostId,
75 HostDescription hostDescription) { 72 HostDescription hostDescription) {
76 - Host host = hosts.get(hostId); 73 + StoredHost host = hosts.get(hostId);
77 if (host == null) { 74 if (host == null) {
78 return createHost(providerId, hostId, hostDescription); 75 return createHost(providerId, hostId, hostDescription);
79 } 76 }
...@@ -83,11 +80,11 @@ implements HostStore { ...@@ -83,11 +80,11 @@ implements HostStore {
83 // creates a new host and sends HOST_ADDED 80 // creates a new host and sends HOST_ADDED
84 private HostEvent createHost(ProviderId providerId, HostId hostId, 81 private HostEvent createHost(ProviderId providerId, HostId hostId,
85 HostDescription descr) { 82 HostDescription descr) {
86 - DefaultHost newhost = new DefaultHost(providerId, hostId, 83 + StoredHost newhost = new StoredHost(providerId, hostId,
87 descr.hwAddress(), 84 descr.hwAddress(),
88 descr.vlan(), 85 descr.vlan(),
89 descr.location(), 86 descr.location(),
90 - descr.ipAddresses()); 87 + ImmutableSet.of(descr.ipAddress()));
91 synchronized (this) { 88 synchronized (this) {
92 hosts.put(hostId, newhost); 89 hosts.put(hostId, newhost);
93 locations.put(descr.location(), newhost); 90 locations.put(descr.location(), newhost);
...@@ -96,28 +93,24 @@ implements HostStore { ...@@ -96,28 +93,24 @@ implements HostStore {
96 } 93 }
97 94
98 // checks for type of update to host, sends appropriate event 95 // checks for type of update to host, sends appropriate event
99 - private HostEvent updateHost(ProviderId providerId, Host host, 96 + private HostEvent updateHost(ProviderId providerId, StoredHost host,
100 HostDescription descr) { 97 HostDescription descr) {
101 - DefaultHost updated;
102 HostEvent event; 98 HostEvent event;
103 if (!host.location().equals(descr.location())) { 99 if (!host.location().equals(descr.location())) {
104 - updated = new DefaultHost(providerId, host.id(), 100 + host.setLocation(descr.location());
105 - host.mac(), 101 + return new HostEvent(HOST_MOVED, host);
106 - host.vlan(), 102 + }
107 - descr.location(),
108 - host.ipAddresses());
109 - event = new HostEvent(HOST_MOVED, updated);
110 103
111 - } else if (!(host.ipAddresses().equals(descr.ipAddresses()))) { 104 + if (host.ipAddresses().contains(descr.ipAddress())) {
112 - updated = new DefaultHost(providerId, host.id(),
113 - host.mac(),
114 - host.vlan(),
115 - descr.location(),
116 - descr.ipAddresses());
117 - event = new HostEvent(HOST_UPDATED, updated);
118 - } else {
119 return null; 105 return null;
120 } 106 }
107 +
108 + Set<IpPrefix> addresses = new HashSet<>(host.ipAddresses());
109 + addresses.add(descr.ipAddress());
110 + StoredHost updated = new StoredHost(providerId, host.id(),
111 + host.mac(), host.vlan(),
112 + descr.location(), addresses);
113 + event = new HostEvent(HOST_UPDATED, updated);
121 synchronized (this) { 114 synchronized (this) {
122 hosts.put(host.id(), updated); 115 hosts.put(host.id(), updated);
123 locations.remove(host.location(), host); 116 locations.remove(host.location(), host);
...@@ -145,7 +138,7 @@ implements HostStore { ...@@ -145,7 +138,7 @@ implements HostStore {
145 138
146 @Override 139 @Override
147 public Iterable<Host> getHosts() { 140 public Iterable<Host> getHosts() {
148 - return Collections.unmodifiableSet(new HashSet<>(hosts.values())); 141 + return ImmutableSet.<Host>copyOf(hosts.values());
149 } 142 }
150 143
151 @Override 144 @Override
...@@ -275,4 +268,35 @@ implements HostStore { ...@@ -275,4 +268,35 @@ implements HostStore {
275 return addresses; 268 return addresses;
276 } 269 }
277 270
271 + // Auxiliary extension to allow location to mutate.
272 + private class StoredHost extends DefaultHost {
273 + private HostLocation location;
274 +
275 + /**
276 + * Creates an end-station host using the supplied information.
277 + *
278 + * @param providerId provider identity
279 + * @param id host identifier
280 + * @param mac host MAC address
281 + * @param vlan host VLAN identifier
282 + * @param location host location
283 + * @param ips host IP addresses
284 + * @param annotations optional key/value annotations
285 + */
286 + public StoredHost(ProviderId providerId, HostId id,
287 + MacAddress mac, VlanId vlan, HostLocation location,
288 + Set<IpPrefix> ips, Annotations... annotations) {
289 + super(providerId, id, mac, vlan, location, ips, annotations);
290 + this.location = location;
291 + }
292 +
293 + void setLocation(HostLocation location) {
294 + this.location = location;
295 + }
296 +
297 + @Override
298 + public HostLocation location() {
299 + return location;
300 + }
301 + }
278 } 302 }
......
...@@ -31,7 +31,6 @@ import org.onlab.onos.net.provider.ProviderId; ...@@ -31,7 +31,6 @@ import org.onlab.onos.net.provider.ProviderId;
31 import org.onlab.onos.store.AbstractStore; 31 import org.onlab.onos.store.AbstractStore;
32 import org.onlab.onos.store.ClockService; 32 import org.onlab.onos.store.ClockService;
33 import org.onlab.onos.store.Timestamp; 33 import org.onlab.onos.store.Timestamp;
34 -import org.onlab.onos.store.VersionedValue;
35 import org.slf4j.Logger; 34 import org.slf4j.Logger;
36 35
37 import com.google.common.collect.HashMultimap; 36 import com.google.common.collect.HashMultimap;
......
1 -package org.onlab.onos.store; 1 +package org.onlab.onos.store.link.impl;
2 2
3 import java.util.Objects; 3 import java.util.Objects;
4 4
5 +import org.onlab.onos.store.Timestamp;
6 +
7 +// TODO: remove once we stop using this
5 /** 8 /**
6 * Wrapper class for a entity that is versioned 9 * Wrapper class for a entity that is versioned
7 * and can either be up or down. 10 * and can either be up or down.
......
1 -package org.onlab.onos.store.cluster.messaging.impl; 1 +package org.onlab.onos.store.serializers;
2 2
3 import org.onlab.onos.cluster.NodeId; 3 import org.onlab.onos.cluster.NodeId;
4 import org.onlab.onos.store.cluster.messaging.ClusterMessage; 4 import org.onlab.onos.store.cluster.messaging.ClusterMessage;
......
1 +package org.onlab.onos.store.serializers;
2 +
3 +import org.onlab.onos.store.common.impl.MastershipBasedTimestamp;
4 +import org.onlab.onos.store.common.impl.Timestamped;
5 +import org.onlab.util.KryoPool;
6 +
7 +public final class DistributedStoreSerializers {
8 +
9 + /**
10 + * KryoPool which can serialize ON.lab misc classes.
11 + */
12 + public static final KryoPool COMMON = KryoPool.newBuilder()
13 + .register(KryoPoolUtil.API)
14 + .register(Timestamped.class)
15 + .register(MastershipBasedTimestamp.class, new MastershipBasedTimestampSerializer())
16 + .build();
17 +
18 + // avoid instantiation
19 + private DistributedStoreSerializers() {}
20 +}
1 -package org.onlab.onos.store.common.impl; 1 +package org.onlab.onos.store.serializers;
2 +
3 +import org.onlab.onos.store.common.impl.MastershipBasedTimestamp;
2 4
3 import com.esotericsoftware.kryo.Kryo; 5 import com.esotericsoftware.kryo.Kryo;
4 import com.esotericsoftware.kryo.Serializer; 6 import com.esotericsoftware.kryo.Serializer;
...@@ -7,12 +9,12 @@ import com.esotericsoftware.kryo.io.Output; ...@@ -7,12 +9,12 @@ import com.esotericsoftware.kryo.io.Output;
7 9
8 // To be used if Timestamp ever needs to cross bundle boundary. 10 // To be used if Timestamp ever needs to cross bundle boundary.
9 /** 11 /**
10 - * Kryo Serializer for {@link DeviceMastershipBasedTimestamp}. 12 + * Kryo Serializer for {@link MastershipBasedTimestamp}.
11 */ 13 */
12 -public class MastershipBasedTimestampSerializer extends Serializer<DeviceMastershipBasedTimestamp> { 14 +public class MastershipBasedTimestampSerializer extends Serializer<MastershipBasedTimestamp> {
13 15
14 /** 16 /**
15 - * Creates a serializer for {@link DeviceMastershipBasedTimestamp}. 17 + * Creates a serializer for {@link MastershipBasedTimestamp}.
16 */ 18 */
17 public MastershipBasedTimestampSerializer() { 19 public MastershipBasedTimestampSerializer() {
18 // non-null, immutable 20 // non-null, immutable
...@@ -20,15 +22,15 @@ public class MastershipBasedTimestampSerializer extends Serializer<DeviceMasters ...@@ -20,15 +22,15 @@ public class MastershipBasedTimestampSerializer extends Serializer<DeviceMasters
20 } 22 }
21 23
22 @Override 24 @Override
23 - public void write(Kryo kryo, Output output, DeviceMastershipBasedTimestamp object) { 25 + public void write(Kryo kryo, Output output, MastershipBasedTimestamp object) {
24 output.writeInt(object.termNumber()); 26 output.writeInt(object.termNumber());
25 output.writeInt(object.sequenceNumber()); 27 output.writeInt(object.sequenceNumber());
26 } 28 }
27 29
28 @Override 30 @Override
29 - public DeviceMastershipBasedTimestamp read(Kryo kryo, Input input, Class<DeviceMastershipBasedTimestamp> type) { 31 + public MastershipBasedTimestamp read(Kryo kryo, Input input, Class<MastershipBasedTimestamp> type) {
30 final int term = input.readInt(); 32 final int term = input.readInt();
31 final int sequence = input.readInt(); 33 final int sequence = input.readInt();
32 - return new DeviceMastershipBasedTimestamp(term, sequence); 34 + return new MastershipBasedTimestamp(term, sequence);
33 } 35 }
34 } 36 }
......
1 -package org.onlab.onos.store.cluster.messaging.impl; 1 +package org.onlab.onos.store.serializers;
2 2
3 import org.onlab.onos.store.cluster.messaging.MessageSubject; 3 import org.onlab.onos.store.cluster.messaging.MessageSubject;
4 4
......
...@@ -6,25 +6,26 @@ import java.nio.ByteBuffer; ...@@ -6,25 +6,26 @@ import java.nio.ByteBuffer;
6 6
7 import org.junit.Test; 7 import org.junit.Test;
8 import org.onlab.onos.store.Timestamp; 8 import org.onlab.onos.store.Timestamp;
9 +import org.onlab.onos.store.serializers.MastershipBasedTimestampSerializer;
9 import org.onlab.util.KryoPool; 10 import org.onlab.util.KryoPool;
10 11
11 import com.google.common.testing.EqualsTester; 12 import com.google.common.testing.EqualsTester;
12 13
13 /** 14 /**
14 - * Test of {@link DeviceMastershipBasedTimestamp}. 15 + * Test of {@link MastershipBasedTimestamp}.
15 */ 16 */
16 public class MastershipBasedTimestampTest { 17 public class MastershipBasedTimestampTest {
17 18
18 - private static final Timestamp TS_1_1 = new DeviceMastershipBasedTimestamp(1, 1); 19 + private static final Timestamp TS_1_1 = new MastershipBasedTimestamp(1, 1);
19 - private static final Timestamp TS_1_2 = new DeviceMastershipBasedTimestamp(1, 2); 20 + private static final Timestamp TS_1_2 = new MastershipBasedTimestamp(1, 2);
20 - private static final Timestamp TS_2_1 = new DeviceMastershipBasedTimestamp(2, 1); 21 + private static final Timestamp TS_2_1 = new MastershipBasedTimestamp(2, 1);
21 - private static final Timestamp TS_2_2 = new DeviceMastershipBasedTimestamp(2, 2); 22 + private static final Timestamp TS_2_2 = new MastershipBasedTimestamp(2, 2);
22 23
23 @Test 24 @Test
24 public final void testBasic() { 25 public final void testBasic() {
25 final int termNumber = 5; 26 final int termNumber = 5;
26 final int sequenceNumber = 6; 27 final int sequenceNumber = 6;
27 - DeviceMastershipBasedTimestamp ts = new DeviceMastershipBasedTimestamp(termNumber, 28 + MastershipBasedTimestamp ts = new MastershipBasedTimestamp(termNumber,
28 sequenceNumber); 29 sequenceNumber);
29 30
30 assertEquals(termNumber, ts.termNumber()); 31 assertEquals(termNumber, ts.termNumber());
...@@ -34,7 +35,7 @@ public class MastershipBasedTimestampTest { ...@@ -34,7 +35,7 @@ public class MastershipBasedTimestampTest {
34 @Test 35 @Test
35 public final void testCompareTo() { 36 public final void testCompareTo() {
36 assertTrue(TS_1_1.compareTo(TS_1_1) == 0); 37 assertTrue(TS_1_1.compareTo(TS_1_1) == 0);
37 - assertTrue(TS_1_1.compareTo(new DeviceMastershipBasedTimestamp(1, 1)) == 0); 38 + assertTrue(TS_1_1.compareTo(new MastershipBasedTimestamp(1, 1)) == 0);
38 39
39 assertTrue(TS_1_1.compareTo(TS_1_2) < 0); 40 assertTrue(TS_1_1.compareTo(TS_1_2) < 0);
40 assertTrue(TS_1_2.compareTo(TS_1_1) > 0); 41 assertTrue(TS_1_2.compareTo(TS_1_1) > 0);
...@@ -48,14 +49,14 @@ public class MastershipBasedTimestampTest { ...@@ -48,14 +49,14 @@ public class MastershipBasedTimestampTest {
48 @Test 49 @Test
49 public final void testEqualsObject() { 50 public final void testEqualsObject() {
50 new EqualsTester() 51 new EqualsTester()
51 - .addEqualityGroup(new DeviceMastershipBasedTimestamp(1, 1), 52 + .addEqualityGroup(new MastershipBasedTimestamp(1, 1),
52 - new DeviceMastershipBasedTimestamp(1, 1), TS_1_1) 53 + new MastershipBasedTimestamp(1, 1), TS_1_1)
53 - .addEqualityGroup(new DeviceMastershipBasedTimestamp(1, 2), 54 + .addEqualityGroup(new MastershipBasedTimestamp(1, 2),
54 - new DeviceMastershipBasedTimestamp(1, 2), TS_1_2) 55 + new MastershipBasedTimestamp(1, 2), TS_1_2)
55 - .addEqualityGroup(new DeviceMastershipBasedTimestamp(2, 1), 56 + .addEqualityGroup(new MastershipBasedTimestamp(2, 1),
56 - new DeviceMastershipBasedTimestamp(2, 1), TS_2_1) 57 + new MastershipBasedTimestamp(2, 1), TS_2_1)
57 - .addEqualityGroup(new DeviceMastershipBasedTimestamp(2, 2), 58 + .addEqualityGroup(new MastershipBasedTimestamp(2, 2),
58 - new DeviceMastershipBasedTimestamp(2, 2), TS_2_2) 59 + new MastershipBasedTimestamp(2, 2), TS_2_2)
59 .testEquals(); 60 .testEquals();
60 } 61 }
61 62
...@@ -63,7 +64,7 @@ public class MastershipBasedTimestampTest { ...@@ -63,7 +64,7 @@ public class MastershipBasedTimestampTest {
63 public final void testKryoSerializable() { 64 public final void testKryoSerializable() {
64 final ByteBuffer buffer = ByteBuffer.allocate(1 * 1024 * 1024); 65 final ByteBuffer buffer = ByteBuffer.allocate(1 * 1024 * 1024);
65 final KryoPool kryos = KryoPool.newBuilder() 66 final KryoPool kryos = KryoPool.newBuilder()
66 - .register(DeviceMastershipBasedTimestamp.class) 67 + .register(MastershipBasedTimestamp.class)
67 .build(); 68 .build();
68 69
69 kryos.serialize(TS_2_1, buffer); 70 kryos.serialize(TS_2_1, buffer);
...@@ -79,7 +80,7 @@ public class MastershipBasedTimestampTest { ...@@ -79,7 +80,7 @@ public class MastershipBasedTimestampTest {
79 public final void testKryoSerializableWithHandcraftedSerializer() { 80 public final void testKryoSerializableWithHandcraftedSerializer() {
80 final ByteBuffer buffer = ByteBuffer.allocate(1 * 1024 * 1024); 81 final ByteBuffer buffer = ByteBuffer.allocate(1 * 1024 * 1024);
81 final KryoPool kryos = KryoPool.newBuilder() 82 final KryoPool kryos = KryoPool.newBuilder()
82 - .register(DeviceMastershipBasedTimestamp.class, new MastershipBasedTimestampSerializer()) 83 + .register(MastershipBasedTimestamp.class, new MastershipBasedTimestampSerializer())
83 .build(); 84 .build();
84 85
85 kryos.serialize(TS_1_2, buffer); 86 kryos.serialize(TS_1_2, buffer);
......
...@@ -6,7 +6,6 @@ import java.nio.ByteBuffer; ...@@ -6,7 +6,6 @@ import java.nio.ByteBuffer;
6 6
7 import org.junit.Test; 7 import org.junit.Test;
8 import org.onlab.onos.store.Timestamp; 8 import org.onlab.onos.store.Timestamp;
9 -import org.onlab.onos.store.Timestamped;
10 import org.onlab.util.KryoPool; 9 import org.onlab.util.KryoPool;
11 10
12 import com.google.common.testing.EqualsTester; 11 import com.google.common.testing.EqualsTester;
...@@ -16,9 +15,9 @@ import com.google.common.testing.EqualsTester; ...@@ -16,9 +15,9 @@ import com.google.common.testing.EqualsTester;
16 */ 15 */
17 public class TimestampedTest { 16 public class TimestampedTest {
18 17
19 - private static final Timestamp TS_1_1 = new DeviceMastershipBasedTimestamp(1, 1); 18 + private static final Timestamp TS_1_1 = new MastershipBasedTimestamp(1, 1);
20 - private static final Timestamp TS_1_2 = new DeviceMastershipBasedTimestamp(1, 2); 19 + private static final Timestamp TS_1_2 = new MastershipBasedTimestamp(1, 2);
21 - private static final Timestamp TS_2_1 = new DeviceMastershipBasedTimestamp(2, 1); 20 + private static final Timestamp TS_2_1 = new MastershipBasedTimestamp(2, 1);
22 21
23 @Test 22 @Test
24 public final void testHashCode() { 23 public final void testHashCode() {
...@@ -80,7 +79,7 @@ public class TimestampedTest { ...@@ -80,7 +79,7 @@ public class TimestampedTest {
80 final ByteBuffer buffer = ByteBuffer.allocate(1 * 1024 * 1024); 79 final ByteBuffer buffer = ByteBuffer.allocate(1 * 1024 * 1024);
81 final KryoPool kryos = KryoPool.newBuilder() 80 final KryoPool kryos = KryoPool.newBuilder()
82 .register(Timestamped.class, 81 .register(Timestamped.class,
83 - DeviceMastershipBasedTimestamp.class) 82 + MastershipBasedTimestamp.class)
84 .build(); 83 .build();
85 84
86 Timestamped<String> original = new Timestamped<>("foobar", TS_1_1); 85 Timestamped<String> original = new Timestamped<>("foobar", TS_1_1);
......
...@@ -25,6 +25,7 @@ import org.onlab.onos.cluster.ClusterService; ...@@ -25,6 +25,7 @@ import org.onlab.onos.cluster.ClusterService;
25 import org.onlab.onos.cluster.ControllerNode; 25 import org.onlab.onos.cluster.ControllerNode;
26 import org.onlab.onos.cluster.ControllerNode.State; 26 import org.onlab.onos.cluster.ControllerNode.State;
27 import org.onlab.onos.cluster.DefaultControllerNode; 27 import org.onlab.onos.cluster.DefaultControllerNode;
28 +import org.onlab.onos.cluster.MastershipTerm;
28 import org.onlab.onos.cluster.NodeId; 29 import org.onlab.onos.cluster.NodeId;
29 import org.onlab.onos.net.Annotations; 30 import org.onlab.onos.net.Annotations;
30 import org.onlab.onos.net.DefaultAnnotations; 31 import org.onlab.onos.net.DefaultAnnotations;
...@@ -39,7 +40,6 @@ import org.onlab.onos.net.device.DeviceDescription; ...@@ -39,7 +40,6 @@ import org.onlab.onos.net.device.DeviceDescription;
39 import org.onlab.onos.net.device.DeviceEvent; 40 import org.onlab.onos.net.device.DeviceEvent;
40 import org.onlab.onos.net.device.DeviceStore; 41 import org.onlab.onos.net.device.DeviceStore;
41 import org.onlab.onos.net.device.DeviceStoreDelegate; 42 import org.onlab.onos.net.device.DeviceStoreDelegate;
42 -import org.onlab.onos.net.device.DeviceMastershipTerm;
43 import org.onlab.onos.net.device.PortDescription; 43 import org.onlab.onos.net.device.PortDescription;
44 import org.onlab.onos.net.provider.ProviderId; 44 import org.onlab.onos.net.provider.ProviderId;
45 import org.onlab.onos.store.ClockService; 45 import org.onlab.onos.store.ClockService;
...@@ -113,8 +113,8 @@ public class GossipDeviceStoreTest { ...@@ -113,8 +113,8 @@ public class GossipDeviceStoreTest {
113 deviceClockManager.activate(); 113 deviceClockManager.activate();
114 clockService = deviceClockManager; 114 clockService = deviceClockManager;
115 115
116 - deviceClockManager.setMastershipTerm(DID1, DeviceMastershipTerm.of(MYSELF, 1)); 116 + deviceClockManager.setMastershipTerm(DID1, MastershipTerm.of(MYSELF, 1));
117 - deviceClockManager.setMastershipTerm(DID2, DeviceMastershipTerm.of(MYSELF, 2)); 117 + deviceClockManager.setMastershipTerm(DID2, MastershipTerm.of(MYSELF, 2));
118 118
119 ClusterCommunicationService clusterCommunicator = new TestClusterCommunicationService(); 119 ClusterCommunicationService clusterCommunicator = new TestClusterCommunicationService();
120 ClusterService clusterService = new TestClusterService(); 120 ClusterService clusterService = new TestClusterService();
......
...@@ -46,10 +46,6 @@ ...@@ -46,10 +46,6 @@
46 <groupId>com.hazelcast</groupId> 46 <groupId>com.hazelcast</groupId>
47 <artifactId>hazelcast</artifactId> 47 <artifactId>hazelcast</artifactId>
48 </dependency> 48 </dependency>
49 - <dependency>
50 - <groupId>de.javakaffee</groupId>
51 - <artifactId>kryo-serializers</artifactId>
52 - </dependency>
53 </dependencies> 49 </dependencies>
54 50
55 <build> 51 <build>
......
1 package org.onlab.onos.store.cluster.impl; 1 package org.onlab.onos.store.cluster.impl;
2 2
3 -import static org.onlab.onos.net.device.DeviceMastershipEvent.Type.MASTER_CHANGED; 3 +import static org.onlab.onos.cluster.MastershipEvent.Type.MASTER_CHANGED;
4 4
5 import java.util.Map; 5 import java.util.Map;
6 import java.util.Set; 6 import java.util.Set;
...@@ -12,13 +12,13 @@ import org.apache.felix.scr.annotations.Reference; ...@@ -12,13 +12,13 @@ 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.apache.felix.scr.annotations.Service; 13 import org.apache.felix.scr.annotations.Service;
14 import org.onlab.onos.cluster.ClusterService; 14 import org.onlab.onos.cluster.ClusterService;
15 +import org.onlab.onos.cluster.MastershipEvent;
16 +import org.onlab.onos.cluster.MastershipStore;
17 +import org.onlab.onos.cluster.MastershipStoreDelegate;
18 +import org.onlab.onos.cluster.MastershipTerm;
15 import org.onlab.onos.cluster.NodeId; 19 import org.onlab.onos.cluster.NodeId;
16 import org.onlab.onos.net.DeviceId; 20 import org.onlab.onos.net.DeviceId;
17 import org.onlab.onos.net.MastershipRole; 21 import org.onlab.onos.net.MastershipRole;
18 -import org.onlab.onos.net.device.DeviceMastershipEvent;
19 -import org.onlab.onos.net.device.DeviceMastershipStore;
20 -import org.onlab.onos.net.device.DeviceMastershipStoreDelegate;
21 -import org.onlab.onos.net.device.DeviceMastershipTerm;
22 import org.onlab.onos.store.common.AbstractHazelcastStore; 22 import org.onlab.onos.store.common.AbstractHazelcastStore;
23 23
24 import com.google.common.collect.ImmutableSet; 24 import com.google.common.collect.ImmutableSet;
...@@ -32,9 +32,9 @@ import com.hazelcast.core.MultiMap; ...@@ -32,9 +32,9 @@ import com.hazelcast.core.MultiMap;
32 */ 32 */
33 @Component(immediate = true) 33 @Component(immediate = true)
34 @Service 34 @Service
35 -public class DistributedDeviceMastershipStore 35 +public class DistributedMastershipStore
36 -extends AbstractHazelcastStore<DeviceMastershipEvent, DeviceMastershipStoreDelegate> 36 +extends AbstractHazelcastStore<MastershipEvent, MastershipStoreDelegate>
37 -implements DeviceMastershipStore { 37 +implements MastershipStore {
38 38
39 //arbitrary lock name 39 //arbitrary lock name
40 private static final String LOCK = "lock"; 40 private static final String LOCK = "lock";
...@@ -100,7 +100,7 @@ implements DeviceMastershipStore { ...@@ -100,7 +100,7 @@ implements DeviceMastershipStore {
100 } 100 }
101 101
102 @Override 102 @Override
103 - public DeviceMastershipEvent setMaster(NodeId nodeId, DeviceId deviceId) { 103 + public MastershipEvent setMaster(NodeId nodeId, DeviceId deviceId) {
104 byte [] did = serialize(deviceId); 104 byte [] did = serialize(deviceId);
105 byte [] nid = serialize(nodeId); 105 byte [] nid = serialize(nodeId);
106 106
...@@ -123,12 +123,12 @@ implements DeviceMastershipStore { ...@@ -123,12 +123,12 @@ implements DeviceMastershipStore {
123 masters.put(did, nid); 123 masters.put(did, nid);
124 evict(nid, did); 124 evict(nid, did);
125 updateTerm(did); 125 updateTerm(did);
126 - return new DeviceMastershipEvent(MASTER_CHANGED, deviceId, nodeId); 126 + return new MastershipEvent(MASTER_CHANGED, deviceId, nodeId);
127 case NONE: 127 case NONE:
128 masters.put(did, nid); 128 masters.put(did, nid);
129 evict(nid, did); 129 evict(nid, did);
130 updateTerm(did); 130 updateTerm(did);
131 - return new DeviceMastershipEvent(MASTER_CHANGED, deviceId, nodeId); 131 + return new MastershipEvent(MASTER_CHANGED, deviceId, nodeId);
132 default: 132 default:
133 log.warn("unknown Mastership Role {}", role); 133 log.warn("unknown Mastership Role {}", role);
134 return null; 134 return null;
...@@ -191,21 +191,21 @@ implements DeviceMastershipStore { ...@@ -191,21 +191,21 @@ implements DeviceMastershipStore {
191 } 191 }
192 192
193 @Override 193 @Override
194 - public DeviceMastershipTerm getTermFor(DeviceId deviceId) { 194 + public MastershipTerm getTermFor(DeviceId deviceId) {
195 byte[] did = serialize(deviceId); 195 byte[] did = serialize(deviceId);
196 if ((masters.get(did) == null) || 196 if ((masters.get(did) == null) ||
197 (terms.get(did) == null)) { 197 (terms.get(did) == null)) {
198 return null; 198 return null;
199 } 199 }
200 - return DeviceMastershipTerm.of( 200 + return MastershipTerm.of(
201 (NodeId) deserialize(masters.get(did)), terms.get(did)); 201 (NodeId) deserialize(masters.get(did)), terms.get(did));
202 } 202 }
203 203
204 @Override 204 @Override
205 - public DeviceMastershipEvent setStandby(NodeId nodeId, DeviceId deviceId) { 205 + public MastershipEvent setStandby(NodeId nodeId, DeviceId deviceId) {
206 byte [] did = serialize(deviceId); 206 byte [] did = serialize(deviceId);
207 byte [] nid = serialize(nodeId); 207 byte [] nid = serialize(nodeId);
208 - DeviceMastershipEvent event = null; 208 + MastershipEvent event = null;
209 209
210 ILock lock = theInstance.getLock(LOCK); 210 ILock lock = theInstance.getLock(LOCK);
211 lock.lock(); 211 lock.lock();
...@@ -231,10 +231,10 @@ implements DeviceMastershipStore { ...@@ -231,10 +231,10 @@ implements DeviceMastershipStore {
231 } 231 }
232 232
233 @Override 233 @Override
234 - public DeviceMastershipEvent relinquishRole(NodeId nodeId, DeviceId deviceId) { 234 + public MastershipEvent relinquishRole(NodeId nodeId, DeviceId deviceId) {
235 byte [] did = serialize(deviceId); 235 byte [] did = serialize(deviceId);
236 byte [] nid = serialize(nodeId); 236 byte [] nid = serialize(nodeId);
237 - DeviceMastershipEvent event = null; 237 + MastershipEvent event = null;
238 238
239 ILock lock = theInstance.getLock(LOCK); 239 ILock lock = theInstance.getLock(LOCK);
240 lock.lock(); 240 lock.lock();
...@@ -260,7 +260,7 @@ implements DeviceMastershipStore { ...@@ -260,7 +260,7 @@ implements DeviceMastershipStore {
260 } 260 }
261 261
262 //helper to fetch a new master candidate for a given device. 262 //helper to fetch a new master candidate for a given device.
263 - private DeviceMastershipEvent reelect(NodeId current, DeviceId deviceId) { 263 + private MastershipEvent reelect(NodeId current, DeviceId deviceId) {
264 byte [] did = serialize(deviceId); 264 byte [] did = serialize(deviceId);
265 byte [] nid = serialize(current); 265 byte [] nid = serialize(current);
266 266
...@@ -281,7 +281,7 @@ implements DeviceMastershipStore { ...@@ -281,7 +281,7 @@ implements DeviceMastershipStore {
281 evict(backup, did); 281 evict(backup, did);
282 Integer term = terms.get(did); 282 Integer term = terms.get(did);
283 terms.put(did, ++term); 283 terms.put(did, ++term);
284 - return new DeviceMastershipEvent( 284 + return new MastershipEvent(
285 MASTER_CHANGED, deviceId, (NodeId) deserialize(backup)); 285 MASTER_CHANGED, deviceId, (NodeId) deserialize(backup));
286 } 286 }
287 } 287 }
...@@ -320,7 +320,7 @@ implements DeviceMastershipStore { ...@@ -320,7 +320,7 @@ implements DeviceMastershipStore {
320 320
321 @Override 321 @Override
322 protected void onAdd(DeviceId deviceId, NodeId nodeId) { 322 protected void onAdd(DeviceId deviceId, NodeId nodeId) {
323 - notifyDelegate(new DeviceMastershipEvent(MASTER_CHANGED, deviceId, nodeId)); 323 + notifyDelegate(new MastershipEvent(MASTER_CHANGED, deviceId, nodeId));
324 } 324 }
325 325
326 @Override 326 @Override
......
...@@ -21,12 +21,12 @@ import org.onlab.onos.cluster.ClusterService; ...@@ -21,12 +21,12 @@ import org.onlab.onos.cluster.ClusterService;
21 import org.onlab.onos.cluster.ControllerNode; 21 import org.onlab.onos.cluster.ControllerNode;
22 import org.onlab.onos.cluster.ControllerNode.State; 22 import org.onlab.onos.cluster.ControllerNode.State;
23 import org.onlab.onos.cluster.DefaultControllerNode; 23 import org.onlab.onos.cluster.DefaultControllerNode;
24 +import org.onlab.onos.cluster.MastershipEvent;
25 +import org.onlab.onos.cluster.MastershipEvent.Type;
26 +import org.onlab.onos.cluster.MastershipStoreDelegate;
27 +import org.onlab.onos.cluster.MastershipTerm;
24 import org.onlab.onos.cluster.NodeId; 28 import org.onlab.onos.cluster.NodeId;
25 import org.onlab.onos.net.DeviceId; 29 import org.onlab.onos.net.DeviceId;
26 -import org.onlab.onos.net.device.DeviceMastershipEvent;
27 -import org.onlab.onos.net.device.DeviceMastershipStoreDelegate;
28 -import org.onlab.onos.net.device.DeviceMastershipTerm;
29 -import org.onlab.onos.net.device.DeviceMastershipEvent.Type;
30 import org.onlab.onos.store.common.StoreManager; 30 import org.onlab.onos.store.common.StoreManager;
31 import org.onlab.onos.store.common.StoreService; 31 import org.onlab.onos.store.common.StoreService;
32 import org.onlab.onos.store.common.TestStoreManager; 32 import org.onlab.onos.store.common.TestStoreManager;
...@@ -40,7 +40,7 @@ import com.hazelcast.core.Hazelcast; ...@@ -40,7 +40,7 @@ import com.hazelcast.core.Hazelcast;
40 /** 40 /**
41 * Test of the Hazelcast-based distributed MastershipStore implementation. 41 * Test of the Hazelcast-based distributed MastershipStore implementation.
42 */ 42 */
43 -public class DistributedDeviceMastershipStoreTest { 43 +public class DistributedMastershipStoreTest {
44 44
45 private static final DeviceId DID1 = DeviceId.deviceId("of:01"); 45 private static final DeviceId DID1 = DeviceId.deviceId("of:01");
46 private static final DeviceId DID2 = DeviceId.deviceId("of:02"); 46 private static final DeviceId DID2 = DeviceId.deviceId("of:02");
...@@ -54,8 +54,8 @@ public class DistributedDeviceMastershipStoreTest { ...@@ -54,8 +54,8 @@ public class DistributedDeviceMastershipStoreTest {
54 private static final ControllerNode CN1 = new DefaultControllerNode(N1, IP); 54 private static final ControllerNode CN1 = new DefaultControllerNode(N1, IP);
55 private static final ControllerNode CN2 = new DefaultControllerNode(N2, IP); 55 private static final ControllerNode CN2 = new DefaultControllerNode(N2, IP);
56 56
57 - private DistributedDeviceMastershipStore dms; 57 + private DistributedMastershipStore dms;
58 - private TestDistributedDeviceMastershipStore testStore; 58 + private TestDistributedMastershipStore testStore;
59 private KryoSerializer serializationMgr; 59 private KryoSerializer serializationMgr;
60 private StoreManager storeMgr; 60 private StoreManager storeMgr;
61 61
...@@ -77,11 +77,11 @@ public class DistributedDeviceMastershipStoreTest { ...@@ -77,11 +77,11 @@ public class DistributedDeviceMastershipStoreTest {
77 77
78 serializationMgr = new KryoSerializer(); 78 serializationMgr = new KryoSerializer();
79 79
80 - dms = new TestDistributedDeviceMastershipStore(storeMgr, serializationMgr); 80 + dms = new TestDistributedMastershipStore(storeMgr, serializationMgr);
81 dms.clusterService = new TestClusterService(); 81 dms.clusterService = new TestClusterService();
82 dms.activate(); 82 dms.activate();
83 83
84 - testStore = (TestDistributedDeviceMastershipStore) dms; 84 + testStore = (TestDistributedMastershipStore) dms;
85 } 85 }
86 86
87 @After 87 @After
...@@ -133,7 +133,7 @@ public class DistributedDeviceMastershipStoreTest { ...@@ -133,7 +133,7 @@ public class DistributedDeviceMastershipStoreTest {
133 assertEquals("wrong role for NONE:", MASTER, dms.requestRole(DID1)); 133 assertEquals("wrong role for NONE:", MASTER, dms.requestRole(DID1));
134 assertTrue("wrong state for store:", !dms.terms.isEmpty()); 134 assertTrue("wrong state for store:", !dms.terms.isEmpty());
135 assertEquals("wrong term", 135 assertEquals("wrong term",
136 - DeviceMastershipTerm.of(N1, 0), dms.getTermFor(DID1)); 136 + MastershipTerm.of(N1, 0), dms.getTermFor(DID1));
137 137
138 //CN2 now local. DID2 has N1 as MASTER so N2 is STANDBY 138 //CN2 now local. DID2 has N1 as MASTER so N2 is STANDBY
139 testStore.setCurrent(CN2); 139 testStore.setCurrent(CN2);
...@@ -143,7 +143,7 @@ public class DistributedDeviceMastershipStoreTest { ...@@ -143,7 +143,7 @@ public class DistributedDeviceMastershipStoreTest {
143 //change term and requestRole() again; should persist 143 //change term and requestRole() again; should persist
144 testStore.increment(DID2); 144 testStore.increment(DID2);
145 assertEquals("wrong role for STANDBY:", STANDBY, dms.requestRole(DID2)); 145 assertEquals("wrong role for STANDBY:", STANDBY, dms.requestRole(DID2));
146 - assertEquals("wrong term", DeviceMastershipTerm.of(N1, 1), dms.getTermFor(DID2)); 146 + assertEquals("wrong term", MastershipTerm.of(N1, 1), dms.getTermFor(DID2));
147 } 147 }
148 148
149 @Test 149 @Test
...@@ -155,15 +155,15 @@ public class DistributedDeviceMastershipStoreTest { ...@@ -155,15 +155,15 @@ public class DistributedDeviceMastershipStoreTest {
155 155
156 //switch over to N2 156 //switch over to N2
157 assertEquals("wrong event:", Type.MASTER_CHANGED, dms.setMaster(N2, DID1).type()); 157 assertEquals("wrong event:", Type.MASTER_CHANGED, dms.setMaster(N2, DID1).type());
158 - assertEquals("wrong term", DeviceMastershipTerm.of(N2, 1), dms.getTermFor(DID1)); 158 + assertEquals("wrong term", MastershipTerm.of(N2, 1), dms.getTermFor(DID1));
159 159
160 //orphan switch - should be rare case 160 //orphan switch - should be rare case
161 assertEquals("wrong event:", Type.MASTER_CHANGED, dms.setMaster(N2, DID2).type()); 161 assertEquals("wrong event:", Type.MASTER_CHANGED, dms.setMaster(N2, DID2).type());
162 - assertEquals("wrong term", DeviceMastershipTerm.of(N2, 0), dms.getTermFor(DID2)); 162 + assertEquals("wrong term", MastershipTerm.of(N2, 0), dms.getTermFor(DID2));
163 //disconnect and reconnect - sign of failing re-election or single-instance channel 163 //disconnect and reconnect - sign of failing re-election or single-instance channel
164 testStore.reset(true, false, false); 164 testStore.reset(true, false, false);
165 dms.setMaster(N2, DID2); 165 dms.setMaster(N2, DID2);
166 - assertEquals("wrong term", DeviceMastershipTerm.of(N2, 1), dms.getTermFor(DID2)); 166 + assertEquals("wrong term", MastershipTerm.of(N2, 1), dms.getTermFor(DID2));
167 } 167 }
168 168
169 @Test 169 @Test
...@@ -211,9 +211,9 @@ public class DistributedDeviceMastershipStoreTest { ...@@ -211,9 +211,9 @@ public class DistributedDeviceMastershipStoreTest {
211 //shamelessly copy other distributed store tests 211 //shamelessly copy other distributed store tests
212 final CountDownLatch addLatch = new CountDownLatch(1); 212 final CountDownLatch addLatch = new CountDownLatch(1);
213 213
214 - DeviceMastershipStoreDelegate checkAdd = new DeviceMastershipStoreDelegate() { 214 + MastershipStoreDelegate checkAdd = new MastershipStoreDelegate() {
215 @Override 215 @Override
216 - public void notify(DeviceMastershipEvent event) { 216 + public void notify(MastershipEvent event) {
217 assertEquals("wrong event:", Type.MASTER_CHANGED, event.type()); 217 assertEquals("wrong event:", Type.MASTER_CHANGED, event.type());
218 assertEquals("wrong subject", DID1, event.subject()); 218 assertEquals("wrong subject", DID1, event.subject());
219 assertEquals("wrong subject", N1, event.master()); 219 assertEquals("wrong subject", N1, event.master());
...@@ -227,9 +227,9 @@ public class DistributedDeviceMastershipStoreTest { ...@@ -227,9 +227,9 @@ public class DistributedDeviceMastershipStoreTest {
227 assertTrue("Add event fired", addLatch.await(1, TimeUnit.SECONDS)); 227 assertTrue("Add event fired", addLatch.await(1, TimeUnit.SECONDS));
228 } 228 }
229 229
230 - private class TestDistributedDeviceMastershipStore extends 230 + private class TestDistributedMastershipStore extends
231 - DistributedDeviceMastershipStore { 231 + DistributedMastershipStore {
232 - public TestDistributedDeviceMastershipStore(StoreService storeService, 232 + public TestDistributedMastershipStore(StoreService storeService,
233 KryoSerializer kryoSerialization) { 233 KryoSerializer kryoSerialization) {
234 this.storeService = storeService; 234 this.storeService = storeService;
235 this.serializer = kryoSerialization; 235 this.serializer = kryoSerialization;
......
...@@ -35,8 +35,8 @@ ...@@ -35,8 +35,8 @@
35 <artifactId>hazelcast</artifactId> 35 <artifactId>hazelcast</artifactId>
36 </dependency> 36 </dependency>
37 <dependency> 37 <dependency>
38 - <groupId>de.javakaffee</groupId> 38 + <groupId>org.apache.commons</groupId>
39 - <artifactId>kryo-serializers</artifactId> 39 + <artifactId>commons-lang3</artifactId>
40 </dependency> 40 </dependency>
41 </dependencies> 41 </dependencies>
42 42
......
...@@ -23,11 +23,6 @@ ...@@ -23,11 +23,6 @@
23 </dependency> 23 </dependency>
24 <dependency> 24 <dependency>
25 <groupId>org.onlab.onos</groupId> 25 <groupId>org.onlab.onos</groupId>
26 - <artifactId>onos-core-serializers</artifactId>
27 - <version>${project.version}</version>
28 - </dependency>
29 - <dependency>
30 - <groupId>org.onlab.onos</groupId>
31 <artifactId>onos-core-hz-common</artifactId> 26 <artifactId>onos-core-hz-common</artifactId>
32 <version>${project.version}</version> 27 <version>${project.version}</version>
33 </dependency> 28 </dependency>
...@@ -46,10 +41,6 @@ ...@@ -46,10 +41,6 @@
46 <groupId>com.hazelcast</groupId> 41 <groupId>com.hazelcast</groupId>
47 <artifactId>hazelcast</artifactId> 42 <artifactId>hazelcast</artifactId>
48 </dependency> 43 </dependency>
49 - <dependency>
50 - <groupId>de.javakaffee</groupId>
51 - <artifactId>kryo-serializers</artifactId>
52 - </dependency>
53 </dependencies> 44 </dependencies>
54 45
55 <build> 46 <build>
......
...@@ -2,8 +2,8 @@ package org.onlab.onos.store.device.impl; ...@@ -2,8 +2,8 @@ package org.onlab.onos.store.device.impl;
2 2
3 import org.apache.felix.scr.annotations.Component; 3 import org.apache.felix.scr.annotations.Component;
4 import org.apache.felix.scr.annotations.Service; 4 import org.apache.felix.scr.annotations.Service;
5 +import org.onlab.onos.cluster.MastershipTerm;
5 import org.onlab.onos.net.DeviceId; 6 import org.onlab.onos.net.DeviceId;
6 -import org.onlab.onos.net.device.DeviceMastershipTerm;
7 import org.onlab.onos.store.ClockProviderService; 7 import org.onlab.onos.store.ClockProviderService;
8 8
9 // FIXME: Code clone in onos-core-trivial, onos-core-hz-net 9 // FIXME: Code clone in onos-core-trivial, onos-core-hz-net
...@@ -15,6 +15,6 @@ import org.onlab.onos.store.ClockProviderService; ...@@ -15,6 +15,6 @@ import org.onlab.onos.store.ClockProviderService;
15 public class NoOpClockProviderService implements ClockProviderService { 15 public class NoOpClockProviderService implements ClockProviderService {
16 16
17 @Override 17 @Override
18 - public void setMastershipTerm(DeviceId deviceId, DeviceMastershipTerm term) { 18 + public void setMastershipTerm(DeviceId deviceId, MastershipTerm term) {
19 } 19 }
20 } 20 }
......
1 package org.onlab.onos.store.host.impl; 1 package org.onlab.onos.store.host.impl;
2 2
3 -import static org.onlab.onos.net.host.HostEvent.Type.HOST_ADDED; 3 +import com.google.common.collect.HashMultimap;
4 -import static org.onlab.onos.net.host.HostEvent.Type.HOST_MOVED; 4 +import com.google.common.collect.ImmutableSet;
5 -import static org.onlab.onos.net.host.HostEvent.Type.HOST_REMOVED; 5 +import com.google.common.collect.Multimap;
6 -import static org.onlab.onos.net.host.HostEvent.Type.HOST_UPDATED; 6 +import com.google.common.collect.Sets;
7 -import static org.slf4j.LoggerFactory.getLogger;
8 -
9 -import java.util.Collections;
10 -import java.util.HashSet;
11 -import java.util.Map;
12 -import java.util.Set;
13 -import java.util.concurrent.ConcurrentHashMap;
14 -
15 import org.apache.felix.scr.annotations.Activate; 7 import org.apache.felix.scr.annotations.Activate;
16 import org.apache.felix.scr.annotations.Component; 8 import org.apache.felix.scr.annotations.Component;
17 import org.apache.felix.scr.annotations.Deactivate; 9 import org.apache.felix.scr.annotations.Deactivate;
18 import org.apache.felix.scr.annotations.Service; 10 import org.apache.felix.scr.annotations.Service;
11 +import org.onlab.onos.net.Annotations;
19 import org.onlab.onos.net.ConnectPoint; 12 import org.onlab.onos.net.ConnectPoint;
20 import org.onlab.onos.net.DefaultHost; 13 import org.onlab.onos.net.DefaultHost;
21 import org.onlab.onos.net.DeviceId; 14 import org.onlab.onos.net.DeviceId;
22 import org.onlab.onos.net.Host; 15 import org.onlab.onos.net.Host;
23 import org.onlab.onos.net.HostId; 16 import org.onlab.onos.net.HostId;
17 +import org.onlab.onos.net.HostLocation;
24 import org.onlab.onos.net.host.HostDescription; 18 import org.onlab.onos.net.host.HostDescription;
25 import org.onlab.onos.net.host.HostEvent; 19 import org.onlab.onos.net.host.HostEvent;
26 import org.onlab.onos.net.host.HostStore; 20 import org.onlab.onos.net.host.HostStore;
...@@ -33,10 +27,13 @@ import org.onlab.packet.MacAddress; ...@@ -33,10 +27,13 @@ import org.onlab.packet.MacAddress;
33 import org.onlab.packet.VlanId; 27 import org.onlab.packet.VlanId;
34 import org.slf4j.Logger; 28 import org.slf4j.Logger;
35 29
36 -import com.google.common.collect.HashMultimap; 30 +import java.util.HashSet;
37 -import com.google.common.collect.ImmutableSet; 31 +import java.util.Map;
38 -import com.google.common.collect.Multimap; 32 +import java.util.Set;
39 -import com.google.common.collect.Sets; 33 +import java.util.concurrent.ConcurrentHashMap;
34 +
35 +import static org.onlab.onos.net.host.HostEvent.Type.*;
36 +import static org.slf4j.LoggerFactory.getLogger;
40 37
41 /** 38 /**
42 * TEMPORARY: Manages inventory of end-station hosts using distributed 39 * TEMPORARY: Manages inventory of end-station hosts using distributed
...@@ -46,13 +43,13 @@ import com.google.common.collect.Sets; ...@@ -46,13 +43,13 @@ import com.google.common.collect.Sets;
46 @Component(immediate = true) 43 @Component(immediate = true)
47 @Service 44 @Service
48 public class DistributedHostStore 45 public class DistributedHostStore
49 -extends AbstractStore<HostEvent, HostStoreDelegate> 46 + extends AbstractStore<HostEvent, HostStoreDelegate>
50 -implements HostStore { 47 + implements HostStore {
51 48
52 private final Logger log = getLogger(getClass()); 49 private final Logger log = getLogger(getClass());
53 50
54 // Host inventory 51 // Host inventory
55 - private final Map<HostId, Host> hosts = new ConcurrentHashMap<>(); 52 + private final Map<HostId, StoredHost> hosts = new ConcurrentHashMap<>(2000000, 0.75f, 16);
56 53
57 // Hosts tracked by their location 54 // Hosts tracked by their location
58 private final Multimap<ConnectPoint, Host> locations = HashMultimap.create(); 55 private final Multimap<ConnectPoint, Host> locations = HashMultimap.create();
...@@ -73,7 +70,7 @@ implements HostStore { ...@@ -73,7 +70,7 @@ implements HostStore {
73 @Override 70 @Override
74 public HostEvent createOrUpdateHost(ProviderId providerId, HostId hostId, 71 public HostEvent createOrUpdateHost(ProviderId providerId, HostId hostId,
75 HostDescription hostDescription) { 72 HostDescription hostDescription) {
76 - Host host = hosts.get(hostId); 73 + StoredHost host = hosts.get(hostId);
77 if (host == null) { 74 if (host == null) {
78 return createHost(providerId, hostId, hostDescription); 75 return createHost(providerId, hostId, hostDescription);
79 } 76 }
...@@ -83,11 +80,11 @@ implements HostStore { ...@@ -83,11 +80,11 @@ implements HostStore {
83 // creates a new host and sends HOST_ADDED 80 // creates a new host and sends HOST_ADDED
84 private HostEvent createHost(ProviderId providerId, HostId hostId, 81 private HostEvent createHost(ProviderId providerId, HostId hostId,
85 HostDescription descr) { 82 HostDescription descr) {
86 - DefaultHost newhost = new DefaultHost(providerId, hostId, 83 + StoredHost newhost = new StoredHost(providerId, hostId,
87 descr.hwAddress(), 84 descr.hwAddress(),
88 descr.vlan(), 85 descr.vlan(),
89 descr.location(), 86 descr.location(),
90 - descr.ipAddresses()); 87 + ImmutableSet.of(descr.ipAddress()));
91 synchronized (this) { 88 synchronized (this) {
92 hosts.put(hostId, newhost); 89 hosts.put(hostId, newhost);
93 locations.put(descr.location(), newhost); 90 locations.put(descr.location(), newhost);
...@@ -96,28 +93,24 @@ implements HostStore { ...@@ -96,28 +93,24 @@ implements HostStore {
96 } 93 }
97 94
98 // checks for type of update to host, sends appropriate event 95 // checks for type of update to host, sends appropriate event
99 - private HostEvent updateHost(ProviderId providerId, Host host, 96 + private HostEvent updateHost(ProviderId providerId, StoredHost host,
100 HostDescription descr) { 97 HostDescription descr) {
101 - DefaultHost updated;
102 HostEvent event; 98 HostEvent event;
103 if (!host.location().equals(descr.location())) { 99 if (!host.location().equals(descr.location())) {
104 - updated = new DefaultHost(providerId, host.id(), 100 + host.setLocation(descr.location());
105 - host.mac(), 101 + return new HostEvent(HOST_MOVED, host);
106 - host.vlan(), 102 + }
107 - descr.location(),
108 - host.ipAddresses());
109 - event = new HostEvent(HOST_MOVED, updated);
110 103
111 - } else if (!(host.ipAddresses().equals(descr.ipAddresses()))) { 104 + if (host.ipAddresses().contains(descr.ipAddress())) {
112 - updated = new DefaultHost(providerId, host.id(),
113 - host.mac(),
114 - host.vlan(),
115 - descr.location(),
116 - descr.ipAddresses());
117 - event = new HostEvent(HOST_UPDATED, updated);
118 - } else {
119 return null; 105 return null;
120 } 106 }
107 +
108 + Set<IpPrefix> addresses = new HashSet<>(host.ipAddresses());
109 + addresses.add(descr.ipAddress());
110 + StoredHost updated = new StoredHost(providerId, host.id(),
111 + host.mac(), host.vlan(),
112 + descr.location(), addresses);
113 + event = new HostEvent(HOST_UPDATED, updated);
121 synchronized (this) { 114 synchronized (this) {
122 hosts.put(host.id(), updated); 115 hosts.put(host.id(), updated);
123 locations.remove(host.location(), host); 116 locations.remove(host.location(), host);
...@@ -145,7 +138,7 @@ implements HostStore { ...@@ -145,7 +138,7 @@ implements HostStore {
145 138
146 @Override 139 @Override
147 public Iterable<Host> getHosts() { 140 public Iterable<Host> getHosts() {
148 - return Collections.unmodifiableSet(new HashSet<>(hosts.values())); 141 + return ImmutableSet.<Host>copyOf(hosts.values());
149 } 142 }
150 143
151 @Override 144 @Override
...@@ -275,4 +268,35 @@ implements HostStore { ...@@ -275,4 +268,35 @@ implements HostStore {
275 return addresses; 268 return addresses;
276 } 269 }
277 270
271 + // Auxiliary extension to allow location to mutate.
272 + private class StoredHost extends DefaultHost {
273 + private HostLocation location;
274 +
275 + /**
276 + * Creates an end-station host using the supplied information.
277 + *
278 + * @param providerId provider identity
279 + * @param id host identifier
280 + * @param mac host MAC address
281 + * @param vlan host VLAN identifier
282 + * @param location host location
283 + * @param ips host IP addresses
284 + * @param annotations optional key/value annotations
285 + */
286 + public StoredHost(ProviderId providerId, HostId id,
287 + MacAddress mac, VlanId vlan, HostLocation location,
288 + Set<IpPrefix> ips, Annotations... annotations) {
289 + super(providerId, id, mac, vlan, location, ips, annotations);
290 + this.location = location;
291 + }
292 +
293 + void setLocation(HostLocation location) {
294 + this.location = location;
295 + }
296 +
297 + @Override
298 + public HostLocation location() {
299 + return location;
300 + }
301 + }
278 } 302 }
......
...@@ -26,8 +26,13 @@ ...@@ -26,8 +26,13 @@
26 <artifactId>org.apache.felix.scr.annotations</artifactId> 26 <artifactId>org.apache.felix.scr.annotations</artifactId>
27 </dependency> 27 </dependency>
28 <dependency> 28 <dependency>
29 - <groupId>de.javakaffee</groupId> 29 + <groupId>com.esotericsoftware</groupId>
30 - <artifactId>kryo-serializers</artifactId> 30 + <artifactId>kryo</artifactId>
31 + </dependency>
32 + <dependency>
33 + <groupId>com.google.guava</groupId>
34 + <artifactId>guava-testlib</artifactId>
35 + <scope>test</scope>
31 </dependency> 36 </dependency>
32 </dependencies> 37 </dependencies>
33 38
......
...@@ -7,6 +7,7 @@ import java.util.HashMap; ...@@ -7,6 +7,7 @@ import java.util.HashMap;
7 7
8 import org.onlab.onos.cluster.ControllerNode; 8 import org.onlab.onos.cluster.ControllerNode;
9 import org.onlab.onos.cluster.DefaultControllerNode; 9 import org.onlab.onos.cluster.DefaultControllerNode;
10 +import org.onlab.onos.cluster.MastershipTerm;
10 import org.onlab.onos.cluster.NodeId; 11 import org.onlab.onos.cluster.NodeId;
11 import org.onlab.onos.net.ConnectPoint; 12 import org.onlab.onos.net.ConnectPoint;
12 import org.onlab.onos.net.DefaultAnnotations; 13 import org.onlab.onos.net.DefaultAnnotations;
...@@ -23,14 +24,12 @@ import org.onlab.onos.net.Port; ...@@ -23,14 +24,12 @@ import org.onlab.onos.net.Port;
23 import org.onlab.onos.net.PortNumber; 24 import org.onlab.onos.net.PortNumber;
24 import org.onlab.onos.net.device.DefaultDeviceDescription; 25 import org.onlab.onos.net.device.DefaultDeviceDescription;
25 import org.onlab.onos.net.device.DefaultPortDescription; 26 import org.onlab.onos.net.device.DefaultPortDescription;
26 -import org.onlab.onos.net.device.DeviceMastershipTerm;
27 import org.onlab.onos.net.provider.ProviderId; 27 import org.onlab.onos.net.provider.ProviderId;
28 +import org.onlab.onos.store.Timestamp;
28 import org.onlab.packet.IpAddress; 29 import org.onlab.packet.IpAddress;
29 import org.onlab.packet.IpPrefix; 30 import org.onlab.packet.IpPrefix;
30 import org.onlab.util.KryoPool; 31 import org.onlab.util.KryoPool;
31 32
32 -import de.javakaffee.kryoserializers.URISerializer;
33 -
34 public final class KryoPoolUtil { 33 public final class KryoPoolUtil {
35 34
36 /** 35 /**
...@@ -63,7 +62,9 @@ public final class KryoPoolUtil { ...@@ -63,7 +62,9 @@ public final class KryoPoolUtil {
63 Port.class, 62 Port.class,
64 DefaultPortDescription.class, 63 DefaultPortDescription.class,
65 Element.class, 64 Element.class,
66 - Link.Type.class 65 + Link.Type.class,
66 + Timestamp.class
67 +
67 ) 68 )
68 .register(URI.class, new URISerializer()) 69 .register(URI.class, new URISerializer())
69 .register(NodeId.class, new NodeIdSerializer()) 70 .register(NodeId.class, new NodeIdSerializer())
...@@ -74,7 +75,7 @@ public final class KryoPoolUtil { ...@@ -74,7 +75,7 @@ public final class KryoPoolUtil {
74 .register(LinkKey.class, new LinkKeySerializer()) 75 .register(LinkKey.class, new LinkKeySerializer())
75 .register(ConnectPoint.class, new ConnectPointSerializer()) 76 .register(ConnectPoint.class, new ConnectPointSerializer())
76 .register(DefaultLink.class, new DefaultLinkSerializer()) 77 .register(DefaultLink.class, new DefaultLinkSerializer())
77 - .register(DeviceMastershipTerm.class, new MastershipTermSerializer()) 78 + .register(MastershipTerm.class, new MastershipTermSerializer())
78 .register(MastershipRole.class, new MastershipRoleSerializer()) 79 .register(MastershipRole.class, new MastershipRoleSerializer())
79 80
80 .build(); 81 .build();
......
1 package org.onlab.onos.store.serializers; 1 package org.onlab.onos.store.serializers;
2 2
3 import org.onlab.util.KryoPool; 3 import org.onlab.util.KryoPool;
4 -import org.slf4j.Logger;
5 -import org.slf4j.LoggerFactory;
6 -
7 import java.nio.ByteBuffer; 4 import java.nio.ByteBuffer;
8 5
9 /** 6 /**
...@@ -11,10 +8,8 @@ import java.nio.ByteBuffer; ...@@ -11,10 +8,8 @@ import java.nio.ByteBuffer;
11 */ 8 */
12 public class KryoSerializer implements StoreSerializer { 9 public class KryoSerializer implements StoreSerializer {
13 10
14 - private final Logger log = LoggerFactory.getLogger(getClass());
15 protected KryoPool serializerPool; 11 protected KryoPool serializerPool;
16 12
17 -
18 public KryoSerializer() { 13 public KryoSerializer() {
19 setupKryoPool(); 14 setupKryoPool();
20 } 15 }
......
1 package org.onlab.onos.store.serializers; 1 package org.onlab.onos.store.serializers;
2 2
3 +import org.onlab.onos.cluster.MastershipTerm;
3 import org.onlab.onos.cluster.NodeId; 4 import org.onlab.onos.cluster.NodeId;
4 -import org.onlab.onos.net.device.DeviceMastershipTerm;
5 -
6 import com.esotericsoftware.kryo.Kryo; 5 import com.esotericsoftware.kryo.Kryo;
7 import com.esotericsoftware.kryo.Serializer; 6 import com.esotericsoftware.kryo.Serializer;
8 import com.esotericsoftware.kryo.io.Input; 7 import com.esotericsoftware.kryo.io.Input;
9 import com.esotericsoftware.kryo.io.Output; 8 import com.esotericsoftware.kryo.io.Output;
10 9
11 /** 10 /**
12 - * Kryo Serializer for {@link org.onlab.onos.net.device.DeviceMastershipTerm}. 11 + * Kryo Serializer for {@link org.onlab.onos.cluster.MastershipTerm}.
13 */ 12 */
14 -public class MastershipTermSerializer extends Serializer<DeviceMastershipTerm> { 13 +public class MastershipTermSerializer extends Serializer<MastershipTerm> {
15 14
16 /** 15 /**
17 - * Creates {@link DeviceMastershipTerm} serializer instance. 16 + * Creates {@link MastershipTerm} serializer instance.
18 */ 17 */
19 public MastershipTermSerializer() { 18 public MastershipTermSerializer() {
20 // non-null, immutable 19 // non-null, immutable
...@@ -22,14 +21,14 @@ public class MastershipTermSerializer extends Serializer<DeviceMastershipTerm> { ...@@ -22,14 +21,14 @@ public class MastershipTermSerializer extends Serializer<DeviceMastershipTerm> {
22 } 21 }
23 22
24 @Override 23 @Override
25 - public DeviceMastershipTerm read(Kryo kryo, Input input, Class<DeviceMastershipTerm> type) { 24 + public MastershipTerm read(Kryo kryo, Input input, Class<MastershipTerm> type) {
26 final NodeId node = new NodeId(input.readString()); 25 final NodeId node = new NodeId(input.readString());
27 final int term = input.readInt(); 26 final int term = input.readInt();
28 - return DeviceMastershipTerm.of(node, term); 27 + return MastershipTerm.of(node, term);
29 } 28 }
30 29
31 @Override 30 @Override
32 - public void write(Kryo kryo, Output output, DeviceMastershipTerm object) { 31 + public void write(Kryo kryo, Output output, MastershipTerm object) {
33 output.writeString(object.master().toString()); 32 output.writeString(object.master().toString());
34 output.writeInt(object.termNumber()); 33 output.writeInt(object.termNumber());
35 } 34 }
......
1 +package org.onlab.onos.store.serializers;
2 +
3 +import java.net.URI;
4 +
5 +import com.esotericsoftware.kryo.Kryo;
6 +import com.esotericsoftware.kryo.Serializer;
7 +import com.esotericsoftware.kryo.io.Input;
8 +import com.esotericsoftware.kryo.io.Output;
9 +
10 +/**
11 + * Serializer for {@link URI}.
12 + */
13 +public class URISerializer extends Serializer<URI> {
14 +
15 + /**
16 + * Creates {@link URI} serializer instance.
17 + */
18 + public URISerializer() {
19 + super(false);
20 + }
21 +
22 + @Override
23 + public void write(Kryo kryo, Output output, URI object) {
24 + output.writeString(object.toString());
25 + }
26 +
27 + @Override
28 + public URI read(Kryo kryo, Input input, Class<URI> type) {
29 + return URI.create(input.readString());
30 + }
31 +}
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.