alshabib

proxy arp application

Change-Id: Ic2136537a4104e75b64ae4731e1bae4f3a4c1661
......@@ -26,9 +26,7 @@ import org.onlab.onos.net.packet.InboundPacket;
import org.onlab.onos.net.packet.PacketContext;
import org.onlab.onos.net.packet.PacketProcessor;
import org.onlab.onos.net.packet.PacketService;
import org.onlab.onos.net.proxyarp.ProxyArpService;
import org.onlab.onos.net.topology.TopologyService;
import org.onlab.packet.ARP;
import org.onlab.packet.Ethernet;
import org.slf4j.Logger;
......@@ -55,9 +53,6 @@ public class ReactiveForwarding {
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected FlowRuleService flowRuleService;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected ProxyArpService proxyArpService;
private ReactivePacketProcessor processor = new ReactivePacketProcessor();
private ApplicationId appId;
......@@ -65,7 +60,7 @@ public class ReactiveForwarding {
@Activate
public void activate() {
appId = ApplicationId.getAppId();
packetService.addProcessor(processor, PacketProcessor.ADVISOR_MAX + 1);
packetService.addProcessor(processor, PacketProcessor.ADVISOR_MAX + 2);
log.info("Started with Application ID {}", appId.id());
}
......@@ -93,16 +88,6 @@ public class ReactiveForwarding {
InboundPacket pkt = context.inPacket();
Ethernet ethPkt = pkt.parsed();
if (ethPkt.getEtherType() == Ethernet.TYPE_ARP) {
ARP arp = (ARP) ethPkt.getPayload();
if (arp.getOpCode() == ARP.OP_REPLY) {
proxyArpService.forward(ethPkt);
} else if (arp.getOpCode() == ARP.OP_REQUEST) {
proxyArpService.reply(ethPkt);
}
context.block();
return;
}
HostId id = HostId.hostId(ethPkt.getDestinationMAC());
......@@ -181,24 +166,24 @@ public class ReactiveForwarding {
// We don't yet support bufferids in the flowservice so packet out first.
packetOut(context, portNumber);
if (context.inPacket().parsed().getEtherType() == Ethernet.TYPE_IPV4) {
// Install the flow rule to handle this type of message from now on.
Ethernet inPkt = context.inPacket().parsed();
TrafficSelector.Builder builder = DefaultTrafficSelector.builder();
builder.matchEthType(inPkt.getEtherType())
.matchEthSrc(inPkt.getSourceMAC())
.matchEthDst(inPkt.getDestinationMAC())
.matchInport(context.inPacket().receivedFrom().port());
TrafficTreatment.Builder treat = DefaultTrafficTreatment.builder();
treat.setOutput(portNumber);
// Install the flow rule to handle this type of message from now on.
Ethernet inPkt = context.inPacket().parsed();
TrafficSelector.Builder builder = DefaultTrafficSelector.builder();
builder.matchEthType(inPkt.getEtherType())
.matchEthSrc(inPkt.getSourceMAC())
.matchEthDst(inPkt.getDestinationMAC())
.matchInport(context.inPacket().receivedFrom().port());
FlowRule f = new DefaultFlowRule(context.inPacket().receivedFrom().deviceId(),
builder.build(), treat.build(), PRIORITY, appId, TIMEOUT);
TrafficTreatment.Builder treat = DefaultTrafficTreatment.builder();
treat.setOutput(portNumber);
FlowRule f = new DefaultFlowRule(context.inPacket().receivedFrom().deviceId(),
builder.build(), treat.build(), PRIORITY, appId, TIMEOUT);
flowRuleService.applyFlowRules(f);
flowRuleService.applyFlowRules(f);
}
}
}
......
......@@ -21,6 +21,7 @@
<module>fwd</module>
<module>foo</module>
<module>mobility</module>
<module>proxyarp</module>
<module>config</module>
</modules>
......
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.onlab.onos</groupId>
<artifactId>onos-apps</artifactId>
<version>1.0.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>onos-app-proxyarp</artifactId>
<packaging>bundle</packaging>
<description>ONOS simple proxy arp module</description>
</project>
package org.onlab.onos.proxyarp;
import static org.slf4j.LoggerFactory.getLogger;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Deactivate;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.ReferenceCardinality;
import org.onlab.onos.ApplicationId;
import org.onlab.onos.net.packet.PacketContext;
import org.onlab.onos.net.packet.PacketProcessor;
import org.onlab.onos.net.packet.PacketService;
import org.onlab.onos.net.proxyarp.ProxyArpService;
import org.slf4j.Logger;
/**
* Sample reactive proxy arp application.
*/
@Component(immediate = true)
public class ProxyArp {
private final Logger log = getLogger(getClass());
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected PacketService packetService;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected ProxyArpService proxyArpService;
private ProxyArpProcessor processor = new ProxyArpProcessor();
private ApplicationId appId;
@Activate
public void activate() {
appId = ApplicationId.getAppId();
packetService.addProcessor(processor, PacketProcessor.ADVISOR_MAX + 1);
log.info("Started with Application ID {}", appId.id());
}
@Deactivate
public void deactivate() {
packetService.removeProcessor(processor);
processor = null;
log.info("Stopped");
}
/**
* Packet processor responsible for forwarding packets along their paths.
*/
private class ProxyArpProcessor implements PacketProcessor {
@Override
public void process(PacketContext context) {
// Stop processing if the packet has been handled, since we
// can't do any more to it.
if (context.isHandled()) {
return;
}
//handle the arp packet.
proxyArpService.handleArp(context);
}
}
}
/**
* Proxy Arp application that handles arp resolution for you.
*/
package org.onlab.onos.proxyarp;
package org.onlab.onos.net.proxyarp;
import org.onlab.onos.net.packet.PacketContext;
import org.onlab.packet.Ethernet;
import org.onlab.packet.IpPrefix;
......@@ -33,4 +34,12 @@ public interface ProxyArpService {
*/
void forward(Ethernet eth);
/**
* Handles a arp packet.
* Replies to arp requests and forwards request to the right place.
* @param context the packet context to handle
* @return true if handled, false otherwise.
*/
boolean handleArp(PacketContext context);
}
......
......@@ -158,7 +158,7 @@ implements FlowRuleService, FlowRuleProviderRegistry {
checkValidity();
FlowRule stored = store.getFlowRule(flowRule);
if (stored == null) {
log.debug("Rule already evicted from store: {}", flowRule);
log.info("Rule already evicted from store: {}", flowRule);
return;
}
Device device = deviceService.getDevice(flowRule.deviceId());
......@@ -247,8 +247,12 @@ implements FlowRuleService, FlowRuleProviderRegistry {
idleTime.put(swRule, currentTime);
return true;
}
return (currentTime - idleTime.get(swRule)) <= timeout;
if ((currentTime - idleTime.get(swRule)) <= timeout) {
idleTime.put(swRule, currentTime);
return true;
}
return false;
}
// Posts the specified event to the local event dispatcher.
......
......@@ -31,6 +31,8 @@ import org.onlab.onos.net.link.LinkEvent;
import org.onlab.onos.net.link.LinkListener;
import org.onlab.onos.net.link.LinkService;
import org.onlab.onos.net.packet.DefaultOutboundPacket;
import org.onlab.onos.net.packet.InboundPacket;
import org.onlab.onos.net.packet.PacketContext;
import org.onlab.onos.net.packet.PacketService;
import org.onlab.onos.net.proxyarp.ProxyArpService;
import org.onlab.packet.ARP;
......@@ -155,6 +157,23 @@ public class ProxyArpManager implements ProxyArpService {
}
@Override
public boolean handleArp(PacketContext context) {
InboundPacket pkt = context.inPacket();
Ethernet ethPkt = pkt.parsed();
if (ethPkt.getEtherType() == Ethernet.TYPE_ARP) {
ARP arp = (ARP) ethPkt.getPayload();
if (arp.getOpCode() == ARP.OP_REPLY) {
forward(ethPkt);
} else if (arp.getOpCode() == ARP.OP_REQUEST) {
reply(ethPkt);
}
context.block();
return true;
}
return false;
}
/**
* Flood the arp request at all edges in the network.
* @param request the arp request.
......@@ -321,7 +340,6 @@ public class ProxyArpManager implements ProxyArpService {
}
}
}
}
......
......@@ -121,11 +121,17 @@
</feature>
<feature name="onos-app-mobility" version="1.0.0"
description="ONOS sample forwarding application">
description="ONOS sample mobility application">
<feature>onos-api</feature>
<bundle>mvn:org.onlab.onos/onos-app-mobility/1.0.0-SNAPSHOT</bundle>
</feature>
<feature name="onos-app-proxyarp" version="1.0.0"
description="ONOS sample proxyarp application">
<feature>onos-api</feature>
<bundle>mvn:org.onlab.onos/onos-app-proxyarp/1.0.0-SNAPSHOT</bundle>
</feature>
<feature name="onos-app-foo" version="1.0.0"
......
......@@ -82,10 +82,9 @@ public class FlowRuleBuilder {
// TODO: revisit potentially.
return new DefaultFlowRule(DeviceId.deviceId(Dpid.uri(dpid)),
buildSelector(), null, removed.getPriority(),
FlowRuleState.REMOVED, stat.getDurationSec(),
FlowRuleState.REMOVED, removed.getDurationSec(),
removed.getPacketCount().getValue(), removed.getByteCount().getValue(),
removed.getCookie().getValue(),
stat.getIdleTimeout());
removed.getCookie().getValue(), removed.getIdleTimeout());
}
}
......