Committed by
Gerrit Code Review
Configurable extraneous flow rules
Change-Id: I216605743d5a8814a366a030290614d840657444
Showing
2 changed files
with
42 additions
and
4 deletions
... | @@ -15,6 +15,7 @@ | ... | @@ -15,6 +15,7 @@ |
15 | */ | 15 | */ |
16 | package org.onosproject.net.flow.impl; | 16 | package org.onosproject.net.flow.impl; |
17 | 17 | ||
18 | +import com.google.common.base.Strings; | ||
18 | import com.google.common.collect.ArrayListMultimap; | 19 | import com.google.common.collect.ArrayListMultimap; |
19 | import com.google.common.collect.Iterables; | 20 | import com.google.common.collect.Iterables; |
20 | import com.google.common.collect.Lists; | 21 | import com.google.common.collect.Lists; |
... | @@ -24,9 +25,13 @@ import com.google.common.collect.Sets; | ... | @@ -24,9 +25,13 @@ import com.google.common.collect.Sets; |
24 | import org.apache.felix.scr.annotations.Activate; | 25 | import org.apache.felix.scr.annotations.Activate; |
25 | import org.apache.felix.scr.annotations.Component; | 26 | import org.apache.felix.scr.annotations.Component; |
26 | import org.apache.felix.scr.annotations.Deactivate; | 27 | import org.apache.felix.scr.annotations.Deactivate; |
28 | +import org.apache.felix.scr.annotations.Modified; | ||
29 | +import org.apache.felix.scr.annotations.Property; | ||
27 | import org.apache.felix.scr.annotations.Reference; | 30 | import org.apache.felix.scr.annotations.Reference; |
28 | import org.apache.felix.scr.annotations.ReferenceCardinality; | 31 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
29 | import org.apache.felix.scr.annotations.Service; | 32 | import org.apache.felix.scr.annotations.Service; |
33 | +import org.onlab.util.Tools; | ||
34 | +import org.onosproject.cfg.ComponentConfigService; | ||
30 | import org.onosproject.core.ApplicationId; | 35 | import org.onosproject.core.ApplicationId; |
31 | import org.onosproject.core.CoreService; | 36 | import org.onosproject.core.CoreService; |
32 | import org.onosproject.core.IdGenerator; | 37 | import org.onosproject.core.IdGenerator; |
... | @@ -55,9 +60,11 @@ import org.onosproject.net.flow.FlowRuleStore; | ... | @@ -55,9 +60,11 @@ import org.onosproject.net.flow.FlowRuleStore; |
55 | import org.onosproject.net.flow.FlowRuleStoreDelegate; | 60 | import org.onosproject.net.flow.FlowRuleStoreDelegate; |
56 | import org.onosproject.net.provider.AbstractProviderRegistry; | 61 | import org.onosproject.net.provider.AbstractProviderRegistry; |
57 | import org.onosproject.net.provider.AbstractProviderService; | 62 | import org.onosproject.net.provider.AbstractProviderService; |
63 | +import org.osgi.service.component.ComponentContext; | ||
58 | import org.slf4j.Logger; | 64 | import org.slf4j.Logger; |
59 | 65 | ||
60 | import java.util.Collections; | 66 | import java.util.Collections; |
67 | +import java.util.Dictionary; | ||
61 | import java.util.List; | 68 | import java.util.List; |
62 | import java.util.Map; | 69 | import java.util.Map; |
63 | import java.util.Set; | 70 | import java.util.Set; |
... | @@ -82,6 +89,12 @@ public class FlowRuleManager | ... | @@ -82,6 +89,12 @@ public class FlowRuleManager |
82 | enum BatchState { STARTED, FINISHED, CANCELLED } | 89 | enum BatchState { STARTED, FINISHED, CANCELLED } |
83 | 90 | ||
84 | public static final String FLOW_RULE_NULL = "FlowRule cannot be null"; | 91 | public static final String FLOW_RULE_NULL = "FlowRule cannot be null"; |
92 | + private static final boolean ALLOW_EXTRANEOUS_RULES = false; | ||
93 | + | ||
94 | + @Property(name = "allowExtraneousRules", boolValue = ALLOW_EXTRANEOUS_RULES, | ||
95 | + label = "Allow flow rules in switch not installed by ONOS") | ||
96 | + private boolean allowExtraneousRules = ALLOW_EXTRANEOUS_RULES; | ||
97 | + | ||
85 | private final Logger log = getLogger(getClass()); | 98 | private final Logger log = getLogger(getClass()); |
86 | 99 | ||
87 | private final AbstractListenerRegistry<FlowRuleEvent, FlowRuleListener> | 100 | private final AbstractListenerRegistry<FlowRuleEvent, FlowRuleListener> |
... | @@ -112,11 +125,15 @@ public class FlowRuleManager | ... | @@ -112,11 +125,15 @@ public class FlowRuleManager |
112 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 125 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
113 | protected CoreService coreService; | 126 | protected CoreService coreService; |
114 | 127 | ||
115 | - @Activate | 128 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
116 | - public void activate() { | 129 | + protected ComponentConfigService cfgService; |
117 | 130 | ||
131 | + @Activate | ||
132 | + public void activate(ComponentContext context) { | ||
133 | + cfgService.registerProperties(getClass()); | ||
118 | idGenerator = coreService.getIdGenerator(FLOW_OP_TOPIC); | 134 | idGenerator = coreService.getIdGenerator(FLOW_OP_TOPIC); |
119 | 135 | ||
136 | + modified(context); | ||
120 | 137 | ||
121 | store.setDelegate(delegate); | 138 | store.setDelegate(delegate); |
122 | eventDispatcher.addSink(FlowRuleEvent.class, listenerRegistry); | 139 | eventDispatcher.addSink(FlowRuleEvent.class, listenerRegistry); |
... | @@ -125,6 +142,7 @@ public class FlowRuleManager | ... | @@ -125,6 +142,7 @@ public class FlowRuleManager |
125 | 142 | ||
126 | @Deactivate | 143 | @Deactivate |
127 | public void deactivate() { | 144 | public void deactivate() { |
145 | + cfgService.unregisterProperties(getClass(), false); | ||
128 | deviceInstallers.shutdownNow(); | 146 | deviceInstallers.shutdownNow(); |
129 | operationsService.shutdownNow(); | 147 | operationsService.shutdownNow(); |
130 | store.unsetDelegate(delegate); | 148 | store.unsetDelegate(delegate); |
... | @@ -132,6 +150,22 @@ public class FlowRuleManager | ... | @@ -132,6 +150,22 @@ public class FlowRuleManager |
132 | log.info("Stopped"); | 150 | log.info("Stopped"); |
133 | } | 151 | } |
134 | 152 | ||
153 | + @Modified | ||
154 | + public void modified(ComponentContext context) { | ||
155 | + if (context == null) { | ||
156 | + return; | ||
157 | + } | ||
158 | + | ||
159 | + Dictionary<?, ?> properties = context.getProperties(); | ||
160 | + | ||
161 | + String s = Tools.get(properties, "allowExtraneousRules"); | ||
162 | + allowExtraneousRules = Strings.isNullOrEmpty(s) ? ALLOW_EXTRANEOUS_RULES : Boolean.valueOf(s); | ||
163 | + | ||
164 | + if (allowExtraneousRules) { | ||
165 | + log.info("Allowing flow rules not installed by ONOS"); | ||
166 | + } | ||
167 | + } | ||
168 | + | ||
135 | @Override | 169 | @Override |
136 | public int getFlowRuleCount() { | 170 | public int getFlowRuleCount() { |
137 | return store.getFlowRuleCount(); | 171 | return store.getFlowRuleCount(); |
... | @@ -362,7 +396,9 @@ public class FlowRuleManager | ... | @@ -362,7 +396,9 @@ public class FlowRuleManager |
362 | flowAdded(rule); | 396 | flowAdded(rule); |
363 | } else { | 397 | } else { |
364 | // the device has a rule the store does not have | 398 | // the device has a rule the store does not have |
365 | - extraneousFlow(rule); | 399 | + if (!allowExtraneousRules) { |
400 | + extraneousFlow(rule); | ||
401 | + } | ||
366 | } | 402 | } |
367 | } catch (Throwable e) { | 403 | } catch (Throwable e) { |
368 | log.debug("Can't process added or extra rule {}", e.getMessage()); | 404 | log.debug("Can't process added or extra rule {}", e.getMessage()); | ... | ... |
... | @@ -24,6 +24,7 @@ import com.google.common.util.concurrent.MoreExecutors; | ... | @@ -24,6 +24,7 @@ import com.google.common.util.concurrent.MoreExecutors; |
24 | import org.junit.After; | 24 | import org.junit.After; |
25 | import org.junit.Before; | 25 | import org.junit.Before; |
26 | import org.junit.Test; | 26 | import org.junit.Test; |
27 | +import org.onosproject.cfg.ComponentConfigAdapter; | ||
27 | import org.onosproject.core.ApplicationId; | 28 | import org.onosproject.core.ApplicationId; |
28 | import org.onosproject.core.CoreServiceAdapter; | 29 | import org.onosproject.core.CoreServiceAdapter; |
29 | import org.onosproject.core.DefaultApplicationId; | 30 | import org.onosproject.core.DefaultApplicationId; |
... | @@ -115,10 +116,11 @@ public class FlowRuleManagerTest { | ... | @@ -115,10 +116,11 @@ public class FlowRuleManagerTest { |
115 | mgr.coreService = new TestCoreService(); | 116 | mgr.coreService = new TestCoreService(); |
116 | mgr.operationsService = MoreExecutors.newDirectExecutorService(); | 117 | mgr.operationsService = MoreExecutors.newDirectExecutorService(); |
117 | mgr.deviceInstallers = MoreExecutors.newDirectExecutorService(); | 118 | mgr.deviceInstallers = MoreExecutors.newDirectExecutorService(); |
119 | + mgr.cfgService = new ComponentConfigAdapter(); | ||
118 | service = mgr; | 120 | service = mgr; |
119 | registry = mgr; | 121 | registry = mgr; |
120 | 122 | ||
121 | - mgr.activate(); | 123 | + mgr.activate(null); |
122 | mgr.addListener(listener); | 124 | mgr.addListener(listener); |
123 | provider = new TestProvider(PID); | 125 | provider = new TestProvider(PID); |
124 | providerService = registry.register(provider); | 126 | providerService = registry.register(provider); | ... | ... |
-
Please register or login to post a comment