Committed by
Gerrit Code Review
IGMP ssm translate
Change-Id: Id5654702ad55b6294323e4cb753fe28ea1f61276
Showing
2 changed files
with
81 additions
and
3 deletions
| ... | @@ -66,6 +66,7 @@ import org.onosproject.olt.AccessDeviceData; | ... | @@ -66,6 +66,7 @@ import org.onosproject.olt.AccessDeviceData; |
| 66 | import org.slf4j.Logger; | 66 | import org.slf4j.Logger; |
| 67 | 67 | ||
| 68 | import java.nio.ByteBuffer; | 68 | import java.nio.ByteBuffer; |
| 69 | +import java.util.Collection; | ||
| 69 | import java.util.List; | 70 | import java.util.List; |
| 70 | import java.util.Map; | 71 | import java.util.Map; |
| 71 | import java.util.concurrent.ConcurrentHashMap; | 72 | import java.util.concurrent.ConcurrentHashMap; |
| ... | @@ -131,6 +132,8 @@ public class IgmpSnoop { | ... | @@ -131,6 +132,8 @@ public class IgmpSnoop { |
| 131 | 132 | ||
| 132 | private Map<DeviceId, AccessDeviceData> oltData = new ConcurrentHashMap<>(); | 133 | private Map<DeviceId, AccessDeviceData> oltData = new ConcurrentHashMap<>(); |
| 133 | 134 | ||
| 135 | + private Map<IpAddress, IpAddress> ssmTranslateTable = new ConcurrentHashMap<>(); | ||
| 136 | + | ||
| 134 | private DeviceListener deviceListener = new InternalDeviceListener(); | 137 | private DeviceListener deviceListener = new InternalDeviceListener(); |
| 135 | private IgmpPacketProcessor processor = new IgmpPacketProcessor(); | 138 | private IgmpPacketProcessor processor = new IgmpPacketProcessor(); |
| 136 | private static ApplicationId appId; | 139 | private static ApplicationId appId; |
| ... | @@ -150,6 +153,15 @@ public class IgmpSnoop { | ... | @@ -150,6 +153,15 @@ public class IgmpSnoop { |
| 150 | } | 153 | } |
| 151 | }; | 154 | }; |
| 152 | 155 | ||
| 156 | + private ConfigFactory<ApplicationId, IgmpSsmTranslateConfig> ssmTranslateConfigFactory = | ||
| 157 | + new ConfigFactory<ApplicationId, IgmpSsmTranslateConfig>( | ||
| 158 | + SubjectFactories.APP_SUBJECT_FACTORY, IgmpSsmTranslateConfig.class, "ssmTranslate", true) { | ||
| 159 | + @Override | ||
| 160 | + public IgmpSsmTranslateConfig createConfig() { | ||
| 161 | + return new IgmpSsmTranslateConfig(); | ||
| 162 | + } | ||
| 163 | + }; | ||
| 164 | + | ||
| 153 | 165 | ||
| 154 | private ByteBuffer queryPacket; | 166 | private ByteBuffer queryPacket; |
| 155 | 167 | ||
| ... | @@ -161,6 +173,7 @@ public class IgmpSnoop { | ... | @@ -161,6 +173,7 @@ public class IgmpSnoop { |
| 161 | packetService.addProcessor(processor, PacketProcessor.director(1)); | 173 | packetService.addProcessor(processor, PacketProcessor.director(1)); |
| 162 | 174 | ||
| 163 | networkConfig.registerConfigFactory(configFactory); | 175 | networkConfig.registerConfigFactory(configFactory); |
| 176 | + networkConfig.registerConfigFactory(ssmTranslateConfigFactory); | ||
| 164 | networkConfig.addListener(configListener); | 177 | networkConfig.addListener(configListener); |
| 165 | 178 | ||
| 166 | networkConfig.getSubjects(DeviceId.class, AccessDeviceConfig.class).forEach( | 179 | networkConfig.getSubjects(DeviceId.class, AccessDeviceConfig.class).forEach( |
| ... | @@ -175,6 +188,16 @@ public class IgmpSnoop { | ... | @@ -175,6 +188,16 @@ public class IgmpSnoop { |
| 175 | } | 188 | } |
| 176 | ); | 189 | ); |
| 177 | 190 | ||
| 191 | + IgmpSsmTranslateConfig ssmTranslateConfig = | ||
| 192 | + networkConfig.getConfig(appId, IgmpSsmTranslateConfig.class); | ||
| 193 | + | ||
| 194 | + if (ssmTranslateConfig != null) { | ||
| 195 | + Collection<McastRoute> translations = ssmTranslateConfig.getSsmTranslations(); | ||
| 196 | + for (McastRoute route : translations) { | ||
| 197 | + ssmTranslateTable.put(route.group(), route.source()); | ||
| 198 | + } | ||
| 199 | + } | ||
| 200 | + | ||
| 178 | oltData.keySet().stream() | 201 | oltData.keySet().stream() |
| 179 | .flatMap(did -> deviceService.getPorts(did).stream()) | 202 | .flatMap(did -> deviceService.getPorts(did).stream()) |
| 180 | .filter(p -> !oltData.get(p.element().id()).uplink().equals(p.number())) | 203 | .filter(p -> !oltData.get(p.element().id()).uplink().equals(p.number())) |
| ... | @@ -201,6 +224,7 @@ public class IgmpSnoop { | ... | @@ -201,6 +224,7 @@ public class IgmpSnoop { |
| 201 | deviceService.removeListener(deviceListener); | 224 | deviceService.removeListener(deviceListener); |
| 202 | networkConfig.removeListener(configListener); | 225 | networkConfig.removeListener(configListener); |
| 203 | networkConfig.unregisterConfigFactory(configFactory); | 226 | networkConfig.unregisterConfigFactory(configFactory); |
| 227 | + networkConfig.unregisterConfigFactory(ssmTranslateConfigFactory); | ||
| 204 | queryTask.cancel(true); | 228 | queryTask.cancel(true); |
| 205 | queryService.shutdownNow(); | 229 | queryService.shutdownNow(); |
| 206 | log.info("Stopped"); | 230 | log.info("Stopped"); |
| ... | @@ -248,9 +272,15 @@ public class IgmpSnoop { | ... | @@ -248,9 +272,15 @@ public class IgmpSnoop { |
| 248 | 272 | ||
| 249 | IGMPMembership membership = (IGMPMembership) group; | 273 | IGMPMembership membership = (IGMPMembership) group; |
| 250 | 274 | ||
| 251 | - McastRoute route = new McastRoute(IpAddress.valueOf("0.0.0.0"), | 275 | + // TODO allow pulling source from IGMP packet |
| 252 | - group.getGaddr(), | 276 | + IpAddress source = IpAddress.valueOf("0.0.0.0"); |
| 253 | - McastRoute.Type.IGMP); | 277 | + if (ssmTranslateTable.containsKey(group.getGaddr())) { |
| 278 | + source = ssmTranslateTable.get(group.getGaddr()); | ||
| 279 | + } | ||
| 280 | + | ||
| 281 | + McastRoute route = new McastRoute(source, | ||
| 282 | + group.getGaddr(), | ||
| 283 | + McastRoute.Type.IGMP); | ||
| 254 | 284 | ||
| 255 | if (membership.getRecordType() == IGMPMembership.MODE_IS_INCLUDE || | 285 | if (membership.getRecordType() == IGMPMembership.MODE_IS_INCLUDE || |
| 256 | membership.getRecordType() == IGMPMembership.CHANGE_TO_INCLUDE_MODE) { | 286 | membership.getRecordType() == IGMPMembership.CHANGE_TO_INCLUDE_MODE) { | ... | ... |
| 1 | +/* | ||
| 2 | + * Copyright 2016 Open Networking Laboratory | ||
| 3 | + * | ||
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 5 | + * you may not use this file except in compliance with the License. | ||
| 6 | + * You may obtain a copy of the License at | ||
| 7 | + * | ||
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 9 | + * | ||
| 10 | + * Unless required by applicable law or agreed to in writing, software | ||
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 13 | + * See the License for the specific language governing permissions and | ||
| 14 | + * limitations under the License. | ||
| 15 | + */ | ||
| 16 | + | ||
| 17 | +package org.onosproject.igmp; | ||
| 18 | + | ||
| 19 | +import com.fasterxml.jackson.databind.JsonNode; | ||
| 20 | +import org.onlab.packet.IpAddress; | ||
| 21 | +import org.onosproject.core.ApplicationId; | ||
| 22 | +import org.onosproject.net.config.Config; | ||
| 23 | +import org.onosproject.net.mcast.McastRoute; | ||
| 24 | + | ||
| 25 | +import java.util.ArrayList; | ||
| 26 | +import java.util.List; | ||
| 27 | + | ||
| 28 | +/** | ||
| 29 | + * Created by jono on 2/16/16. | ||
| 30 | + */ | ||
| 31 | +public class IgmpSsmTranslateConfig extends Config<ApplicationId> { | ||
| 32 | + private static final String SSM_TRANSLATE = "ssmTranslate"; | ||
| 33 | + private static final String SOURCE = "source"; | ||
| 34 | + private static final String GROUP = "group"; | ||
| 35 | + | ||
| 36 | + public List<McastRoute> getSsmTranslations() { | ||
| 37 | + List<McastRoute> translations = new ArrayList(); | ||
| 38 | + for (JsonNode node : array) { | ||
| 39 | + translations.add( | ||
| 40 | + new McastRoute( | ||
| 41 | + IpAddress.valueOf(node.path(SOURCE).asText().trim()), | ||
| 42 | + IpAddress.valueOf(node.path(GROUP).asText().trim()), | ||
| 43 | + McastRoute.Type.STATIC)); | ||
| 44 | + } | ||
| 45 | + | ||
| 46 | + return translations; | ||
| 47 | + } | ||
| 48 | +} |
-
Please register or login to post a comment