blob: 35ca7eb9751adf36e9fcc2a45eb33edfb86bcdf7 [file] [log] [blame]
alshabibed0951f2015-10-02 21:39:27 +02001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2015-present Open Networking Foundation
alshabibed0951f2015-10-02 21:39:27 +02003 *
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 Milkeya9ae0d42017-08-06 22:10:47 -070016package org.onosproject.net.mcast.impl;
17
alshabibed0951f2015-10-02 21:39:27 +020018import org.onosproject.event.AbstractListenerManager;
19import org.onosproject.net.ConnectPoint;
20import org.onosproject.net.mcast.McastEvent;
21import org.onosproject.net.mcast.McastListener;
22import org.onosproject.net.mcast.McastRoute;
alshabib79e52872015-12-07 16:01:01 -080023import org.onosproject.net.mcast.McastStore;
24import org.onosproject.net.mcast.McastStoreDelegate;
alshabibed0951f2015-10-02 21:39:27 +020025import org.onosproject.net.mcast.MulticastRouteService;
Ray Milkeyd84f89b2018-08-17 14:54:17 -070026import org.osgi.service.component.annotations.Activate;
27import org.osgi.service.component.annotations.Component;
28import org.osgi.service.component.annotations.Deactivate;
29import org.osgi.service.component.annotations.Reference;
30import org.osgi.service.component.annotations.ReferenceCardinality;
alshabibed0951f2015-10-02 21:39:27 +020031import org.slf4j.Logger;
32
Ray Milkeyd84f89b2018-08-17 14:54:17 -070033import java.util.Set;
34
alshabib79e52872015-12-07 16:01:01 -080035import static com.google.common.base.Preconditions.checkNotNull;
alshabibed0951f2015-10-02 21:39:27 +020036import static org.slf4j.LoggerFactory.getLogger;
37
38/**
39 * An implementation of a multicast route table.
40 */
Ray Milkeyd84f89b2018-08-17 14:54:17 -070041@Component(immediate = true, service = MulticastRouteService.class)
alshabibed0951f2015-10-02 21:39:27 +020042public class MulticastRouteManager
43 extends AbstractListenerManager<McastEvent, McastListener>
44 implements MulticastRouteService {
45 //TODO: add MulticastRouteAdminService
46
alshabibed0951f2015-10-02 21:39:27 +020047 private Logger log = getLogger(getClass());
48
alshabib79e52872015-12-07 16:01:01 -080049 private final McastStoreDelegate delegate = new InternalMcastStoreDelegate();
alshabibed0951f2015-10-02 21:39:27 +020050
Ray Milkeyd84f89b2018-08-17 14:54:17 -070051 @Reference(cardinality = ReferenceCardinality.MANDATORY)
alshabib79e52872015-12-07 16:01:01 -080052 protected McastStore store;
alshabibed0951f2015-10-02 21:39:27 +020053
54 @Activate
55 public void activate() {
alshabibed0951f2015-10-02 21:39:27 +020056 eventDispatcher.addSink(McastEvent.class, listenerRegistry);
alshabib79e52872015-12-07 16:01:01 -080057 store.setDelegate(delegate);
alshabibed0951f2015-10-02 21:39:27 +020058
59 log.info("Started");
60 }
61
62 @Deactivate
63 public void deactivate() {
Yuta HIGUCHIdf43aa32017-05-26 21:26:09 -070064 store.unsetDelegate(delegate);
Victor Silva878c78c2016-11-14 13:32:36 -030065 eventDispatcher.removeSink(McastEvent.class);
alshabibed0951f2015-10-02 21:39:27 +020066 log.info("Stopped");
67 }
68
69 @Override
70 public void add(McastRoute route) {
alshabib79e52872015-12-07 16:01:01 -080071 checkNotNull(route, "Route cannot be null");
72 store.storeRoute(route, McastStore.Type.ADD);
alshabibed0951f2015-10-02 21:39:27 +020073 }
74
75 @Override
76 public void remove(McastRoute route) {
alshabib79e52872015-12-07 16:01:01 -080077 checkNotNull(route, "Route cannot be null");
78 store.storeRoute(route, McastStore.Type.REMOVE);
alshabibed0951f2015-10-02 21:39:27 +020079 }
80
81 @Override
Jonathan Hart07eb0412016-02-08 16:42:29 -080082 public Set<McastRoute> getRoutes() {
83 return store.getRoutes();
84 }
85
86 @Override
alshabibed0951f2015-10-02 21:39:27 +020087 public void addSource(McastRoute route, ConnectPoint connectPoint) {
alshabib79e52872015-12-07 16:01:01 -080088 checkNotNull(route, "Route cannot be null");
89 checkNotNull(connectPoint, "Source cannot be null");
90 store.storeSource(route, connectPoint);
alshabibed0951f2015-10-02 21:39:27 +020091 }
92
93 @Override
94 public void addSink(McastRoute route, ConnectPoint connectPoint) {
alshabib79e52872015-12-07 16:01:01 -080095 checkNotNull(route, "Route cannot be null");
96 checkNotNull(connectPoint, "Sink cannot be null");
97 store.storeSink(route, connectPoint, McastStore.Type.ADD);
alshabibc6b60802015-10-06 11:42:50 +020098
alshabibed0951f2015-10-02 21:39:27 +020099 }
100
alshabibed0951f2015-10-02 21:39:27 +0200101 @Override
102 public void removeSink(McastRoute route, ConnectPoint connectPoint) {
alshabibc6b60802015-10-06 11:42:50 +0200103
alshabib79e52872015-12-07 16:01:01 -0800104 checkNotNull(route, "Route cannot be null");
105 checkNotNull(connectPoint, "Sink cannot be null");
106
107 store.storeSink(route, connectPoint, McastStore.Type.REMOVE);
alshabibed0951f2015-10-02 21:39:27 +0200108 }
109
110 @Override
111 public ConnectPoint fetchSource(McastRoute route) {
alshabib79e52872015-12-07 16:01:01 -0800112 return store.sourceFor(route);
alshabibed0951f2015-10-02 21:39:27 +0200113 }
114
115 @Override
alshabib79e52872015-12-07 16:01:01 -0800116 public Set<ConnectPoint> fetchSinks(McastRoute route) {
117 return store.sinksFor(route);
118 }
119
120 private class InternalMcastStoreDelegate implements McastStoreDelegate {
121 @Override
122 public void notify(McastEvent event) {
123 post(event);
124 }
alshabibed0951f2015-10-02 21:39:27 +0200125 }
126}