blob: 431c5d7024351a2b4d16b12305595ee119860225 [file] [log] [blame]
Thomas Vachuska781d18b2014-10-27 10:31:25 -07001/*
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 */
alshabibc274c902014-10-03 14:58:27 -070019package org.onlab.onos.proxyarp;
20
21import static org.slf4j.LoggerFactory.getLogger;
22
23import org.apache.felix.scr.annotations.Activate;
24import org.apache.felix.scr.annotations.Component;
25import org.apache.felix.scr.annotations.Deactivate;
26import org.apache.felix.scr.annotations.Reference;
27import org.apache.felix.scr.annotations.ReferenceCardinality;
28import org.onlab.onos.ApplicationId;
alshabib92c65ad2014-10-08 21:56:05 -070029import org.onlab.onos.CoreService;
alshabibc274c902014-10-03 14:58:27 -070030import org.onlab.onos.net.packet.PacketContext;
31import org.onlab.onos.net.packet.PacketProcessor;
32import org.onlab.onos.net.packet.PacketService;
33import org.onlab.onos.net.proxyarp.ProxyArpService;
34import org.slf4j.Logger;
35
36/**
37 * Sample reactive proxy arp application.
38 */
39@Component(immediate = true)
40public 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
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() {
alshabib92c65ad2014-10-08 21:56:05 -070060 appId = coreService.registerApplication("org.onlab.onos.proxyarp");
alshabibc274c902014-10-03 14:58:27 -070061 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