pankaj

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

Showing 120 changed files with 2101 additions and 1071 deletions
...@@ -18,18 +18,20 @@ ...@@ -18,18 +18,20 @@
18 18
19 <dependencies> 19 <dependencies>
20 <dependency> 20 <dependency>
21 - <groupId>org.codehaus.jackson</groupId> 21 + <groupId>org.codehaus.jackson</groupId>
22 - <artifactId>jackson-core-asl</artifactId> 22 + <artifactId>jackson-core-asl</artifactId>
23 </dependency> 23 </dependency>
24 <dependency> 24 <dependency>
25 - <groupId>org.codehaus.jackson</groupId> 25 + <groupId>org.codehaus.jackson</groupId>
26 - <artifactId>jackson-mapper-asl</artifactId> 26 + <artifactId>jackson-mapper-asl</artifactId>
27 </dependency> 27 </dependency>
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>
......
...@@ -23,7 +23,8 @@ ...@@ -23,7 +23,8 @@
23 <module>foo</module> 23 <module>foo</module>
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");
...@@ -94,14 +92,14 @@ public class HostManagerTest { ...@@ -94,14 +92,14 @@ public class HostManagerTest {
94 provider = new TestHostProvider(); 92 provider = new TestHostProvider();
95 providerService = registry.register(provider); 93 providerService = registry.register(provider);
96 assertTrue("provider should be registered", 94 assertTrue("provider should be registered",
97 - registry.getProviders().contains(provider.id())); 95 + registry.getProviders().contains(provider.id()));
98 } 96 }
99 97
100 @After 98 @After
101 public void tearDown() { 99 public void tearDown() {
102 registry.unregister(provider); 100 registry.unregister(provider);
103 assertFalse("provider should not be registered", 101 assertFalse("provider should not be registered",
104 - registry.getProviders().contains(provider.id())); 102 + registry.getProviders().contains(provider.id()));
105 103
106 mgr.removeListener(listener); 104 mgr.removeListener(listener);
107 mgr.deactivate(); 105 mgr.deactivate();
...@@ -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);
...@@ -210,7 +208,7 @@ public class HostManagerTest { ...@@ -210,7 +208,7 @@ public class HostManagerTest {
210 @Test 208 @Test
211 public void bindAddressesToPort() { 209 public void bindAddressesToPort() {
212 PortAddresses add1 = new PortAddresses(CP1, 210 PortAddresses add1 = new PortAddresses(CP1,
213 - Sets.newHashSet(PREFIX1, PREFIX2), MAC1); 211 + Sets.newHashSet(PREFIX1, PREFIX2), MAC1);
214 212
215 mgr.bindAddressesToPort(add1); 213 mgr.bindAddressesToPort(add1);
216 PortAddresses storedAddresses = mgr.getAddressBindingsForPort(CP1); 214 PortAddresses storedAddresses = mgr.getAddressBindingsForPort(CP1);
...@@ -241,7 +239,7 @@ public class HostManagerTest { ...@@ -241,7 +239,7 @@ public class HostManagerTest {
241 @Test 239 @Test
242 public void unbindAddressesFromPort() { 240 public void unbindAddressesFromPort() {
243 PortAddresses add1 = new PortAddresses(CP1, 241 PortAddresses add1 = new PortAddresses(CP1,
244 - Sets.newHashSet(PREFIX1, PREFIX2), MAC1); 242 + Sets.newHashSet(PREFIX1, PREFIX2), MAC1);
245 243
246 mgr.bindAddressesToPort(add1); 244 mgr.bindAddressesToPort(add1);
247 PortAddresses storedAddresses = mgr.getAddressBindingsForPort(CP1); 245 PortAddresses storedAddresses = mgr.getAddressBindingsForPort(CP1);
...@@ -250,7 +248,7 @@ public class HostManagerTest { ...@@ -250,7 +248,7 @@ public class HostManagerTest {
250 assertNotNull(storedAddresses.mac()); 248 assertNotNull(storedAddresses.mac());
251 249
252 PortAddresses rem1 = new PortAddresses(CP1, 250 PortAddresses rem1 = new PortAddresses(CP1,
253 - Sets.newHashSet(PREFIX1), null); 251 + Sets.newHashSet(PREFIX1), null);
254 252
255 mgr.unbindAddressesFromPort(rem1); 253 mgr.unbindAddressesFromPort(rem1);
256 storedAddresses = mgr.getAddressBindingsForPort(CP1); 254 storedAddresses = mgr.getAddressBindingsForPort(CP1);
...@@ -267,7 +265,7 @@ public class HostManagerTest { ...@@ -267,7 +265,7 @@ public class HostManagerTest {
267 assertNull(storedAddresses.mac()); 265 assertNull(storedAddresses.mac());
268 266
269 PortAddresses rem3 = new PortAddresses(CP1, 267 PortAddresses rem3 = new PortAddresses(CP1,
270 - Sets.newHashSet(PREFIX2), MAC1); 268 + Sets.newHashSet(PREFIX2), MAC1);
271 269
272 mgr.unbindAddressesFromPort(rem3); 270 mgr.unbindAddressesFromPort(rem3);
273 storedAddresses = mgr.getAddressBindingsForPort(CP1); 271 storedAddresses = mgr.getAddressBindingsForPort(CP1);
...@@ -279,7 +277,7 @@ public class HostManagerTest { ...@@ -279,7 +277,7 @@ public class HostManagerTest {
279 @Test 277 @Test
280 public void clearAddresses() { 278 public void clearAddresses() {
281 PortAddresses add1 = new PortAddresses(CP1, 279 PortAddresses add1 = new PortAddresses(CP1,
282 - Sets.newHashSet(PREFIX1, PREFIX2), MAC1); 280 + Sets.newHashSet(PREFIX1, PREFIX2), MAC1);
283 281
284 mgr.bindAddressesToPort(add1); 282 mgr.bindAddressesToPort(add1);
285 PortAddresses storedAddresses = mgr.getAddressBindingsForPort(CP1); 283 PortAddresses storedAddresses = mgr.getAddressBindingsForPort(CP1);
...@@ -297,7 +295,7 @@ public class HostManagerTest { ...@@ -297,7 +295,7 @@ public class HostManagerTest {
297 @Test 295 @Test
298 public void getAddressBindingsForPort() { 296 public void getAddressBindingsForPort() {
299 PortAddresses add1 = new PortAddresses(CP1, 297 PortAddresses add1 = new PortAddresses(CP1,
300 - Sets.newHashSet(PREFIX1, PREFIX2), MAC1); 298 + Sets.newHashSet(PREFIX1, PREFIX2), MAC1);
301 299
302 mgr.bindAddressesToPort(add1); 300 mgr.bindAddressesToPort(add1);
303 PortAddresses storedAddresses = mgr.getAddressBindingsForPort(CP1); 301 PortAddresses storedAddresses = mgr.getAddressBindingsForPort(CP1);
...@@ -314,7 +312,7 @@ public class HostManagerTest { ...@@ -314,7 +312,7 @@ public class HostManagerTest {
314 assertTrue(storedAddresses.isEmpty()); 312 assertTrue(storedAddresses.isEmpty());
315 313
316 PortAddresses add1 = new PortAddresses(CP1, 314 PortAddresses add1 = new PortAddresses(CP1,
317 - Sets.newHashSet(PREFIX1, PREFIX2), MAC1); 315 + Sets.newHashSet(PREFIX1, PREFIX2), MAC1);
318 316
319 mgr.bindAddressesToPort(add1); 317 mgr.bindAddressesToPort(add1);
320 318
...@@ -323,7 +321,7 @@ public class HostManagerTest { ...@@ -323,7 +321,7 @@ public class HostManagerTest {
323 assertTrue(storedAddresses.size() == 1); 321 assertTrue(storedAddresses.size() == 1);
324 322
325 PortAddresses add2 = new PortAddresses(CP2, 323 PortAddresses add2 = new PortAddresses(CP2,
326 - Sets.newHashSet(PREFIX3), MAC2); 324 + Sets.newHashSet(PREFIX3), MAC2);
327 325
328 mgr.bindAddressesToPort(add2); 326 mgr.bindAddressesToPort(add2);
329 327
......
...@@ -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 +}
...@@ -5,8 +5,7 @@ import com.google.common.collect.ImmutableList; ...@@ -5,8 +5,7 @@ import com.google.common.collect.ImmutableList;
5 import com.google.common.collect.Maps; 5 import com.google.common.collect.Maps;
6 import com.google.common.collect.Sets; 6 import com.google.common.collect.Sets;
7 7
8 -import org.apache.commons.lang3.concurrent.ConcurrentException; 8 +import org.apache.commons.lang3.RandomUtils;
9 -import org.apache.commons.lang3.concurrent.ConcurrentInitializer;
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;
...@@ -14,6 +13,8 @@ import org.apache.felix.scr.annotations.Reference; ...@@ -14,6 +13,8 @@ import org.apache.felix.scr.annotations.Reference;
14 import org.apache.felix.scr.annotations.ReferenceCardinality; 13 import org.apache.felix.scr.annotations.ReferenceCardinality;
15 import org.apache.felix.scr.annotations.Service; 14 import org.apache.felix.scr.annotations.Service;
16 import org.onlab.onos.cluster.ClusterService; 15 import org.onlab.onos.cluster.ClusterService;
16 +import org.onlab.onos.cluster.ControllerNode;
17 +import org.onlab.onos.cluster.NodeId;
17 import org.onlab.onos.net.AnnotationsUtil; 18 import org.onlab.onos.net.AnnotationsUtil;
18 import org.onlab.onos.net.DefaultAnnotations; 19 import org.onlab.onos.net.DefaultAnnotations;
19 import org.onlab.onos.net.DefaultDevice; 20 import org.onlab.onos.net.DefaultDevice;
...@@ -23,9 +24,6 @@ import org.onlab.onos.net.Device.Type; ...@@ -23,9 +24,6 @@ import org.onlab.onos.net.Device.Type;
23 import org.onlab.onos.net.DeviceId; 24 import org.onlab.onos.net.DeviceId;
24 import org.onlab.onos.net.Port; 25 import org.onlab.onos.net.Port;
25 import org.onlab.onos.net.PortNumber; 26 import org.onlab.onos.net.PortNumber;
26 -import org.onlab.onos.net.SparseAnnotations;
27 -import org.onlab.onos.net.device.DefaultDeviceDescription;
28 -import org.onlab.onos.net.device.DefaultPortDescription;
29 import org.onlab.onos.net.device.DeviceDescription; 27 import org.onlab.onos.net.device.DeviceDescription;
30 import org.onlab.onos.net.device.DeviceEvent; 28 import org.onlab.onos.net.device.DeviceEvent;
31 import org.onlab.onos.net.device.DeviceStore; 29 import org.onlab.onos.net.device.DeviceStore;
...@@ -35,21 +33,25 @@ import org.onlab.onos.net.provider.ProviderId; ...@@ -35,21 +33,25 @@ import org.onlab.onos.net.provider.ProviderId;
35 import org.onlab.onos.store.AbstractStore; 33 import org.onlab.onos.store.AbstractStore;
36 import org.onlab.onos.store.ClockService; 34 import org.onlab.onos.store.ClockService;
37 import org.onlab.onos.store.Timestamp; 35 import org.onlab.onos.store.Timestamp;
38 -import org.onlab.onos.store.Timestamped;
39 import org.onlab.onos.store.cluster.messaging.ClusterCommunicationService; 36 import org.onlab.onos.store.cluster.messaging.ClusterCommunicationService;
40 import org.onlab.onos.store.cluster.messaging.ClusterMessage; 37 import org.onlab.onos.store.cluster.messaging.ClusterMessage;
41 import org.onlab.onos.store.cluster.messaging.ClusterMessageHandler; 38 import org.onlab.onos.store.cluster.messaging.ClusterMessageHandler;
42 -import org.onlab.onos.store.common.impl.DeviceMastershipBasedTimestamp; 39 +import org.onlab.onos.store.cluster.messaging.MessageSubject;
43 -import org.onlab.onos.store.common.impl.MastershipBasedTimestampSerializer; 40 +import org.onlab.onos.store.common.impl.Timestamped;
44 -import org.onlab.onos.store.serializers.KryoPoolUtil; 41 +import org.onlab.onos.store.device.impl.peermsg.DeviceAntiEntropyAdvertisement;
42 +import org.onlab.onos.store.device.impl.peermsg.DeviceFragmentId;
43 +import org.onlab.onos.store.device.impl.peermsg.PortFragmentId;
45 import org.onlab.onos.store.serializers.KryoSerializer; 44 import org.onlab.onos.store.serializers.KryoSerializer;
45 +import org.onlab.onos.store.serializers.DistributedStoreSerializers;
46 import org.onlab.util.KryoPool; 46 import org.onlab.util.KryoPool;
47 import org.onlab.util.NewConcurrentHashMap; 47 import org.onlab.util.NewConcurrentHashMap;
48 import org.slf4j.Logger; 48 import org.slf4j.Logger;
49 49
50 import java.io.IOException; 50 import java.io.IOException;
51 import java.util.ArrayList; 51 import java.util.ArrayList;
52 +import java.util.Collection;
52 import java.util.Collections; 53 import java.util.Collections;
54 +import java.util.HashMap;
53 import java.util.HashSet; 55 import java.util.HashSet;
54 import java.util.Iterator; 56 import java.util.Iterator;
55 import java.util.List; 57 import java.util.List;
...@@ -57,19 +59,21 @@ import java.util.Map; ...@@ -57,19 +59,21 @@ import java.util.Map;
57 import java.util.Map.Entry; 59 import java.util.Map.Entry;
58 import java.util.Objects; 60 import java.util.Objects;
59 import java.util.Set; 61 import java.util.Set;
60 -import java.util.concurrent.ConcurrentHashMap;
61 import java.util.concurrent.ConcurrentMap; 62 import java.util.concurrent.ConcurrentMap;
62 -import java.util.concurrent.atomic.AtomicReference; 63 +import java.util.concurrent.ScheduledExecutorService;
64 +import java.util.concurrent.TimeUnit;
63 65
64 import static com.google.common.base.Preconditions.checkArgument; 66 import static com.google.common.base.Preconditions.checkArgument;
65 -import static com.google.common.base.Preconditions.checkNotNull;
66 import static com.google.common.base.Predicates.notNull; 67 import static com.google.common.base.Predicates.notNull;
67 import static org.onlab.onos.net.device.DeviceEvent.Type.*; 68 import static org.onlab.onos.net.device.DeviceEvent.Type.*;
68 import static org.slf4j.LoggerFactory.getLogger; 69 import static org.slf4j.LoggerFactory.getLogger;
69 import static org.apache.commons.lang3.concurrent.ConcurrentUtils.createIfAbsentUnchecked; 70 import static org.apache.commons.lang3.concurrent.ConcurrentUtils.createIfAbsentUnchecked;
70 import static org.onlab.onos.net.DefaultAnnotations.merge; 71 import static org.onlab.onos.net.DefaultAnnotations.merge;
71 -import static org.onlab.onos.net.DefaultAnnotations.union;
72 import static com.google.common.base.Verify.verify; 72 import static com.google.common.base.Verify.verify;
73 +import static org.onlab.util.Tools.namedThreads;
74 +import static java.util.concurrent.Executors.newSingleThreadScheduledExecutor;
75 +import static org.onlab.onos.store.device.impl.GossipDeviceStoreMessageSubjects.DEVICE_ADVERTISE;
76 +import static org.onlab.onos.store.common.impl.ControllerNodeToNodeId.toNodeId;
73 77
74 // TODO: give me a better name 78 // TODO: give me a better name
75 /** 79 /**
...@@ -86,8 +90,9 @@ public class GossipDeviceStore ...@@ -86,8 +90,9 @@ public class GossipDeviceStore
86 90
87 public static final String DEVICE_NOT_FOUND = "Device with ID %s not found"; 91 public static final String DEVICE_NOT_FOUND = "Device with ID %s not found";
88 92
89 - // TODO: Check if inner Map can be replaced with plain Map 93 + // TODO: Check if inner Map can be replaced with plain Map.
90 // innerMap is used to lock a Device, thus instance should never be replaced. 94 // innerMap is used to lock a Device, thus instance should never be replaced.
95 +
91 // collection of Description given from various providers 96 // collection of Description given from various providers
92 private final ConcurrentMap<DeviceId, 97 private final ConcurrentMap<DeviceId,
93 ConcurrentMap<ProviderId, DeviceDescriptions>> 98 ConcurrentMap<ProviderId, DeviceDescriptions>>
...@@ -117,21 +122,23 @@ public class GossipDeviceStore ...@@ -117,21 +122,23 @@ public class GossipDeviceStore
117 @Override 122 @Override
118 protected void setupKryoPool() { 123 protected void setupKryoPool() {
119 serializerPool = KryoPool.newBuilder() 124 serializerPool = KryoPool.newBuilder()
120 - .register(KryoPoolUtil.API) 125 + .register(DistributedStoreSerializers.COMMON)
126 +
121 .register(InternalDeviceEvent.class, new InternalDeviceEventSerializer()) 127 .register(InternalDeviceEvent.class, new InternalDeviceEventSerializer())
122 .register(InternalDeviceOfflineEvent.class, new InternalDeviceOfflineEventSerializer()) 128 .register(InternalDeviceOfflineEvent.class, new InternalDeviceOfflineEventSerializer())
123 .register(InternalDeviceRemovedEvent.class) 129 .register(InternalDeviceRemovedEvent.class)
124 .register(InternalPortEvent.class, new InternalPortEventSerializer()) 130 .register(InternalPortEvent.class, new InternalPortEventSerializer())
125 .register(InternalPortStatusEvent.class, new InternalPortStatusEventSerializer()) 131 .register(InternalPortStatusEvent.class, new InternalPortStatusEventSerializer())
126 - .register(Timestamp.class) 132 + .register(DeviceAntiEntropyAdvertisement.class)
127 - .register(Timestamped.class) 133 + .register(DeviceFragmentId.class)
128 - .register(DeviceMastershipBasedTimestamp.class, new MastershipBasedTimestampSerializer()) 134 + .register(PortFragmentId.class)
129 .build() 135 .build()
130 .populate(1); 136 .populate(1);
131 } 137 }
132 -
133 }; 138 };
134 139
140 + private ScheduledExecutorService executor;
141 +
135 @Activate 142 @Activate
136 public void activate() { 143 public void activate() {
137 clusterCommunicator.addSubscriber( 144 clusterCommunicator.addSubscriber(
...@@ -144,11 +151,35 @@ public class GossipDeviceStore ...@@ -144,11 +151,35 @@ public class GossipDeviceStore
144 GossipDeviceStoreMessageSubjects.PORT_UPDATE, new InternalPortEventListener()); 151 GossipDeviceStoreMessageSubjects.PORT_UPDATE, new InternalPortEventListener());
145 clusterCommunicator.addSubscriber( 152 clusterCommunicator.addSubscriber(
146 GossipDeviceStoreMessageSubjects.PORT_STATUS_UPDATE, new InternalPortStatusEventListener()); 153 GossipDeviceStoreMessageSubjects.PORT_STATUS_UPDATE, new InternalPortStatusEventListener());
154 + clusterCommunicator.addSubscriber(
155 + GossipDeviceStoreMessageSubjects.DEVICE_ADVERTISE, new InternalDeviceAdvertisementListener());
156 +
157 + executor =
158 + newSingleThreadScheduledExecutor(namedThreads("anti-entropy-%d"));
159 +
160 + // TODO: Make these configurable
161 + long initialDelaySec = 5;
162 + long periodSec = 5;
163 + // start anti-entropy thread
164 + executor.scheduleAtFixedRate(new SendAdvertisementTask(),
165 + initialDelaySec, periodSec, TimeUnit.SECONDS);
166 +
147 log.info("Started"); 167 log.info("Started");
148 } 168 }
149 169
150 @Deactivate 170 @Deactivate
151 public void deactivate() { 171 public void deactivate() {
172 +
173 + executor.shutdownNow();
174 + try {
175 + boolean timedout = executor.awaitTermination(5, TimeUnit.SECONDS);
176 + if (timedout) {
177 + log.error("Timeout during executor shutdown");
178 + }
179 + } catch (InterruptedException e) {
180 + log.error("Error during executor shutdown", e);
181 + }
182 +
152 deviceDescs.clear(); 183 deviceDescs.clear();
153 devices.clear(); 184 devices.clear();
154 devicePorts.clear(); 185 devicePorts.clear();
...@@ -543,14 +574,14 @@ public class GossipDeviceStore ...@@ -543,14 +574,14 @@ public class GossipDeviceStore
543 574
544 final Timestamped<PortDescription> existingPortDesc = descs.getPortDesc(number); 575 final Timestamped<PortDescription> existingPortDesc = descs.getPortDesc(number);
545 if (existingPortDesc == null || 576 if (existingPortDesc == null ||
546 - deltaDesc == existingPortDesc ||
547 deltaDesc.isNewer(existingPortDesc)) { 577 deltaDesc.isNewer(existingPortDesc)) {
548 // on new port or valid update 578 // on new port or valid update
549 // update description 579 // update description
550 descs.putPortDesc(deltaDesc); 580 descs.putPortDesc(deltaDesc);
551 newPort = composePort(device, number, descsMap); 581 newPort = composePort(device, number, descsMap);
552 } else { 582 } else {
553 - // outdated event, ignored. 583 + // same or outdated event, ignored.
584 + log.trace("ignore same or outdated {} >= {}", existingPortDesc, deltaDesc);
554 return null; 585 return null;
555 } 586 }
556 587
...@@ -627,6 +658,14 @@ public class GossipDeviceStore ...@@ -627,6 +658,14 @@ public class GossipDeviceStore
627 } 658 }
628 } 659 }
629 660
661 + /**
662 + * Checks if given timestamp is superseded by removal request
663 + * with more recent timestamp.
664 + *
665 + * @param deviceId identifier of a device
666 + * @param timestampToCheck timestamp of an event to check
667 + * @return true if device is already removed
668 + */
630 private boolean isDeviceRemoved(DeviceId deviceId, Timestamp timestampToCheck) { 669 private boolean isDeviceRemoved(DeviceId deviceId, Timestamp timestampToCheck) {
631 Timestamp removalTimestamp = removalRequest.get(deviceId); 670 Timestamp removalTimestamp = removalRequest.get(deviceId);
632 if (removalTimestamp != null && 671 if (removalTimestamp != null &&
...@@ -667,7 +706,7 @@ public class GossipDeviceStore ...@@ -667,7 +706,7 @@ public class GossipDeviceStore
667 continue; 706 continue;
668 } 707 }
669 // TODO: should keep track of Description timestamp 708 // TODO: should keep track of Description timestamp
670 - // and only merge conflicting keys when timestamp is newer 709 + // and only merge conflicting keys when timestamp is newer.
671 // Currently assuming there will never be a key conflict between 710 // Currently assuming there will never be a key conflict between
672 // providers 711 // providers
673 712
...@@ -708,7 +747,7 @@ public class GossipDeviceStore ...@@ -708,7 +747,7 @@ public class GossipDeviceStore
708 continue; 747 continue;
709 } 748 }
710 // TODO: should keep track of Description timestamp 749 // TODO: should keep track of Description timestamp
711 - // and only merge conflicting keys when timestamp is newer 750 + // and only merge conflicting keys when timestamp is newer.
712 // Currently assuming there will never be a key conflict between 751 // Currently assuming there will never be a key conflict between
713 // providers 752 // providers
714 753
...@@ -745,129 +784,258 @@ public class GossipDeviceStore ...@@ -745,129 +784,258 @@ public class GossipDeviceStore
745 return providerDescs.get(pid); 784 return providerDescs.get(pid);
746 } 785 }
747 786
748 - public static final class InitDeviceDescs 787 + // TODO: should we be throwing exception?
749 - implements ConcurrentInitializer<DeviceDescriptions> { 788 + private void unicastMessage(NodeId recipient, MessageSubject subject, Object event) throws IOException {
789 + ClusterMessage message = new ClusterMessage(
790 + clusterService.getLocalNode().id(),
791 + subject,
792 + SERIALIZER.encode(event));
793 + clusterCommunicator.unicast(message, recipient);
794 + }
750 795
751 - private final Timestamped<DeviceDescription> deviceDesc; 796 + // TODO: should we be throwing exception?
797 + private void broadcastMessage(MessageSubject subject, Object event) throws IOException {
798 + ClusterMessage message = new ClusterMessage(
799 + clusterService.getLocalNode().id(),
800 + subject,
801 + SERIALIZER.encode(event));
802 + clusterCommunicator.broadcast(message);
803 + }
752 804
753 - public InitDeviceDescs(Timestamped<DeviceDescription> deviceDesc) { 805 + private void notifyPeers(InternalDeviceEvent event) throws IOException {
754 - this.deviceDesc = checkNotNull(deviceDesc); 806 + broadcastMessage(GossipDeviceStoreMessageSubjects.DEVICE_UPDATE, event);
755 - }
756 - @Override
757 - public DeviceDescriptions get() throws ConcurrentException {
758 - return new DeviceDescriptions(deviceDesc);
759 - }
760 } 807 }
761 808
809 + private void notifyPeers(InternalDeviceOfflineEvent event) throws IOException {
810 + broadcastMessage(GossipDeviceStoreMessageSubjects.DEVICE_OFFLINE, event);
811 + }
762 812
763 - /** 813 + private void notifyPeers(InternalDeviceRemovedEvent event) throws IOException {
764 - * Collection of Description of a Device and it's Ports given from a Provider. 814 + broadcastMessage(GossipDeviceStoreMessageSubjects.DEVICE_REMOVED, event);
765 - */ 815 + }
766 - public static class DeviceDescriptions {
767 816
768 - private final AtomicReference<Timestamped<DeviceDescription>> deviceDesc; 817 + private void notifyPeers(InternalPortEvent event) throws IOException {
769 - private final ConcurrentMap<PortNumber, Timestamped<PortDescription>> portDescs; 818 + broadcastMessage(GossipDeviceStoreMessageSubjects.PORT_UPDATE, event);
819 + }
770 820
771 - public DeviceDescriptions(Timestamped<DeviceDescription> desc) { 821 + private void notifyPeers(InternalPortStatusEvent event) throws IOException {
772 - this.deviceDesc = new AtomicReference<>(checkNotNull(desc)); 822 + broadcastMessage(GossipDeviceStoreMessageSubjects.PORT_STATUS_UPDATE, event);
773 - this.portDescs = new ConcurrentHashMap<>(); 823 + }
774 - }
775 824
776 - Timestamp getLatestTimestamp() { 825 + private void notifyPeer(NodeId recipient, InternalDeviceEvent event) {
777 - Timestamp latest = deviceDesc.get().timestamp(); 826 + try {
778 - for (Timestamped<PortDescription> desc : portDescs.values()) { 827 + unicastMessage(recipient, GossipDeviceStoreMessageSubjects.DEVICE_UPDATE, event);
779 - if (desc.timestamp().compareTo(latest) > 0) { 828 + } catch (IOException e) {
780 - latest = desc.timestamp(); 829 + log.error("Failed to send" + event + " to " + recipient, e);
781 - }
782 - }
783 - return latest;
784 } 830 }
831 + }
785 832
786 - public Timestamped<DeviceDescription> getDeviceDesc() { 833 + private void notifyPeer(NodeId recipient, InternalDeviceOfflineEvent event) {
787 - return deviceDesc.get(); 834 + try {
835 + unicastMessage(recipient, GossipDeviceStoreMessageSubjects.DEVICE_OFFLINE, event);
836 + } catch (IOException e) {
837 + log.error("Failed to send" + event + " to " + recipient, e);
788 } 838 }
839 + }
789 840
790 - public Timestamped<PortDescription> getPortDesc(PortNumber number) { 841 + private void notifyPeer(NodeId recipient, InternalDeviceRemovedEvent event) {
791 - return portDescs.get(number); 842 + try {
843 + unicastMessage(recipient, GossipDeviceStoreMessageSubjects.DEVICE_REMOVED, event);
844 + } catch (IOException e) {
845 + log.error("Failed to send" + event + " to " + recipient, e);
792 } 846 }
847 + }
793 848
794 - /** 849 + private void notifyPeer(NodeId recipient, InternalPortEvent event) {
795 - * Puts DeviceDescription, merging annotations as necessary. 850 + try {
796 - * 851 + unicastMessage(recipient, GossipDeviceStoreMessageSubjects.PORT_UPDATE, event);
797 - * @param newDesc new DeviceDescription 852 + } catch (IOException e) {
798 - * @return previous DeviceDescription 853 + log.error("Failed to send" + event + " to " + recipient, e);
799 - */
800 - public synchronized Timestamped<DeviceDescription> putDeviceDesc(Timestamped<DeviceDescription> newDesc) {
801 - Timestamped<DeviceDescription> oldOne = deviceDesc.get();
802 - Timestamped<DeviceDescription> newOne = newDesc;
803 - if (oldOne != null) {
804 - SparseAnnotations merged = union(oldOne.value().annotations(),
805 - newDesc.value().annotations());
806 - newOne = new Timestamped<DeviceDescription>(
807 - new DefaultDeviceDescription(newDesc.value(), merged),
808 - newDesc.timestamp());
809 - }
810 - return deviceDesc.getAndSet(newOne);
811 - }
812 -
813 - /**
814 - * Puts PortDescription, merging annotations as necessary.
815 - *
816 - * @param newDesc new PortDescription
817 - * @return previous PortDescription
818 - */
819 - public synchronized Timestamped<PortDescription> putPortDesc(Timestamped<PortDescription> newDesc) {
820 - Timestamped<PortDescription> oldOne = portDescs.get(newDesc.value().portNumber());
821 - Timestamped<PortDescription> newOne = newDesc;
822 - if (oldOne != null) {
823 - SparseAnnotations merged = union(oldOne.value().annotations(),
824 - newDesc.value().annotations());
825 - newOne = new Timestamped<PortDescription>(
826 - new DefaultPortDescription(newDesc.value(), merged),
827 - newDesc.timestamp());
828 - }
829 - return portDescs.put(newOne.value().portNumber(), newOne);
830 } 854 }
831 } 855 }
832 856
833 - private void notifyPeers(InternalDeviceEvent event) throws IOException { 857 + private void notifyPeer(NodeId recipient, InternalPortStatusEvent event) {
834 - ClusterMessage message = new ClusterMessage( 858 + try {
835 - clusterService.getLocalNode().id(), 859 + unicastMessage(recipient, GossipDeviceStoreMessageSubjects.PORT_STATUS_UPDATE, event);
836 - GossipDeviceStoreMessageSubjects.DEVICE_UPDATE, 860 + } catch (IOException e) {
837 - SERIALIZER.encode(event)); 861 + log.error("Failed to send" + event + " to " + recipient, e);
838 - clusterCommunicator.broadcast(message); 862 + }
839 } 863 }
840 864
841 - private void notifyPeers(InternalDeviceOfflineEvent event) throws IOException { 865 + private DeviceAntiEntropyAdvertisement createAdvertisement() {
842 - ClusterMessage message = new ClusterMessage( 866 + final NodeId self = clusterService.getLocalNode().id();
843 - clusterService.getLocalNode().id(),
844 - GossipDeviceStoreMessageSubjects.DEVICE_OFFLINE,
845 - SERIALIZER.encode(event));
846 - clusterCommunicator.broadcast(message);
847 - }
848 867
849 - private void notifyPeers(InternalDeviceRemovedEvent event) throws IOException { 868 + Map<DeviceFragmentId, Timestamp> devices = new HashMap<>(deviceDescs.size());
850 - ClusterMessage message = new ClusterMessage( 869 + final int portsPerDevice = 8; // random guess to minimize reallocation
851 - clusterService.getLocalNode().id(), 870 + Map<PortFragmentId, Timestamp> ports = new HashMap<>(devices.size() * portsPerDevice);
852 - GossipDeviceStoreMessageSubjects.DEVICE_REMOVED, 871 + Map<DeviceId, Timestamp> offline = new HashMap<>(devices.size());
853 - SERIALIZER.encode(event));
854 - clusterCommunicator.broadcast(message);
855 - }
856 872
857 - private void notifyPeers(InternalPortEvent event) throws IOException { 873 + for (Entry<DeviceId, ConcurrentMap<ProviderId, DeviceDescriptions>>
858 - ClusterMessage message = new ClusterMessage( 874 + provs : deviceDescs.entrySet()) {
859 - clusterService.getLocalNode().id(), 875 +
860 - GossipDeviceStoreMessageSubjects.PORT_UPDATE, 876 + final DeviceId deviceId = provs.getKey();
861 - SERIALIZER.encode(event)); 877 + final ConcurrentMap<ProviderId, DeviceDescriptions> devDescs = provs.getValue();
862 - clusterCommunicator.broadcast(message); 878 + synchronized (devDescs) {
879 +
880 + offline.put(deviceId, this.offline.get(deviceId));
881 +
882 + for (Entry<ProviderId, DeviceDescriptions>
883 + prov : devDescs.entrySet()) {
884 +
885 + final ProviderId provId = prov.getKey();
886 + final DeviceDescriptions descs = prov.getValue();
887 +
888 + devices.put(new DeviceFragmentId(deviceId, provId),
889 + descs.getDeviceDesc().timestamp());
890 +
891 + for (Entry<PortNumber, Timestamped<PortDescription>>
892 + portDesc : descs.getPortDescs().entrySet()) {
893 +
894 + final PortNumber number = portDesc.getKey();
895 + ports.put(new PortFragmentId(deviceId, provId, number),
896 + portDesc.getValue().timestamp());
897 + }
898 + }
899 + }
900 + }
901 +
902 + return new DeviceAntiEntropyAdvertisement(self, devices, ports, offline);
863 } 903 }
864 904
865 - private void notifyPeers(InternalPortStatusEvent event) throws IOException { 905 + /**
866 - ClusterMessage message = new ClusterMessage( 906 + * Responds to anti-entropy advertisement message.
867 - clusterService.getLocalNode().id(), 907 + * <P>
868 - GossipDeviceStoreMessageSubjects.PORT_STATUS_UPDATE, 908 + * Notify sender about out-dated information using regular replication message.
869 - SERIALIZER.encode(event)); 909 + * Send back advertisement to sender if not in sync.
870 - clusterCommunicator.broadcast(message); 910 + *
911 + * @param advertisement to respond to
912 + */
913 + private void handleAdvertisement(DeviceAntiEntropyAdvertisement advertisement) {
914 +
915 + final NodeId sender = advertisement.sender();
916 +
917 + Map<DeviceFragmentId, Timestamp> devAds = new HashMap<>(advertisement.deviceFingerPrints());
918 + Map<PortFragmentId, Timestamp> portAds = new HashMap<>(advertisement.ports());
919 + Map<DeviceId, Timestamp> offlineAds = new HashMap<>(advertisement.offline());
920 +
921 + // Fragments to request
922 + Collection<DeviceFragmentId> reqDevices = new ArrayList<>();
923 + Collection<PortFragmentId> reqPorts = new ArrayList<>();
924 +
925 + for (Entry<DeviceId, ConcurrentMap<ProviderId, DeviceDescriptions>> de : deviceDescs.entrySet()) {
926 + final DeviceId deviceId = de.getKey();
927 + final Map<ProviderId, DeviceDescriptions> lDevice = de.getValue();
928 +
929 + synchronized (lDevice) {
930 + // latestTimestamp across provider
931 + // Note: can be null initially
932 + Timestamp localLatest = offline.get(deviceId);
933 +
934 + // handle device Ads
935 + for (Entry<ProviderId, DeviceDescriptions> prov : lDevice.entrySet()) {
936 + final ProviderId provId = prov.getKey();
937 + final DeviceDescriptions lDeviceDescs = prov.getValue();
938 +
939 + final DeviceFragmentId devFragId = new DeviceFragmentId(deviceId, provId);
940 +
941 +
942 + Timestamped<DeviceDescription> lProvDevice = lDeviceDescs.getDeviceDesc();
943 + Timestamp advDevTimestamp = devAds.get(devFragId);
944 +
945 + if (advDevTimestamp == null || lProvDevice.isNewer(advDevTimestamp)) {
946 + // remote does not have it or outdated, suggest
947 + notifyPeer(sender, new InternalDeviceEvent(provId, deviceId, lProvDevice));
948 + } else if (!lProvDevice.timestamp().equals(advDevTimestamp)) {
949 + // local is outdated, request
950 + reqDevices.add(devFragId);
951 + }
952 +
953 + // handle port Ads
954 + for (Entry<PortNumber, Timestamped<PortDescription>>
955 + pe : lDeviceDescs.getPortDescs().entrySet()) {
956 +
957 + final PortNumber num = pe.getKey();
958 + final Timestamped<PortDescription> lPort = pe.getValue();
959 +
960 + final PortFragmentId portFragId = new PortFragmentId(deviceId, provId, num);
961 +
962 + Timestamp advPortTimestamp = portAds.get(portFragId);
963 + if (advPortTimestamp == null || lPort.isNewer(advPortTimestamp)) {
964 + // remote does not have it or outdated, suggest
965 + notifyPeer(sender, new InternalPortStatusEvent(provId, deviceId, lPort));
966 + } else if (!lPort.timestamp().equals(advPortTimestamp)) {
967 + // local is outdated, request
968 + log.trace("need update {} < {}", lPort.timestamp(), advPortTimestamp);
969 + reqPorts.add(portFragId);
970 + }
971 +
972 + // remove port Ad already processed
973 + portAds.remove(portFragId);
974 + } // end local port loop
975 +
976 + // remove device Ad already processed
977 + devAds.remove(devFragId);
978 +
979 + // find latest and update
980 + final Timestamp providerLatest = lDeviceDescs.getLatestTimestamp();
981 + if (localLatest == null ||
982 + providerLatest.compareTo(localLatest) > 0) {
983 + localLatest = providerLatest;
984 + }
985 + } // end local provider loop
986 +
987 + // checking if remote timestamp is more recent.
988 + Timestamp rOffline = offlineAds.get(deviceId);
989 + if (rOffline != null &&
990 + rOffline.compareTo(localLatest) > 0) {
991 + // remote offline timestamp suggests that the
992 + // device is off-line
993 + markOfflineInternal(deviceId, rOffline);
994 + }
995 +
996 + Timestamp lOffline = offline.get(deviceId);
997 + if (lOffline != null && rOffline == null) {
998 + // locally offline, but remote is online, suggest offline
999 + notifyPeer(sender, new InternalDeviceOfflineEvent(deviceId, lOffline));
1000 + }
1001 +
1002 + // remove device offline Ad already processed
1003 + offlineAds.remove(deviceId);
1004 + } // end local device loop
1005 + } // device lock
1006 +
1007 + // If there is any Ads left, request them
1008 + log.trace("Ads left {}, {}", devAds, portAds);
1009 + reqDevices.addAll(devAds.keySet());
1010 + reqPorts.addAll(portAds.keySet());
1011 +
1012 + if (reqDevices.isEmpty() && reqPorts.isEmpty()) {
1013 + log.trace("Nothing to request to remote peer {}", sender);
1014 + return;
1015 + }
1016 +
1017 + log.info("Need to sync {} {}", reqDevices, reqPorts);
1018 +
1019 + // 2-way Anti-Entropy for now
1020 + try {
1021 + unicastMessage(sender, DEVICE_ADVERTISE, createAdvertisement());
1022 + } catch (IOException e) {
1023 + log.error("Failed to send response advertisement to " + sender, e);
1024 + }
1025 +
1026 +// Sketch of 3-way Anti-Entropy
1027 +// DeviceAntiEntropyRequest request = new DeviceAntiEntropyRequest(self, reqDevices, reqPorts);
1028 +// ClusterMessage message = new ClusterMessage(
1029 +// clusterService.getLocalNode().id(),
1030 +// GossipDeviceStoreMessageSubjects.DEVICE_REQUEST,
1031 +// SERIALIZER.encode(request));
1032 +//
1033 +// try {
1034 +// clusterCommunicator.unicast(message, advertisement.sender());
1035 +// } catch (IOException e) {
1036 +// log.error("Failed to send advertisement reply to "
1037 +// + advertisement.sender(), e);
1038 +// }
871 } 1039 }
872 1040
873 private void notifyDelegateIfNotNull(DeviceEvent event) { 1041 private void notifyDelegateIfNotNull(DeviceEvent event) {
...@@ -876,6 +1044,54 @@ public class GossipDeviceStore ...@@ -876,6 +1044,54 @@ public class GossipDeviceStore
876 } 1044 }
877 } 1045 }
878 1046
1047 + private final class SendAdvertisementTask implements Runnable {
1048 +
1049 + @Override
1050 + public void run() {
1051 + if (Thread.currentThread().isInterrupted()) {
1052 + log.info("Interrupted, quitting");
1053 + return;
1054 + }
1055 +
1056 + try {
1057 + final NodeId self = clusterService.getLocalNode().id();
1058 + Set<ControllerNode> nodes = clusterService.getNodes();
1059 +
1060 + ImmutableList<NodeId> nodeIds = FluentIterable.from(nodes)
1061 + .transform(toNodeId())
1062 + .toList();
1063 +
1064 + if (nodeIds.size() == 1 && nodeIds.get(0).equals(self)) {
1065 + log.info("No other peers in the cluster.");
1066 + return;
1067 + }
1068 +
1069 + NodeId peer;
1070 + do {
1071 + int idx = RandomUtils.nextInt(0, nodeIds.size());
1072 + peer = nodeIds.get(idx);
1073 + } while (peer.equals(self));
1074 +
1075 + DeviceAntiEntropyAdvertisement ad = createAdvertisement();
1076 +
1077 + if (Thread.currentThread().isInterrupted()) {
1078 + log.info("Interrupted, quitting");
1079 + return;
1080 + }
1081 +
1082 + try {
1083 + unicastMessage(peer, DEVICE_ADVERTISE, ad);
1084 + } catch (IOException e) {
1085 + log.error("Failed to send anti-entropy advertisement", e);
1086 + return;
1087 + }
1088 + } catch (Exception e) {
1089 + // catch all Exception to avoid Scheduled task being suppressed.
1090 + log.error("Exception thrown while sending advertisement", e);
1091 + }
1092 + }
1093 + }
1094 +
879 private class InternalDeviceEventListener implements ClusterMessageHandler { 1095 private class InternalDeviceEventListener implements ClusterMessageHandler {
880 @Override 1096 @Override
881 public void handle(ClusterMessage message) { 1097 public void handle(ClusterMessage message) {
...@@ -940,6 +1156,7 @@ public class GossipDeviceStore ...@@ -940,6 +1156,7 @@ public class GossipDeviceStore
940 1156
941 log.info("Received port status update event from peer: {}", message.sender()); 1157 log.info("Received port status update event from peer: {}", message.sender());
942 InternalPortStatusEvent event = (InternalPortStatusEvent) SERIALIZER.decode(message.payload()); 1158 InternalPortStatusEvent event = (InternalPortStatusEvent) SERIALIZER.decode(message.payload());
1159 + log.info("{}", event);
943 1160
944 ProviderId providerId = event.providerId(); 1161 ProviderId providerId = event.providerId();
945 DeviceId deviceId = event.deviceId(); 1162 DeviceId deviceId = event.deviceId();
...@@ -948,4 +1165,15 @@ public class GossipDeviceStore ...@@ -948,4 +1165,15 @@ public class GossipDeviceStore
948 notifyDelegateIfNotNull(updatePortStatusInternal(providerId, deviceId, portDescription)); 1165 notifyDelegateIfNotNull(updatePortStatusInternal(providerId, deviceId, portDescription));
949 } 1166 }
950 } 1167 }
1168 +
1169 + private final class InternalDeviceAdvertisementListener
1170 + implements ClusterMessageHandler {
1171 +
1172 + @Override
1173 + public void handle(ClusterMessage message) {
1174 + log.info("Received Device advertisement from peer: {}", message.sender());
1175 + DeviceAntiEntropyAdvertisement advertisement = SERIALIZER.decode(message.payload());
1176 + handleAdvertisement(advertisement);
1177 + }
1178 + }
951 } 1179 }
......
...@@ -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();
...@@ -72,8 +69,8 @@ implements HostStore { ...@@ -72,8 +69,8 @@ implements HostStore {
72 69
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 }
...@@ -82,12 +79,12 @@ implements HostStore { ...@@ -82,12 +79,12 @@ implements HostStore {
82 79
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(), 103 +
108 - host.ipAddresses()); 104 + if (host.ipAddresses().contains(descr.ipAddress())) {
109 - event = new HostEvent(HOST_MOVED, updated);
110 -
111 - } else if (!(host.ipAddresses().equals(descr.ipAddresses()))) {
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;
...@@ -35,4 +35,4 @@ public final class ClusterMessageSerializer extends Serializer<ClusterMessage> { ...@@ -35,4 +35,4 @@ public final class ClusterMessageSerializer extends Serializer<ClusterMessage> {
35 byte[] payload = input.readBytes(payloadSize); 35 byte[] payload = input.readBytes(payloadSize);
36 return new ClusterMessage(sender, subject, payload); 36 return new ClusterMessage(sender, subject, payload);
37 } 37 }
38 -}
...\ No newline at end of file ...\ No newline at end of file
38 +}
......
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();
...@@ -72,8 +69,8 @@ implements HostStore { ...@@ -72,8 +69,8 @@ implements HostStore {
72 69
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 }
...@@ -82,12 +79,12 @@ implements HostStore { ...@@ -82,12 +79,12 @@ implements HostStore {
82 79
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(), 103 +
108 - host.ipAddresses()); 104 + if (host.ipAddresses().contains(descr.ipAddress())) {
109 - event = new HostEvent(HOST_MOVED, updated);
110 -
111 - } else if (!(host.ipAddresses().equals(descr.ipAddresses()))) {
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 +}
...@@ -10,6 +10,7 @@ import org.junit.After; ...@@ -10,6 +10,7 @@ import org.junit.After;
10 import org.junit.Before; 10 import org.junit.Before;
11 import org.junit.BeforeClass; 11 import org.junit.BeforeClass;
12 import org.junit.Test; 12 import org.junit.Test;
13 +import org.onlab.onos.cluster.MastershipTerm;
13 import org.onlab.onos.cluster.NodeId; 14 import org.onlab.onos.cluster.NodeId;
14 import org.onlab.onos.net.Annotations; 15 import org.onlab.onos.net.Annotations;
15 import org.onlab.onos.net.ConnectPoint; 16 import org.onlab.onos.net.ConnectPoint;
...@@ -24,7 +25,6 @@ import org.onlab.onos.net.LinkKey; ...@@ -24,7 +25,6 @@ import org.onlab.onos.net.LinkKey;
24 import org.onlab.onos.net.MastershipRole; 25 import org.onlab.onos.net.MastershipRole;
25 import org.onlab.onos.net.PortNumber; 26 import org.onlab.onos.net.PortNumber;
26 import org.onlab.onos.net.SparseAnnotations; 27 import org.onlab.onos.net.SparseAnnotations;
27 -import org.onlab.onos.net.device.DeviceMastershipTerm;
28 import org.onlab.onos.net.provider.ProviderId; 28 import org.onlab.onos.net.provider.ProviderId;
29 import org.onlab.packet.IpAddress; 29 import org.onlab.packet.IpAddress;
30 import org.onlab.packet.IpPrefix; 30 import org.onlab.packet.IpPrefix;
...@@ -114,7 +114,7 @@ public class KryoSerializerTest { ...@@ -114,7 +114,7 @@ public class KryoSerializerTest {
114 testSerialized(PID); 114 testSerialized(PID);
115 testSerialized(PIDA); 115 testSerialized(PIDA);
116 testSerialized(new NodeId("bar")); 116 testSerialized(new NodeId("bar"));
117 - testSerialized(DeviceMastershipTerm.of(new NodeId("foo"), 2)); 117 + testSerialized(MastershipTerm.of(new NodeId("foo"), 2));
118 for (MastershipRole role : MastershipRole.values()) { 118 for (MastershipRole role : MastershipRole.values()) {
119 testSerialized(role); 119 testSerialized(role);
120 } 120 }
......
...@@ -2,8 +2,8 @@ package org.onlab.onos.store.trivial.impl; ...@@ -2,8 +2,8 @@ package org.onlab.onos.store.trivial.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.trivial.impl; 1 package org.onlab.onos.store.trivial.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
...@@ -51,7 +48,7 @@ public class SimpleHostStore ...@@ -51,7 +48,7 @@ public class SimpleHostStore
51 private final Logger log = getLogger(getClass()); 48 private final Logger log = getLogger(getClass());
52 49
53 // Host inventory 50 // Host inventory
54 - private final Map<HostId, Host> hosts = new ConcurrentHashMap<>(); 51 + private final Map<HostId, StoredHost> hosts = new ConcurrentHashMap<>(2000000, 0.75f, 16);
55 52
56 // Hosts tracked by their location 53 // Hosts tracked by their location
57 private final Multimap<ConnectPoint, Host> locations = HashMultimap.create(); 54 private final Multimap<ConnectPoint, Host> locations = HashMultimap.create();
...@@ -72,7 +69,7 @@ public class SimpleHostStore ...@@ -72,7 +69,7 @@ public class SimpleHostStore
72 @Override 69 @Override
73 public HostEvent createOrUpdateHost(ProviderId providerId, HostId hostId, 70 public HostEvent createOrUpdateHost(ProviderId providerId, HostId hostId,
74 HostDescription hostDescription) { 71 HostDescription hostDescription) {
75 - Host host = hosts.get(hostId); 72 + StoredHost host = hosts.get(hostId);
76 if (host == null) { 73 if (host == null) {
77 return createHost(providerId, hostId, hostDescription); 74 return createHost(providerId, hostId, hostDescription);
78 } 75 }
...@@ -82,11 +79,11 @@ public class SimpleHostStore ...@@ -82,11 +79,11 @@ public class SimpleHostStore
82 // creates a new host and sends HOST_ADDED 79 // creates a new host and sends HOST_ADDED
83 private HostEvent createHost(ProviderId providerId, HostId hostId, 80 private HostEvent createHost(ProviderId providerId, HostId hostId,
84 HostDescription descr) { 81 HostDescription descr) {
85 - DefaultHost newhost = new DefaultHost(providerId, hostId, 82 + StoredHost newhost = new StoredHost(providerId, hostId,
86 - descr.hwAddress(), 83 + descr.hwAddress(),
87 - descr.vlan(), 84 + descr.vlan(),
88 - descr.location(), 85 + descr.location(),
89 - descr.ipAddresses()); 86 + ImmutableSet.of(descr.ipAddress()));
90 synchronized (this) { 87 synchronized (this) {
91 hosts.put(hostId, newhost); 88 hosts.put(hostId, newhost);
92 locations.put(descr.location(), newhost); 89 locations.put(descr.location(), newhost);
...@@ -95,28 +92,24 @@ public class SimpleHostStore ...@@ -95,28 +92,24 @@ public class SimpleHostStore
95 } 92 }
96 93
97 // checks for type of update to host, sends appropriate event 94 // checks for type of update to host, sends appropriate event
98 - private HostEvent updateHost(ProviderId providerId, Host host, 95 + private HostEvent updateHost(ProviderId providerId, StoredHost host,
99 HostDescription descr) { 96 HostDescription descr) {
100 - DefaultHost updated;
101 HostEvent event; 97 HostEvent event;
102 if (!host.location().equals(descr.location())) { 98 if (!host.location().equals(descr.location())) {
103 - updated = new DefaultHost(providerId, host.id(), 99 + host.setLocation(descr.location());
104 - host.mac(), 100 + return new HostEvent(HOST_MOVED, host);
105 - host.vlan(), 101 + }
106 - descr.location(), 102 +
107 - host.ipAddresses()); 103 + if (host.ipAddresses().contains(descr.ipAddress())) {
108 - event = new HostEvent(HOST_MOVED, updated);
109 -
110 - } else if (!(host.ipAddresses().equals(descr.ipAddresses()))) {
111 - updated = new DefaultHost(providerId, host.id(),
112 - host.mac(),
113 - host.vlan(),
114 - descr.location(),
115 - descr.ipAddresses());
116 - event = new HostEvent(HOST_UPDATED, updated);
117 - } else {
118 return null; 104 return null;
119 } 105 }
106 +
107 + Set<IpPrefix> addresses = new HashSet<>(host.ipAddresses());
108 + addresses.add(descr.ipAddress());
109 + StoredHost updated = new StoredHost(providerId, host.id(),
110 + host.mac(), host.vlan(),
111 + descr.location(), addresses);
112 + event = new HostEvent(HOST_UPDATED, updated);
120 synchronized (this) { 113 synchronized (this) {
121 hosts.put(host.id(), updated); 114 hosts.put(host.id(), updated);
122 locations.remove(host.location(), host); 115 locations.remove(host.location(), host);
...@@ -144,7 +137,7 @@ public class SimpleHostStore ...@@ -144,7 +137,7 @@ public class SimpleHostStore
144 137
145 @Override 138 @Override
146 public Iterable<Host> getHosts() { 139 public Iterable<Host> getHosts() {
147 - return Collections.unmodifiableSet(new HashSet<>(hosts.values())); 140 + return ImmutableSet.<Host>copyOf(hosts.values());
148 } 141 }
149 142
150 @Override 143 @Override
...@@ -274,4 +267,35 @@ public class SimpleHostStore ...@@ -274,4 +267,35 @@ public class SimpleHostStore
274 return addresses; 267 return addresses;
275 } 268 }
276 269
270 + // Auxiliary extension to allow location to mutate.
271 + private class StoredHost extends DefaultHost {
272 + private HostLocation location;
273 +
274 + /**
275 + * Creates an end-station host using the supplied information.
276 + *
277 + * @param providerId provider identity
278 + * @param id host identifier
279 + * @param mac host MAC address
280 + * @param vlan host VLAN identifier
281 + * @param location host location
282 + * @param ips host IP addresses
283 + * @param annotations optional key/value annotations
284 + */
285 + public StoredHost(ProviderId providerId, HostId id,
286 + MacAddress mac, VlanId vlan, HostLocation location,
287 + Set<IpPrefix> ips, Annotations... annotations) {
288 + super(providerId, id, mac, vlan, location, ips, annotations);
289 + this.location = location;
290 + }
291 +
292 + void setLocation(HostLocation location) {
293 + this.location = location;
294 + }
295 +
296 + @Override
297 + public HostLocation location() {
298 + return location;
299 + }
300 + }
277 } 301 }
......
...@@ -15,18 +15,18 @@ import org.apache.felix.scr.annotations.Deactivate; ...@@ -15,18 +15,18 @@ import org.apache.felix.scr.annotations.Deactivate;
15 import org.apache.felix.scr.annotations.Service; 15 import org.apache.felix.scr.annotations.Service;
16 import org.onlab.onos.cluster.ControllerNode; 16 import org.onlab.onos.cluster.ControllerNode;
17 import org.onlab.onos.cluster.DefaultControllerNode; 17 import org.onlab.onos.cluster.DefaultControllerNode;
18 +import org.onlab.onos.cluster.MastershipEvent;
19 +import org.onlab.onos.cluster.MastershipStore;
20 +import org.onlab.onos.cluster.MastershipStoreDelegate;
21 +import org.onlab.onos.cluster.MastershipTerm;
18 import org.onlab.onos.cluster.NodeId; 22 import org.onlab.onos.cluster.NodeId;
19 import org.onlab.onos.net.DeviceId; 23 import org.onlab.onos.net.DeviceId;
20 import org.onlab.onos.net.MastershipRole; 24 import org.onlab.onos.net.MastershipRole;
21 -import org.onlab.onos.net.device.DeviceMastershipEvent;
22 -import org.onlab.onos.net.device.DeviceMastershipStore;
23 -import org.onlab.onos.net.device.DeviceMastershipStoreDelegate;
24 -import org.onlab.onos.net.device.DeviceMastershipTerm;
25 import org.onlab.onos.store.AbstractStore; 25 import org.onlab.onos.store.AbstractStore;
26 import org.onlab.packet.IpPrefix; 26 import org.onlab.packet.IpPrefix;
27 import org.slf4j.Logger; 27 import org.slf4j.Logger;
28 28
29 -import static org.onlab.onos.net.device.DeviceMastershipEvent.Type.*; 29 +import static org.onlab.onos.cluster.MastershipEvent.Type.*;
30 30
31 /** 31 /**
32 * Manages inventory of controller mastership over devices using 32 * Manages inventory of controller mastership over devices using
...@@ -35,8 +35,8 @@ import static org.onlab.onos.net.device.DeviceMastershipEvent.Type.*; ...@@ -35,8 +35,8 @@ import static org.onlab.onos.net.device.DeviceMastershipEvent.Type.*;
35 @Component(immediate = true) 35 @Component(immediate = true)
36 @Service 36 @Service
37 public class SimpleMastershipStore 37 public class SimpleMastershipStore
38 - extends AbstractStore<DeviceMastershipEvent, DeviceMastershipStoreDelegate> 38 + extends AbstractStore<MastershipEvent, MastershipStoreDelegate>
39 - implements DeviceMastershipStore { 39 + implements MastershipStore {
40 40
41 private final Logger log = getLogger(getClass()); 41 private final Logger log = getLogger(getClass());
42 42
...@@ -63,7 +63,7 @@ public class SimpleMastershipStore ...@@ -63,7 +63,7 @@ public class SimpleMastershipStore
63 } 63 }
64 64
65 @Override 65 @Override
66 - public DeviceMastershipEvent setMaster(NodeId nodeId, DeviceId deviceId) { 66 + public MastershipEvent setMaster(NodeId nodeId, DeviceId deviceId) {
67 MastershipRole role = getRole(nodeId, deviceId); 67 MastershipRole role = getRole(nodeId, deviceId);
68 68
69 synchronized (this) { 69 synchronized (this) {
...@@ -86,7 +86,7 @@ public class SimpleMastershipStore ...@@ -86,7 +86,7 @@ public class SimpleMastershipStore
86 } 86 }
87 } 87 }
88 88
89 - return new DeviceMastershipEvent(MASTER_CHANGED, deviceId, nodeId); 89 + return new MastershipEvent(MASTER_CHANGED, deviceId, nodeId);
90 } 90 }
91 91
92 @Override 92 @Override
...@@ -164,17 +164,17 @@ public class SimpleMastershipStore ...@@ -164,17 +164,17 @@ public class SimpleMastershipStore
164 } 164 }
165 165
166 @Override 166 @Override
167 - public DeviceMastershipTerm getTermFor(DeviceId deviceId) { 167 + public MastershipTerm getTermFor(DeviceId deviceId) {
168 if ((masterMap.get(deviceId) == null) || 168 if ((masterMap.get(deviceId) == null) ||
169 (termMap.get(deviceId) == null)) { 169 (termMap.get(deviceId) == null)) {
170 return null; 170 return null;
171 } 171 }
172 - return DeviceMastershipTerm.of( 172 + return MastershipTerm.of(
173 masterMap.get(deviceId), termMap.get(deviceId).get()); 173 masterMap.get(deviceId), termMap.get(deviceId).get());
174 } 174 }
175 175
176 @Override 176 @Override
177 - public DeviceMastershipEvent setStandby(NodeId nodeId, DeviceId deviceId) { 177 + public MastershipEvent setStandby(NodeId nodeId, DeviceId deviceId) {
178 MastershipRole role = getRole(nodeId, deviceId); 178 MastershipRole role = getRole(nodeId, deviceId);
179 synchronized (this) { 179 synchronized (this) {
180 switch (role) { 180 switch (role) {
...@@ -185,7 +185,7 @@ public class SimpleMastershipStore ...@@ -185,7 +185,7 @@ public class SimpleMastershipStore
185 } else { 185 } else {
186 masterMap.put(deviceId, backup); 186 masterMap.put(deviceId, backup);
187 termMap.get(deviceId).incrementAndGet(); 187 termMap.get(deviceId).incrementAndGet();
188 - return new DeviceMastershipEvent(MASTER_CHANGED, deviceId, backup); 188 + return new MastershipEvent(MASTER_CHANGED, deviceId, backup);
189 } 189 }
190 case STANDBY: 190 case STANDBY:
191 case NONE: 191 case NONE:
...@@ -215,7 +215,7 @@ public class SimpleMastershipStore ...@@ -215,7 +215,7 @@ public class SimpleMastershipStore
215 } 215 }
216 216
217 @Override 217 @Override
218 - public DeviceMastershipEvent relinquishRole(NodeId nodeId, DeviceId deviceId) { 218 + public MastershipEvent relinquishRole(NodeId nodeId, DeviceId deviceId) {
219 return setStandby(nodeId, deviceId); 219 return setStandby(nodeId, deviceId);
220 } 220 }
221 221
......
...@@ -6,9 +6,9 @@ import java.util.concurrent.atomic.AtomicInteger; ...@@ -6,9 +6,9 @@ import java.util.concurrent.atomic.AtomicInteger;
6 import org.junit.After; 6 import org.junit.After;
7 import org.junit.Before; 7 import org.junit.Before;
8 import org.junit.Test; 8 import org.junit.Test;
9 +import org.onlab.onos.cluster.MastershipTerm;
9 import org.onlab.onos.cluster.NodeId; 10 import org.onlab.onos.cluster.NodeId;
10 import org.onlab.onos.net.DeviceId; 11 import org.onlab.onos.net.DeviceId;
11 -import org.onlab.onos.net.device.DeviceMastershipTerm;
12 12
13 import com.google.common.collect.Sets; 13 import com.google.common.collect.Sets;
14 14
...@@ -16,7 +16,7 @@ import static org.junit.Assert.assertEquals; ...@@ -16,7 +16,7 @@ import static org.junit.Assert.assertEquals;
16 import static org.junit.Assert.assertNull; 16 import static org.junit.Assert.assertNull;
17 import static org.junit.Assert.assertTrue; 17 import static org.junit.Assert.assertTrue;
18 import static org.onlab.onos.net.MastershipRole.*; 18 import static org.onlab.onos.net.MastershipRole.*;
19 -import static org.onlab.onos.net.device.DeviceMastershipEvent.Type.*; 19 +import static org.onlab.onos.cluster.MastershipEvent.Type.*;
20 20
21 /** 21 /**
22 * Test for the simple MastershipStore implementation. 22 * Test for the simple MastershipStore implementation.
...@@ -98,12 +98,12 @@ public class SimpleMastershipStoreTest { ...@@ -98,12 +98,12 @@ public class SimpleMastershipStoreTest {
98 @Test 98 @Test
99 public void getTermFor() { 99 public void getTermFor() {
100 put(DID1, N1, true, true); 100 put(DID1, N1, true, true);
101 - assertEquals("wrong term", DeviceMastershipTerm.of(N1, 0), sms.getTermFor(DID1)); 101 + assertEquals("wrong term", MastershipTerm.of(N1, 0), sms.getTermFor(DID1));
102 102
103 //switch to N2 and back - 2 term switches 103 //switch to N2 and back - 2 term switches
104 sms.setMaster(N2, DID1); 104 sms.setMaster(N2, DID1);
105 sms.setMaster(N1, DID1); 105 sms.setMaster(N1, DID1);
106 - assertEquals("wrong term", DeviceMastershipTerm.of(N1, 2), sms.getTermFor(DID1)); 106 + assertEquals("wrong term", MastershipTerm.of(N1, 2), sms.getTermFor(DID1));
107 } 107 }
108 108
109 @Test 109 @Test
......
...@@ -20,10 +20,11 @@ ...@@ -20,10 +20,11 @@
20 <bundle>mvn:io.dropwizard.metrics/metrics-core/3.1.0</bundle> 20 <bundle>mvn:io.dropwizard.metrics/metrics-core/3.1.0</bundle>
21 <bundle>mvn:com.eclipsesource.minimal-json/minimal-json/0.9.1</bundle> 21 <bundle>mvn:com.eclipsesource.minimal-json/minimal-json/0.9.1</bundle>
22 22
23 - <bundle>mvn:com.esotericsoftware.kryo/kryo/2.24.0</bundle> 23 + <bundle>mvn:com.esotericsoftware/kryo/3.0.0</bundle>
24 + <bundle>mvn:com.esotericsoftware/reflectasm/1.10.0</bundle>
25 + <bundle>mvn:org.ow2.asm/asm/4.2</bundle>
24 <bundle>mvn:com.esotericsoftware/minlog/1.3.0</bundle> 26 <bundle>mvn:com.esotericsoftware/minlog/1.3.0</bundle>
25 <bundle>mvn:org.objenesis/objenesis/2.1</bundle> 27 <bundle>mvn:org.objenesis/objenesis/2.1</bundle>
26 - <bundle>mvn:de.javakaffee/kryo-serializers/0.27</bundle>
27 28
28 <bundle>mvn:org.onlab.onos/onlab-nio/1.0.0-SNAPSHOT</bundle> 29 <bundle>mvn:org.onlab.onos/onlab-nio/1.0.0-SNAPSHOT</bundle>
29 30
......
...@@ -30,7 +30,7 @@ ...@@ -30,7 +30,7 @@
30 <groupId>org.projectfloodlight</groupId> 30 <groupId>org.projectfloodlight</groupId>
31 <artifactId>openflowj</artifactId> 31 <artifactId>openflowj</artifactId>
32 <!-- FIXME once experimenter gets merged to upstream --> 32 <!-- FIXME once experimenter gets merged to upstream -->
33 - <version>0.3.8-optical_experimenter</version> 33 + <version>0.3.8-optical_experimenter2</version>
34 </dependency> 34 </dependency>
35 <dependency> 35 <dependency>
36 <groupId>io.netty</groupId> 36 <groupId>io.netty</groupId>
......
...@@ -981,13 +981,13 @@ class OFChannelHandler extends IdleStateAwareChannelHandler { ...@@ -981,13 +981,13 @@ class OFChannelHandler extends IdleStateAwareChannelHandler {
981 // switch was a duplicate-dpid, calling the method below would clear 981 // switch was a duplicate-dpid, calling the method below would clear
982 // all state for the original switch (with the same dpid), 982 // all state for the original switch (with the same dpid),
983 // which we obviously don't want. 983 // which we obviously don't want.
984 - log.info("{}:removal called"); 984 + log.info("{}:removal called", getSwitchInfoString());
985 sw.removeConnectedSwitch(); 985 sw.removeConnectedSwitch();
986 } else { 986 } else {
987 // A duplicate was disconnected on this ChannelHandler, 987 // A duplicate was disconnected on this ChannelHandler,
988 // this is the same switch reconnecting, but the original state was 988 // this is the same switch reconnecting, but the original state was
989 // not cleaned up - XXX check liveness of original ChannelHandler 989 // not cleaned up - XXX check liveness of original ChannelHandler
990 - log.info("{}:duplicate found"); 990 + log.info("{}:duplicate found", getSwitchInfoString());
991 duplicateDpidFound = Boolean.FALSE; 991 duplicateDpidFound = Boolean.FALSE;
992 } 992 }
993 } else { 993 } else {
......
...@@ -57,6 +57,12 @@ public final class DriverManager implements OpenFlowSwitchDriverFactory { ...@@ -57,6 +57,12 @@ public final class DriverManager implements OpenFlowSwitchDriverFactory {
57 } 57 }
58 } 58 }
59 59
60 + String sw = desc.getSwDesc();
61 + if (sw.startsWith("LINC-OE")) {
62 + log.debug("Optical Emulator LINC-OE with DPID:{} found..", dpid);
63 + return new OFOpticalSwitchImplLINC13(dpid, desc);
64 + }
65 +
60 log.warn("DriverManager could not identify switch desc: {}. " 66 log.warn("DriverManager could not identify switch desc: {}. "
61 + "Assigning AbstractOpenFlowSwich", desc); 67 + "Assigning AbstractOpenFlowSwich", desc);
62 return new AbstractOpenFlowSwitch(dpid, desc) { 68 return new AbstractOpenFlowSwitch(dpid, desc) {
......
1 +package org.onlab.onos.openflow.drivers.impl;
2 +
3 +import org.onlab.onos.openflow.controller.driver.SwitchDriverSubHandshakeAlreadyStarted;
4 +import org.onlab.onos.openflow.controller.driver.SwitchDriverSubHandshakeCompleted;
5 +import org.onlab.onos.openflow.controller.driver.SwitchDriverSubHandshakeNotStarted;
6 +import org.onlab.onos.openflow.controller.Dpid;
7 +import org.onlab.onos.openflow.controller.driver.AbstractOpenFlowSwitch;
8 +import org.projectfloodlight.openflow.protocol.OFCircuitPortsReply;
9 +import org.projectfloodlight.openflow.protocol.OFCircuitPortsRequest;
10 +import org.projectfloodlight.openflow.protocol.OFDescStatsReply;
11 +import org.projectfloodlight.openflow.protocol.OFErrorMsg;
12 +import org.projectfloodlight.openflow.protocol.OFMatchV3;
13 +import org.projectfloodlight.openflow.protocol.OFMessage;
14 +import org.projectfloodlight.openflow.protocol.OFOxmList;
15 +import org.projectfloodlight.openflow.protocol.OFPortDesc;
16 +import org.projectfloodlight.openflow.protocol.OFPortOptical;
17 +import org.projectfloodlight.openflow.protocol.action.OFAction;
18 +import org.projectfloodlight.openflow.protocol.action.OFActionCircuit;
19 +import org.projectfloodlight.openflow.protocol.instruction.OFInstruction;
20 +import org.projectfloodlight.openflow.protocol.oxm.OFOxmInPort;
21 +import org.projectfloodlight.openflow.protocol.oxm.OFOxmOchSigid;
22 +import org.projectfloodlight.openflow.protocol.oxm.OFOxmOchSigidBasic;
23 +import org.projectfloodlight.openflow.protocol.oxm.OFOxmOchSigtype;
24 +import org.projectfloodlight.openflow.protocol.oxm.OFOxmOchSigtypeBasic;
25 +import org.projectfloodlight.openflow.types.CircuitSignalID;
26 +import org.projectfloodlight.openflow.types.OFPort;
27 +import org.projectfloodlight.openflow.types.U8;
28 +import org.slf4j.Logger;
29 +import org.slf4j.LoggerFactory;
30 +
31 +import java.io.IOException;
32 +import java.util.ArrayList;
33 +import java.util.Collection;
34 +import java.util.Collections;
35 +import java.util.List;
36 +import java.util.concurrent.atomic.AtomicBoolean;
37 +
38 +/**
39 + * LINC-OE Optical Emulator switch class.
40 + */
41 +public class OFOpticalSwitchImplLINC13 extends AbstractOpenFlowSwitch {
42 +
43 + private final AtomicBoolean driverHandshakeComplete;
44 + private long barrierXidToWaitFor = -1;
45 +
46 + private final Logger log =
47 + LoggerFactory.getLogger(OFOpticalSwitchImplLINC13.class);
48 +
49 + OFOpticalSwitchImplLINC13(Dpid dpid, OFDescStatsReply desc) {
50 + super(dpid);
51 + //setAttribute("optical", "true");
52 + driverHandshakeComplete = new AtomicBoolean(false);
53 + setSwitchDescription(desc);
54 + }
55 +
56 + @Override
57 + public String toString() {
58 + return "OFOpticalSwitchImplLINC13 [" + ((channel != null)
59 + ? channel.getRemoteAddress() : "?")
60 + + " DPID[" + ((getStringId() != null) ? getStringId() : "?") + "]]";
61 + }
62 +
63 + @Override
64 + public void startDriverHandshake() {
65 + log.debug("Starting driver handshake for sw {}", getStringId());
66 + if (startDriverHandshakeCalled) {
67 + throw new SwitchDriverSubHandshakeAlreadyStarted();
68 + }
69 + startDriverHandshakeCalled = true;
70 + try {
71 + sendHandshakeOFExperimenterPortDescRequest();
72 + } catch (IOException e) {
73 + e.printStackTrace();
74 + }
75 + }
76 +
77 + @Override
78 + public boolean isDriverHandshakeComplete() {
79 + if (!startDriverHandshakeCalled) {
80 + throw new SwitchDriverSubHandshakeNotStarted();
81 + }
82 + return driverHandshakeComplete.get();
83 + }
84 +
85 + @Override
86 + public void processDriverHandshakeMessage(OFMessage m) {
87 + if (!startDriverHandshakeCalled) {
88 + throw new SwitchDriverSubHandshakeNotStarted();
89 + }
90 + if (driverHandshakeComplete.get()) {
91 + throw new SwitchDriverSubHandshakeCompleted(m);
92 + }
93 +
94 + switch (m.getType()) {
95 + case BARRIER_REPLY:
96 + if (m.getXid() == barrierXidToWaitFor) {
97 + log.debug("LINC-OE Received barrier response");
98 + }
99 + break;
100 + case ERROR:
101 + log.error("Switch {} Error {}", getStringId(), (OFErrorMsg) m);
102 + break;
103 + case FEATURES_REPLY:
104 + break;
105 + case FLOW_REMOVED:
106 + break;
107 + case GET_ASYNC_REPLY:
108 + break;
109 + case PACKET_IN:
110 + break;
111 + case PORT_STATUS:
112 + break;
113 + case QUEUE_GET_CONFIG_REPLY:
114 + break;
115 + case ROLE_REPLY:
116 + break;
117 + case STATS_REPLY:
118 + log.debug("LINC-OE : Received stats reply message {}", m);
119 + processHandshakeOFExperimenterPortDescRequest(
120 + (OFCircuitPortsReply) m);
121 + driverHandshakeComplete.set(true);
122 + /* try {
123 + testMA();
124 + } catch (IOException e) {
125 + e.printStackTrace();
126 + }*/
127 + break;
128 + default:
129 + log.debug("Received message {} during switch-driver " +
130 + "subhandshake " + "from switch {} ... " +
131 + "Ignoring message", m,
132 + getStringId());
133 +
134 + }
135 + }
136 +
137 +
138 + private void processHandshakeOFExperimenterPortDescRequest(
139 + OFCircuitPortsReply sr) {
140 + Collection<OFPortOptical> entries = sr.getEntries();
141 + List<OFPortDesc> ofPortDescList = new ArrayList<>(entries.size());
142 + for (OFPortOptical entry : entries) {
143 + ofPortDescList.add(factory().buildPortDesc().
144 + setPortNo(entry.getPortNo())
145 + .setConfig(entry.getConfig())
146 + .setState(entry.getState())
147 + .setHwAddr(entry.getHwAddr())
148 + .setName(entry.getName())
149 + .build());
150 + }
151 + setPortDescReply(factory().buildPortDescStatsReply().
152 + setEntries(ofPortDescList).build());
153 + }
154 +
155 +
156 + private void sendHandshakeOFExperimenterPortDescRequest() throws
157 + IOException {
158 + // send multi part message for port description for optical switches
159 + OFCircuitPortsRequest circuitPortsRequest = factory()
160 + .buildCircuitPortsRequest().setXid(getNextTransactionId())
161 + .build();
162 + log.debug("LINC-OE : Sending experimented circuit port stats " +
163 + "message " +
164 + "{}",
165 + circuitPortsRequest.toString());
166 + channel.write(Collections.singletonList(circuitPortsRequest));
167 + }
168 +
169 +
170 +
171 + //todo for testing
172 + public static final U8 SIGNAL_TYPE = U8.of((short) 1);
173 + private void testMA() throws IOException {
174 + log.debug("LINC OE *** Testing MA ");
175 + short lambda = 100;
176 + if (getId() == 0x0000ffffffffff02L) {
177 + final int inport = 10;
178 + final int outport = 20;
179 + //Circuit signal id
180 + CircuitSignalID sigID = getSignalID(lambda);
181 +
182 + OFOxmOchSigid fieldSigIDMatch = factory().oxms().ochSigid(sigID);
183 + OFOxmOchSigtype fieldSigType = factory()
184 + .oxms()
185 + .ochSigtype(SIGNAL_TYPE);
186 +
187 + OFOxmOchSigidBasic ofOxmOchSigidBasic =
188 + factory().oxms().ochSigidBasic(sigID);
189 +
190 + OFOxmOchSigtypeBasic ofOxmOchSigtypeBasic =
191 + factory().oxms().ochSigtypeBasic(SIGNAL_TYPE);
192 +
193 + //Match Port
194 + OFOxmInPort fieldPort = factory().oxms()
195 + .inPort(OFPort.of(inport));
196 + OFMatchV3 matchPort =
197 + factory()
198 + .buildMatchV3().
199 + setOxmList(OFOxmList.of(fieldPort,
200 + fieldSigType,
201 + fieldSigIDMatch)).build();
202 +
203 +
204 + // Set Action outport ,sigType and sigID
205 + List<OFAction> actionList = new ArrayList<>();
206 + OFAction actionOutPort =
207 + factory().actions().output(OFPort.of(outport),
208 + Short.MAX_VALUE);
209 +
210 + OFActionCircuit actionCircuit = factory()
211 + .actions()
212 + .circuit(ofOxmOchSigidBasic);
213 + OFActionCircuit setActionSigType = factory()
214 + .actions()
215 + .circuit(ofOxmOchSigtypeBasic);
216 +
217 + actionList.add(actionOutPort);
218 + actionList.add(setActionSigType);
219 + actionList.add(actionCircuit);
220 +
221 + OFInstruction instructionAction =
222 + factory().instructions().buildApplyActions()
223 + .setActions(actionList)
224 + .build();
225 + List<OFInstruction> instructions =
226 + Collections.singletonList(instructionAction);
227 +
228 + OFMessage opticalFlowEntry =
229 + factory().buildFlowAdd()
230 + .setMatch(matchPort)
231 + .setInstructions(instructions)
232 + .setXid(getNextTransactionId())
233 + .build();
234 + log.debug("Adding optical flow in sw {}", getStringId());
235 + List<OFMessage> msglist = new ArrayList<>(1);
236 + msglist.add(opticalFlowEntry);
237 + write(msglist);
238 + } else if (getId() == 0x0000ffffffffff03L) {
239 + final int inport = 21;
240 + final int outport = 22;
241 + //Circuit signal id
242 + CircuitSignalID sigID = getSignalID(lambda);
243 +
244 + OFOxmOchSigid fieldSigIDMatch = factory().oxms().ochSigid(sigID);
245 + OFOxmOchSigtype fieldSigType = factory()
246 + .oxms()
247 + .ochSigtype(SIGNAL_TYPE);
248 +
249 + OFOxmOchSigidBasic ofOxmOchSigidBasic =
250 + factory().oxms().ochSigidBasic(sigID);
251 +
252 + OFOxmOchSigtypeBasic ofOxmOchSigtypeBasic =
253 + factory().oxms().ochSigtypeBasic(SIGNAL_TYPE);
254 +
255 + //Match Port,SigType,SigID
256 + OFOxmInPort fieldPort = factory()
257 + .oxms()
258 + .inPort(OFPort.of(inport));
259 + OFMatchV3 matchPort = factory()
260 + .buildMatchV3()
261 + .setOxmList(OFOxmList.of(fieldPort,
262 + fieldSigType,
263 + fieldSigIDMatch))
264 + .build();
265 +
266 + // Set Action outport ,SigType, sigID
267 + List<OFAction> actionList = new ArrayList<>();
268 + OFAction actionOutPort =
269 + factory().actions().output(OFPort.of(outport),
270 + Short.MAX_VALUE);
271 +
272 + OFActionCircuit setActionSigType = factory()
273 + .actions()
274 + .circuit(ofOxmOchSigtypeBasic);
275 + OFActionCircuit actionCircuit = factory()
276 + .actions()
277 + .circuit(ofOxmOchSigidBasic);
278 +
279 +
280 + actionList.add(actionOutPort);
281 + actionList.add(setActionSigType);
282 + actionList.add(actionCircuit);
283 +
284 + OFInstruction instructionAction =
285 + factory().instructions().buildApplyActions()
286 + .setActions(actionList)
287 + .build();
288 + List<OFInstruction> instructions =
289 + Collections.singletonList(instructionAction);
290 +
291 + OFMessage opticalFlowEntry =
292 + factory().buildFlowAdd()
293 + .setMatch(matchPort)
294 + .setInstructions(instructions)
295 + .setXid(getNextTransactionId())
296 + .build();
297 + log.debug("Adding optical flow in sw {}", getStringId());
298 + List<OFMessage> msglist = new ArrayList<>(1);
299 + msglist.add(opticalFlowEntry);
300 + write(msglist);
301 +
302 + } else if (getId() == 0x0000ffffffffff04L) {
303 + final int inport = 23;
304 + final int outport = 11;
305 + //Circuit signal id
306 + CircuitSignalID sigID = getSignalID(lambda);
307 +
308 + OFOxmOchSigid fieldSigIDMatch = factory().oxms().ochSigid(sigID);
309 + OFOxmOchSigtype fieldSigType = factory()
310 + .oxms()
311 + .ochSigtype(SIGNAL_TYPE);
312 +
313 +
314 + //Match Port, sig type and sig id
315 + OFOxmInPort fieldPort = factory()
316 + .oxms()
317 + .inPort(OFPort.of(inport));
318 + OFMatchV3 matchPort =
319 + factory().buildMatchV3()
320 + .setOxmList(OFOxmList.of(fieldPort,
321 + fieldSigType,
322 + fieldSigIDMatch))
323 + .build();
324 +
325 + // Set Action outport
326 + List<OFAction> actionList = new ArrayList<>();
327 + OFAction actionOutPort =
328 + factory().actions().output(OFPort.of(outport),
329 + Short.MAX_VALUE);
330 +
331 + actionList.add(actionOutPort);
332 +
333 + OFInstruction instructionAction =
334 + factory().instructions().buildApplyActions()
335 + .setActions(actionList)
336 + .build();
337 + List<OFInstruction> instructions =
338 + Collections.singletonList(instructionAction);
339 +
340 + OFMessage opticalFlowEntry =
341 + factory().buildFlowAdd()
342 + .setMatch(matchPort)
343 + .setInstructions(instructions)
344 + .setXid(getNextTransactionId())
345 + .build();
346 + log.debug("Adding optical flow in sw {}", getStringId());
347 + List<OFMessage> msglist = new ArrayList<>(1);
348 + msglist.add(opticalFlowEntry);
349 + write(msglist);
350 + }
351 +
352 + }
353 +
354 + // Todo remove - for testing purpose only
355 + private static CircuitSignalID getSignalID(short lambda) {
356 + byte myGrid = 1;
357 + byte myCs = 2;
358 + short myCn = lambda;
359 + short mySw = 1;
360 +
361 + CircuitSignalID signalID = new CircuitSignalID(myGrid,
362 + myCs,
363 + myCn,
364 + mySw);
365 + return signalID;
366 + }
367 +
368 + @Override
369 + public void write(OFMessage msg) {
370 + this.channel.write(msg);
371 + }
372 +
373 + @Override
374 + public void write(List<OFMessage> msgs) {
375 + this.channel.write(msgs);
376 + }
377 +
378 + @Override
379 + public Boolean supportNxRole() {
380 + return false;
381 + }
382 +
383 +}
...@@ -193,9 +193,20 @@ ...@@ -193,9 +193,20 @@
193 <version>0.9.1</version> 193 <version>0.9.1</version>
194 </dependency> 194 </dependency>
195 <dependency> 195 <dependency>
196 - <groupId>com.esotericsoftware.kryo</groupId> 196 + <groupId>com.esotericsoftware</groupId>
197 - <artifactId>kryo</artifactId> 197 + <artifactId>kryo</artifactId>
198 - <version>2.24.0</version> 198 + <version>3.0.0</version>
199 + </dependency>
200 + <dependency>
201 + <groupId>com.esotericsoftware</groupId>
202 + <artifactId>reflectasm</artifactId>
203 + <version>1.10.0</version>
204 + <type>bundle</type>
205 + </dependency>
206 + <dependency>
207 + <groupId>org.ow2.asm</groupId>
208 + <artifactId>asm</artifactId>
209 + <version>4.2</version>
199 </dependency> 210 </dependency>
200 <dependency> 211 <dependency>
201 <groupId>com.esotericsoftware</groupId> 212 <groupId>com.esotericsoftware</groupId>
...@@ -207,11 +218,6 @@ ...@@ -207,11 +218,6 @@
207 <artifactId>objenesis</artifactId> 218 <artifactId>objenesis</artifactId>
208 <version>2.1</version> 219 <version>2.1</version>
209 </dependency> 220 </dependency>
210 - <dependency>
211 - <groupId>de.javakaffee</groupId>
212 - <artifactId>kryo-serializers</artifactId>
213 - <version>0.27</version>
214 - </dependency>
215 221
216 <!-- ONOS related --> 222 <!-- ONOS related -->
217 <dependency> 223 <dependency>
...@@ -284,6 +290,10 @@ ...@@ -284,6 +290,10 @@
284 </dependency> 290 </dependency>
285 <dependency> 291 <dependency>
286 <groupId>org.slf4j</groupId> 292 <groupId>org.slf4j</groupId>
293 + <artifactId>slf4j-api</artifactId>
294 + </dependency>
295 + <dependency>
296 + <groupId>org.slf4j</groupId>
287 <artifactId>slf4j-jdk14</artifactId> 297 <artifactId>slf4j-jdk14</artifactId>
288 </dependency> 298 </dependency>
289 </dependencies> 299 </dependencies>
...@@ -434,9 +444,6 @@ ...@@ -434,9 +444,6 @@
434 <version>3.2</version> 444 <version>3.2</version>
435 <configuration> 445 <configuration>
436 <excludes> 446 <excludes>
437 - <exclude>**/datastore/serializers/**</exclude>
438 - <exclude>**/edu/stanford/**</exclude>
439 - <exclude>**/net/floodlightcontroller/**</exclude>
440 </excludes> 447 </excludes>
441 <rulesets> 448 <rulesets>
442 <ruleset>onos/pmd.xml</ruleset> 449 <ruleset>onos/pmd.xml</ruleset>
...@@ -493,7 +500,7 @@ ...@@ -493,7 +500,7 @@
493 <group> 500 <group>
494 <title>Core Subsystems</title> 501 <title>Core Subsystems</title>
495 <packages> 502 <packages>
496 - org.onlab.onos.cluster.impl:org.onlab.onos.net.device.impl:org.onlab.onos.net.link.impl:org.onlab.onos.net.host.impl:org.onlab.onos.net.topology.impl:org.onlab.onos.net.packet.impl:org.onlab.onos.net.flow.impl:org.onlab.onos.store.trivial.*:org.onlab.onos.net.*.impl:org.onlab.onos.event.impl:org.onlab.onos.store.*:org.onlab.onos.net.intent.impl 503 + org.onlab.onos.impl:org.onlab.onos.cluster.impl:org.onlab.onos.net.device.impl:org.onlab.onos.net.link.impl:org.onlab.onos.net.host.impl:org.onlab.onos.net.topology.impl:org.onlab.onos.net.packet.impl:org.onlab.onos.net.flow.impl:org.onlab.onos.store.trivial.*:org.onlab.onos.net.*.impl:org.onlab.onos.event.impl:org.onlab.onos.store.*:org.onlab.onos.net.intent.impl:org.onlab.onos.net.proxyarp.impl
497 </packages> 504 </packages>
498 </group> 505 </group>
499 <group> 506 <group>
...@@ -518,7 +525,7 @@ ...@@ -518,7 +525,7 @@
518 <group> 525 <group>
519 <title>Sample Applications</title> 526 <title>Sample Applications</title>
520 <packages> 527 <packages>
521 - org.onlab.onos.tvue:org.onlab.onos.fwd:org.onlab.onos.foo 528 + org.onlab.onos.tvue:org.onlab.onos.fwd:org.onlab.onos.ifwd:org.onlab.onos.mobility:org.onlab.onos.proxyarp:org.onlab.onos.foo
522 </packages> 529 </packages>
523 </group> 530 </group>
524 </groups> 531 </groups>
...@@ -545,9 +552,6 @@ ...@@ -545,9 +552,6 @@
545 <version>3.2</version> 552 <version>3.2</version>
546 <configuration> 553 <configuration>
547 <excludes> 554 <excludes>
548 - <exclude>**/datastore/serializers/**</exclude>
549 - <exclude>**/edu/stanford/**</exclude>
550 - <exclude>**/net/floodlightcontroller/**</exclude>
551 </excludes> 555 </excludes>
552 <rulesets> 556 <rulesets>
553 <ruleset>onos/pmd.xml</ruleset> 557 <ruleset>onos/pmd.xml</ruleset>
......
1 package org.onlab.onos.provider.of.host.impl; 1 package org.onlab.onos.provider.of.host.impl;
2 2
3 -import static com.google.common.collect.Sets.newHashSet;
4 -import static org.onlab.onos.net.DeviceId.deviceId;
5 -import static org.onlab.onos.net.PortNumber.portNumber;
6 -import static org.slf4j.LoggerFactory.getLogger;
7 -
8 -import java.util.Set;
9 -
10 import org.apache.felix.scr.annotations.Activate; 3 import org.apache.felix.scr.annotations.Activate;
11 import org.apache.felix.scr.annotations.Component; 4 import org.apache.felix.scr.annotations.Component;
12 import org.apache.felix.scr.annotations.Deactivate; 5 import org.apache.felix.scr.annotations.Deactivate;
...@@ -36,6 +29,10 @@ import org.onlab.packet.IpPrefix; ...@@ -36,6 +29,10 @@ import org.onlab.packet.IpPrefix;
36 import org.onlab.packet.VlanId; 29 import org.onlab.packet.VlanId;
37 import org.slf4j.Logger; 30 import org.slf4j.Logger;
38 31
32 +import static org.onlab.onos.net.DeviceId.deviceId;
33 +import static org.onlab.onos.net.PortNumber.portNumber;
34 +import static org.slf4j.LoggerFactory.getLogger;
35 +
39 /** 36 /**
40 * Provider which uses an OpenFlow controller to detect network 37 * Provider which uses an OpenFlow controller to detect network
41 * end-station hosts. 38 * end-station hosts.
...@@ -58,6 +55,8 @@ public class OpenFlowHostProvider extends AbstractProvider implements HostProvid ...@@ -58,6 +55,8 @@ public class OpenFlowHostProvider extends AbstractProvider implements HostProvid
58 55
59 private final InternalHostProvider listener = new InternalHostProvider(); 56 private final InternalHostProvider listener = new InternalHostProvider();
60 57
58 + private boolean ipLearn = true;
59 +
61 /** 60 /**
62 * Creates an OpenFlow host provider. 61 * Creates an OpenFlow host provider.
63 */ 62 */
...@@ -69,7 +68,6 @@ public class OpenFlowHostProvider extends AbstractProvider implements HostProvid ...@@ -69,7 +68,6 @@ public class OpenFlowHostProvider extends AbstractProvider implements HostProvid
69 public void activate() { 68 public void activate() {
70 providerService = providerRegistry.register(this); 69 providerService = providerRegistry.register(this);
71 controller.addPacketListener(10, listener); 70 controller.addPacketListener(10, listener);
72 -
73 log.info("Started"); 71 log.info("Started");
74 } 72 }
75 73
...@@ -78,7 +76,6 @@ public class OpenFlowHostProvider extends AbstractProvider implements HostProvid ...@@ -78,7 +76,6 @@ public class OpenFlowHostProvider extends AbstractProvider implements HostProvid
78 providerRegistry.unregister(this); 76 providerRegistry.unregister(this);
79 controller.removePacketListener(listener); 77 controller.removePacketListener(listener);
80 providerService = null; 78 providerService = null;
81 -
82 log.info("Stopped"); 79 log.info("Stopped");
83 } 80 }
84 81
...@@ -95,33 +92,33 @@ public class OpenFlowHostProvider extends AbstractProvider implements HostProvid ...@@ -95,33 +92,33 @@ public class OpenFlowHostProvider extends AbstractProvider implements HostProvid
95 92
96 VlanId vlan = VlanId.vlanId(eth.getVlanID()); 93 VlanId vlan = VlanId.vlanId(eth.getVlanID());
97 ConnectPoint heardOn = new ConnectPoint(deviceId(Dpid.uri(pktCtx.dpid())), 94 ConnectPoint heardOn = new ConnectPoint(deviceId(Dpid.uri(pktCtx.dpid())),
98 - portNumber(pktCtx.inPort())); 95 + portNumber(pktCtx.inPort()));
99 96
100 - // If this is not an edge port, bail out. 97 + // If this is not an edge port, bail out.
101 Topology topology = topologyService.currentTopology(); 98 Topology topology = topologyService.currentTopology();
102 if (topologyService.isInfrastructure(topology, heardOn)) { 99 if (topologyService.isInfrastructure(topology, heardOn)) {
103 return; 100 return;
104 } 101 }
105 102
106 HostLocation hloc = new HostLocation(deviceId(Dpid.uri(pktCtx.dpid())), 103 HostLocation hloc = new HostLocation(deviceId(Dpid.uri(pktCtx.dpid())),
107 - portNumber(pktCtx.inPort()), 104 + portNumber(pktCtx.inPort()),
108 - System.currentTimeMillis()); 105 + System.currentTimeMillis());
106 +
109 HostId hid = HostId.hostId(eth.getSourceMAC(), vlan); 107 HostId hid = HostId.hostId(eth.getSourceMAC(), vlan);
108 +
110 // Potentially a new or moved host 109 // Potentially a new or moved host
111 if (eth.getEtherType() == Ethernet.TYPE_ARP) { 110 if (eth.getEtherType() == Ethernet.TYPE_ARP) {
112 -
113 -
114 ARP arp = (ARP) eth.getPayload(); 111 ARP arp = (ARP) eth.getPayload();
115 - Set<IpPrefix> ips = newHashSet(IpPrefix.valueOf(arp.getSenderProtocolAddress())); 112 + IpPrefix ip = IpPrefix.valueOf(arp.getSenderProtocolAddress());
116 HostDescription hdescr = 113 HostDescription hdescr =
117 - new DefaultHostDescription(eth.getSourceMAC(), vlan, hloc, ips); 114 + new DefaultHostDescription(eth.getSourceMAC(), vlan, hloc, ip);
118 providerService.hostDetected(hid, hdescr); 115 providerService.hostDetected(hid, hdescr);
119 116
120 - } else if (eth.getEtherType() == Ethernet.TYPE_IPV4) { 117 + } else if (ipLearn && eth.getEtherType() == Ethernet.TYPE_IPV4) {
121 - IPv4 ip = (IPv4) eth.getPayload(); 118 + IPv4 pip = (IPv4) eth.getPayload();
122 - Set<IpPrefix> ips = newHashSet(IpPrefix.valueOf(ip.getSourceAddress())); 119 + IpPrefix ip = IpPrefix.valueOf(pip.getSourceAddress());
123 HostDescription hdescr = 120 HostDescription hdescr =
124 - new DefaultHostDescription(eth.getSourceMAC(), vlan, hloc, ips); 121 + new DefaultHostDescription(eth.getSourceMAC(), vlan, hloc, ip);
125 providerService.hostDetected(hid, hdescr); 122 providerService.hostDetected(hid, hdescr);
126 123
127 } 124 }
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
6 export ONOS_ROOT=${ONOS_ROOT:-~/onos-next} 6 export ONOS_ROOT=${ONOS_ROOT:-~/onos-next}
7 7
8 # Setup some environmental context for developers 8 # Setup some environmental context for developers
9 -export JAVA_HOME=$(/usr/libexec/java_home -v 1.7) 9 +export JAVA_HOME=${JAVA_HOME:-$(/usr/libexec/java_home -v 1.7)}
10 export MAVEN=${MAVEN:-~/Applications/apache-maven-3.2.2} 10 export MAVEN=${MAVEN:-~/Applications/apache-maven-3.2.2}
11 export KARAF=${KARAF:-~/Applications/apache-karaf-3.0.1} 11 export KARAF=${KARAF:-~/Applications/apache-karaf-3.0.1}
12 export KARAF_LOG=$KARAF/data/log/karaf.log 12 export KARAF_LOG=$KARAF/data/log/karaf.log
......
1 +#!/bin/bash
1 #------------------------------------------------------------------------------ 2 #------------------------------------------------------------------------------
2 # Echoes project-level directory if a Java file within is newer than the 3 # Echoes project-level directory if a Java file within is newer than the
3 # target directory. 4 # target directory.
......
1 +#!/bin/bash
2 +
3 +kpid=$(ps -ef | grep karaf.main.Main | grep -v grep | cut -c10-15 | tr -d ' ')
4 +
5 +[ -z "$kpid" ] && echo "No ONOS!" && exit 1
6 +
7 +/opt/jprofiler8/bin/jpenable --gui --port=8849 --pid=$kpid
1 +# Local VirtualBox-based single ONOS instance & ONOS mininet box
2 +
3 +export ONOS_NIC=192.168.56.*
4 +export OC1="192.168.56.103"
5 +export OCN="192.168.56.103"
6 +
7 +export ONOS_FEATURES="webconsole,onos-api,onos-core-trivial,onos-cli,onos-openflow,onos-app-fwd"
...@@ -44,18 +44,10 @@ ...@@ -44,18 +44,10 @@
44 <artifactId>minimal-json</artifactId> 44 <artifactId>minimal-json</artifactId>
45 </dependency> 45 </dependency>
46 <dependency> 46 <dependency>
47 - <groupId>com.esotericsoftware.kryo</groupId> 47 + <groupId>com.esotericsoftware</groupId>
48 <artifactId>kryo</artifactId> 48 <artifactId>kryo</artifactId>
49 </dependency> 49 </dependency>
50 <dependency> 50 <dependency>
51 - <groupId>com.esotericsoftware</groupId>
52 - <artifactId>minlog</artifactId>
53 - </dependency>
54 - <dependency>
55 - <groupId>org.objenesis</groupId>
56 - <artifactId>objenesis</artifactId>
57 - </dependency>
58 - <dependency>
59 <groupId>io.dropwizard.metrics</groupId> 51 <groupId>io.dropwizard.metrics</groupId>
60 <artifactId>metrics-core</artifactId> 52 <artifactId>metrics-core</artifactId>
61 <version>3.1.0</version> 53 <version>3.1.0</version>
......
...@@ -22,11 +22,12 @@ import java.util.Arrays; ...@@ -22,11 +22,12 @@ import java.util.Arrays;
22 * 22 *
23 */ 23 */
24 public class MacAddress { 24 public class MacAddress {
25 - public static final byte[] ZERO_MAC_ADDRESS =
26 - MacAddress.valueOf("00:00:00:00:00:00").getAddress();
27 25
28 - public static final byte[] BROADCAST_MAC = 26 + public static final MacAddress ZERO = valueOf("00:00:00:00:00:00");
29 - MacAddress.valueOf("ff:ff:ff:ff:ff:ff").getAddress(); 27 + public static final MacAddress BROADCAST = valueOf("ff:ff:ff:ff:ff:ff");
28 +
29 + public static final byte[] ZERO_MAC_ADDRESS = ZERO.getAddress();
30 + public static final byte[] BROADCAST_MAC = BROADCAST.getAddress();
30 31
31 public static final int MAC_ADDRESS_LENGTH = 6; 32 public static final int MAC_ADDRESS_LENGTH = 6;
32 private byte[] address = new byte[MacAddress.MAC_ADDRESS_LENGTH]; 33 private byte[] address = new byte[MacAddress.MAC_ADDRESS_LENGTH];
......
...@@ -3,12 +3,15 @@ package org.onlab.packet; ...@@ -3,12 +3,15 @@ package org.onlab.packet;
3 /** 3 /**
4 * Representation of a VLAN ID. 4 * Representation of a VLAN ID.
5 */ 5 */
6 -// FIXME: This will end-up looking like a constant; we should name it 'VlanId', 'IpAddress', 'MacAddress'.
7 public class VlanId { 6 public class VlanId {
8 7
9 private final short value; 8 private final short value;
9 +
10 // Based on convention used elsewhere? Check and change if needed 10 // Based on convention used elsewhere? Check and change if needed
11 public static final short UNTAGGED = (short) 0xffff; 11 public static final short UNTAGGED = (short) 0xffff;
12 +
13 + public static final VlanId NONE = VlanId.vlanId(UNTAGGED);
14 +
12 // A VLAN ID is actually 12 bits of a VLAN tag. 15 // A VLAN ID is actually 12 bits of a VLAN tag.
13 public static final short MAX_VLAN = 4095; 16 public static final short MAX_VLAN = 4095;
14 17
......
...@@ -32,10 +32,6 @@ ...@@ -32,10 +32,6 @@
32 <scope>test</scope> 32 <scope>test</scope>
33 </dependency> 33 </dependency>
34 <dependency> 34 <dependency>
35 - <groupId>de.javakaffee</groupId>
36 - <artifactId>kryo-serializers</artifactId>
37 - </dependency>
38 - <dependency>
39 <groupId>io.netty</groupId> 35 <groupId>io.netty</groupId>
40 <artifactId>netty-all</artifactId> 36 <artifactId>netty-all</artifactId>
41 </dependency> 37 </dependency>
......