Showing
3 changed files
with
40 additions
and
5 deletions
| ... | @@ -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 | ... | ... |
| ... | @@ -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> | ... | ... |
-
Please register or login to post a comment