ONOS-2145 Added ability to withdraw packet intercepts via PacketService::cancelPackets.
Change-Id: Ie41271fa02740560bd67b0faf49f633ee749773c
Showing
17 changed files
with
323 additions
and
362 deletions
This diff is collapsed. Click to expand it.
| ... | @@ -20,14 +20,27 @@ import com.google.common.annotations.Beta; | ... | @@ -20,14 +20,27 @@ import com.google.common.annotations.Beta; |
| 20 | /** | 20 | /** |
| 21 | * The context of a objective that will become the subject of | 21 | * The context of a objective that will become the subject of |
| 22 | * the notification. | 22 | * the notification. |
| 23 | - * | 23 | + * <p> |
| 24 | * Implementations of this class must be serializable. | 24 | * Implementations of this class must be serializable. |
| 25 | + * </p> | ||
| 25 | */ | 26 | */ |
| 26 | @Beta | 27 | @Beta |
| 27 | public interface ObjectiveContext { | 28 | public interface ObjectiveContext { |
| 28 | 29 | ||
| 29 | - default void onSuccess(Objective objective) {} | 30 | + /** |
| 31 | + * Invoked on successful execution of the flow objective. | ||
| 32 | + * | ||
| 33 | + * @param objective objective to execute | ||
| 34 | + */ | ||
| 35 | + default void onSuccess(Objective objective) { | ||
| 36 | + } | ||
| 30 | 37 | ||
| 31 | - default void onError(Objective objective, ObjectiveError error) {} | 38 | + /** |
| 39 | + * Invoked when error is encountered while executing the flow objective. | ||
| 40 | + * | ||
| 41 | + * @param objective objective to execute | ||
| 42 | + */ | ||
| 43 | + default void onError(Objective objective, ObjectiveError error) { | ||
| 44 | + } | ||
| 32 | 45 | ||
| 33 | } | 46 | } | ... | ... |
| ... | @@ -17,9 +17,10 @@ package org.onosproject.net.packet; | ... | @@ -17,9 +17,10 @@ package org.onosproject.net.packet; |
| 17 | 17 | ||
| 18 | import com.google.common.base.MoreObjects; | 18 | import com.google.common.base.MoreObjects; |
| 19 | import org.onosproject.core.ApplicationId; | 19 | import org.onosproject.core.ApplicationId; |
| 20 | -import org.onosproject.net.flow.FlowRule; | ||
| 21 | import org.onosproject.net.flow.TrafficSelector; | 20 | import org.onosproject.net.flow.TrafficSelector; |
| 22 | 21 | ||
| 22 | +import java.util.Objects; | ||
| 23 | + | ||
| 23 | /** | 24 | /** |
| 24 | * Default implementation of a packet request. | 25 | * Default implementation of a packet request. |
| 25 | */ | 26 | */ |
| ... | @@ -27,14 +28,19 @@ public final class DefaultPacketRequest implements PacketRequest { | ... | @@ -27,14 +28,19 @@ public final class DefaultPacketRequest implements PacketRequest { |
| 27 | private final TrafficSelector selector; | 28 | private final TrafficSelector selector; |
| 28 | private final PacketPriority priority; | 29 | private final PacketPriority priority; |
| 29 | private final ApplicationId appId; | 30 | private final ApplicationId appId; |
| 30 | - private final FlowRule.Type tableType; | ||
| 31 | 31 | ||
| 32 | + /** | ||
| 33 | + * Creates a new packet request. | ||
| 34 | + * | ||
| 35 | + * @param selector traffic selector | ||
| 36 | + * @param priority intercept priority | ||
| 37 | + * @param appId application id | ||
| 38 | + */ | ||
| 32 | public DefaultPacketRequest(TrafficSelector selector, PacketPriority priority, | 39 | public DefaultPacketRequest(TrafficSelector selector, PacketPriority priority, |
| 33 | - ApplicationId appId, FlowRule.Type tableType) { | 40 | + ApplicationId appId) { |
| 34 | this.selector = selector; | 41 | this.selector = selector; |
| 35 | this.priority = priority; | 42 | this.priority = priority; |
| 36 | this.appId = appId; | 43 | this.appId = appId; |
| 37 | - this.tableType = tableType; | ||
| 38 | } | 44 | } |
| 39 | 45 | ||
| 40 | public TrafficSelector selector() { | 46 | public TrafficSelector selector() { |
| ... | @@ -49,39 +55,23 @@ public final class DefaultPacketRequest implements PacketRequest { | ... | @@ -49,39 +55,23 @@ public final class DefaultPacketRequest implements PacketRequest { |
| 49 | return appId; | 55 | return appId; |
| 50 | } | 56 | } |
| 51 | 57 | ||
| 52 | - public FlowRule.Type tableType() { | 58 | + @Override |
| 53 | - return tableType; | 59 | + public int hashCode() { |
| 60 | + return Objects.hash(selector, priority, appId); | ||
| 54 | } | 61 | } |
| 55 | 62 | ||
| 56 | @Override | 63 | @Override |
| 57 | - public boolean equals(Object o) { | 64 | + public boolean equals(Object obj) { |
| 58 | - if (this == o) { | 65 | + if (this == obj) { |
| 59 | return true; | 66 | return true; |
| 60 | } | 67 | } |
| 61 | - if (o == null || getClass() != o.getClass()) { | 68 | + if (obj == null || getClass() != obj.getClass()) { |
| 62 | - return false; | ||
| 63 | - } | ||
| 64 | - | ||
| 65 | - DefaultPacketRequest that = (DefaultPacketRequest) o; | ||
| 66 | - | ||
| 67 | - if (priority != that.priority) { | ||
| 68 | - return false; | ||
| 69 | - } | ||
| 70 | - if (!selector.equals(that.selector)) { | ||
| 71 | - return false; | ||
| 72 | - } | ||
| 73 | - if (!tableType.equals(that.tableType)) { | ||
| 74 | return false; | 69 | return false; |
| 75 | } | 70 | } |
| 76 | - | 71 | + final DefaultPacketRequest other = (DefaultPacketRequest) obj; |
| 77 | - return true; | 72 | + return Objects.equals(this.selector, other.selector) |
| 78 | - } | 73 | + && Objects.equals(this.priority, other.priority) |
| 79 | - | 74 | + && Objects.equals(this.appId, other.appId); |
| 80 | - @Override | ||
| 81 | - public int hashCode() { | ||
| 82 | - int result = selector.hashCode(); | ||
| 83 | - result = 31 * result + priority.hashCode(); | ||
| 84 | - return result; | ||
| 85 | } | 75 | } |
| 86 | 76 | ||
| 87 | @Override | 77 | @Override |
| ... | @@ -89,7 +79,6 @@ public final class DefaultPacketRequest implements PacketRequest { | ... | @@ -89,7 +79,6 @@ public final class DefaultPacketRequest implements PacketRequest { |
| 89 | return MoreObjects.toStringHelper(this.getClass()) | 79 | return MoreObjects.toStringHelper(this.getClass()) |
| 90 | .add("selector", selector) | 80 | .add("selector", selector) |
| 91 | .add("priority", priority) | 81 | .add("priority", priority) |
| 92 | - .add("appId", appId) | 82 | + .add("appId", appId).toString(); |
| 93 | - .add("table-type", tableType).toString(); | ||
| 94 | } | 83 | } |
| 95 | } | 84 | } |
| ... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
| ... | @@ -16,7 +16,6 @@ | ... | @@ -16,7 +16,6 @@ |
| 16 | package org.onosproject.net.packet; | 16 | package org.onosproject.net.packet; |
| 17 | 17 | ||
| 18 | import org.onosproject.core.ApplicationId; | 18 | import org.onosproject.core.ApplicationId; |
| 19 | -import org.onosproject.net.flow.FlowRule; | ||
| 20 | import org.onosproject.net.flow.TrafficSelector; | 19 | import org.onosproject.net.flow.TrafficSelector; |
| 21 | 20 | ||
| 22 | /** | 21 | /** |
| ... | @@ -26,26 +25,23 @@ public interface PacketRequest { | ... | @@ -26,26 +25,23 @@ public interface PacketRequest { |
| 26 | 25 | ||
| 27 | /** | 26 | /** |
| 28 | * Obtain the traffic selector. | 27 | * Obtain the traffic selector. |
| 28 | + * | ||
| 29 | * @return a traffic selector | 29 | * @return a traffic selector |
| 30 | */ | 30 | */ |
| 31 | TrafficSelector selector(); | 31 | TrafficSelector selector(); |
| 32 | 32 | ||
| 33 | /** | 33 | /** |
| 34 | * Obtain the priority. | 34 | * Obtain the priority. |
| 35 | + * | ||
| 35 | * @return a PacketPriority | 36 | * @return a PacketPriority |
| 36 | */ | 37 | */ |
| 37 | PacketPriority priority(); | 38 | PacketPriority priority(); |
| 38 | 39 | ||
| 39 | /** | 40 | /** |
| 40 | * Obtain the application id. | 41 | * Obtain the application id. |
| 42 | + * | ||
| 41 | * @return an application id | 43 | * @return an application id |
| 42 | */ | 44 | */ |
| 43 | ApplicationId appId(); | 45 | ApplicationId appId(); |
| 44 | 46 | ||
| 45 | - /** | ||
| 46 | - * Obtain the table type. | ||
| 47 | - * @return a table type | ||
| 48 | - */ | ||
| 49 | - FlowRule.Type tableType(); | ||
| 50 | - | ||
| 51 | } | 47 | } | ... | ... |
| ... | @@ -16,7 +16,6 @@ | ... | @@ -16,7 +16,6 @@ |
| 16 | package org.onosproject.net.packet; | 16 | package org.onosproject.net.packet; |
| 17 | 17 | ||
| 18 | import org.onosproject.core.ApplicationId; | 18 | import org.onosproject.core.ApplicationId; |
| 19 | -import org.onosproject.net.flow.FlowRule; | ||
| 20 | import org.onosproject.net.flow.TrafficSelector; | 19 | import org.onosproject.net.flow.TrafficSelector; |
| 21 | 20 | ||
| 22 | /** | 21 | /** |
| ... | @@ -54,28 +53,21 @@ public interface PacketService { | ... | @@ -54,28 +53,21 @@ public interface PacketService { |
| 54 | * | 53 | * |
| 55 | * @param selector the traffic selector used to match packets | 54 | * @param selector the traffic selector used to match packets |
| 56 | * @param priority the priority of the rule | 55 | * @param priority the priority of the rule |
| 57 | - * @param appId the application ID of the requester | 56 | + * @param appId the application ID of the requester |
| 58 | */ | 57 | */ |
| 59 | void requestPackets(TrafficSelector selector, PacketPriority priority, | 58 | void requestPackets(TrafficSelector selector, PacketPriority priority, |
| 60 | ApplicationId appId); | 59 | ApplicationId appId); |
| 61 | 60 | ||
| 62 | /** | 61 | /** |
| 63 | - * Requests that packets matching the given selector are punted from the | 62 | + * Cancels previous packet requests for packets matching the given |
| 64 | - * dataplane to the controller. Clients of the PacketService should use | 63 | + * selector to be punted from the dataplane to the controller. |
| 65 | - * this call to hint at the tableType in the dataplane valid for the selector. | ||
| 66 | * | 64 | * |
| 67 | * @param selector the traffic selector used to match packets | 65 | * @param selector the traffic selector used to match packets |
| 68 | * @param priority the priority of the rule | 66 | * @param priority the priority of the rule |
| 69 | - * @param appId the application ID of the requester | 67 | + * @param appId the application ID of the requester |
| 70 | - * @param tableType the abstract table Type in the dataplane where flowrules | ||
| 71 | - * should be inserted to punt the selector packets to the | ||
| 72 | - * control plane | ||
| 73 | */ | 68 | */ |
| 74 | - void requestPackets(TrafficSelector selector, PacketPriority priority, | 69 | + void cancelPackets(TrafficSelector selector, PacketPriority priority, |
| 75 | - ApplicationId appId, FlowRule.Type tableType); | 70 | + ApplicationId appId); |
| 76 | - | ||
| 77 | - | ||
| 78 | - // TODO add API to allow applications to revoke requests when they deactivate | ||
| 79 | 71 | ||
| 80 | /** | 72 | /** |
| 81 | * Emits the specified outbound packet onto the network. | 73 | * Emits the specified outbound packet onto the network. | ... | ... |
| ... | @@ -34,16 +34,22 @@ public interface PacketStore extends Store<PacketEvent, PacketStoreDelegate> { | ... | @@ -34,16 +34,22 @@ public interface PacketStore extends Store<PacketEvent, PacketStoreDelegate> { |
| 34 | void emit(OutboundPacket packet); | 34 | void emit(OutboundPacket packet); |
| 35 | 35 | ||
| 36 | /** | 36 | /** |
| 37 | - * Register a request for packets. If the registration | 37 | + * Requests intercept of packets that match the given selector. |
| 38 | - * is successful the manager can proceed, otherwise it should | ||
| 39 | - * consider these packet already available in the system. | ||
| 40 | * | 38 | * |
| 41 | * @param request a packet request | 39 | * @param request a packet request |
| 42 | - * @return a boolean indicating registration state. | 40 | + * @return true if the first time the given selector was requested |
| 43 | */ | 41 | */ |
| 44 | boolean requestPackets(PacketRequest request); | 42 | boolean requestPackets(PacketRequest request); |
| 45 | 43 | ||
| 46 | /** | 44 | /** |
| 45 | + * Cancels intercept of packets that match the given selector. | ||
| 46 | + * | ||
| 47 | + * @param request a packet request | ||
| 48 | + * @return true if there is no other application requesting the given selector | ||
| 49 | + */ | ||
| 50 | + boolean cancelPackets(PacketRequest request); | ||
| 51 | + | ||
| 52 | + /** | ||
| 47 | * Obtains all existing requests in the system. | 53 | * Obtains all existing requests in the system. |
| 48 | * | 54 | * |
| 49 | * @return a set of packet requests | 55 | * @return a set of packet requests | ... | ... |
| 1 | +/* | ||
| 2 | + * Copyright 2015 Open Networking Laboratory | ||
| 3 | + * | ||
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 5 | + * you may not use this file except in compliance with the License. | ||
| 6 | + * You may obtain a copy of the License at | ||
| 7 | + * | ||
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 9 | + * | ||
| 10 | + * Unless required by applicable law or agreed to in writing, software | ||
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 13 | + * See the License for the specific language governing permissions and | ||
| 14 | + * limitations under the License. | ||
| 15 | + */ | ||
| 16 | +package org.onosproject.net.packet; | ||
| 17 | + | ||
| 18 | +import org.onosproject.core.ApplicationId; | ||
| 19 | +import org.onosproject.net.flow.TrafficSelector; | ||
| 20 | + | ||
| 21 | +/** | ||
| 22 | + * Test adapter for packet service. | ||
| 23 | + */ | ||
| 24 | +public class PacketServiceAdapter implements PacketService { | ||
| 25 | + @Override | ||
| 26 | + public void addProcessor(PacketProcessor processor, int priority) { | ||
| 27 | + } | ||
| 28 | + | ||
| 29 | + @Override | ||
| 30 | + public void removeProcessor(PacketProcessor processor) { | ||
| 31 | + } | ||
| 32 | + | ||
| 33 | + @Override | ||
| 34 | + public void requestPackets(TrafficSelector selector, PacketPriority priority, ApplicationId appId) { | ||
| 35 | + } | ||
| 36 | + | ||
| 37 | + @Override | ||
| 38 | + public void cancelPackets(TrafficSelector selector, PacketPriority priority, ApplicationId appId) { | ||
| 39 | + } | ||
| 40 | + | ||
| 41 | + @Override | ||
| 42 | + public void emit(OutboundPacket packet) { | ||
| 43 | + } | ||
| 44 | +} |
| ... | @@ -52,6 +52,11 @@ public class SimplePacketStore | ... | @@ -52,6 +52,11 @@ public class SimplePacketStore |
| 52 | } | 52 | } |
| 53 | 53 | ||
| 54 | @Override | 54 | @Override |
| 55 | + public boolean cancelPackets(PacketRequest request) { | ||
| 56 | + return requests.remove(request); | ||
| 57 | + } | ||
| 58 | + | ||
| 59 | + @Override | ||
| 55 | public Set<PacketRequest> existingRequests() { | 60 | public Set<PacketRequest> existingRequests() { |
| 56 | return Collections.unmodifiableSet(requests); | 61 | return Collections.unmodifiableSet(requests); |
| 57 | } | 62 | } | ... | ... |
| ... | @@ -498,10 +498,10 @@ public class FlowRuleManager | ... | @@ -498,10 +498,10 @@ public class FlowRuleManager |
| 498 | FlowRuleBatchOperation batchOperation = | 498 | FlowRuleBatchOperation batchOperation = |
| 499 | request.asBatchOperation(deviceId); | 499 | request.asBatchOperation(deviceId); |
| 500 | 500 | ||
| 501 | - FlowRuleProvider flowRuleProvider = | 501 | + FlowRuleProvider flowRuleProvider = getProvider(deviceId); |
| 502 | - getProvider(deviceId); | 502 | + if (flowRuleProvider != null) { |
| 503 | - | 503 | + flowRuleProvider.executeBatch(batchOperation); |
| 504 | - flowRuleProvider.executeBatch(batchOperation); | 504 | + } |
| 505 | 505 | ||
| 506 | break; | 506 | break; |
| 507 | 507 | ... | ... |
| ... | @@ -29,10 +29,8 @@ import org.onosproject.net.device.DeviceEvent; | ... | @@ -29,10 +29,8 @@ import org.onosproject.net.device.DeviceEvent; |
| 29 | import org.onosproject.net.device.DeviceListener; | 29 | import org.onosproject.net.device.DeviceListener; |
| 30 | import org.onosproject.net.device.DeviceService; | 30 | import org.onosproject.net.device.DeviceService; |
| 31 | import org.onosproject.net.flow.DefaultTrafficTreatment; | 31 | import org.onosproject.net.flow.DefaultTrafficTreatment; |
| 32 | -import org.onosproject.net.flow.FlowRule; | ||
| 33 | import org.onosproject.net.flow.FlowRuleService; | 32 | import org.onosproject.net.flow.FlowRuleService; |
| 34 | import org.onosproject.net.flow.TrafficSelector; | 33 | import org.onosproject.net.flow.TrafficSelector; |
| 35 | -import org.onosproject.net.flow.TrafficTreatment; | ||
| 36 | import org.onosproject.net.flowobjective.DefaultForwardingObjective; | 34 | import org.onosproject.net.flowobjective.DefaultForwardingObjective; |
| 37 | import org.onosproject.net.flowobjective.FlowObjectiveService; | 35 | import org.onosproject.net.flowobjective.FlowObjectiveService; |
| 38 | import org.onosproject.net.flowobjective.ForwardingObjective; | 36 | import org.onosproject.net.flowobjective.ForwardingObjective; |
| ... | @@ -62,9 +60,9 @@ import java.util.concurrent.ExecutorService; | ... | @@ -62,9 +60,9 @@ import java.util.concurrent.ExecutorService; |
| 62 | import java.util.concurrent.Executors; | 60 | import java.util.concurrent.Executors; |
| 63 | 61 | ||
| 64 | import static com.google.common.base.Preconditions.checkNotNull; | 62 | import static com.google.common.base.Preconditions.checkNotNull; |
| 65 | -import static org.slf4j.LoggerFactory.getLogger; | ||
| 66 | import static org.onlab.util.Tools.groupedThreads; | 63 | import static org.onlab.util.Tools.groupedThreads; |
| 67 | import static org.onosproject.security.AppGuard.checkPermission; | 64 | import static org.onosproject.security.AppGuard.checkPermission; |
| 65 | +import static org.slf4j.LoggerFactory.getLogger; | ||
| 68 | 66 | ||
| 69 | 67 | ||
| 70 | /** | 68 | /** |
| ... | @@ -78,6 +76,10 @@ public class PacketManager | ... | @@ -78,6 +76,10 @@ public class PacketManager |
| 78 | 76 | ||
| 79 | private final Logger log = getLogger(getClass()); | 77 | private final Logger log = getLogger(getClass()); |
| 80 | 78 | ||
| 79 | + private static final String TABLE_TYPE_MSG = | ||
| 80 | + "Table Type cannot be null. For requesting packets without " + | ||
| 81 | + "table hints, use other methods in the packetService API"; | ||
| 82 | + | ||
| 81 | private final PacketStoreDelegate delegate = new InternalStoreDelegate(); | 83 | private final PacketStoreDelegate delegate = new InternalStoreDelegate(); |
| 82 | 84 | ||
| 83 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 85 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| ... | @@ -125,7 +127,6 @@ public class PacketManager | ... | @@ -125,7 +127,6 @@ public class PacketManager |
| 125 | @Override | 127 | @Override |
| 126 | public void addProcessor(PacketProcessor processor, int priority) { | 128 | public void addProcessor(PacketProcessor processor, int priority) { |
| 127 | checkPermission(Permission.PACKET_EVENT); | 129 | checkPermission(Permission.PACKET_EVENT); |
| 128 | - | ||
| 129 | checkNotNull(processor, "Processor cannot be null"); | 130 | checkNotNull(processor, "Processor cannot be null"); |
| 130 | processors.put(priority, processor); | 131 | processors.put(priority, processor); |
| 131 | } | 132 | } |
| ... | @@ -133,7 +134,6 @@ public class PacketManager | ... | @@ -133,7 +134,6 @@ public class PacketManager |
| 133 | @Override | 134 | @Override |
| 134 | public void removeProcessor(PacketProcessor processor) { | 135 | public void removeProcessor(PacketProcessor processor) { |
| 135 | checkPermission(Permission.PACKET_EVENT); | 136 | checkPermission(Permission.PACKET_EVENT); |
| 136 | - | ||
| 137 | checkNotNull(processor, "Processor cannot be null"); | 137 | checkNotNull(processor, "Processor cannot be null"); |
| 138 | processors.values().remove(processor); | 138 | processors.values().remove(processor); |
| 139 | } | 139 | } |
| ... | @@ -142,35 +142,26 @@ public class PacketManager | ... | @@ -142,35 +142,26 @@ public class PacketManager |
| 142 | public void requestPackets(TrafficSelector selector, PacketPriority priority, | 142 | public void requestPackets(TrafficSelector selector, PacketPriority priority, |
| 143 | ApplicationId appId) { | 143 | ApplicationId appId) { |
| 144 | checkPermission(Permission.PACKET_READ); | 144 | checkPermission(Permission.PACKET_READ); |
| 145 | - | ||
| 146 | checkNotNull(selector, "Selector cannot be null"); | 145 | checkNotNull(selector, "Selector cannot be null"); |
| 147 | checkNotNull(appId, "Application ID cannot be null"); | 146 | checkNotNull(appId, "Application ID cannot be null"); |
| 148 | 147 | ||
| 149 | - PacketRequest request = | 148 | + PacketRequest request = new DefaultPacketRequest(selector, priority, appId); |
| 150 | - new DefaultPacketRequest(selector, priority, appId, FlowRule.Type.DEFAULT); | ||
| 151 | - | ||
| 152 | if (store.requestPackets(request)) { | 149 | if (store.requestPackets(request)) { |
| 153 | pushToAllDevices(request); | 150 | pushToAllDevices(request); |
| 154 | } | 151 | } |
| 155 | } | 152 | } |
| 156 | 153 | ||
| 157 | @Override | 154 | @Override |
| 158 | - public void requestPackets(TrafficSelector selector, PacketPriority priority, | 155 | + public void cancelPackets(TrafficSelector selector, PacketPriority priority, |
| 159 | - ApplicationId appId, FlowRule.Type tableType) { | 156 | + ApplicationId appId) { |
| 160 | checkPermission(Permission.PACKET_READ); | 157 | checkPermission(Permission.PACKET_READ); |
| 161 | - | ||
| 162 | checkNotNull(selector, "Selector cannot be null"); | 158 | checkNotNull(selector, "Selector cannot be null"); |
| 163 | checkNotNull(appId, "Application ID cannot be null"); | 159 | checkNotNull(appId, "Application ID cannot be null"); |
| 164 | - checkNotNull(tableType, "Table Type cannot be null. For requesting packets +" | ||
| 165 | - + "without table hints, use other methods in the packetService API"); | ||
| 166 | - | ||
| 167 | - PacketRequest request = | ||
| 168 | - new DefaultPacketRequest(selector, priority, appId, tableType); | ||
| 169 | 160 | ||
| 170 | - if (store.requestPackets(request)) { | 161 | + PacketRequest request = new DefaultPacketRequest(selector, priority, appId); |
| 171 | - pushToAllDevices(request); | 162 | + if (store.cancelPackets(request)) { |
| 163 | + removeFromAllDevices(request); | ||
| 172 | } | 164 | } |
| 173 | - | ||
| 174 | } | 165 | } |
| 175 | 166 | ||
| 176 | /** | 167 | /** |
| ... | @@ -184,9 +175,20 @@ public class PacketManager | ... | @@ -184,9 +175,20 @@ public class PacketManager |
| 184 | } | 175 | } |
| 185 | } | 176 | } |
| 186 | 177 | ||
| 178 | + | ||
| 187 | /** | 179 | /** |
| 188 | - * Pushes flow rules to the device to request packets be sent to the | 180 | + * Removes packet request flow rule from all devices. |
| 189 | - * controller. | 181 | + * |
| 182 | + * @param request the packet request | ||
| 183 | + */ | ||
| 184 | + private void removeFromAllDevices(PacketRequest request) { | ||
| 185 | + for (Device device : deviceService.getDevices()) { | ||
| 186 | + removeRule(device, request); | ||
| 187 | + } | ||
| 188 | + } | ||
| 189 | + | ||
| 190 | + /** | ||
| 191 | + * Pushes packet intercept flow rules to the device. | ||
| 190 | * | 192 | * |
| 191 | * @param device the device to push the rules to | 193 | * @param device the device to push the rules to |
| 192 | * @param request the packet request | 194 | * @param request the packet request |
| ... | @@ -197,37 +199,54 @@ public class PacketManager | ... | @@ -197,37 +199,54 @@ public class PacketManager |
| 197 | return; | 199 | return; |
| 198 | } | 200 | } |
| 199 | 201 | ||
| 200 | - TrafficTreatment treatment = DefaultTrafficTreatment.builder() | 202 | + ForwardingObjective forwarding = createBuilder(request) |
| 201 | - .punt() | ||
| 202 | - .build(); | ||
| 203 | - | ||
| 204 | - ForwardingObjective forwarding = DefaultForwardingObjective.builder() | ||
| 205 | - .withPriority(request.priority().priorityValue()) | ||
| 206 | - .withSelector(request.selector()) | ||
| 207 | - .fromApp(appId) | ||
| 208 | - .withFlag(ForwardingObjective.Flag.VERSATILE) | ||
| 209 | - .withTreatment(treatment) | ||
| 210 | - .makePermanent() | ||
| 211 | .add(new ObjectiveContext() { | 203 | .add(new ObjectiveContext() { |
| 212 | @Override | 204 | @Override |
| 213 | - public void onSuccess(Objective objective) { } | 205 | + public void onError(Objective objective, ObjectiveError error) { |
| 206 | + log.warn("Failed to install packet request {}: {}", request, error); | ||
| 207 | + } | ||
| 208 | + }); | ||
| 209 | + | ||
| 210 | + objectiveService.forward(device.id(), forwarding); | ||
| 211 | + } | ||
| 214 | 212 | ||
| 213 | + /** | ||
| 214 | + * Removes packet intercept flow rules from the device. | ||
| 215 | + * | ||
| 216 | + * @param device the device to remove the rules deom | ||
| 217 | + * @param request the packet request | ||
| 218 | + */ | ||
| 219 | + private void removeRule(Device device, PacketRequest request) { | ||
| 220 | + // Everything is pre-provisioned on ROADMs | ||
| 221 | + if (device.type().equals(Device.Type.ROADM)) { | ||
| 222 | + return; | ||
| 223 | + } | ||
| 224 | + | ||
| 225 | + ForwardingObjective forwarding = createBuilder(request) | ||
| 226 | + .remove(new ObjectiveContext() { | ||
| 215 | @Override | 227 | @Override |
| 216 | public void onError(Objective objective, ObjectiveError error) { | 228 | public void onError(Objective objective, ObjectiveError error) { |
| 217 | - log.warn("Failed to install packet request {}: {}", | 229 | + log.warn("Failed to withdraw packet request {}: {}", request, error); |
| 218 | - request, error); | ||
| 219 | } | 230 | } |
| 220 | }); | 231 | }); |
| 221 | 232 | ||
| 222 | objectiveService.forward(device.id(), forwarding); | 233 | objectiveService.forward(device.id(), forwarding); |
| 223 | } | 234 | } |
| 224 | 235 | ||
| 236 | + private DefaultForwardingObjective.Builder createBuilder(PacketRequest request) { | ||
| 237 | + return DefaultForwardingObjective.builder() | ||
| 238 | + .withPriority(request.priority().priorityValue()) | ||
| 239 | + .withSelector(request.selector()) | ||
| 240 | + .fromApp(appId) | ||
| 241 | + .withFlag(ForwardingObjective.Flag.VERSATILE) | ||
| 242 | + .withTreatment(DefaultTrafficTreatment.builder().punt().build()) | ||
| 243 | + .makePermanent(); | ||
| 244 | + } | ||
| 245 | + | ||
| 225 | @Override | 246 | @Override |
| 226 | public void emit(OutboundPacket packet) { | 247 | public void emit(OutboundPacket packet) { |
| 227 | checkPermission(Permission.PACKET_WRITE); | 248 | checkPermission(Permission.PACKET_WRITE); |
| 228 | - | ||
| 229 | checkNotNull(packet, "Packet cannot be null"); | 249 | checkNotNull(packet, "Packet cannot be null"); |
| 230 | - | ||
| 231 | store.emit(packet); | 250 | store.emit(packet); |
| 232 | } | 251 | } |
| 233 | 252 | ||
| ... | @@ -238,8 +257,7 @@ public class PacketManager | ... | @@ -238,8 +257,7 @@ public class PacketManager |
| 238 | return; | 257 | return; |
| 239 | } | 258 | } |
| 240 | 259 | ||
| 241 | - final PacketProvider packetProvider = getProvider(device.providerId()); | 260 | + PacketProvider packetProvider = getProvider(device.providerId()); |
| 242 | - | ||
| 243 | if (packetProvider != null) { | 261 | if (packetProvider != null) { |
| 244 | packetProvider.emit(packet); | 262 | packetProvider.emit(packet); |
| 245 | } | 263 | } |
| ... | @@ -250,7 +268,7 @@ public class PacketManager | ... | @@ -250,7 +268,7 @@ public class PacketManager |
| 250 | return new InternalPacketProviderService(provider); | 268 | return new InternalPacketProviderService(provider); |
| 251 | } | 269 | } |
| 252 | 270 | ||
| 253 | - // Personalized link provider service issued to the supplied provider. | 271 | + // Personalized packet provider service issued to the supplied provider. |
| 254 | private class InternalPacketProviderService | 272 | private class InternalPacketProviderService |
| 255 | extends AbstractProviderService<PacketProvider> | 273 | extends AbstractProviderService<PacketProvider> |
| 256 | implements PacketProviderService { | 274 | implements PacketProviderService { | ... | ... |
| ... | @@ -15,20 +15,9 @@ | ... | @@ -15,20 +15,9 @@ |
| 15 | */ | 15 | */ |
| 16 | package org.onosproject.net.host.impl; | 16 | package org.onosproject.net.host.impl; |
| 17 | 17 | ||
| 18 | -import static org.easymock.EasyMock.createMock; | 18 | +import com.google.common.collect.HashMultimap; |
| 19 | -import static org.easymock.EasyMock.expect; | 19 | +import com.google.common.collect.Lists; |
| 20 | -import static org.easymock.EasyMock.expectLastCall; | 20 | +import com.google.common.collect.Multimap; |
| 21 | -import static org.easymock.EasyMock.replay; | ||
| 22 | -import static org.easymock.EasyMock.verify; | ||
| 23 | -import static org.junit.Assert.assertArrayEquals; | ||
| 24 | -import static org.junit.Assert.assertEquals; | ||
| 25 | -import static org.junit.Assert.assertTrue; | ||
| 26 | - | ||
| 27 | -import java.util.ArrayList; | ||
| 28 | -import java.util.Collections; | ||
| 29 | -import java.util.List; | ||
| 30 | -import java.util.Set; | ||
| 31 | - | ||
| 32 | import org.junit.After; | 21 | import org.junit.After; |
| 33 | import org.junit.Test; | 22 | import org.junit.Test; |
| 34 | import org.onlab.packet.ARP; | 23 | import org.onlab.packet.ARP; |
| ... | @@ -36,7 +25,6 @@ import org.onlab.packet.Ethernet; | ... | @@ -36,7 +25,6 @@ import org.onlab.packet.Ethernet; |
| 36 | import org.onlab.packet.IpAddress; | 25 | import org.onlab.packet.IpAddress; |
| 37 | import org.onlab.packet.IpPrefix; | 26 | import org.onlab.packet.IpPrefix; |
| 38 | import org.onlab.packet.MacAddress; | 27 | import org.onlab.packet.MacAddress; |
| 39 | -import org.onosproject.core.ApplicationId; | ||
| 40 | import org.onlab.packet.VlanId; | 28 | import org.onlab.packet.VlanId; |
| 41 | import org.onosproject.net.ConnectPoint; | 29 | import org.onosproject.net.ConnectPoint; |
| 42 | import org.onosproject.net.Device; | 30 | import org.onosproject.net.Device; |
| ... | @@ -47,31 +35,31 @@ import org.onosproject.net.Port; | ... | @@ -47,31 +35,31 @@ import org.onosproject.net.Port; |
| 47 | import org.onosproject.net.PortNumber; | 35 | import org.onosproject.net.PortNumber; |
| 48 | import org.onosproject.net.device.DeviceListener; | 36 | import org.onosproject.net.device.DeviceListener; |
| 49 | import org.onosproject.net.device.DeviceServiceAdapter; | 37 | import org.onosproject.net.device.DeviceServiceAdapter; |
| 50 | -import org.onosproject.net.flow.FlowRule; | ||
| 51 | -import org.onosproject.net.flow.TrafficSelector; | ||
| 52 | import org.onosproject.net.flow.instructions.Instruction; | 38 | import org.onosproject.net.flow.instructions.Instruction; |
| 53 | import org.onosproject.net.flow.instructions.Instructions.OutputInstruction; | 39 | import org.onosproject.net.flow.instructions.Instructions.OutputInstruction; |
| 54 | import org.onosproject.net.host.HostProvider; | 40 | import org.onosproject.net.host.HostProvider; |
| 55 | import org.onosproject.net.host.InterfaceIpAddress; | 41 | import org.onosproject.net.host.InterfaceIpAddress; |
| 56 | import org.onosproject.net.host.PortAddresses; | 42 | import org.onosproject.net.host.PortAddresses; |
| 57 | import org.onosproject.net.packet.OutboundPacket; | 43 | import org.onosproject.net.packet.OutboundPacket; |
| 58 | -import org.onosproject.net.packet.PacketPriority; | 44 | +import org.onosproject.net.packet.PacketServiceAdapter; |
| 59 | -import org.onosproject.net.packet.PacketProcessor; | ||
| 60 | -import org.onosproject.net.packet.PacketService; | ||
| 61 | import org.onosproject.net.provider.ProviderId; | 45 | import org.onosproject.net.provider.ProviderId; |
| 62 | 46 | ||
| 63 | -import com.google.common.collect.HashMultimap; | 47 | +import java.util.ArrayList; |
| 64 | -import com.google.common.collect.Lists; | 48 | +import java.util.Collections; |
| 65 | -import com.google.common.collect.Multimap; | 49 | +import java.util.List; |
| 50 | +import java.util.Set; | ||
| 51 | + | ||
| 52 | +import static org.easymock.EasyMock.*; | ||
| 53 | +import static org.junit.Assert.*; | ||
| 66 | 54 | ||
| 67 | public class HostMonitorTest { | 55 | public class HostMonitorTest { |
| 68 | 56 | ||
| 69 | private static final IpAddress TARGET_IP_ADDR = | 57 | private static final IpAddress TARGET_IP_ADDR = |
| 70 | - IpAddress.valueOf("10.0.0.1"); | 58 | + IpAddress.valueOf("10.0.0.1"); |
| 71 | private static final IpAddress SOURCE_ADDR = | 59 | private static final IpAddress SOURCE_ADDR = |
| 72 | - IpAddress.valueOf("10.0.0.99"); | 60 | + IpAddress.valueOf("10.0.0.99"); |
| 73 | private static final InterfaceIpAddress IA1 = | 61 | private static final InterfaceIpAddress IA1 = |
| 74 | - new InterfaceIpAddress(SOURCE_ADDR, IpPrefix.valueOf("10.0.0.0/24")); | 62 | + new InterfaceIpAddress(SOURCE_ADDR, IpPrefix.valueOf("10.0.0.0/24")); |
| 75 | private MacAddress sourceMac = MacAddress.valueOf(1L); | 63 | private MacAddress sourceMac = MacAddress.valueOf(1L); |
| 76 | 64 | ||
| 77 | private HostMonitor hostMonitor; | 65 | private HostMonitor hostMonitor; |
| ... | @@ -132,7 +120,7 @@ public class HostMonitorTest { | ... | @@ -132,7 +120,7 @@ public class HostMonitorTest { |
| 132 | 120 | ||
| 133 | ConnectPoint cp = new ConnectPoint(devId, portNum); | 121 | ConnectPoint cp = new ConnectPoint(devId, portNum); |
| 134 | PortAddresses pa = | 122 | PortAddresses pa = |
| 135 | - new PortAddresses(cp, Collections.singleton(IA1), sourceMac, VlanId.NONE); | 123 | + new PortAddresses(cp, Collections.singleton(IA1), sourceMac, VlanId.NONE); |
| 136 | 124 | ||
| 137 | expect(hostManager.getHostsByIp(TARGET_IP_ADDR)) | 125 | expect(hostManager.getHostsByIp(TARGET_IP_ADDR)) |
| 138 | .andReturn(Collections.<Host>emptySet()).anyTimes(); | 126 | .andReturn(Collections.<Host>emptySet()).anyTimes(); |
| ... | @@ -200,8 +188,8 @@ public class HostMonitorTest { | ... | @@ -200,8 +188,8 @@ public class HostMonitorTest { |
| 200 | 188 | ||
| 201 | ConnectPoint cp = new ConnectPoint(devId, portNum); | 189 | ConnectPoint cp = new ConnectPoint(devId, portNum); |
| 202 | PortAddresses pa = | 190 | PortAddresses pa = |
| 203 | - new PortAddresses(cp, Collections.singleton(IA1), sourceMac, | 191 | + new PortAddresses(cp, Collections.singleton(IA1), sourceMac, |
| 204 | - VlanId.vlanId(vlan)); | 192 | + VlanId.vlanId(vlan)); |
| 205 | 193 | ||
| 206 | expect(hostManager.getHostsByIp(TARGET_IP_ADDR)) | 194 | expect(hostManager.getHostsByIp(TARGET_IP_ADDR)) |
| 207 | .andReturn(Collections.<Host>emptySet()).anyTimes(); | 195 | .andReturn(Collections.<Host>emptySet()).anyTimes(); |
| ... | @@ -246,33 +234,14 @@ public class HostMonitorTest { | ... | @@ -246,33 +234,14 @@ public class HostMonitorTest { |
| 246 | arp.getTargetProtocolAddress()); | 234 | arp.getTargetProtocolAddress()); |
| 247 | } | 235 | } |
| 248 | 236 | ||
| 249 | - class TestPacketService implements PacketService { | 237 | + class TestPacketService extends PacketServiceAdapter { |
| 250 | 238 | ||
| 251 | List<OutboundPacket> packets = new ArrayList<>(); | 239 | List<OutboundPacket> packets = new ArrayList<>(); |
| 252 | 240 | ||
| 253 | @Override | 241 | @Override |
| 254 | - public void addProcessor(PacketProcessor processor, int priority) { | ||
| 255 | - } | ||
| 256 | - | ||
| 257 | - @Override | ||
| 258 | - public void removeProcessor(PacketProcessor processor) { | ||
| 259 | - } | ||
| 260 | - | ||
| 261 | - @Override | ||
| 262 | public void emit(OutboundPacket packet) { | 242 | public void emit(OutboundPacket packet) { |
| 263 | packets.add(packet); | 243 | packets.add(packet); |
| 264 | } | 244 | } |
| 265 | - | ||
| 266 | - @Override | ||
| 267 | - public void requestPackets(TrafficSelector selector, | ||
| 268 | - PacketPriority priority, ApplicationId appId) { | ||
| 269 | - } | ||
| 270 | - | ||
| 271 | - @Override | ||
| 272 | - public void requestPackets(TrafficSelector selector, | ||
| 273 | - PacketPriority priority, ApplicationId appId, | ||
| 274 | - FlowRule.Type tableType) { | ||
| 275 | - } | ||
| 276 | } | 245 | } |
| 277 | 246 | ||
| 278 | class TestDeviceService extends DeviceServiceAdapter { | 247 | class TestDeviceService extends DeviceServiceAdapter { | ... | ... |
| ... | @@ -15,21 +15,7 @@ | ... | @@ -15,21 +15,7 @@ |
| 15 | */ | 15 | */ |
| 16 | package org.onosproject.net.proxyarp.impl; | 16 | package org.onosproject.net.proxyarp.impl; |
| 17 | 17 | ||
| 18 | -import static org.easymock.EasyMock.anyObject; | 18 | +import com.google.common.collect.Sets; |
| 19 | -import static org.easymock.EasyMock.createMock; | ||
| 20 | -import static org.easymock.EasyMock.expect; | ||
| 21 | -import static org.easymock.EasyMock.replay; | ||
| 22 | -import static org.junit.Assert.assertArrayEquals; | ||
| 23 | -import static org.junit.Assert.assertEquals; | ||
| 24 | -import static org.junit.Assert.assertFalse; | ||
| 25 | -import static org.junit.Assert.assertTrue; | ||
| 26 | - | ||
| 27 | -import java.util.ArrayList; | ||
| 28 | -import java.util.Collections; | ||
| 29 | -import java.util.Comparator; | ||
| 30 | -import java.util.List; | ||
| 31 | -import java.util.Set; | ||
| 32 | - | ||
| 33 | import org.junit.Before; | 19 | import org.junit.Before; |
| 34 | import org.junit.Test; | 20 | import org.junit.Test; |
| 35 | import org.onlab.packet.ARP; | 21 | import org.onlab.packet.ARP; |
| ... | @@ -38,7 +24,6 @@ import org.onlab.packet.Ip4Address; | ... | @@ -38,7 +24,6 @@ import org.onlab.packet.Ip4Address; |
| 38 | import org.onlab.packet.Ip4Prefix; | 24 | import org.onlab.packet.Ip4Prefix; |
| 39 | import org.onlab.packet.MacAddress; | 25 | import org.onlab.packet.MacAddress; |
| 40 | import org.onlab.packet.VlanId; | 26 | import org.onlab.packet.VlanId; |
| 41 | -import org.onosproject.core.ApplicationId; | ||
| 42 | import org.onosproject.net.ConnectPoint; | 27 | import org.onosproject.net.ConnectPoint; |
| 43 | import org.onosproject.net.DefaultHost; | 28 | import org.onosproject.net.DefaultHost; |
| 44 | import org.onosproject.net.Device; | 29 | import org.onosproject.net.Device; |
| ... | @@ -51,8 +36,6 @@ import org.onosproject.net.Port; | ... | @@ -51,8 +36,6 @@ import org.onosproject.net.Port; |
| 51 | import org.onosproject.net.PortNumber; | 36 | import org.onosproject.net.PortNumber; |
| 52 | import org.onosproject.net.device.DeviceListener; | 37 | import org.onosproject.net.device.DeviceListener; |
| 53 | import org.onosproject.net.device.DeviceService; | 38 | import org.onosproject.net.device.DeviceService; |
| 54 | -import org.onosproject.net.flow.FlowRule; | ||
| 55 | -import org.onosproject.net.flow.TrafficSelector; | ||
| 56 | import org.onosproject.net.flow.instructions.Instruction; | 39 | import org.onosproject.net.flow.instructions.Instruction; |
| 57 | import org.onosproject.net.flow.instructions.Instructions.OutputInstruction; | 40 | import org.onosproject.net.flow.instructions.Instructions.OutputInstruction; |
| 58 | import org.onosproject.net.host.HostService; | 41 | import org.onosproject.net.host.HostService; |
| ... | @@ -61,12 +44,17 @@ import org.onosproject.net.host.PortAddresses; | ... | @@ -61,12 +44,17 @@ import org.onosproject.net.host.PortAddresses; |
| 61 | import org.onosproject.net.link.LinkListener; | 44 | import org.onosproject.net.link.LinkListener; |
| 62 | import org.onosproject.net.link.LinkService; | 45 | import org.onosproject.net.link.LinkService; |
| 63 | import org.onosproject.net.packet.OutboundPacket; | 46 | import org.onosproject.net.packet.OutboundPacket; |
| 64 | -import org.onosproject.net.packet.PacketPriority; | 47 | +import org.onosproject.net.packet.PacketServiceAdapter; |
| 65 | -import org.onosproject.net.packet.PacketProcessor; | ||
| 66 | -import org.onosproject.net.packet.PacketService; | ||
| 67 | import org.onosproject.net.provider.ProviderId; | 48 | import org.onosproject.net.provider.ProviderId; |
| 68 | 49 | ||
| 69 | -import com.google.common.collect.Sets; | 50 | +import java.util.ArrayList; |
| 51 | +import java.util.Collections; | ||
| 52 | +import java.util.Comparator; | ||
| 53 | +import java.util.List; | ||
| 54 | +import java.util.Set; | ||
| 55 | + | ||
| 56 | +import static org.easymock.EasyMock.*; | ||
| 57 | +import static org.junit.Assert.*; | ||
| 70 | 58 | ||
| 71 | /** | 59 | /** |
| 72 | * Tests for the {@link ProxyArpManager} class. | 60 | * Tests for the {@link ProxyArpManager} class. |
| ... | @@ -208,17 +196,17 @@ public class ProxyArpManagerTest { | ... | @@ -208,17 +196,17 @@ public class ProxyArpManagerTest { |
| 208 | for (int i = 1; i <= NUM_ADDRESS_PORTS; i++) { | 196 | for (int i = 1; i <= NUM_ADDRESS_PORTS; i++) { |
| 209 | ConnectPoint cp = new ConnectPoint(getDeviceId(i), P1); | 197 | ConnectPoint cp = new ConnectPoint(getDeviceId(i), P1); |
| 210 | Ip4Prefix prefix1 = | 198 | Ip4Prefix prefix1 = |
| 211 | - Ip4Prefix.valueOf("10.0." + (2 * i - 1) + ".0/24"); | 199 | + Ip4Prefix.valueOf("10.0." + (2 * i - 1) + ".0/24"); |
| 212 | Ip4Address addr1 = | 200 | Ip4Address addr1 = |
| 213 | - Ip4Address.valueOf("10.0." + (2 * i - 1) + ".1"); | 201 | + Ip4Address.valueOf("10.0." + (2 * i - 1) + ".1"); |
| 214 | Ip4Prefix prefix2 = Ip4Prefix.valueOf("10.0." + (2 * i) + ".0/24"); | 202 | Ip4Prefix prefix2 = Ip4Prefix.valueOf("10.0." + (2 * i) + ".0/24"); |
| 215 | Ip4Address addr2 = Ip4Address.valueOf("10.0." + (2 * i) + ".1"); | 203 | Ip4Address addr2 = Ip4Address.valueOf("10.0." + (2 * i) + ".1"); |
| 216 | InterfaceIpAddress ia1 = new InterfaceIpAddress(addr1, prefix1); | 204 | InterfaceIpAddress ia1 = new InterfaceIpAddress(addr1, prefix1); |
| 217 | InterfaceIpAddress ia2 = new InterfaceIpAddress(addr2, prefix2); | 205 | InterfaceIpAddress ia2 = new InterfaceIpAddress(addr2, prefix2); |
| 218 | PortAddresses pa1 = | 206 | PortAddresses pa1 = |
| 219 | - new PortAddresses(cp, Sets.newHashSet(ia1), | 207 | + new PortAddresses(cp, Sets.newHashSet(ia1), |
| 220 | - MacAddress.valueOf(2 * i - 1), | 208 | + MacAddress.valueOf(2 * i - 1), |
| 221 | - VlanId.vlanId((short) 1)); | 209 | + VlanId.vlanId((short) 1)); |
| 222 | PortAddresses pa2 = | 210 | PortAddresses pa2 = |
| 223 | new PortAddresses(cp, Sets.newHashSet(ia2), | 211 | new PortAddresses(cp, Sets.newHashSet(ia2), |
| 224 | MacAddress.valueOf(2 * i), | 212 | MacAddress.valueOf(2 * i), |
| ... | @@ -235,7 +223,7 @@ public class ProxyArpManagerTest { | ... | @@ -235,7 +223,7 @@ public class ProxyArpManagerTest { |
| 235 | 223 | ||
| 236 | for (int i = 1; i <= NUM_FLOOD_PORTS; i++) { | 224 | for (int i = 1; i <= NUM_FLOOD_PORTS; i++) { |
| 237 | ConnectPoint cp = new ConnectPoint(getDeviceId(i + NUM_ADDRESS_PORTS), | 225 | ConnectPoint cp = new ConnectPoint(getDeviceId(i + NUM_ADDRESS_PORTS), |
| 238 | - P1); | 226 | + P1); |
| 239 | expect(hostService.getAddressBindingsForPort(cp)) | 227 | expect(hostService.getAddressBindingsForPort(cp)) |
| 240 | .andReturn(Collections.<PortAddresses>emptySet()).anyTimes(); | 228 | .andReturn(Collections.<PortAddresses>emptySet()).anyTimes(); |
| 241 | } | 229 | } |
| ... | @@ -279,13 +267,13 @@ public class ProxyArpManagerTest { | ... | @@ -279,13 +267,13 @@ public class ProxyArpManagerTest { |
| 279 | @Test | 267 | @Test |
| 280 | public void testReplyKnown() { | 268 | public void testReplyKnown() { |
| 281 | Host replyer = new DefaultHost(PID, HID1, MAC1, VLAN1, getLocation(4), | 269 | Host replyer = new DefaultHost(PID, HID1, MAC1, VLAN1, getLocation(4), |
| 282 | - Collections.singleton(IP1)); | 270 | + Collections.singleton(IP1)); |
| 283 | 271 | ||
| 284 | Host requestor = new DefaultHost(PID, HID2, MAC2, VLAN1, getLocation(5), | 272 | Host requestor = new DefaultHost(PID, HID2, MAC2, VLAN1, getLocation(5), |
| 285 | - Collections.singleton(IP2)); | 273 | + Collections.singleton(IP2)); |
| 286 | 274 | ||
| 287 | expect(hostService.getHostsByIp(IP1)) | 275 | expect(hostService.getHostsByIp(IP1)) |
| 288 | - .andReturn(Collections.singleton(replyer)); | 276 | + .andReturn(Collections.singleton(replyer)); |
| 289 | expect(hostService.getHost(HID2)).andReturn(requestor); | 277 | expect(hostService.getHost(HID2)).andReturn(requestor); |
| 290 | 278 | ||
| 291 | replay(hostService); | 279 | replay(hostService); |
| ... | @@ -307,7 +295,7 @@ public class ProxyArpManagerTest { | ... | @@ -307,7 +295,7 @@ public class ProxyArpManagerTest { |
| 307 | @Test | 295 | @Test |
| 308 | public void testReplyUnknown() { | 296 | public void testReplyUnknown() { |
| 309 | Host requestor = new DefaultHost(PID, HID2, MAC2, VLAN1, getLocation(5), | 297 | Host requestor = new DefaultHost(PID, HID2, MAC2, VLAN1, getLocation(5), |
| 310 | - Collections.singleton(IP2)); | 298 | + Collections.singleton(IP2)); |
| 311 | 299 | ||
| 312 | expect(hostService.getHostsByIp(IP1)) | 300 | expect(hostService.getHostsByIp(IP1)) |
| 313 | .andReturn(Collections.<Host>emptySet()); | 301 | .andReturn(Collections.<Host>emptySet()); |
| ... | @@ -331,10 +319,10 @@ public class ProxyArpManagerTest { | ... | @@ -331,10 +319,10 @@ public class ProxyArpManagerTest { |
| 331 | @Test | 319 | @Test |
| 332 | public void testReplyDifferentVlan() { | 320 | public void testReplyDifferentVlan() { |
| 333 | Host replyer = new DefaultHost(PID, HID1, MAC1, VLAN2, getLocation(4), | 321 | Host replyer = new DefaultHost(PID, HID1, MAC1, VLAN2, getLocation(4), |
| 334 | - Collections.singleton(IP1)); | 322 | + Collections.singleton(IP1)); |
| 335 | 323 | ||
| 336 | Host requestor = new DefaultHost(PID, HID2, MAC2, VLAN1, getLocation(5), | 324 | Host requestor = new DefaultHost(PID, HID2, MAC2, VLAN1, getLocation(5), |
| 337 | - Collections.singleton(IP2)); | 325 | + Collections.singleton(IP2)); |
| 338 | 326 | ||
| 339 | expect(hostService.getHostsByIp(IP1)) | 327 | expect(hostService.getHostsByIp(IP1)) |
| 340 | .andReturn(Collections.singleton(replyer)); | 328 | .andReturn(Collections.singleton(replyer)); |
| ... | @@ -358,7 +346,7 @@ public class ProxyArpManagerTest { | ... | @@ -358,7 +346,7 @@ public class ProxyArpManagerTest { |
| 358 | MacAddress secondMac = MacAddress.valueOf(2L); | 346 | MacAddress secondMac = MacAddress.valueOf(2L); |
| 359 | 347 | ||
| 360 | Host requestor = new DefaultHost(PID, HID2, MAC2, VLAN1, LOC1, | 348 | Host requestor = new DefaultHost(PID, HID2, MAC2, VLAN1, LOC1, |
| 361 | - Collections.singleton(theirIp)); | 349 | + Collections.singleton(theirIp)); |
| 362 | 350 | ||
| 363 | expect(hostService.getHost(HID2)).andReturn(requestor); | 351 | expect(hostService.getHost(HID2)).andReturn(requestor); |
| 364 | replay(hostService); | 352 | replay(hostService); |
| ... | @@ -390,7 +378,7 @@ public class ProxyArpManagerTest { | ... | @@ -390,7 +378,7 @@ public class ProxyArpManagerTest { |
| 390 | 378 | ||
| 391 | // Request for a valid external IP address but coming in the wrong port | 379 | // Request for a valid external IP address but coming in the wrong port |
| 392 | Ethernet arpRequest = buildArp(ARP.OP_REQUEST, MAC1, null, theirIp, | 380 | Ethernet arpRequest = buildArp(ARP.OP_REQUEST, MAC1, null, theirIp, |
| 393 | - Ip4Address.valueOf("10.0.3.1")); | 381 | + Ip4Address.valueOf("10.0.3.1")); |
| 394 | proxyArp.reply(arpRequest, LOC1); | 382 | proxyArp.reply(arpRequest, LOC1); |
| 395 | assertEquals(0, packetService.packets.size()); | 383 | assertEquals(0, packetService.packets.size()); |
| 396 | 384 | ||
| ... | @@ -433,7 +421,7 @@ public class ProxyArpManagerTest { | ... | @@ -433,7 +421,7 @@ public class ProxyArpManagerTest { |
| 433 | @Test | 421 | @Test |
| 434 | public void testForwardToHost() { | 422 | public void testForwardToHost() { |
| 435 | Host host1 = new DefaultHost(PID, HID1, MAC1, VLAN1, LOC1, | 423 | Host host1 = new DefaultHost(PID, HID1, MAC1, VLAN1, LOC1, |
| 436 | - Collections.singleton(IP1)); | 424 | + Collections.singleton(IP1)); |
| 437 | 425 | ||
| 438 | expect(hostService.getHost(HID1)).andReturn(host1); | 426 | expect(hostService.getHost(HID1)).andReturn(host1); |
| 439 | replay(hostService); | 427 | replay(hostService); |
| ... | @@ -476,17 +464,17 @@ public class ProxyArpManagerTest { | ... | @@ -476,17 +464,17 @@ public class ProxyArpManagerTest { |
| 476 | assertEquals(NUM_FLOOD_PORTS - 1, packetService.packets.size()); | 464 | assertEquals(NUM_FLOOD_PORTS - 1, packetService.packets.size()); |
| 477 | 465 | ||
| 478 | Collections.sort(packetService.packets, | 466 | Collections.sort(packetService.packets, |
| 479 | - new Comparator<OutboundPacket>() { | 467 | + new Comparator<OutboundPacket>() { |
| 480 | - @Override | 468 | + @Override |
| 481 | - public int compare(OutboundPacket o1, OutboundPacket o2) { | 469 | + public int compare(OutboundPacket o1, OutboundPacket o2) { |
| 482 | - return o1.sendThrough().uri().compareTo(o2.sendThrough().uri()); | 470 | + return o1.sendThrough().uri().compareTo(o2.sendThrough().uri()); |
| 483 | - } | 471 | + } |
| 484 | - }); | 472 | + }); |
| 485 | 473 | ||
| 486 | 474 | ||
| 487 | for (int i = 0; i < NUM_FLOOD_PORTS - 1; i++) { | 475 | for (int i = 0; i < NUM_FLOOD_PORTS - 1; i++) { |
| 488 | ConnectPoint cp = new ConnectPoint(getDeviceId(NUM_ADDRESS_PORTS + i + 1), | 476 | ConnectPoint cp = new ConnectPoint(getDeviceId(NUM_ADDRESS_PORTS + i + 1), |
| 489 | - PortNumber.portNumber(1)); | 477 | + PortNumber.portNumber(1)); |
| 490 | 478 | ||
| 491 | OutboundPacket outboundPacket = packetService.packets.get(i); | 479 | OutboundPacket outboundPacket = packetService.packets.get(i); |
| 492 | verifyPacketOut(packet, cp, outboundPacket); | 480 | verifyPacketOut(packet, cp, outboundPacket); |
| ... | @@ -497,11 +485,11 @@ public class ProxyArpManagerTest { | ... | @@ -497,11 +485,11 @@ public class ProxyArpManagerTest { |
| 497 | * Verifies the given packet was sent out the given port. | 485 | * Verifies the given packet was sent out the given port. |
| 498 | * | 486 | * |
| 499 | * @param expected the packet that was expected to be sent | 487 | * @param expected the packet that was expected to be sent |
| 500 | - * @param outPort the port the packet was expected to be sent out | 488 | + * @param outPort the port the packet was expected to be sent out |
| 501 | - * @param actual the actual OutboundPacket to verify | 489 | + * @param actual the actual OutboundPacket to verify |
| 502 | */ | 490 | */ |
| 503 | private void verifyPacketOut(Ethernet expected, ConnectPoint outPort, | 491 | private void verifyPacketOut(Ethernet expected, ConnectPoint outPort, |
| 504 | - OutboundPacket actual) { | 492 | + OutboundPacket actual) { |
| 505 | assertArrayEquals(expected.serialize(), actual.data().array()); | 493 | assertArrayEquals(expected.serialize(), actual.data().array()); |
| 506 | assertEquals(1, actual.treatment().immediate().size()); | 494 | assertEquals(1, actual.treatment().immediate().size()); |
| 507 | assertEquals(outPort.deviceId(), actual.sendThrough()); | 495 | assertEquals(outPort.deviceId(), actual.sendThrough()); |
| ... | @@ -530,12 +518,12 @@ public class ProxyArpManagerTest { | ... | @@ -530,12 +518,12 @@ public class ProxyArpManagerTest { |
| 530 | * @param opcode opcode of the ARP packet | 518 | * @param opcode opcode of the ARP packet |
| 531 | * @param srcMac source MAC address | 519 | * @param srcMac source MAC address |
| 532 | * @param dstMac destination MAC address, or null if this is a request | 520 | * @param dstMac destination MAC address, or null if this is a request |
| 533 | - * @param srcIp source IP address | 521 | + * @param srcIp source IP address |
| 534 | - * @param dstIp destination IP address | 522 | + * @param dstIp destination IP address |
| 535 | * @return the ARP packet | 523 | * @return the ARP packet |
| 536 | */ | 524 | */ |
| 537 | private Ethernet buildArp(short opcode, MacAddress srcMac, MacAddress dstMac, | 525 | private Ethernet buildArp(short opcode, MacAddress srcMac, MacAddress dstMac, |
| 538 | - Ip4Address srcIp, Ip4Address dstIp) { | 526 | + Ip4Address srcIp, Ip4Address dstIp) { |
| 539 | Ethernet eth = new Ethernet(); | 527 | Ethernet eth = new Ethernet(); |
| 540 | 528 | ||
| 541 | if (dstMac == null) { | 529 | if (dstMac == null) { |
| ... | @@ -574,32 +562,14 @@ public class ProxyArpManagerTest { | ... | @@ -574,32 +562,14 @@ public class ProxyArpManagerTest { |
| 574 | * Test PacketService implementation that simply stores OutboundPackets | 562 | * Test PacketService implementation that simply stores OutboundPackets |
| 575 | * passed to {@link #emit(OutboundPacket)} for later verification. | 563 | * passed to {@link #emit(OutboundPacket)} for later verification. |
| 576 | */ | 564 | */ |
| 577 | - class TestPacketService implements PacketService { | 565 | + class TestPacketService extends PacketServiceAdapter { |
| 578 | 566 | ||
| 579 | List<OutboundPacket> packets = new ArrayList<>(); | 567 | List<OutboundPacket> packets = new ArrayList<>(); |
| 580 | 568 | ||
| 581 | @Override | 569 | @Override |
| 582 | - public void addProcessor(PacketProcessor processor, int priority) { | ||
| 583 | - } | ||
| 584 | - | ||
| 585 | - @Override | ||
| 586 | - public void removeProcessor(PacketProcessor processor) { | ||
| 587 | - } | ||
| 588 | - | ||
| 589 | - @Override | ||
| 590 | public void emit(OutboundPacket packet) { | 570 | public void emit(OutboundPacket packet) { |
| 591 | packets.add(packet); | 571 | packets.add(packet); |
| 592 | } | 572 | } |
| 593 | 573 | ||
| 594 | - @Override | ||
| 595 | - public void requestPackets(TrafficSelector selector, | ||
| 596 | - PacketPriority priority, ApplicationId appId) { | ||
| 597 | - } | ||
| 598 | - | ||
| 599 | - @Override | ||
| 600 | - public void requestPackets(TrafficSelector selector, | ||
| 601 | - PacketPriority priority, ApplicationId appId, | ||
| 602 | - FlowRule.Type tableType) { | ||
| 603 | - } | ||
| 604 | } | 574 | } |
| 605 | } | 575 | } | ... | ... |
| ... | @@ -15,6 +15,7 @@ | ... | @@ -15,6 +15,7 @@ |
| 15 | */ | 15 | */ |
| 16 | package org.onosproject.store.packet.impl; | 16 | package org.onosproject.store.packet.impl; |
| 17 | 17 | ||
| 18 | +import com.google.common.collect.ImmutableSet; | ||
| 18 | import org.apache.felix.scr.annotations.Activate; | 19 | import org.apache.felix.scr.annotations.Activate; |
| 19 | import org.apache.felix.scr.annotations.Component; | 20 | import org.apache.felix.scr.annotations.Component; |
| 20 | import org.apache.felix.scr.annotations.Deactivate; | 21 | import org.apache.felix.scr.annotations.Deactivate; |
| ... | @@ -25,6 +26,7 @@ import org.onlab.util.KryoNamespace; | ... | @@ -25,6 +26,7 @@ import org.onlab.util.KryoNamespace; |
| 25 | import org.onosproject.cluster.ClusterService; | 26 | import org.onosproject.cluster.ClusterService; |
| 26 | import org.onosproject.cluster.NodeId; | 27 | import org.onosproject.cluster.NodeId; |
| 27 | import org.onosproject.mastership.MastershipService; | 28 | import org.onosproject.mastership.MastershipService; |
| 29 | +import org.onosproject.net.flow.TrafficSelector; | ||
| 28 | import org.onosproject.net.packet.OutboundPacket; | 30 | import org.onosproject.net.packet.OutboundPacket; |
| 29 | import org.onosproject.net.packet.PacketEvent; | 31 | import org.onosproject.net.packet.PacketEvent; |
| 30 | import org.onosproject.net.packet.PacketEvent.Type; | 32 | import org.onosproject.net.packet.PacketEvent.Type; |
| ... | @@ -41,8 +43,10 @@ import org.onosproject.store.serializers.KryoSerializer; | ... | @@ -41,8 +43,10 @@ import org.onosproject.store.serializers.KryoSerializer; |
| 41 | import org.onosproject.store.service.ConsistentMap; | 43 | import org.onosproject.store.service.ConsistentMap; |
| 42 | import org.onosproject.store.service.Serializer; | 44 | import org.onosproject.store.service.Serializer; |
| 43 | import org.onosproject.store.service.StorageService; | 45 | import org.onosproject.store.service.StorageService; |
| 46 | +import org.onosproject.store.service.Versioned; | ||
| 44 | import org.slf4j.Logger; | 47 | import org.slf4j.Logger; |
| 45 | 48 | ||
| 49 | +import java.util.HashSet; | ||
| 46 | import java.util.Set; | 50 | import java.util.Set; |
| 47 | import java.util.concurrent.ExecutorService; | 51 | import java.util.concurrent.ExecutorService; |
| 48 | import java.util.concurrent.Executors; | 52 | import java.util.concurrent.Executors; |
| ... | @@ -96,7 +100,7 @@ public class DistributedPacketStore | ... | @@ -96,7 +100,7 @@ public class DistributedPacketStore |
| 96 | 100 | ||
| 97 | @Activate | 101 | @Activate |
| 98 | public void activate() { | 102 | public void activate() { |
| 99 | - messageHandlingExecutor = Executors.newFixedThreadPool( | 103 | + messageHandlingExecutor = Executors.newFixedThreadPool( |
| 100 | MESSAGE_HANDLER_THREAD_POOL_SIZE, | 104 | MESSAGE_HANDLER_THREAD_POOL_SIZE, |
| 101 | groupedThreads("onos/store/packet", "message-handlers")); | 105 | groupedThreads("onos/store/packet", "message-handlers")); |
| 102 | 106 | ||
| ... | @@ -104,7 +108,7 @@ public class DistributedPacketStore | ... | @@ -104,7 +108,7 @@ public class DistributedPacketStore |
| 104 | new InternalClusterMessageHandler(), | 108 | new InternalClusterMessageHandler(), |
| 105 | messageHandlingExecutor); | 109 | messageHandlingExecutor); |
| 106 | 110 | ||
| 107 | - tracker = new PacketRequestTracker(); | 111 | + tracker = new PacketRequestTracker(); |
| 108 | 112 | ||
| 109 | log.info("Started"); | 113 | log.info("Started"); |
| 110 | } | 114 | } |
| ... | @@ -141,6 +145,11 @@ public class DistributedPacketStore | ... | @@ -141,6 +145,11 @@ public class DistributedPacketStore |
| 141 | } | 145 | } |
| 142 | 146 | ||
| 143 | @Override | 147 | @Override |
| 148 | + public boolean cancelPackets(PacketRequest request) { | ||
| 149 | + return tracker.remove(request); | ||
| 150 | + } | ||
| 151 | + | ||
| 152 | + @Override | ||
| 144 | public Set<PacketRequest> existingRequests() { | 153 | public Set<PacketRequest> existingRequests() { |
| 145 | return tracker.requests(); | 154 | return tracker.requests(); |
| 146 | } | 155 | } |
| ... | @@ -162,47 +171,49 @@ public class DistributedPacketStore | ... | @@ -162,47 +171,49 @@ public class DistributedPacketStore |
| 162 | 171 | ||
| 163 | private class PacketRequestTracker { | 172 | private class PacketRequestTracker { |
| 164 | 173 | ||
| 165 | - private ConsistentMap<PacketRequest, Boolean> requests; | 174 | + private ConsistentMap<TrafficSelector, Set<PacketRequest>> requests; |
| 166 | 175 | ||
| 167 | public PacketRequestTracker() { | 176 | public PacketRequestTracker() { |
| 168 | - requests = storageService.<PacketRequest, Boolean>consistentMapBuilder() | 177 | + requests = storageService.<TrafficSelector, Set<PacketRequest>>consistentMapBuilder() |
| 169 | - .withName("packet-requests") | 178 | + .withName("onos-packet-requests") |
| 170 | .withPartitionsDisabled() | 179 | .withPartitionsDisabled() |
| 171 | - .withSerializer(Serializer.using( | 180 | + .withSerializer(Serializer.using(KryoNamespaces.API)) |
| 172 | - new KryoNamespace.Builder().register(KryoNamespaces.API).build())) | 181 | + .build(); |
| 173 | - .withSerializer(new Serializer() { | ||
| 174 | - KryoNamespace kryo = new KryoNamespace.Builder() | ||
| 175 | - .register(KryoNamespaces.API) | ||
| 176 | - .build(); | ||
| 177 | - | ||
| 178 | - @Override | ||
| 179 | - public <T> byte[] encode(T object) { | ||
| 180 | - return kryo.serialize(object); | ||
| 181 | - } | ||
| 182 | - | ||
| 183 | - @Override | ||
| 184 | - public <T> T decode(byte[] bytes) { | ||
| 185 | - return kryo.deserialize(bytes); | ||
| 186 | - } | ||
| 187 | - }).build(); | ||
| 188 | } | 182 | } |
| 189 | 183 | ||
| 190 | public boolean add(PacketRequest request) { | 184 | public boolean add(PacketRequest request) { |
| 191 | - if (requests.putIfAbsent(request, true) == null) { | 185 | + Versioned<Set<PacketRequest>> old = requests.get(request.selector()); |
| 192 | - return true; | 186 | + if (old != null && old.value().contains(request)) { |
| 187 | + return false; | ||
| 188 | + } | ||
| 189 | + // FIXME: add retry logic using a random delay | ||
| 190 | + Set<PacketRequest> newSet = new HashSet<>(); | ||
| 191 | + newSet.add(request); | ||
| 192 | + if (old == null) { | ||
| 193 | + return requests.putIfAbsent(request.selector(), newSet) == null; | ||
| 193 | } | 194 | } |
| 194 | - return false; | 195 | + newSet.addAll(old.value()); |
| 196 | + return requests.replace(request.selector(), old.version(), newSet); | ||
| 195 | } | 197 | } |
| 196 | 198 | ||
| 197 | public boolean remove(PacketRequest request) { | 199 | public boolean remove(PacketRequest request) { |
| 198 | - if (requests.remove(request) == null) { | 200 | + Versioned<Set<PacketRequest>> old = requests.get(request.selector()); |
| 201 | + if (old == null || !old.value().contains(request)) { | ||
| 199 | return false; | 202 | return false; |
| 200 | } | 203 | } |
| 201 | - return true; | 204 | + // FIXME: add retry logic using a random delay |
| 205 | + Set<PacketRequest> newSet = new HashSet<>(old.value()); | ||
| 206 | + newSet.remove(request); | ||
| 207 | + if (newSet.isEmpty()) { | ||
| 208 | + return requests.remove(request.selector(), old.version()); | ||
| 209 | + } | ||
| 210 | + return requests.replace(request.selector(), old.version(), newSet); | ||
| 202 | } | 211 | } |
| 203 | 212 | ||
| 204 | public Set<PacketRequest> requests() { | 213 | public Set<PacketRequest> requests() { |
| 205 | - return requests.keySet(); | 214 | + ImmutableSet.Builder<PacketRequest> builder = ImmutableSet.builder(); |
| 215 | + requests.values().forEach(v -> builder.addAll(v.value())); | ||
| 216 | + return builder.build(); | ||
| 206 | } | 217 | } |
| 207 | 218 | ||
| 208 | } | 219 | } | ... | ... |
This diff is collapsed. Click to expand it.
| ... | @@ -15,27 +15,7 @@ | ... | @@ -15,27 +15,7 @@ |
| 15 | */ | 15 | */ |
| 16 | package org.onosproject.provider.host.impl; | 16 | package org.onosproject.provider.host.impl; |
| 17 | 17 | ||
| 18 | -import static org.easymock.EasyMock.createMock; | 18 | +import com.google.common.collect.ImmutableSet; |
| 19 | -import static org.easymock.EasyMock.expect; | ||
| 20 | -import static org.easymock.EasyMock.replay; | ||
| 21 | -import static org.junit.Assert.assertEquals; | ||
| 22 | -import static org.junit.Assert.assertNotNull; | ||
| 23 | -import static org.junit.Assert.assertNull; | ||
| 24 | -import static org.onlab.packet.VlanId.vlanId; | ||
| 25 | -import static org.onosproject.net.Device.Type.SWITCH; | ||
| 26 | -import static org.onosproject.net.DeviceId.deviceId; | ||
| 27 | -import static org.onosproject.net.HostId.hostId; | ||
| 28 | -import static org.onosproject.net.PortNumber.portNumber; | ||
| 29 | -import static org.onosproject.net.device.DeviceEvent.Type.DEVICE_AVAILABILITY_CHANGED; | ||
| 30 | -import static org.onosproject.net.device.DeviceEvent.Type.DEVICE_REMOVED; | ||
| 31 | -import static org.onosproject.net.device.DeviceEvent.Type.PORT_UPDATED; | ||
| 32 | - | ||
| 33 | -import java.nio.ByteBuffer; | ||
| 34 | -import java.util.Collections; | ||
| 35 | -import java.util.Dictionary; | ||
| 36 | -import java.util.Hashtable; | ||
| 37 | -import java.util.Set; | ||
| 38 | - | ||
| 39 | import org.junit.After; | 19 | import org.junit.After; |
| 40 | import org.junit.Before; | 20 | import org.junit.Before; |
| 41 | import org.junit.Test; | 21 | import org.junit.Test; |
| ... | @@ -62,8 +42,6 @@ import org.onosproject.net.HostLocation; | ... | @@ -62,8 +42,6 @@ import org.onosproject.net.HostLocation; |
| 62 | import org.onosproject.net.device.DeviceEvent; | 42 | import org.onosproject.net.device.DeviceEvent; |
| 63 | import org.onosproject.net.device.DeviceListener; | 43 | import org.onosproject.net.device.DeviceListener; |
| 64 | import org.onosproject.net.device.DeviceServiceAdapter; | 44 | import org.onosproject.net.device.DeviceServiceAdapter; |
| 65 | -import org.onosproject.net.flow.FlowRule; | ||
| 66 | -import org.onosproject.net.flow.TrafficSelector; | ||
| 67 | import org.onosproject.net.flow.TrafficTreatment; | 45 | import org.onosproject.net.flow.TrafficTreatment; |
| 68 | import org.onosproject.net.host.HostDescription; | 46 | import org.onosproject.net.host.HostDescription; |
| 69 | import org.onosproject.net.host.HostProvider; | 47 | import org.onosproject.net.host.HostProvider; |
| ... | @@ -74,15 +52,27 @@ import org.onosproject.net.packet.DefaultInboundPacket; | ... | @@ -74,15 +52,27 @@ import org.onosproject.net.packet.DefaultInboundPacket; |
| 74 | import org.onosproject.net.packet.InboundPacket; | 52 | import org.onosproject.net.packet.InboundPacket; |
| 75 | import org.onosproject.net.packet.OutboundPacket; | 53 | import org.onosproject.net.packet.OutboundPacket; |
| 76 | import org.onosproject.net.packet.PacketContext; | 54 | import org.onosproject.net.packet.PacketContext; |
| 77 | -import org.onosproject.net.packet.PacketPriority; | ||
| 78 | import org.onosproject.net.packet.PacketProcessor; | 55 | import org.onosproject.net.packet.PacketProcessor; |
| 79 | -import org.onosproject.net.packet.PacketService; | 56 | +import org.onosproject.net.packet.PacketServiceAdapter; |
| 80 | import org.onosproject.net.provider.AbstractProviderService; | 57 | import org.onosproject.net.provider.AbstractProviderService; |
| 81 | import org.onosproject.net.provider.ProviderId; | 58 | import org.onosproject.net.provider.ProviderId; |
| 82 | import org.onosproject.net.topology.Topology; | 59 | import org.onosproject.net.topology.Topology; |
| 83 | import org.onosproject.net.topology.TopologyServiceAdapter; | 60 | import org.onosproject.net.topology.TopologyServiceAdapter; |
| 84 | 61 | ||
| 85 | -import com.google.common.collect.ImmutableSet; | 62 | +import java.nio.ByteBuffer; |
| 63 | +import java.util.Collections; | ||
| 64 | +import java.util.Dictionary; | ||
| 65 | +import java.util.Hashtable; | ||
| 66 | +import java.util.Set; | ||
| 67 | + | ||
| 68 | +import static org.easymock.EasyMock.*; | ||
| 69 | +import static org.junit.Assert.*; | ||
| 70 | +import static org.onlab.packet.VlanId.vlanId; | ||
| 71 | +import static org.onosproject.net.Device.Type.SWITCH; | ||
| 72 | +import static org.onosproject.net.DeviceId.deviceId; | ||
| 73 | +import static org.onosproject.net.HostId.hostId; | ||
| 74 | +import static org.onosproject.net.PortNumber.portNumber; | ||
| 75 | +import static org.onosproject.net.device.DeviceEvent.Type.*; | ||
| 86 | 76 | ||
| 87 | public class HostLocationProviderTest { | 77 | public class HostLocationProviderTest { |
| 88 | 78 | ||
| ... | @@ -143,7 +133,7 @@ public class HostLocationProviderTest { | ... | @@ -143,7 +133,7 @@ public class HostLocationProviderTest { |
| 143 | 133 | ||
| 144 | coreService = createMock(CoreService.class); | 134 | coreService = createMock(CoreService.class); |
| 145 | expect(coreService.registerApplication(appId.name())) | 135 | expect(coreService.registerApplication(appId.name())) |
| 146 | - .andReturn(appId).anyTimes(); | 136 | + .andReturn(appId).anyTimes(); |
| 147 | replay(coreService); | 137 | replay(coreService); |
| 148 | 138 | ||
| 149 | provider.cfgService = new ComponentConfigAdapter(); | 139 | provider.cfgService = new ComponentConfigAdapter(); |
| ... | @@ -271,31 +261,11 @@ public class HostLocationProviderTest { | ... | @@ -271,31 +261,11 @@ public class HostLocationProviderTest { |
| 271 | 261 | ||
| 272 | } | 262 | } |
| 273 | 263 | ||
| 274 | - private class TestPacketService implements PacketService { | 264 | + private class TestPacketService extends PacketServiceAdapter { |
| 275 | - | ||
| 276 | @Override | 265 | @Override |
| 277 | public void addProcessor(PacketProcessor processor, int priority) { | 266 | public void addProcessor(PacketProcessor processor, int priority) { |
| 278 | testProcessor = processor; | 267 | testProcessor = processor; |
| 279 | } | 268 | } |
| 280 | - | ||
| 281 | - @Override | ||
| 282 | - public void removeProcessor(PacketProcessor processor) { | ||
| 283 | - } | ||
| 284 | - | ||
| 285 | - @Override | ||
| 286 | - public void emit(OutboundPacket packet) { | ||
| 287 | - } | ||
| 288 | - | ||
| 289 | - @Override | ||
| 290 | - public void requestPackets(TrafficSelector selector, | ||
| 291 | - PacketPriority priority, ApplicationId appId) { | ||
| 292 | - } | ||
| 293 | - | ||
| 294 | - @Override | ||
| 295 | - public void requestPackets(TrafficSelector selector, | ||
| 296 | - PacketPriority priority, ApplicationId appId, | ||
| 297 | - FlowRule.Type tableType) { | ||
| 298 | - } | ||
| 299 | } | 269 | } |
| 300 | 270 | ||
| 301 | 271 | ... | ... |
| ... | @@ -178,18 +178,20 @@ public class LLDPLinkProvider extends AbstractProvider implements LinkProvider { | ... | @@ -178,18 +178,20 @@ public class LLDPLinkProvider extends AbstractProvider implements LinkProvider { |
| 178 | executor = newSingleThreadScheduledExecutor(groupedThreads("onos/device", "sync-%d")); | 178 | executor = newSingleThreadScheduledExecutor(groupedThreads("onos/device", "sync-%d")); |
| 179 | executor.scheduleAtFixedRate(new SyncDeviceInfoTask(), INIT_DELAY, DELAY, SECONDS); | 179 | executor.scheduleAtFixedRate(new SyncDeviceInfoTask(), INIT_DELAY, DELAY, SECONDS); |
| 180 | 180 | ||
| 181 | - requestPackets(); | 181 | + requestIntercepts(); |
| 182 | 182 | ||
| 183 | log.info("Started"); | 183 | log.info("Started"); |
| 184 | } | 184 | } |
| 185 | 185 | ||
| 186 | @Deactivate | 186 | @Deactivate |
| 187 | public void deactivate() { | 187 | public void deactivate() { |
| 188 | - // TODO revoke all packet requests when deactivate | ||
| 189 | cfgService.unregisterProperties(getClass(), false); | 188 | cfgService.unregisterProperties(getClass(), false); |
| 190 | if (disableLinkDiscovery) { | 189 | if (disableLinkDiscovery) { |
| 191 | return; | 190 | return; |
| 192 | } | 191 | } |
| 192 | + | ||
| 193 | + withdrawIntercepts(); | ||
| 194 | + | ||
| 193 | providerRegistry.unregister(this); | 195 | providerRegistry.unregister(this); |
| 194 | deviceService.removeListener(listener); | 196 | deviceService.removeListener(listener); |
| 195 | packetService.removeProcessor(listener); | 197 | packetService.removeProcessor(listener); |
| ... | @@ -205,7 +207,6 @@ public class LLDPLinkProvider extends AbstractProvider implements LinkProvider { | ... | @@ -205,7 +207,6 @@ public class LLDPLinkProvider extends AbstractProvider implements LinkProvider { |
| 205 | 207 | ||
| 206 | @Modified | 208 | @Modified |
| 207 | public void modified(ComponentContext context) { | 209 | public void modified(ComponentContext context) { |
| 208 | - // TODO revoke unnecessary packet requests when config being modified | ||
| 209 | if (context == null) { | 210 | if (context == null) { |
| 210 | loadSuppressionRules(); | 211 | loadSuppressionRules(); |
| 211 | return; | 212 | return; |
| ... | @@ -225,7 +226,7 @@ public class LLDPLinkProvider extends AbstractProvider implements LinkProvider { | ... | @@ -225,7 +226,7 @@ public class LLDPLinkProvider extends AbstractProvider implements LinkProvider { |
| 225 | if (!Strings.isNullOrEmpty(s)) { | 226 | if (!Strings.isNullOrEmpty(s)) { |
| 226 | lldpSuppression = s; | 227 | lldpSuppression = s; |
| 227 | } | 228 | } |
| 228 | - | 229 | + requestIntercepts(); |
| 229 | loadSuppressionRules(); | 230 | loadSuppressionRules(); |
| 230 | } | 231 | } |
| 231 | 232 | ||
| ... | @@ -246,22 +247,33 @@ public class LLDPLinkProvider extends AbstractProvider implements LinkProvider { | ... | @@ -246,22 +247,33 @@ public class LLDPLinkProvider extends AbstractProvider implements LinkProvider { |
| 246 | } | 247 | } |
| 247 | 248 | ||
| 248 | /** | 249 | /** |
| 249 | - * Request packet in via PacketService. | 250 | + * Request packet intercepts. |
| 250 | */ | 251 | */ |
| 251 | - private void requestPackets() { | 252 | + private void requestIntercepts() { |
| 252 | - TrafficSelector.Builder lldpSelector = DefaultTrafficSelector.builder(); | 253 | + TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); |
| 253 | - lldpSelector.matchEthType(Ethernet.TYPE_LLDP); | 254 | + selector.matchEthType(Ethernet.TYPE_LLDP); |
| 254 | - packetService.requestPackets(lldpSelector.build(), | 255 | + packetService.requestPackets(selector.build(), PacketPriority.CONTROL, appId); |
| 255 | - PacketPriority.CONTROL, appId); | ||
| 256 | 256 | ||
| 257 | + selector.matchEthType(Ethernet.TYPE_BSN); | ||
| 257 | if (useBDDP) { | 258 | if (useBDDP) { |
| 258 | - TrafficSelector.Builder bddpSelector = DefaultTrafficSelector.builder(); | 259 | + packetService.requestPackets(selector.build(), PacketPriority.CONTROL, appId); |
| 259 | - bddpSelector.matchEthType(Ethernet.TYPE_BSN); | 260 | + } else { |
| 260 | - packetService.requestPackets(bddpSelector.build(), | 261 | + packetService.cancelPackets(selector.build(), PacketPriority.CONTROL, appId); |
| 261 | - PacketPriority.CONTROL, appId); | ||
| 262 | } | 262 | } |
| 263 | } | 263 | } |
| 264 | 264 | ||
| 265 | + /** | ||
| 266 | + * Withdraw packet intercepts. | ||
| 267 | + */ | ||
| 268 | + private void withdrawIntercepts() { | ||
| 269 | + TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); | ||
| 270 | + selector.matchEthType(Ethernet.TYPE_LLDP); | ||
| 271 | + packetService.cancelPackets(selector.build(), PacketPriority.CONTROL, appId); | ||
| 272 | + selector.matchEthType(Ethernet.TYPE_BSN); | ||
| 273 | + packetService.cancelPackets(selector.build(), PacketPriority.CONTROL, appId); | ||
| 274 | + } | ||
| 275 | + | ||
| 276 | + | ||
| 265 | private class InternalRoleListener implements MastershipListener { | 277 | private class InternalRoleListener implements MastershipListener { |
| 266 | 278 | ||
| 267 | @Override | 279 | @Override | ... | ... |
| ... | @@ -15,23 +15,9 @@ | ... | @@ -15,23 +15,9 @@ |
| 15 | */ | 15 | */ |
| 16 | package org.onosproject.provider.lldp.impl; | 16 | package org.onosproject.provider.lldp.impl; |
| 17 | 17 | ||
| 18 | -import static org.easymock.EasyMock.createMock; | 18 | +import com.google.common.collect.ArrayListMultimap; |
| 19 | -import static org.easymock.EasyMock.expect; | 19 | +import com.google.common.collect.Lists; |
| 20 | -import static org.easymock.EasyMock.replay; | 20 | +import com.google.common.collect.Maps; |
| 21 | -import static org.junit.Assert.assertEquals; | ||
| 22 | -import static org.junit.Assert.assertFalse; | ||
| 23 | -import static org.junit.Assert.assertNotNull; | ||
| 24 | -import static org.junit.Assert.assertNull; | ||
| 25 | -import static org.junit.Assert.assertTrue; | ||
| 26 | - | ||
| 27 | -import java.nio.ByteBuffer; | ||
| 28 | -import java.util.Collections; | ||
| 29 | -import java.util.HashMap; | ||
| 30 | -import java.util.List; | ||
| 31 | -import java.util.Map; | ||
| 32 | -import java.util.Set; | ||
| 33 | -import java.util.concurrent.CompletableFuture; | ||
| 34 | - | ||
| 35 | import org.junit.After; | 21 | import org.junit.After; |
| 36 | import org.junit.Before; | 22 | import org.junit.Before; |
| 37 | import org.junit.Test; | 23 | import org.junit.Test; |
| ... | @@ -57,8 +43,6 @@ import org.onosproject.net.PortNumber; | ... | @@ -57,8 +43,6 @@ import org.onosproject.net.PortNumber; |
| 57 | import org.onosproject.net.device.DeviceEvent; | 43 | import org.onosproject.net.device.DeviceEvent; |
| 58 | import org.onosproject.net.device.DeviceListener; | 44 | import org.onosproject.net.device.DeviceListener; |
| 59 | import org.onosproject.net.device.DeviceServiceAdapter; | 45 | import org.onosproject.net.device.DeviceServiceAdapter; |
| 60 | -import org.onosproject.net.flow.FlowRule; | ||
| 61 | -import org.onosproject.net.flow.TrafficSelector; | ||
| 62 | import org.onosproject.net.flow.TrafficTreatment; | 46 | import org.onosproject.net.flow.TrafficTreatment; |
| 63 | import org.onosproject.net.link.LinkDescription; | 47 | import org.onosproject.net.link.LinkDescription; |
| 64 | import org.onosproject.net.link.LinkProvider; | 48 | import org.onosproject.net.link.LinkProvider; |
| ... | @@ -68,15 +52,21 @@ import org.onosproject.net.packet.DefaultInboundPacket; | ... | @@ -68,15 +52,21 @@ import org.onosproject.net.packet.DefaultInboundPacket; |
| 68 | import org.onosproject.net.packet.InboundPacket; | 52 | import org.onosproject.net.packet.InboundPacket; |
| 69 | import org.onosproject.net.packet.OutboundPacket; | 53 | import org.onosproject.net.packet.OutboundPacket; |
| 70 | import org.onosproject.net.packet.PacketContext; | 54 | import org.onosproject.net.packet.PacketContext; |
| 71 | -import org.onosproject.net.packet.PacketPriority; | ||
| 72 | import org.onosproject.net.packet.PacketProcessor; | 55 | import org.onosproject.net.packet.PacketProcessor; |
| 73 | -import org.onosproject.net.packet.PacketService; | 56 | +import org.onosproject.net.packet.PacketServiceAdapter; |
| 74 | import org.onosproject.net.provider.AbstractProviderService; | 57 | import org.onosproject.net.provider.AbstractProviderService; |
| 75 | import org.onosproject.net.provider.ProviderId; | 58 | import org.onosproject.net.provider.ProviderId; |
| 76 | 59 | ||
| 77 | -import com.google.common.collect.ArrayListMultimap; | 60 | +import java.nio.ByteBuffer; |
| 78 | -import com.google.common.collect.Lists; | 61 | +import java.util.Collections; |
| 79 | -import com.google.common.collect.Maps; | 62 | +import java.util.HashMap; |
| 63 | +import java.util.List; | ||
| 64 | +import java.util.Map; | ||
| 65 | +import java.util.Set; | ||
| 66 | +import java.util.concurrent.CompletableFuture; | ||
| 67 | + | ||
| 68 | +import static org.easymock.EasyMock.*; | ||
| 69 | +import static org.junit.Assert.*; | ||
| 80 | 70 | ||
| 81 | public class LLDPLinkProviderTest { | 71 | public class LLDPLinkProviderTest { |
| 82 | 72 | ||
| ... | @@ -383,33 +373,11 @@ public class LLDPLinkProviderTest { | ... | @@ -383,33 +373,11 @@ public class LLDPLinkProviderTest { |
| 383 | 373 | ||
| 384 | } | 374 | } |
| 385 | 375 | ||
| 386 | - private class TestPacketService implements PacketService { | 376 | + private class TestPacketService extends PacketServiceAdapter { |
| 387 | - | ||
| 388 | @Override | 377 | @Override |
| 389 | public void addProcessor(PacketProcessor processor, int priority) { | 378 | public void addProcessor(PacketProcessor processor, int priority) { |
| 390 | testProcessor = processor; | 379 | testProcessor = processor; |
| 391 | } | 380 | } |
| 392 | - | ||
| 393 | - @Override | ||
| 394 | - public void removeProcessor(PacketProcessor processor) { | ||
| 395 | - | ||
| 396 | - } | ||
| 397 | - | ||
| 398 | - @Override | ||
| 399 | - public void emit(OutboundPacket packet) { | ||
| 400 | - | ||
| 401 | - } | ||
| 402 | - | ||
| 403 | - @Override | ||
| 404 | - public void requestPackets(TrafficSelector selector, | ||
| 405 | - PacketPriority priority, ApplicationId appId) { | ||
| 406 | - } | ||
| 407 | - | ||
| 408 | - @Override | ||
| 409 | - public void requestPackets(TrafficSelector selector, | ||
| 410 | - PacketPriority priority, ApplicationId appId, | ||
| 411 | - FlowRule.Type tableType) { | ||
| 412 | - } | ||
| 413 | } | 381 | } |
| 414 | 382 | ||
| 415 | private class TestDeviceService extends DeviceServiceAdapter { | 383 | private class TestDeviceService extends DeviceServiceAdapter { |
| ... | @@ -433,8 +401,6 @@ public class LLDPLinkProviderTest { | ... | @@ -433,8 +401,6 @@ public class LLDPLinkProviderTest { |
| 433 | 401 | ||
| 434 | ports.putAll(DID1, Lists.newArrayList(pd1, pd2)); | 402 | ports.putAll(DID1, Lists.newArrayList(pd1, pd2)); |
| 435 | ports.putAll(DID2, Lists.newArrayList(pd3, pd4)); | 403 | ports.putAll(DID2, Lists.newArrayList(pd3, pd4)); |
| 436 | - | ||
| 437 | - | ||
| 438 | } | 404 | } |
| 439 | 405 | ||
| 440 | @Override | 406 | @Override | ... | ... |
-
Please register or login to post a comment