blob: f0dce524863db63f7aa46c6f204bb0e3552401c3 [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 */
Brian O'Connorabafb502014-12-02 22:26:20 -080016package org.onosproject.proxyarp;
alshabibc274c902014-10-03 14:58:27 -070017
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;
Jonathan Hart3cfce8e2015-01-14 16:43:27 -080025import org.onlab.packet.Ethernet;
Brian O'Connorabafb502014-12-02 22:26:20 -080026import org.onosproject.core.ApplicationId;
27import org.onosproject.core.CoreService;
Jonathan Hart3cfce8e2015-01-14 16:43:27 -080028import org.onosproject.net.flow.DefaultTrafficSelector;
29import org.onosproject.net.flow.TrafficSelector;
Brian O'Connorabafb502014-12-02 22:26:20 -080030import org.onosproject.net.packet.PacketContext;
Jonathan Hart3cfce8e2015-01-14 16:43:27 -080031import org.onosproject.net.packet.PacketPriority;
Brian O'Connorabafb502014-12-02 22:26:20 -080032import org.onosproject.net.packet.PacketProcessor;
33import org.onosproject.net.packet.PacketService;
34import org.onosproject.net.proxyarp.ProxyArpService;
alshabibc274c902014-10-03 14:58:27 -070035import org.slf4j.Logger;
36
37/**
38 * Sample reactive proxy arp application.
39 */
40@Component(immediate = true)
41public class ProxyArp {
42
alshabibc274c902014-10-03 14:58:27 -070043 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
alshabib92c65ad2014-10-08 21:56:05 -070053 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
54 protected CoreService coreService;
55
alshabibc274c902014-10-03 14:58:27 -070056 private ApplicationId appId;
57
58 @Activate
59 public void activate() {
Brian O'Connorabafb502014-12-02 22:26:20 -080060 appId = coreService.registerApplication("org.onosproject.proxyarp");
alshabibc274c902014-10-03 14:58:27 -070061 packetService.addProcessor(processor, PacketProcessor.ADVISOR_MAX + 1);
Jonathan Hart3cfce8e2015-01-14 16:43:27 -080062
63 TrafficSelector.Builder selectorBuilder =
64 DefaultTrafficSelector.builder();
65 selectorBuilder.matchEthType(Ethernet.TYPE_ARP);
66 packetService.requestPackets(selectorBuilder.build(),
67 PacketPriority.CONTROL, appId);
68
alshabibc274c902014-10-03 14:58:27 -070069 log.info("Started with Application ID {}", appId.id());
70 }
71
72 @Deactivate
73 public void deactivate() {
74 packetService.removeProcessor(processor);
75 processor = null;
76 log.info("Stopped");
77 }
78
79
80 /**
81 * Packet processor responsible for forwarding packets along their paths.
82 */
83 private class ProxyArpProcessor implements PacketProcessor {
84
85 @Override
86 public void process(PacketContext context) {
87 // Stop processing if the packet has been handled, since we
88 // can't do any more to it.
89 if (context.isHandled()) {
90 return;
91 }
92
93 //handle the arp packet.
Kunihiro Ishigurof1bff502015-01-30 15:47:06 -080094 proxyArpService.handlePacket(context);
alshabibc274c902014-10-03 14:58:27 -070095 }
96 }
97}
98
99