Committed by
Gerrit Code Review
fixing igmp bootstrap issues
Change-Id: Id8d7b6c33fa4196db72ea049b484cb9c52d2c87f
Showing
3 changed files
with
94 additions
and
3 deletions
apps/igmp/features.xml
0 → 100644
1 | +<?xml version="1.0" encoding="UTF-8" standalone="yes"?> | ||
2 | +<!-- | ||
3 | + ~ Copyright 2016 Open Networking Laboratory | ||
4 | + ~ | ||
5 | + ~ Licensed under the Apache License, Version 2.0 (the "License"); | ||
6 | + ~ you may not use this file except in compliance with the License. | ||
7 | + ~ You may obtain a copy of the License at | ||
8 | + ~ | ||
9 | + ~ http://www.apache.org/licenses/LICENSE-2.0 | ||
10 | + ~ | ||
11 | + ~ Unless required by applicable law or agreed to in writing, software | ||
12 | + ~ distributed under the License is distributed on an "AS IS" BASIS, | ||
13 | + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
14 | + ~ See the License for the specific language governing permissions and | ||
15 | + ~ limitations under the License. | ||
16 | + --> | ||
17 | +<features xmlns="http://karaf.apache.org/xmlns/features/v1.2.0" name="${project.artifactId}-${project.version}"> | ||
18 | + <feature name="onos-app-igmp" version="${project.version}" | ||
19 | + description="${project.description}"> | ||
20 | + <feature>onos-api</feature> | ||
21 | + <bundle>mvn:${project.groupId}/onos-app-olt-api/${project.version}</bundle> | ||
22 | + <bundle>mvn:${project.groupId}/onos-app-igmp/${project.version}</bundle> | ||
23 | + </feature> | ||
24 | +</features> |
... | @@ -34,7 +34,11 @@ import org.onosproject.net.ConnectPoint; | ... | @@ -34,7 +34,11 @@ import org.onosproject.net.ConnectPoint; |
34 | import org.onosproject.net.DeviceId; | 34 | import org.onosproject.net.DeviceId; |
35 | import org.onosproject.net.Port; | 35 | import org.onosproject.net.Port; |
36 | import org.onosproject.net.PortNumber; | 36 | import org.onosproject.net.PortNumber; |
37 | +import org.onosproject.net.config.ConfigFactory; | ||
38 | +import org.onosproject.net.config.NetworkConfigEvent; | ||
39 | +import org.onosproject.net.config.NetworkConfigListener; | ||
37 | import org.onosproject.net.config.NetworkConfigRegistry; | 40 | import org.onosproject.net.config.NetworkConfigRegistry; |
41 | +import org.onosproject.net.config.basics.SubjectFactories; | ||
38 | import org.onosproject.net.device.DeviceEvent; | 42 | import org.onosproject.net.device.DeviceEvent; |
39 | import org.onosproject.net.device.DeviceListener; | 43 | import org.onosproject.net.device.DeviceListener; |
40 | import org.onosproject.net.device.DeviceService; | 44 | import org.onosproject.net.device.DeviceService; |
... | @@ -56,6 +60,7 @@ import org.onosproject.olt.AccessDeviceConfig; | ... | @@ -56,6 +60,7 @@ import org.onosproject.olt.AccessDeviceConfig; |
56 | import org.onosproject.olt.AccessDeviceData; | 60 | import org.onosproject.olt.AccessDeviceData; |
57 | import org.slf4j.Logger; | 61 | import org.slf4j.Logger; |
58 | 62 | ||
63 | +import java.util.List; | ||
59 | import java.util.Map; | 64 | import java.util.Map; |
60 | import java.util.concurrent.ConcurrentHashMap; | 65 | import java.util.concurrent.ConcurrentHashMap; |
61 | 66 | ||
... | @@ -98,12 +103,31 @@ public class IgmpSnoop { | ... | @@ -98,12 +103,31 @@ public class IgmpSnoop { |
98 | private IgmpPacketProcessor processor = new IgmpPacketProcessor(); | 103 | private IgmpPacketProcessor processor = new IgmpPacketProcessor(); |
99 | private static ApplicationId appId; | 104 | private static ApplicationId appId; |
100 | 105 | ||
106 | + private InternalNetworkConfigListener configListener = | ||
107 | + new InternalNetworkConfigListener(); | ||
108 | + | ||
109 | + private static final Class<AccessDeviceConfig> CONFIG_CLASS = | ||
110 | + AccessDeviceConfig.class; | ||
111 | + | ||
112 | + private ConfigFactory<DeviceId, AccessDeviceConfig> configFactory = | ||
113 | + new ConfigFactory<DeviceId, AccessDeviceConfig>( | ||
114 | + SubjectFactories.DEVICE_SUBJECT_FACTORY, CONFIG_CLASS, "accessDevice") { | ||
115 | + @Override | ||
116 | + public AccessDeviceConfig createConfig() { | ||
117 | + return new AccessDeviceConfig(); | ||
118 | + } | ||
119 | + }; | ||
120 | + | ||
121 | + | ||
101 | @Activate | 122 | @Activate |
102 | public void activate() { | 123 | public void activate() { |
103 | appId = coreService.registerApplication("org.onosproject.igmp"); | 124 | appId = coreService.registerApplication("org.onosproject.igmp"); |
104 | 125 | ||
105 | packetService.addProcessor(processor, PacketProcessor.director(1)); | 126 | packetService.addProcessor(processor, PacketProcessor.director(1)); |
106 | 127 | ||
128 | + networkConfig.registerConfigFactory(configFactory); | ||
129 | + networkConfig.addListener(configListener); | ||
130 | + | ||
107 | networkConfig.getSubjects(DeviceId.class, AccessDeviceConfig.class).forEach( | 131 | networkConfig.getSubjects(DeviceId.class, AccessDeviceConfig.class).forEach( |
108 | subject -> { | 132 | subject -> { |
109 | AccessDeviceConfig config = networkConfig.getConfig(subject, | 133 | AccessDeviceConfig config = networkConfig.getConfig(subject, |
... | @@ -111,10 +135,17 @@ public class IgmpSnoop { | ... | @@ -111,10 +135,17 @@ public class IgmpSnoop { |
111 | if (config != null) { | 135 | if (config != null) { |
112 | AccessDeviceData data = config.getOlt(); | 136 | AccessDeviceData data = config.getOlt(); |
113 | oltData.put(data.deviceId(), data); | 137 | oltData.put(data.deviceId(), data); |
138 | + | ||
114 | } | 139 | } |
115 | } | 140 | } |
116 | ); | 141 | ); |
117 | 142 | ||
143 | + oltData.keySet().stream() | ||
144 | + .flatMap(did -> deviceService.getPorts(did).stream()) | ||
145 | + .filter(p -> !oltData.get(p.element().id()).uplink().equals(p.number())) | ||
146 | + .filter(p -> p.isEnabled()) | ||
147 | + .forEach(p -> processFilterObjective((DeviceId) p.element().id(), p, false)); | ||
148 | + | ||
118 | deviceService.addListener(deviceListener); | 149 | deviceService.addListener(deviceListener); |
119 | 150 | ||
120 | log.info("Started"); | 151 | log.info("Started"); |
... | @@ -125,6 +156,8 @@ public class IgmpSnoop { | ... | @@ -125,6 +156,8 @@ public class IgmpSnoop { |
125 | packetService.removeProcessor(processor); | 156 | packetService.removeProcessor(processor); |
126 | processor = null; | 157 | processor = null; |
127 | deviceService.removeListener(deviceListener); | 158 | deviceService.removeListener(deviceListener); |
159 | + networkConfig.removeListener(configListener); | ||
160 | + networkConfig.unregisterConfigFactory(configFactory); | ||
128 | log.info("Stopped"); | 161 | log.info("Stopped"); |
129 | } | 162 | } |
130 | 163 | ||
... | @@ -248,7 +281,6 @@ public class IgmpSnoop { | ... | @@ -248,7 +281,6 @@ public class IgmpSnoop { |
248 | } | 281 | } |
249 | 282 | ||
250 | 283 | ||
251 | - | ||
252 | private class InternalDeviceListener implements DeviceListener { | 284 | private class InternalDeviceListener implements DeviceListener { |
253 | @Override | 285 | @Override |
254 | public void event(DeviceEvent event) { | 286 | public void event(DeviceEvent event) { |
... | @@ -274,7 +306,7 @@ public class IgmpSnoop { | ... | @@ -274,7 +306,7 @@ public class IgmpSnoop { |
274 | } | 306 | } |
275 | break; | 307 | break; |
276 | case PORT_REMOVED: | 308 | case PORT_REMOVED: |
277 | - processFilterObjective(event.subject().id(), event.port(), false); | 309 | + processFilterObjective(event.subject().id(), event.port(), true); |
278 | break; | 310 | break; |
279 | default: | 311 | default: |
280 | log.warn("Unknown device event {}", event.type()); | 312 | log.warn("Unknown device event {}", event.type()); |
... | @@ -288,4 +320,38 @@ public class IgmpSnoop { | ... | @@ -288,4 +320,38 @@ public class IgmpSnoop { |
288 | return oltData.containsKey(event.subject().id()); | 320 | return oltData.containsKey(event.subject().id()); |
289 | } | 321 | } |
290 | } | 322 | } |
323 | + | ||
324 | + private class InternalNetworkConfigListener implements NetworkConfigListener { | ||
325 | + @Override | ||
326 | + public void event(NetworkConfigEvent event) { | ||
327 | + switch (event.type()) { | ||
328 | + | ||
329 | + case CONFIG_ADDED: | ||
330 | + case CONFIG_UPDATED: | ||
331 | + if (event.configClass().equals(CONFIG_CLASS)) { | ||
332 | + AccessDeviceConfig config = | ||
333 | + networkConfig.getConfig((DeviceId) event.subject(), CONFIG_CLASS); | ||
334 | + if (config != null) { | ||
335 | + oltData.put(config.getOlt().deviceId(), config.getOlt()); | ||
336 | + provisionDefaultFlows((DeviceId) event.subject()); | ||
337 | + } | ||
338 | + } | ||
339 | + break; | ||
340 | + case CONFIG_UNREGISTERED: | ||
341 | + case CONFIG_REMOVED: | ||
342 | + default: | ||
343 | + break; | ||
344 | + } | ||
345 | + } | ||
346 | + } | ||
347 | + | ||
348 | + private void provisionDefaultFlows(DeviceId deviceId) { | ||
349 | + List<Port> ports = deviceService.getPorts(deviceId); | ||
350 | + | ||
351 | + ports.stream() | ||
352 | + .filter(p -> !oltData.get(p.element().id()).uplink().equals(p.number())) | ||
353 | + .filter(p -> p.isEnabled()) | ||
354 | + .forEach(p -> processFilterObjective((DeviceId) p.element().id(), p, false)); | ||
355 | + | ||
356 | + } | ||
291 | } | 357 | } | ... | ... |
... | @@ -148,7 +148,7 @@ public class Olt | ... | @@ -148,7 +148,7 @@ public class Olt |
148 | 148 | ||
149 | oltData.keySet().stream() | 149 | oltData.keySet().stream() |
150 | .flatMap(did -> deviceService.getPorts(did).stream()) | 150 | .flatMap(did -> deviceService.getPorts(did).stream()) |
151 | - .filter(p -> oltData.get(p.element().id()).uplink() != p.number()) | 151 | + .filter(p -> !oltData.get(p.element().id()).uplink().equals(p.number())) |
152 | .filter(p -> p.isEnabled()) | 152 | .filter(p -> p.isEnabled()) |
153 | .forEach(p -> processFilteringObjectives((DeviceId) p.element().id(), p, true)); | 153 | .forEach(p -> processFilteringObjectives((DeviceId) p.element().id(), p, true)); |
154 | 154 | ||
... | @@ -159,6 +159,7 @@ public class Olt | ... | @@ -159,6 +159,7 @@ public class Olt |
159 | 159 | ||
160 | @Deactivate | 160 | @Deactivate |
161 | public void deactivate() { | 161 | public void deactivate() { |
162 | + deviceService.removeListener(deviceListener); | ||
162 | networkConfig.removeListener(configListener); | 163 | networkConfig.removeListener(configListener); |
163 | networkConfig.unregisterConfigFactory(configFactory); | 164 | networkConfig.unregisterConfigFactory(configFactory); |
164 | log.info("Stopped"); | 165 | log.info("Stopped"); | ... | ... |
-
Please register or login to post a comment