Showing
6 changed files
with
150 additions
and
17 deletions
... | @@ -17,6 +17,15 @@ public interface FlowRuleProvider extends Provider { | ... | @@ -17,6 +17,15 @@ public interface FlowRuleProvider extends Provider { |
17 | */ | 17 | */ |
18 | void applyFlowRule(FlowRule... flowRules); | 18 | void applyFlowRule(FlowRule... flowRules); |
19 | 19 | ||
20 | + /** | ||
21 | + * Instructs the provider to remove the specified flow rules to their | ||
22 | + * respective devices. | ||
23 | + * @param flowRules one or more flow rules | ||
24 | + * throws SomeKindOfException that indicates which ones were applied and | ||
25 | + * which ones failed | ||
26 | + */ | ||
27 | + void removeFlowRule(FlowRule... flowRules); | ||
28 | + | ||
20 | 29 | ||
21 | /** | 30 | /** |
22 | * Returns the collection of flow entries currently applied on the given | 31 | * Returns the collection of flow entries currently applied on the given | ... | ... |
core/trivial/src/main/java/org/onlab/onos/net/trivial/flow/impl/SimpleFlowRuleManager.java
0 → 100644
1 | +package org.onlab.onos.net.trivial.flow.impl; | ||
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.apache.felix.scr.annotations.Service; | ||
11 | +import org.onlab.onos.event.AbstractListenerRegistry; | ||
12 | +import org.onlab.onos.event.EventDeliveryService; | ||
13 | +import org.onlab.onos.net.Device; | ||
14 | +import org.onlab.onos.net.DeviceId; | ||
15 | +import org.onlab.onos.net.device.DeviceService; | ||
16 | +import org.onlab.onos.net.flow.FlowEntry; | ||
17 | +import org.onlab.onos.net.flow.FlowRule; | ||
18 | +import org.onlab.onos.net.flow.FlowRuleEvent; | ||
19 | +import org.onlab.onos.net.flow.FlowRuleListener; | ||
20 | +import org.onlab.onos.net.flow.FlowRuleProvider; | ||
21 | +import org.onlab.onos.net.flow.FlowRuleProviderRegistry; | ||
22 | +import org.onlab.onos.net.flow.FlowRuleProviderService; | ||
23 | +import org.onlab.onos.net.flow.FlowRuleService; | ||
24 | +import org.onlab.onos.net.provider.AbstractProviderRegistry; | ||
25 | +import org.onlab.onos.net.provider.AbstractProviderService; | ||
26 | +import org.slf4j.Logger; | ||
27 | + | ||
28 | +@Component(immediate = true) | ||
29 | +@Service | ||
30 | +public class SimpleFlowRuleManager | ||
31 | +extends AbstractProviderRegistry<FlowRuleProvider, FlowRuleProviderService> | ||
32 | +implements FlowRuleService, FlowRuleProviderRegistry { | ||
33 | + | ||
34 | + private final Logger log = getLogger(getClass()); | ||
35 | + | ||
36 | + private final AbstractListenerRegistry<FlowRuleEvent, FlowRuleListener> | ||
37 | + listenerRegistry = new AbstractListenerRegistry<>(); | ||
38 | + | ||
39 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
40 | + private EventDeliveryService eventDispatcher; | ||
41 | + | ||
42 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
43 | + private DeviceService deviceService; | ||
44 | + | ||
45 | + @Activate | ||
46 | + public void activate() { | ||
47 | + eventDispatcher.addSink(FlowRuleEvent.class, listenerRegistry); | ||
48 | + log.info("Started"); | ||
49 | + } | ||
50 | + | ||
51 | + @Deactivate | ||
52 | + public void deactivate() { | ||
53 | + eventDispatcher.removeSink(FlowRuleEvent.class); | ||
54 | + log.info("Stopped"); | ||
55 | + } | ||
56 | + | ||
57 | + @Override | ||
58 | + public Iterable<FlowEntry> getFlowEntries(DeviceId deviceId) { | ||
59 | + //TODO: store rules somewhere and return them here | ||
60 | + return null; | ||
61 | + } | ||
62 | + | ||
63 | + @Override | ||
64 | + public void applyFlowRules(FlowRule... flowRules) { | ||
65 | + for (int i = 0; i < flowRules.length; i++) { | ||
66 | + FlowRule f = flowRules[0]; | ||
67 | + final Device device = deviceService.getDevice(f.deviceId()); | ||
68 | + final FlowRuleProvider frp = getProvider(device.providerId()); | ||
69 | + //TODO: store rules somewhere | ||
70 | + frp.applyFlowRule(f); | ||
71 | + } | ||
72 | + | ||
73 | + | ||
74 | + } | ||
75 | + | ||
76 | + @Override | ||
77 | + public void removeFlowRules(FlowRule... flowRules) { | ||
78 | + for (int i = 0; i < flowRules.length; i++) { | ||
79 | + FlowRule f = flowRules[0]; | ||
80 | + final Device device = deviceService.getDevice(f.deviceId()); | ||
81 | + final FlowRuleProvider frp = getProvider(device.providerId()); | ||
82 | + //TODO: remove stored rules from wherever they are | ||
83 | + frp.removeFlowRule(f); | ||
84 | + } | ||
85 | + | ||
86 | + } | ||
87 | + | ||
88 | + @Override | ||
89 | + public void addListener(FlowRuleListener listener) { | ||
90 | + listenerRegistry.addListener(listener); | ||
91 | + } | ||
92 | + | ||
93 | + @Override | ||
94 | + public void removeListener(FlowRuleListener listener) { | ||
95 | + listenerRegistry.removeListener(listener); | ||
96 | + } | ||
97 | + | ||
98 | + @Override | ||
99 | + protected FlowRuleProviderService createProviderService( | ||
100 | + FlowRuleProvider provider) { | ||
101 | + return new InternalFlowRuleProviderService(provider); | ||
102 | + } | ||
103 | + | ||
104 | + private class InternalFlowRuleProviderService | ||
105 | + extends AbstractProviderService<FlowRuleProvider> | ||
106 | + implements FlowRuleProviderService { | ||
107 | + | ||
108 | + protected InternalFlowRuleProviderService(FlowRuleProvider provider) { | ||
109 | + super(provider); | ||
110 | + } | ||
111 | + | ||
112 | + @Override | ||
113 | + public void flowRemoved(FlowRule flowRule) { | ||
114 | + // TODO Auto-generated method stub | ||
115 | + | ||
116 | + } | ||
117 | + | ||
118 | + @Override | ||
119 | + public void flowMissing(FlowRule flowRule) { | ||
120 | + // TODO Auto-generated method stub | ||
121 | + | ||
122 | + } | ||
123 | + | ||
124 | + @Override | ||
125 | + public void flowAdded(FlowRule flowRule) { | ||
126 | + // TODO Auto-generated method stub | ||
127 | + | ||
128 | + } | ||
129 | + | ||
130 | + } | ||
131 | + | ||
132 | +} |
1 | -package org.onlab.onos.of.controller; | ||
2 | - | ||
3 | -/** | ||
4 | - * Meta events that can happen at a switch. | ||
5 | - * | ||
6 | - */ | ||
7 | -public enum OpenFlowSwitchEvent { | ||
8 | - /** | ||
9 | - * The switch connected. | ||
10 | - */ | ||
11 | - SWITCH_CONNECTED, | ||
12 | - | ||
13 | - /** | ||
14 | - * The switch disconnected. | ||
15 | - */ | ||
16 | - SWITCH_DISCONNECTED | ||
17 | -} |
-
Please register or login to post a comment