blob: 82ebef016a9dd05a78dc9e770b63a785a89284a5 [file] [log] [blame]
Thomas Vachuska781d18b2014-10-27 10:31:25 -07001/*
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07002 * Copyright 2014 Open Networking Laboratory
Thomas Vachuska781d18b2014-10-27 10:31:25 -07003 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07004 * 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 Vachuska781d18b2014-10-27 10:31:25 -07007 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07008 * 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 Vachuska781d18b2014-10-27 10:31:25 -070015 */
alshabibc274c902014-10-03 14:58:27 -070016package org.onlab.onos.proxyarp;
17
18import static org.slf4j.LoggerFactory.getLogger;
19
20import org.apache.felix.scr.annotations.Activate;
21import org.apache.felix.scr.annotations.Component;
22import org.apache.felix.scr.annotations.Deactivate;
23import org.apache.felix.scr.annotations.Reference;
24import org.apache.felix.scr.annotations.ReferenceCardinality;
Thomas Vachuskae0f804a2014-10-27 23:40:48 -070025import org.onlab.onos.core.ApplicationId;
26import org.onlab.onos.core.CoreService;
alshabibc274c902014-10-03 14:58:27 -070027import org.onlab.onos.net.packet.PacketContext;
28import org.onlab.onos.net.packet.PacketProcessor;
29import org.onlab.onos.net.packet.PacketService;
30import org.onlab.onos.net.proxyarp.ProxyArpService;
31import org.slf4j.Logger;
32
33/**
34 * Sample reactive proxy arp application.
35 */
36@Component(immediate = true)
37public 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
alshabib92c65ad2014-10-08 21:56:05 -070050 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
51 protected CoreService coreService;
52
alshabibc274c902014-10-03 14:58:27 -070053 private ApplicationId appId;
54
55 @Activate
56 public void activate() {
alshabib92c65ad2014-10-08 21:56:05 -070057 appId = coreService.registerApplication("org.onlab.onos.proxyarp");
alshabibc274c902014-10-03 14:58:27 -070058 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