Thomas Vachuska | 781d18b | 2014-10-27 10:31:25 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2014-present Open Networking Foundation |
Thomas Vachuska | 781d18b | 2014-10-27 10:31:25 -0700 | [diff] [blame] | 3 | * |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 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 |
Thomas Vachuska | 781d18b | 2014-10-27 10:31:25 -0700 | [diff] [blame] | 7 | * |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 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. |
Thomas Vachuska | 781d18b | 2014-10-27 10:31:25 -0700 | [diff] [blame] | 15 | */ |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 16 | package org.onosproject.sdnip; |
Jonathan Hart | 039d2b1 | 2014-10-10 09:33:04 -0700 | [diff] [blame] | 17 | |
Jonathan Hart | 3d8ff28 | 2016-09-06 10:59:41 -0700 | [diff] [blame] | 18 | import com.google.common.collect.ImmutableList; |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 19 | import org.osgi.service.component.annotations.Activate; |
| 20 | import org.osgi.service.component.annotations.Component; |
| 21 | import org.osgi.service.component.annotations.Deactivate; |
| 22 | import org.osgi.service.component.annotations.Reference; |
| 23 | import org.osgi.service.component.annotations.ReferenceCardinality; |
Pingping Lin | c07781f | 2015-10-30 00:44:41 -0700 | [diff] [blame] | 24 | import org.onosproject.app.ApplicationService; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 25 | import org.onosproject.core.ApplicationId; |
| 26 | import org.onosproject.core.CoreService; |
Ray Milkey | e56c34d | 2017-08-03 13:39:30 -0700 | [diff] [blame] | 27 | import org.onosproject.component.ComponentService; |
Ray Milkey | facf286 | 2017-08-03 11:58:29 -0700 | [diff] [blame] | 28 | import org.onosproject.net.intf.InterfaceService; |
Luca Prete | 83bac34 | 2016-12-06 19:42:05 -0800 | [diff] [blame] | 29 | import org.onosproject.net.config.ConfigFactory; |
| 30 | import org.onosproject.net.config.NetworkConfigRegistry; |
Pingping Lin | c07781f | 2015-10-30 00:44:41 -0700 | [diff] [blame] | 31 | import org.onosproject.net.config.NetworkConfigService; |
Luca Prete | 83bac34 | 2016-12-06 19:42:05 -0800 | [diff] [blame] | 32 | import org.onosproject.net.config.basics.SubjectFactories; |
Jonathan Hart | 470ed4f | 2017-01-31 16:52:28 -0800 | [diff] [blame] | 33 | import org.onosproject.intentsync.IntentSynchronizationService; |
Jonathan Hart | 2da1e60 | 2015-02-18 19:09:24 -0800 | [diff] [blame] | 34 | import org.onosproject.routing.RoutingService; |
slowr | 8bbf77f | 2017-07-05 14:24:47 -0700 | [diff] [blame] | 35 | import org.onosproject.routing.config.RoutingConfiguration; |
Luca Prete | 83bac34 | 2016-12-06 19:42:05 -0800 | [diff] [blame] | 36 | import org.onosproject.sdnip.config.SdnIpConfig; |
Pavlin Radoslavov | a7243cc | 2014-11-22 21:38:02 -0800 | [diff] [blame] | 37 | import org.slf4j.Logger; |
Pavlin Radoslavov | 8b75244 | 2014-11-18 14:34:37 -0800 | [diff] [blame] | 38 | |
Jonathan Hart | c22e847 | 2015-11-17 18:25:45 -0800 | [diff] [blame] | 39 | import java.util.List; |
| 40 | |
Jonathan Hart | 365335e | 2015-12-10 11:09:53 -0800 | [diff] [blame] | 41 | import static org.slf4j.LoggerFactory.getLogger; |
| 42 | |
Jonathan Hart | 039d2b1 | 2014-10-10 09:33:04 -0700 | [diff] [blame] | 43 | /** |
Jonathan Hart | 0b04bed | 2014-10-16 16:39:19 -0700 | [diff] [blame] | 44 | * Component for the SDN-IP peering application. |
Jonathan Hart | 039d2b1 | 2014-10-10 09:33:04 -0700 | [diff] [blame] | 45 | */ |
| 46 | @Component(immediate = true) |
Jonathan Hart | 365335e | 2015-12-10 11:09:53 -0800 | [diff] [blame] | 47 | public class SdnIp { |
Jonathan Hart | 039d2b1 | 2014-10-10 09:33:04 -0700 | [diff] [blame] | 48 | |
Jonathan Hart | 365335e | 2015-12-10 11:09:53 -0800 | [diff] [blame] | 49 | public static final String SDN_IP_APP = "org.onosproject.sdnip"; |
Jonathan Hart | 039d2b1 | 2014-10-10 09:33:04 -0700 | [diff] [blame] | 50 | private final Logger log = getLogger(getClass()); |
| 51 | |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 52 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Thomas Vachuska | b97cf28 | 2014-10-20 23:31:12 -0700 | [diff] [blame] | 53 | protected CoreService coreService; |
| 54 | |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 55 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Pingping Lin | c07781f | 2015-10-30 00:44:41 -0700 | [diff] [blame] | 56 | protected ApplicationService applicationService; |
| 57 | |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 58 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Pavlin Radoslavov | 492cc3a | 2015-01-22 18:46:26 -0800 | [diff] [blame] | 59 | protected NetworkConfigService networkConfigService; |
| 60 | |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 61 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Jonathan Hart | 4cb3988 | 2015-08-12 23:50:55 -0400 | [diff] [blame] | 62 | protected InterfaceService interfaceService; |
| 63 | |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 64 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Jonathan Hart | 365335e | 2015-12-10 11:09:53 -0800 | [diff] [blame] | 65 | protected IntentSynchronizationService intentSynchronizer; |
Jonathan Hart | 41349e9 | 2015-02-09 14:14:02 -0800 | [diff] [blame] | 66 | |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 67 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Luca Prete | 83bac34 | 2016-12-06 19:42:05 -0800 | [diff] [blame] | 68 | protected NetworkConfigRegistry cfgRegistry; |
| 69 | |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 70 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Jonathan Hart | c22e847 | 2015-11-17 18:25:45 -0800 | [diff] [blame] | 71 | protected ComponentService componentService; |
| 72 | |
Jonathan Hart | 365335e | 2015-12-10 11:09:53 -0800 | [diff] [blame] | 73 | private PeerConnectivityManager peerConnectivity; |
| 74 | |
Pavlin Radoslavov | c91eebe | 2014-11-25 18:45:46 -0800 | [diff] [blame] | 75 | private ApplicationId appId; |
Pavlin Radoslavov | 8b75244 | 2014-11-18 14:34:37 -0800 | [diff] [blame] | 76 | |
Jonathan Hart | 3d8ff28 | 2016-09-06 10:59:41 -0700 | [diff] [blame] | 77 | private final List<String> components = ImmutableList.of( |
| 78 | "org.onosproject.routing.bgp.BgpSessionManager", |
Jonathan Hart | a9e2955 | 2016-09-09 07:17:41 -0700 | [diff] [blame] | 79 | "org.onosproject.routing.impl.BgpSpeakerNeighbourHandler", |
Jonathan Hart | 3d8ff28 | 2016-09-06 10:59:41 -0700 | [diff] [blame] | 80 | org.onosproject.sdnip.SdnIpFib.class.getName() |
| 81 | ); |
Jonathan Hart | c22e847 | 2015-11-17 18:25:45 -0800 | [diff] [blame] | 82 | |
Luca Prete | 83bac34 | 2016-12-06 19:42:05 -0800 | [diff] [blame] | 83 | private final List<ConfigFactory<?, ?>> factories = ImmutableList.of( |
| 84 | new ConfigFactory<ApplicationId, SdnIpConfig>(SubjectFactories.APP_SUBJECT_FACTORY, |
| 85 | SdnIpConfig.class, SdnIpConfig.CONFIG_KEY) { |
| 86 | @Override |
| 87 | public SdnIpConfig createConfig() { |
| 88 | return new SdnIpConfig(); |
| 89 | } |
| 90 | }); |
| 91 | |
Jonathan Hart | 039d2b1 | 2014-10-10 09:33:04 -0700 | [diff] [blame] | 92 | @Activate |
Jonathan Hart | d24fafb | 2015-02-09 17:55:32 -0800 | [diff] [blame] | 93 | protected void activate() { |
Pavlin Radoslavov | a7243cc | 2014-11-22 21:38:02 -0800 | [diff] [blame] | 94 | appId = coreService.registerApplication(SDN_IP_APP); |
Jonathan Hart | dc711bd | 2014-10-15 11:24:23 -0700 | [diff] [blame] | 95 | |
slowr | 8bbf77f | 2017-07-05 14:24:47 -0700 | [diff] [blame] | 96 | RoutingConfiguration.register(cfgRegistry); |
| 97 | |
Luca Prete | 83bac34 | 2016-12-06 19:42:05 -0800 | [diff] [blame] | 98 | factories.forEach(cfgRegistry::registerConfigFactory); |
| 99 | |
| 100 | components.forEach(name -> componentService.activate(appId, name)); |
| 101 | |
Pavlin Radoslavov | a7243cc | 2014-11-22 21:38:02 -0800 | [diff] [blame] | 102 | peerConnectivity = new PeerConnectivityManager(appId, |
| 103 | intentSynchronizer, |
Jonathan Hart | 4cb3988 | 2015-08-12 23:50:55 -0400 | [diff] [blame] | 104 | networkConfigService, |
Jonathan Hart | 365335e | 2015-12-10 11:09:53 -0800 | [diff] [blame] | 105 | coreService.registerApplication(RoutingService.ROUTER_APP_ID), |
Jonathan Hart | 4cb3988 | 2015-08-12 23:50:55 -0400 | [diff] [blame] | 106 | interfaceService); |
Jonathan Hart | dc711bd | 2014-10-15 11:24:23 -0700 | [diff] [blame] | 107 | peerConnectivity.start(); |
| 108 | |
Jonathan Hart | 3d8ff28 | 2016-09-06 10:59:41 -0700 | [diff] [blame] | 109 | applicationService.registerDeactivateHook(appId, |
| 110 | () -> intentSynchronizer.removeIntentsByAppId(appId)); |
Pingping Lin | c07781f | 2015-10-30 00:44:41 -0700 | [diff] [blame] | 111 | |
Jonathan Hart | 3d8ff28 | 2016-09-06 10:59:41 -0700 | [diff] [blame] | 112 | log.info("Started"); |
Jonathan Hart | 039d2b1 | 2014-10-10 09:33:04 -0700 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | @Deactivate |
| 116 | protected void deactivate() { |
Jonathan Hart | c22e847 | 2015-11-17 18:25:45 -0800 | [diff] [blame] | 117 | components.forEach(name -> componentService.deactivate(appId, name)); |
| 118 | |
slowr | 8bbf77f | 2017-07-05 14:24:47 -0700 | [diff] [blame] | 119 | RoutingConfiguration.unregister(cfgRegistry); |
| 120 | |
Luca Prete | 83bac34 | 2016-12-06 19:42:05 -0800 | [diff] [blame] | 121 | factories.forEach(cfgRegistry::unregisterConfigFactory); |
| 122 | |
Pavlin Radoslavov | a071b1e | 2014-11-17 13:37:57 -0800 | [diff] [blame] | 123 | peerConnectivity.stop(); |
Pavlin Radoslavov | 8b75244 | 2014-11-18 14:34:37 -0800 | [diff] [blame] | 124 | |
Jonathan Hart | 3d8ff28 | 2016-09-06 10:59:41 -0700 | [diff] [blame] | 125 | log.info("Stopped"); |
Jonathan Hart | 039d2b1 | 2014-10-10 09:33:04 -0700 | [diff] [blame] | 126 | } |
Jonathan Hart | 039d2b1 | 2014-10-10 09:33:04 -0700 | [diff] [blame] | 127 | } |