blob: bbc8bdbb5a2ee98fdae068da689250d9475e4cc9 [file] [log] [blame]
alshabibed0951f2015-10-02 21:39:27 +02001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
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 */
16package org.onosproject.incubator.net.mcast.impl;
17
18import org.apache.felix.scr.annotations.Activate;
19import org.apache.felix.scr.annotations.Component;
20import org.apache.felix.scr.annotations.Deactivate;
21import org.apache.felix.scr.annotations.Reference;
22import org.apache.felix.scr.annotations.ReferenceCardinality;
23import org.apache.felix.scr.annotations.Service;
alshabibed0951f2015-10-02 21:39:27 +020024import org.onosproject.event.AbstractListenerManager;
25import org.onosproject.net.ConnectPoint;
26import org.onosproject.net.mcast.McastEvent;
27import org.onosproject.net.mcast.McastListener;
28import org.onosproject.net.mcast.McastRoute;
alshabib79e52872015-12-07 16:01:01 -080029import org.onosproject.net.mcast.McastStore;
30import org.onosproject.net.mcast.McastStoreDelegate;
alshabibed0951f2015-10-02 21:39:27 +020031import org.onosproject.net.mcast.MulticastRouteService;
alshabibed0951f2015-10-02 21:39:27 +020032import org.slf4j.Logger;
33
alshabib79e52872015-12-07 16:01:01 -080034import java.util.Set;
alshabibed0951f2015-10-02 21:39:27 +020035
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() {
Victor Silva878c78c2016-11-14 13:32:36 -030066 eventDispatcher.removeSink(McastEvent.class);
alshabibed0951f2015-10-02 21:39:27 +020067 log.info("Stopped");
68 }
69
70 @Override
71 public void add(McastRoute route) {
alshabib79e52872015-12-07 16:01:01 -080072 checkNotNull(route, "Route cannot be null");
73 store.storeRoute(route, McastStore.Type.ADD);
alshabibed0951f2015-10-02 21:39:27 +020074 }
75
76 @Override
77 public void remove(McastRoute route) {
alshabib79e52872015-12-07 16:01:01 -080078 checkNotNull(route, "Route cannot be null");
79 store.storeRoute(route, McastStore.Type.REMOVE);
alshabibed0951f2015-10-02 21:39:27 +020080 }
81
82 @Override
Jonathan Hart07eb0412016-02-08 16:42:29 -080083 public Set<McastRoute> getRoutes() {
84 return store.getRoutes();
85 }
86
87 @Override
alshabibed0951f2015-10-02 21:39:27 +020088 public void addSource(McastRoute route, ConnectPoint connectPoint) {
alshabib79e52872015-12-07 16:01:01 -080089 checkNotNull(route, "Route cannot be null");
90 checkNotNull(connectPoint, "Source cannot be null");
91 store.storeSource(route, connectPoint);
alshabibed0951f2015-10-02 21:39:27 +020092 }
93
94 @Override
95 public void addSink(McastRoute route, ConnectPoint connectPoint) {
alshabib79e52872015-12-07 16:01:01 -080096 checkNotNull(route, "Route cannot be null");
97 checkNotNull(connectPoint, "Sink cannot be null");
98 store.storeSink(route, connectPoint, McastStore.Type.ADD);
alshabibc6b60802015-10-06 11:42:50 +020099
alshabibed0951f2015-10-02 21:39:27 +0200100 }
101
alshabibed0951f2015-10-02 21:39:27 +0200102 @Override
103 public void removeSink(McastRoute route, ConnectPoint connectPoint) {
alshabibc6b60802015-10-06 11:42:50 +0200104
alshabib79e52872015-12-07 16:01:01 -0800105 checkNotNull(route, "Route cannot be null");
106 checkNotNull(connectPoint, "Sink cannot be null");
107
108 store.storeSink(route, connectPoint, McastStore.Type.REMOVE);
alshabibed0951f2015-10-02 21:39:27 +0200109 }
110
111 @Override
112 public ConnectPoint fetchSource(McastRoute route) {
alshabib79e52872015-12-07 16:01:01 -0800113 return store.sourceFor(route);
alshabibed0951f2015-10-02 21:39:27 +0200114 }
115
116 @Override
alshabib79e52872015-12-07 16:01:01 -0800117 public Set<ConnectPoint> fetchSinks(McastRoute route) {
118 return store.sinksFor(route);
119 }
120
121 private class InternalMcastStoreDelegate implements McastStoreDelegate {
122 @Override
123 public void notify(McastEvent event) {
124 post(event);
125 }
alshabibed0951f2015-10-02 21:39:27 +0200126 }
127}