alshabib
Committed by Gerrit Code Review

moving igmp app to use access device config

Change-Id: I2940b3db9c6da3a3c43c192a2b390c46b40749e7
...@@ -51,6 +51,12 @@ ...@@ -51,6 +51,12 @@
51 <version>${project.version}</version> 51 <version>${project.version}</version>
52 </dependency> 52 </dependency>
53 53
54 + <dependency>
55 + <groupId>org.onosproject</groupId>
56 + <artifactId>onos-app-olt-api</artifactId>
57 + <version>${project.version}</version>
58 + </dependency>
59 +
54 60
55 <dependency> 61 <dependency>
56 <groupId>org.onosproject</groupId> 62 <groupId>org.onosproject</groupId>
......
1 -/*
2 - * Copyright 2015 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 org.onosproject.net.DeviceId;
20 -import org.onosproject.net.config.Config;
21 -
22 -/**
23 - * Config object for access device data.
24 - */
25 -public class IgmpDeviceConfig extends Config<DeviceId> {
26 -
27 - /**
28 - * Gets the device information.
29 - *
30 - * @return device information
31 - */
32 - public IgmpDeviceData getDevice() {
33 - return new IgmpDeviceData(subject());
34 - }
35 -}
1 -package org.onosproject.igmp;
2 -
3 -import org.onosproject.net.DeviceId;
4 -
5 -import static com.google.common.base.Preconditions.checkNotNull;
6 -
7 -/**
8 - * Information about an igmp enabled device.
9 - */
10 -public class IgmpDeviceData {
11 -
12 - private static final String DEVICE_ID_MISSING = "Device ID cannot be null";
13 -
14 - private final DeviceId deviceId;
15 -
16 - public IgmpDeviceData(DeviceId deviceId) {
17 - this.deviceId = checkNotNull(deviceId, DEVICE_ID_MISSING);
18 - }
19 -
20 - /**
21 - * Retrieves the access device ID.
22 - *
23 - * @return device ID
24 - */
25 - public DeviceId deviceId() {
26 - return deviceId;
27 - }
28 -}
...@@ -15,37 +15,51 @@ ...@@ -15,37 +15,51 @@
15 */ 15 */
16 package org.onosproject.igmp; 16 package org.onosproject.igmp;
17 17
18 -import static org.slf4j.LoggerFactory.getLogger;
19 -
20 import org.apache.felix.scr.annotations.Activate; 18 import org.apache.felix.scr.annotations.Activate;
21 import org.apache.felix.scr.annotations.Component; 19 import org.apache.felix.scr.annotations.Component;
22 import org.apache.felix.scr.annotations.Deactivate; 20 import org.apache.felix.scr.annotations.Deactivate;
23 import org.apache.felix.scr.annotations.Property; 21 import org.apache.felix.scr.annotations.Property;
24 import org.apache.felix.scr.annotations.Reference; 22 import org.apache.felix.scr.annotations.Reference;
25 import org.apache.felix.scr.annotations.ReferenceCardinality; 23 import org.apache.felix.scr.annotations.ReferenceCardinality;
24 +import org.onlab.packet.EthType;
26 import org.onlab.packet.Ethernet; 25 import org.onlab.packet.Ethernet;
26 +import org.onlab.packet.IGMP;
27 import org.onlab.packet.IPv4; 27 import org.onlab.packet.IPv4;
28 import org.onlab.packet.Ip4Address; 28 import org.onlab.packet.Ip4Address;
29 import org.onlab.packet.IpAddress; 29 import org.onlab.packet.IpAddress;
30 import org.onlab.packet.IpPrefix; 30 import org.onlab.packet.IpPrefix;
31 -import org.onlab.packet.IGMP;
32 import org.onosproject.core.ApplicationId; 31 import org.onosproject.core.ApplicationId;
33 import org.onosproject.core.CoreService; 32 import org.onosproject.core.CoreService;
34 import org.onosproject.net.ConnectPoint; 33 import org.onosproject.net.ConnectPoint;
35 import org.onosproject.net.DeviceId; 34 import org.onosproject.net.DeviceId;
35 +import org.onosproject.net.Port;
36 +import org.onosproject.net.PortNumber;
36 import org.onosproject.net.config.NetworkConfigRegistry; 37 import org.onosproject.net.config.NetworkConfigRegistry;
37 -import org.onosproject.net.flow.DefaultTrafficSelector; 38 +import org.onosproject.net.device.DeviceEvent;
38 -import org.onosproject.net.flow.TrafficSelector; 39 +import org.onosproject.net.device.DeviceListener;
40 +import org.onosproject.net.device.DeviceService;
41 +import org.onosproject.net.flow.DefaultTrafficTreatment;
42 +import org.onosproject.net.flow.criteria.Criteria;
43 +import org.onosproject.net.flowobjective.DefaultFilteringObjective;
44 +import org.onosproject.net.flowobjective.FilteringObjective;
45 +import org.onosproject.net.flowobjective.FlowObjectiveService;
46 +import org.onosproject.net.flowobjective.Objective;
47 +import org.onosproject.net.flowobjective.ObjectiveContext;
48 +import org.onosproject.net.flowobjective.ObjectiveError;
39 import org.onosproject.net.mcast.McastRoute; 49 import org.onosproject.net.mcast.McastRoute;
40 import org.onosproject.net.mcast.MulticastRouteService; 50 import org.onosproject.net.mcast.MulticastRouteService;
41 import org.onosproject.net.packet.InboundPacket; 51 import org.onosproject.net.packet.InboundPacket;
42 import org.onosproject.net.packet.PacketContext; 52 import org.onosproject.net.packet.PacketContext;
43 -import org.onosproject.net.packet.PacketPriority;
44 import org.onosproject.net.packet.PacketProcessor; 53 import org.onosproject.net.packet.PacketProcessor;
45 import org.onosproject.net.packet.PacketService; 54 import org.onosproject.net.packet.PacketService;
55 +import org.onosproject.olt.AccessDeviceConfig;
56 +import org.onosproject.olt.AccessDeviceData;
46 import org.slf4j.Logger; 57 import org.slf4j.Logger;
47 58
48 -import java.util.Optional; 59 +import java.util.Map;
60 +import java.util.concurrent.ConcurrentHashMap;
61 +
62 +import static org.slf4j.LoggerFactory.getLogger;
49 63
50 /** 64 /**
51 * Internet Group Management Protocol. 65 * Internet Group Management Protocol.
...@@ -61,6 +75,9 @@ public class IgmpSnoop { ...@@ -61,6 +75,9 @@ public class IgmpSnoop {
61 private String multicastAddress = DEFAULT_MCAST_ADDR; 75 private String multicastAddress = DEFAULT_MCAST_ADDR;
62 76
63 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 77 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
78 + protected FlowObjectiveService flowObjectiveService;
79 +
80 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
64 protected PacketService packetService; 81 protected PacketService packetService;
65 82
66 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 83 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
...@@ -72,6 +89,12 @@ public class IgmpSnoop { ...@@ -72,6 +89,12 @@ public class IgmpSnoop {
72 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 89 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
73 protected MulticastRouteService multicastService; 90 protected MulticastRouteService multicastService;
74 91
92 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
93 + protected DeviceService deviceService;
94 +
95 + private Map<DeviceId, AccessDeviceData> oltData = new ConcurrentHashMap<>();
96 +
97 + private DeviceListener deviceListener = new InternalDeviceListener();
75 private IgmpPacketProcessor processor = new IgmpPacketProcessor(); 98 private IgmpPacketProcessor processor = new IgmpPacketProcessor();
76 private static ApplicationId appId; 99 private static ApplicationId appId;
77 100
...@@ -81,17 +104,19 @@ public class IgmpSnoop { ...@@ -81,17 +104,19 @@ public class IgmpSnoop {
81 104
82 packetService.addProcessor(processor, PacketProcessor.director(1)); 105 packetService.addProcessor(processor, PacketProcessor.director(1));
83 106
84 - networkConfig.getSubjects(DeviceId.class, IgmpDeviceConfig.class).forEach( 107 + networkConfig.getSubjects(DeviceId.class, AccessDeviceConfig.class).forEach(
85 subject -> { 108 subject -> {
86 - IgmpDeviceConfig config = networkConfig.getConfig(subject, 109 + AccessDeviceConfig config = networkConfig.getConfig(subject,
87 - IgmpDeviceConfig.class); 110 + AccessDeviceConfig.class);
88 if (config != null) { 111 if (config != null) {
89 - IgmpDeviceData data = config.getDevice(); 112 + AccessDeviceData data = config.getOlt();
90 - submitPacketRequests(data.deviceId()); 113 + oltData.put(data.deviceId(), data);
91 } 114 }
92 } 115 }
93 ); 116 );
94 117
118 + deviceService.addListener(deviceListener);
119 +
95 log.info("Started"); 120 log.info("Started");
96 } 121 }
97 122
...@@ -99,18 +124,52 @@ public class IgmpSnoop { ...@@ -99,18 +124,52 @@ public class IgmpSnoop {
99 public void deactivate() { 124 public void deactivate() {
100 packetService.removeProcessor(processor); 125 packetService.removeProcessor(processor);
101 processor = null; 126 processor = null;
127 + deviceService.removeListener(deviceListener);
102 log.info("Stopped"); 128 log.info("Stopped");
103 } 129 }
104 130
105 - private void submitPacketRequests(DeviceId deviceId) { 131 + private void processFilterObjective(DeviceId devId, Port port, boolean remove) {
106 - TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); 132 +
107 - selector.matchEthType(Ethernet.TYPE_IPV4); 133 + //TODO migrate to packet requests when packet service uses filtering objectives
108 - selector.matchIPProtocol(IPv4.PROTOCOL_IGMP); 134 + DefaultFilteringObjective.Builder builder = DefaultFilteringObjective.builder();
109 - packetService.requestPackets(selector.build(), 135 +
110 - PacketPriority.REACTIVE, 136 + builder = remove ? builder.deny() : builder.permit();
111 - appId, 137 +
112 - Optional.of(deviceId)); 138 + FilteringObjective igmp = builder
139 + .withKey(Criteria.matchInPort(port.number()))
140 + .addCondition(Criteria.matchEthType(EthType.EtherType.IPV4.ethType()))
141 + .addCondition(Criteria.matchIPProtocol(IPv4.PROTOCOL_IGMP))
142 + .withMeta(DefaultTrafficTreatment.builder()
143 + .setOutput(PortNumber.CONTROLLER).build())
144 + .fromApp(appId)
145 + .withPriority(1000)
146 + .add(new ObjectiveContext() {
147 + @Override
148 + public void onSuccess(Objective objective) {
149 + log.info("Igmp filter for {} on {} installed.",
150 + devId, port);
151 + }
152 +
153 + @Override
154 + public void onError(Objective objective, ObjectiveError error) {
155 + log.info("Igmp filter for {} on {} failed because {}.",
156 + devId, port, error);
157 + }
158 + });
159 +
160 + flowObjectiveService.filter(devId, igmp);
161 + }
162 +
163 + private void processQuery(IGMP pkt, ConnectPoint location) {
164 + pkt.getGroups().forEach(group -> group.getSources().forEach(src -> {
165 +
166 + McastRoute route = new McastRoute(src,
167 + group.getGaddr(),
168 + McastRoute.Type.IGMP);
169 + multicastService.add(route);
170 + multicastService.addSink(route, location);
113 171
172 + }));
114 } 173 }
115 174
116 /** 175 /**
...@@ -188,15 +247,45 @@ public class IgmpSnoop { ...@@ -188,15 +247,45 @@ public class IgmpSnoop {
188 } 247 }
189 } 248 }
190 249
191 - private void processQuery(IGMP pkt, ConnectPoint location) {
192 - pkt.getGroups().forEach(group -> group.getSources().forEach(src -> {
193 250
194 - McastRoute route = new McastRoute(src,
195 - group.getGaddr(),
196 - McastRoute.Type.IGMP);
197 - multicastService.add(route);
198 - multicastService.addSink(route, location);
199 251
200 - })); 252 + private class InternalDeviceListener implements DeviceListener {
253 + @Override
254 + public void event(DeviceEvent event) {
255 + switch (event.type()) {
256 +
257 + case DEVICE_ADDED:
258 + case DEVICE_UPDATED:
259 + case DEVICE_REMOVED:
260 + case DEVICE_SUSPENDED:
261 + case DEVICE_AVAILABILITY_CHANGED:
262 + case PORT_STATS_UPDATED:
263 + break;
264 + case PORT_ADDED:
265 + if (event.port().isEnabled()) {
266 + processFilterObjective(event.subject().id(), event.port(), false);
267 + }
268 + break;
269 + case PORT_UPDATED:
270 + if (event.port().isEnabled()) {
271 + processFilterObjective(event.subject().id(), event.port(), false);
272 + } else {
273 + processFilterObjective(event.subject().id(), event.port(), true);
274 + }
275 + break;
276 + case PORT_REMOVED:
277 + processFilterObjective(event.subject().id(), event.port(), false);
278 + break;
279 + default:
280 + log.warn("Unknown device event {}", event.type());
281 + break;
282 + }
283 +
284 + }
285 +
286 + @Override
287 + public boolean isRelevant(DeviceEvent event) {
288 + return oltData.containsKey(event.subject().id());
289 + }
201 } 290 }
202 } 291 }
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
14 * limitations under the License. 14 * limitations under the License.
15 */ 15 */
16 16
17 -package org.onosproject.olt.impl; 17 +package org.onosproject.olt;
18 18
19 import com.fasterxml.jackson.databind.JsonNode; 19 import com.fasterxml.jackson.databind.JsonNode;
20 import org.onlab.packet.VlanId; 20 import org.onlab.packet.VlanId;
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
14 * limitations under the License. 14 * limitations under the License.
15 */ 15 */
16 16
17 -package org.onosproject.olt.impl; 17 +package org.onosproject.olt;
18 18
19 import org.onlab.packet.VlanId; 19 import org.onlab.packet.VlanId;
20 import org.onosproject.net.DeviceId; 20 import org.onosproject.net.DeviceId;
......
...@@ -24,7 +24,6 @@ import org.apache.felix.scr.annotations.Reference; ...@@ -24,7 +24,6 @@ import org.apache.felix.scr.annotations.Reference;
24 import org.apache.felix.scr.annotations.ReferenceCardinality; 24 import org.apache.felix.scr.annotations.ReferenceCardinality;
25 import org.apache.felix.scr.annotations.Service; 25 import org.apache.felix.scr.annotations.Service;
26 import org.onlab.packet.EthType; 26 import org.onlab.packet.EthType;
27 -import org.onlab.packet.IPv4;
28 import org.onlab.packet.VlanId; 27 import org.onlab.packet.VlanId;
29 import org.onosproject.core.ApplicationId; 28 import org.onosproject.core.ApplicationId;
30 import org.onosproject.core.CoreService; 29 import org.onosproject.core.CoreService;
...@@ -54,6 +53,8 @@ import org.onosproject.net.flowobjective.ForwardingObjective; ...@@ -54,6 +53,8 @@ import org.onosproject.net.flowobjective.ForwardingObjective;
54 import org.onosproject.net.flowobjective.Objective; 53 import org.onosproject.net.flowobjective.Objective;
55 import org.onosproject.net.flowobjective.ObjectiveContext; 54 import org.onosproject.net.flowobjective.ObjectiveContext;
56 import org.onosproject.net.flowobjective.ObjectiveError; 55 import org.onosproject.net.flowobjective.ObjectiveError;
56 +import org.onosproject.olt.AccessDeviceConfig;
57 +import org.onosproject.olt.AccessDeviceData;
57 import org.onosproject.olt.AccessDeviceEvent; 58 import org.onosproject.olt.AccessDeviceEvent;
58 import org.onosproject.olt.AccessDeviceListener; 59 import org.onosproject.olt.AccessDeviceListener;
59 import org.onosproject.olt.AccessDeviceService; 60 import org.onosproject.olt.AccessDeviceService;
...@@ -366,32 +367,8 @@ public class Olt ...@@ -366,32 +367,8 @@ public class Olt
366 } 367 }
367 }); 368 });
368 369
369 -
370 - FilteringObjective igmp = DefaultFilteringObjective.builder()
371 - .permit()
372 - .withKey(Criteria.matchInPort(port.number()))
373 - .addCondition(Criteria.matchEthType(EthType.EtherType.IPV4.ethType()))
374 - .addCondition(Criteria.matchIPProtocol(IPv4.PROTOCOL_IGMP))
375 - .withMeta(DefaultTrafficTreatment.builder()
376 - .setOutput(PortNumber.CONTROLLER).build())
377 - .fromApp(appId)
378 - .withPriority(1000)
379 - .add(new ObjectiveContext() {
380 - @Override
381 - public void onSuccess(Objective objective) {
382 - log.info("Igmp filter for {} on {} installed.",
383 - devId, port);
384 - }
385 -
386 - @Override
387 - public void onError(Objective objective, ObjectiveError error) {
388 - log.info("Igmp filter for {} on {} failed because {}.",
389 - devId, port, error);
390 - }
391 - });
392 -
393 flowObjectiveService.filter(devId, eapol); 370 flowObjectiveService.filter(devId, eapol);
394 - flowObjectiveService.filter(devId, igmp); 371 +
395 } 372 }
396 373
397 private class InternalDeviceListener implements DeviceListener { 374 private class InternalDeviceListener implements DeviceListener {
......