Moved default flows logic into the PacketManager.
This prevents us duplicating code in each of the apps and allows us to manage packet requests better in the future. Change-Id: I5656b2f0f3cecd3e42fe7b4a0a5ab7cb6582bb25
Showing
13 changed files
with
316 additions
and
382 deletions
| ... | @@ -30,14 +30,10 @@ import org.apache.felix.scr.annotations.ReferenceCardinality; | ... | @@ -30,14 +30,10 @@ import org.apache.felix.scr.annotations.ReferenceCardinality; |
| 30 | import org.onlab.packet.Ethernet; | 30 | import org.onlab.packet.Ethernet; |
| 31 | import org.onosproject.core.ApplicationId; | 31 | import org.onosproject.core.ApplicationId; |
| 32 | import org.onosproject.core.CoreService; | 32 | import org.onosproject.core.CoreService; |
| 33 | -import org.onosproject.net.Device; | ||
| 34 | import org.onosproject.net.Host; | 33 | import org.onosproject.net.Host; |
| 35 | import org.onosproject.net.HostId; | 34 | import org.onosproject.net.HostId; |
| 36 | import org.onosproject.net.Path; | 35 | import org.onosproject.net.Path; |
| 37 | import org.onosproject.net.PortNumber; | 36 | import org.onosproject.net.PortNumber; |
| 38 | -import org.onosproject.net.device.DeviceEvent; | ||
| 39 | -import org.onosproject.net.device.DeviceListener; | ||
| 40 | -import org.onosproject.net.device.DeviceService; | ||
| 41 | import org.onosproject.net.flow.DefaultFlowRule; | 37 | import org.onosproject.net.flow.DefaultFlowRule; |
| 42 | import org.onosproject.net.flow.DefaultTrafficSelector; | 38 | import org.onosproject.net.flow.DefaultTrafficSelector; |
| 43 | import org.onosproject.net.flow.DefaultTrafficTreatment; | 39 | import org.onosproject.net.flow.DefaultTrafficTreatment; |
| ... | @@ -48,6 +44,7 @@ import org.onosproject.net.flow.TrafficTreatment; | ... | @@ -48,6 +44,7 @@ import org.onosproject.net.flow.TrafficTreatment; |
| 48 | import org.onosproject.net.host.HostService; | 44 | import org.onosproject.net.host.HostService; |
| 49 | import org.onosproject.net.packet.InboundPacket; | 45 | import org.onosproject.net.packet.InboundPacket; |
| 50 | import org.onosproject.net.packet.PacketContext; | 46 | import org.onosproject.net.packet.PacketContext; |
| 47 | +import org.onosproject.net.packet.PacketPriority; | ||
| 51 | import org.onosproject.net.packet.PacketProcessor; | 48 | import org.onosproject.net.packet.PacketProcessor; |
| 52 | import org.onosproject.net.packet.PacketService; | 49 | import org.onosproject.net.packet.PacketService; |
| 53 | import org.onosproject.net.topology.TopologyService; | 50 | import org.onosproject.net.topology.TopologyService; |
| ... | @@ -62,7 +59,6 @@ public class ReactiveForwarding { | ... | @@ -62,7 +59,6 @@ public class ReactiveForwarding { |
| 62 | 59 | ||
| 63 | private static final int TIMEOUT = 10; | 60 | private static final int TIMEOUT = 10; |
| 64 | private static final int PRIORITY = 10; | 61 | private static final int PRIORITY = 10; |
| 65 | - private static final int PUNT_RULE_PRIORITY = 5; | ||
| 66 | 62 | ||
| 67 | private final Logger log = getLogger(getClass()); | 63 | private final Logger log = getLogger(getClass()); |
| 68 | 64 | ||
| ... | @@ -79,9 +75,6 @@ public class ReactiveForwarding { | ... | @@ -79,9 +75,6 @@ public class ReactiveForwarding { |
| 79 | protected FlowRuleService flowRuleService; | 75 | protected FlowRuleService flowRuleService; |
| 80 | 76 | ||
| 81 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 77 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 82 | - protected DeviceService deviceService; | ||
| 83 | - | ||
| 84 | - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
| 85 | protected CoreService coreService; | 78 | protected CoreService coreService; |
| 86 | 79 | ||
| 87 | private ReactivePacketProcessor processor = new ReactivePacketProcessor(); | 80 | private ReactivePacketProcessor processor = new ReactivePacketProcessor(); |
| ... | @@ -99,10 +92,14 @@ public class ReactiveForwarding { | ... | @@ -99,10 +92,14 @@ public class ReactiveForwarding { |
| 99 | @Activate | 92 | @Activate |
| 100 | public void activate(ComponentContext context) { | 93 | public void activate(ComponentContext context) { |
| 101 | appId = coreService.registerApplication("org.onosproject.fwd"); | 94 | appId = coreService.registerApplication("org.onosproject.fwd"); |
| 102 | - deviceService.addListener(new InternalDeviceListener()); | 95 | + |
| 103 | - pushRules(); | ||
| 104 | packetService.addProcessor(processor, PacketProcessor.ADVISOR_MAX + 2); | 96 | packetService.addProcessor(processor, PacketProcessor.ADVISOR_MAX + 2); |
| 105 | readComponentConfiguration(context); | 97 | readComponentConfiguration(context); |
| 98 | + | ||
| 99 | + TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); | ||
| 100 | + selector.matchEthType(Ethernet.TYPE_IPV4); | ||
| 101 | + packetService.requestPackets(selector.build(), PacketPriority.REACTIVE, appId); | ||
| 102 | + | ||
| 106 | log.info("Started with Application ID {}", appId.id()); | 103 | log.info("Started with Application ID {}", appId.id()); |
| 107 | } | 104 | } |
| 108 | 105 | ||
| ... | @@ -303,58 +300,6 @@ public class ReactiveForwarding { | ... | @@ -303,58 +300,6 @@ public class ReactiveForwarding { |
| 303 | } | 300 | } |
| 304 | } | 301 | } |
| 305 | 302 | ||
| 306 | - /** | ||
| 307 | - * Pushes flow rules to all devices. | ||
| 308 | - */ | ||
| 309 | - private void pushRules() { | ||
| 310 | - for (Device device : deviceService.getDevices()) { | ||
| 311 | - pushRules(device); | ||
| 312 | - } | ||
| 313 | - } | ||
| 314 | - | ||
| 315 | - /** | ||
| 316 | - * Pushes flow rules to the device to receive packets that need | ||
| 317 | - * to be processed. | ||
| 318 | - * | ||
| 319 | - * @param device the device to push the rules to | ||
| 320 | - */ | ||
| 321 | - private synchronized void pushRules(Device device) { | ||
| 322 | - TrafficSelector.Builder sbuilder = DefaultTrafficSelector.builder(); | ||
| 323 | - TrafficTreatment.Builder tbuilder = DefaultTrafficTreatment.builder(); | ||
| 324 | - | ||
| 325 | - // Get all IPv4 packets | ||
| 326 | - sbuilder.matchEthType(Ethernet.TYPE_IPV4); | ||
| 327 | - tbuilder.punt(); | ||
| 328 | - FlowRule flowArp = | ||
| 329 | - new DefaultFlowRule(device.id(), | ||
| 330 | - sbuilder.build(), tbuilder.build(), | ||
| 331 | - PUNT_RULE_PRIORITY, appId, 0, true); | ||
| 332 | - | ||
| 333 | - flowRuleService.applyFlowRules(flowArp); | ||
| 334 | - } | ||
| 335 | - | ||
| 336 | - public class InternalDeviceListener implements DeviceListener { | ||
| 337 | - | ||
| 338 | - @Override | ||
| 339 | - public void event(DeviceEvent event) { | ||
| 340 | - Device device = event.subject(); | ||
| 341 | - switch (event.type()) { | ||
| 342 | - case DEVICE_ADDED: | ||
| 343 | - pushRules(device); | ||
| 344 | - break; | ||
| 345 | - case DEVICE_AVAILABILITY_CHANGED: | ||
| 346 | - case DEVICE_SUSPENDED: | ||
| 347 | - case DEVICE_UPDATED: | ||
| 348 | - case DEVICE_REMOVED: | ||
| 349 | - case PORT_ADDED: | ||
| 350 | - case PORT_UPDATED: | ||
| 351 | - case PORT_REMOVED: | ||
| 352 | - default: | ||
| 353 | - break; | ||
| 354 | - } | ||
| 355 | - } | ||
| 356 | - } | ||
| 357 | - | ||
| 358 | } | 303 | } |
| 359 | 304 | ||
| 360 | 305 | ... | ... |
| ... | @@ -25,17 +25,11 @@ import org.apache.felix.scr.annotations.ReferenceCardinality; | ... | @@ -25,17 +25,11 @@ import org.apache.felix.scr.annotations.ReferenceCardinality; |
| 25 | import org.onlab.packet.Ethernet; | 25 | import org.onlab.packet.Ethernet; |
| 26 | import org.onosproject.core.ApplicationId; | 26 | import org.onosproject.core.ApplicationId; |
| 27 | import org.onosproject.core.CoreService; | 27 | import org.onosproject.core.CoreService; |
| 28 | -import org.onosproject.net.Device; | ||
| 29 | import org.onosproject.net.Host; | 28 | import org.onosproject.net.Host; |
| 30 | import org.onosproject.net.HostId; | 29 | import org.onosproject.net.HostId; |
| 31 | import org.onosproject.net.PortNumber; | 30 | import org.onosproject.net.PortNumber; |
| 32 | -import org.onosproject.net.device.DeviceEvent; | ||
| 33 | -import org.onosproject.net.device.DeviceListener; | ||
| 34 | -import org.onosproject.net.device.DeviceService; | ||
| 35 | -import org.onosproject.net.flow.DefaultFlowRule; | ||
| 36 | import org.onosproject.net.flow.DefaultTrafficSelector; | 31 | import org.onosproject.net.flow.DefaultTrafficSelector; |
| 37 | import org.onosproject.net.flow.DefaultTrafficTreatment; | 32 | import org.onosproject.net.flow.DefaultTrafficTreatment; |
| 38 | -import org.onosproject.net.flow.FlowRule; | ||
| 39 | import org.onosproject.net.flow.FlowRuleService; | 33 | import org.onosproject.net.flow.FlowRuleService; |
| 40 | import org.onosproject.net.flow.TrafficSelector; | 34 | import org.onosproject.net.flow.TrafficSelector; |
| 41 | import org.onosproject.net.flow.TrafficTreatment; | 35 | import org.onosproject.net.flow.TrafficTreatment; |
| ... | @@ -46,6 +40,7 @@ import org.onosproject.net.packet.DefaultOutboundPacket; | ... | @@ -46,6 +40,7 @@ import org.onosproject.net.packet.DefaultOutboundPacket; |
| 46 | import org.onosproject.net.packet.InboundPacket; | 40 | import org.onosproject.net.packet.InboundPacket; |
| 47 | import org.onosproject.net.packet.OutboundPacket; | 41 | import org.onosproject.net.packet.OutboundPacket; |
| 48 | import org.onosproject.net.packet.PacketContext; | 42 | import org.onosproject.net.packet.PacketContext; |
| 43 | +import org.onosproject.net.packet.PacketPriority; | ||
| 49 | import org.onosproject.net.packet.PacketProcessor; | 44 | import org.onosproject.net.packet.PacketProcessor; |
| 50 | import org.onosproject.net.packet.PacketService; | 45 | import org.onosproject.net.packet.PacketService; |
| 51 | import org.onosproject.net.topology.TopologyService; | 46 | import org.onosproject.net.topology.TopologyService; |
| ... | @@ -59,8 +54,6 @@ public class IntentReactiveForwarding { | ... | @@ -59,8 +54,6 @@ public class IntentReactiveForwarding { |
| 59 | 54 | ||
| 60 | private final Logger log = getLogger(getClass()); | 55 | private final Logger log = getLogger(getClass()); |
| 61 | 56 | ||
| 62 | - private static final int PUNT_RULE_PRIORITY = 5; | ||
| 63 | - | ||
| 64 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 57 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 65 | protected CoreService coreService; | 58 | protected CoreService coreService; |
| 66 | 59 | ||
| ... | @@ -79,18 +72,19 @@ public class IntentReactiveForwarding { | ... | @@ -79,18 +72,19 @@ public class IntentReactiveForwarding { |
| 79 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 72 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 80 | protected FlowRuleService flowRuleService; | 73 | protected FlowRuleService flowRuleService; |
| 81 | 74 | ||
| 82 | - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
| 83 | - protected DeviceService deviceService; | ||
| 84 | - | ||
| 85 | private ReactivePacketProcessor processor = new ReactivePacketProcessor(); | 75 | private ReactivePacketProcessor processor = new ReactivePacketProcessor(); |
| 86 | private ApplicationId appId; | 76 | private ApplicationId appId; |
| 87 | 77 | ||
| 88 | @Activate | 78 | @Activate |
| 89 | public void activate() { | 79 | public void activate() { |
| 90 | appId = coreService.registerApplication("org.onosproject.ifwd"); | 80 | appId = coreService.registerApplication("org.onosproject.ifwd"); |
| 91 | - deviceService.addListener(new InternalDeviceListener()); | 81 | + |
| 92 | - pushRules(); | ||
| 93 | packetService.addProcessor(processor, PacketProcessor.ADVISOR_MAX + 2); | 82 | packetService.addProcessor(processor, PacketProcessor.ADVISOR_MAX + 2); |
| 83 | + | ||
| 84 | + TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); | ||
| 85 | + selector.matchEthType(Ethernet.TYPE_IPV4); | ||
| 86 | + packetService.requestPackets(selector.build(), PacketPriority.REACTIVE, appId); | ||
| 87 | + | ||
| 94 | log.info("Started"); | 88 | log.info("Started"); |
| 95 | } | 89 | } |
| 96 | 90 | ||
| ... | @@ -172,56 +166,4 @@ public class IntentReactiveForwarding { | ... | @@ -172,56 +166,4 @@ public class IntentReactiveForwarding { |
| 172 | intentService.submit(intent); | 166 | intentService.submit(intent); |
| 173 | } | 167 | } |
| 174 | 168 | ||
| 175 | - /** | ||
| 176 | - * Pushes flow rules to all devices. | ||
| 177 | - */ | ||
| 178 | - private void pushRules() { | ||
| 179 | - for (Device device : deviceService.getDevices()) { | ||
| 180 | - pushRules(device); | ||
| 181 | - } | ||
| 182 | - } | ||
| 183 | - | ||
| 184 | - /** | ||
| 185 | - * Pushes flow rules to the device to receive packets that need | ||
| 186 | - * to be processed. | ||
| 187 | - * | ||
| 188 | - * @param device the device to push the rules to | ||
| 189 | - */ | ||
| 190 | - private synchronized void pushRules(Device device) { | ||
| 191 | - TrafficSelector.Builder sbuilder = DefaultTrafficSelector.builder(); | ||
| 192 | - TrafficTreatment.Builder tbuilder = DefaultTrafficTreatment.builder(); | ||
| 193 | - | ||
| 194 | - // Get all IPv4 packets | ||
| 195 | - sbuilder.matchEthType(Ethernet.TYPE_IPV4); | ||
| 196 | - tbuilder.punt(); | ||
| 197 | - FlowRule flowArp = | ||
| 198 | - new DefaultFlowRule(device.id(), | ||
| 199 | - sbuilder.build(), tbuilder.build(), | ||
| 200 | - PUNT_RULE_PRIORITY, appId, 0, true); | ||
| 201 | - | ||
| 202 | - flowRuleService.applyFlowRules(flowArp); | ||
| 203 | - } | ||
| 204 | - | ||
| 205 | - public class InternalDeviceListener implements DeviceListener { | ||
| 206 | - | ||
| 207 | - @Override | ||
| 208 | - public void event(DeviceEvent event) { | ||
| 209 | - Device device = event.subject(); | ||
| 210 | - switch (event.type()) { | ||
| 211 | - case DEVICE_ADDED: | ||
| 212 | - pushRules(device); | ||
| 213 | - break; | ||
| 214 | - case DEVICE_AVAILABILITY_CHANGED: | ||
| 215 | - case DEVICE_SUSPENDED: | ||
| 216 | - case DEVICE_UPDATED: | ||
| 217 | - case DEVICE_REMOVED: | ||
| 218 | - case PORT_ADDED: | ||
| 219 | - case PORT_UPDATED: | ||
| 220 | - case PORT_REMOVED: | ||
| 221 | - default: | ||
| 222 | - break; | ||
| 223 | - } | ||
| 224 | - } | ||
| 225 | - } | ||
| 226 | - | ||
| 227 | } | 169 | } | ... | ... |
| ... | @@ -22,9 +22,13 @@ import org.apache.felix.scr.annotations.Component; | ... | @@ -22,9 +22,13 @@ import org.apache.felix.scr.annotations.Component; |
| 22 | import org.apache.felix.scr.annotations.Deactivate; | 22 | import org.apache.felix.scr.annotations.Deactivate; |
| 23 | import org.apache.felix.scr.annotations.Reference; | 23 | import org.apache.felix.scr.annotations.Reference; |
| 24 | import org.apache.felix.scr.annotations.ReferenceCardinality; | 24 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
| 25 | +import org.onlab.packet.Ethernet; | ||
| 25 | import org.onosproject.core.ApplicationId; | 26 | import org.onosproject.core.ApplicationId; |
| 26 | import org.onosproject.core.CoreService; | 27 | import org.onosproject.core.CoreService; |
| 28 | +import org.onosproject.net.flow.DefaultTrafficSelector; | ||
| 29 | +import org.onosproject.net.flow.TrafficSelector; | ||
| 27 | import org.onosproject.net.packet.PacketContext; | 30 | import org.onosproject.net.packet.PacketContext; |
| 31 | +import org.onosproject.net.packet.PacketPriority; | ||
| 28 | import org.onosproject.net.packet.PacketProcessor; | 32 | import org.onosproject.net.packet.PacketProcessor; |
| 29 | import org.onosproject.net.packet.PacketService; | 33 | import org.onosproject.net.packet.PacketService; |
| 30 | import org.onosproject.net.proxyarp.ProxyArpService; | 34 | import org.onosproject.net.proxyarp.ProxyArpService; |
| ... | @@ -36,7 +40,6 @@ import org.slf4j.Logger; | ... | @@ -36,7 +40,6 @@ import org.slf4j.Logger; |
| 36 | @Component(immediate = true) | 40 | @Component(immediate = true) |
| 37 | public class ProxyArp { | 41 | public class ProxyArp { |
| 38 | 42 | ||
| 39 | - | ||
| 40 | private final Logger log = getLogger(getClass()); | 43 | private final Logger log = getLogger(getClass()); |
| 41 | 44 | ||
| 42 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 45 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| ... | @@ -56,6 +59,13 @@ public class ProxyArp { | ... | @@ -56,6 +59,13 @@ public class ProxyArp { |
| 56 | public void activate() { | 59 | public void activate() { |
| 57 | appId = coreService.registerApplication("org.onosproject.proxyarp"); | 60 | appId = coreService.registerApplication("org.onosproject.proxyarp"); |
| 58 | packetService.addProcessor(processor, PacketProcessor.ADVISOR_MAX + 1); | 61 | packetService.addProcessor(processor, PacketProcessor.ADVISOR_MAX + 1); |
| 62 | + | ||
| 63 | + TrafficSelector.Builder selectorBuilder = | ||
| 64 | + DefaultTrafficSelector.builder(); | ||
| 65 | + selectorBuilder.matchEthType(Ethernet.TYPE_ARP); | ||
| 66 | + packetService.requestPackets(selectorBuilder.build(), | ||
| 67 | + PacketPriority.CONTROL, appId); | ||
| 68 | + | ||
| 59 | log.info("Started with Application ID {}", appId.id()); | 69 | log.info("Started with Application ID {}", appId.id()); |
| 60 | } | 70 | } |
| 61 | 71 | ... | ... |
| 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 | +/** | ||
| 19 | + * Priorities available to applications for requests for packets from the data | ||
| 20 | + * plane. | ||
| 21 | + */ | ||
| 22 | +public enum PacketPriority { | ||
| 23 | + /** | ||
| 24 | + * High priority for control traffic. This will result in all traffic | ||
| 25 | + * matching the selector being sent to the controller. | ||
| 26 | + */ | ||
| 27 | + CONTROL(40000), | ||
| 28 | + | ||
| 29 | + /** | ||
| 30 | + * Low priority for reactive applications. Packets are only sent to the | ||
| 31 | + * controller if they fail to match any of the rules installed in the switch. | ||
| 32 | + */ | ||
| 33 | + REACTIVE(5); | ||
| 34 | + | ||
| 35 | + private final int priorityValue; | ||
| 36 | + | ||
| 37 | + private PacketPriority(int priorityValue) { | ||
| 38 | + this.priorityValue = priorityValue; | ||
| 39 | + } | ||
| 40 | + | ||
| 41 | + /** | ||
| 42 | + * Returns the integer value of the priority level. | ||
| 43 | + * | ||
| 44 | + * @return priority value | ||
| 45 | + */ | ||
| 46 | + public int priorityValue() { | ||
| 47 | + return priorityValue; | ||
| 48 | + } | ||
| 49 | +} | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| ... | @@ -15,6 +15,9 @@ | ... | @@ -15,6 +15,9 @@ |
| 15 | */ | 15 | */ |
| 16 | package org.onosproject.net.packet; | 16 | package org.onosproject.net.packet; |
| 17 | 17 | ||
| 18 | +import org.onosproject.core.ApplicationId; | ||
| 19 | +import org.onosproject.net.flow.TrafficSelector; | ||
| 20 | + | ||
| 18 | /** | 21 | /** |
| 19 | * Service for intercepting data plane packets and for emitting synthetic | 22 | * Service for intercepting data plane packets and for emitting synthetic |
| 20 | * outbound packets. | 23 | * outbound packets. |
| ... | @@ -35,6 +38,8 @@ public interface PacketService { | ... | @@ -35,6 +38,8 @@ public interface PacketService { |
| 35 | */ | 38 | */ |
| 36 | void addProcessor(PacketProcessor processor, int priority); | 39 | void addProcessor(PacketProcessor processor, int priority); |
| 37 | 40 | ||
| 41 | + // TODO allow processors to register for particular types of packets | ||
| 42 | + | ||
| 38 | /** | 43 | /** |
| 39 | * Removes the specified processor from the processing pipeline. | 44 | * Removes the specified processor from the processing pipeline. |
| 40 | * | 45 | * |
| ... | @@ -43,6 +48,19 @@ public interface PacketService { | ... | @@ -43,6 +48,19 @@ public interface PacketService { |
| 43 | void removeProcessor(PacketProcessor processor); | 48 | void removeProcessor(PacketProcessor processor); |
| 44 | 49 | ||
| 45 | /** | 50 | /** |
| 51 | + * Requests that packets matching the given selector are punted from the | ||
| 52 | + * dataplane to the controller. | ||
| 53 | + * | ||
| 54 | + * @param selector the traffic selector used to match packets | ||
| 55 | + * @param priority the priority of the rule | ||
| 56 | + * @param appId the application ID of the requester | ||
| 57 | + */ | ||
| 58 | + void requestPackets(TrafficSelector selector, PacketPriority priority, | ||
| 59 | + ApplicationId appId); | ||
| 60 | + | ||
| 61 | + // TODO add API to allow applications to revoke requests when they deactivate | ||
| 62 | + | ||
| 63 | + /** | ||
| 46 | * Emits the specified outbound packet onto the network. | 64 | * Emits the specified outbound packet onto the network. |
| 47 | * | 65 | * |
| 48 | * @param packet outbound packet | 66 | * @param packet outbound packet | ... | ... |
| ... | @@ -18,7 +18,9 @@ package org.onosproject.net.packet.impl; | ... | @@ -18,7 +18,9 @@ package org.onosproject.net.packet.impl; |
| 18 | import static com.google.common.base.Preconditions.checkNotNull; | 18 | import static com.google.common.base.Preconditions.checkNotNull; |
| 19 | import static org.slf4j.LoggerFactory.getLogger; | 19 | import static org.slf4j.LoggerFactory.getLogger; |
| 20 | 20 | ||
| 21 | +import java.util.Collections; | ||
| 21 | import java.util.Map; | 22 | import java.util.Map; |
| 23 | +import java.util.Set; | ||
| 22 | import java.util.concurrent.ConcurrentHashMap; | 24 | import java.util.concurrent.ConcurrentHashMap; |
| 23 | 25 | ||
| 24 | import org.apache.felix.scr.annotations.Activate; | 26 | import org.apache.felix.scr.annotations.Activate; |
| ... | @@ -27,11 +29,21 @@ import org.apache.felix.scr.annotations.Deactivate; | ... | @@ -27,11 +29,21 @@ import org.apache.felix.scr.annotations.Deactivate; |
| 27 | import org.apache.felix.scr.annotations.Reference; | 29 | import org.apache.felix.scr.annotations.Reference; |
| 28 | import org.apache.felix.scr.annotations.ReferenceCardinality; | 30 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
| 29 | import org.apache.felix.scr.annotations.Service; | 31 | import org.apache.felix.scr.annotations.Service; |
| 32 | +import org.onosproject.core.ApplicationId; | ||
| 30 | import org.onosproject.net.Device; | 33 | import org.onosproject.net.Device; |
| 34 | +import org.onosproject.net.device.DeviceEvent; | ||
| 35 | +import org.onosproject.net.device.DeviceListener; | ||
| 31 | import org.onosproject.net.device.DeviceService; | 36 | import org.onosproject.net.device.DeviceService; |
| 37 | +import org.onosproject.net.flow.DefaultFlowRule; | ||
| 38 | +import org.onosproject.net.flow.DefaultTrafficTreatment; | ||
| 39 | +import org.onosproject.net.flow.FlowRule; | ||
| 40 | +import org.onosproject.net.flow.FlowRuleService; | ||
| 41 | +import org.onosproject.net.flow.TrafficSelector; | ||
| 42 | +import org.onosproject.net.flow.TrafficTreatment; | ||
| 32 | import org.onosproject.net.packet.OutboundPacket; | 43 | import org.onosproject.net.packet.OutboundPacket; |
| 33 | import org.onosproject.net.packet.PacketContext; | 44 | import org.onosproject.net.packet.PacketContext; |
| 34 | import org.onosproject.net.packet.PacketEvent; | 45 | import org.onosproject.net.packet.PacketEvent; |
| 46 | +import org.onosproject.net.packet.PacketPriority; | ||
| 35 | import org.onosproject.net.packet.PacketProcessor; | 47 | import org.onosproject.net.packet.PacketProcessor; |
| 36 | import org.onosproject.net.packet.PacketProvider; | 48 | import org.onosproject.net.packet.PacketProvider; |
| 37 | import org.onosproject.net.packet.PacketProviderRegistry; | 49 | import org.onosproject.net.packet.PacketProviderRegistry; |
| ... | @@ -60,19 +72,55 @@ implements PacketService, PacketProviderRegistry { | ... | @@ -60,19 +72,55 @@ implements PacketService, PacketProviderRegistry { |
| 60 | private DeviceService deviceService; | 72 | private DeviceService deviceService; |
| 61 | 73 | ||
| 62 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 74 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 75 | + private FlowRuleService flowService; | ||
| 76 | + | ||
| 77 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
| 63 | private PacketStore store; | 78 | private PacketStore store; |
| 64 | 79 | ||
| 80 | + private final DeviceListener deviceListener = new InternalDeviceListener(); | ||
| 81 | + | ||
| 65 | private final Map<Integer, PacketProcessor> processors = new ConcurrentHashMap<>(); | 82 | private final Map<Integer, PacketProcessor> processors = new ConcurrentHashMap<>(); |
| 66 | 83 | ||
| 84 | + private Set<PacketRequest> packetRequests = | ||
| 85 | + Collections.newSetFromMap(new ConcurrentHashMap<>()); | ||
| 86 | + | ||
| 87 | + private final class PacketRequest { | ||
| 88 | + private final TrafficSelector selector; | ||
| 89 | + private final PacketPriority priority; | ||
| 90 | + private final ApplicationId appId; | ||
| 91 | + | ||
| 92 | + public PacketRequest(TrafficSelector selector, PacketPriority priority, | ||
| 93 | + ApplicationId appId) { | ||
| 94 | + this.selector = selector; | ||
| 95 | + this.priority = priority; | ||
| 96 | + this.appId = appId; | ||
| 97 | + } | ||
| 98 | + | ||
| 99 | + public TrafficSelector selector() { | ||
| 100 | + return selector; | ||
| 101 | + } | ||
| 102 | + | ||
| 103 | + public PacketPriority priority() { | ||
| 104 | + return priority; | ||
| 105 | + } | ||
| 106 | + | ||
| 107 | + public ApplicationId appId() { | ||
| 108 | + return appId; | ||
| 109 | + } | ||
| 110 | + | ||
| 111 | + } | ||
| 112 | + | ||
| 67 | @Activate | 113 | @Activate |
| 68 | public void activate() { | 114 | public void activate() { |
| 69 | store.setDelegate(delegate); | 115 | store.setDelegate(delegate); |
| 116 | + deviceService.addListener(deviceListener); | ||
| 70 | log.info("Started"); | 117 | log.info("Started"); |
| 71 | } | 118 | } |
| 72 | 119 | ||
| 73 | @Deactivate | 120 | @Deactivate |
| 74 | public void deactivate() { | 121 | public void deactivate() { |
| 75 | store.unsetDelegate(delegate); | 122 | store.unsetDelegate(delegate); |
| 123 | + deviceService.removeListener(deviceListener); | ||
| 76 | log.info("Stopped"); | 124 | log.info("Stopped"); |
| 77 | } | 125 | } |
| 78 | 126 | ||
| ... | @@ -89,6 +137,52 @@ implements PacketService, PacketProviderRegistry { | ... | @@ -89,6 +137,52 @@ implements PacketService, PacketProviderRegistry { |
| 89 | } | 137 | } |
| 90 | 138 | ||
| 91 | @Override | 139 | @Override |
| 140 | + public void requestPackets(TrafficSelector selector, PacketPriority priority, | ||
| 141 | + ApplicationId appId) { | ||
| 142 | + checkNotNull(selector, "Selector cannot be null"); | ||
| 143 | + checkNotNull(appId, "Application ID cannot be null"); | ||
| 144 | + | ||
| 145 | + PacketRequest request = | ||
| 146 | + new PacketRequest(selector, priority, appId); | ||
| 147 | + | ||
| 148 | + packetRequests.add(request); | ||
| 149 | + pushToAllDevices(request); | ||
| 150 | + } | ||
| 151 | + | ||
| 152 | + /** | ||
| 153 | + * Pushes a packet request flow rule to all devices. | ||
| 154 | + * | ||
| 155 | + * @param request the packet request | ||
| 156 | + */ | ||
| 157 | + private void pushToAllDevices(PacketRequest request) { | ||
| 158 | + for (Device device : deviceService.getDevices()) { | ||
| 159 | + pushRule(device, request); | ||
| 160 | + } | ||
| 161 | + } | ||
| 162 | + | ||
| 163 | + /** | ||
| 164 | + * Pushes flow rules to the device to request packets be sent to the | ||
| 165 | + * controller. | ||
| 166 | + * | ||
| 167 | + * @param device the device to push the rules to | ||
| 168 | + * @param request the packet request | ||
| 169 | + */ | ||
| 170 | + private void pushRule(Device device, PacketRequest request) { | ||
| 171 | + TrafficTreatment treatment = DefaultTrafficTreatment.builder() | ||
| 172 | + .punt() | ||
| 173 | + .build(); | ||
| 174 | + | ||
| 175 | + FlowRule flow = new DefaultFlowRule(device.id(), | ||
| 176 | + request.selector(), | ||
| 177 | + treatment, | ||
| 178 | + request.priority().priorityValue(), | ||
| 179 | + request.appId(), | ||
| 180 | + 0, true); | ||
| 181 | + | ||
| 182 | + flowService.applyFlowRules(flow); | ||
| 183 | + } | ||
| 184 | + | ||
| 185 | + @Override | ||
| 92 | public void emit(OutboundPacket packet) { | 186 | public void emit(OutboundPacket packet) { |
| 93 | checkNotNull(packet, "Packet cannot be null"); | 187 | checkNotNull(packet, "Packet cannot be null"); |
| 94 | 188 | ||
| ... | @@ -125,6 +219,7 @@ implements PacketService, PacketProviderRegistry { | ... | @@ -125,6 +219,7 @@ implements PacketService, PacketProviderRegistry { |
| 125 | 219 | ||
| 126 | @Override | 220 | @Override |
| 127 | public void processPacket(PacketContext context) { | 221 | public void processPacket(PacketContext context) { |
| 222 | + // TODO filter packets sent to processors based on registrations | ||
| 128 | for (PacketProcessor processor : processors.values()) { | 223 | for (PacketProcessor processor : processors.values()) { |
| 129 | processor.process(context); | 224 | processor.process(context); |
| 130 | } | 225 | } |
| ... | @@ -143,4 +238,19 @@ implements PacketService, PacketProviderRegistry { | ... | @@ -143,4 +238,19 @@ implements PacketService, PacketProviderRegistry { |
| 143 | } | 238 | } |
| 144 | } | 239 | } |
| 145 | 240 | ||
| 241 | + /** | ||
| 242 | + * Internal listener for device service events. | ||
| 243 | + */ | ||
| 244 | + private class InternalDeviceListener implements DeviceListener { | ||
| 245 | + @Override | ||
| 246 | + public void event(DeviceEvent event) { | ||
| 247 | + Device device = event.subject(); | ||
| 248 | + if (event.type() == DeviceEvent.Type.DEVICE_ADDED) { | ||
| 249 | + for (PacketRequest request : packetRequests) { | ||
| 250 | + pushRule(device, request); | ||
| 251 | + } | ||
| 252 | + } | ||
| 253 | + } | ||
| 254 | + } | ||
| 255 | + | ||
| 146 | } | 256 | } | ... | ... |
| ... | @@ -37,8 +37,6 @@ import org.onlab.packet.Ip4Address; | ... | @@ -37,8 +37,6 @@ import org.onlab.packet.Ip4Address; |
| 37 | import org.onlab.packet.IpAddress; | 37 | import org.onlab.packet.IpAddress; |
| 38 | import org.onlab.packet.MacAddress; | 38 | import org.onlab.packet.MacAddress; |
| 39 | import org.onlab.packet.VlanId; | 39 | import org.onlab.packet.VlanId; |
| 40 | -import org.onosproject.core.ApplicationId; | ||
| 41 | -import org.onosproject.core.CoreService; | ||
| 42 | import org.onosproject.net.ConnectPoint; | 40 | import org.onosproject.net.ConnectPoint; |
| 43 | import org.onosproject.net.Device; | 41 | import org.onosproject.net.Device; |
| 44 | import org.onosproject.net.Host; | 42 | import org.onosproject.net.Host; |
| ... | @@ -49,12 +47,7 @@ import org.onosproject.net.PortNumber; | ... | @@ -49,12 +47,7 @@ import org.onosproject.net.PortNumber; |
| 49 | import org.onosproject.net.device.DeviceEvent; | 47 | import org.onosproject.net.device.DeviceEvent; |
| 50 | import org.onosproject.net.device.DeviceListener; | 48 | import org.onosproject.net.device.DeviceListener; |
| 51 | import org.onosproject.net.device.DeviceService; | 49 | import org.onosproject.net.device.DeviceService; |
| 52 | -import org.onosproject.net.flow.DefaultFlowRule; | ||
| 53 | -import org.onosproject.net.flow.DefaultTrafficSelector; | ||
| 54 | import org.onosproject.net.flow.DefaultTrafficTreatment; | 50 | import org.onosproject.net.flow.DefaultTrafficTreatment; |
| 55 | -import org.onosproject.net.flow.FlowRule; | ||
| 56 | -import org.onosproject.net.flow.FlowRuleService; | ||
| 57 | -import org.onosproject.net.flow.TrafficSelector; | ||
| 58 | import org.onosproject.net.flow.TrafficTreatment; | 51 | import org.onosproject.net.flow.TrafficTreatment; |
| 59 | import org.onosproject.net.host.HostService; | 52 | import org.onosproject.net.host.HostService; |
| 60 | import org.onosproject.net.host.InterfaceIpAddress; | 53 | import org.onosproject.net.host.InterfaceIpAddress; |
| ... | @@ -79,8 +72,6 @@ public class ProxyArpManager implements ProxyArpService { | ... | @@ -79,8 +72,6 @@ public class ProxyArpManager implements ProxyArpService { |
| 79 | 72 | ||
| 80 | private final Logger log = getLogger(getClass()); | 73 | private final Logger log = getLogger(getClass()); |
| 81 | 74 | ||
| 82 | - private static final int FLOW_RULE_PRIORITY = 40000; | ||
| 83 | - | ||
| 84 | private static final String MAC_ADDR_NULL = "Mac address cannot be null."; | 75 | private static final String MAC_ADDR_NULL = "Mac address cannot be null."; |
| 85 | private static final String REQUEST_NULL = "Arp request cannot be null."; | 76 | private static final String REQUEST_NULL = "Arp request cannot be null."; |
| 86 | private static final String REQUEST_NOT_ARP = "Ethernet frame does not contain ARP request."; | 77 | private static final String REQUEST_NOT_ARP = "Ethernet frame does not contain ARP request."; |
| ... | @@ -88,12 +79,6 @@ public class ProxyArpManager implements ProxyArpService { | ... | @@ -88,12 +79,6 @@ public class ProxyArpManager implements ProxyArpService { |
| 88 | private static final String NOT_ARP_REPLY = "ARP is not a reply."; | 79 | private static final String NOT_ARP_REPLY = "ARP is not a reply."; |
| 89 | 80 | ||
| 90 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 81 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 91 | - protected CoreService coreService; | ||
| 92 | - | ||
| 93 | - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
| 94 | - protected FlowRuleService flowRuleService; | ||
| 95 | - | ||
| 96 | - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
| 97 | protected HostService hostService; | 82 | protected HostService hostService; |
| 98 | 83 | ||
| 99 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 84 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| ... | @@ -111,21 +96,15 @@ public class ProxyArpManager implements ProxyArpService { | ... | @@ -111,21 +96,15 @@ public class ProxyArpManager implements ProxyArpService { |
| 111 | private final Multimap<Device, PortNumber> externalPorts = | 96 | private final Multimap<Device, PortNumber> externalPorts = |
| 112 | HashMultimap.<Device, PortNumber>create(); | 97 | HashMultimap.<Device, PortNumber>create(); |
| 113 | 98 | ||
| 114 | - private ApplicationId appId; | ||
| 115 | - | ||
| 116 | /** | 99 | /** |
| 117 | * Listens to both device service and link service to determine | 100 | * Listens to both device service and link service to determine |
| 118 | * whether a port is internal or external. | 101 | * whether a port is internal or external. |
| 119 | */ | 102 | */ |
| 120 | @Activate | 103 | @Activate |
| 121 | public void activate() { | 104 | public void activate() { |
| 122 | - appId = | ||
| 123 | - coreService.registerApplication("org.onosproject.net.proxyarp"); | ||
| 124 | - | ||
| 125 | deviceService.addListener(new InternalDeviceListener()); | 105 | deviceService.addListener(new InternalDeviceListener()); |
| 126 | linkService.addListener(new InternalLinkListener()); | 106 | linkService.addListener(new InternalLinkListener()); |
| 127 | determinePortLocations(); | 107 | determinePortLocations(); |
| 128 | - pushRules(); | ||
| 129 | 108 | ||
| 130 | log.info("Started"); | 109 | log.info("Started"); |
| 131 | } | 110 | } |
| ... | @@ -418,36 +397,6 @@ public class ProxyArpManager implements ProxyArpService { | ... | @@ -418,36 +397,6 @@ public class ProxyArpManager implements ProxyArpService { |
| 418 | return eth; | 397 | return eth; |
| 419 | } | 398 | } |
| 420 | 399 | ||
| 421 | - /** | ||
| 422 | - * Pushes flow rules to all devices. | ||
| 423 | - */ | ||
| 424 | - private void pushRules() { | ||
| 425 | - for (Device device : deviceService.getDevices()) { | ||
| 426 | - pushRules(device); | ||
| 427 | - } | ||
| 428 | - } | ||
| 429 | - | ||
| 430 | - /** | ||
| 431 | - * Pushes flow rules to the device to receive control packets that need | ||
| 432 | - * to be processed. | ||
| 433 | - * | ||
| 434 | - * @param device the device to push the rules to | ||
| 435 | - */ | ||
| 436 | - private synchronized void pushRules(Device device) { | ||
| 437 | - TrafficSelector.Builder sbuilder = DefaultTrafficSelector.builder(); | ||
| 438 | - TrafficTreatment.Builder tbuilder = DefaultTrafficTreatment.builder(); | ||
| 439 | - | ||
| 440 | - // Get all ARP packets | ||
| 441 | - sbuilder.matchEthType(Ethernet.TYPE_ARP); | ||
| 442 | - tbuilder.punt(); | ||
| 443 | - FlowRule flowArp = | ||
| 444 | - new DefaultFlowRule(device.id(), | ||
| 445 | - sbuilder.build(), tbuilder.build(), | ||
| 446 | - FLOW_RULE_PRIORITY, appId, 0, true); | ||
| 447 | - | ||
| 448 | - flowRuleService.applyFlowRules(flowArp); | ||
| 449 | - } | ||
| 450 | - | ||
| 451 | public class InternalLinkListener implements LinkListener { | 400 | public class InternalLinkListener implements LinkListener { |
| 452 | 401 | ||
| 453 | @Override | 402 | @Override |
| ... | @@ -492,8 +441,6 @@ public class ProxyArpManager implements ProxyArpService { | ... | @@ -492,8 +441,6 @@ public class ProxyArpManager implements ProxyArpService { |
| 492 | Device device = event.subject(); | 441 | Device device = event.subject(); |
| 493 | switch (event.type()) { | 442 | switch (event.type()) { |
| 494 | case DEVICE_ADDED: | 443 | case DEVICE_ADDED: |
| 495 | - pushRules(device); | ||
| 496 | - break; | ||
| 497 | case DEVICE_AVAILABILITY_CHANGED: | 444 | case DEVICE_AVAILABILITY_CHANGED: |
| 498 | case DEVICE_SUSPENDED: | 445 | case DEVICE_SUSPENDED: |
| 499 | case DEVICE_UPDATED: | 446 | case DEVICE_UPDATED: | ... | ... |
| ... | @@ -31,6 +31,12 @@ import java.util.Set; | ... | @@ -31,6 +31,12 @@ import java.util.Set; |
| 31 | 31 | ||
| 32 | import org.junit.After; | 32 | import org.junit.After; |
| 33 | import org.junit.Test; | 33 | import org.junit.Test; |
| 34 | +import org.onlab.packet.ARP; | ||
| 35 | +import org.onlab.packet.Ethernet; | ||
| 36 | +import org.onlab.packet.IpAddress; | ||
| 37 | +import org.onlab.packet.IpPrefix; | ||
| 38 | +import org.onlab.packet.MacAddress; | ||
| 39 | +import org.onosproject.core.ApplicationId; | ||
| 34 | import org.onosproject.net.ConnectPoint; | 40 | import org.onosproject.net.ConnectPoint; |
| 35 | import org.onosproject.net.Device; | 41 | import org.onosproject.net.Device; |
| 36 | import org.onosproject.net.DeviceId; | 42 | import org.onosproject.net.DeviceId; |
| ... | @@ -40,20 +46,17 @@ import org.onosproject.net.Port; | ... | @@ -40,20 +46,17 @@ import org.onosproject.net.Port; |
| 40 | import org.onosproject.net.PortNumber; | 46 | import org.onosproject.net.PortNumber; |
| 41 | import org.onosproject.net.device.DeviceListener; | 47 | import org.onosproject.net.device.DeviceListener; |
| 42 | import org.onosproject.net.device.DeviceServiceAdapter; | 48 | import org.onosproject.net.device.DeviceServiceAdapter; |
| 49 | +import org.onosproject.net.flow.TrafficSelector; | ||
| 43 | import org.onosproject.net.flow.instructions.Instruction; | 50 | import org.onosproject.net.flow.instructions.Instruction; |
| 44 | import org.onosproject.net.flow.instructions.Instructions.OutputInstruction; | 51 | import org.onosproject.net.flow.instructions.Instructions.OutputInstruction; |
| 45 | import org.onosproject.net.host.HostProvider; | 52 | import org.onosproject.net.host.HostProvider; |
| 46 | import org.onosproject.net.host.InterfaceIpAddress; | 53 | import org.onosproject.net.host.InterfaceIpAddress; |
| 47 | import org.onosproject.net.host.PortAddresses; | 54 | import org.onosproject.net.host.PortAddresses; |
| 48 | import org.onosproject.net.packet.OutboundPacket; | 55 | import org.onosproject.net.packet.OutboundPacket; |
| 56 | +import org.onosproject.net.packet.PacketPriority; | ||
| 49 | import org.onosproject.net.packet.PacketProcessor; | 57 | import org.onosproject.net.packet.PacketProcessor; |
| 50 | import org.onosproject.net.packet.PacketService; | 58 | import org.onosproject.net.packet.PacketService; |
| 51 | import org.onosproject.net.provider.ProviderId; | 59 | import org.onosproject.net.provider.ProviderId; |
| 52 | -import org.onlab.packet.ARP; | ||
| 53 | -import org.onlab.packet.Ethernet; | ||
| 54 | -import org.onlab.packet.IpAddress; | ||
| 55 | -import org.onlab.packet.IpPrefix; | ||
| 56 | -import org.onlab.packet.MacAddress; | ||
| 57 | 60 | ||
| 58 | import com.google.common.collect.HashMultimap; | 61 | import com.google.common.collect.HashMultimap; |
| 59 | import com.google.common.collect.Lists; | 62 | import com.google.common.collect.Lists; |
| ... | @@ -187,6 +190,11 @@ public class HostMonitorTest { | ... | @@ -187,6 +190,11 @@ public class HostMonitorTest { |
| 187 | public void emit(OutboundPacket packet) { | 190 | public void emit(OutboundPacket packet) { |
| 188 | packets.add(packet); | 191 | packets.add(packet); |
| 189 | } | 192 | } |
| 193 | + | ||
| 194 | + @Override | ||
| 195 | + public void requestPackets(TrafficSelector selector, | ||
| 196 | + PacketPriority priority, ApplicationId appId) { | ||
| 197 | + } | ||
| 190 | } | 198 | } |
| 191 | 199 | ||
| 192 | class TestDeviceService extends DeviceServiceAdapter { | 200 | class TestDeviceService extends DeviceServiceAdapter { | ... | ... |
| ... | @@ -18,7 +18,6 @@ package org.onosproject.net.proxyarp.impl; | ... | @@ -18,7 +18,6 @@ package org.onosproject.net.proxyarp.impl; |
| 18 | import static org.easymock.EasyMock.anyObject; | 18 | import static org.easymock.EasyMock.anyObject; |
| 19 | import static org.easymock.EasyMock.createMock; | 19 | import static org.easymock.EasyMock.createMock; |
| 20 | import static org.easymock.EasyMock.expect; | 20 | import static org.easymock.EasyMock.expect; |
| 21 | -import static org.easymock.EasyMock.expectLastCall; | ||
| 22 | import static org.easymock.EasyMock.replay; | 21 | import static org.easymock.EasyMock.replay; |
| 23 | import static org.junit.Assert.assertArrayEquals; | 22 | import static org.junit.Assert.assertArrayEquals; |
| 24 | import static org.junit.Assert.assertEquals; | 23 | import static org.junit.Assert.assertEquals; |
| ... | @@ -33,9 +32,13 @@ import java.util.Set; | ... | @@ -33,9 +32,13 @@ import java.util.Set; |
| 33 | 32 | ||
| 34 | import org.junit.Before; | 33 | import org.junit.Before; |
| 35 | import org.junit.Test; | 34 | import org.junit.Test; |
| 35 | +import org.onlab.packet.ARP; | ||
| 36 | +import org.onlab.packet.Ethernet; | ||
| 37 | +import org.onlab.packet.Ip4Address; | ||
| 38 | +import org.onlab.packet.Ip4Prefix; | ||
| 39 | +import org.onlab.packet.MacAddress; | ||
| 40 | +import org.onlab.packet.VlanId; | ||
| 36 | import org.onosproject.core.ApplicationId; | 41 | import org.onosproject.core.ApplicationId; |
| 37 | -import org.onosproject.core.CoreService; | ||
| 38 | -import org.onosproject.core.DefaultApplicationId; | ||
| 39 | import org.onosproject.net.ConnectPoint; | 42 | import org.onosproject.net.ConnectPoint; |
| 40 | import org.onosproject.net.DefaultHost; | 43 | import org.onosproject.net.DefaultHost; |
| 41 | import org.onosproject.net.Device; | 44 | import org.onosproject.net.Device; |
| ... | @@ -48,8 +51,7 @@ import org.onosproject.net.Port; | ... | @@ -48,8 +51,7 @@ import org.onosproject.net.Port; |
| 48 | import org.onosproject.net.PortNumber; | 51 | import org.onosproject.net.PortNumber; |
| 49 | import org.onosproject.net.device.DeviceListener; | 52 | import org.onosproject.net.device.DeviceListener; |
| 50 | import org.onosproject.net.device.DeviceService; | 53 | import org.onosproject.net.device.DeviceService; |
| 51 | -import org.onosproject.net.flow.FlowRule; | 54 | +import org.onosproject.net.flow.TrafficSelector; |
| 52 | -import org.onosproject.net.flow.FlowRuleService; | ||
| 53 | import org.onosproject.net.flow.instructions.Instruction; | 55 | import org.onosproject.net.flow.instructions.Instruction; |
| 54 | import org.onosproject.net.flow.instructions.Instructions.OutputInstruction; | 56 | import org.onosproject.net.flow.instructions.Instructions.OutputInstruction; |
| 55 | import org.onosproject.net.host.HostService; | 57 | import org.onosproject.net.host.HostService; |
| ... | @@ -58,15 +60,10 @@ import org.onosproject.net.host.PortAddresses; | ... | @@ -58,15 +60,10 @@ import org.onosproject.net.host.PortAddresses; |
| 58 | import org.onosproject.net.link.LinkListener; | 60 | import org.onosproject.net.link.LinkListener; |
| 59 | import org.onosproject.net.link.LinkService; | 61 | import org.onosproject.net.link.LinkService; |
| 60 | import org.onosproject.net.packet.OutboundPacket; | 62 | import org.onosproject.net.packet.OutboundPacket; |
| 63 | +import org.onosproject.net.packet.PacketPriority; | ||
| 61 | import org.onosproject.net.packet.PacketProcessor; | 64 | import org.onosproject.net.packet.PacketProcessor; |
| 62 | import org.onosproject.net.packet.PacketService; | 65 | import org.onosproject.net.packet.PacketService; |
| 63 | import org.onosproject.net.provider.ProviderId; | 66 | import org.onosproject.net.provider.ProviderId; |
| 64 | -import org.onlab.packet.ARP; | ||
| 65 | -import org.onlab.packet.Ethernet; | ||
| 66 | -import org.onlab.packet.Ip4Address; | ||
| 67 | -import org.onlab.packet.Ip4Prefix; | ||
| 68 | -import org.onlab.packet.MacAddress; | ||
| 69 | -import org.onlab.packet.VlanId; | ||
| 70 | 67 | ||
| 71 | import com.google.common.collect.Sets; | 68 | import com.google.common.collect.Sets; |
| 72 | 69 | ||
| ... | @@ -102,14 +99,9 @@ public class ProxyArpManagerTest { | ... | @@ -102,14 +99,9 @@ public class ProxyArpManagerTest { |
| 102 | private ProxyArpManager proxyArp; | 99 | private ProxyArpManager proxyArp; |
| 103 | 100 | ||
| 104 | private TestPacketService packetService; | 101 | private TestPacketService packetService; |
| 105 | - | ||
| 106 | - private CoreService coreService; | ||
| 107 | private DeviceService deviceService; | 102 | private DeviceService deviceService; |
| 108 | - private FlowRuleService flowRuleService; | ||
| 109 | private LinkService linkService; | 103 | private LinkService linkService; |
| 110 | private HostService hostService; | 104 | private HostService hostService; |
| 111 | - private ApplicationId appId = new DefaultApplicationId((short) 100, | ||
| 112 | - "org.onosproject.net.proxyarp"); | ||
| 113 | 105 | ||
| 114 | @Before | 106 | @Before |
| 115 | public void setUp() throws Exception { | 107 | public void setUp() throws Exception { |
| ... | @@ -123,9 +115,7 @@ public class ProxyArpManagerTest { | ... | @@ -123,9 +115,7 @@ public class ProxyArpManagerTest { |
| 123 | proxyArp.hostService = hostService; | 115 | proxyArp.hostService = hostService; |
| 124 | 116 | ||
| 125 | createTopology(); | 117 | createTopology(); |
| 126 | - proxyArp.coreService = coreService; | ||
| 127 | proxyArp.deviceService = deviceService; | 118 | proxyArp.deviceService = deviceService; |
| 128 | - proxyArp.flowRuleService = flowRuleService; | ||
| 129 | proxyArp.linkService = linkService; | 119 | proxyArp.linkService = linkService; |
| 130 | 120 | ||
| 131 | proxyArp.activate(); | 121 | proxyArp.activate(); |
| ... | @@ -142,16 +132,6 @@ public class ProxyArpManagerTest { | ... | @@ -142,16 +132,6 @@ public class ProxyArpManagerTest { |
| 142 | * addresses configured. | 132 | * addresses configured. |
| 143 | */ | 133 | */ |
| 144 | private void createTopology() { | 134 | private void createTopology() { |
| 145 | - coreService = createMock(CoreService.class); | ||
| 146 | - expect(coreService.registerApplication(appId.name())) | ||
| 147 | - .andReturn(appId).anyTimes(); | ||
| 148 | - replay(coreService); | ||
| 149 | - | ||
| 150 | - flowRuleService = createMock(FlowRuleService.class); | ||
| 151 | - flowRuleService.applyFlowRules(anyObject(FlowRule.class)); | ||
| 152 | - expectLastCall().anyTimes(); | ||
| 153 | - replay(flowRuleService); | ||
| 154 | - | ||
| 155 | deviceService = createMock(DeviceService.class); | 135 | deviceService = createMock(DeviceService.class); |
| 156 | linkService = createMock(LinkService.class); | 136 | linkService = createMock(LinkService.class); |
| 157 | 137 | ||
| ... | @@ -602,5 +582,10 @@ public class ProxyArpManagerTest { | ... | @@ -602,5 +582,10 @@ public class ProxyArpManagerTest { |
| 602 | public void emit(OutboundPacket packet) { | 582 | public void emit(OutboundPacket packet) { |
| 603 | packets.add(packet); | 583 | packets.add(packet); |
| 604 | } | 584 | } |
| 585 | + | ||
| 586 | + @Override | ||
| 587 | + public void requestPackets(TrafficSelector selector, | ||
| 588 | + PacketPriority priority, ApplicationId appId) { | ||
| 589 | + } | ||
| 605 | } | 590 | } |
| 606 | } | 591 | } | ... | ... |
| ... | @@ -45,13 +45,8 @@ import org.onosproject.net.HostLocation; | ... | @@ -45,13 +45,8 @@ import org.onosproject.net.HostLocation; |
| 45 | import org.onosproject.net.device.DeviceEvent; | 45 | import org.onosproject.net.device.DeviceEvent; |
| 46 | import org.onosproject.net.device.DeviceListener; | 46 | import org.onosproject.net.device.DeviceListener; |
| 47 | import org.onosproject.net.device.DeviceService; | 47 | import org.onosproject.net.device.DeviceService; |
| 48 | -import org.onosproject.net.flow.DefaultFlowRule; | ||
| 49 | import org.onosproject.net.flow.DefaultTrafficSelector; | 48 | import org.onosproject.net.flow.DefaultTrafficSelector; |
| 50 | -import org.onosproject.net.flow.DefaultTrafficTreatment; | ||
| 51 | -import org.onosproject.net.flow.FlowRule; | ||
| 52 | -import org.onosproject.net.flow.FlowRuleService; | ||
| 53 | import org.onosproject.net.flow.TrafficSelector; | 49 | import org.onosproject.net.flow.TrafficSelector; |
| 54 | -import org.onosproject.net.flow.TrafficTreatment; | ||
| 55 | import org.onosproject.net.host.DefaultHostDescription; | 50 | import org.onosproject.net.host.DefaultHostDescription; |
| 56 | import org.onosproject.net.host.HostDescription; | 51 | import org.onosproject.net.host.HostDescription; |
| 57 | import org.onosproject.net.host.HostProvider; | 52 | import org.onosproject.net.host.HostProvider; |
| ... | @@ -59,6 +54,7 @@ import org.onosproject.net.host.HostProviderRegistry; | ... | @@ -59,6 +54,7 @@ import org.onosproject.net.host.HostProviderRegistry; |
| 59 | import org.onosproject.net.host.HostProviderService; | 54 | import org.onosproject.net.host.HostProviderService; |
| 60 | import org.onosproject.net.host.HostService; | 55 | import org.onosproject.net.host.HostService; |
| 61 | import org.onosproject.net.packet.PacketContext; | 56 | import org.onosproject.net.packet.PacketContext; |
| 57 | +import org.onosproject.net.packet.PacketPriority; | ||
| 62 | import org.onosproject.net.packet.PacketProcessor; | 58 | import org.onosproject.net.packet.PacketProcessor; |
| 63 | import org.onosproject.net.packet.PacketService; | 59 | import org.onosproject.net.packet.PacketService; |
| 64 | import org.onosproject.net.provider.AbstractProvider; | 60 | import org.onosproject.net.provider.AbstractProvider; |
| ... | @@ -77,15 +73,10 @@ public class HostLocationProvider extends AbstractProvider implements HostProvid | ... | @@ -77,15 +73,10 @@ public class HostLocationProvider extends AbstractProvider implements HostProvid |
| 77 | 73 | ||
| 78 | private final Logger log = getLogger(getClass()); | 74 | private final Logger log = getLogger(getClass()); |
| 79 | 75 | ||
| 80 | - private static final int FLOW_RULE_PRIORITY = 40000; | ||
| 81 | - | ||
| 82 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 76 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 83 | protected CoreService coreService; | 77 | protected CoreService coreService; |
| 84 | 78 | ||
| 85 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 79 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 86 | - protected FlowRuleService flowRuleService; | ||
| 87 | - | ||
| 88 | - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
| 89 | protected HostProviderRegistry providerRegistry; | 80 | protected HostProviderRegistry providerRegistry; |
| 90 | 81 | ||
| 91 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 82 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| ... | @@ -128,7 +119,12 @@ public class HostLocationProvider extends AbstractProvider implements HostProvid | ... | @@ -128,7 +119,12 @@ public class HostLocationProvider extends AbstractProvider implements HostProvid |
| 128 | providerService = providerRegistry.register(this); | 119 | providerService = providerRegistry.register(this); |
| 129 | pktService.addProcessor(processor, 1); | 120 | pktService.addProcessor(processor, 1); |
| 130 | deviceService.addListener(deviceListener); | 121 | deviceService.addListener(deviceListener); |
| 131 | - pushRules(); | 122 | + |
| 123 | + TrafficSelector.Builder selectorBuilder = | ||
| 124 | + DefaultTrafficSelector.builder(); | ||
| 125 | + selectorBuilder.matchEthType(Ethernet.TYPE_ARP); | ||
| 126 | + pktService.requestPackets(selectorBuilder.build(), | ||
| 127 | + PacketPriority.CONTROL, appId); | ||
| 132 | 128 | ||
| 133 | log.info("Started"); | 129 | log.info("Started"); |
| 134 | } | 130 | } |
| ... | @@ -161,36 +157,6 @@ public class HostLocationProvider extends AbstractProvider implements HostProvid | ... | @@ -161,36 +157,6 @@ public class HostLocationProvider extends AbstractProvider implements HostProvid |
| 161 | log.info("Triggering probe on device {}", host); | 157 | log.info("Triggering probe on device {}", host); |
| 162 | } | 158 | } |
| 163 | 159 | ||
| 164 | - /** | ||
| 165 | - * Pushes flow rules to all devices. | ||
| 166 | - */ | ||
| 167 | - private void pushRules() { | ||
| 168 | - for (Device device : deviceService.getDevices()) { | ||
| 169 | - pushRules(device); | ||
| 170 | - } | ||
| 171 | - } | ||
| 172 | - | ||
| 173 | - /** | ||
| 174 | - * Pushes flow rules to the device to receive control packets that need | ||
| 175 | - * to be processed. | ||
| 176 | - * | ||
| 177 | - * @param device the device to push the rules to | ||
| 178 | - */ | ||
| 179 | - private synchronized void pushRules(Device device) { | ||
| 180 | - TrafficSelector.Builder sbuilder = DefaultTrafficSelector.builder(); | ||
| 181 | - TrafficTreatment.Builder tbuilder = DefaultTrafficTreatment.builder(); | ||
| 182 | - | ||
| 183 | - // Get all ARP packets | ||
| 184 | - sbuilder.matchEthType(Ethernet.TYPE_ARP); | ||
| 185 | - tbuilder.punt(); | ||
| 186 | - FlowRule flowArp = | ||
| 187 | - new DefaultFlowRule(device.id(), | ||
| 188 | - sbuilder.build(), tbuilder.build(), | ||
| 189 | - FLOW_RULE_PRIORITY, appId, 0, true); | ||
| 190 | - | ||
| 191 | - flowRuleService.applyFlowRules(flowArp); | ||
| 192 | - } | ||
| 193 | - | ||
| 194 | private class InternalHostProvider implements PacketProcessor { | 160 | private class InternalHostProvider implements PacketProcessor { |
| 195 | 161 | ||
| 196 | @Override | 162 | @Override |
| ... | @@ -265,7 +231,6 @@ public class HostLocationProvider extends AbstractProvider implements HostProvid | ... | @@ -265,7 +231,6 @@ public class HostLocationProvider extends AbstractProvider implements HostProvid |
| 265 | Device device = event.subject(); | 231 | Device device = event.subject(); |
| 266 | switch (event.type()) { | 232 | switch (event.type()) { |
| 267 | case DEVICE_ADDED: | 233 | case DEVICE_ADDED: |
| 268 | - pushRules(device); | ||
| 269 | break; | 234 | break; |
| 270 | case DEVICE_AVAILABILITY_CHANGED: | 235 | case DEVICE_AVAILABILITY_CHANGED: |
| 271 | if (hostRemovalEnabled && | 236 | if (hostRemovalEnabled && | ... | ... |
| ... | @@ -15,16 +15,37 @@ | ... | @@ -15,16 +15,37 @@ |
| 15 | */ | 15 | */ |
| 16 | package org.onosproject.provider.host.impl; | 16 | package org.onosproject.provider.host.impl; |
| 17 | 17 | ||
| 18 | -import static org.easymock.EasyMock.anyObject; | ||
| 19 | import static org.easymock.EasyMock.createMock; | 18 | import static org.easymock.EasyMock.createMock; |
| 20 | import static org.easymock.EasyMock.expect; | 19 | import static org.easymock.EasyMock.expect; |
| 21 | -import static org.easymock.EasyMock.expectLastCall; | ||
| 22 | import static org.easymock.EasyMock.replay; | 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; | ||
| 23 | 38 | ||
| 24 | -import com.google.common.collect.ImmutableSet; | ||
| 25 | import org.junit.After; | 39 | import org.junit.After; |
| 26 | import org.junit.Before; | 40 | import org.junit.Before; |
| 27 | import org.junit.Test; | 41 | import org.junit.Test; |
| 42 | +import org.onlab.osgi.ComponentContextAdapter; | ||
| 43 | +import org.onlab.packet.ARP; | ||
| 44 | +import org.onlab.packet.ChassisId; | ||
| 45 | +import org.onlab.packet.Ethernet; | ||
| 46 | +import org.onlab.packet.IpAddress; | ||
| 47 | +import org.onlab.packet.MacAddress; | ||
| 48 | +import org.onlab.packet.VlanId; | ||
| 28 | import org.onosproject.core.ApplicationId; | 49 | import org.onosproject.core.ApplicationId; |
| 29 | import org.onosproject.core.CoreService; | 50 | import org.onosproject.core.CoreService; |
| 30 | import org.onosproject.core.DefaultApplicationId; | 51 | import org.onosproject.core.DefaultApplicationId; |
| ... | @@ -40,8 +61,7 @@ import org.onosproject.net.HostLocation; | ... | @@ -40,8 +61,7 @@ import org.onosproject.net.HostLocation; |
| 40 | import org.onosproject.net.device.DeviceEvent; | 61 | import org.onosproject.net.device.DeviceEvent; |
| 41 | import org.onosproject.net.device.DeviceListener; | 62 | import org.onosproject.net.device.DeviceListener; |
| 42 | import org.onosproject.net.device.DeviceServiceAdapter; | 63 | import org.onosproject.net.device.DeviceServiceAdapter; |
| 43 | -import org.onosproject.net.flow.FlowRule; | 64 | +import org.onosproject.net.flow.TrafficSelector; |
| 44 | -import org.onosproject.net.flow.FlowRuleService; | ||
| 45 | import org.onosproject.net.flow.TrafficTreatment; | 65 | import org.onosproject.net.flow.TrafficTreatment; |
| 46 | import org.onosproject.net.host.HostDescription; | 66 | import org.onosproject.net.host.HostDescription; |
| 47 | import org.onosproject.net.host.HostProvider; | 67 | import org.onosproject.net.host.HostProvider; |
| ... | @@ -52,35 +72,15 @@ import org.onosproject.net.packet.DefaultInboundPacket; | ... | @@ -52,35 +72,15 @@ import org.onosproject.net.packet.DefaultInboundPacket; |
| 52 | import org.onosproject.net.packet.InboundPacket; | 72 | import org.onosproject.net.packet.InboundPacket; |
| 53 | import org.onosproject.net.packet.OutboundPacket; | 73 | import org.onosproject.net.packet.OutboundPacket; |
| 54 | import org.onosproject.net.packet.PacketContext; | 74 | import org.onosproject.net.packet.PacketContext; |
| 75 | +import org.onosproject.net.packet.PacketPriority; | ||
| 55 | import org.onosproject.net.packet.PacketProcessor; | 76 | import org.onosproject.net.packet.PacketProcessor; |
| 56 | import org.onosproject.net.packet.PacketService; | 77 | import org.onosproject.net.packet.PacketService; |
| 57 | import org.onosproject.net.provider.AbstractProviderService; | 78 | import org.onosproject.net.provider.AbstractProviderService; |
| 58 | import org.onosproject.net.provider.ProviderId; | 79 | import org.onosproject.net.provider.ProviderId; |
| 59 | import org.onosproject.net.topology.Topology; | 80 | import org.onosproject.net.topology.Topology; |
| 60 | import org.onosproject.net.topology.TopologyServiceAdapter; | 81 | import org.onosproject.net.topology.TopologyServiceAdapter; |
| 61 | -import org.onlab.osgi.ComponentContextAdapter; | ||
| 62 | -import org.onlab.packet.ARP; | ||
| 63 | -import org.onlab.packet.ChassisId; | ||
| 64 | -import org.onlab.packet.Ethernet; | ||
| 65 | -import org.onlab.packet.IpAddress; | ||
| 66 | -import org.onlab.packet.MacAddress; | ||
| 67 | -import org.onlab.packet.VlanId; | ||
| 68 | - | ||
| 69 | -import java.nio.ByteBuffer; | ||
| 70 | -import java.util.Collections; | ||
| 71 | -import java.util.Dictionary; | ||
| 72 | -import java.util.Hashtable; | ||
| 73 | -import java.util.Set; | ||
| 74 | 82 | ||
| 75 | -import static org.junit.Assert.*; | 83 | +import com.google.common.collect.ImmutableSet; |
| 76 | -import static org.onosproject.net.Device.Type.SWITCH; | ||
| 77 | -import static org.onosproject.net.DeviceId.deviceId; | ||
| 78 | -import static org.onosproject.net.HostId.hostId; | ||
| 79 | -import static org.onosproject.net.PortNumber.portNumber; | ||
| 80 | -import static org.onosproject.net.device.DeviceEvent.Type.DEVICE_AVAILABILITY_CHANGED; | ||
| 81 | -import static org.onosproject.net.device.DeviceEvent.Type.DEVICE_REMOVED; | ||
| 82 | -import static org.onosproject.net.device.DeviceEvent.Type.PORT_UPDATED; | ||
| 83 | -import static org.onlab.packet.VlanId.vlanId; | ||
| 84 | 84 | ||
| 85 | public class HostLocationProviderTest { | 85 | public class HostLocationProviderTest { |
| 86 | 86 | ||
| ... | @@ -131,7 +131,6 @@ public class HostLocationProviderTest { | ... | @@ -131,7 +131,6 @@ public class HostLocationProviderTest { |
| 131 | 131 | ||
| 132 | private PacketProcessor testProcessor; | 132 | private PacketProcessor testProcessor; |
| 133 | private CoreService coreService; | 133 | private CoreService coreService; |
| 134 | - private FlowRuleService flowRuleService; | ||
| 135 | private TestHostProviderService providerService; | 134 | private TestHostProviderService providerService; |
| 136 | 135 | ||
| 137 | private ApplicationId appId = new DefaultApplicationId((short) 100, | 136 | private ApplicationId appId = new DefaultApplicationId((short) 100, |
| ... | @@ -145,13 +144,7 @@ public class HostLocationProviderTest { | ... | @@ -145,13 +144,7 @@ public class HostLocationProviderTest { |
| 145 | .andReturn(appId).anyTimes(); | 144 | .andReturn(appId).anyTimes(); |
| 146 | replay(coreService); | 145 | replay(coreService); |
| 147 | 146 | ||
| 148 | - flowRuleService = createMock(FlowRuleService.class); | ||
| 149 | - flowRuleService.applyFlowRules(anyObject(FlowRule.class)); | ||
| 150 | - expectLastCall().anyTimes(); | ||
| 151 | - replay(flowRuleService); | ||
| 152 | - | ||
| 153 | provider.coreService = coreService; | 147 | provider.coreService = coreService; |
| 154 | - provider.flowRuleService = flowRuleService; | ||
| 155 | 148 | ||
| 156 | provider.providerRegistry = hostRegistry; | 149 | provider.providerRegistry = hostRegistry; |
| 157 | provider.topologyService = topoService; | 150 | provider.topologyService = topoService; |
| ... | @@ -221,7 +214,6 @@ public class HostLocationProviderTest { | ... | @@ -221,7 +214,6 @@ public class HostLocationProviderTest { |
| 221 | public void tearDown() { | 214 | public void tearDown() { |
| 222 | provider.deactivate(); | 215 | provider.deactivate(); |
| 223 | provider.coreService = null; | 216 | provider.coreService = null; |
| 224 | - provider.flowRuleService = null; | ||
| 225 | provider.providerRegistry = null; | 217 | provider.providerRegistry = null; |
| 226 | } | 218 | } |
| 227 | 219 | ||
| ... | @@ -290,6 +282,11 @@ public class HostLocationProviderTest { | ... | @@ -290,6 +282,11 @@ public class HostLocationProviderTest { |
| 290 | @Override | 282 | @Override |
| 291 | public void emit(OutboundPacket packet) { | 283 | public void emit(OutboundPacket packet) { |
| 292 | } | 284 | } |
| 285 | + | ||
| 286 | + @Override | ||
| 287 | + public void requestPackets(TrafficSelector selector, | ||
| 288 | + PacketPriority priority, ApplicationId appId) { | ||
| 289 | + } | ||
| 293 | } | 290 | } |
| 294 | 291 | ||
| 295 | 292 | ... | ... |
| ... | @@ -15,6 +15,18 @@ | ... | @@ -15,6 +15,18 @@ |
| 15 | */ | 15 | */ |
| 16 | package org.onosproject.provider.lldp.impl; | 16 | package org.onosproject.provider.lldp.impl; |
| 17 | 17 | ||
| 18 | +import static java.util.concurrent.Executors.newSingleThreadScheduledExecutor; | ||
| 19 | +import static org.onlab.util.Tools.namedThreads; | ||
| 20 | +import static org.slf4j.LoggerFactory.getLogger; | ||
| 21 | + | ||
| 22 | +import java.io.IOException; | ||
| 23 | +import java.util.Dictionary; | ||
| 24 | +import java.util.EnumSet; | ||
| 25 | +import java.util.Map; | ||
| 26 | +import java.util.concurrent.ConcurrentHashMap; | ||
| 27 | +import java.util.concurrent.ScheduledExecutorService; | ||
| 28 | +import java.util.concurrent.TimeUnit; | ||
| 29 | + | ||
| 18 | import org.apache.felix.scr.annotations.Activate; | 30 | import org.apache.felix.scr.annotations.Activate; |
| 19 | import org.apache.felix.scr.annotations.Component; | 31 | import org.apache.felix.scr.annotations.Component; |
| 20 | import org.apache.felix.scr.annotations.Deactivate; | 32 | import org.apache.felix.scr.annotations.Deactivate; |
| ... | @@ -35,17 +47,13 @@ import org.onosproject.net.Port; | ... | @@ -35,17 +47,13 @@ import org.onosproject.net.Port; |
| 35 | import org.onosproject.net.device.DeviceEvent; | 47 | import org.onosproject.net.device.DeviceEvent; |
| 36 | import org.onosproject.net.device.DeviceListener; | 48 | import org.onosproject.net.device.DeviceListener; |
| 37 | import org.onosproject.net.device.DeviceService; | 49 | import org.onosproject.net.device.DeviceService; |
| 38 | -import org.onosproject.net.flow.DefaultFlowRule; | ||
| 39 | import org.onosproject.net.flow.DefaultTrafficSelector; | 50 | import org.onosproject.net.flow.DefaultTrafficSelector; |
| 40 | -import org.onosproject.net.flow.DefaultTrafficTreatment; | ||
| 41 | -import org.onosproject.net.flow.FlowRule; | ||
| 42 | -import org.onosproject.net.flow.FlowRuleService; | ||
| 43 | import org.onosproject.net.flow.TrafficSelector; | 51 | import org.onosproject.net.flow.TrafficSelector; |
| 44 | -import org.onosproject.net.flow.TrafficTreatment; | ||
| 45 | import org.onosproject.net.link.LinkProvider; | 52 | import org.onosproject.net.link.LinkProvider; |
| 46 | import org.onosproject.net.link.LinkProviderRegistry; | 53 | import org.onosproject.net.link.LinkProviderRegistry; |
| 47 | import org.onosproject.net.link.LinkProviderService; | 54 | import org.onosproject.net.link.LinkProviderService; |
| 48 | import org.onosproject.net.packet.PacketContext; | 55 | import org.onosproject.net.packet.PacketContext; |
| 56 | +import org.onosproject.net.packet.PacketPriority; | ||
| 49 | import org.onosproject.net.packet.PacketProcessor; | 57 | import org.onosproject.net.packet.PacketProcessor; |
| 50 | import org.onosproject.net.packet.PacketService; | 58 | import org.onosproject.net.packet.PacketService; |
| 51 | import org.onosproject.net.provider.AbstractProvider; | 59 | import org.onosproject.net.provider.AbstractProvider; |
| ... | @@ -57,18 +65,6 @@ import com.google.common.base.Strings; | ... | @@ -57,18 +65,6 @@ import com.google.common.base.Strings; |
| 57 | import com.google.common.collect.ImmutableMap; | 65 | import com.google.common.collect.ImmutableMap; |
| 58 | import com.google.common.collect.ImmutableSet; | 66 | import com.google.common.collect.ImmutableSet; |
| 59 | 67 | ||
| 60 | -import java.io.IOException; | ||
| 61 | -import java.util.Dictionary; | ||
| 62 | -import java.util.EnumSet; | ||
| 63 | -import java.util.Map; | ||
| 64 | -import java.util.concurrent.ConcurrentHashMap; | ||
| 65 | -import java.util.concurrent.ScheduledExecutorService; | ||
| 66 | -import java.util.concurrent.TimeUnit; | ||
| 67 | - | ||
| 68 | -import static java.util.concurrent.Executors.newSingleThreadScheduledExecutor; | ||
| 69 | -import static org.onlab.util.Tools.namedThreads; | ||
| 70 | -import static org.slf4j.LoggerFactory.getLogger; | ||
| 71 | - | ||
| 72 | 68 | ||
| 73 | /** | 69 | /** |
| 74 | * Provider which uses an OpenFlow controller to detect network | 70 | * Provider which uses an OpenFlow controller to detect network |
| ... | @@ -85,15 +81,10 @@ public class LLDPLinkProvider extends AbstractProvider implements LinkProvider { | ... | @@ -85,15 +81,10 @@ public class LLDPLinkProvider extends AbstractProvider implements LinkProvider { |
| 85 | 81 | ||
| 86 | private final Logger log = getLogger(getClass()); | 82 | private final Logger log = getLogger(getClass()); |
| 87 | 83 | ||
| 88 | - private static final int FLOW_RULE_PRIORITY = 40000; | ||
| 89 | - | ||
| 90 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 84 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 91 | protected CoreService coreService; | 85 | protected CoreService coreService; |
| 92 | 86 | ||
| 93 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 87 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 94 | - protected FlowRuleService flowRuleService; | ||
| 95 | - | ||
| 96 | - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
| 97 | protected LinkProviderRegistry providerRegistry; | 88 | protected LinkProviderRegistry providerRegistry; |
| 98 | 89 | ||
| 99 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 90 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| ... | @@ -174,7 +165,7 @@ public class LLDPLinkProvider extends AbstractProvider implements LinkProvider { | ... | @@ -174,7 +165,7 @@ public class LLDPLinkProvider extends AbstractProvider implements LinkProvider { |
| 174 | executor.scheduleAtFixedRate(new SyncDeviceInfoTask(), INIT_DELAY, | 165 | executor.scheduleAtFixedRate(new SyncDeviceInfoTask(), INIT_DELAY, |
| 175 | DELAY, TimeUnit.SECONDS); | 166 | DELAY, TimeUnit.SECONDS); |
| 176 | 167 | ||
| 177 | - pushRules(); | 168 | + requestPackets(); |
| 178 | 169 | ||
| 179 | log.info("Started"); | 170 | log.info("Started"); |
| 180 | } | 171 | } |
| ... | @@ -233,48 +224,20 @@ public class LLDPLinkProvider extends AbstractProvider implements LinkProvider { | ... | @@ -233,48 +224,20 @@ public class LLDPLinkProvider extends AbstractProvider implements LinkProvider { |
| 233 | // should refresh discoverers when we need dynamic reconfiguration | 224 | // should refresh discoverers when we need dynamic reconfiguration |
| 234 | } | 225 | } |
| 235 | 226 | ||
| 236 | - /** | 227 | + private void requestPackets() { |
| 237 | - * Pushes flow rules to all devices. | 228 | + TrafficSelector.Builder lldpSelector = DefaultTrafficSelector.builder(); |
| 238 | - */ | 229 | + lldpSelector.matchEthType(Ethernet.TYPE_LLDP); |
| 239 | - private void pushRules() { | 230 | + packetSevice.requestPackets(lldpSelector.build(), |
| 240 | - for (Device device : deviceService.getDevices()) { | 231 | + PacketPriority.CONTROL, appId); |
| 241 | - pushRules(device); | 232 | + |
| 233 | + if (useBDDP) { | ||
| 234 | + TrafficSelector.Builder bddpSelector = DefaultTrafficSelector.builder(); | ||
| 235 | + bddpSelector.matchEthType(Ethernet.TYPE_BSN); | ||
| 236 | + packetSevice.requestPackets(bddpSelector.build(), | ||
| 237 | + PacketPriority.CONTROL, appId); | ||
| 242 | } | 238 | } |
| 243 | } | 239 | } |
| 244 | 240 | ||
| 245 | - /** | ||
| 246 | - * Pushes flow rules to the device to receive control packets that need | ||
| 247 | - * to be processed. | ||
| 248 | - * | ||
| 249 | - * @param device the device to push the rules to | ||
| 250 | - */ | ||
| 251 | - private synchronized void pushRules(Device device) { | ||
| 252 | - TrafficSelector.Builder sbuilder; | ||
| 253 | - TrafficTreatment.Builder tbuilder; | ||
| 254 | - | ||
| 255 | - // Get all LLDP packets | ||
| 256 | - sbuilder = DefaultTrafficSelector.builder(); | ||
| 257 | - tbuilder = DefaultTrafficTreatment.builder(); | ||
| 258 | - sbuilder.matchEthType(Ethernet.TYPE_LLDP); | ||
| 259 | - tbuilder.punt(); | ||
| 260 | - FlowRule flowLldp = | ||
| 261 | - new DefaultFlowRule(device.id(), | ||
| 262 | - sbuilder.build(), tbuilder.build(), | ||
| 263 | - FLOW_RULE_PRIORITY, appId, 0, true); | ||
| 264 | - | ||
| 265 | - // Get all BDDP packets | ||
| 266 | - sbuilder = DefaultTrafficSelector.builder(); | ||
| 267 | - tbuilder = DefaultTrafficTreatment.builder(); | ||
| 268 | - sbuilder.matchEthType(Ethernet.TYPE_BSN); | ||
| 269 | - tbuilder.punt(); | ||
| 270 | - FlowRule flowBddp = | ||
| 271 | - new DefaultFlowRule(device.id(), | ||
| 272 | - sbuilder.build(), tbuilder.build(), | ||
| 273 | - FLOW_RULE_PRIORITY, appId, 0, true); | ||
| 274 | - | ||
| 275 | - flowRuleService.applyFlowRules(flowLldp, flowBddp); | ||
| 276 | - } | ||
| 277 | - | ||
| 278 | private class InternalRoleListener implements MastershipListener { | 241 | private class InternalRoleListener implements MastershipListener { |
| 279 | 242 | ||
| 280 | @Override | 243 | @Override |
| ... | @@ -323,8 +286,6 @@ public class LLDPLinkProvider extends AbstractProvider implements LinkProvider { | ... | @@ -323,8 +286,6 @@ public class LLDPLinkProvider extends AbstractProvider implements LinkProvider { |
| 323 | final DeviceId deviceId = device.id(); | 286 | final DeviceId deviceId = device.id(); |
| 324 | switch (event.type()) { | 287 | switch (event.type()) { |
| 325 | case DEVICE_ADDED: | 288 | case DEVICE_ADDED: |
| 326 | - pushRules(device); | ||
| 327 | - // FALLTHROUGH | ||
| 328 | case DEVICE_UPDATED: | 289 | case DEVICE_UPDATED: |
| 329 | synchronized (discoverers) { | 290 | synchronized (discoverers) { |
| 330 | ld = discoverers.get(deviceId); | 291 | ld = discoverers.get(deviceId); | ... | ... |
| ... | @@ -15,19 +15,28 @@ | ... | @@ -15,19 +15,28 @@ |
| 15 | */ | 15 | */ |
| 16 | package org.onosproject.provider.lldp.impl; | 16 | package org.onosproject.provider.lldp.impl; |
| 17 | 17 | ||
| 18 | -import static org.easymock.EasyMock.anyObject; | ||
| 19 | import static org.easymock.EasyMock.createMock; | 18 | import static org.easymock.EasyMock.createMock; |
| 20 | import static org.easymock.EasyMock.expect; | 19 | import static org.easymock.EasyMock.expect; |
| 21 | -import static org.easymock.EasyMock.expectLastCall; | ||
| 22 | import static org.easymock.EasyMock.replay; | 20 | import static org.easymock.EasyMock.replay; |
| 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; | ||
| 23 | 26 | ||
| 24 | -import com.google.common.collect.ArrayListMultimap; | 27 | +import java.nio.ByteBuffer; |
| 25 | -import com.google.common.collect.Lists; | 28 | +import java.util.Collections; |
| 26 | -import com.google.common.collect.Maps; | 29 | +import java.util.HashMap; |
| 30 | +import java.util.List; | ||
| 31 | +import java.util.Map; | ||
| 32 | +import java.util.Set; | ||
| 27 | 33 | ||
| 28 | import org.junit.After; | 34 | import org.junit.After; |
| 29 | import org.junit.Before; | 35 | import org.junit.Before; |
| 30 | import org.junit.Test; | 36 | import org.junit.Test; |
| 37 | +import org.onlab.packet.ChassisId; | ||
| 38 | +import org.onlab.packet.Ethernet; | ||
| 39 | +import org.onlab.packet.ONOSLLDP; | ||
| 31 | import org.onosproject.cluster.NodeId; | 40 | import org.onosproject.cluster.NodeId; |
| 32 | import org.onosproject.cluster.RoleInfo; | 41 | import org.onosproject.cluster.RoleInfo; |
| 33 | import org.onosproject.core.ApplicationId; | 42 | import org.onosproject.core.ApplicationId; |
| ... | @@ -46,8 +55,7 @@ import org.onosproject.net.PortNumber; | ... | @@ -46,8 +55,7 @@ import org.onosproject.net.PortNumber; |
| 46 | import org.onosproject.net.device.DeviceEvent; | 55 | import org.onosproject.net.device.DeviceEvent; |
| 47 | import org.onosproject.net.device.DeviceListener; | 56 | import org.onosproject.net.device.DeviceListener; |
| 48 | import org.onosproject.net.device.DeviceServiceAdapter; | 57 | import org.onosproject.net.device.DeviceServiceAdapter; |
| 49 | -import org.onosproject.net.flow.FlowRule; | 58 | +import org.onosproject.net.flow.TrafficSelector; |
| 50 | -import org.onosproject.net.flow.FlowRuleService; | ||
| 51 | import org.onosproject.net.flow.TrafficTreatment; | 59 | import org.onosproject.net.flow.TrafficTreatment; |
| 52 | import org.onosproject.net.link.LinkDescription; | 60 | import org.onosproject.net.link.LinkDescription; |
| 53 | import org.onosproject.net.link.LinkProvider; | 61 | import org.onosproject.net.link.LinkProvider; |
| ... | @@ -57,22 +65,15 @@ import org.onosproject.net.packet.DefaultInboundPacket; | ... | @@ -57,22 +65,15 @@ import org.onosproject.net.packet.DefaultInboundPacket; |
| 57 | import org.onosproject.net.packet.InboundPacket; | 65 | import org.onosproject.net.packet.InboundPacket; |
| 58 | import org.onosproject.net.packet.OutboundPacket; | 66 | import org.onosproject.net.packet.OutboundPacket; |
| 59 | import org.onosproject.net.packet.PacketContext; | 67 | import org.onosproject.net.packet.PacketContext; |
| 68 | +import org.onosproject.net.packet.PacketPriority; | ||
| 60 | import org.onosproject.net.packet.PacketProcessor; | 69 | import org.onosproject.net.packet.PacketProcessor; |
| 61 | import org.onosproject.net.packet.PacketService; | 70 | import org.onosproject.net.packet.PacketService; |
| 62 | import org.onosproject.net.provider.AbstractProviderService; | 71 | import org.onosproject.net.provider.AbstractProviderService; |
| 63 | import org.onosproject.net.provider.ProviderId; | 72 | import org.onosproject.net.provider.ProviderId; |
| 64 | -import org.onlab.packet.ChassisId; | ||
| 65 | -import org.onlab.packet.Ethernet; | ||
| 66 | -import org.onlab.packet.ONOSLLDP; | ||
| 67 | 73 | ||
| 68 | -import java.nio.ByteBuffer; | 74 | +import com.google.common.collect.ArrayListMultimap; |
| 69 | -import java.util.Collections; | 75 | +import com.google.common.collect.Lists; |
| 70 | -import java.util.HashMap; | 76 | +import com.google.common.collect.Maps; |
| 71 | -import java.util.List; | ||
| 72 | -import java.util.Map; | ||
| 73 | -import java.util.Set; | ||
| 74 | - | ||
| 75 | -import static org.junit.Assert.*; | ||
| 76 | 77 | ||
| 77 | public class LLDPLinkProviderTest { | 78 | public class LLDPLinkProviderTest { |
| 78 | 79 | ||
| ... | @@ -91,7 +92,6 @@ public class LLDPLinkProviderTest { | ... | @@ -91,7 +92,6 @@ public class LLDPLinkProviderTest { |
| 91 | private final TestMasterShipService masterService = new TestMasterShipService(); | 92 | private final TestMasterShipService masterService = new TestMasterShipService(); |
| 92 | 93 | ||
| 93 | private CoreService coreService; | 94 | private CoreService coreService; |
| 94 | - private FlowRuleService flowRuleService; | ||
| 95 | private TestLinkProviderService providerService; | 95 | private TestLinkProviderService providerService; |
| 96 | 96 | ||
| 97 | private PacketProcessor testProcessor; | 97 | private PacketProcessor testProcessor; |
| ... | @@ -108,14 +108,7 @@ public class LLDPLinkProviderTest { | ... | @@ -108,14 +108,7 @@ public class LLDPLinkProviderTest { |
| 108 | .andReturn(appId).anyTimes(); | 108 | .andReturn(appId).anyTimes(); |
| 109 | replay(coreService); | 109 | replay(coreService); |
| 110 | 110 | ||
| 111 | - flowRuleService = createMock(FlowRuleService.class); | ||
| 112 | - flowRuleService.applyFlowRules(anyObject(FlowRule.class), | ||
| 113 | - anyObject(FlowRule.class)); | ||
| 114 | - expectLastCall().anyTimes(); | ||
| 115 | - replay(flowRuleService); | ||
| 116 | - | ||
| 117 | provider.coreService = coreService; | 111 | provider.coreService = coreService; |
| 118 | - provider.flowRuleService = flowRuleService; | ||
| 119 | 112 | ||
| 120 | provider.deviceService = deviceService; | 113 | provider.deviceService = deviceService; |
| 121 | provider.packetSevice = packetService; | 114 | provider.packetSevice = packetService; |
| ... | @@ -208,7 +201,6 @@ public class LLDPLinkProviderTest { | ... | @@ -208,7 +201,6 @@ public class LLDPLinkProviderTest { |
| 208 | public void tearDown() { | 201 | public void tearDown() { |
| 209 | provider.deactivate(); | 202 | provider.deactivate(); |
| 210 | provider.coreService = null; | 203 | provider.coreService = null; |
| 211 | - provider.flowRuleService = null; | ||
| 212 | provider.providerRegistry = null; | 204 | provider.providerRegistry = null; |
| 213 | provider.deviceService = null; | 205 | provider.deviceService = null; |
| 214 | provider.packetSevice = null; | 206 | provider.packetSevice = null; |
| ... | @@ -403,6 +395,11 @@ public class LLDPLinkProviderTest { | ... | @@ -403,6 +395,11 @@ public class LLDPLinkProviderTest { |
| 403 | public void emit(OutboundPacket packet) { | 395 | public void emit(OutboundPacket packet) { |
| 404 | 396 | ||
| 405 | } | 397 | } |
| 398 | + | ||
| 399 | + @Override | ||
| 400 | + public void requestPackets(TrafficSelector selector, | ||
| 401 | + PacketPriority priority, ApplicationId appId) { | ||
| 402 | + } | ||
| 406 | } | 403 | } |
| 407 | 404 | ||
| 408 | private class TestDeviceService extends DeviceServiceAdapter { | 405 | private class TestDeviceService extends DeviceServiceAdapter { | ... | ... |
-
Please register or login to post a comment