Showing
5 changed files
with
165 additions
and
2 deletions
apps/ifwd/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-ifwd</artifactId> | ||
15 | + <packaging>bundle</packaging> | ||
16 | + | ||
17 | + <description>ONOS simple reactive forwarding app that uses intent service</description> | ||
18 | + | ||
19 | +</project> |
1 | +package org.onlab.onos.ifwd; | ||
2 | + | ||
3 | +import org.apache.felix.scr.annotations.Activate; | ||
4 | +import org.apache.felix.scr.annotations.Component; | ||
5 | +import org.apache.felix.scr.annotations.Deactivate; | ||
6 | +import org.apache.felix.scr.annotations.Reference; | ||
7 | +import org.apache.felix.scr.annotations.ReferenceCardinality; | ||
8 | +import org.onlab.onos.ApplicationId; | ||
9 | +import org.onlab.onos.net.Host; | ||
10 | +import org.onlab.onos.net.HostId; | ||
11 | +import org.onlab.onos.net.PortNumber; | ||
12 | +import org.onlab.onos.net.flow.DefaultTrafficSelector; | ||
13 | +import org.onlab.onos.net.flow.DefaultTrafficTreatment; | ||
14 | +import org.onlab.onos.net.flow.TrafficSelector; | ||
15 | +import org.onlab.onos.net.flow.TrafficTreatment; | ||
16 | +import org.onlab.onos.net.host.HostService; | ||
17 | +import org.onlab.onos.net.intent.HostToHostIntent; | ||
18 | +import org.onlab.onos.net.intent.IntentId; | ||
19 | +import org.onlab.onos.net.intent.IntentService; | ||
20 | +import org.onlab.onos.net.packet.InboundPacket; | ||
21 | +import org.onlab.onos.net.packet.PacketContext; | ||
22 | +import org.onlab.onos.net.packet.PacketProcessor; | ||
23 | +import org.onlab.onos.net.packet.PacketService; | ||
24 | +import org.onlab.onos.net.topology.TopologyService; | ||
25 | +import org.onlab.packet.Ethernet; | ||
26 | +import org.slf4j.Logger; | ||
27 | + | ||
28 | +import static org.slf4j.LoggerFactory.getLogger; | ||
29 | + | ||
30 | +/** | ||
31 | + * WORK-IN-PROGRESS: Sample reactive forwarding application using intent framework. | ||
32 | + */ | ||
33 | +@Component(immediate = true) | ||
34 | +public class IntentReactiveForwarding { | ||
35 | + | ||
36 | + private static final int TIMEOUT = 10; | ||
37 | + private static final int PRIORITY = 10; | ||
38 | + | ||
39 | + private final Logger log = getLogger(getClass()); | ||
40 | + | ||
41 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
42 | + protected TopologyService topologyService; | ||
43 | + | ||
44 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
45 | + protected PacketService packetService; | ||
46 | + | ||
47 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
48 | + protected IntentService intentService; | ||
49 | + | ||
50 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
51 | + protected HostService hostService; | ||
52 | + | ||
53 | + private ReactivePacketProcessor processor = new ReactivePacketProcessor(); | ||
54 | + | ||
55 | + private ApplicationId appId; | ||
56 | + private static long intentId = 1; | ||
57 | + | ||
58 | + @Activate | ||
59 | + public void activate() { | ||
60 | + appId = ApplicationId.getAppId(); | ||
61 | + packetService.addProcessor(processor, PacketProcessor.ADVISOR_MAX + 2); | ||
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 ReactivePacketProcessor 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 | + InboundPacket pkt = context.inPacket(); | ||
87 | + Ethernet ethPkt = pkt.parsed(); | ||
88 | + | ||
89 | + HostId srcId = HostId.hostId(ethPkt.getSourceMAC()); | ||
90 | + HostId dstId = HostId.hostId(ethPkt.getDestinationMAC()); | ||
91 | + | ||
92 | + // Do we know who this is for? If not, flood and bail. | ||
93 | + Host dst = hostService.getHost(dstId); | ||
94 | + if (dst == null) { | ||
95 | + flood(context); | ||
96 | + return; | ||
97 | + } | ||
98 | + | ||
99 | + // Otherwise forward and be done with it. | ||
100 | + setUpConnectivity(context, srcId, dstId); | ||
101 | + } | ||
102 | + } | ||
103 | + | ||
104 | + // Floods the specified packet if permissible. | ||
105 | + private void flood(PacketContext context) { | ||
106 | + if (topologyService.isBroadcastPoint(topologyService.currentTopology(), | ||
107 | + context.inPacket().receivedFrom())) { | ||
108 | + packetOut(context, PortNumber.FLOOD); | ||
109 | + } else { | ||
110 | + context.block(); | ||
111 | + } | ||
112 | + } | ||
113 | + | ||
114 | + // Sends a packet out the specified port. | ||
115 | + private void packetOut(PacketContext context, PortNumber portNumber) { | ||
116 | + context.treatmentBuilder().setOutput(portNumber); | ||
117 | + context.send(); | ||
118 | + } | ||
119 | + | ||
120 | + // Install a rule forwarding the packet to the specified port. | ||
121 | + private void setUpConnectivity(PacketContext context, HostId srcId, HostId dstId) { | ||
122 | + TrafficSelector selector = DefaultTrafficSelector.builder().build(); | ||
123 | + TrafficTreatment treatment = DefaultTrafficTreatment.builder().build(); | ||
124 | + | ||
125 | + HostToHostIntent intent = | ||
126 | + new HostToHostIntent(new IntentId(intentId++), srcId, dstId, | ||
127 | + selector, treatment); | ||
128 | + | ||
129 | + intentService.submit(intent); | ||
130 | + } | ||
131 | + | ||
132 | +} | ||
133 | + | ||
134 | + |
... | @@ -19,6 +19,7 @@ | ... | @@ -19,6 +19,7 @@ |
19 | <modules> | 19 | <modules> |
20 | <module>tvue</module> | 20 | <module>tvue</module> |
21 | <module>fwd</module> | 21 | <module>fwd</module> |
22 | + <module>ifwd</module> | ||
22 | <module>foo</module> | 23 | <module>foo</module> |
23 | <module>mobility</module> | 24 | <module>mobility</module> |
24 | <module>proxyarp</module> | 25 | <module>proxyarp</module> | ... | ... |
... | @@ -120,6 +120,12 @@ | ... | @@ -120,6 +120,12 @@ |
120 | <bundle>mvn:org.onlab.onos/onos-app-fwd/1.0.0-SNAPSHOT</bundle> | 120 | <bundle>mvn:org.onlab.onos/onos-app-fwd/1.0.0-SNAPSHOT</bundle> |
121 | </feature> | 121 | </feature> |
122 | 122 | ||
123 | + <feature name="onos-app-ifwd" version="1.0.0" | ||
124 | + description="ONOS sample forwarding application using intents"> | ||
125 | + <feature>onos-api</feature> | ||
126 | + <bundle>mvn:org.onlab.onos/onos-app-ifwd/1.0.0-SNAPSHOT</bundle> | ||
127 | + </feature> | ||
128 | + | ||
123 | <feature name="onos-app-mobility" version="1.0.0" | 129 | <feature name="onos-app-mobility" version="1.0.0" |
124 | description="ONOS sample mobility application"> | 130 | description="ONOS sample mobility application"> |
125 | <feature>onos-api</feature> | 131 | <feature>onos-api</feature> |
... | @@ -132,8 +138,6 @@ | ... | @@ -132,8 +138,6 @@ |
132 | <bundle>mvn:org.onlab.onos/onos-app-proxyarp/1.0.0-SNAPSHOT</bundle> | 138 | <bundle>mvn:org.onlab.onos/onos-app-proxyarp/1.0.0-SNAPSHOT</bundle> |
133 | </feature> | 139 | </feature> |
134 | 140 | ||
135 | - | ||
136 | - | ||
137 | <feature name="onos-app-foo" version="1.0.0" | 141 | <feature name="onos-app-foo" version="1.0.0" |
138 | description="ONOS sample playground application"> | 142 | description="ONOS sample playground application"> |
139 | <feature>onos-api</feature> | 143 | <feature>onos-api</feature> | ... | ... |
-
Please register or login to post a comment