ONOS-2145 Added ability to withdraw packet intercepts via PacketService::cancelPackets.
Change-Id: Ie41271fa02740560bd67b0faf49f633ee749773c
Showing
17 changed files
with
348 additions
and
357 deletions
| ... | @@ -163,15 +163,15 @@ public class ReactiveForwarding { | ... | @@ -163,15 +163,15 @@ public class ReactiveForwarding { |
| 163 | 163 | ||
| 164 | packetService.addProcessor(processor, PacketProcessor.ADVISOR_MAX + 2); | 164 | packetService.addProcessor(processor, PacketProcessor.ADVISOR_MAX + 2); |
| 165 | readComponentConfiguration(context); | 165 | readComponentConfiguration(context); |
| 166 | - requestPackests(); | 166 | + requestIntercepts(); |
| 167 | 167 | ||
| 168 | log.info("Started with Application ID {}", appId.id()); | 168 | log.info("Started with Application ID {}", appId.id()); |
| 169 | } | 169 | } |
| 170 | 170 | ||
| 171 | @Deactivate | 171 | @Deactivate |
| 172 | public void deactivate() { | 172 | public void deactivate() { |
| 173 | - // TODO revoke all packet requests when deactivate | ||
| 174 | cfgService.unregisterProperties(getClass(), false); | 173 | cfgService.unregisterProperties(getClass(), false); |
| 174 | + withdrawIntercepts(); | ||
| 175 | flowRuleService.removeFlowRulesById(appId); | 175 | flowRuleService.removeFlowRulesById(appId); |
| 176 | packetService.removeProcessor(processor); | 176 | packetService.removeProcessor(processor); |
| 177 | processor = null; | 177 | processor = null; |
| ... | @@ -180,31 +180,42 @@ public class ReactiveForwarding { | ... | @@ -180,31 +180,42 @@ public class ReactiveForwarding { |
| 180 | 180 | ||
| 181 | @Modified | 181 | @Modified |
| 182 | public void modified(ComponentContext context) { | 182 | public void modified(ComponentContext context) { |
| 183 | - // TODO revoke unnecessary packet requests when config being modified | ||
| 184 | readComponentConfiguration(context); | 183 | readComponentConfiguration(context); |
| 185 | - requestPackests(); | 184 | + requestIntercepts(); |
| 186 | } | 185 | } |
| 187 | 186 | ||
| 188 | /** | 187 | /** |
| 189 | * Request packet in via PacketService. | 188 | * Request packet in via PacketService. |
| 190 | */ | 189 | */ |
| 191 | - private void requestPackests() { | 190 | + private void requestIntercepts() { |
| 192 | TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); | 191 | TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); |
| 193 | selector.matchEthType(Ethernet.TYPE_IPV4); | 192 | selector.matchEthType(Ethernet.TYPE_IPV4); |
| 194 | - packetService.requestPackets(selector.build(), PacketPriority.REACTIVE, | 193 | + packetService.requestPackets(selector.build(), PacketPriority.REACTIVE, appId); |
| 195 | - appId); | ||
| 196 | selector.matchEthType(Ethernet.TYPE_ARP); | 194 | selector.matchEthType(Ethernet.TYPE_ARP); |
| 197 | - packetService.requestPackets(selector.build(), PacketPriority.REACTIVE, | 195 | + packetService.requestPackets(selector.build(), PacketPriority.REACTIVE, appId); |
| 198 | - appId); | ||
| 199 | 196 | ||
| 200 | - if (ipv6Forwarding) { | ||
| 201 | selector.matchEthType(Ethernet.TYPE_IPV6); | 197 | selector.matchEthType(Ethernet.TYPE_IPV6); |
| 202 | - packetService.requestPackets(selector.build(), | 198 | + if (ipv6Forwarding) { |
| 203 | - PacketPriority.REACTIVE, appId); | 199 | + packetService.requestPackets(selector.build(), PacketPriority.REACTIVE, appId); |
| 200 | + } else { | ||
| 201 | + packetService.cancelPackets(selector.build(), PacketPriority.REACTIVE, appId); | ||
| 204 | } | 202 | } |
| 205 | } | 203 | } |
| 206 | 204 | ||
| 207 | /** | 205 | /** |
| 206 | + * Request packet in via PacketService. | ||
| 207 | + */ | ||
| 208 | + private void withdrawIntercepts() { | ||
| 209 | + TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); | ||
| 210 | + selector.matchEthType(Ethernet.TYPE_IPV4); | ||
| 211 | + packetService.cancelPackets(selector.build(), PacketPriority.REACTIVE, appId); | ||
| 212 | + selector.matchEthType(Ethernet.TYPE_ARP); | ||
| 213 | + packetService.cancelPackets(selector.build(), PacketPriority.REACTIVE, appId); | ||
| 214 | + selector.matchEthType(Ethernet.TYPE_IPV6); | ||
| 215 | + packetService.cancelPackets(selector.build(), PacketPriority.REACTIVE, appId); | ||
| 216 | + } | ||
| 217 | + | ||
| 218 | + /** | ||
| 208 | * Extracts properties from the component configuration context. | 219 | * Extracts properties from the component configuration context. |
| 209 | * | 220 | * |
| 210 | * @param context the component context | 221 | * @param context the component context | ... | ... |
| ... | @@ -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; | 69 | return false; |
| 63 | } | 70 | } |
| 64 | - | 71 | + final DefaultPacketRequest other = (DefaultPacketRequest) obj; |
| 65 | - DefaultPacketRequest that = (DefaultPacketRequest) o; | 72 | + return Objects.equals(this.selector, other.selector) |
| 66 | - | 73 | + && Objects.equals(this.priority, other.priority) |
| 67 | - if (priority != that.priority) { | 74 | + && Objects.equals(this.appId, other.appId); |
| 68 | - return false; | ||
| 69 | - } | ||
| 70 | - if (!selector.equals(that.selector)) { | ||
| 71 | - return false; | ||
| 72 | - } | ||
| 73 | - if (!tableType.equals(that.tableType)) { | ||
| 74 | - return false; | ||
| 75 | - } | ||
| 76 | - | ||
| 77 | - return true; | ||
| 78 | - } | ||
| 79 | - | ||
| 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 | /** |
| ... | @@ -60,22 +59,15 @@ public interface PacketService { | ... | @@ -60,22 +59,15 @@ public interface PacketService { |
| 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 | - | ||
| 504 | flowRuleProvider.executeBatch(batchOperation); | 503 | 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 | 160 | ||
| 167 | - PacketRequest request = | 161 | + PacketRequest request = new DefaultPacketRequest(selector, priority, appId); |
| 168 | - new DefaultPacketRequest(selector, priority, appId, tableType); | 162 | + if (store.cancelPackets(request)) { |
| 169 | - | 163 | + removeFromAllDevices(request); |
| 170 | - if (store.requestPackets(request)) { | ||
| 171 | - pushToAllDevices(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 | + } | ||
| 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 | + } | ||
| 214 | 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,22 +35,22 @@ import org.onosproject.net.Port; | ... | @@ -47,22 +35,22 @@ 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 | ||
| ... | @@ -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. |
| ... | @@ -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; |
| ... | @@ -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())) | ||
| 173 | - .withSerializer(new Serializer() { | ||
| 174 | - KryoNamespace kryo = new KryoNamespace.Builder() | ||
| 175 | - .register(KryoNamespaces.API) | ||
| 176 | .build(); | 181 | .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)) { |
| 193 | - } | ||
| 194 | return false; | 187 | return false; |
| 195 | } | 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; | ||
| 194 | + } | ||
| 195 | + newSet.addAll(old.value()); | ||
| 196 | + return requests.replace(request.selector(), old.version(), newSet); | ||
| 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 | } | ... | ... |
| ... | @@ -133,15 +133,17 @@ public class HostLocationProvider extends AbstractProvider implements HostProvid | ... | @@ -133,15 +133,17 @@ public class HostLocationProvider extends AbstractProvider implements HostProvid |
| 133 | packetService.addProcessor(processor, 1); | 133 | packetService.addProcessor(processor, 1); |
| 134 | deviceService.addListener(deviceListener); | 134 | deviceService.addListener(deviceListener); |
| 135 | readComponentConfiguration(context); | 135 | readComponentConfiguration(context); |
| 136 | - requestPackests(); | 136 | + requestIntercepts(); |
| 137 | 137 | ||
| 138 | log.info("Started with Application ID {}", appId.id()); | 138 | log.info("Started with Application ID {}", appId.id()); |
| 139 | } | 139 | } |
| 140 | 140 | ||
| 141 | @Deactivate | 141 | @Deactivate |
| 142 | public void deactivate() { | 142 | public void deactivate() { |
| 143 | - // TODO revoke all packet requests when deactivate | ||
| 144 | cfgService.unregisterProperties(getClass(), false); | 143 | cfgService.unregisterProperties(getClass(), false); |
| 144 | + | ||
| 145 | + withdrawIntercepts(); | ||
| 146 | + | ||
| 145 | providerRegistry.unregister(this); | 147 | providerRegistry.unregister(this); |
| 146 | packetService.removeProcessor(processor); | 148 | packetService.removeProcessor(processor); |
| 147 | deviceService.removeListener(deviceListener); | 149 | deviceService.removeListener(deviceListener); |
| ... | @@ -151,41 +153,57 @@ public class HostLocationProvider extends AbstractProvider implements HostProvid | ... | @@ -151,41 +153,57 @@ public class HostLocationProvider extends AbstractProvider implements HostProvid |
| 151 | 153 | ||
| 152 | @Modified | 154 | @Modified |
| 153 | public void modified(ComponentContext context) { | 155 | public void modified(ComponentContext context) { |
| 154 | - // TODO revoke unnecessary packet requests when config being modified | ||
| 155 | readComponentConfiguration(context); | 156 | readComponentConfiguration(context); |
| 156 | - requestPackests(); | 157 | + requestIntercepts(); |
| 157 | } | 158 | } |
| 158 | 159 | ||
| 159 | /** | 160 | /** |
| 160 | - * Request packet in via PacketService. | 161 | + * Request packet intercepts. |
| 161 | */ | 162 | */ |
| 162 | - private void requestPackests() { | 163 | + private void requestIntercepts() { |
| 163 | - TrafficSelector.Builder selectorBuilder = | 164 | + TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); |
| 164 | - DefaultTrafficSelector.builder(); | 165 | + selector.matchEthType(Ethernet.TYPE_ARP); |
| 165 | - selectorBuilder.matchEthType(Ethernet.TYPE_ARP); | 166 | + packetService.requestPackets(selector.build(), PacketPriority.CONTROL, appId); |
| 166 | - packetService.requestPackets(selectorBuilder.build(), | ||
| 167 | - PacketPriority.CONTROL, appId); | ||
| 168 | 167 | ||
| 169 | - if (ipv6NeighborDiscovery) { | ||
| 170 | // IPv6 Neighbor Solicitation packet. | 168 | // IPv6 Neighbor Solicitation packet. |
| 171 | - selectorBuilder = DefaultTrafficSelector.builder(); | 169 | + selector.matchEthType(Ethernet.TYPE_IPV6); |
| 172 | - selectorBuilder.matchEthType(Ethernet.TYPE_IPV6); | 170 | + selector.matchIPProtocol(IPv6.PROTOCOL_ICMP6); |
| 173 | - selectorBuilder.matchIPProtocol(IPv6.PROTOCOL_ICMP6); | 171 | + selector.matchIcmpv6Type(ICMP6.NEIGHBOR_SOLICITATION); |
| 174 | - selectorBuilder.matchIcmpv6Type(ICMP6.NEIGHBOR_SOLICITATION); | 172 | + if (ipv6NeighborDiscovery) { |
| 175 | - packetService.requestPackets(selectorBuilder.build(), | 173 | + packetService.requestPackets(selector.build(), PacketPriority.CONTROL, appId); |
| 176 | - PacketPriority.CONTROL, appId); | 174 | + } else { |
| 175 | + packetService.cancelPackets(selector.build(), PacketPriority.CONTROL, appId); | ||
| 176 | + } | ||
| 177 | 177 | ||
| 178 | // IPv6 Neighbor Advertisement packet. | 178 | // IPv6 Neighbor Advertisement packet. |
| 179 | - selectorBuilder = DefaultTrafficSelector.builder(); | 179 | + selector.matchIcmpv6Type(ICMP6.NEIGHBOR_ADVERTISEMENT); |
| 180 | - selectorBuilder.matchEthType(Ethernet.TYPE_IPV6); | 180 | + if (ipv6NeighborDiscovery) { |
| 181 | - selectorBuilder.matchIPProtocol(IPv6.PROTOCOL_ICMP6); | 181 | + packetService.requestPackets(selector.build(), PacketPriority.CONTROL, appId); |
| 182 | - selectorBuilder.matchIcmpv6Type(ICMP6.NEIGHBOR_ADVERTISEMENT); | 182 | + } else { |
| 183 | - packetService.requestPackets(selectorBuilder.build(), | 183 | + packetService.cancelPackets(selector.build(), PacketPriority.CONTROL, appId); |
| 184 | - PacketPriority.CONTROL, appId); | ||
| 185 | } | 184 | } |
| 186 | } | 185 | } |
| 187 | 186 | ||
| 188 | /** | 187 | /** |
| 188 | + * Withdraw packet intercepts. | ||
| 189 | + */ | ||
| 190 | + private void withdrawIntercepts() { | ||
| 191 | + TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); | ||
| 192 | + selector.matchEthType(Ethernet.TYPE_ARP); | ||
| 193 | + packetService.requestPackets(selector.build(), PacketPriority.CONTROL, appId); | ||
| 194 | + | ||
| 195 | + // IPv6 Neighbor Solicitation packet. | ||
| 196 | + selector.matchEthType(Ethernet.TYPE_IPV6); | ||
| 197 | + selector.matchIPProtocol(IPv6.PROTOCOL_ICMP6); | ||
| 198 | + selector.matchIcmpv6Type(ICMP6.NEIGHBOR_SOLICITATION); | ||
| 199 | + packetService.cancelPackets(selector.build(), PacketPriority.CONTROL, appId); | ||
| 200 | + | ||
| 201 | + // IPv6 Neighbor Advertisement packet. | ||
| 202 | + selector.matchIcmpv6Type(ICMP6.NEIGHBOR_ADVERTISEMENT); | ||
| 203 | + packetService.cancelPackets(selector.build(), PacketPriority.CONTROL, appId); | ||
| 204 | + } | ||
| 205 | + | ||
| 206 | + /** | ||
| 189 | * Extracts properties from the component configuration context. | 207 | * Extracts properties from the component configuration context. |
| 190 | * | 208 | * |
| 191 | * @param context the component context | 209 | * @param context the component context |
| ... | @@ -254,6 +272,7 @@ public class HostLocationProvider extends AbstractProvider implements HostProvid | ... | @@ -254,6 +272,7 @@ public class HostLocationProvider extends AbstractProvider implements HostProvid |
| 254 | HostDescription desc = new DefaultHostDescription(mac, vlan, hloc); | 272 | HostDescription desc = new DefaultHostDescription(mac, vlan, hloc); |
| 255 | providerService.hostDetected(hid, desc); | 273 | providerService.hostDetected(hid, desc); |
| 256 | } | 274 | } |
| 275 | + | ||
| 257 | /** | 276 | /** |
| 258 | * Update host location and IP address. | 277 | * Update host location and IP address. |
| 259 | * | 278 | * | ... | ... |
| ... | @@ -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 | ||
| ... | @@ -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