Thomas Vachuska | 781d18b | 2014-10-27 10:31:25 -0700 | [diff] [blame^] | 1 | /* |
| 2 | * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | * or more contributor license agreements. See the NOTICE file |
| 4 | * distributed with this work for additional information |
| 5 | * regarding copyright ownership. The ASF licenses this file |
| 6 | * to you under the Apache License, Version 2.0 (the |
| 7 | * "License"); you may not use this file except in compliance |
| 8 | * with the License. You may obtain a copy of the License at |
| 9 | * |
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | * |
| 12 | * Unless required by applicable law or agreed to in writing, |
| 13 | * software distributed under the License is distributed on an |
| 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | * KIND, either express or implied. See the License for the |
| 16 | * specific language governing permissions and limitations |
| 17 | * under the License. |
| 18 | */ |
alshabib | c274c90 | 2014-10-03 14:58:27 -0700 | [diff] [blame] | 19 | package org.onlab.onos.proxyarp; |
| 20 | |
| 21 | import static org.slf4j.LoggerFactory.getLogger; |
| 22 | |
| 23 | import org.apache.felix.scr.annotations.Activate; |
| 24 | import org.apache.felix.scr.annotations.Component; |
| 25 | import org.apache.felix.scr.annotations.Deactivate; |
| 26 | import org.apache.felix.scr.annotations.Reference; |
| 27 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
| 28 | import org.onlab.onos.ApplicationId; |
alshabib | 92c65ad | 2014-10-08 21:56:05 -0700 | [diff] [blame] | 29 | import org.onlab.onos.CoreService; |
alshabib | c274c90 | 2014-10-03 14:58:27 -0700 | [diff] [blame] | 30 | import org.onlab.onos.net.packet.PacketContext; |
| 31 | import org.onlab.onos.net.packet.PacketProcessor; |
| 32 | import org.onlab.onos.net.packet.PacketService; |
| 33 | import org.onlab.onos.net.proxyarp.ProxyArpService; |
| 34 | import org.slf4j.Logger; |
| 35 | |
| 36 | /** |
| 37 | * Sample reactive proxy arp application. |
| 38 | */ |
| 39 | @Component(immediate = true) |
| 40 | public class ProxyArp { |
| 41 | |
| 42 | |
| 43 | private final Logger log = getLogger(getClass()); |
| 44 | |
| 45 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 46 | protected PacketService packetService; |
| 47 | |
| 48 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 49 | protected ProxyArpService proxyArpService; |
| 50 | |
| 51 | private ProxyArpProcessor processor = new ProxyArpProcessor(); |
| 52 | |
alshabib | 92c65ad | 2014-10-08 21:56:05 -0700 | [diff] [blame] | 53 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 54 | protected CoreService coreService; |
| 55 | |
alshabib | c274c90 | 2014-10-03 14:58:27 -0700 | [diff] [blame] | 56 | private ApplicationId appId; |
| 57 | |
| 58 | @Activate |
| 59 | public void activate() { |
alshabib | 92c65ad | 2014-10-08 21:56:05 -0700 | [diff] [blame] | 60 | appId = coreService.registerApplication("org.onlab.onos.proxyarp"); |
alshabib | c274c90 | 2014-10-03 14:58:27 -0700 | [diff] [blame] | 61 | packetService.addProcessor(processor, PacketProcessor.ADVISOR_MAX + 1); |
| 62 | log.info("Started with Application ID {}", appId.id()); |
| 63 | } |
| 64 | |
| 65 | @Deactivate |
| 66 | public void deactivate() { |
| 67 | packetService.removeProcessor(processor); |
| 68 | processor = null; |
| 69 | log.info("Stopped"); |
| 70 | } |
| 71 | |
| 72 | |
| 73 | /** |
| 74 | * Packet processor responsible for forwarding packets along their paths. |
| 75 | */ |
| 76 | private class ProxyArpProcessor implements PacketProcessor { |
| 77 | |
| 78 | @Override |
| 79 | public void process(PacketContext context) { |
| 80 | // Stop processing if the packet has been handled, since we |
| 81 | // can't do any more to it. |
| 82 | if (context.isHandled()) { |
| 83 | return; |
| 84 | } |
| 85 | |
| 86 | //handle the arp packet. |
| 87 | proxyArpService.handleArp(context); |
| 88 | } |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | |