alshabib | c274c90 | 2014-10-03 14:58:27 -0700 | [diff] [blame^] | 1 | package org.onlab.onos.proxyarp; |
| 2 | |
| 3 | import static org.slf4j.LoggerFactory.getLogger; |
| 4 | |
| 5 | import org.apache.felix.scr.annotations.Activate; |
| 6 | import org.apache.felix.scr.annotations.Component; |
| 7 | import org.apache.felix.scr.annotations.Deactivate; |
| 8 | import org.apache.felix.scr.annotations.Reference; |
| 9 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
| 10 | import org.onlab.onos.ApplicationId; |
| 11 | import org.onlab.onos.net.packet.PacketContext; |
| 12 | import org.onlab.onos.net.packet.PacketProcessor; |
| 13 | import org.onlab.onos.net.packet.PacketService; |
| 14 | import org.onlab.onos.net.proxyarp.ProxyArpService; |
| 15 | import org.slf4j.Logger; |
| 16 | |
| 17 | /** |
| 18 | * Sample reactive proxy arp application. |
| 19 | */ |
| 20 | @Component(immediate = true) |
| 21 | public class ProxyArp { |
| 22 | |
| 23 | |
| 24 | private final Logger log = getLogger(getClass()); |
| 25 | |
| 26 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 27 | protected PacketService packetService; |
| 28 | |
| 29 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 30 | protected ProxyArpService proxyArpService; |
| 31 | |
| 32 | private ProxyArpProcessor processor = new ProxyArpProcessor(); |
| 33 | |
| 34 | private ApplicationId appId; |
| 35 | |
| 36 | @Activate |
| 37 | public void activate() { |
| 38 | appId = ApplicationId.getAppId(); |
| 39 | packetService.addProcessor(processor, PacketProcessor.ADVISOR_MAX + 1); |
| 40 | log.info("Started with Application ID {}", appId.id()); |
| 41 | } |
| 42 | |
| 43 | @Deactivate |
| 44 | public void deactivate() { |
| 45 | packetService.removeProcessor(processor); |
| 46 | processor = null; |
| 47 | log.info("Stopped"); |
| 48 | } |
| 49 | |
| 50 | |
| 51 | /** |
| 52 | * Packet processor responsible for forwarding packets along their paths. |
| 53 | */ |
| 54 | private class ProxyArpProcessor implements PacketProcessor { |
| 55 | |
| 56 | @Override |
| 57 | public void process(PacketContext context) { |
| 58 | // Stop processing if the packet has been handled, since we |
| 59 | // can't do any more to it. |
| 60 | if (context.isHandled()) { |
| 61 | return; |
| 62 | } |
| 63 | |
| 64 | //handle the arp packet. |
| 65 | proxyArpService.handleArp(context); |
| 66 | } |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | |