blob: 643bb2b90daa9f97be8fbd5fb2126bedda338404 [file] [log] [blame]
Thomas Vachuska781d18b2014-10-27 10:31:25 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2014-present Open Networking Laboratory
Thomas Vachuska781d18b2014-10-27 10:31:25 -07003 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07004 * 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
Thomas Vachuska781d18b2014-10-27 10:31:25 -07007 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07008 * 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.
Thomas Vachuska781d18b2014-10-27 10:31:25 -070015 */
Brian O'Connorabafb502014-12-02 22:26:20 -080016package org.onosproject.sdnip;
Jonathan Hart039d2b12014-10-10 09:33:04 -070017
Jonathan Hart3d8ff282016-09-06 10:59:41 -070018import com.google.common.collect.ImmutableList;
Jonathan Hart039d2b12014-10-10 09:33:04 -070019import org.apache.felix.scr.annotations.Activate;
20import org.apache.felix.scr.annotations.Component;
21import org.apache.felix.scr.annotations.Deactivate;
Jonathan Hartdc711bd2014-10-15 11:24:23 -070022import org.apache.felix.scr.annotations.Reference;
23import org.apache.felix.scr.annotations.ReferenceCardinality;
Pingping Linc07781f2015-10-30 00:44:41 -070024import org.onosproject.app.ApplicationService;
Brian O'Connorabafb502014-12-02 22:26:20 -080025import org.onosproject.core.ApplicationId;
26import org.onosproject.core.CoreService;
Jonathan Hartc22e8472015-11-17 18:25:45 -080027import org.onosproject.incubator.component.ComponentService;
Jonathan Hart4cb39882015-08-12 23:50:55 -040028import org.onosproject.incubator.net.intf.InterfaceService;
Pingping Linc07781f2015-10-30 00:44:41 -070029import org.onosproject.net.config.NetworkConfigService;
Jonathan Hart9a426f82015-09-03 15:43:13 +020030import org.onosproject.routing.IntentSynchronizationService;
Jonathan Hart2da1e602015-02-18 19:09:24 -080031import org.onosproject.routing.RoutingService;
Pavlin Radoslavova7243cc2014-11-22 21:38:02 -080032import org.slf4j.Logger;
Pavlin Radoslavov8b752442014-11-18 14:34:37 -080033
Jonathan Hartc22e8472015-11-17 18:25:45 -080034import java.util.List;
35
Jonathan Hart365335e2015-12-10 11:09:53 -080036import static org.slf4j.LoggerFactory.getLogger;
37
Jonathan Hart039d2b12014-10-10 09:33:04 -070038/**
Jonathan Hart0b04bed2014-10-16 16:39:19 -070039 * Component for the SDN-IP peering application.
Jonathan Hart039d2b12014-10-10 09:33:04 -070040 */
41@Component(immediate = true)
Jonathan Hart365335e2015-12-10 11:09:53 -080042public class SdnIp {
Jonathan Hart039d2b12014-10-10 09:33:04 -070043
Jonathan Hart365335e2015-12-10 11:09:53 -080044 public static final String SDN_IP_APP = "org.onosproject.sdnip";
Jonathan Hart039d2b12014-10-10 09:33:04 -070045 private final Logger log = getLogger(getClass());
46
Jonathan Hartdc711bd2014-10-15 11:24:23 -070047 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
Thomas Vachuskab97cf282014-10-20 23:31:12 -070048 protected CoreService coreService;
49
50 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
Pingping Linc07781f2015-10-30 00:44:41 -070051 protected ApplicationService applicationService;
52
53 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
Pavlin Radoslavov492cc3a2015-01-22 18:46:26 -080054 protected NetworkConfigService networkConfigService;
55
Jonathan Hart4cb39882015-08-12 23:50:55 -040056 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
57 protected InterfaceService interfaceService;
58
Jonathan Hart365335e2015-12-10 11:09:53 -080059 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
60 protected IntentSynchronizationService intentSynchronizer;
Jonathan Hart41349e92015-02-09 14:14:02 -080061
Jonathan Hart365335e2015-12-10 11:09:53 -080062 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
Jonathan Hartc22e8472015-11-17 18:25:45 -080063 protected ComponentService componentService;
64
Jonathan Hart365335e2015-12-10 11:09:53 -080065 private PeerConnectivityManager peerConnectivity;
66
Pavlin Radoslavovc91eebe2014-11-25 18:45:46 -080067 private ApplicationId appId;
Pavlin Radoslavov8b752442014-11-18 14:34:37 -080068
Jonathan Hart3d8ff282016-09-06 10:59:41 -070069 private final List<String> components = ImmutableList.of(
70 "org.onosproject.routing.bgp.BgpSessionManager",
Jonathan Harta9e29552016-09-09 07:17:41 -070071 "org.onosproject.routing.impl.BgpSpeakerNeighbourHandler",
Jonathan Hart3d8ff282016-09-06 10:59:41 -070072 org.onosproject.sdnip.SdnIpFib.class.getName()
73 );
Jonathan Hartc22e8472015-11-17 18:25:45 -080074
Jonathan Hart039d2b12014-10-10 09:33:04 -070075 @Activate
Jonathan Hartd24fafb2015-02-09 17:55:32 -080076 protected void activate() {
Jonathan Hartc22e8472015-11-17 18:25:45 -080077 components.forEach(name -> componentService.activate(appId, name));
78
Pavlin Radoslavova7243cc2014-11-22 21:38:02 -080079 appId = coreService.registerApplication(SDN_IP_APP);
Jonathan Hartdc711bd2014-10-15 11:24:23 -070080
Pavlin Radoslavova7243cc2014-11-22 21:38:02 -080081 peerConnectivity = new PeerConnectivityManager(appId,
82 intentSynchronizer,
Jonathan Hart4cb39882015-08-12 23:50:55 -040083 networkConfigService,
Jonathan Hart365335e2015-12-10 11:09:53 -080084 coreService.registerApplication(RoutingService.ROUTER_APP_ID),
Jonathan Hart4cb39882015-08-12 23:50:55 -040085 interfaceService);
Jonathan Hartdc711bd2014-10-15 11:24:23 -070086 peerConnectivity.start();
87
Jonathan Hart3d8ff282016-09-06 10:59:41 -070088 applicationService.registerDeactivateHook(appId,
89 () -> intentSynchronizer.removeIntentsByAppId(appId));
Pingping Linc07781f2015-10-30 00:44:41 -070090
Jonathan Hart3d8ff282016-09-06 10:59:41 -070091 log.info("Started");
Jonathan Hart039d2b12014-10-10 09:33:04 -070092 }
93
94 @Deactivate
95 protected void deactivate() {
Jonathan Hartc22e8472015-11-17 18:25:45 -080096 components.forEach(name -> componentService.deactivate(appId, name));
97
Pavlin Radoslavova071b1e2014-11-17 13:37:57 -080098 peerConnectivity.stop();
Pavlin Radoslavov8b752442014-11-18 14:34:37 -080099
Jonathan Hart3d8ff282016-09-06 10:59:41 -0700100 log.info("Stopped");
Jonathan Hart039d2b12014-10-10 09:33:04 -0700101 }
Jonathan Hart039d2b12014-10-10 09:33:04 -0700102}