Committed by
Gerrit Code Review
Including nodeId in DefaultPacketRequest so that we do not prematurely withdraw …
…intercepts when a node is shutdown Change-Id: If6ae0be8f53a4a158af37e6cc4938309a5e9991b
Showing
5 changed files
with
50 additions
and
11 deletions
| ... | @@ -16,6 +16,8 @@ | ... | @@ -16,6 +16,8 @@ |
| 16 | package org.onosproject.net.packet; | 16 | package org.onosproject.net.packet; |
| 17 | 17 | ||
| 18 | import com.google.common.base.MoreObjects; | 18 | import com.google.common.base.MoreObjects; |
| 19 | + | ||
| 20 | +import org.onosproject.cluster.NodeId; | ||
| 19 | import org.onosproject.core.ApplicationId; | 21 | import org.onosproject.core.ApplicationId; |
| 20 | import org.onosproject.net.flow.TrafficSelector; | 22 | import org.onosproject.net.flow.TrafficSelector; |
| 21 | 23 | ||
| ... | @@ -28,6 +30,7 @@ public final class DefaultPacketRequest implements PacketRequest { | ... | @@ -28,6 +30,7 @@ public final class DefaultPacketRequest implements PacketRequest { |
| 28 | private final TrafficSelector selector; | 30 | private final TrafficSelector selector; |
| 29 | private final PacketPriority priority; | 31 | private final PacketPriority priority; |
| 30 | private final ApplicationId appId; | 32 | private final ApplicationId appId; |
| 33 | + private final NodeId nodeId; | ||
| 31 | 34 | ||
| 32 | /** | 35 | /** |
| 33 | * Creates a new packet request. | 36 | * Creates a new packet request. |
| ... | @@ -35,29 +38,40 @@ public final class DefaultPacketRequest implements PacketRequest { | ... | @@ -35,29 +38,40 @@ public final class DefaultPacketRequest implements PacketRequest { |
| 35 | * @param selector traffic selector | 38 | * @param selector traffic selector |
| 36 | * @param priority intercept priority | 39 | * @param priority intercept priority |
| 37 | * @param appId application id | 40 | * @param appId application id |
| 41 | + * @param nodeId identifier of node where request originated | ||
| 38 | */ | 42 | */ |
| 39 | public DefaultPacketRequest(TrafficSelector selector, PacketPriority priority, | 43 | public DefaultPacketRequest(TrafficSelector selector, PacketPriority priority, |
| 40 | - ApplicationId appId) { | 44 | + ApplicationId appId, |
| 45 | + NodeId nodeId) { | ||
| 41 | this.selector = selector; | 46 | this.selector = selector; |
| 42 | this.priority = priority; | 47 | this.priority = priority; |
| 43 | this.appId = appId; | 48 | this.appId = appId; |
| 49 | + this.nodeId = nodeId; | ||
| 44 | } | 50 | } |
| 45 | 51 | ||
| 52 | + @Override | ||
| 46 | public TrafficSelector selector() { | 53 | public TrafficSelector selector() { |
| 47 | return selector; | 54 | return selector; |
| 48 | } | 55 | } |
| 49 | 56 | ||
| 57 | + @Override | ||
| 50 | public PacketPriority priority() { | 58 | public PacketPriority priority() { |
| 51 | return priority; | 59 | return priority; |
| 52 | } | 60 | } |
| 53 | 61 | ||
| 62 | + @Override | ||
| 54 | public ApplicationId appId() { | 63 | public ApplicationId appId() { |
| 55 | return appId; | 64 | return appId; |
| 56 | } | 65 | } |
| 57 | 66 | ||
| 58 | @Override | 67 | @Override |
| 68 | + public NodeId nodeId() { | ||
| 69 | + return nodeId; | ||
| 70 | + } | ||
| 71 | + | ||
| 72 | + @Override | ||
| 59 | public int hashCode() { | 73 | public int hashCode() { |
| 60 | - return Objects.hash(selector, priority, appId); | 74 | + return Objects.hash(selector, priority, appId, nodeId); |
| 61 | } | 75 | } |
| 62 | 76 | ||
| 63 | @Override | 77 | @Override |
| ... | @@ -71,7 +85,8 @@ public final class DefaultPacketRequest implements PacketRequest { | ... | @@ -71,7 +85,8 @@ public final class DefaultPacketRequest implements PacketRequest { |
| 71 | final DefaultPacketRequest other = (DefaultPacketRequest) obj; | 85 | final DefaultPacketRequest other = (DefaultPacketRequest) obj; |
| 72 | return Objects.equals(this.selector, other.selector) | 86 | return Objects.equals(this.selector, other.selector) |
| 73 | && Objects.equals(this.priority, other.priority) | 87 | && Objects.equals(this.priority, other.priority) |
| 74 | - && Objects.equals(this.appId, other.appId); | 88 | + && Objects.equals(this.appId, other.appId) |
| 89 | + && Objects.equals(this.nodeId, other.nodeId); | ||
| 75 | } | 90 | } |
| 76 | 91 | ||
| 77 | @Override | 92 | @Override |
| ... | @@ -79,6 +94,7 @@ public final class DefaultPacketRequest implements PacketRequest { | ... | @@ -79,6 +94,7 @@ public final class DefaultPacketRequest implements PacketRequest { |
| 79 | return MoreObjects.toStringHelper(this.getClass()) | 94 | return MoreObjects.toStringHelper(this.getClass()) |
| 80 | .add("selector", selector) | 95 | .add("selector", selector) |
| 81 | .add("priority", priority) | 96 | .add("priority", priority) |
| 82 | - .add("appId", appId).toString(); | 97 | + .add("appId", appId) |
| 98 | + .add("nodeId", nodeId).toString(); | ||
| 83 | } | 99 | } |
| 84 | } | 100 | } |
| ... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
| ... | @@ -15,6 +15,7 @@ | ... | @@ -15,6 +15,7 @@ |
| 15 | */ | 15 | */ |
| 16 | package org.onosproject.net.packet; | 16 | package org.onosproject.net.packet; |
| 17 | 17 | ||
| 18 | +import org.onosproject.cluster.NodeId; | ||
| 18 | import org.onosproject.core.ApplicationId; | 19 | import org.onosproject.core.ApplicationId; |
| 19 | import org.onosproject.net.flow.TrafficSelector; | 20 | import org.onosproject.net.flow.TrafficSelector; |
| 20 | 21 | ||
| ... | @@ -44,4 +45,10 @@ public interface PacketRequest { | ... | @@ -44,4 +45,10 @@ public interface PacketRequest { |
| 44 | */ | 45 | */ |
| 45 | ApplicationId appId(); | 46 | ApplicationId appId(); |
| 46 | 47 | ||
| 48 | + /** | ||
| 49 | + * Obtain the node id. | ||
| 50 | + * | ||
| 51 | + * @return an node id | ||
| 52 | + */ | ||
| 53 | + NodeId nodeId(); | ||
| 47 | } | 54 | } | ... | ... |
| ... | @@ -18,6 +18,7 @@ package org.onosproject.net; | ... | @@ -18,6 +18,7 @@ package org.onosproject.net; |
| 18 | import org.onlab.junit.TestUtils; | 18 | import org.onlab.junit.TestUtils; |
| 19 | import org.onlab.packet.ChassisId; | 19 | import org.onlab.packet.ChassisId; |
| 20 | import org.onosproject.TestApplicationId; | 20 | import org.onosproject.TestApplicationId; |
| 21 | +import org.onosproject.cluster.NodeId; | ||
| 21 | import org.onosproject.core.ApplicationId; | 22 | import org.onosproject.core.ApplicationId; |
| 22 | import org.onosproject.event.EventDeliveryService; | 23 | import org.onosproject.event.EventDeliveryService; |
| 23 | import org.onosproject.net.provider.ProviderId; | 24 | import org.onosproject.net.provider.ProviderId; |
| ... | @@ -44,6 +45,7 @@ public final class NetTestTools { | ... | @@ -44,6 +45,7 @@ public final class NetTestTools { |
| 44 | 45 | ||
| 45 | public static final ProviderId PID = new ProviderId("of", "foo"); | 46 | public static final ProviderId PID = new ProviderId("of", "foo"); |
| 46 | public static final ApplicationId APP_ID = new TestApplicationId("foo"); | 47 | public static final ApplicationId APP_ID = new TestApplicationId("foo"); |
| 48 | + public static final NodeId NODE_ID = new NodeId("node1"); | ||
| 47 | 49 | ||
| 48 | // Short-hand for producing a device id from a string | 50 | // Short-hand for producing a device id from a string |
| 49 | public static DeviceId did(String id) { | 51 | public static DeviceId did(String id) { | ... | ... |
| ... | @@ -16,6 +16,7 @@ | ... | @@ -16,6 +16,7 @@ |
| 16 | package org.onosproject.net.packet; | 16 | package org.onosproject.net.packet; |
| 17 | 17 | ||
| 18 | import org.junit.Test; | 18 | import org.junit.Test; |
| 19 | +import org.onosproject.cluster.NodeId; | ||
| 19 | import org.onosproject.core.DefaultApplicationId; | 20 | import org.onosproject.core.DefaultApplicationId; |
| 20 | import org.onosproject.net.NetTestTools; | 21 | import org.onosproject.net.NetTestTools; |
| 21 | import org.onosproject.net.flow.DefaultTrafficSelector; | 22 | import org.onosproject.net.flow.DefaultTrafficSelector; |
| ... | @@ -40,23 +41,28 @@ public class DefaultPacketRequestTest { | ... | @@ -40,23 +41,28 @@ public class DefaultPacketRequestTest { |
| 40 | private final DefaultPacketRequest packetRequest1 = | 41 | private final DefaultPacketRequest packetRequest1 = |
| 41 | new DefaultPacketRequest(DefaultTrafficSelector.emptySelector(), | 42 | new DefaultPacketRequest(DefaultTrafficSelector.emptySelector(), |
| 42 | PacketPriority.CONTROL, | 43 | PacketPriority.CONTROL, |
| 43 | - NetTestTools.APP_ID); | 44 | + NetTestTools.APP_ID, |
| 45 | + NetTestTools.NODE_ID); | ||
| 44 | private final DefaultPacketRequest sameAsacketRequest1 = | 46 | private final DefaultPacketRequest sameAsacketRequest1 = |
| 45 | new DefaultPacketRequest(DefaultTrafficSelector.emptySelector(), | 47 | new DefaultPacketRequest(DefaultTrafficSelector.emptySelector(), |
| 46 | PacketPriority.CONTROL, | 48 | PacketPriority.CONTROL, |
| 47 | - NetTestTools.APP_ID); | 49 | + NetTestTools.APP_ID, |
| 50 | + NetTestTools.NODE_ID); | ||
| 48 | private final DefaultPacketRequest packetRequest2 = | 51 | private final DefaultPacketRequest packetRequest2 = |
| 49 | new DefaultPacketRequest(selector, | 52 | new DefaultPacketRequest(selector, |
| 50 | PacketPriority.CONTROL, | 53 | PacketPriority.CONTROL, |
| 51 | - NetTestTools.APP_ID); | 54 | + NetTestTools.APP_ID, |
| 55 | + NetTestTools.NODE_ID); | ||
| 52 | private final DefaultPacketRequest packetRequest3 = | 56 | private final DefaultPacketRequest packetRequest3 = |
| 53 | new DefaultPacketRequest(DefaultTrafficSelector.emptySelector(), | 57 | new DefaultPacketRequest(DefaultTrafficSelector.emptySelector(), |
| 54 | PacketPriority.REACTIVE, | 58 | PacketPriority.REACTIVE, |
| 55 | - NetTestTools.APP_ID); | 59 | + NetTestTools.APP_ID, |
| 60 | + NetTestTools.NODE_ID); | ||
| 56 | private final DefaultPacketRequest packetRequest4 = | 61 | private final DefaultPacketRequest packetRequest4 = |
| 57 | new DefaultPacketRequest(DefaultTrafficSelector.emptySelector(), | 62 | new DefaultPacketRequest(DefaultTrafficSelector.emptySelector(), |
| 58 | PacketPriority.CONTROL, | 63 | PacketPriority.CONTROL, |
| 59 | - new DefaultApplicationId(1, "foo")); | 64 | + new DefaultApplicationId(1, "foo"), |
| 65 | + new NodeId("node1")); | ||
| 60 | 66 | ||
| 61 | /** | 67 | /** |
| 62 | * Tests the operation of the equals(), toAstring() and hashCode() methods. | 68 | * Tests the operation of the equals(), toAstring() and hashCode() methods. | ... | ... |
| ... | @@ -17,12 +17,15 @@ package org.onosproject.net.packet.impl; | ... | @@ -17,12 +17,15 @@ package org.onosproject.net.packet.impl; |
| 17 | 17 | ||
| 18 | import com.google.common.collect.ImmutableList; | 18 | import com.google.common.collect.ImmutableList; |
| 19 | import com.google.common.collect.Lists; | 19 | import com.google.common.collect.Lists; |
| 20 | + | ||
| 20 | import org.apache.felix.scr.annotations.Activate; | 21 | import org.apache.felix.scr.annotations.Activate; |
| 21 | import org.apache.felix.scr.annotations.Component; | 22 | import org.apache.felix.scr.annotations.Component; |
| 22 | import org.apache.felix.scr.annotations.Deactivate; | 23 | import org.apache.felix.scr.annotations.Deactivate; |
| 23 | import org.apache.felix.scr.annotations.Reference; | 24 | import org.apache.felix.scr.annotations.Reference; |
| 24 | import org.apache.felix.scr.annotations.ReferenceCardinality; | 25 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
| 25 | import org.apache.felix.scr.annotations.Service; | 26 | import org.apache.felix.scr.annotations.Service; |
| 27 | +import org.onosproject.cluster.ClusterService; | ||
| 28 | +import org.onosproject.cluster.NodeId; | ||
| 26 | import org.onosproject.core.ApplicationId; | 29 | import org.onosproject.core.ApplicationId; |
| 27 | import org.onosproject.core.CoreService; | 30 | import org.onosproject.core.CoreService; |
| 28 | import org.onosproject.net.Device; | 31 | import org.onosproject.net.Device; |
| ... | @@ -87,6 +90,9 @@ public class PacketManager | ... | @@ -87,6 +90,9 @@ public class PacketManager |
| 87 | private CoreService coreService; | 90 | private CoreService coreService; |
| 88 | 91 | ||
| 89 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 92 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 93 | + private ClusterService clusterService; | ||
| 94 | + | ||
| 95 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
| 90 | private DeviceService deviceService; | 96 | private DeviceService deviceService; |
| 91 | 97 | ||
| 92 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 98 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| ... | @@ -105,11 +111,13 @@ public class PacketManager | ... | @@ -105,11 +111,13 @@ public class PacketManager |
| 105 | private final List<ProcessorEntry> processors = Lists.newCopyOnWriteArrayList(); | 111 | private final List<ProcessorEntry> processors = Lists.newCopyOnWriteArrayList(); |
| 106 | 112 | ||
| 107 | private ApplicationId appId; | 113 | private ApplicationId appId; |
| 114 | + private NodeId localNodeId; | ||
| 108 | 115 | ||
| 109 | @Activate | 116 | @Activate |
| 110 | public void activate() { | 117 | public void activate() { |
| 111 | eventHandlingExecutor = Executors.newSingleThreadExecutor( | 118 | eventHandlingExecutor = Executors.newSingleThreadExecutor( |
| 112 | groupedThreads("onos/net/packet", "event-handler")); | 119 | groupedThreads("onos/net/packet", "event-handler")); |
| 120 | + localNodeId = clusterService.getLocalNode().id(); | ||
| 113 | appId = coreService.getAppId(CoreService.CORE_APP_NAME); | 121 | appId = coreService.getAppId(CoreService.CORE_APP_NAME); |
| 114 | store.setDelegate(delegate); | 122 | store.setDelegate(delegate); |
| 115 | deviceService.addListener(deviceListener); | 123 | deviceService.addListener(deviceListener); |
| ... | @@ -167,7 +175,7 @@ public class PacketManager | ... | @@ -167,7 +175,7 @@ public class PacketManager |
| 167 | checkNotNull(selector, "Selector cannot be null"); | 175 | checkNotNull(selector, "Selector cannot be null"); |
| 168 | checkNotNull(appId, "Application ID cannot be null"); | 176 | checkNotNull(appId, "Application ID cannot be null"); |
| 169 | 177 | ||
| 170 | - PacketRequest request = new DefaultPacketRequest(selector, priority, appId); | 178 | + PacketRequest request = new DefaultPacketRequest(selector, priority, appId, localNodeId); |
| 171 | store.requestPackets(request); | 179 | store.requestPackets(request); |
| 172 | } | 180 | } |
| 173 | 181 | ||
| ... | @@ -178,7 +186,7 @@ public class PacketManager | ... | @@ -178,7 +186,7 @@ public class PacketManager |
| 178 | checkNotNull(selector, "Selector cannot be null"); | 186 | checkNotNull(selector, "Selector cannot be null"); |
| 179 | checkNotNull(appId, "Application ID cannot be null"); | 187 | checkNotNull(appId, "Application ID cannot be null"); |
| 180 | 188 | ||
| 181 | - PacketRequest request = new DefaultPacketRequest(selector, priority, appId); | 189 | + PacketRequest request = new DefaultPacketRequest(selector, priority, appId, localNodeId); |
| 182 | store.cancelPackets(request); | 190 | store.cancelPackets(request); |
| 183 | } | 191 | } |
| 184 | 192 | ... | ... |
-
Please register or login to post a comment