proxy arp application
Change-Id: Ic2136537a4104e75b64ae4731e1bae4f3a4c1661
Showing
10 changed files
with
153 additions
and
38 deletions
... | @@ -26,9 +26,7 @@ import org.onlab.onos.net.packet.InboundPacket; | ... | @@ -26,9 +26,7 @@ import org.onlab.onos.net.packet.InboundPacket; |
26 | import org.onlab.onos.net.packet.PacketContext; | 26 | import org.onlab.onos.net.packet.PacketContext; |
27 | import org.onlab.onos.net.packet.PacketProcessor; | 27 | import org.onlab.onos.net.packet.PacketProcessor; |
28 | import org.onlab.onos.net.packet.PacketService; | 28 | import org.onlab.onos.net.packet.PacketService; |
29 | -import org.onlab.onos.net.proxyarp.ProxyArpService; | ||
30 | import org.onlab.onos.net.topology.TopologyService; | 29 | import org.onlab.onos.net.topology.TopologyService; |
31 | -import org.onlab.packet.ARP; | ||
32 | import org.onlab.packet.Ethernet; | 30 | import org.onlab.packet.Ethernet; |
33 | import org.slf4j.Logger; | 31 | import org.slf4j.Logger; |
34 | 32 | ||
... | @@ -55,9 +53,6 @@ public class ReactiveForwarding { | ... | @@ -55,9 +53,6 @@ public class ReactiveForwarding { |
55 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 53 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
56 | protected FlowRuleService flowRuleService; | 54 | protected FlowRuleService flowRuleService; |
57 | 55 | ||
58 | - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
59 | - protected ProxyArpService proxyArpService; | ||
60 | - | ||
61 | private ReactivePacketProcessor processor = new ReactivePacketProcessor(); | 56 | private ReactivePacketProcessor processor = new ReactivePacketProcessor(); |
62 | 57 | ||
63 | private ApplicationId appId; | 58 | private ApplicationId appId; |
... | @@ -65,7 +60,7 @@ public class ReactiveForwarding { | ... | @@ -65,7 +60,7 @@ public class ReactiveForwarding { |
65 | @Activate | 60 | @Activate |
66 | public void activate() { | 61 | public void activate() { |
67 | appId = ApplicationId.getAppId(); | 62 | appId = ApplicationId.getAppId(); |
68 | - packetService.addProcessor(processor, PacketProcessor.ADVISOR_MAX + 1); | 63 | + packetService.addProcessor(processor, PacketProcessor.ADVISOR_MAX + 2); |
69 | log.info("Started with Application ID {}", appId.id()); | 64 | log.info("Started with Application ID {}", appId.id()); |
70 | } | 65 | } |
71 | 66 | ||
... | @@ -93,16 +88,6 @@ public class ReactiveForwarding { | ... | @@ -93,16 +88,6 @@ public class ReactiveForwarding { |
93 | 88 | ||
94 | InboundPacket pkt = context.inPacket(); | 89 | InboundPacket pkt = context.inPacket(); |
95 | Ethernet ethPkt = pkt.parsed(); | 90 | Ethernet ethPkt = pkt.parsed(); |
96 | - if (ethPkt.getEtherType() == Ethernet.TYPE_ARP) { | ||
97 | - ARP arp = (ARP) ethPkt.getPayload(); | ||
98 | - if (arp.getOpCode() == ARP.OP_REPLY) { | ||
99 | - proxyArpService.forward(ethPkt); | ||
100 | - } else if (arp.getOpCode() == ARP.OP_REQUEST) { | ||
101 | - proxyArpService.reply(ethPkt); | ||
102 | - } | ||
103 | - context.block(); | ||
104 | - return; | ||
105 | - } | ||
106 | 91 | ||
107 | HostId id = HostId.hostId(ethPkt.getDestinationMAC()); | 92 | HostId id = HostId.hostId(ethPkt.getDestinationMAC()); |
108 | 93 | ||
... | @@ -181,24 +166,24 @@ public class ReactiveForwarding { | ... | @@ -181,24 +166,24 @@ public class ReactiveForwarding { |
181 | // We don't yet support bufferids in the flowservice so packet out first. | 166 | // We don't yet support bufferids in the flowservice so packet out first. |
182 | packetOut(context, portNumber); | 167 | packetOut(context, portNumber); |
183 | 168 | ||
184 | - if (context.inPacket().parsed().getEtherType() == Ethernet.TYPE_IPV4) { | ||
185 | 169 | ||
186 | - // Install the flow rule to handle this type of message from now on. | ||
187 | - Ethernet inPkt = context.inPacket().parsed(); | ||
188 | - TrafficSelector.Builder builder = DefaultTrafficSelector.builder(); | ||
189 | - builder.matchEthType(inPkt.getEtherType()) | ||
190 | - .matchEthSrc(inPkt.getSourceMAC()) | ||
191 | - .matchEthDst(inPkt.getDestinationMAC()) | ||
192 | - .matchInport(context.inPacket().receivedFrom().port()); | ||
193 | 170 | ||
194 | - TrafficTreatment.Builder treat = DefaultTrafficTreatment.builder(); | 171 | + // Install the flow rule to handle this type of message from now on. |
195 | - treat.setOutput(portNumber); | 172 | + Ethernet inPkt = context.inPacket().parsed(); |
173 | + TrafficSelector.Builder builder = DefaultTrafficSelector.builder(); | ||
174 | + builder.matchEthType(inPkt.getEtherType()) | ||
175 | + .matchEthSrc(inPkt.getSourceMAC()) | ||
176 | + .matchEthDst(inPkt.getDestinationMAC()) | ||
177 | + .matchInport(context.inPacket().receivedFrom().port()); | ||
196 | 178 | ||
197 | - FlowRule f = new DefaultFlowRule(context.inPacket().receivedFrom().deviceId(), | 179 | + TrafficTreatment.Builder treat = DefaultTrafficTreatment.builder(); |
198 | - builder.build(), treat.build(), PRIORITY, appId, TIMEOUT); | 180 | + treat.setOutput(portNumber); |
181 | + | ||
182 | + FlowRule f = new DefaultFlowRule(context.inPacket().receivedFrom().deviceId(), | ||
183 | + builder.build(), treat.build(), PRIORITY, appId, TIMEOUT); | ||
184 | + | ||
185 | + flowRuleService.applyFlowRules(f); | ||
199 | 186 | ||
200 | - flowRuleService.applyFlowRules(f); | ||
201 | - } | ||
202 | } | 187 | } |
203 | 188 | ||
204 | } | 189 | } | ... | ... |
... | @@ -21,6 +21,7 @@ | ... | @@ -21,6 +21,7 @@ |
21 | <module>fwd</module> | 21 | <module>fwd</module> |
22 | <module>foo</module> | 22 | <module>foo</module> |
23 | <module>mobility</module> | 23 | <module>mobility</module> |
24 | + <module>proxyarp</module> | ||
24 | <module>config</module> | 25 | <module>config</module> |
25 | </modules> | 26 | </modules> |
26 | 27 | ... | ... |
apps/proxyarp/pom.xml
0 → 100644
1 | +<?xml version="1.0" encoding="UTF-8"?> | ||
2 | +<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
3 | + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
4 | + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | ||
5 | + <modelVersion>4.0.0</modelVersion> | ||
6 | + | ||
7 | + <parent> | ||
8 | + <groupId>org.onlab.onos</groupId> | ||
9 | + <artifactId>onos-apps</artifactId> | ||
10 | + <version>1.0.0-SNAPSHOT</version> | ||
11 | + <relativePath>../pom.xml</relativePath> | ||
12 | + </parent> | ||
13 | + | ||
14 | + <artifactId>onos-app-proxyarp</artifactId> | ||
15 | + <packaging>bundle</packaging> | ||
16 | + | ||
17 | + <description>ONOS simple proxy arp module</description> | ||
18 | + | ||
19 | +</project> |
1 | +package org.onlab.onos.proxyarp; | ||
2 | + | ||
3 | +import static org.slf4j.LoggerFactory.getLogger; | ||
4 | + | ||
5 | +import org.apache.felix.scr.annotations.Activate; | ||
6 | +import org.apache.felix.scr.annotations.Component; | ||
7 | +import org.apache.felix.scr.annotations.Deactivate; | ||
8 | +import org.apache.felix.scr.annotations.Reference; | ||
9 | +import org.apache.felix.scr.annotations.ReferenceCardinality; | ||
10 | +import org.onlab.onos.ApplicationId; | ||
11 | +import org.onlab.onos.net.packet.PacketContext; | ||
12 | +import org.onlab.onos.net.packet.PacketProcessor; | ||
13 | +import org.onlab.onos.net.packet.PacketService; | ||
14 | +import org.onlab.onos.net.proxyarp.ProxyArpService; | ||
15 | +import org.slf4j.Logger; | ||
16 | + | ||
17 | +/** | ||
18 | + * Sample reactive proxy arp application. | ||
19 | + */ | ||
20 | +@Component(immediate = true) | ||
21 | +public class ProxyArp { | ||
22 | + | ||
23 | + | ||
24 | + private final Logger log = getLogger(getClass()); | ||
25 | + | ||
26 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
27 | + protected PacketService packetService; | ||
28 | + | ||
29 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
30 | + protected ProxyArpService proxyArpService; | ||
31 | + | ||
32 | + private ProxyArpProcessor processor = new ProxyArpProcessor(); | ||
33 | + | ||
34 | + private ApplicationId appId; | ||
35 | + | ||
36 | + @Activate | ||
37 | + public void activate() { | ||
38 | + appId = ApplicationId.getAppId(); | ||
39 | + packetService.addProcessor(processor, PacketProcessor.ADVISOR_MAX + 1); | ||
40 | + log.info("Started with Application ID {}", appId.id()); | ||
41 | + } | ||
42 | + | ||
43 | + @Deactivate | ||
44 | + public void deactivate() { | ||
45 | + packetService.removeProcessor(processor); | ||
46 | + processor = null; | ||
47 | + log.info("Stopped"); | ||
48 | + } | ||
49 | + | ||
50 | + | ||
51 | + /** | ||
52 | + * Packet processor responsible for forwarding packets along their paths. | ||
53 | + */ | ||
54 | + private class ProxyArpProcessor implements PacketProcessor { | ||
55 | + | ||
56 | + @Override | ||
57 | + public void process(PacketContext context) { | ||
58 | + // Stop processing if the packet has been handled, since we | ||
59 | + // can't do any more to it. | ||
60 | + if (context.isHandled()) { | ||
61 | + return; | ||
62 | + } | ||
63 | + | ||
64 | + //handle the arp packet. | ||
65 | + proxyArpService.handleArp(context); | ||
66 | + } | ||
67 | + } | ||
68 | +} | ||
69 | + | ||
70 | + |
1 | package org.onlab.onos.net.proxyarp; | 1 | package org.onlab.onos.net.proxyarp; |
2 | 2 | ||
3 | +import org.onlab.onos.net.packet.PacketContext; | ||
3 | import org.onlab.packet.Ethernet; | 4 | import org.onlab.packet.Ethernet; |
4 | import org.onlab.packet.IpPrefix; | 5 | import org.onlab.packet.IpPrefix; |
5 | 6 | ||
... | @@ -33,4 +34,12 @@ public interface ProxyArpService { | ... | @@ -33,4 +34,12 @@ public interface ProxyArpService { |
33 | */ | 34 | */ |
34 | void forward(Ethernet eth); | 35 | void forward(Ethernet eth); |
35 | 36 | ||
37 | + /** | ||
38 | + * Handles a arp packet. | ||
39 | + * Replies to arp requests and forwards request to the right place. | ||
40 | + * @param context the packet context to handle | ||
41 | + * @return true if handled, false otherwise. | ||
42 | + */ | ||
43 | + boolean handleArp(PacketContext context); | ||
44 | + | ||
36 | } | 45 | } | ... | ... |
... | @@ -158,7 +158,7 @@ implements FlowRuleService, FlowRuleProviderRegistry { | ... | @@ -158,7 +158,7 @@ implements FlowRuleService, FlowRuleProviderRegistry { |
158 | checkValidity(); | 158 | checkValidity(); |
159 | FlowRule stored = store.getFlowRule(flowRule); | 159 | FlowRule stored = store.getFlowRule(flowRule); |
160 | if (stored == null) { | 160 | if (stored == null) { |
161 | - log.debug("Rule already evicted from store: {}", flowRule); | 161 | + log.info("Rule already evicted from store: {}", flowRule); |
162 | return; | 162 | return; |
163 | } | 163 | } |
164 | Device device = deviceService.getDevice(flowRule.deviceId()); | 164 | Device device = deviceService.getDevice(flowRule.deviceId()); |
... | @@ -247,8 +247,12 @@ implements FlowRuleService, FlowRuleProviderRegistry { | ... | @@ -247,8 +247,12 @@ implements FlowRuleService, FlowRuleProviderRegistry { |
247 | idleTime.put(swRule, currentTime); | 247 | idleTime.put(swRule, currentTime); |
248 | return true; | 248 | return true; |
249 | } | 249 | } |
250 | - return (currentTime - idleTime.get(swRule)) <= timeout; | ||
251 | 250 | ||
251 | + if ((currentTime - idleTime.get(swRule)) <= timeout) { | ||
252 | + idleTime.put(swRule, currentTime); | ||
253 | + return true; | ||
254 | + } | ||
255 | + return false; | ||
252 | } | 256 | } |
253 | 257 | ||
254 | // Posts the specified event to the local event dispatcher. | 258 | // Posts the specified event to the local event dispatcher. | ... | ... |
... | @@ -31,6 +31,8 @@ import org.onlab.onos.net.link.LinkEvent; | ... | @@ -31,6 +31,8 @@ import org.onlab.onos.net.link.LinkEvent; |
31 | import org.onlab.onos.net.link.LinkListener; | 31 | import org.onlab.onos.net.link.LinkListener; |
32 | import org.onlab.onos.net.link.LinkService; | 32 | import org.onlab.onos.net.link.LinkService; |
33 | import org.onlab.onos.net.packet.DefaultOutboundPacket; | 33 | import org.onlab.onos.net.packet.DefaultOutboundPacket; |
34 | +import org.onlab.onos.net.packet.InboundPacket; | ||
35 | +import org.onlab.onos.net.packet.PacketContext; | ||
34 | import org.onlab.onos.net.packet.PacketService; | 36 | import org.onlab.onos.net.packet.PacketService; |
35 | import org.onlab.onos.net.proxyarp.ProxyArpService; | 37 | import org.onlab.onos.net.proxyarp.ProxyArpService; |
36 | import org.onlab.packet.ARP; | 38 | import org.onlab.packet.ARP; |
... | @@ -155,6 +157,23 @@ public class ProxyArpManager implements ProxyArpService { | ... | @@ -155,6 +157,23 @@ public class ProxyArpManager implements ProxyArpService { |
155 | 157 | ||
156 | } | 158 | } |
157 | 159 | ||
160 | + @Override | ||
161 | + public boolean handleArp(PacketContext context) { | ||
162 | + InboundPacket pkt = context.inPacket(); | ||
163 | + Ethernet ethPkt = pkt.parsed(); | ||
164 | + if (ethPkt.getEtherType() == Ethernet.TYPE_ARP) { | ||
165 | + ARP arp = (ARP) ethPkt.getPayload(); | ||
166 | + if (arp.getOpCode() == ARP.OP_REPLY) { | ||
167 | + forward(ethPkt); | ||
168 | + } else if (arp.getOpCode() == ARP.OP_REQUEST) { | ||
169 | + reply(ethPkt); | ||
170 | + } | ||
171 | + context.block(); | ||
172 | + return true; | ||
173 | + } | ||
174 | + return false; | ||
175 | + } | ||
176 | + | ||
158 | /** | 177 | /** |
159 | * Flood the arp request at all edges in the network. | 178 | * Flood the arp request at all edges in the network. |
160 | * @param request the arp request. | 179 | * @param request the arp request. |
... | @@ -321,7 +340,6 @@ public class ProxyArpManager implements ProxyArpService { | ... | @@ -321,7 +340,6 @@ public class ProxyArpManager implements ProxyArpService { |
321 | 340 | ||
322 | } | 341 | } |
323 | 342 | ||
324 | -} | 343 | + } |
325 | - | ||
326 | 344 | ||
327 | } | 345 | } | ... | ... |
... | @@ -121,11 +121,17 @@ | ... | @@ -121,11 +121,17 @@ |
121 | </feature> | 121 | </feature> |
122 | 122 | ||
123 | <feature name="onos-app-mobility" version="1.0.0" | 123 | <feature name="onos-app-mobility" version="1.0.0" |
124 | - description="ONOS sample forwarding application"> | 124 | + description="ONOS sample mobility application"> |
125 | <feature>onos-api</feature> | 125 | <feature>onos-api</feature> |
126 | <bundle>mvn:org.onlab.onos/onos-app-mobility/1.0.0-SNAPSHOT</bundle> | 126 | <bundle>mvn:org.onlab.onos/onos-app-mobility/1.0.0-SNAPSHOT</bundle> |
127 | </feature> | 127 | </feature> |
128 | 128 | ||
129 | + <feature name="onos-app-proxyarp" version="1.0.0" | ||
130 | + description="ONOS sample proxyarp application"> | ||
131 | + <feature>onos-api</feature> | ||
132 | + <bundle>mvn:org.onlab.onos/onos-app-proxyarp/1.0.0-SNAPSHOT</bundle> | ||
133 | + </feature> | ||
134 | + | ||
129 | 135 | ||
130 | 136 | ||
131 | <feature name="onos-app-foo" version="1.0.0" | 137 | <feature name="onos-app-foo" version="1.0.0" | ... | ... |
... | @@ -82,10 +82,9 @@ public class FlowRuleBuilder { | ... | @@ -82,10 +82,9 @@ public class FlowRuleBuilder { |
82 | // TODO: revisit potentially. | 82 | // TODO: revisit potentially. |
83 | return new DefaultFlowRule(DeviceId.deviceId(Dpid.uri(dpid)), | 83 | return new DefaultFlowRule(DeviceId.deviceId(Dpid.uri(dpid)), |
84 | buildSelector(), null, removed.getPriority(), | 84 | buildSelector(), null, removed.getPriority(), |
85 | - FlowRuleState.REMOVED, stat.getDurationSec(), | 85 | + FlowRuleState.REMOVED, removed.getDurationSec(), |
86 | removed.getPacketCount().getValue(), removed.getByteCount().getValue(), | 86 | removed.getPacketCount().getValue(), removed.getByteCount().getValue(), |
87 | - removed.getCookie().getValue(), | 87 | + removed.getCookie().getValue(), removed.getIdleTimeout()); |
88 | - stat.getIdleTimeout()); | ||
89 | } | 88 | } |
90 | } | 89 | } |
91 | 90 | ... | ... |
-
Please register or login to post a comment