Showing
56 changed files
with
792 additions
and
234 deletions
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 | + | ||
4 | import org.apache.karaf.shell.commands.Command; | 5 | import org.apache.karaf.shell.commands.Command; |
5 | import org.onlab.onos.cluster.ClusterService; | 6 | import org.onlab.onos.cluster.ClusterService; |
6 | import org.onlab.onos.cluster.ControllerNode; | 7 | 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; | ||
9 | 10 | ||
10 | import java.util.Collections; | 11 | import java.util.Collections; |
11 | import java.util.List; | 12 | import java.util.List; |
... | @@ -22,7 +23,7 @@ public class MastersListCommand extends AbstractShellCommand { | ... | @@ -22,7 +23,7 @@ public class MastersListCommand extends AbstractShellCommand { |
22 | @Override | 23 | @Override |
23 | protected void execute() { | 24 | protected void execute() { |
24 | ClusterService service = get(ClusterService.class); | 25 | ClusterService service = get(ClusterService.class); |
25 | - MastershipService mastershipService = get(MastershipService.class); | 26 | + DeviceMastershipService mastershipService = get(DeviceMastershipService.class); |
26 | List<ControllerNode> nodes = newArrayList(service.getNodes()); | 27 | List<ControllerNode> nodes = newArrayList(service.getNodes()); |
27 | Collections.sort(nodes, Comparators.NODE_COMPARATOR); | 28 | Collections.sort(nodes, Comparators.NODE_COMPARATOR); |
28 | ControllerNode self = service.getLocalNode(); | 29 | ControllerNode self = service.getLocalNode(); | ... | ... |
... | @@ -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; | ||
7 | import org.onlab.onos.cluster.NodeId; | 6 | import org.onlab.onos.cluster.NodeId; |
8 | import org.onlab.onos.net.MastershipRole; | 7 | 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 | - MastershipAdminService service = get(MastershipAdminService.class); | 33 | + DeviceMastershipAdminService service = get(DeviceMastershipAdminService.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.cluster; | 1 | +package org.onlab.onos.net.device; |
2 | 2 | ||
3 | +import org.onlab.onos.cluster.NodeId; | ||
3 | import org.onlab.onos.net.DeviceId; | 4 | import org.onlab.onos.net.DeviceId; |
4 | import org.onlab.onos.net.MastershipRole; | 5 | import org.onlab.onos.net.MastershipRole; |
5 | 6 | ||
6 | /** | 7 | /** |
7 | * Service for administering the inventory of device masterships. | 8 | * Service for administering the inventory of device masterships. |
8 | */ | 9 | */ |
9 | -public interface MastershipAdminService { | 10 | +public interface DeviceMastershipAdminService { |
10 | 11 | ||
11 | /** | 12 | /** |
12 | * Applies the current mastership role for the specified device. | 13 | * Applies the current mastership role for the specified device. | ... | ... |
1 | -package org.onlab.onos.cluster; | 1 | +package org.onlab.onos.net.device; |
2 | 2 | ||
3 | +import org.onlab.onos.cluster.NodeId; | ||
3 | import org.onlab.onos.event.AbstractEvent; | 4 | import org.onlab.onos.event.AbstractEvent; |
4 | import org.onlab.onos.net.DeviceId; | 5 | import org.onlab.onos.net.DeviceId; |
5 | 6 | ||
6 | /** | 7 | /** |
7 | * Describes a device mastership event. | 8 | * Describes a device mastership event. |
8 | */ | 9 | */ |
9 | -public class MastershipEvent extends AbstractEvent<MastershipEvent.Type, DeviceId> { | 10 | +public class DeviceMastershipEvent extends AbstractEvent<DeviceMastershipEvent.Type, DeviceId> { |
10 | 11 | ||
11 | //do we worry about explicitly setting slaves/equals? probably not, | 12 | //do we worry about explicitly setting slaves/equals? probably not, |
12 | //to keep it simple | 13 | //to keep it simple |
... | @@ -30,7 +31,7 @@ public class MastershipEvent extends AbstractEvent<MastershipEvent.Type, DeviceI | ... | @@ -30,7 +31,7 @@ public class MastershipEvent extends AbstractEvent<MastershipEvent.Type, DeviceI |
30 | * @param device event device subject | 31 | * @param device event device subject |
31 | * @param master master ID subject | 32 | * @param master master ID subject |
32 | */ | 33 | */ |
33 | - public MastershipEvent(Type type, DeviceId device, NodeId master) { | 34 | + public DeviceMastershipEvent(Type type, DeviceId device, NodeId master) { |
34 | super(type, device); | 35 | super(type, device); |
35 | this.master = master; | 36 | this.master = master; |
36 | } | 37 | } |
... | @@ -44,7 +45,7 @@ public class MastershipEvent extends AbstractEvent<MastershipEvent.Type, DeviceI | ... | @@ -44,7 +45,7 @@ public class MastershipEvent extends AbstractEvent<MastershipEvent.Type, DeviceI |
44 | * @param master master ID subject | 45 | * @param master master ID subject |
45 | * @param time occurrence time | 46 | * @param time occurrence time |
46 | */ | 47 | */ |
47 | - public MastershipEvent(Type type, DeviceId device, NodeId master, long time) { | 48 | + public DeviceMastershipEvent(Type type, DeviceId device, NodeId master, long time) { |
48 | super(type, device, time); | 49 | super(type, device, time); |
49 | this.master = master; | 50 | this.master = master; |
50 | } | 51 | } | ... | ... |
1 | -package org.onlab.onos.cluster; | 1 | +package org.onlab.onos.net.device; |
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 MastershipListener extends EventListener<MastershipEvent> { | 8 | +public interface DeviceMastershipListener extends EventListener<DeviceMastershipEvent> { |
9 | } | 9 | } | ... | ... |
1 | -package org.onlab.onos.cluster; | 1 | +package org.onlab.onos.net.device; |
2 | 2 | ||
3 | import java.util.Set; | 3 | import java.util.Set; |
4 | 4 | ||
5 | +import org.onlab.onos.cluster.NodeId; | ||
5 | import org.onlab.onos.net.DeviceId; | 6 | import org.onlab.onos.net.DeviceId; |
6 | import org.onlab.onos.net.MastershipRole; | 7 | import org.onlab.onos.net.MastershipRole; |
7 | 8 | ||
... | @@ -11,7 +12,7 @@ import org.onlab.onos.net.MastershipRole; | ... | @@ -11,7 +12,7 @@ import org.onlab.onos.net.MastershipRole; |
11 | * determining mastership, but is not responsible for actually applying it | 12 | * determining mastership, but is not responsible for actually applying it |
12 | * to the devices; this falls on the device service. | 13 | * to the devices; this falls on the device service. |
13 | */ | 14 | */ |
14 | -public interface MastershipService { | 15 | +public interface DeviceMastershipService { |
15 | 16 | ||
16 | /** | 17 | /** |
17 | * Returns the role of the local node for the specified device, without | 18 | * Returns the role of the local node for the specified device, without |
... | @@ -62,20 +63,20 @@ public interface MastershipService { | ... | @@ -62,20 +63,20 @@ public interface MastershipService { |
62 | * | 63 | * |
63 | * @return the MastershipTermService for this mastership manager | 64 | * @return the MastershipTermService for this mastership manager |
64 | */ | 65 | */ |
65 | - MastershipTermService requestTermService(); | 66 | + DeviceMastershipTermService requestTermService(); |
66 | 67 | ||
67 | /** | 68 | /** |
68 | * Adds the specified mastership change listener. | 69 | * Adds the specified mastership change listener. |
69 | * | 70 | * |
70 | * @param listener the mastership listener | 71 | * @param listener the mastership listener |
71 | */ | 72 | */ |
72 | - void addListener(MastershipListener listener); | 73 | + void addListener(DeviceMastershipListener listener); |
73 | 74 | ||
74 | /** | 75 | /** |
75 | * Removes the specified mastership change listener. | 76 | * Removes the specified mastership change listener. |
76 | * | 77 | * |
77 | * @param listener the mastership listener | 78 | * @param listener the mastership listener |
78 | */ | 79 | */ |
79 | - void removeListener(MastershipListener listener); | 80 | + void removeListener(DeviceMastershipListener listener); |
80 | 81 | ||
81 | } | 82 | } | ... | ... |
1 | -package org.onlab.onos.cluster; | 1 | +package org.onlab.onos.net.device; |
2 | 2 | ||
3 | import java.util.Set; | 3 | import java.util.Set; |
4 | 4 | ||
5 | +import org.onlab.onos.cluster.NodeId; | ||
5 | import org.onlab.onos.net.DeviceId; | 6 | import org.onlab.onos.net.DeviceId; |
6 | import org.onlab.onos.net.MastershipRole; | 7 | import org.onlab.onos.net.MastershipRole; |
7 | import org.onlab.onos.store.Store; | 8 | import org.onlab.onos.store.Store; |
... | @@ -10,7 +11,7 @@ import org.onlab.onos.store.Store; | ... | @@ -10,7 +11,7 @@ import org.onlab.onos.store.Store; |
10 | * Manages inventory of mastership roles for devices, across controller | 11 | * Manages inventory of mastership roles for devices, across controller |
11 | * instances; not intended for direct use. | 12 | * instances; not intended for direct use. |
12 | */ | 13 | */ |
13 | -public interface MastershipStore extends Store<MastershipEvent, MastershipStoreDelegate> { | 14 | +public interface DeviceMastershipStore extends Store<DeviceMastershipEvent, DeviceMastershipStoreDelegate> { |
14 | 15 | ||
15 | // three things to map: NodeId, DeviceId, MastershipRole | 16 | // three things to map: NodeId, DeviceId, MastershipRole |
16 | 17 | ||
... | @@ -54,7 +55,7 @@ public interface MastershipStore extends Store<MastershipEvent, MastershipStoreD | ... | @@ -54,7 +55,7 @@ public interface MastershipStore extends Store<MastershipEvent, MastershipStoreD |
54 | * @param deviceId device identifier | 55 | * @param deviceId device identifier |
55 | * @return a mastership event | 56 | * @return a mastership event |
56 | */ | 57 | */ |
57 | - MastershipEvent setMaster(NodeId nodeId, DeviceId deviceId); | 58 | + DeviceMastershipEvent setMaster(NodeId nodeId, DeviceId deviceId); |
58 | 59 | ||
59 | /** | 60 | /** |
60 | * Returns the current master and number of past mastership hand-offs | 61 | * Returns the current master and number of past mastership hand-offs |
... | @@ -63,7 +64,7 @@ public interface MastershipStore extends Store<MastershipEvent, MastershipStoreD | ... | @@ -63,7 +64,7 @@ public interface MastershipStore extends Store<MastershipEvent, MastershipStoreD |
63 | * @param deviceId the device identifier | 64 | * @param deviceId the device identifier |
64 | * @return the current master's ID and the term value for device, or null | 65 | * @return the current master's ID and the term value for device, or null |
65 | */ | 66 | */ |
66 | - MastershipTerm getTermFor(DeviceId deviceId); | 67 | + DeviceMastershipTerm getTermFor(DeviceId deviceId); |
67 | 68 | ||
68 | /** | 69 | /** |
69 | * Sets a controller instance's mastership role to STANDBY for a device. | 70 | * Sets a controller instance's mastership role to STANDBY for a device. |
... | @@ -74,7 +75,7 @@ public interface MastershipStore extends Store<MastershipEvent, MastershipStoreD | ... | @@ -74,7 +75,7 @@ public interface MastershipStore extends Store<MastershipEvent, MastershipStoreD |
74 | * @param deviceId device to revoke mastership role for | 75 | * @param deviceId device to revoke mastership role for |
75 | * @return a mastership event | 76 | * @return a mastership event |
76 | */ | 77 | */ |
77 | - MastershipEvent setStandby(NodeId nodeId, DeviceId deviceId); | 78 | + DeviceMastershipEvent setStandby(NodeId nodeId, DeviceId deviceId); |
78 | 79 | ||
79 | /** | 80 | /** |
80 | * Allows a controller instance to give up its current role for a device. | 81 | * Allows a controller instance to give up its current role for a device. |
... | @@ -85,6 +86,6 @@ public interface MastershipStore extends Store<MastershipEvent, MastershipStoreD | ... | @@ -85,6 +86,6 @@ public interface MastershipStore extends Store<MastershipEvent, MastershipStoreD |
85 | * @param deviceId device to revoke mastership role for | 86 | * @param deviceId device to revoke mastership role for |
86 | * @return a mastership event | 87 | * @return a mastership event |
87 | */ | 88 | */ |
88 | - MastershipEvent relinquishRole(NodeId nodeId, DeviceId deviceId); | 89 | + DeviceMastershipEvent relinquishRole(NodeId nodeId, DeviceId deviceId); |
89 | 90 | ||
90 | } | 91 | } | ... | ... |
1 | -package org.onlab.onos.cluster; | 1 | +package org.onlab.onos.net.device; |
2 | 2 | ||
3 | import org.onlab.onos.store.StoreDelegate; | 3 | import org.onlab.onos.store.StoreDelegate; |
4 | 4 | ||
5 | /** | 5 | /** |
6 | - * Mastership store delegate abstraction. | 6 | + * DeviceMastership store delegate abstraction. |
7 | */ | 7 | */ |
8 | -public interface MastershipStoreDelegate extends StoreDelegate<MastershipEvent> { | 8 | +public interface DeviceMastershipStoreDelegate extends StoreDelegate<DeviceMastershipEvent> { |
9 | } | 9 | } | ... | ... |
1 | -package org.onlab.onos.cluster; | 1 | +package org.onlab.onos.net.device; |
2 | 2 | ||
3 | import java.util.Objects; | 3 | import java.util.Objects; |
4 | 4 | ||
5 | -public final class MastershipTerm { | 5 | +import org.onlab.onos.cluster.NodeId; |
6 | + | ||
7 | +public final class DeviceMastershipTerm { | ||
6 | 8 | ||
7 | private final NodeId master; | 9 | private final NodeId master; |
8 | private final int termNumber; | 10 | private final int termNumber; |
9 | 11 | ||
10 | - private MastershipTerm(NodeId master, int term) { | 12 | + private DeviceMastershipTerm(NodeId master, int term) { |
11 | this.master = master; | 13 | this.master = master; |
12 | this.termNumber = term; | 14 | this.termNumber = term; |
13 | } | 15 | } |
14 | 16 | ||
15 | - public static MastershipTerm of(NodeId master, int term) { | 17 | + public static DeviceMastershipTerm of(NodeId master, int term) { |
16 | - return new MastershipTerm(master, term); | 18 | + return new DeviceMastershipTerm(master, term); |
17 | } | 19 | } |
18 | 20 | ||
19 | public NodeId master() { | 21 | public NodeId master() { |
... | @@ -34,8 +36,8 @@ public final class MastershipTerm { | ... | @@ -34,8 +36,8 @@ public final class MastershipTerm { |
34 | if (this == other) { | 36 | if (this == other) { |
35 | return true; | 37 | return true; |
36 | } | 38 | } |
37 | - if (other instanceof MastershipTerm) { | 39 | + if (other instanceof DeviceMastershipTerm) { |
38 | - MastershipTerm that = (MastershipTerm) other; | 40 | + DeviceMastershipTerm that = (DeviceMastershipTerm) other; |
39 | if (!this.master.equals(that.master)) { | 41 | if (!this.master.equals(that.master)) { |
40 | return false; | 42 | return false; |
41 | } | 43 | } | ... | ... |
1 | -package org.onlab.onos.cluster; | 1 | +package org.onlab.onos.net.device; |
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 MastershipTermService { | 9 | +public interface DeviceMastershipTermService { |
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 MastershipTermService { | ... | @@ -16,5 +16,5 @@ public interface MastershipTermService { |
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 | - MastershipTerm getMastershipTerm(DeviceId deviceId); | 19 | + DeviceMastershipTerm getMastershipTerm(DeviceId deviceId); |
20 | } | 20 | } | ... | ... |
... | @@ -140,6 +140,16 @@ public final class DefaultTrafficSelector implements TrafficSelector { | ... | @@ -140,6 +140,16 @@ public final class DefaultTrafficSelector implements TrafficSelector { |
140 | } | 140 | } |
141 | 141 | ||
142 | @Override | 142 | @Override |
143 | + public Builder matchTcpSrc(Short tcpPort) { | ||
144 | + return add(Criteria.matchTcpSrc(tcpPort)); | ||
145 | + } | ||
146 | + | ||
147 | + @Override | ||
148 | + public Builder matchTcpDst(Short tcpPort) { | ||
149 | + return add(Criteria.matchTcpDst(tcpPort)); | ||
150 | + } | ||
151 | + | ||
152 | + @Override | ||
143 | public TrafficSelector build() { | 153 | public TrafficSelector build() { |
144 | return new DefaultTrafficSelector(ImmutableSet.copyOf(selector.values())); | 154 | return new DefaultTrafficSelector(ImmutableSet.copyOf(selector.values())); |
145 | } | 155 | } | ... | ... |
... | @@ -98,6 +98,20 @@ public interface TrafficSelector { | ... | @@ -98,6 +98,20 @@ public interface TrafficSelector { |
98 | public Builder matchIPDst(IpPrefix ip); | 98 | public Builder matchIPDst(IpPrefix ip); |
99 | 99 | ||
100 | /** | 100 | /** |
101 | + * Matches a TCP source port number. | ||
102 | + * @param tcpPort a TCP source port number | ||
103 | + * @return a selection builder | ||
104 | + */ | ||
105 | + public Builder matchTcpSrc(Short tcpPort); | ||
106 | + | ||
107 | + /** | ||
108 | + * Matches a TCP destination port number. | ||
109 | + * @param tcpPort a TCP destination port number | ||
110 | + * @return a selection builder | ||
111 | + */ | ||
112 | + public Builder matchTcpDst(Short tcpPort); | ||
113 | + | ||
114 | + /** | ||
101 | * Builds an immutable traffic selector. | 115 | * Builds an immutable traffic selector. |
102 | * | 116 | * |
103 | * @return traffic selector | 117 | * @return traffic selector | ... | ... |
... | @@ -113,6 +113,25 @@ public final class Criteria { | ... | @@ -113,6 +113,25 @@ public final class Criteria { |
113 | return new IPCriterion(ip, Type.IPV4_DST); | 113 | return new IPCriterion(ip, Type.IPV4_DST); |
114 | } | 114 | } |
115 | 115 | ||
116 | + /** | ||
117 | + * Creates a match on TCP source port field using the specified value. | ||
118 | + * | ||
119 | + * @param tcpPort | ||
120 | + * @return match criterion | ||
121 | + */ | ||
122 | + public static Criterion matchTcpSrc(Short tcpPort) { | ||
123 | + return new TcpPortCriterion(tcpPort, Type.TCP_SRC); | ||
124 | + } | ||
125 | + | ||
126 | + /** | ||
127 | + * Creates a match on TCP destination port field using the specified value. | ||
128 | + * | ||
129 | + * @param tcpPort | ||
130 | + * @return match criterion | ||
131 | + */ | ||
132 | + public static Criterion matchTcpDst(Short tcpPort) { | ||
133 | + return new TcpPortCriterion(tcpPort, Type.TCP_DST); | ||
134 | + } | ||
116 | 135 | ||
117 | /* | 136 | /* |
118 | * Implementations of criteria. | 137 | * Implementations of criteria. |
... | @@ -437,4 +456,49 @@ public final class Criteria { | ... | @@ -437,4 +456,49 @@ public final class Criteria { |
437 | } | 456 | } |
438 | 457 | ||
439 | 458 | ||
459 | + public static final class TcpPortCriterion implements Criterion { | ||
460 | + | ||
461 | + private final Short tcpPort; | ||
462 | + private final Type type; | ||
463 | + | ||
464 | + public TcpPortCriterion(Short tcpPort, Type type) { | ||
465 | + this.tcpPort = tcpPort; | ||
466 | + this.type = type; | ||
467 | + } | ||
468 | + | ||
469 | + @Override | ||
470 | + public Type type() { | ||
471 | + return this.type; | ||
472 | + } | ||
473 | + | ||
474 | + public Short tcpPort() { | ||
475 | + return this.tcpPort; | ||
476 | + } | ||
477 | + | ||
478 | + @Override | ||
479 | + public String toString() { | ||
480 | + return toStringHelper(type().toString()) | ||
481 | + .add("tcpPort", tcpPort).toString(); | ||
482 | + } | ||
483 | + | ||
484 | + @Override | ||
485 | + public int hashCode() { | ||
486 | + return Objects.hash(tcpPort, type); | ||
487 | + } | ||
488 | + | ||
489 | + @Override | ||
490 | + public boolean equals(Object obj) { | ||
491 | + if (this == obj) { | ||
492 | + return true; | ||
493 | + } | ||
494 | + if (obj instanceof TcpPortCriterion) { | ||
495 | + TcpPortCriterion that = (TcpPortCriterion) obj; | ||
496 | + return Objects.equals(tcpPort, that.tcpPort) && | ||
497 | + Objects.equals(type, that.type); | ||
498 | + | ||
499 | + | ||
500 | + } | ||
501 | + return false; | ||
502 | + } | ||
503 | + } | ||
440 | } | 504 | } | ... | ... |
... | @@ -33,6 +33,8 @@ public interface IntentStore extends Store<IntentEvent, IntentStoreDelegate> { | ... | @@ -33,6 +33,8 @@ public interface IntentStore extends Store<IntentEvent, IntentStoreDelegate> { |
33 | 33 | ||
34 | /** | 34 | /** |
35 | * Returns the number of intents in the store. | 35 | * Returns the number of intents in the store. |
36 | + * | ||
37 | + * @return the number of intents in the store | ||
36 | */ | 38 | */ |
37 | long getIntentCount(); | 39 | long getIntentCount(); |
38 | 40 | ||
... | @@ -44,7 +46,7 @@ public interface IntentStore extends Store<IntentEvent, IntentStoreDelegate> { | ... | @@ -44,7 +46,7 @@ public interface IntentStore extends Store<IntentEvent, IntentStoreDelegate> { |
44 | Iterable<Intent> getIntents(); | 46 | Iterable<Intent> getIntents(); |
45 | 47 | ||
46 | /** | 48 | /** |
47 | - * Returns the intent with the specified identifer. | 49 | + * Returns the intent with the specified identifier. |
48 | * | 50 | * |
49 | * @param intentId intent identification | 51 | * @param intentId intent identification |
50 | * @return intent or null if not found | 52 | * @return intent or null if not found |
... | @@ -94,7 +96,6 @@ public interface IntentStore extends Store<IntentEvent, IntentStoreDelegate> { | ... | @@ -94,7 +96,6 @@ public interface IntentStore extends Store<IntentEvent, IntentStoreDelegate> { |
94 | * specified original intent. | 96 | * specified original intent. |
95 | * | 97 | * |
96 | * @param intentId original intent identifier | 98 | * @param intentId original intent identifier |
97 | - * @return compiled state transition event | ||
98 | */ | 99 | */ |
99 | void removeInstalledIntents(IntentId intentId); | 100 | void removeInstalledIntents(IntentId intentId); |
100 | 101 | ... | ... |
1 | package org.onlab.onos.store; | 1 | package org.onlab.onos.store; |
2 | 2 | ||
3 | +import java.util.List; | ||
4 | + | ||
3 | import org.onlab.onos.event.Event; | 5 | import org.onlab.onos.event.Event; |
4 | 6 | ||
5 | import static com.google.common.base.Preconditions.checkState; | 7 | import static com.google.common.base.Preconditions.checkState; |
... | @@ -41,4 +43,15 @@ public class AbstractStore<E extends Event, D extends StoreDelegate<E>> | ... | @@ -41,4 +43,15 @@ public class AbstractStore<E extends Event, D extends StoreDelegate<E>> |
41 | delegate.notify(event); | 43 | delegate.notify(event); |
42 | } | 44 | } |
43 | } | 45 | } |
46 | + | ||
47 | + /** | ||
48 | + * Notifies the delegate with the specified list of events. | ||
49 | + * | ||
50 | + * @param events list of events to delegate | ||
51 | + */ | ||
52 | + protected void notifyDelegate(List<E> events) { | ||
53 | + for (E event: events) { | ||
54 | + notifyDelegate(event); | ||
55 | + } | ||
56 | + } | ||
44 | } | 57 | } | ... | ... |
1 | package org.onlab.onos.store; | 1 | package org.onlab.onos.store; |
2 | 2 | ||
3 | -import org.onlab.onos.cluster.MastershipTerm; | ||
4 | import org.onlab.onos.net.DeviceId; | 3 | 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, MastershipTerm term); | 19 | + public void setMastershipTerm(DeviceId deviceId, DeviceMastershipTerm term); |
20 | } | 20 | } | ... | ... |
1 | -package org.onlab.onos.store.common.impl; | 1 | +package org.onlab.onos.store; |
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 | - | ||
9 | import com.google.common.base.MoreObjects; | 7 | import com.google.common.base.MoreObjects; |
10 | 8 | ||
11 | /** | 9 | /** | ... | ... |
1 | -package org.onlab.onos.store.device.impl; | 1 | +package org.onlab.onos.store; |
2 | 2 | ||
3 | import java.util.Objects; | 3 | import java.util.Objects; |
4 | 4 | ||
5 | -import org.onlab.onos.store.Timestamp; | ||
6 | - | ||
7 | /** | 5 | /** |
8 | * Wrapper class for a entity that is versioned | 6 | * Wrapper class for a entity that is versioned |
9 | * and can either be up or down. | 7 | * and can either be up or down. | ... | ... |
... | @@ -2,13 +2,16 @@ package org.onlab.onos.cluster; | ... | @@ -2,13 +2,16 @@ 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; | ||
5 | 8 | ||
6 | import java.util.Set; | 9 | import java.util.Set; |
7 | 10 | ||
8 | /** | 11 | /** |
9 | * Test adapter for mastership service. | 12 | * Test adapter for mastership service. |
10 | */ | 13 | */ |
11 | -public class MastershipServiceAdapter implements MastershipService { | 14 | +public class MastershipServiceAdapter implements DeviceMastershipService { |
12 | @Override | 15 | @Override |
13 | public MastershipRole getLocalRole(DeviceId deviceId) { | 16 | public MastershipRole getLocalRole(DeviceId deviceId) { |
14 | return null; | 17 | return null; |
... | @@ -34,15 +37,15 @@ public class MastershipServiceAdapter implements MastershipService { | ... | @@ -34,15 +37,15 @@ public class MastershipServiceAdapter implements MastershipService { |
34 | } | 37 | } |
35 | 38 | ||
36 | @Override | 39 | @Override |
37 | - public void addListener(MastershipListener listener) { | 40 | + public void addListener(DeviceMastershipListener listener) { |
38 | } | 41 | } |
39 | 42 | ||
40 | @Override | 43 | @Override |
41 | - public void removeListener(MastershipListener listener) { | 44 | + public void removeListener(DeviceMastershipListener listener) { |
42 | } | 45 | } |
43 | 46 | ||
44 | @Override | 47 | @Override |
45 | - public MastershipTermService requestTermService() { | 48 | + public DeviceMastershipTermService requestTermService() { |
46 | return null; | 49 | return null; |
47 | } | 50 | } |
48 | } | 51 | } | ... | ... |
... | @@ -3,6 +3,7 @@ package org.onlab.onos.cluster; | ... | @@ -3,6 +3,7 @@ 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; | ||
6 | 7 | ||
7 | import com.google.common.testing.EqualsTester; | 8 | import com.google.common.testing.EqualsTester; |
8 | 9 | ||
... | @@ -11,10 +12,10 @@ public class MastershipTermTest { | ... | @@ -11,10 +12,10 @@ public class MastershipTermTest { |
11 | private static final NodeId N1 = new NodeId("foo"); | 12 | private static final NodeId N1 = new NodeId("foo"); |
12 | private static final NodeId N2 = new NodeId("bar"); | 13 | private static final NodeId N2 = new NodeId("bar"); |
13 | 14 | ||
14 | - private static final MastershipTerm TERM1 = MastershipTerm.of(N1, 0); | 15 | + private static final DeviceMastershipTerm TERM1 = DeviceMastershipTerm.of(N1, 0); |
15 | - private static final MastershipTerm TERM2 = MastershipTerm.of(N2, 1); | 16 | + private static final DeviceMastershipTerm TERM2 = DeviceMastershipTerm.of(N2, 1); |
16 | - private static final MastershipTerm TERM3 = MastershipTerm.of(N2, 1); | 17 | + private static final DeviceMastershipTerm TERM3 = DeviceMastershipTerm.of(N2, 1); |
17 | - private static final MastershipTerm TERM4 = MastershipTerm.of(N1, 1); | 18 | + private static final DeviceMastershipTerm TERM4 = DeviceMastershipTerm.of(N1, 1); |
18 | 19 | ||
19 | @Test | 20 | @Test |
20 | public void basics() { | 21 | public void basics() { |
... | @@ -24,7 +25,7 @@ public class MastershipTermTest { | ... | @@ -24,7 +25,7 @@ public class MastershipTermTest { |
24 | 25 | ||
25 | @Test | 26 | @Test |
26 | public void testEquality() { | 27 | public void testEquality() { |
27 | - new EqualsTester().addEqualityGroup(MastershipTerm.of(N1, 0), TERM1) | 28 | + new EqualsTester().addEqualityGroup(DeviceMastershipTerm.of(N1, 0), TERM1) |
28 | .addEqualityGroup(TERM2, TERM3) | 29 | .addEqualityGroup(TERM2, TERM3) |
29 | .addEqualityGroup(TERM4); | 30 | .addEqualityGroup(TERM4); |
30 | } | 31 | } | ... | ... |
... | @@ -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; | ||
25 | import org.onlab.onos.cluster.NodeId; | 17 | import org.onlab.onos.cluster.NodeId; |
26 | import org.onlab.onos.event.AbstractListenerRegistry; | 18 | import org.onlab.onos.event.AbstractListenerRegistry; |
27 | import org.onlab.onos.event.EventDeliveryService; | 19 | import org.onlab.onos.event.EventDeliveryService; |
28 | import org.onlab.onos.net.DeviceId; | 20 | import org.onlab.onos.net.DeviceId; |
29 | import org.onlab.onos.net.MastershipRole; | 21 | 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 MastershipService, MastershipAdminService { | 35 | +implements DeviceMastershipService, DeviceMastershipAdminService { |
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 MastershipService, MastershipAdminService { | ... | @@ -40,13 +40,13 @@ implements MastershipService, MastershipAdminService { |
40 | 40 | ||
41 | private final Logger log = getLogger(getClass()); | 41 | private final Logger log = getLogger(getClass()); |
42 | 42 | ||
43 | - protected final AbstractListenerRegistry<MastershipEvent, MastershipListener> | 43 | + protected final AbstractListenerRegistry<DeviceMastershipEvent, DeviceMastershipListener> |
44 | listenerRegistry = new AbstractListenerRegistry<>(); | 44 | listenerRegistry = new AbstractListenerRegistry<>(); |
45 | 45 | ||
46 | - private final MastershipStoreDelegate delegate = new InternalDelegate(); | 46 | + private final DeviceMastershipStoreDelegate delegate = new InternalDelegate(); |
47 | 47 | ||
48 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 48 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
49 | - protected MastershipStore store; | 49 | + protected DeviceMastershipStore 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 MastershipService, MastershipAdminService { | ... | @@ -58,7 +58,7 @@ implements MastershipService, MastershipAdminService { |
58 | 58 | ||
59 | @Activate | 59 | @Activate |
60 | public void activate() { | 60 | public void activate() { |
61 | - eventDispatcher.addSink(MastershipEvent.class, listenerRegistry); | 61 | + eventDispatcher.addSink(DeviceMastershipEvent.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 MastershipService, MastershipAdminService { | ... | @@ -66,7 +66,7 @@ implements MastershipService, MastershipAdminService { |
66 | 66 | ||
67 | @Deactivate | 67 | @Deactivate |
68 | public void deactivate() { | 68 | public void deactivate() { |
69 | - eventDispatcher.removeSink(MastershipEvent.class); | 69 | + eventDispatcher.removeSink(DeviceMastershipEvent.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 MastershipService, MastershipAdminService { | ... | @@ -78,7 +78,7 @@ implements MastershipService, MastershipAdminService { |
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 | - MastershipEvent event = null; | 81 | + DeviceMastershipEvent 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 MastershipService, MastershipAdminService { | ... | @@ -98,7 +98,7 @@ implements MastershipService, MastershipAdminService { |
98 | 98 | ||
99 | @Override | 99 | @Override |
100 | public void relinquishMastership(DeviceId deviceId) { | 100 | public void relinquishMastership(DeviceId deviceId) { |
101 | - MastershipEvent event = null; | 101 | + DeviceMastershipEvent 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 MastershipService, MastershipAdminService { | ... | @@ -127,18 +127,18 @@ implements MastershipService, MastershipAdminService { |
127 | 127 | ||
128 | 128 | ||
129 | @Override | 129 | @Override |
130 | - public MastershipTermService requestTermService() { | 130 | + public DeviceMastershipTermService requestTermService() { |
131 | return new InternalMastershipTermService(); | 131 | return new InternalMastershipTermService(); |
132 | } | 132 | } |
133 | 133 | ||
134 | @Override | 134 | @Override |
135 | - public void addListener(MastershipListener listener) { | 135 | + public void addListener(DeviceMastershipListener 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(MastershipListener listener) { | 141 | + public void removeListener(DeviceMastershipListener listener) { |
142 | checkNotNull(listener); | 142 | checkNotNull(listener); |
143 | listenerRegistry.removeListener(listener); | 143 | listenerRegistry.removeListener(listener); |
144 | } | 144 | } |
... | @@ -146,16 +146,16 @@ implements MastershipService, MastershipAdminService { | ... | @@ -146,16 +146,16 @@ implements MastershipService, MastershipAdminService { |
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(MastershipEvent event) { | 149 | + private void post(DeviceMastershipEvent 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 MastershipTermService { | 155 | + private class InternalMastershipTermService implements DeviceMastershipTermService { |
156 | 156 | ||
157 | @Override | 157 | @Override |
158 | - public MastershipTerm getMastershipTerm(DeviceId deviceId) { | 158 | + public DeviceMastershipTerm getMastershipTerm(DeviceId deviceId) { |
159 | return store.getTermFor(deviceId); | 159 | return store.getTermFor(deviceId); |
160 | } | 160 | } |
161 | 161 | ||
... | @@ -181,10 +181,10 @@ implements MastershipService, MastershipAdminService { | ... | @@ -181,10 +181,10 @@ implements MastershipService, MastershipAdminService { |
181 | 181 | ||
182 | } | 182 | } |
183 | 183 | ||
184 | - public class InternalDelegate implements MastershipStoreDelegate { | 184 | + public class InternalDelegate implements DeviceMastershipStoreDelegate { |
185 | 185 | ||
186 | @Override | 186 | @Override |
187 | - public void notify(MastershipEvent event) { | 187 | + public void notify(DeviceMastershipEvent 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,11 +13,6 @@ import org.apache.felix.scr.annotations.Reference; | ... | @@ -13,11 +13,6 @@ 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; | ||
21 | import org.onlab.onos.cluster.NodeId; | 16 | import org.onlab.onos.cluster.NodeId; |
22 | import org.onlab.onos.event.AbstractListenerRegistry; | 17 | import org.onlab.onos.event.AbstractListenerRegistry; |
23 | import org.onlab.onos.event.EventDeliveryService; | 18 | import org.onlab.onos.event.EventDeliveryService; |
... | @@ -36,6 +31,11 @@ import org.onlab.onos.net.device.DeviceProviderService; | ... | @@ -36,6 +31,11 @@ import org.onlab.onos.net.device.DeviceProviderService; |
36 | import org.onlab.onos.net.device.DeviceService; | 31 | import org.onlab.onos.net.device.DeviceService; |
37 | import org.onlab.onos.net.device.DeviceStore; | 32 | import org.onlab.onos.net.device.DeviceStore; |
38 | import org.onlab.onos.net.device.DeviceStoreDelegate; | 33 | 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 MastershipListener mastershipListener = new InternalMastershipListener(); | 67 | + private final DeviceMastershipListener 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 MastershipService mastershipService; | 79 | + protected DeviceMastershipService mastershipService; |
80 | 80 | ||
81 | - protected MastershipTermService termService; | 81 | + protected DeviceMastershipTermService 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 | - MastershipTerm term = mastershipService.requestTermService() | 212 | + DeviceMastershipTerm 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 MastershipListener { | 323 | + private class InternalMastershipListener implements DeviceMastershipListener { |
324 | 324 | ||
325 | @Override | 325 | @Override |
326 | - public void event(MastershipEvent event) { | 326 | + public void event(DeviceMastershipEvent 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 | - MastershipTerm term = termService.getMastershipTerm(did); | 332 | + DeviceMastershipTerm 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 | ... | ... |
... | @@ -55,6 +55,7 @@ public class ProxyArpManager implements ProxyArpService { | ... | @@ -55,6 +55,7 @@ public class ProxyArpManager implements ProxyArpService { |
55 | private static final String REQUEST_NULL = "Arp request cannot be null."; | 55 | private static final String REQUEST_NULL = "Arp request cannot be null."; |
56 | private static final String REQUEST_NOT_ARP = "Ethernet frame does not contain ARP request."; | 56 | private static final String REQUEST_NOT_ARP = "Ethernet frame does not contain ARP request."; |
57 | private static final String NOT_ARP_REQUEST = "ARP is not a request."; | 57 | private static final String NOT_ARP_REQUEST = "ARP is not a request."; |
58 | + private static final String NOT_ARP_REPLY = "ARP is not a reply."; | ||
58 | 59 | ||
59 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 60 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
60 | protected HostService hostService; | 61 | protected HostService hostService; |
... | @@ -141,7 +142,7 @@ public class ProxyArpManager implements ProxyArpService { | ... | @@ -141,7 +142,7 @@ public class ProxyArpManager implements ProxyArpService { |
141 | checkArgument(eth.getEtherType() == Ethernet.TYPE_ARP, | 142 | checkArgument(eth.getEtherType() == Ethernet.TYPE_ARP, |
142 | REQUEST_NOT_ARP); | 143 | REQUEST_NOT_ARP); |
143 | ARP arp = (ARP) eth.getPayload(); | 144 | ARP arp = (ARP) eth.getPayload(); |
144 | - checkArgument(arp.getOpCode() == ARP.OP_REPLY, NOT_ARP_REQUEST); | 145 | + checkArgument(arp.getOpCode() == ARP.OP_REPLY, NOT_ARP_REPLY); |
145 | 146 | ||
146 | Host h = hostService.getHost(HostId.hostId(eth.getDestinationMAC(), | 147 | Host h = hostService.getHost(HostId.hostId(eth.getDestinationMAC(), |
147 | VlanId.vlanId(eth.getVlanID()))); | 148 | VlanId.vlanId(eth.getVlanID()))); | ... | ... |
... | @@ -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; | ||
15 | import org.onlab.onos.cluster.NodeId; | 13 | import org.onlab.onos.cluster.NodeId; |
16 | import org.onlab.onos.event.impl.TestEventDispatcher; | 14 | import org.onlab.onos.event.impl.TestEventDispatcher; |
17 | import org.onlab.onos.net.DeviceId; | 15 | 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 MastershipService service; | 37 | + protected DeviceMastershipService 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 | - MastershipTermService ts = mgr.requestTermService(); | 123 | + DeviceMastershipTermService 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,8 +11,6 @@ import org.onlab.onos.cluster.ClusterService; | ... | @@ -11,8 +11,6 @@ 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; | ||
16 | import org.onlab.onos.cluster.NodeId; | 14 | import org.onlab.onos.cluster.NodeId; |
17 | import org.onlab.onos.cluster.ControllerNode.State; | 15 | import org.onlab.onos.cluster.ControllerNode.State; |
18 | import org.onlab.onos.event.Event; | 16 | import org.onlab.onos.event.Event; |
... | @@ -32,6 +30,8 @@ import org.onlab.onos.net.device.DeviceProvider; | ... | @@ -32,6 +30,8 @@ import org.onlab.onos.net.device.DeviceProvider; |
32 | import org.onlab.onos.net.device.DeviceProviderRegistry; | 30 | import org.onlab.onos.net.device.DeviceProviderRegistry; |
33 | import org.onlab.onos.net.device.DeviceProviderService; | 31 | import org.onlab.onos.net.device.DeviceProviderService; |
34 | import org.onlab.onos.net.device.DeviceService; | 32 | 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 MastershipTermService requestTermService() { | 293 | + public DeviceMastershipTermService requestTermService() { |
294 | - return new MastershipTermService() { | 294 | + return new DeviceMastershipTermService() { |
295 | @Override | 295 | @Override |
296 | - public MastershipTerm getMastershipTerm(DeviceId deviceId) { | 296 | + public DeviceMastershipTerm getMastershipTerm(DeviceId deviceId) { |
297 | // FIXME: just returning something not null | 297 | // FIXME: just returning something not null |
298 | - return MastershipTerm.of(NID_LOCAL, 1); | 298 | + return DeviceMastershipTerm.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, MastershipTerm term) { | 342 | + public void setMastershipTerm(DeviceId deviceId, DeviceMastershipTerm term) { |
343 | // TODO Auto-generated method stub | 343 | // TODO Auto-generated method stub |
344 | } | 344 | } |
345 | } | 345 | } | ... | ... |
1 | +package org.onlab.onos.net.proxyarp.impl; | ||
2 | + | ||
3 | +import static org.easymock.EasyMock.anyObject; | ||
4 | +import static org.easymock.EasyMock.createMock; | ||
5 | +import static org.easymock.EasyMock.expect; | ||
6 | +import static org.easymock.EasyMock.replay; | ||
7 | +import static org.junit.Assert.assertEquals; | ||
8 | +import static org.junit.Assert.assertFalse; | ||
9 | +import static org.junit.Assert.assertTrue; | ||
10 | + | ||
11 | +import java.util.ArrayList; | ||
12 | +import java.util.Arrays; | ||
13 | +import java.util.Collections; | ||
14 | +import java.util.Comparator; | ||
15 | +import java.util.List; | ||
16 | + | ||
17 | +import org.junit.Before; | ||
18 | +import org.junit.Test; | ||
19 | +import org.onlab.onos.net.ConnectPoint; | ||
20 | +import org.onlab.onos.net.DefaultHost; | ||
21 | +import org.onlab.onos.net.Device; | ||
22 | +import org.onlab.onos.net.DeviceId; | ||
23 | +import org.onlab.onos.net.Host; | ||
24 | +import org.onlab.onos.net.HostId; | ||
25 | +import org.onlab.onos.net.HostLocation; | ||
26 | +import org.onlab.onos.net.Link; | ||
27 | +import org.onlab.onos.net.Port; | ||
28 | +import org.onlab.onos.net.PortNumber; | ||
29 | +import org.onlab.onos.net.device.DeviceListener; | ||
30 | +import org.onlab.onos.net.device.DeviceService; | ||
31 | +import org.onlab.onos.net.flow.instructions.Instruction; | ||
32 | +import org.onlab.onos.net.flow.instructions.Instructions.OutputInstruction; | ||
33 | +import org.onlab.onos.net.host.HostService; | ||
34 | +import org.onlab.onos.net.link.LinkListener; | ||
35 | +import org.onlab.onos.net.link.LinkService; | ||
36 | +import org.onlab.onos.net.packet.OutboundPacket; | ||
37 | +import org.onlab.onos.net.packet.PacketProcessor; | ||
38 | +import org.onlab.onos.net.packet.PacketService; | ||
39 | +import org.onlab.onos.net.provider.ProviderId; | ||
40 | +import org.onlab.packet.ARP; | ||
41 | +import org.onlab.packet.Ethernet; | ||
42 | +import org.onlab.packet.IpPrefix; | ||
43 | +import org.onlab.packet.MacAddress; | ||
44 | +import org.onlab.packet.VlanId; | ||
45 | + | ||
46 | +import com.google.common.collect.Sets; | ||
47 | + | ||
48 | +/** | ||
49 | + * Tests for the {@link ProxyArpManager} class. | ||
50 | + */ | ||
51 | +public class ProxyArpManagerTest { | ||
52 | + | ||
53 | + private static final int NUM_DEVICES = 4; | ||
54 | + private static final int NUM_PORTS_PER_DEVICE = 3; | ||
55 | + private static final int NUM_FLOOD_PORTS = 4; | ||
56 | + | ||
57 | + private static final IpPrefix IP1 = IpPrefix.valueOf("10.0.0.1/24"); | ||
58 | + private static final IpPrefix IP2 = IpPrefix.valueOf("10.0.0.2/24"); | ||
59 | + | ||
60 | + private static final ProviderId PID = new ProviderId("of", "foo"); | ||
61 | + | ||
62 | + private static final VlanId VLAN1 = VlanId.vlanId((short) 1); | ||
63 | + private static final VlanId VLAN2 = VlanId.vlanId((short) 2); | ||
64 | + private static final MacAddress MAC1 = MacAddress.valueOf("00:00:11:00:00:01"); | ||
65 | + private static final MacAddress MAC2 = MacAddress.valueOf("00:00:22:00:00:02"); | ||
66 | + private static final HostId HID1 = HostId.hostId(MAC1, VLAN1); | ||
67 | + private static final HostId HID2 = HostId.hostId(MAC2, VLAN1); | ||
68 | + | ||
69 | + private static final DeviceId DID1 = getDeviceId(1); | ||
70 | + private static final DeviceId DID2 = getDeviceId(2); | ||
71 | + private static final PortNumber P1 = PortNumber.portNumber(1); | ||
72 | + private static final HostLocation LOC1 = new HostLocation(DID1, P1, 123L); | ||
73 | + private static final HostLocation LOC2 = new HostLocation(DID2, P1, 123L); | ||
74 | + | ||
75 | + private ProxyArpManager proxyArp; | ||
76 | + | ||
77 | + private TestPacketService packetService; | ||
78 | + | ||
79 | + private DeviceService deviceService; | ||
80 | + private LinkService linkService; | ||
81 | + private HostService hostService; | ||
82 | + | ||
83 | + @Before | ||
84 | + public void setUp() throws Exception { | ||
85 | + proxyArp = new ProxyArpManager(); | ||
86 | + packetService = new TestPacketService(); | ||
87 | + proxyArp.packetService = packetService; | ||
88 | + | ||
89 | + // Create a host service mock here. Must be replayed by tests once the | ||
90 | + // expectations have been set up | ||
91 | + hostService = createMock(HostService.class); | ||
92 | + proxyArp.hostService = hostService; | ||
93 | + | ||
94 | + createTopology(); | ||
95 | + proxyArp.deviceService = deviceService; | ||
96 | + proxyArp.linkService = linkService; | ||
97 | + | ||
98 | + proxyArp.activate(); | ||
99 | + } | ||
100 | + | ||
101 | + /** | ||
102 | + * Creates a fake topology to feed into the ARP module. | ||
103 | + * <p/> | ||
104 | + * The default topology is a unidirectional ring topology. Each switch has | ||
105 | + * 3 ports. Ports 2 and 3 have the links to neighbor switches, and port 1 | ||
106 | + * is free (edge port). | ||
107 | + */ | ||
108 | + private void createTopology() { | ||
109 | + deviceService = createMock(DeviceService.class); | ||
110 | + linkService = createMock(LinkService.class); | ||
111 | + | ||
112 | + deviceService.addListener(anyObject(DeviceListener.class)); | ||
113 | + linkService.addListener(anyObject(LinkListener.class)); | ||
114 | + | ||
115 | + createDevices(NUM_DEVICES, NUM_PORTS_PER_DEVICE); | ||
116 | + createLinks(NUM_DEVICES); | ||
117 | + } | ||
118 | + | ||
119 | + /** | ||
120 | + * Creates the devices for the fake topology. | ||
121 | + */ | ||
122 | + private void createDevices(int numDevices, int numPorts) { | ||
123 | + List<Device> devices = new ArrayList<>(); | ||
124 | + | ||
125 | + for (int i = 1; i <= numDevices; i++) { | ||
126 | + DeviceId devId = getDeviceId(i); | ||
127 | + Device device = createMock(Device.class); | ||
128 | + expect(device.id()).andReturn(devId).anyTimes(); | ||
129 | + replay(device); | ||
130 | + | ||
131 | + devices.add(device); | ||
132 | + | ||
133 | + List<Port> ports = new ArrayList<>(); | ||
134 | + for (int j = 1; j <= numPorts; j++) { | ||
135 | + Port port = createMock(Port.class); | ||
136 | + expect(port.number()).andReturn(PortNumber.portNumber(j)).anyTimes(); | ||
137 | + replay(port); | ||
138 | + ports.add(port); | ||
139 | + } | ||
140 | + | ||
141 | + expect(deviceService.getPorts(devId)).andReturn(ports); | ||
142 | + } | ||
143 | + | ||
144 | + expect(deviceService.getDevices()).andReturn(devices); | ||
145 | + replay(deviceService); | ||
146 | + } | ||
147 | + | ||
148 | + /** | ||
149 | + * Creates the links for the fake topology. | ||
150 | + * NB: Only unidirectional links are created, as for this purpose all we | ||
151 | + * need is to occupy the ports with some link. | ||
152 | + */ | ||
153 | + private void createLinks(int numDevices) { | ||
154 | + List<Link> links = new ArrayList<Link>(); | ||
155 | + | ||
156 | + for (int i = 1; i <= numDevices; i++) { | ||
157 | + ConnectPoint src = new ConnectPoint( | ||
158 | + getDeviceId(i), | ||
159 | + PortNumber.portNumber(2)); | ||
160 | + ConnectPoint dst = new ConnectPoint( | ||
161 | + getDeviceId((i + 1 > numDevices) ? 1 : i + 1), | ||
162 | + PortNumber.portNumber(3)); | ||
163 | + | ||
164 | + Link link = createMock(Link.class); | ||
165 | + expect(link.src()).andReturn(src).anyTimes(); | ||
166 | + expect(link.dst()).andReturn(dst).anyTimes(); | ||
167 | + replay(link); | ||
168 | + | ||
169 | + links.add(link); | ||
170 | + } | ||
171 | + | ||
172 | + expect(linkService.getLinks()).andReturn(links).anyTimes(); | ||
173 | + replay(linkService); | ||
174 | + } | ||
175 | + | ||
176 | + /** | ||
177 | + * Tests {@link ProxyArpManager#known(IpPrefix)} in the case where the | ||
178 | + * IP address is not known. | ||
179 | + * Verifies the method returns false. | ||
180 | + */ | ||
181 | + @Test | ||
182 | + public void testNotKnown() { | ||
183 | + expect(hostService.getHostsByIp(IP1)).andReturn(Collections.<Host>emptySet()); | ||
184 | + replay(hostService); | ||
185 | + | ||
186 | + assertFalse(proxyArp.known(IP1)); | ||
187 | + } | ||
188 | + | ||
189 | + /** | ||
190 | + * Tests {@link ProxyArpManager#known(IpPrefix)} in the case where the | ||
191 | + * IP address is known. | ||
192 | + * Verifies the method returns true. | ||
193 | + */ | ||
194 | + @Test | ||
195 | + public void testKnown() { | ||
196 | + Host host1 = createMock(Host.class); | ||
197 | + Host host2 = createMock(Host.class); | ||
198 | + | ||
199 | + expect(hostService.getHostsByIp(IP1)) | ||
200 | + .andReturn(Sets.newHashSet(host1, host2)); | ||
201 | + replay(hostService); | ||
202 | + | ||
203 | + assertTrue(proxyArp.known(IP1)); | ||
204 | + } | ||
205 | + | ||
206 | + /** | ||
207 | + * Tests {@link ProxyArpManager#reply(Ethernet)} in the case where the | ||
208 | + * destination host is known. | ||
209 | + * Verifies the correct ARP reply is sent out the correct port. | ||
210 | + */ | ||
211 | + @Test | ||
212 | + public void testReplyKnown() { | ||
213 | + Host replyer = new DefaultHost(PID, HID1, MAC1, VLAN1, LOC2, | ||
214 | + Collections.singleton(IP1)); | ||
215 | + | ||
216 | + Host requestor = new DefaultHost(PID, HID2, MAC2, VLAN1, LOC1, | ||
217 | + Collections.singleton(IP2)); | ||
218 | + | ||
219 | + expect(hostService.getHostsByIp(IpPrefix.valueOf(IP1.toOctets()))) | ||
220 | + .andReturn(Collections.singleton(replyer)); | ||
221 | + expect(hostService.getHost(HID2)).andReturn(requestor); | ||
222 | + | ||
223 | + replay(hostService); | ||
224 | + | ||
225 | + Ethernet arpRequest = buildArp(ARP.OP_REQUEST, MAC2, null, IP2, IP1); | ||
226 | + | ||
227 | + proxyArp.reply(arpRequest); | ||
228 | + | ||
229 | + assertEquals(1, packetService.packets.size()); | ||
230 | + Ethernet arpReply = buildArp(ARP.OP_REPLY, MAC1, MAC2, IP1, IP2); | ||
231 | + verifyPacketOut(arpReply, LOC1, packetService.packets.get(0)); | ||
232 | + } | ||
233 | + | ||
234 | + /** | ||
235 | + * Tests {@link ProxyArpManager#reply(Ethernet)} in the case where the | ||
236 | + * destination host is not known. | ||
237 | + * Verifies the ARP request is flooded out the correct edge ports. | ||
238 | + */ | ||
239 | + @Test | ||
240 | + public void testReplyUnknown() { | ||
241 | + Host requestor = new DefaultHost(PID, HID2, MAC2, VLAN1, LOC1, | ||
242 | + Collections.singleton(IP2)); | ||
243 | + | ||
244 | + expect(hostService.getHostsByIp(IpPrefix.valueOf(IP1.toOctets()))) | ||
245 | + .andReturn(Collections.<Host>emptySet()); | ||
246 | + expect(hostService.getHost(HID2)).andReturn(requestor); | ||
247 | + | ||
248 | + replay(hostService); | ||
249 | + | ||
250 | + Ethernet arpRequest = buildArp(ARP.OP_REQUEST, MAC2, null, IP2, IP1); | ||
251 | + | ||
252 | + proxyArp.reply(arpRequest); | ||
253 | + | ||
254 | + verifyFlood(arpRequest); | ||
255 | + } | ||
256 | + | ||
257 | + /** | ||
258 | + * Tests {@link ProxyArpManager#reply(Ethernet)} in the case where the | ||
259 | + * destination host is known for that IP address, but is not on the same | ||
260 | + * VLAN as the source host. | ||
261 | + * Verifies the ARP request is flooded out the correct edge ports. | ||
262 | + */ | ||
263 | + @Test | ||
264 | + public void testReplyDifferentVlan() { | ||
265 | + Host replyer = new DefaultHost(PID, HID1, MAC1, VLAN2, LOC2, | ||
266 | + Collections.singleton(IP1)); | ||
267 | + | ||
268 | + Host requestor = new DefaultHost(PID, HID2, MAC2, VLAN1, LOC1, | ||
269 | + Collections.singleton(IP2)); | ||
270 | + | ||
271 | + expect(hostService.getHostsByIp(IpPrefix.valueOf(IP1.toOctets()))) | ||
272 | + .andReturn(Collections.singleton(replyer)); | ||
273 | + expect(hostService.getHost(HID2)).andReturn(requestor); | ||
274 | + | ||
275 | + replay(hostService); | ||
276 | + | ||
277 | + Ethernet arpRequest = buildArp(ARP.OP_REQUEST, MAC2, null, IP2, IP1); | ||
278 | + | ||
279 | + proxyArp.reply(arpRequest); | ||
280 | + | ||
281 | + verifyFlood(arpRequest); | ||
282 | + } | ||
283 | + | ||
284 | + /** | ||
285 | + * Tests {@link ProxyArpManager#forward(Ethernet)} in the case where the | ||
286 | + * destination host is known. | ||
287 | + * Verifies the correct ARP request is sent out the correct port. | ||
288 | + */ | ||
289 | + @Test | ||
290 | + public void testForwardToHost() { | ||
291 | + Host host1 = new DefaultHost(PID, HID1, MAC1, VLAN1, LOC1, | ||
292 | + Collections.singleton(IP1)); | ||
293 | + | ||
294 | + expect(hostService.getHost(HID1)).andReturn(host1); | ||
295 | + replay(hostService); | ||
296 | + | ||
297 | + Ethernet arpRequest = buildArp(ARP.OP_REPLY, MAC2, MAC1, IP2, IP1); | ||
298 | + | ||
299 | + proxyArp.forward(arpRequest); | ||
300 | + | ||
301 | + assertEquals(1, packetService.packets.size()); | ||
302 | + OutboundPacket packet = packetService.packets.get(0); | ||
303 | + | ||
304 | + verifyPacketOut(arpRequest, LOC1, packet); | ||
305 | + } | ||
306 | + | ||
307 | + /** | ||
308 | + * Tests {@link ProxyArpManager#forward(Ethernet)} in the case where the | ||
309 | + * destination host is not known. | ||
310 | + * Verifies the correct ARP request is flooded out the correct edge ports. | ||
311 | + */ | ||
312 | + @Test | ||
313 | + public void testForwardFlood() { | ||
314 | + expect(hostService.getHost(HID1)).andReturn(null); | ||
315 | + replay(hostService); | ||
316 | + | ||
317 | + Ethernet arpRequest = buildArp(ARP.OP_REPLY, MAC2, MAC1, IP2, IP1); | ||
318 | + | ||
319 | + proxyArp.forward(arpRequest); | ||
320 | + | ||
321 | + verifyFlood(arpRequest); | ||
322 | + } | ||
323 | + | ||
324 | + /** | ||
325 | + * Verifies that the given packet was flooded out all available edge ports. | ||
326 | + * | ||
327 | + * @param packet the packet that was expected to be flooded | ||
328 | + */ | ||
329 | + private void verifyFlood(Ethernet packet) { | ||
330 | + assertEquals(NUM_FLOOD_PORTS, packetService.packets.size()); | ||
331 | + | ||
332 | + Collections.sort(packetService.packets, | ||
333 | + new Comparator<OutboundPacket>() { | ||
334 | + @Override | ||
335 | + public int compare(OutboundPacket o1, OutboundPacket o2) { | ||
336 | + return o1.sendThrough().uri().compareTo(o2.sendThrough().uri()); | ||
337 | + } | ||
338 | + }); | ||
339 | + | ||
340 | + for (int i = 0; i < NUM_FLOOD_PORTS; i++) { | ||
341 | + ConnectPoint cp = new ConnectPoint(getDeviceId(i + 1), PortNumber.portNumber(1)); | ||
342 | + | ||
343 | + OutboundPacket outboundPacket = packetService.packets.get(i); | ||
344 | + verifyPacketOut(packet, cp, outboundPacket); | ||
345 | + } | ||
346 | + } | ||
347 | + | ||
348 | + /** | ||
349 | + * Verifies the given packet was sent out the given port. | ||
350 | + * | ||
351 | + * @param expected the packet that was expected to be sent | ||
352 | + * @param outPort the port the packet was expected to be sent out | ||
353 | + * @param actual the actual OutboundPacket to verify | ||
354 | + */ | ||
355 | + private void verifyPacketOut(Ethernet expected, ConnectPoint outPort, | ||
356 | + OutboundPacket actual) { | ||
357 | + assertTrue(Arrays.equals(expected.serialize(), actual.data().array())); | ||
358 | + assertEquals(1, actual.treatment().instructions().size()); | ||
359 | + assertEquals(outPort.deviceId(), actual.sendThrough()); | ||
360 | + Instruction instruction = actual.treatment().instructions().get(0); | ||
361 | + assertTrue(instruction instanceof OutputInstruction); | ||
362 | + assertEquals(outPort.port(), ((OutputInstruction) instruction).port()); | ||
363 | + } | ||
364 | + | ||
365 | + /** | ||
366 | + * Returns the device ID of the ith device. | ||
367 | + * | ||
368 | + * @param i device to get the ID of | ||
369 | + * @return the device ID | ||
370 | + */ | ||
371 | + private static DeviceId getDeviceId(int i) { | ||
372 | + return DeviceId.deviceId("" + i); | ||
373 | + } | ||
374 | + | ||
375 | + /** | ||
376 | + * Builds an ARP packet with the given parameters. | ||
377 | + * | ||
378 | + * @param opcode opcode of the ARP packet | ||
379 | + * @param srcMac source MAC address | ||
380 | + * @param dstMac destination MAC address, or null if this is a request | ||
381 | + * @param srcIp source IP address | ||
382 | + * @param dstIp destination IP address | ||
383 | + * @return the ARP packet | ||
384 | + */ | ||
385 | + private Ethernet buildArp(short opcode, MacAddress srcMac, MacAddress dstMac, | ||
386 | + IpPrefix srcIp, IpPrefix dstIp) { | ||
387 | + Ethernet eth = new Ethernet(); | ||
388 | + | ||
389 | + if (dstMac == null) { | ||
390 | + eth.setDestinationMACAddress(MacAddress.BROADCAST_MAC); | ||
391 | + } else { | ||
392 | + eth.setDestinationMACAddress(dstMac.getAddress()); | ||
393 | + } | ||
394 | + | ||
395 | + eth.setSourceMACAddress(srcMac.getAddress()); | ||
396 | + eth.setEtherType(Ethernet.TYPE_ARP); | ||
397 | + eth.setVlanID(VLAN1.toShort()); | ||
398 | + | ||
399 | + ARP arp = new ARP(); | ||
400 | + arp.setOpCode(opcode); | ||
401 | + arp.setProtocolType(ARP.PROTO_TYPE_IP); | ||
402 | + arp.setHardwareType(ARP.HW_TYPE_ETHERNET); | ||
403 | + | ||
404 | + arp.setProtocolAddressLength((byte) IpPrefix.INET_LEN); | ||
405 | + arp.setHardwareAddressLength((byte) Ethernet.DATALAYER_ADDRESS_LENGTH); | ||
406 | + arp.setSenderHardwareAddress(srcMac.getAddress()); | ||
407 | + | ||
408 | + if (dstMac == null) { | ||
409 | + arp.setTargetHardwareAddress(MacAddress.ZERO_MAC_ADDRESS); | ||
410 | + } else { | ||
411 | + arp.setTargetHardwareAddress(dstMac.getAddress()); | ||
412 | + } | ||
413 | + | ||
414 | + arp.setSenderProtocolAddress(srcIp.toOctets()); | ||
415 | + arp.setTargetProtocolAddress(dstIp.toOctets()); | ||
416 | + | ||
417 | + eth.setPayload(arp); | ||
418 | + return eth; | ||
419 | + } | ||
420 | + | ||
421 | + /** | ||
422 | + * Test PacketService implementation that simply stores OutboundPackets | ||
423 | + * passed to {@link #emit(OutboundPacket)} for later verification. | ||
424 | + */ | ||
425 | + class TestPacketService implements PacketService { | ||
426 | + | ||
427 | + List<OutboundPacket> packets = new ArrayList<>(); | ||
428 | + | ||
429 | + @Override | ||
430 | + public void addProcessor(PacketProcessor processor, int priority) { | ||
431 | + } | ||
432 | + | ||
433 | + @Override | ||
434 | + public void removeProcessor(PacketProcessor processor) { | ||
435 | + } | ||
436 | + | ||
437 | + @Override | ||
438 | + public void emit(OutboundPacket packet) { | ||
439 | + packets.add(packet); | ||
440 | + } | ||
441 | + } | ||
442 | +} |
... | @@ -6,6 +6,7 @@ import java.io.IOException; | ... | @@ -6,6 +6,7 @@ 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 | + | ||
9 | import org.apache.felix.scr.annotations.Activate; | 10 | import org.apache.felix.scr.annotations.Activate; |
10 | import org.apache.felix.scr.annotations.Component; | 11 | import org.apache.felix.scr.annotations.Component; |
11 | import org.apache.felix.scr.annotations.Deactivate; | 12 | import org.apache.felix.scr.annotations.Deactivate; |
... | @@ -23,10 +24,8 @@ import org.onlab.onos.store.cluster.messaging.ClusterCommunicationService; | ... | @@ -23,10 +24,8 @@ import org.onlab.onos.store.cluster.messaging.ClusterCommunicationService; |
23 | import org.onlab.onos.store.cluster.messaging.ClusterMessage; | 24 | import org.onlab.onos.store.cluster.messaging.ClusterMessage; |
24 | import org.onlab.onos.store.cluster.messaging.ClusterMessageHandler; | 25 | import org.onlab.onos.store.cluster.messaging.ClusterMessageHandler; |
25 | import org.onlab.onos.store.cluster.messaging.MessageSubject; | 26 | 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; | ||
30 | import org.onlab.util.KryoPool; | 29 | import org.onlab.util.KryoPool; |
31 | import org.onlab.netty.Endpoint; | 30 | import org.onlab.netty.Endpoint; |
32 | import org.onlab.netty.Message; | 31 | import org.onlab.netty.Message; | ... | ... |
1 | -package org.onlab.onos.store.serializers; | 1 | +package org.onlab.onos.store.cluster.messaging.impl; |
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; | ... | ... |
... | @@ -4,7 +4,7 @@ import java.util.Map; | ... | @@ -4,7 +4,7 @@ import java.util.Map; |
4 | import java.util.Set; | 4 | import java.util.Set; |
5 | 5 | ||
6 | import org.onlab.onos.cluster.NodeId; | 6 | import org.onlab.onos.cluster.NodeId; |
7 | -import org.onlab.onos.store.device.impl.VersionedValue; | 7 | +import org.onlab.onos.store.VersionedValue; |
8 | 8 | ||
9 | import com.google.common.collect.ImmutableMap; | 9 | import com.google.common.collect.ImmutableMap; |
10 | import com.google.common.collect.ImmutableSet; | 10 | import com.google.common.collect.ImmutableSet; | ... | ... |
... | @@ -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 MastershipBasedTimestamp implements Timestamp { | 16 | +public final class DeviceMastershipBasedTimestamp 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 MastershipBasedTimestamp implements Timestamp { | ... | @@ -24,16 +24,16 @@ public final class MastershipBasedTimestamp 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 MastershipBasedTimestamp(int termNumber, int sequenceNumber) { | 27 | + public DeviceMastershipBasedTimestamp(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 MastershipBasedTimestamp, | 34 | + checkArgument(o instanceof DeviceMastershipBasedTimestamp, |
35 | "Must be MastershipBasedTimestamp", o); | 35 | "Must be MastershipBasedTimestamp", o); |
36 | - MastershipBasedTimestamp that = (MastershipBasedTimestamp) o; | 36 | + DeviceMastershipBasedTimestamp that = (DeviceMastershipBasedTimestamp) 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 MastershipBasedTimestamp implements Timestamp { | ... | @@ -51,10 +51,10 @@ public final class MastershipBasedTimestamp implements Timestamp { |
51 | if (this == obj) { | 51 | if (this == obj) { |
52 | return true; | 52 | return true; |
53 | } | 53 | } |
54 | - if (!(obj instanceof MastershipBasedTimestamp)) { | 54 | + if (!(obj instanceof DeviceMastershipBasedTimestamp)) { |
55 | return false; | 55 | return false; |
56 | } | 56 | } |
57 | - MastershipBasedTimestamp that = (MastershipBasedTimestamp) obj; | 57 | + DeviceMastershipBasedTimestamp that = (DeviceMastershipBasedTimestamp) 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 MastershipBasedTimestamp implements Timestamp { | ... | @@ -87,7 +87,7 @@ public final class MastershipBasedTimestamp implements Timestamp { |
87 | 87 | ||
88 | // Default constructor for serialization | 88 | // Default constructor for serialization |
89 | @Deprecated | 89 | @Deprecated |
90 | - protected MastershipBasedTimestamp() { | 90 | + protected DeviceMastershipBasedTimestamp() { |
91 | this.termNumber = -1; | 91 | this.termNumber = -1; |
92 | this.sequenceNumber = -1; | 92 | this.sequenceNumber = -1; |
93 | } | 93 | } | ... | ... |
1 | -package org.onlab.onos.store.serializers; | 1 | +package org.onlab.onos.store.common.impl; |
2 | - | ||
3 | -import org.onlab.onos.store.common.impl.MastershipBasedTimestamp; | ||
4 | 2 | ||
5 | import com.esotericsoftware.kryo.Kryo; | 3 | import com.esotericsoftware.kryo.Kryo; |
6 | import com.esotericsoftware.kryo.Serializer; | 4 | import com.esotericsoftware.kryo.Serializer; |
... | @@ -9,12 +7,12 @@ import com.esotericsoftware.kryo.io.Output; | ... | @@ -9,12 +7,12 @@ import com.esotericsoftware.kryo.io.Output; |
9 | 7 | ||
10 | // To be used if Timestamp ever needs to cross bundle boundary. | 8 | // To be used if Timestamp ever needs to cross bundle boundary. |
11 | /** | 9 | /** |
12 | - * Kryo Serializer for {@link MastershipBasedTimestamp}. | 10 | + * Kryo Serializer for {@link DeviceMastershipBasedTimestamp}. |
13 | */ | 11 | */ |
14 | -public class MastershipBasedTimestampSerializer extends Serializer<MastershipBasedTimestamp> { | 12 | +public class MastershipBasedTimestampSerializer extends Serializer<DeviceMastershipBasedTimestamp> { |
15 | 13 | ||
16 | /** | 14 | /** |
17 | - * Creates a serializer for {@link MastershipBasedTimestamp}. | 15 | + * Creates a serializer for {@link DeviceMastershipBasedTimestamp}. |
18 | */ | 16 | */ |
19 | public MastershipBasedTimestampSerializer() { | 17 | public MastershipBasedTimestampSerializer() { |
20 | // non-null, immutable | 18 | // non-null, immutable |
... | @@ -22,15 +20,15 @@ public class MastershipBasedTimestampSerializer extends Serializer<MastershipBas | ... | @@ -22,15 +20,15 @@ public class MastershipBasedTimestampSerializer extends Serializer<MastershipBas |
22 | } | 20 | } |
23 | 21 | ||
24 | @Override | 22 | @Override |
25 | - public void write(Kryo kryo, Output output, MastershipBasedTimestamp object) { | 23 | + public void write(Kryo kryo, Output output, DeviceMastershipBasedTimestamp object) { |
26 | output.writeInt(object.termNumber()); | 24 | output.writeInt(object.termNumber()); |
27 | output.writeInt(object.sequenceNumber()); | 25 | output.writeInt(object.sequenceNumber()); |
28 | } | 26 | } |
29 | 27 | ||
30 | @Override | 28 | @Override |
31 | - public MastershipBasedTimestamp read(Kryo kryo, Input input, Class<MastershipBasedTimestamp> type) { | 29 | + public DeviceMastershipBasedTimestamp read(Kryo kryo, Input input, Class<DeviceMastershipBasedTimestamp> type) { |
32 | final int term = input.readInt(); | 30 | final int term = input.readInt(); |
33 | final int sequence = input.readInt(); | 31 | final int sequence = input.readInt(); |
34 | - return new MastershipBasedTimestamp(term, sequence); | 32 | + return new DeviceMastershipBasedTimestamp(term, sequence); |
35 | } | 33 | } |
36 | } | 34 | } | ... | ... |
... | @@ -8,6 +8,7 @@ import org.onlab.onos.cluster.NodeId; | ... | @@ -8,6 +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.VersionedValue; | ||
11 | import org.onlab.onos.store.common.impl.AntiEntropyAdvertisement; | 12 | import org.onlab.onos.store.common.impl.AntiEntropyAdvertisement; |
12 | 13 | ||
13 | // TODO DeviceID needs to be changed to something like (ProviderID, DeviceID) | 14 | // TODO DeviceID needs to be changed to something like (ProviderID, DeviceID) | ... | ... |
... | @@ -10,6 +10,7 @@ import org.onlab.onos.cluster.NodeId; | ... | @@ -10,6 +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.VersionedValue; | ||
13 | import org.onlab.onos.store.common.impl.AntiEntropyReply; | 14 | import org.onlab.onos.store.common.impl.AntiEntropyReply; |
14 | 15 | ||
15 | import com.google.common.collect.ImmutableMap; | 16 | import com.google.common.collect.ImmutableMap; | ... | ... |
... | @@ -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; | ||
14 | import org.onlab.onos.net.DeviceId; | 13 | 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.MastershipBasedTimestamp; | 18 | +import org.onlab.onos.store.common.impl.DeviceMastershipBasedTimestamp; |
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, MastershipTerm> deviceMastershipTerms = new ConcurrentHashMap<>(); | 32 | + private ConcurrentMap<DeviceId, DeviceMastershipTerm> 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 | - MastershipTerm term = deviceMastershipTerms.get(deviceId); | 46 | + DeviceMastershipTerm 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 MastershipBasedTimestamp(term.termNumber(), ticker.incrementAndGet()); | 50 | + return new DeviceMastershipBasedTimestamp(term.termNumber(), ticker.incrementAndGet()); |
51 | } | 51 | } |
52 | 52 | ||
53 | @Override | 53 | @Override |
54 | - public void setMastershipTerm(DeviceId deviceId, MastershipTerm term) { | 54 | + public void setMastershipTerm(DeviceId deviceId, DeviceMastershipTerm term) { |
55 | deviceMastershipTerms.put(deviceId, term); | 55 | deviceMastershipTerms.put(deviceId, term); |
56 | } | 56 | } |
57 | } | 57 | } | ... | ... |
... | @@ -35,14 +35,14 @@ import org.onlab.onos.net.provider.ProviderId; | ... | @@ -35,14 +35,14 @@ import org.onlab.onos.net.provider.ProviderId; |
35 | import org.onlab.onos.store.AbstractStore; | 35 | import org.onlab.onos.store.AbstractStore; |
36 | import org.onlab.onos.store.ClockService; | 36 | import org.onlab.onos.store.ClockService; |
37 | import org.onlab.onos.store.Timestamp; | 37 | import org.onlab.onos.store.Timestamp; |
38 | +import org.onlab.onos.store.Timestamped; | ||
38 | import org.onlab.onos.store.cluster.messaging.ClusterCommunicationService; | 39 | import org.onlab.onos.store.cluster.messaging.ClusterCommunicationService; |
39 | import org.onlab.onos.store.cluster.messaging.ClusterMessage; | 40 | import org.onlab.onos.store.cluster.messaging.ClusterMessage; |
40 | import org.onlab.onos.store.cluster.messaging.ClusterMessageHandler; | 41 | import org.onlab.onos.store.cluster.messaging.ClusterMessageHandler; |
41 | -import org.onlab.onos.store.common.impl.MastershipBasedTimestamp; | 42 | +import org.onlab.onos.store.common.impl.DeviceMastershipBasedTimestamp; |
42 | -import org.onlab.onos.store.common.impl.Timestamped; | 43 | +import org.onlab.onos.store.common.impl.MastershipBasedTimestampSerializer; |
43 | import org.onlab.onos.store.serializers.KryoPoolUtil; | 44 | import org.onlab.onos.store.serializers.KryoPoolUtil; |
44 | import org.onlab.onos.store.serializers.KryoSerializer; | 45 | import org.onlab.onos.store.serializers.KryoSerializer; |
45 | -import org.onlab.onos.store.serializers.MastershipBasedTimestampSerializer; | ||
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; |
... | @@ -125,7 +125,7 @@ public class GossipDeviceStore | ... | @@ -125,7 +125,7 @@ public class GossipDeviceStore |
125 | .register(InternalPortStatusEvent.class, new InternalPortStatusEventSerializer()) | 125 | .register(InternalPortStatusEvent.class, new InternalPortStatusEventSerializer()) |
126 | .register(Timestamp.class) | 126 | .register(Timestamp.class) |
127 | .register(Timestamped.class) | 127 | .register(Timestamped.class) |
128 | - .register(MastershipBasedTimestamp.class, new MastershipBasedTimestampSerializer()) | 128 | + .register(DeviceMastershipBasedTimestamp.class, new MastershipBasedTimestampSerializer()) |
129 | .build() | 129 | .build() |
130 | .populate(1); | 130 | .populate(1); |
131 | } | 131 | } |
... | @@ -870,6 +870,12 @@ public class GossipDeviceStore | ... | @@ -870,6 +870,12 @@ public class GossipDeviceStore |
870 | clusterCommunicator.broadcast(message); | 870 | clusterCommunicator.broadcast(message); |
871 | } | 871 | } |
872 | 872 | ||
873 | + private void notifyDelegateIfNotNull(DeviceEvent event) { | ||
874 | + if (event != null) { | ||
875 | + notifyDelegate(event); | ||
876 | + } | ||
877 | + } | ||
878 | + | ||
873 | private class InternalDeviceEventListener implements ClusterMessageHandler { | 879 | private class InternalDeviceEventListener implements ClusterMessageHandler { |
874 | @Override | 880 | @Override |
875 | public void handle(ClusterMessage message) { | 881 | public void handle(ClusterMessage message) { |
... | @@ -881,7 +887,7 @@ public class GossipDeviceStore | ... | @@ -881,7 +887,7 @@ public class GossipDeviceStore |
881 | DeviceId deviceId = event.deviceId(); | 887 | DeviceId deviceId = event.deviceId(); |
882 | Timestamped<DeviceDescription> deviceDescription = event.deviceDescription(); | 888 | Timestamped<DeviceDescription> deviceDescription = event.deviceDescription(); |
883 | 889 | ||
884 | - createOrUpdateDeviceInternal(providerId, deviceId, deviceDescription); | 890 | + notifyDelegateIfNotNull(createOrUpdateDeviceInternal(providerId, deviceId, deviceDescription)); |
885 | } | 891 | } |
886 | } | 892 | } |
887 | 893 | ||
... | @@ -895,7 +901,7 @@ public class GossipDeviceStore | ... | @@ -895,7 +901,7 @@ public class GossipDeviceStore |
895 | DeviceId deviceId = event.deviceId(); | 901 | DeviceId deviceId = event.deviceId(); |
896 | Timestamp timestamp = event.timestamp(); | 902 | Timestamp timestamp = event.timestamp(); |
897 | 903 | ||
898 | - markOfflineInternal(deviceId, timestamp); | 904 | + notifyDelegateIfNotNull(markOfflineInternal(deviceId, timestamp)); |
899 | } | 905 | } |
900 | } | 906 | } |
901 | 907 | ||
... | @@ -909,7 +915,7 @@ public class GossipDeviceStore | ... | @@ -909,7 +915,7 @@ public class GossipDeviceStore |
909 | DeviceId deviceId = event.deviceId(); | 915 | DeviceId deviceId = event.deviceId(); |
910 | Timestamp timestamp = event.timestamp(); | 916 | Timestamp timestamp = event.timestamp(); |
911 | 917 | ||
912 | - removeDeviceInternal(deviceId, timestamp); | 918 | + notifyDelegateIfNotNull(removeDeviceInternal(deviceId, timestamp)); |
913 | } | 919 | } |
914 | } | 920 | } |
915 | 921 | ||
... | @@ -924,7 +930,7 @@ public class GossipDeviceStore | ... | @@ -924,7 +930,7 @@ public class GossipDeviceStore |
924 | DeviceId deviceId = event.deviceId(); | 930 | DeviceId deviceId = event.deviceId(); |
925 | Timestamped<List<PortDescription>> portDescriptions = event.portDescriptions(); | 931 | Timestamped<List<PortDescription>> portDescriptions = event.portDescriptions(); |
926 | 932 | ||
927 | - updatePortsInternal(providerId, deviceId, portDescriptions); | 933 | + notifyDelegate(updatePortsInternal(providerId, deviceId, portDescriptions)); |
928 | } | 934 | } |
929 | } | 935 | } |
930 | 936 | ||
... | @@ -939,7 +945,7 @@ public class GossipDeviceStore | ... | @@ -939,7 +945,7 @@ public class GossipDeviceStore |
939 | DeviceId deviceId = event.deviceId(); | 945 | DeviceId deviceId = event.deviceId(); |
940 | Timestamped<PortDescription> portDescription = event.portDescription(); | 946 | Timestamped<PortDescription> portDescription = event.portDescription(); |
941 | 947 | ||
942 | - updatePortStatusInternal(providerId, deviceId, portDescription); | 948 | + notifyDelegateIfNotNull(updatePortStatusInternal(providerId, deviceId, portDescription)); |
943 | } | 949 | } |
944 | } | 950 | } |
945 | } | 951 | } | ... | ... |
... | @@ -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.common.impl.Timestamped; | 6 | +import org.onlab.onos.store.Timestamped; |
7 | 7 | ||
8 | /** | 8 | /** |
9 | * Information published by GossipDeviceStore to notify peers of a device | 9 | * Information published by GossipDeviceStore to notify peers of a device | ... | ... |
... | @@ -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.common.impl.Timestamped; | 6 | +import org.onlab.onos.store.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; | ... | ... |
... | @@ -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.common.impl.Timestamped; | 8 | +import org.onlab.onos.store.Timestamped; |
9 | 9 | ||
10 | /** | 10 | /** |
11 | * Information published by GossipDeviceStore to notify peers of a port | 11 | * Information published by GossipDeviceStore to notify peers of a port | ... | ... |
... | @@ -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.common.impl.Timestamped; | 8 | +import org.onlab.onos.store.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,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.common.impl.Timestamped; | 6 | +import org.onlab.onos.store.Timestamped; |
7 | 7 | ||
8 | /** | 8 | /** |
9 | * Information published by GossipDeviceStore to notify peers of a port | 9 | * Information published by GossipDeviceStore to notify peers of a port | ... | ... |
... | @@ -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.common.impl.Timestamped; | 6 | +import org.onlab.onos.store.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; | ... | ... |
... | @@ -31,7 +31,7 @@ import org.onlab.onos.net.provider.ProviderId; | ... | @@ -31,7 +31,7 @@ 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.device.impl.VersionedValue; | 34 | +import org.onlab.onos.store.VersionedValue; |
35 | import org.slf4j.Logger; | 35 | import org.slf4j.Logger; |
36 | 36 | ||
37 | import com.google.common.collect.HashMultimap; | 37 | import com.google.common.collect.HashMultimap; | ... | ... |
... | @@ -6,26 +6,25 @@ import java.nio.ByteBuffer; | ... | @@ -6,26 +6,25 @@ 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; | ||
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; |
13 | 12 | ||
14 | /** | 13 | /** |
15 | - * Test of {@link MastershipBasedTimestamp}. | 14 | + * Test of {@link DeviceMastershipBasedTimestamp}. |
16 | */ | 15 | */ |
17 | public class MastershipBasedTimestampTest { | 16 | public class MastershipBasedTimestampTest { |
18 | 17 | ||
19 | - private static final Timestamp TS_1_1 = new MastershipBasedTimestamp(1, 1); | 18 | + private static final Timestamp TS_1_1 = new DeviceMastershipBasedTimestamp(1, 1); |
20 | - private static final Timestamp TS_1_2 = new MastershipBasedTimestamp(1, 2); | 19 | + private static final Timestamp TS_1_2 = new DeviceMastershipBasedTimestamp(1, 2); |
21 | - private static final Timestamp TS_2_1 = new MastershipBasedTimestamp(2, 1); | 20 | + private static final Timestamp TS_2_1 = new DeviceMastershipBasedTimestamp(2, 1); |
22 | - private static final Timestamp TS_2_2 = new MastershipBasedTimestamp(2, 2); | 21 | + private static final Timestamp TS_2_2 = new DeviceMastershipBasedTimestamp(2, 2); |
23 | 22 | ||
24 | @Test | 23 | @Test |
25 | public final void testBasic() { | 24 | public final void testBasic() { |
26 | final int termNumber = 5; | 25 | final int termNumber = 5; |
27 | final int sequenceNumber = 6; | 26 | final int sequenceNumber = 6; |
28 | - MastershipBasedTimestamp ts = new MastershipBasedTimestamp(termNumber, | 27 | + DeviceMastershipBasedTimestamp ts = new DeviceMastershipBasedTimestamp(termNumber, |
29 | sequenceNumber); | 28 | sequenceNumber); |
30 | 29 | ||
31 | assertEquals(termNumber, ts.termNumber()); | 30 | assertEquals(termNumber, ts.termNumber()); |
... | @@ -35,7 +34,7 @@ public class MastershipBasedTimestampTest { | ... | @@ -35,7 +34,7 @@ public class MastershipBasedTimestampTest { |
35 | @Test | 34 | @Test |
36 | public final void testCompareTo() { | 35 | public final void testCompareTo() { |
37 | assertTrue(TS_1_1.compareTo(TS_1_1) == 0); | 36 | assertTrue(TS_1_1.compareTo(TS_1_1) == 0); |
38 | - assertTrue(TS_1_1.compareTo(new MastershipBasedTimestamp(1, 1)) == 0); | 37 | + assertTrue(TS_1_1.compareTo(new DeviceMastershipBasedTimestamp(1, 1)) == 0); |
39 | 38 | ||
40 | assertTrue(TS_1_1.compareTo(TS_1_2) < 0); | 39 | assertTrue(TS_1_1.compareTo(TS_1_2) < 0); |
41 | assertTrue(TS_1_2.compareTo(TS_1_1) > 0); | 40 | assertTrue(TS_1_2.compareTo(TS_1_1) > 0); |
... | @@ -49,14 +48,14 @@ public class MastershipBasedTimestampTest { | ... | @@ -49,14 +48,14 @@ public class MastershipBasedTimestampTest { |
49 | @Test | 48 | @Test |
50 | public final void testEqualsObject() { | 49 | public final void testEqualsObject() { |
51 | new EqualsTester() | 50 | new EqualsTester() |
52 | - .addEqualityGroup(new MastershipBasedTimestamp(1, 1), | 51 | + .addEqualityGroup(new DeviceMastershipBasedTimestamp(1, 1), |
53 | - new MastershipBasedTimestamp(1, 1), TS_1_1) | 52 | + new DeviceMastershipBasedTimestamp(1, 1), TS_1_1) |
54 | - .addEqualityGroup(new MastershipBasedTimestamp(1, 2), | 53 | + .addEqualityGroup(new DeviceMastershipBasedTimestamp(1, 2), |
55 | - new MastershipBasedTimestamp(1, 2), TS_1_2) | 54 | + new DeviceMastershipBasedTimestamp(1, 2), TS_1_2) |
56 | - .addEqualityGroup(new MastershipBasedTimestamp(2, 1), | 55 | + .addEqualityGroup(new DeviceMastershipBasedTimestamp(2, 1), |
57 | - new MastershipBasedTimestamp(2, 1), TS_2_1) | 56 | + new DeviceMastershipBasedTimestamp(2, 1), TS_2_1) |
58 | - .addEqualityGroup(new MastershipBasedTimestamp(2, 2), | 57 | + .addEqualityGroup(new DeviceMastershipBasedTimestamp(2, 2), |
59 | - new MastershipBasedTimestamp(2, 2), TS_2_2) | 58 | + new DeviceMastershipBasedTimestamp(2, 2), TS_2_2) |
60 | .testEquals(); | 59 | .testEquals(); |
61 | } | 60 | } |
62 | 61 | ||
... | @@ -64,7 +63,7 @@ public class MastershipBasedTimestampTest { | ... | @@ -64,7 +63,7 @@ public class MastershipBasedTimestampTest { |
64 | public final void testKryoSerializable() { | 63 | public final void testKryoSerializable() { |
65 | final ByteBuffer buffer = ByteBuffer.allocate(1 * 1024 * 1024); | 64 | final ByteBuffer buffer = ByteBuffer.allocate(1 * 1024 * 1024); |
66 | final KryoPool kryos = KryoPool.newBuilder() | 65 | final KryoPool kryos = KryoPool.newBuilder() |
67 | - .register(MastershipBasedTimestamp.class) | 66 | + .register(DeviceMastershipBasedTimestamp.class) |
68 | .build(); | 67 | .build(); |
69 | 68 | ||
70 | kryos.serialize(TS_2_1, buffer); | 69 | kryos.serialize(TS_2_1, buffer); |
... | @@ -80,7 +79,7 @@ public class MastershipBasedTimestampTest { | ... | @@ -80,7 +79,7 @@ public class MastershipBasedTimestampTest { |
80 | public final void testKryoSerializableWithHandcraftedSerializer() { | 79 | public final void testKryoSerializableWithHandcraftedSerializer() { |
81 | final ByteBuffer buffer = ByteBuffer.allocate(1 * 1024 * 1024); | 80 | final ByteBuffer buffer = ByteBuffer.allocate(1 * 1024 * 1024); |
82 | final KryoPool kryos = KryoPool.newBuilder() | 81 | final KryoPool kryos = KryoPool.newBuilder() |
83 | - .register(MastershipBasedTimestamp.class, new MastershipBasedTimestampSerializer()) | 82 | + .register(DeviceMastershipBasedTimestamp.class, new MastershipBasedTimestampSerializer()) |
84 | .build(); | 83 | .build(); |
85 | 84 | ||
86 | kryos.serialize(TS_1_2, buffer); | 85 | kryos.serialize(TS_1_2, buffer); | ... | ... |
... | @@ -6,6 +6,7 @@ import java.nio.ByteBuffer; | ... | @@ -6,6 +6,7 @@ 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; | ||
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; |
... | @@ -15,9 +16,9 @@ import com.google.common.testing.EqualsTester; | ... | @@ -15,9 +16,9 @@ import com.google.common.testing.EqualsTester; |
15 | */ | 16 | */ |
16 | public class TimestampedTest { | 17 | public class TimestampedTest { |
17 | 18 | ||
18 | - private static final Timestamp TS_1_1 = new MastershipBasedTimestamp(1, 1); | 19 | + private static final Timestamp TS_1_1 = new DeviceMastershipBasedTimestamp(1, 1); |
19 | - private static final Timestamp TS_1_2 = new MastershipBasedTimestamp(1, 2); | 20 | + private static final Timestamp TS_1_2 = new DeviceMastershipBasedTimestamp(1, 2); |
20 | - private static final Timestamp TS_2_1 = new MastershipBasedTimestamp(2, 1); | 21 | + private static final Timestamp TS_2_1 = new DeviceMastershipBasedTimestamp(2, 1); |
21 | 22 | ||
22 | @Test | 23 | @Test |
23 | public final void testHashCode() { | 24 | public final void testHashCode() { |
... | @@ -79,7 +80,7 @@ public class TimestampedTest { | ... | @@ -79,7 +80,7 @@ public class TimestampedTest { |
79 | final ByteBuffer buffer = ByteBuffer.allocate(1 * 1024 * 1024); | 80 | final ByteBuffer buffer = ByteBuffer.allocate(1 * 1024 * 1024); |
80 | final KryoPool kryos = KryoPool.newBuilder() | 81 | final KryoPool kryos = KryoPool.newBuilder() |
81 | .register(Timestamped.class, | 82 | .register(Timestamped.class, |
82 | - MastershipBasedTimestamp.class) | 83 | + DeviceMastershipBasedTimestamp.class) |
83 | .build(); | 84 | .build(); |
84 | 85 | ||
85 | Timestamped<String> original = new Timestamped<>("foobar", TS_1_1); | 86 | Timestamped<String> original = new Timestamped<>("foobar", TS_1_1); | ... | ... |
... | @@ -25,7 +25,6 @@ import org.onlab.onos.cluster.ClusterService; | ... | @@ -25,7 +25,6 @@ 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; | ||
29 | import org.onlab.onos.cluster.NodeId; | 28 | import org.onlab.onos.cluster.NodeId; |
30 | import org.onlab.onos.net.Annotations; | 29 | import org.onlab.onos.net.Annotations; |
31 | import org.onlab.onos.net.DefaultAnnotations; | 30 | import org.onlab.onos.net.DefaultAnnotations; |
... | @@ -40,6 +39,7 @@ import org.onlab.onos.net.device.DeviceDescription; | ... | @@ -40,6 +39,7 @@ import org.onlab.onos.net.device.DeviceDescription; |
40 | import org.onlab.onos.net.device.DeviceEvent; | 39 | import org.onlab.onos.net.device.DeviceEvent; |
41 | import org.onlab.onos.net.device.DeviceStore; | 40 | import org.onlab.onos.net.device.DeviceStore; |
42 | import org.onlab.onos.net.device.DeviceStoreDelegate; | 41 | 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, MastershipTerm.of(MYSELF, 1)); | 116 | + deviceClockManager.setMastershipTerm(DID1, DeviceMastershipTerm.of(MYSELF, 1)); |
117 | - deviceClockManager.setMastershipTerm(DID2, MastershipTerm.of(MYSELF, 2)); | 117 | + deviceClockManager.setMastershipTerm(DID2, DeviceMastershipTerm.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(); | ... | ... |
1 | package org.onlab.onos.store.cluster.impl; | 1 | package org.onlab.onos.store.cluster.impl; |
2 | 2 | ||
3 | -import static org.onlab.onos.cluster.MastershipEvent.Type.MASTER_CHANGED; | 3 | +import static org.onlab.onos.net.device.DeviceMastershipEvent.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; | ||
19 | import org.onlab.onos.cluster.NodeId; | 15 | import org.onlab.onos.cluster.NodeId; |
20 | import org.onlab.onos.net.DeviceId; | 16 | import org.onlab.onos.net.DeviceId; |
21 | import org.onlab.onos.net.MastershipRole; | 17 | 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; |
... | @@ -33,8 +33,8 @@ import com.hazelcast.core.MultiMap; | ... | @@ -33,8 +33,8 @@ import com.hazelcast.core.MultiMap; |
33 | @Component(immediate = true) | 33 | @Component(immediate = true) |
34 | @Service | 34 | @Service |
35 | public class DistributedMastershipStore | 35 | public class DistributedMastershipStore |
36 | -extends AbstractHazelcastStore<MastershipEvent, MastershipStoreDelegate> | 36 | +extends AbstractHazelcastStore<DeviceMastershipEvent, DeviceMastershipStoreDelegate> |
37 | -implements MastershipStore { | 37 | +implements DeviceMastershipStore { |
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 MastershipStore { | ... | @@ -100,7 +100,7 @@ implements MastershipStore { |
100 | } | 100 | } |
101 | 101 | ||
102 | @Override | 102 | @Override |
103 | - public MastershipEvent setMaster(NodeId nodeId, DeviceId deviceId) { | 103 | + public DeviceMastershipEvent 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 MastershipStore { | ... | @@ -123,12 +123,12 @@ implements MastershipStore { |
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 MastershipEvent(MASTER_CHANGED, deviceId, nodeId); | 126 | + return new DeviceMastershipEvent(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 MastershipEvent(MASTER_CHANGED, deviceId, nodeId); | 131 | + return new DeviceMastershipEvent(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 MastershipStore { | ... | @@ -191,21 +191,21 @@ implements MastershipStore { |
191 | } | 191 | } |
192 | 192 | ||
193 | @Override | 193 | @Override |
194 | - public MastershipTerm getTermFor(DeviceId deviceId) { | 194 | + public DeviceMastershipTerm 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 MastershipTerm.of( | 200 | + return DeviceMastershipTerm.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 MastershipEvent setStandby(NodeId nodeId, DeviceId deviceId) { | 205 | + public DeviceMastershipEvent 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 | - MastershipEvent event = null; | 208 | + DeviceMastershipEvent 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 MastershipStore { | ... | @@ -231,10 +231,10 @@ implements MastershipStore { |
231 | } | 231 | } |
232 | 232 | ||
233 | @Override | 233 | @Override |
234 | - public MastershipEvent relinquishRole(NodeId nodeId, DeviceId deviceId) { | 234 | + public DeviceMastershipEvent 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 | - MastershipEvent event = null; | 237 | + DeviceMastershipEvent 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 MastershipStore { | ... | @@ -260,7 +260,7 @@ implements MastershipStore { |
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 MastershipEvent reelect(NodeId current, DeviceId deviceId) { | 263 | + private DeviceMastershipEvent 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 MastershipStore { | ... | @@ -281,7 +281,7 @@ implements MastershipStore { |
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 MastershipEvent( | 284 | + return new DeviceMastershipEvent( |
285 | MASTER_CHANGED, deviceId, (NodeId) deserialize(backup)); | 285 | MASTER_CHANGED, deviceId, (NodeId) deserialize(backup)); |
286 | } | 286 | } |
287 | } | 287 | } |
... | @@ -320,7 +320,7 @@ implements MastershipStore { | ... | @@ -320,7 +320,7 @@ implements MastershipStore { |
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 MastershipEvent(MASTER_CHANGED, deviceId, nodeId)); | 323 | + notifyDelegate(new DeviceMastershipEvent(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; | ||
28 | import org.onlab.onos.cluster.NodeId; | 24 | import org.onlab.onos.cluster.NodeId; |
29 | import org.onlab.onos.net.DeviceId; | 25 | 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; |
... | @@ -133,7 +133,7 @@ public class DistributedMastershipStoreTest { | ... | @@ -133,7 +133,7 @@ public class DistributedMastershipStoreTest { |
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 | - MastershipTerm.of(N1, 0), dms.getTermFor(DID1)); | 136 | + DeviceMastershipTerm.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 DistributedMastershipStoreTest { | ... | @@ -143,7 +143,7 @@ public class DistributedMastershipStoreTest { |
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", MastershipTerm.of(N1, 1), dms.getTermFor(DID2)); | 146 | + assertEquals("wrong term", DeviceMastershipTerm.of(N1, 1), dms.getTermFor(DID2)); |
147 | } | 147 | } |
148 | 148 | ||
149 | @Test | 149 | @Test |
... | @@ -155,15 +155,15 @@ public class DistributedMastershipStoreTest { | ... | @@ -155,15 +155,15 @@ public class DistributedMastershipStoreTest { |
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", MastershipTerm.of(N2, 1), dms.getTermFor(DID1)); | 158 | + assertEquals("wrong term", DeviceMastershipTerm.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", MastershipTerm.of(N2, 0), dms.getTermFor(DID2)); | 162 | + assertEquals("wrong term", DeviceMastershipTerm.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", MastershipTerm.of(N2, 1), dms.getTermFor(DID2)); | 166 | + assertEquals("wrong term", DeviceMastershipTerm.of(N2, 1), dms.getTermFor(DID2)); |
167 | } | 167 | } |
168 | 168 | ||
169 | @Test | 169 | @Test |
... | @@ -211,9 +211,9 @@ public class DistributedMastershipStoreTest { | ... | @@ -211,9 +211,9 @@ public class DistributedMastershipStoreTest { |
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 | - MastershipStoreDelegate checkAdd = new MastershipStoreDelegate() { | 214 | + DeviceMastershipStoreDelegate checkAdd = new DeviceMastershipStoreDelegate() { |
215 | @Override | 215 | @Override |
216 | - public void notify(MastershipEvent event) { | 216 | + public void notify(DeviceMastershipEvent 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()); | ... | ... |
... | @@ -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; | ||
6 | import org.onlab.onos.net.DeviceId; | 5 | 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, MastershipTerm term) { | 18 | + public void setMastershipTerm(DeviceId deviceId, DeviceMastershipTerm term) { |
19 | } | 19 | } |
20 | } | 20 | } | ... | ... |
... | @@ -7,7 +7,6 @@ import java.util.HashMap; | ... | @@ -7,7 +7,6 @@ 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; | ||
11 | import org.onlab.onos.cluster.NodeId; | 10 | import org.onlab.onos.cluster.NodeId; |
12 | import org.onlab.onos.net.ConnectPoint; | 11 | import org.onlab.onos.net.ConnectPoint; |
13 | import org.onlab.onos.net.DefaultAnnotations; | 12 | import org.onlab.onos.net.DefaultAnnotations; |
... | @@ -24,6 +23,7 @@ import org.onlab.onos.net.Port; | ... | @@ -24,6 +23,7 @@ import org.onlab.onos.net.Port; |
24 | import org.onlab.onos.net.PortNumber; | 23 | import org.onlab.onos.net.PortNumber; |
25 | import org.onlab.onos.net.device.DefaultDeviceDescription; | 24 | import org.onlab.onos.net.device.DefaultDeviceDescription; |
26 | import org.onlab.onos.net.device.DefaultPortDescription; | 25 | 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.packet.IpAddress; | 28 | import org.onlab.packet.IpAddress; |
29 | import org.onlab.packet.IpPrefix; | 29 | import org.onlab.packet.IpPrefix; |
... | @@ -74,7 +74,7 @@ public final class KryoPoolUtil { | ... | @@ -74,7 +74,7 @@ public final class KryoPoolUtil { |
74 | .register(LinkKey.class, new LinkKeySerializer()) | 74 | .register(LinkKey.class, new LinkKeySerializer()) |
75 | .register(ConnectPoint.class, new ConnectPointSerializer()) | 75 | .register(ConnectPoint.class, new ConnectPointSerializer()) |
76 | .register(DefaultLink.class, new DefaultLinkSerializer()) | 76 | .register(DefaultLink.class, new DefaultLinkSerializer()) |
77 | - .register(MastershipTerm.class, new MastershipTermSerializer()) | 77 | + .register(DeviceMastershipTerm.class, new MastershipTermSerializer()) |
78 | .register(MastershipRole.class, new MastershipRoleSerializer()) | 78 | .register(MastershipRole.class, new MastershipRoleSerializer()) |
79 | 79 | ||
80 | .build(); | 80 | .build(); | ... | ... |
1 | package org.onlab.onos.store.serializers; | 1 | package org.onlab.onos.store.serializers; |
2 | 2 | ||
3 | -import org.onlab.onos.cluster.MastershipTerm; | ||
4 | import org.onlab.onos.cluster.NodeId; | 3 | import org.onlab.onos.cluster.NodeId; |
4 | +import org.onlab.onos.net.device.DeviceMastershipTerm; | ||
5 | + | ||
5 | import com.esotericsoftware.kryo.Kryo; | 6 | import com.esotericsoftware.kryo.Kryo; |
6 | import com.esotericsoftware.kryo.Serializer; | 7 | import com.esotericsoftware.kryo.Serializer; |
7 | import com.esotericsoftware.kryo.io.Input; | 8 | import com.esotericsoftware.kryo.io.Input; |
8 | import com.esotericsoftware.kryo.io.Output; | 9 | import com.esotericsoftware.kryo.io.Output; |
9 | 10 | ||
10 | /** | 11 | /** |
11 | - * Kryo Serializer for {@link org.onlab.onos.cluster.MastershipTerm}. | 12 | + * Kryo Serializer for {@link org.onlab.onos.net.device.DeviceMastershipTerm}. |
12 | */ | 13 | */ |
13 | -public class MastershipTermSerializer extends Serializer<MastershipTerm> { | 14 | +public class MastershipTermSerializer extends Serializer<DeviceMastershipTerm> { |
14 | 15 | ||
15 | /** | 16 | /** |
16 | - * Creates {@link MastershipTerm} serializer instance. | 17 | + * Creates {@link DeviceMastershipTerm} serializer instance. |
17 | */ | 18 | */ |
18 | public MastershipTermSerializer() { | 19 | public MastershipTermSerializer() { |
19 | // non-null, immutable | 20 | // non-null, immutable |
... | @@ -21,14 +22,14 @@ public class MastershipTermSerializer extends Serializer<MastershipTerm> { | ... | @@ -21,14 +22,14 @@ public class MastershipTermSerializer extends Serializer<MastershipTerm> { |
21 | } | 22 | } |
22 | 23 | ||
23 | @Override | 24 | @Override |
24 | - public MastershipTerm read(Kryo kryo, Input input, Class<MastershipTerm> type) { | 25 | + public DeviceMastershipTerm read(Kryo kryo, Input input, Class<DeviceMastershipTerm> type) { |
25 | final NodeId node = new NodeId(input.readString()); | 26 | final NodeId node = new NodeId(input.readString()); |
26 | final int term = input.readInt(); | 27 | final int term = input.readInt(); |
27 | - return MastershipTerm.of(node, term); | 28 | + return DeviceMastershipTerm.of(node, term); |
28 | } | 29 | } |
29 | 30 | ||
30 | @Override | 31 | @Override |
31 | - public void write(Kryo kryo, Output output, MastershipTerm object) { | 32 | + public void write(Kryo kryo, Output output, DeviceMastershipTerm object) { |
32 | output.writeString(object.master().toString()); | 33 | output.writeString(object.master().toString()); |
33 | output.writeInt(object.termNumber()); | 34 | output.writeInt(object.termNumber()); |
34 | } | 35 | } | ... | ... |
... | @@ -10,7 +10,6 @@ import org.junit.After; | ... | @@ -10,7 +10,6 @@ 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; | ||
14 | import org.onlab.onos.cluster.NodeId; | 13 | import org.onlab.onos.cluster.NodeId; |
15 | import org.onlab.onos.net.Annotations; | 14 | import org.onlab.onos.net.Annotations; |
16 | import org.onlab.onos.net.ConnectPoint; | 15 | import org.onlab.onos.net.ConnectPoint; |
... | @@ -25,6 +24,7 @@ import org.onlab.onos.net.LinkKey; | ... | @@ -25,6 +24,7 @@ import org.onlab.onos.net.LinkKey; |
25 | import org.onlab.onos.net.MastershipRole; | 24 | import org.onlab.onos.net.MastershipRole; |
26 | import org.onlab.onos.net.PortNumber; | 25 | import org.onlab.onos.net.PortNumber; |
27 | import org.onlab.onos.net.SparseAnnotations; | 26 | 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(MastershipTerm.of(new NodeId("foo"), 2)); | 117 | + testSerialized(DeviceMastershipTerm.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; | ||
6 | import org.onlab.onos.net.DeviceId; | 5 | 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, MastershipTerm term) { | 18 | + public void setMastershipTerm(DeviceId deviceId, DeviceMastershipTerm term) { |
19 | } | 19 | } |
20 | } | 20 | } | ... | ... |
... | @@ -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; | ||
22 | import org.onlab.onos.cluster.NodeId; | 18 | import org.onlab.onos.cluster.NodeId; |
23 | import org.onlab.onos.net.DeviceId; | 19 | import org.onlab.onos.net.DeviceId; |
24 | import org.onlab.onos.net.MastershipRole; | 20 | 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.cluster.MastershipEvent.Type.*; | 29 | +import static org.onlab.onos.net.device.DeviceMastershipEvent.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.cluster.MastershipEvent.Type.*; | ... | @@ -35,8 +35,8 @@ import static org.onlab.onos.cluster.MastershipEvent.Type.*; |
35 | @Component(immediate = true) | 35 | @Component(immediate = true) |
36 | @Service | 36 | @Service |
37 | public class SimpleMastershipStore | 37 | public class SimpleMastershipStore |
38 | - extends AbstractStore<MastershipEvent, MastershipStoreDelegate> | 38 | + extends AbstractStore<DeviceMastershipEvent, DeviceMastershipStoreDelegate> |
39 | - implements MastershipStore { | 39 | + implements DeviceMastershipStore { |
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 MastershipEvent setMaster(NodeId nodeId, DeviceId deviceId) { | 66 | + public DeviceMastershipEvent 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 MastershipEvent(MASTER_CHANGED, deviceId, nodeId); | 89 | + return new DeviceMastershipEvent(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 MastershipTerm getTermFor(DeviceId deviceId) { | 167 | + public DeviceMastershipTerm 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 MastershipTerm.of( | 172 | + return DeviceMastershipTerm.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 MastershipEvent setStandby(NodeId nodeId, DeviceId deviceId) { | 177 | + public DeviceMastershipEvent 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 MastershipEvent(MASTER_CHANGED, deviceId, backup); | 188 | + return new DeviceMastershipEvent(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 MastershipEvent relinquishRole(NodeId nodeId, DeviceId deviceId) { | 218 | + public DeviceMastershipEvent 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; | ||
10 | import org.onlab.onos.cluster.NodeId; | 9 | import org.onlab.onos.cluster.NodeId; |
11 | import org.onlab.onos.net.DeviceId; | 10 | 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.cluster.MastershipEvent.Type.*; | 19 | +import static org.onlab.onos.net.device.DeviceMastershipEvent.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", MastershipTerm.of(N1, 0), sms.getTermFor(DID1)); | 101 | + assertEquals("wrong term", DeviceMastershipTerm.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", MastershipTerm.of(N1, 2), sms.getTermFor(DID1)); | 106 | + assertEquals("wrong term", DeviceMastershipTerm.of(N1, 2), sms.getTermFor(DID1)); |
107 | } | 107 | } |
108 | 108 | ||
109 | @Test | 109 | @Test | ... | ... |
-
Please register or login to post a comment