blob: 913dcdbdd351214222c59e64e9b8ec010eba1398 [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
18import java.util.Set;
alshabibed0951f2015-10-02 21:39:27 +020019
20import org.apache.felix.scr.annotations.Activate;
21import org.apache.felix.scr.annotations.Component;
22import org.apache.felix.scr.annotations.Deactivate;
23import org.apache.felix.scr.annotations.Reference;
24import org.apache.felix.scr.annotations.ReferenceCardinality;
25import org.apache.felix.scr.annotations.Service;
alshabibed0951f2015-10-02 21:39:27 +020026import org.onosproject.event.AbstractListenerManager;
27import org.onosproject.net.ConnectPoint;
28import org.onosproject.net.mcast.McastEvent;
29import org.onosproject.net.mcast.McastListener;
30import org.onosproject.net.mcast.McastRoute;
alshabib79e52872015-12-07 16:01:01 -080031import org.onosproject.net.mcast.McastStore;
32import org.onosproject.net.mcast.McastStoreDelegate;
alshabibed0951f2015-10-02 21:39:27 +020033import org.onosproject.net.mcast.MulticastRouteService;
alshabibed0951f2015-10-02 21:39:27 +020034import org.slf4j.Logger;
35
alshabib79e52872015-12-07 16:01:01 -080036import static com.google.common.base.Preconditions.checkNotNull;
alshabibed0951f2015-10-02 21:39:27 +020037import static org.slf4j.LoggerFactory.getLogger;
38
39/**
40 * An implementation of a multicast route table.
41 */
42@Component(immediate = true)
43@Service
44public class MulticastRouteManager
45 extends AbstractListenerManager<McastEvent, McastListener>
46 implements MulticastRouteService {
47 //TODO: add MulticastRouteAdminService
48
alshabibed0951f2015-10-02 21:39:27 +020049 private Logger log = getLogger(getClass());
50
alshabib79e52872015-12-07 16:01:01 -080051 private final McastStoreDelegate delegate = new InternalMcastStoreDelegate();
alshabibed0951f2015-10-02 21:39:27 +020052
53 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
alshabib79e52872015-12-07 16:01:01 -080054 protected McastStore store;
alshabibed0951f2015-10-02 21:39:27 +020055
56 @Activate
57 public void activate() {
alshabibed0951f2015-10-02 21:39:27 +020058 eventDispatcher.addSink(McastEvent.class, listenerRegistry);
alshabib79e52872015-12-07 16:01:01 -080059 store.setDelegate(delegate);
alshabibed0951f2015-10-02 21:39:27 +020060
61 log.info("Started");
62 }
63
64 @Deactivate
65 public void deactivate() {
Yuta HIGUCHIdf43aa32017-05-26 21:26:09 -070066 store.unsetDelegate(delegate);
Victor Silva878c78c2016-11-14 13:32:36 -030067 eventDispatcher.removeSink(McastEvent.class);
alshabibed0951f2015-10-02 21:39:27 +020068 log.info("Stopped");
69 }
70
71 @Override
72 public void add(McastRoute route) {
alshabib79e52872015-12-07 16:01:01 -080073 checkNotNull(route, "Route cannot be null");
74 store.storeRoute(route, McastStore.Type.ADD);
alshabibed0951f2015-10-02 21:39:27 +020075 }
76
77 @Override
78 public void remove(McastRoute route) {
alshabib79e52872015-12-07 16:01:01 -080079 checkNotNull(route, "Route cannot be null");
80 store.storeRoute(route, McastStore.Type.REMOVE);
alshabibed0951f2015-10-02 21:39:27 +020081 }
82
83 @Override
Jonathan Hart07eb0412016-02-08 16:42:29 -080084 public Set<McastRoute> getRoutes() {
85 return store.getRoutes();
86 }
87
88 @Override
alshabibed0951f2015-10-02 21:39:27 +020089 public void addSource(McastRoute route, ConnectPoint connectPoint) {
alshabib79e52872015-12-07 16:01:01 -080090 checkNotNull(route, "Route cannot be null");
91 checkNotNull(connectPoint, "Source cannot be null");
92 store.storeSource(route, connectPoint);
alshabibed0951f2015-10-02 21:39:27 +020093 }
94
95 @Override
96 public void addSink(McastRoute route, ConnectPoint connectPoint) {
alshabib79e52872015-12-07 16:01:01 -080097 checkNotNull(route, "Route cannot be null");
98 checkNotNull(connectPoint, "Sink cannot be null");
99 store.storeSink(route, connectPoint, McastStore.Type.ADD);
alshabibc6b60802015-10-06 11:42:50 +0200100
alshabibed0951f2015-10-02 21:39:27 +0200101 }
102
alshabibed0951f2015-10-02 21:39:27 +0200103 @Override
104 public void removeSink(McastRoute route, ConnectPoint connectPoint) {
alshabibc6b60802015-10-06 11:42:50 +0200105
alshabib79e52872015-12-07 16:01:01 -0800106 checkNotNull(route, "Route cannot be null");
107 checkNotNull(connectPoint, "Sink cannot be null");
108
109 store.storeSink(route, connectPoint, McastStore.Type.REMOVE);
alshabibed0951f2015-10-02 21:39:27 +0200110 }
111
112 @Override
113 public ConnectPoint fetchSource(McastRoute route) {
alshabib79e52872015-12-07 16:01:01 -0800114 return store.sourceFor(route);
alshabibed0951f2015-10-02 21:39:27 +0200115 }
116
117 @Override
alshabib79e52872015-12-07 16:01:01 -0800118 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 }
alshabibed0951f2015-10-02 21:39:27 +0200127 }
128}