Jonathan Hart | 3604bbc | 2016-01-07 11:16:42 -0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Laboratory |
Jonathan Hart | 3604bbc | 2016-01-07 11:16:42 -0800 | [diff] [blame] | 3 | * |
| 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 | */ |
| 16 | package org.onosproject.vrouter; |
| 17 | |
Charles Chan | 00d8b5f | 2016-12-04 17:17:39 -0800 | [diff] [blame] | 18 | import com.google.common.collect.Lists; |
Jonathan Hart | 3604bbc | 2016-01-07 11:16:42 -0800 | [diff] [blame] | 19 | import org.apache.felix.scr.annotations.Activate; |
| 20 | import org.apache.felix.scr.annotations.Component; |
| 21 | import org.apache.felix.scr.annotations.Deactivate; |
Charles Chan | 00d8b5f | 2016-12-04 17:17:39 -0800 | [diff] [blame] | 22 | import org.apache.felix.scr.annotations.Modified; |
| 23 | import org.apache.felix.scr.annotations.Property; |
Jonathan Hart | 3604bbc | 2016-01-07 11:16:42 -0800 | [diff] [blame] | 24 | import org.apache.felix.scr.annotations.Reference; |
| 25 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
Charles Chan | 00d8b5f | 2016-12-04 17:17:39 -0800 | [diff] [blame] | 26 | import org.onlab.util.Tools; |
Charles Chan | 0214ded | 2016-11-18 17:48:37 -0800 | [diff] [blame] | 27 | import org.onosproject.cfg.ComponentConfigService; |
Jonathan Hart | 3604bbc | 2016-01-07 11:16:42 -0800 | [diff] [blame] | 28 | import org.onosproject.core.ApplicationId; |
| 29 | import org.onosproject.core.CoreService; |
| 30 | import org.onosproject.incubator.component.ComponentService; |
Charles Chan | 00d8b5f | 2016-12-04 17:17:39 -0800 | [diff] [blame] | 31 | import org.osgi.service.component.ComponentContext; |
Jonathan Hart | 3604bbc | 2016-01-07 11:16:42 -0800 | [diff] [blame] | 32 | import org.slf4j.Logger; |
| 33 | import org.slf4j.LoggerFactory; |
| 34 | |
Charles Chan | 00d8b5f | 2016-12-04 17:17:39 -0800 | [diff] [blame] | 35 | import java.util.Dictionary; |
Jonathan Hart | 3604bbc | 2016-01-07 11:16:42 -0800 | [diff] [blame] | 36 | import java.util.List; |
| 37 | |
| 38 | /** |
| 39 | * Virtual router (vRouter) application. |
| 40 | */ |
| 41 | @Component(immediate = true) |
| 42 | public class Vrouter { |
| 43 | |
| 44 | private final Logger log = LoggerFactory.getLogger(getClass()); |
| 45 | |
| 46 | private static final String APP_NAME = "org.onosproject.vrouter"; |
Charles Chan | 00d8b5f | 2016-12-04 17:17:39 -0800 | [diff] [blame] | 47 | private static final String FPM_MANAGER = "org.onosproject.routing.fpm.FpmManager"; |
| 48 | private static final String FIB_INSTALLER = "org.onosproject.routing.impl.SingleSwitchFibInstaller"; |
| 49 | private static final String CP_REDIRECT = "org.onosproject.routing.impl.ControlPlaneRedirectManager"; |
| 50 | private static final String DIRECT_HOST_MGR = "org.onosproject.routing.impl.DirectHostManager"; |
Jonathan Hart | 3604bbc | 2016-01-07 11:16:42 -0800 | [diff] [blame] | 51 | |
| 52 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
Charles Chan | 00d8b5f | 2016-12-04 17:17:39 -0800 | [diff] [blame] | 53 | private CoreService coreService; |
Jonathan Hart | 3604bbc | 2016-01-07 11:16:42 -0800 | [diff] [blame] | 54 | |
| 55 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
Charles Chan | 00d8b5f | 2016-12-04 17:17:39 -0800 | [diff] [blame] | 56 | private ComponentService componentService; |
Jonathan Hart | 3604bbc | 2016-01-07 11:16:42 -0800 | [diff] [blame] | 57 | |
Charles Chan | 0214ded | 2016-11-18 17:48:37 -0800 | [diff] [blame] | 58 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
Charles Chan | 00d8b5f | 2016-12-04 17:17:39 -0800 | [diff] [blame] | 59 | private ComponentConfigService componentConfigService; |
| 60 | |
| 61 | /** |
| 62 | * vRouter will push flows to the switches when receiving routes by enabling |
| 63 | * FIB installer. |
| 64 | * <p> |
| 65 | * It should be turned off when vRouter is deployed in a scenario where |
| 66 | * other components that pushes the routes. |
| 67 | */ |
Jian Li | 220c2c2 | 2017-01-12 19:11:55 +0900 | [diff] [blame] | 68 | @Property(name = "fibInstallerEnabled", boolValue = true, |
Charles Chan | 00d8b5f | 2016-12-04 17:17:39 -0800 | [diff] [blame] | 69 | label = "Enable single switch fib installer; default is true") |
Jian Li | 220c2c2 | 2017-01-12 19:11:55 +0900 | [diff] [blame] | 70 | private boolean fibInstallerEnabled = true; |
Charles Chan | 0214ded | 2016-11-18 17:48:37 -0800 | [diff] [blame] | 71 | |
Jonathan Hart | 3604bbc | 2016-01-07 11:16:42 -0800 | [diff] [blame] | 72 | private ApplicationId appId; |
| 73 | |
Charles Chan | 00d8b5f | 2016-12-04 17:17:39 -0800 | [diff] [blame] | 74 | private List<String> baseComponents = Lists.newArrayList(FPM_MANAGER, CP_REDIRECT, DIRECT_HOST_MGR); |
Jonathan Hart | 63eeac3 | 2016-06-20 15:55:16 -0700 | [diff] [blame] | 75 | |
Jonathan Hart | 3604bbc | 2016-01-07 11:16:42 -0800 | [diff] [blame] | 76 | @Activate |
Charles Chan | 00d8b5f | 2016-12-04 17:17:39 -0800 | [diff] [blame] | 77 | protected void activate(ComponentContext context) { |
Jonathan Hart | 3604bbc | 2016-01-07 11:16:42 -0800 | [diff] [blame] | 78 | appId = coreService.registerApplication(APP_NAME); |
Charles Chan | 00d8b5f | 2016-12-04 17:17:39 -0800 | [diff] [blame] | 79 | componentConfigService.registerProperties(getClass()); |
Jonathan Hart | 3604bbc | 2016-01-07 11:16:42 -0800 | [diff] [blame] | 80 | |
Charles Chan | 0214ded | 2016-11-18 17:48:37 -0800 | [diff] [blame] | 81 | componentConfigService.preSetProperty( |
| 82 | "org.onosproject.incubator.store.routing.impl.RouteStoreImpl", |
| 83 | "distributed", "true"); |
| 84 | |
Charles Chan | 00d8b5f | 2016-12-04 17:17:39 -0800 | [diff] [blame] | 85 | baseComponents.forEach(name -> componentService.activate(appId, name)); |
| 86 | modified(context); |
Jonathan Hart | 3604bbc | 2016-01-07 11:16:42 -0800 | [diff] [blame] | 87 | |
| 88 | log.info("Started"); |
| 89 | } |
| 90 | |
| 91 | @Deactivate |
| 92 | protected void deactivate() { |
Charles Chan | 0214ded | 2016-11-18 17:48:37 -0800 | [diff] [blame] | 93 | componentConfigService.preSetProperty( |
| 94 | "org.onosproject.incubator.store.routing.impl.RouteStoreImpl", |
| 95 | "distributed", "false"); |
| 96 | |
Jonathan Hart | 3604bbc | 2016-01-07 11:16:42 -0800 | [diff] [blame] | 97 | log.info("Stopped"); |
| 98 | } |
| 99 | |
Charles Chan | 00d8b5f | 2016-12-04 17:17:39 -0800 | [diff] [blame] | 100 | @Modified |
| 101 | private void modified(ComponentContext context) { |
| 102 | Dictionary<?, ?> properties = context.getProperties(); |
| 103 | if (properties == null) { |
| 104 | return; |
| 105 | } |
| 106 | |
Jian Li | 918c0f2 | 2017-01-18 13:34:25 -0800 | [diff] [blame] | 107 | Boolean newFibInstallerEnabled = Tools.isPropertyEnabled(properties, "fibInstallerEnabled"); |
Jian Li | 220c2c2 | 2017-01-12 19:11:55 +0900 | [diff] [blame] | 108 | if (newFibInstallerEnabled == null) { |
| 109 | log.info("fibInstallerEnabled is not configured, " + |
| 110 | "using current value of {}", fibInstallerEnabled); |
| 111 | } else { |
| 112 | fibInstallerEnabled = newFibInstallerEnabled; |
| 113 | log.info("Configured. fibInstallerEnabled set to {}, ", |
| 114 | fibInstallerEnabled ? "enabled" : "disabled"); |
| 115 | } |
Charles Chan | 00d8b5f | 2016-12-04 17:17:39 -0800 | [diff] [blame] | 116 | |
| 117 | if (fibInstallerEnabled) { |
| 118 | componentService.activate(appId, FIB_INSTALLER); |
| 119 | } else { |
| 120 | componentService.deactivate(appId, FIB_INSTALLER); |
| 121 | } |
| 122 | } |
Jonathan Hart | 3604bbc | 2016-01-07 11:16:42 -0800 | [diff] [blame] | 123 | } |