Thomas Vachuska | 781d18b | 2014-10-27 10:31:25 -0700 | [diff] [blame] | 1 | /* |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 2 | * Copyright 2014 Open Networking Laboratory |
Thomas Vachuska | 781d18b | 2014-10-27 10:31:25 -0700 | [diff] [blame] | 3 | * |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 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 |
Thomas Vachuska | 781d18b | 2014-10-27 10:31:25 -0700 | [diff] [blame] | 7 | * |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 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. |
Thomas Vachuska | 781d18b | 2014-10-27 10:31:25 -0700 | [diff] [blame] | 15 | */ |
alshabib | c274c90 | 2014-10-03 14:58:27 -0700 | [diff] [blame] | 16 | package org.onlab.onos.proxyarp; |
| 17 | |
| 18 | import static org.slf4j.LoggerFactory.getLogger; |
| 19 | |
| 20 | import org.apache.felix.scr.annotations.Activate; |
| 21 | import org.apache.felix.scr.annotations.Component; |
| 22 | import org.apache.felix.scr.annotations.Deactivate; |
| 23 | import org.apache.felix.scr.annotations.Reference; |
| 24 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
Thomas Vachuska | e0f804a | 2014-10-27 23:40:48 -0700 | [diff] [blame] | 25 | import org.onlab.onos.core.ApplicationId; |
| 26 | import org.onlab.onos.core.CoreService; |
alshabib | c274c90 | 2014-10-03 14:58:27 -0700 | [diff] [blame] | 27 | import org.onlab.onos.net.packet.PacketContext; |
| 28 | import org.onlab.onos.net.packet.PacketProcessor; |
| 29 | import org.onlab.onos.net.packet.PacketService; |
| 30 | import org.onlab.onos.net.proxyarp.ProxyArpService; |
| 31 | import org.slf4j.Logger; |
| 32 | |
| 33 | /** |
| 34 | * Sample reactive proxy arp application. |
| 35 | */ |
| 36 | @Component(immediate = true) |
| 37 | public class ProxyArp { |
| 38 | |
| 39 | |
| 40 | private final Logger log = getLogger(getClass()); |
| 41 | |
| 42 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 43 | protected PacketService packetService; |
| 44 | |
| 45 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 46 | protected ProxyArpService proxyArpService; |
| 47 | |
| 48 | private ProxyArpProcessor processor = new ProxyArpProcessor(); |
| 49 | |
alshabib | 92c65ad | 2014-10-08 21:56:05 -0700 | [diff] [blame] | 50 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 51 | protected CoreService coreService; |
| 52 | |
alshabib | c274c90 | 2014-10-03 14:58:27 -0700 | [diff] [blame] | 53 | private ApplicationId appId; |
| 54 | |
| 55 | @Activate |
| 56 | public void activate() { |
alshabib | 92c65ad | 2014-10-08 21:56:05 -0700 | [diff] [blame] | 57 | appId = coreService.registerApplication("org.onlab.onos.proxyarp"); |
alshabib | c274c90 | 2014-10-03 14:58:27 -0700 | [diff] [blame] | 58 | packetService.addProcessor(processor, PacketProcessor.ADVISOR_MAX + 1); |
| 59 | log.info("Started with Application ID {}", appId.id()); |
| 60 | } |
| 61 | |
| 62 | @Deactivate |
| 63 | public void deactivate() { |
| 64 | packetService.removeProcessor(processor); |
| 65 | processor = null; |
| 66 | log.info("Stopped"); |
| 67 | } |
| 68 | |
| 69 | |
| 70 | /** |
| 71 | * Packet processor responsible for forwarding packets along their paths. |
| 72 | */ |
| 73 | private class ProxyArpProcessor implements PacketProcessor { |
| 74 | |
| 75 | @Override |
| 76 | public void process(PacketContext context) { |
| 77 | // Stop processing if the packet has been handled, since we |
| 78 | // can't do any more to it. |
| 79 | if (context.isHandled()) { |
| 80 | return; |
| 81 | } |
| 82 | |
| 83 | //handle the arp packet. |
| 84 | proxyArpService.handleArp(context); |
| 85 | } |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | |