Showing
19 changed files
with
243 additions
and
37 deletions
| ... | @@ -13,6 +13,7 @@ import java.util.Collections; | ... | @@ -13,6 +13,7 @@ import java.util.Collections; |
| 13 | import java.util.List; | 13 | import java.util.List; |
| 14 | import java.util.Set; | 14 | import java.util.Set; |
| 15 | 15 | ||
| 16 | +import org.junit.Ignore; | ||
| 16 | import org.junit.Test; | 17 | import org.junit.Test; |
| 17 | import org.onlab.onos.net.ConnectPoint; | 18 | import org.onlab.onos.net.ConnectPoint; |
| 18 | import org.onlab.onos.net.Device; | 19 | import org.onlab.onos.net.Device; |
| ... | @@ -81,6 +82,7 @@ public class HostMonitorTest { | ... | @@ -81,6 +82,7 @@ public class HostMonitorTest { |
| 81 | } | 82 | } |
| 82 | 83 | ||
| 83 | @Test | 84 | @Test |
| 85 | + @Ignore | ||
| 84 | public void testMonitorHostDoesNotExist() throws Exception { | 86 | public void testMonitorHostDoesNotExist() throws Exception { |
| 85 | HostManager hostManager = createMock(HostManager.class); | 87 | HostManager hostManager = createMock(HostManager.class); |
| 86 | 88 | ... | ... |
| 1 | -package org.onlab.onos.store.cluster.messaging.impl; | 1 | +package org.onlab.onos.store.cluster.impl; |
| 2 | 2 | ||
| 3 | import org.onlab.onos.store.cluster.messaging.MessageSubject; | 3 | import org.onlab.onos.store.cluster.messaging.MessageSubject; |
| 4 | 4 | ||
| 5 | -public final class ClusterMessageSubjects { | 5 | +public final class ClusterManagementMessageSubjects { |
| 6 | // avoid instantiation | 6 | // avoid instantiation |
| 7 | - private ClusterMessageSubjects() {} | 7 | + private ClusterManagementMessageSubjects() {} |
| 8 | 8 | ||
| 9 | public static final MessageSubject CLUSTER_MEMBERSHIP_EVENT = new MessageSubject("CLUSTER_MEMBERSHIP_EVENT"); | 9 | public static final MessageSubject CLUSTER_MEMBERSHIP_EVENT = new MessageSubject("CLUSTER_MEMBERSHIP_EVENT"); |
| 10 | } | 10 | } | ... | ... |
| ... | @@ -17,6 +17,8 @@ import org.apache.felix.scr.annotations.ReferenceCardinality; | ... | @@ -17,6 +17,8 @@ import org.apache.felix.scr.annotations.ReferenceCardinality; |
| 17 | import org.apache.felix.scr.annotations.Service; | 17 | import org.apache.felix.scr.annotations.Service; |
| 18 | import org.onlab.onos.cluster.ControllerNode; | 18 | import org.onlab.onos.cluster.ControllerNode; |
| 19 | import org.onlab.onos.cluster.NodeId; | 19 | import org.onlab.onos.cluster.NodeId; |
| 20 | +import org.onlab.onos.store.cluster.impl.ClusterMembershipEvent; | ||
| 21 | +import org.onlab.onos.store.cluster.impl.ClusterMembershipEventType; | ||
| 20 | import org.onlab.onos.store.cluster.impl.ClusterNodesDelegate; | 22 | import org.onlab.onos.store.cluster.impl.ClusterNodesDelegate; |
| 21 | import org.onlab.onos.store.cluster.messaging.ClusterCommunicationAdminService; | 23 | import org.onlab.onos.store.cluster.messaging.ClusterCommunicationAdminService; |
| 22 | import org.onlab.onos.store.cluster.messaging.ClusterCommunicationService; | 24 | import org.onlab.onos.store.cluster.messaging.ClusterCommunicationService; | ... | ... |
| 1 | -package org.onlab.onos.store.cluster.impl; | 1 | +package org.onlab.onos.store.cluster.messaging.impl; |
| 2 | 2 | ||
| 3 | import org.apache.felix.scr.annotations.Activate; | 3 | import org.apache.felix.scr.annotations.Activate; |
| 4 | import org.apache.felix.scr.annotations.Component; | 4 | import org.apache.felix.scr.annotations.Component; | ... | ... |
| ... | @@ -8,7 +8,7 @@ import org.onlab.onos.cluster.NodeId; | ... | @@ -8,7 +8,7 @@ import org.onlab.onos.cluster.NodeId; |
| 8 | import org.onlab.onos.net.Device; | 8 | import org.onlab.onos.net.Device; |
| 9 | import org.onlab.onos.net.DeviceId; | 9 | import org.onlab.onos.net.DeviceId; |
| 10 | import org.onlab.onos.store.Timestamp; | 10 | import org.onlab.onos.store.Timestamp; |
| 11 | -import org.onlab.onos.store.cluster.messaging.AntiEntropyAdvertisement; | 11 | +import org.onlab.onos.store.common.impl.AntiEntropyAdvertisement; |
| 12 | 12 | ||
| 13 | // TODO DeviceID needs to be changed to something like (ProviderID, DeviceID) | 13 | // TODO DeviceID needs to be changed to something like (ProviderID, DeviceID) |
| 14 | // TODO: Handle Port as part of these messages, or separate messages for Ports? | 14 | // TODO: Handle Port as part of these messages, or separate messages for Ports? | ... | ... |
| ... | @@ -10,7 +10,7 @@ import org.onlab.onos.cluster.NodeId; | ... | @@ -10,7 +10,7 @@ import org.onlab.onos.cluster.NodeId; |
| 10 | import org.onlab.onos.net.Device; | 10 | import org.onlab.onos.net.Device; |
| 11 | import org.onlab.onos.net.DeviceId; | 11 | import org.onlab.onos.net.DeviceId; |
| 12 | import org.onlab.onos.store.Timestamp; | 12 | import org.onlab.onos.store.Timestamp; |
| 13 | -import org.onlab.onos.store.cluster.messaging.AntiEntropyReply; | 13 | +import org.onlab.onos.store.common.impl.AntiEntropyReply; |
| 14 | 14 | ||
| 15 | import com.google.common.collect.ImmutableMap; | 15 | import com.google.common.collect.ImmutableMap; |
| 16 | import com.google.common.collect.ImmutableSet; | 16 | import com.google.common.collect.ImmutableSet; | ... | ... |
| ... | @@ -4,6 +4,7 @@ import com.google.common.collect.FluentIterable; | ... | @@ -4,6 +4,7 @@ import com.google.common.collect.FluentIterable; |
| 4 | import com.google.common.collect.ImmutableList; | 4 | 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 | import org.apache.commons.lang3.concurrent.ConcurrentException; | 8 | import org.apache.commons.lang3.concurrent.ConcurrentException; |
| 8 | import org.apache.commons.lang3.concurrent.ConcurrentInitializer; | 9 | import org.apache.commons.lang3.concurrent.ConcurrentInitializer; |
| 9 | import org.apache.felix.scr.annotations.Activate; | 10 | import org.apache.felix.scr.annotations.Activate; |
| ... | @@ -33,10 +34,15 @@ import org.onlab.onos.net.provider.ProviderId; | ... | @@ -33,10 +34,15 @@ import org.onlab.onos.net.provider.ProviderId; |
| 33 | import org.onlab.onos.store.AbstractStore; | 34 | import org.onlab.onos.store.AbstractStore; |
| 34 | import org.onlab.onos.store.ClockService; | 35 | import org.onlab.onos.store.ClockService; |
| 35 | import org.onlab.onos.store.Timestamp; | 36 | import org.onlab.onos.store.Timestamp; |
| 37 | +import org.onlab.onos.store.cluster.messaging.ClusterCommunicationService; | ||
| 38 | +import org.onlab.onos.store.cluster.messaging.ClusterMessage; | ||
| 39 | +import org.onlab.onos.store.cluster.messaging.ClusterMessageHandler; | ||
| 40 | +import org.onlab.onos.store.cluster.messaging.MessageSubject; | ||
| 36 | import org.onlab.onos.store.common.impl.Timestamped; | 41 | import org.onlab.onos.store.common.impl.Timestamped; |
| 37 | import org.onlab.util.NewConcurrentHashMap; | 42 | import org.onlab.util.NewConcurrentHashMap; |
| 38 | import org.slf4j.Logger; | 43 | import org.slf4j.Logger; |
| 39 | 44 | ||
| 45 | +import java.io.IOException; | ||
| 40 | import java.util.ArrayList; | 46 | import java.util.ArrayList; |
| 41 | import java.util.Collections; | 47 | import java.util.Collections; |
| 42 | import java.util.HashSet; | 48 | import java.util.HashSet; |
| ... | @@ -96,6 +102,9 @@ public class GossipDeviceStore | ... | @@ -96,6 +102,9 @@ public class GossipDeviceStore |
| 96 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 102 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 97 | protected ClockService clockService; | 103 | protected ClockService clockService; |
| 98 | 104 | ||
| 105 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
| 106 | + protected ClusterCommunicationService clusterCommunicator; | ||
| 107 | + | ||
| 99 | @Activate | 108 | @Activate |
| 100 | public void activate() { | 109 | public void activate() { |
| 101 | log.info("Started"); | 110 | log.info("Started"); |
| ... | @@ -133,8 +142,14 @@ public class GossipDeviceStore | ... | @@ -133,8 +142,14 @@ public class GossipDeviceStore |
| 133 | final Timestamped<DeviceDescription> deltaDesc = new Timestamped<>(deviceDescription, newTimestamp); | 142 | final Timestamped<DeviceDescription> deltaDesc = new Timestamped<>(deviceDescription, newTimestamp); |
| 134 | DeviceEvent event = createOrUpdateDeviceInternal(providerId, deviceId, deltaDesc); | 143 | DeviceEvent event = createOrUpdateDeviceInternal(providerId, deviceId, deltaDesc); |
| 135 | if (event != null) { | 144 | if (event != null) { |
| 136 | - // FIXME: broadcast deltaDesc, UP | 145 | + log.info("Notifying peers of a device update topology event for providerId: {} and deviceId: {}", |
| 137 | - log.debug("broadcast deltaDesc"); | 146 | + providerId, deviceId); |
| 147 | + try { | ||
| 148 | + notifyPeers(new InternalDeviceEvent(providerId, deviceId, deltaDesc)); | ||
| 149 | + } catch (IOException e) { | ||
| 150 | + log.error("Failed to notify peers of a device update topology event or providerId: " | ||
| 151 | + + providerId + " and deviceId: " + deviceId, e); | ||
| 152 | + } | ||
| 138 | } | 153 | } |
| 139 | return event; | 154 | return event; |
| 140 | } | 155 | } |
| ... | @@ -298,19 +313,21 @@ public class GossipDeviceStore | ... | @@ -298,19 +313,21 @@ public class GossipDeviceStore |
| 298 | List<PortDescription> portDescriptions) { | 313 | List<PortDescription> portDescriptions) { |
| 299 | Timestamp newTimestamp = clockService.getTimestamp(deviceId); | 314 | Timestamp newTimestamp = clockService.getTimestamp(deviceId); |
| 300 | 315 | ||
| 301 | - List<Timestamped<PortDescription>> deltaDescs = new ArrayList<>(portDescriptions.size()); | 316 | + Timestamped<List<PortDescription>> timestampedPortDescriptions = |
| 302 | - for (PortDescription e : portDescriptions) { | 317 | + new Timestamped<>(portDescriptions, newTimestamp); |
| 303 | - deltaDescs.add(new Timestamped<PortDescription>(e, newTimestamp)); | ||
| 304 | - } | ||
| 305 | 318 | ||
| 306 | - List<DeviceEvent> events = updatePortsInternal(providerId, deviceId, | 319 | + List<DeviceEvent> events = updatePortsInternal(providerId, deviceId, timestampedPortDescriptions); |
| 307 | - new Timestamped<>(portDescriptions, newTimestamp)); | ||
| 308 | if (!events.isEmpty()) { | 320 | if (!events.isEmpty()) { |
| 309 | - // FIXME: broadcast deltaDesc, UP | 321 | + log.info("Notifying peers of a port update topology event for providerId: {} and deviceId: {}", |
| 310 | - log.debug("broadcast deltaDesc"); | 322 | + providerId, deviceId); |
| 323 | + try { | ||
| 324 | + notifyPeers(new InternalPortEvent(providerId, deviceId, timestampedPortDescriptions)); | ||
| 325 | + } catch (IOException e) { | ||
| 326 | + log.error("Failed to notify peers of a port update topology event or providerId: " | ||
| 327 | + + providerId + " and deviceId: " + deviceId, e); | ||
| 328 | + } | ||
| 311 | } | 329 | } |
| 312 | return events; | 330 | return events; |
| 313 | - | ||
| 314 | } | 331 | } |
| 315 | 332 | ||
| 316 | private List<DeviceEvent> updatePortsInternal(ProviderId providerId, | 333 | private List<DeviceEvent> updatePortsInternal(ProviderId providerId, |
| ... | @@ -437,8 +454,14 @@ public class GossipDeviceStore | ... | @@ -437,8 +454,14 @@ public class GossipDeviceStore |
| 437 | final Timestamped<PortDescription> deltaDesc = new Timestamped<>(portDescription, newTimestamp); | 454 | final Timestamped<PortDescription> deltaDesc = new Timestamped<>(portDescription, newTimestamp); |
| 438 | DeviceEvent event = updatePortStatusInternal(providerId, deviceId, deltaDesc); | 455 | DeviceEvent event = updatePortStatusInternal(providerId, deviceId, deltaDesc); |
| 439 | if (event != null) { | 456 | if (event != null) { |
| 440 | - // FIXME: broadcast deltaDesc | 457 | + log.info("Notifying peers of a port status update topology event for providerId: {} and deviceId: {}", |
| 441 | - log.debug("broadcast deltaDesc"); | 458 | + providerId, deviceId); |
| 459 | + try { | ||
| 460 | + notifyPeers(new InternalPortStatusEvent(providerId, deviceId, deltaDesc)); | ||
| 461 | + } catch (IOException e) { | ||
| 462 | + log.error("Failed to notify peers of a port status update topology event or providerId: " | ||
| 463 | + + providerId + " and deviceId: " + deviceId, e); | ||
| 464 | + } | ||
| 442 | } | 465 | } |
| 443 | return event; | 466 | return event; |
| 444 | } | 467 | } |
| ... | @@ -749,4 +772,61 @@ public class GossipDeviceStore | ... | @@ -749,4 +772,61 @@ public class GossipDeviceStore |
| 749 | return portDescs.put(newOne.value().portNumber(), newOne); | 772 | return portDescs.put(newOne.value().portNumber(), newOne); |
| 750 | } | 773 | } |
| 751 | } | 774 | } |
| 775 | + | ||
| 776 | + private void notifyPeers(InternalDeviceEvent event) throws IOException { | ||
| 777 | + ClusterMessage message = new ClusterMessage(null, new MessageSubject("peer-device-updates"), event); | ||
| 778 | + clusterCommunicator.broadcast(message); | ||
| 779 | + } | ||
| 780 | + | ||
| 781 | + private void notifyPeers(InternalPortEvent event) throws IOException { | ||
| 782 | + ClusterMessage message = new ClusterMessage(null, new MessageSubject("peer-port-updates"), event); | ||
| 783 | + clusterCommunicator.broadcast(message); | ||
| 784 | + } | ||
| 785 | + | ||
| 786 | + private void notifyPeers(InternalPortStatusEvent event) throws IOException { | ||
| 787 | + ClusterMessage message = new ClusterMessage(null, new MessageSubject("peer-port-status-updates"), event); | ||
| 788 | + clusterCommunicator.broadcast(message); | ||
| 789 | + } | ||
| 790 | + | ||
| 791 | + private class InternalDeviceEventListener implements ClusterMessageHandler { | ||
| 792 | + @Override | ||
| 793 | + public void handle(ClusterMessage message) { | ||
| 794 | + log.info("Received device update event from peer: {}", message.sender()); | ||
| 795 | + InternalDeviceEvent event = (InternalDeviceEvent) message.payload(); | ||
| 796 | + ProviderId providerId = event.providerId(); | ||
| 797 | + DeviceId deviceId = event.deviceId(); | ||
| 798 | + Timestamped<DeviceDescription> deviceDescription = event.deviceDescription(); | ||
| 799 | + createOrUpdateDeviceInternal(providerId, deviceId, deviceDescription); | ||
| 800 | + } | ||
| 801 | + } | ||
| 802 | + | ||
| 803 | + private class InternalPortEventListener implements ClusterMessageHandler { | ||
| 804 | + @Override | ||
| 805 | + public void handle(ClusterMessage message) { | ||
| 806 | + | ||
| 807 | + log.info("Received port update event from peer: {}", message.sender()); | ||
| 808 | + InternalPortEvent event = (InternalPortEvent) message.payload(); | ||
| 809 | + | ||
| 810 | + ProviderId providerId = event.providerId(); | ||
| 811 | + DeviceId deviceId = event.deviceId(); | ||
| 812 | + Timestamped<List<PortDescription>> portDescriptions = event.portDescriptions(); | ||
| 813 | + | ||
| 814 | + updatePortsInternal(providerId, deviceId, portDescriptions); | ||
| 815 | + } | ||
| 816 | + } | ||
| 817 | + | ||
| 818 | + private class InternalPortStatusEventListener implements ClusterMessageHandler { | ||
| 819 | + @Override | ||
| 820 | + public void handle(ClusterMessage message) { | ||
| 821 | + | ||
| 822 | + log.info("Received port status update event from peer: {}", message.sender()); | ||
| 823 | + InternalPortStatusEvent event = (InternalPortStatusEvent) message.payload(); | ||
| 824 | + | ||
| 825 | + ProviderId providerId = event.providerId(); | ||
| 826 | + DeviceId deviceId = event.deviceId(); | ||
| 827 | + Timestamped<PortDescription> portDescription = event.portDescription(); | ||
| 828 | + | ||
| 829 | + updatePortStatusInternal(providerId, deviceId, portDescription); | ||
| 830 | + } | ||
| 831 | + } | ||
| 752 | } | 832 | } | ... | ... |
| 1 | +package org.onlab.onos.store.device.impl; | ||
| 2 | + | ||
| 3 | +import org.onlab.onos.net.DeviceId; | ||
| 4 | +import org.onlab.onos.net.device.DeviceDescription; | ||
| 5 | +import org.onlab.onos.net.provider.ProviderId; | ||
| 6 | +import org.onlab.onos.store.common.impl.Timestamped; | ||
| 7 | + | ||
| 8 | +public class InternalDeviceEvent { | ||
| 9 | + | ||
| 10 | + private final ProviderId providerId; | ||
| 11 | + private final DeviceId deviceId; | ||
| 12 | + private final Timestamped<DeviceDescription> deviceDescription; | ||
| 13 | + | ||
| 14 | + protected InternalDeviceEvent( | ||
| 15 | + ProviderId providerId, | ||
| 16 | + DeviceId deviceId, | ||
| 17 | + Timestamped<DeviceDescription> deviceDescription) { | ||
| 18 | + this.providerId = providerId; | ||
| 19 | + this.deviceId = deviceId; | ||
| 20 | + this.deviceDescription = deviceDescription; | ||
| 21 | + } | ||
| 22 | + | ||
| 23 | + public DeviceId deviceId() { | ||
| 24 | + return deviceId; | ||
| 25 | + } | ||
| 26 | + | ||
| 27 | + public ProviderId providerId() { | ||
| 28 | + return providerId; | ||
| 29 | + } | ||
| 30 | + | ||
| 31 | + public Timestamped<DeviceDescription> deviceDescription() { | ||
| 32 | + return deviceDescription; | ||
| 33 | + } | ||
| 34 | +} |
| 1 | +package org.onlab.onos.store.device.impl; | ||
| 2 | + | ||
| 3 | +import java.util.List; | ||
| 4 | + | ||
| 5 | +import org.onlab.onos.net.DeviceId; | ||
| 6 | +import org.onlab.onos.net.device.PortDescription; | ||
| 7 | +import org.onlab.onos.net.provider.ProviderId; | ||
| 8 | +import org.onlab.onos.store.common.impl.Timestamped; | ||
| 9 | + | ||
| 10 | +public class InternalPortEvent { | ||
| 11 | + | ||
| 12 | + private final ProviderId providerId; | ||
| 13 | + private final DeviceId deviceId; | ||
| 14 | + private final Timestamped<List<PortDescription>> portDescriptions; | ||
| 15 | + | ||
| 16 | + protected InternalPortEvent( | ||
| 17 | + ProviderId providerId, | ||
| 18 | + DeviceId deviceId, | ||
| 19 | + Timestamped<List<PortDescription>> portDescriptions) { | ||
| 20 | + this.providerId = providerId; | ||
| 21 | + this.deviceId = deviceId; | ||
| 22 | + this.portDescriptions = portDescriptions; | ||
| 23 | + } | ||
| 24 | + | ||
| 25 | + public DeviceId deviceId() { | ||
| 26 | + return deviceId; | ||
| 27 | + } | ||
| 28 | + | ||
| 29 | + public ProviderId providerId() { | ||
| 30 | + return providerId; | ||
| 31 | + } | ||
| 32 | + | ||
| 33 | + public Timestamped<List<PortDescription>> portDescriptions() { | ||
| 34 | + return portDescriptions; | ||
| 35 | + } | ||
| 36 | +} |
core/store/dist/src/main/java/org/onlab/onos/store/device/impl/InternalPortStatusEvent.java
0 → 100644
| 1 | +package org.onlab.onos.store.device.impl; | ||
| 2 | + | ||
| 3 | +import org.onlab.onos.net.DeviceId; | ||
| 4 | +import org.onlab.onos.net.device.PortDescription; | ||
| 5 | +import org.onlab.onos.net.provider.ProviderId; | ||
| 6 | +import org.onlab.onos.store.common.impl.Timestamped; | ||
| 7 | + | ||
| 8 | +public class InternalPortStatusEvent { | ||
| 9 | + | ||
| 10 | + private final ProviderId providerId; | ||
| 11 | + private final DeviceId deviceId; | ||
| 12 | + private final Timestamped<PortDescription> portDescription; | ||
| 13 | + | ||
| 14 | + protected InternalPortStatusEvent( | ||
| 15 | + ProviderId providerId, | ||
| 16 | + DeviceId deviceId, | ||
| 17 | + Timestamped<PortDescription> portDescription) { | ||
| 18 | + this.providerId = providerId; | ||
| 19 | + this.deviceId = deviceId; | ||
| 20 | + this.portDescription = portDescription; | ||
| 21 | + } | ||
| 22 | + | ||
| 23 | + public DeviceId deviceId() { | ||
| 24 | + return deviceId; | ||
| 25 | + } | ||
| 26 | + | ||
| 27 | + public ProviderId providerId() { | ||
| 28 | + return providerId; | ||
| 29 | + } | ||
| 30 | + | ||
| 31 | + public Timestamped<PortDescription> portDescription() { | ||
| 32 | + return portDescription; | ||
| 33 | + } | ||
| 34 | +} |
core/store/dist/src/test/java/org/onlab/onos/store/cluster/impl/ClusterCommunicationManagerTest.java
| ... | @@ -7,6 +7,7 @@ import org.junit.Test; | ... | @@ -7,6 +7,7 @@ import org.junit.Test; |
| 7 | import org.onlab.onos.cluster.DefaultControllerNode; | 7 | import org.onlab.onos.cluster.DefaultControllerNode; |
| 8 | import org.onlab.onos.cluster.NodeId; | 8 | import org.onlab.onos.cluster.NodeId; |
| 9 | import org.onlab.onos.store.cluster.messaging.impl.ClusterCommunicationManager; | 9 | import org.onlab.onos.store.cluster.messaging.impl.ClusterCommunicationManager; |
| 10 | +import org.onlab.onos.store.cluster.messaging.impl.MessageSerializer; | ||
| 10 | import org.onlab.netty.NettyMessagingService; | 11 | import org.onlab.netty.NettyMessagingService; |
| 11 | import org.onlab.packet.IpPrefix; | 12 | import org.onlab.packet.IpPrefix; |
| 12 | 13 | ... | ... |
| ... | @@ -5,6 +5,7 @@ import static org.onlab.onos.net.Device.Type.SWITCH; | ... | @@ -5,6 +5,7 @@ import static org.onlab.onos.net.Device.Type.SWITCH; |
| 5 | import static org.onlab.onos.net.DeviceId.deviceId; | 5 | import static org.onlab.onos.net.DeviceId.deviceId; |
| 6 | import static org.onlab.onos.net.device.DeviceEvent.Type.*; | 6 | import static org.onlab.onos.net.device.DeviceEvent.Type.*; |
| 7 | 7 | ||
| 8 | +import java.io.IOException; | ||
| 8 | import java.util.Arrays; | 9 | import java.util.Arrays; |
| 9 | import java.util.HashMap; | 10 | import java.util.HashMap; |
| 10 | import java.util.List; | 11 | import java.util.List; |
| ... | @@ -37,6 +38,10 @@ import org.onlab.onos.net.device.DeviceStoreDelegate; | ... | @@ -37,6 +38,10 @@ import org.onlab.onos.net.device.DeviceStoreDelegate; |
| 37 | import org.onlab.onos.net.device.PortDescription; | 38 | import org.onlab.onos.net.device.PortDescription; |
| 38 | import org.onlab.onos.net.provider.ProviderId; | 39 | import org.onlab.onos.net.provider.ProviderId; |
| 39 | import org.onlab.onos.store.ClockService; | 40 | import org.onlab.onos.store.ClockService; |
| 41 | +import org.onlab.onos.store.cluster.messaging.ClusterCommunicationService; | ||
| 42 | +import org.onlab.onos.store.cluster.messaging.ClusterMessage; | ||
| 43 | +import org.onlab.onos.store.cluster.messaging.ClusterMessageHandler; | ||
| 44 | +import org.onlab.onos.store.cluster.messaging.MessageSubject; | ||
| 40 | 45 | ||
| 41 | import com.google.common.collect.Iterables; | 46 | import com.google.common.collect.Iterables; |
| 42 | import com.google.common.collect.Sets; | 47 | import com.google.common.collect.Sets; |
| ... | @@ -105,7 +110,9 @@ public class GossipDeviceStoreTest { | ... | @@ -105,7 +110,9 @@ public class GossipDeviceStoreTest { |
| 105 | deviceClockManager.setMastershipTerm(DID1, MastershipTerm.of(MYSELF, 1)); | 110 | deviceClockManager.setMastershipTerm(DID1, MastershipTerm.of(MYSELF, 1)); |
| 106 | deviceClockManager.setMastershipTerm(DID2, MastershipTerm.of(MYSELF, 2)); | 111 | deviceClockManager.setMastershipTerm(DID2, MastershipTerm.of(MYSELF, 2)); |
| 107 | 112 | ||
| 108 | - gossipDeviceStore = new TestGossipDeviceStore(clockService); | 113 | + ClusterCommunicationService clusterCommunicator = new TestClusterCommunicationService(); |
| 114 | + | ||
| 115 | + gossipDeviceStore = new TestGossipDeviceStore(clockService, clusterCommunicator); | ||
| 109 | gossipDeviceStore.activate(); | 116 | gossipDeviceStore.activate(); |
| 110 | deviceStore = gossipDeviceStore; | 117 | deviceStore = gossipDeviceStore; |
| 111 | } | 118 | } |
| ... | @@ -541,8 +548,20 @@ public class GossipDeviceStoreTest { | ... | @@ -541,8 +548,20 @@ public class GossipDeviceStoreTest { |
| 541 | 548 | ||
| 542 | private static final class TestGossipDeviceStore extends GossipDeviceStore { | 549 | private static final class TestGossipDeviceStore extends GossipDeviceStore { |
| 543 | 550 | ||
| 544 | - public TestGossipDeviceStore(ClockService clockService) { | 551 | + public TestGossipDeviceStore(ClockService clockService, ClusterCommunicationService clusterCommunicator) { |
| 545 | this.clockService = clockService; | 552 | this.clockService = clockService; |
| 553 | + this.clusterCommunicator = clusterCommunicator; | ||
| 546 | } | 554 | } |
| 547 | } | 555 | } |
| 556 | + | ||
| 557 | + private static final class TestClusterCommunicationService implements ClusterCommunicationService { | ||
| 558 | + @Override | ||
| 559 | + public boolean broadcast(ClusterMessage message) throws IOException { return true; } | ||
| 560 | + @Override | ||
| 561 | + public boolean unicast(ClusterMessage message, NodeId nodeId) throws IOException { return true; } | ||
| 562 | + @Override | ||
| 563 | + public boolean multicast(ClusterMessage message, Set<NodeId> nodeIds) throws IOException { return true; } | ||
| 564 | + @Override | ||
| 565 | + public void addSubscriber(MessageSubject subject, ClusterMessageHandler subscriber) {} | ||
| 566 | + } | ||
| 548 | } | 567 | } | ... | ... |
| ... | @@ -45,12 +45,12 @@ public class KryoSerializer implements Serializer { | ... | @@ -45,12 +45,12 @@ public class KryoSerializer implements Serializer { |
| 45 | } | 45 | } |
| 46 | 46 | ||
| 47 | @Override | 47 | @Override |
| 48 | - public <T> T deserialize(ByteBuffer buffer) { | 48 | + public <T> T decode(ByteBuffer buffer) { |
| 49 | return serializerPool.deserialize(buffer); | 49 | return serializerPool.deserialize(buffer); |
| 50 | } | 50 | } |
| 51 | 51 | ||
| 52 | @Override | 52 | @Override |
| 53 | - public void serialize(Object obj, ByteBuffer buffer) { | 53 | + public void encode(Object obj, ByteBuffer buffer) { |
| 54 | serializerPool.serialize(obj, buffer); | 54 | serializerPool.serialize(obj, buffer); |
| 55 | } | 55 | } |
| 56 | } | 56 | } | ... | ... |
| ... | @@ -48,7 +48,7 @@ public class MessageDecoder extends ReplayingDecoder<DecoderState> { | ... | @@ -48,7 +48,7 @@ public class MessageDecoder extends ReplayingDecoder<DecoderState> { |
| 48 | checkState(serializerVersion == MessageEncoder.SERIALIZER_VERSION, "Unexpected serializer version"); | 48 | checkState(serializerVersion == MessageEncoder.SERIALIZER_VERSION, "Unexpected serializer version"); |
| 49 | checkpoint(DecoderState.READ_CONTENT); | 49 | checkpoint(DecoderState.READ_CONTENT); |
| 50 | case READ_CONTENT: | 50 | case READ_CONTENT: |
| 51 | - InternalMessage message = serializer.deserialize(buffer.readBytes(contentLength).nioBuffer()); | 51 | + InternalMessage message = serializer.decode(buffer.readBytes(contentLength).nioBuffer()); |
| 52 | message.setMessagingService(messagingService); | 52 | message.setMessagingService(messagingService); |
| 53 | out.add(message); | 53 | out.add(message); |
| 54 | checkpoint(DecoderState.READ_HEADER_VERSION); | 54 | checkpoint(DecoderState.READ_HEADER_VERSION); | ... | ... |
| ... | @@ -24,20 +24,18 @@ public interface Serializer { | ... | @@ -24,20 +24,18 @@ public interface Serializer { |
| 24 | public byte[] encode(Object data); | 24 | public byte[] encode(Object data); |
| 25 | 25 | ||
| 26 | /** | 26 | /** |
| 27 | - * Serializes the specified object into bytes using one of the | 27 | + * Encodes the specified POJO into a byte buffer. |
| 28 | - * pre-registered serializers. | ||
| 29 | * | 28 | * |
| 30 | - * @param obj object to be serialized | 29 | + * @param data POJO to be encoded |
| 31 | * @param buffer to write serialized bytes | 30 | * @param buffer to write serialized bytes |
| 32 | */ | 31 | */ |
| 33 | - public void serialize(final Object obj, ByteBuffer buffer); | 32 | + public void encode(final Object data, ByteBuffer buffer); |
| 34 | 33 | ||
| 35 | /** | 34 | /** |
| 36 | - * Deserializes the specified bytes into an object using one of the | 35 | + * Decodes the specified byte buffer to a POJO. |
| 37 | - * pre-registered serializers. | ||
| 38 | * | 36 | * |
| 39 | - * @param buffer bytes to be deserialized | 37 | + * @param buffer bytes to be decoded |
| 40 | - * @return deserialized object | 38 | + * @return POJO |
| 41 | */ | 39 | */ |
| 42 | - public <T> T deserialize(final ByteBuffer buffer); | 40 | + public <T> T decode(final ByteBuffer buffer); |
| 43 | } | 41 | } | ... | ... |
-
Please register or login to post a comment