tom

Added ability to configure reactive forwarding.

...@@ -16,4 +16,11 @@ ...@@ -16,4 +16,11 @@
16 16
17 <description>ONOS simple reactive forwarding app</description> 17 <description>ONOS simple reactive forwarding app</description>
18 18
19 + <dependencies>
20 + <dependency>
21 + <groupId>org.osgi</groupId>
22 + <artifactId>org.osgi.compendium</artifactId>
23 + </dependency>
24 + </dependencies>
25 +
19 </project> 26 </project>
......
1 package org.onlab.onos.fwd; 1 package org.onlab.onos.fwd;
2 2
3 -import static org.slf4j.LoggerFactory.getLogger;
4 -
5 -import java.util.Set;
6 -
7 import org.apache.felix.scr.annotations.Activate; 3 import org.apache.felix.scr.annotations.Activate;
8 import org.apache.felix.scr.annotations.Component; 4 import org.apache.felix.scr.annotations.Component;
9 import org.apache.felix.scr.annotations.Deactivate; 5 import org.apache.felix.scr.annotations.Deactivate;
6 +import org.apache.felix.scr.annotations.Modified;
7 +import org.apache.felix.scr.annotations.Property;
10 import org.apache.felix.scr.annotations.Reference; 8 import org.apache.felix.scr.annotations.Reference;
11 import org.apache.felix.scr.annotations.ReferenceCardinality; 9 import org.apache.felix.scr.annotations.ReferenceCardinality;
12 import org.onlab.onos.ApplicationId; 10 import org.onlab.onos.ApplicationId;
...@@ -29,8 +27,14 @@ import org.onlab.onos.net.packet.PacketProcessor; ...@@ -29,8 +27,14 @@ import org.onlab.onos.net.packet.PacketProcessor;
29 import org.onlab.onos.net.packet.PacketService; 27 import org.onlab.onos.net.packet.PacketService;
30 import org.onlab.onos.net.topology.TopologyService; 28 import org.onlab.onos.net.topology.TopologyService;
31 import org.onlab.packet.Ethernet; 29 import org.onlab.packet.Ethernet;
30 +import org.osgi.service.component.ComponentContext;
32 import org.slf4j.Logger; 31 import org.slf4j.Logger;
33 32
33 +import java.util.Dictionary;
34 +import java.util.Set;
35 +
36 +import static org.slf4j.LoggerFactory.getLogger;
37 +
34 /** 38 /**
35 * Sample reactive forwarding application. 39 * Sample reactive forwarding application.
36 */ 40 */
...@@ -61,6 +65,9 @@ public class ReactiveForwarding { ...@@ -61,6 +65,9 @@ public class ReactiveForwarding {
61 65
62 private ApplicationId appId; 66 private ApplicationId appId;
63 67
68 + @Property(name = "enabled", boolValue = true, label = "Forwarding enabled")
69 + private boolean isEnabled = true;
70 +
64 @Activate 71 @Activate
65 public void activate() { 72 public void activate() {
66 appId = coreService.registerApplication("org.onlab.onos.fwd"); 73 appId = coreService.registerApplication("org.onlab.onos.fwd");
...@@ -76,6 +83,21 @@ public class ReactiveForwarding { ...@@ -76,6 +83,21 @@ public class ReactiveForwarding {
76 log.info("Stopped"); 83 log.info("Stopped");
77 } 84 }
78 85
86 + @Modified
87 + public void modified(ComponentContext context) {
88 + Dictionary properties = context.getProperties();
89 + String flag = (String) properties.get("enabled");
90 + if (flag != null) {
91 + boolean enabled = flag.equals("true");
92 + if (isEnabled != enabled) {
93 + isEnabled = enabled;
94 + if (!isEnabled) {
95 + flowRuleService.removeFlowRulesById(appId);
96 + }
97 + log.info("Reconfigured enabled = {}", isEnabled);
98 + }
99 + }
100 + }
79 101
80 /** 102 /**
81 * Packet processor responsible for forwarding packets along their paths. 103 * Packet processor responsible for forwarding packets along their paths.
...@@ -86,7 +108,7 @@ public class ReactiveForwarding { ...@@ -86,7 +108,7 @@ public class ReactiveForwarding {
86 public void process(PacketContext context) { 108 public void process(PacketContext context) {
87 // Stop processing if the packet has been handled, since we 109 // Stop processing if the packet has been handled, since we
88 // can't do any more to it. 110 // can't do any more to it.
89 - if (context.isHandled()) { 111 + if (!isEnabled || context.isHandled()) {
90 return; 112 return;
91 } 113 }
92 114
...@@ -114,8 +136,8 @@ public class ReactiveForwarding { ...@@ -114,8 +136,8 @@ public class ReactiveForwarding {
114 // Otherwise, get a set of paths that lead from here to the 136 // Otherwise, get a set of paths that lead from here to the
115 // destination edge switch. 137 // destination edge switch.
116 Set<Path> paths = topologyService.getPaths(topologyService.currentTopology(), 138 Set<Path> paths = topologyService.getPaths(topologyService.currentTopology(),
117 - pkt.receivedFrom().deviceId(), 139 + pkt.receivedFrom().deviceId(),
118 - dst.location().deviceId()); 140 + dst.location().deviceId());
119 if (paths.isEmpty()) { 141 if (paths.isEmpty()) {
120 // If there are no paths, flood and bail. 142 // If there are no paths, flood and bail.
121 flood(context); 143 flood(context);
...@@ -127,8 +149,8 @@ public class ReactiveForwarding { ...@@ -127,8 +149,8 @@ public class ReactiveForwarding {
127 Path path = pickForwardPath(paths, pkt.receivedFrom().port()); 149 Path path = pickForwardPath(paths, pkt.receivedFrom().port());
128 if (path == null) { 150 if (path == null) {
129 log.warn("Doh... don't know where to go... {} -> {} received on {}", 151 log.warn("Doh... don't know where to go... {} -> {} received on {}",
130 - ethPkt.getSourceMAC(), ethPkt.getDestinationMAC(), 152 + ethPkt.getSourceMAC(), ethPkt.getDestinationMAC(),
131 - pkt.receivedFrom()); 153 + pkt.receivedFrom());
132 flood(context); 154 flood(context);
133 return; 155 return;
134 } 156 }
...@@ -152,7 +174,7 @@ public class ReactiveForwarding { ...@@ -152,7 +174,7 @@ public class ReactiveForwarding {
152 // Floods the specified packet if permissible. 174 // Floods the specified packet if permissible.
153 private void flood(PacketContext context) { 175 private void flood(PacketContext context) {
154 if (topologyService.isBroadcastPoint(topologyService.currentTopology(), 176 if (topologyService.isBroadcastPoint(topologyService.currentTopology(),
155 - context.inPacket().receivedFrom())) { 177 + context.inPacket().receivedFrom())) {
156 packetOut(context, PortNumber.FLOOD); 178 packetOut(context, PortNumber.FLOOD);
157 } else { 179 } else {
158 context.block(); 180 context.block();
...@@ -174,15 +196,15 @@ public class ReactiveForwarding { ...@@ -174,15 +196,15 @@ public class ReactiveForwarding {
174 Ethernet inPkt = context.inPacket().parsed(); 196 Ethernet inPkt = context.inPacket().parsed();
175 TrafficSelector.Builder builder = DefaultTrafficSelector.builder(); 197 TrafficSelector.Builder builder = DefaultTrafficSelector.builder();
176 builder.matchEthType(inPkt.getEtherType()) 198 builder.matchEthType(inPkt.getEtherType())
177 - .matchEthSrc(inPkt.getSourceMAC()) 199 + .matchEthSrc(inPkt.getSourceMAC())
178 - .matchEthDst(inPkt.getDestinationMAC()) 200 + .matchEthDst(inPkt.getDestinationMAC())
179 - .matchInport(context.inPacket().receivedFrom().port()); 201 + .matchInport(context.inPacket().receivedFrom().port());
180 202
181 TrafficTreatment.Builder treat = DefaultTrafficTreatment.builder(); 203 TrafficTreatment.Builder treat = DefaultTrafficTreatment.builder();
182 treat.setOutput(portNumber); 204 treat.setOutput(portNumber);
183 205
184 FlowRule f = new DefaultFlowRule(context.inPacket().receivedFrom().deviceId(), 206 FlowRule f = new DefaultFlowRule(context.inPacket().receivedFrom().deviceId(),
185 - builder.build(), treat.build(), PRIORITY, appId, TIMEOUT); 207 + builder.build(), treat.build(), PRIORITY, appId, TIMEOUT);
186 208
187 flowRuleService.applyFlowRules(f); 209 flowRuleService.applyFlowRules(f);
188 210
......
...@@ -164,6 +164,12 @@ ...@@ -164,6 +164,12 @@
164 <scope>provided</scope> 164 <scope>provided</scope>
165 </dependency> 165 </dependency>
166 <dependency> 166 <dependency>
167 + <groupId>org.osgi</groupId>
168 + <artifactId>org.osgi.compendium</artifactId>
169 + <version>4.3.1</version>
170 + <scope>provided</scope>
171 + </dependency>
172 + <dependency>
167 <groupId>org.apache.felix</groupId> 173 <groupId>org.apache.felix</groupId>
168 <artifactId>org.apache.felix.scr.annotations</artifactId> 174 <artifactId>org.apache.felix.scr.annotations</artifactId>
169 <version>1.9.8</version> 175 <version>1.9.8</version>
......