alshabib | ed0951f | 2015-10-02 21:39:27 +0200 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Foundation |
alshabib | ed0951f | 2015-10-02 21:39:27 +0200 | [diff] [blame] | 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 | */ |
Ray Milkey | a9ae0d4 | 2017-08-06 22:10:47 -0700 | [diff] [blame] | 16 | package org.onosproject.net.mcast.impl; |
| 17 | |
| 18 | import java.util.Set; |
alshabib | ed0951f | 2015-10-02 21:39:27 +0200 | [diff] [blame] | 19 | |
| 20 | import org.apache.felix.scr.annotations.Activate; |
| 21 | import org.apache.felix.scr.annotations.Component; |
| 22 | import org.apache.felix.scr.annotations.Deactivate; |
| 23 | import org.apache.felix.scr.annotations.Reference; |
| 24 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
| 25 | import org.apache.felix.scr.annotations.Service; |
alshabib | ed0951f | 2015-10-02 21:39:27 +0200 | [diff] [blame] | 26 | import org.onosproject.event.AbstractListenerManager; |
| 27 | import org.onosproject.net.ConnectPoint; |
| 28 | import org.onosproject.net.mcast.McastEvent; |
| 29 | import org.onosproject.net.mcast.McastListener; |
| 30 | import org.onosproject.net.mcast.McastRoute; |
alshabib | 79e5287 | 2015-12-07 16:01:01 -0800 | [diff] [blame] | 31 | import org.onosproject.net.mcast.McastStore; |
| 32 | import org.onosproject.net.mcast.McastStoreDelegate; |
alshabib | ed0951f | 2015-10-02 21:39:27 +0200 | [diff] [blame] | 33 | import org.onosproject.net.mcast.MulticastRouteService; |
alshabib | ed0951f | 2015-10-02 21:39:27 +0200 | [diff] [blame] | 34 | import org.slf4j.Logger; |
| 35 | |
alshabib | 79e5287 | 2015-12-07 16:01:01 -0800 | [diff] [blame] | 36 | import static com.google.common.base.Preconditions.checkNotNull; |
alshabib | ed0951f | 2015-10-02 21:39:27 +0200 | [diff] [blame] | 37 | import static org.slf4j.LoggerFactory.getLogger; |
| 38 | |
| 39 | /** |
| 40 | * An implementation of a multicast route table. |
| 41 | */ |
| 42 | @Component(immediate = true) |
| 43 | @Service |
| 44 | public class MulticastRouteManager |
| 45 | extends AbstractListenerManager<McastEvent, McastListener> |
| 46 | implements MulticastRouteService { |
| 47 | //TODO: add MulticastRouteAdminService |
| 48 | |
alshabib | ed0951f | 2015-10-02 21:39:27 +0200 | [diff] [blame] | 49 | private Logger log = getLogger(getClass()); |
| 50 | |
alshabib | 79e5287 | 2015-12-07 16:01:01 -0800 | [diff] [blame] | 51 | private final McastStoreDelegate delegate = new InternalMcastStoreDelegate(); |
alshabib | ed0951f | 2015-10-02 21:39:27 +0200 | [diff] [blame] | 52 | |
| 53 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
alshabib | 79e5287 | 2015-12-07 16:01:01 -0800 | [diff] [blame] | 54 | protected McastStore store; |
alshabib | ed0951f | 2015-10-02 21:39:27 +0200 | [diff] [blame] | 55 | |
| 56 | @Activate |
| 57 | public void activate() { |
alshabib | ed0951f | 2015-10-02 21:39:27 +0200 | [diff] [blame] | 58 | eventDispatcher.addSink(McastEvent.class, listenerRegistry); |
alshabib | 79e5287 | 2015-12-07 16:01:01 -0800 | [diff] [blame] | 59 | store.setDelegate(delegate); |
alshabib | ed0951f | 2015-10-02 21:39:27 +0200 | [diff] [blame] | 60 | |
| 61 | log.info("Started"); |
| 62 | } |
| 63 | |
| 64 | @Deactivate |
| 65 | public void deactivate() { |
Yuta HIGUCHI | df43aa3 | 2017-05-26 21:26:09 -0700 | [diff] [blame] | 66 | store.unsetDelegate(delegate); |
Victor Silva | 878c78c | 2016-11-14 13:32:36 -0300 | [diff] [blame] | 67 | eventDispatcher.removeSink(McastEvent.class); |
alshabib | ed0951f | 2015-10-02 21:39:27 +0200 | [diff] [blame] | 68 | log.info("Stopped"); |
| 69 | } |
| 70 | |
| 71 | @Override |
| 72 | public void add(McastRoute route) { |
alshabib | 79e5287 | 2015-12-07 16:01:01 -0800 | [diff] [blame] | 73 | checkNotNull(route, "Route cannot be null"); |
| 74 | store.storeRoute(route, McastStore.Type.ADD); |
alshabib | ed0951f | 2015-10-02 21:39:27 +0200 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | @Override |
| 78 | public void remove(McastRoute route) { |
alshabib | 79e5287 | 2015-12-07 16:01:01 -0800 | [diff] [blame] | 79 | checkNotNull(route, "Route cannot be null"); |
| 80 | store.storeRoute(route, McastStore.Type.REMOVE); |
alshabib | ed0951f | 2015-10-02 21:39:27 +0200 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | @Override |
Jonathan Hart | 07eb041 | 2016-02-08 16:42:29 -0800 | [diff] [blame] | 84 | public Set<McastRoute> getRoutes() { |
| 85 | return store.getRoutes(); |
| 86 | } |
| 87 | |
| 88 | @Override |
alshabib | ed0951f | 2015-10-02 21:39:27 +0200 | [diff] [blame] | 89 | public void addSource(McastRoute route, ConnectPoint connectPoint) { |
alshabib | 79e5287 | 2015-12-07 16:01:01 -0800 | [diff] [blame] | 90 | checkNotNull(route, "Route cannot be null"); |
| 91 | checkNotNull(connectPoint, "Source cannot be null"); |
| 92 | store.storeSource(route, connectPoint); |
alshabib | ed0951f | 2015-10-02 21:39:27 +0200 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | @Override |
| 96 | public void addSink(McastRoute route, ConnectPoint connectPoint) { |
alshabib | 79e5287 | 2015-12-07 16:01:01 -0800 | [diff] [blame] | 97 | checkNotNull(route, "Route cannot be null"); |
| 98 | checkNotNull(connectPoint, "Sink cannot be null"); |
| 99 | store.storeSink(route, connectPoint, McastStore.Type.ADD); |
alshabib | c6b6080 | 2015-10-06 11:42:50 +0200 | [diff] [blame] | 100 | |
alshabib | ed0951f | 2015-10-02 21:39:27 +0200 | [diff] [blame] | 101 | } |
| 102 | |
alshabib | ed0951f | 2015-10-02 21:39:27 +0200 | [diff] [blame] | 103 | @Override |
| 104 | public void removeSink(McastRoute route, ConnectPoint connectPoint) { |
alshabib | c6b6080 | 2015-10-06 11:42:50 +0200 | [diff] [blame] | 105 | |
alshabib | 79e5287 | 2015-12-07 16:01:01 -0800 | [diff] [blame] | 106 | checkNotNull(route, "Route cannot be null"); |
| 107 | checkNotNull(connectPoint, "Sink cannot be null"); |
| 108 | |
| 109 | store.storeSink(route, connectPoint, McastStore.Type.REMOVE); |
alshabib | ed0951f | 2015-10-02 21:39:27 +0200 | [diff] [blame] | 110 | } |
| 111 | |
| 112 | @Override |
| 113 | public ConnectPoint fetchSource(McastRoute route) { |
alshabib | 79e5287 | 2015-12-07 16:01:01 -0800 | [diff] [blame] | 114 | return store.sourceFor(route); |
alshabib | ed0951f | 2015-10-02 21:39:27 +0200 | [diff] [blame] | 115 | } |
| 116 | |
| 117 | @Override |
alshabib | 79e5287 | 2015-12-07 16:01:01 -0800 | [diff] [blame] | 118 | public Set<ConnectPoint> fetchSinks(McastRoute route) { |
| 119 | return store.sinksFor(route); |
| 120 | } |
| 121 | |
| 122 | private class InternalMcastStoreDelegate implements McastStoreDelegate { |
| 123 | @Override |
| 124 | public void notify(McastEvent event) { |
| 125 | post(event); |
| 126 | } |
alshabib | ed0951f | 2015-10-02 21:39:27 +0200 | [diff] [blame] | 127 | } |
| 128 | } |