Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Foundation |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [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 | */ |
Thomas Vachuska | 4998caa | 2015-08-26 13:28:38 -0700 | [diff] [blame] | 16 | package org.onosproject.net.config.impl; |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 17 | |
| 18 | import com.google.common.collect.ImmutableSet; |
Thomas Vachuska | 9fadbfc | 2015-07-23 10:56:02 -0700 | [diff] [blame] | 19 | import org.onosproject.core.CoreService; |
Jonathan Hart | 111b42b | 2015-07-14 13:28:05 -0700 | [diff] [blame] | 20 | import org.onosproject.net.ConnectPoint; |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 21 | import org.onosproject.net.DeviceId; |
| 22 | import org.onosproject.net.HostId; |
| 23 | import org.onosproject.net.LinkKey; |
Jonathan Hart | c43fd1c | 2016-01-18 20:02:20 -0800 | [diff] [blame] | 24 | import org.onosproject.net.config.BasicNetworkConfigService; |
Thomas Vachuska | 4998caa | 2015-08-26 13:28:38 -0700 | [diff] [blame] | 25 | import org.onosproject.net.config.ConfigFactory; |
| 26 | import org.onosproject.net.config.NetworkConfigRegistry; |
| 27 | import org.onosproject.net.config.basics.BasicDeviceConfig; |
| 28 | import org.onosproject.net.config.basics.BasicHostConfig; |
| 29 | import org.onosproject.net.config.basics.BasicLinkConfig; |
Simon Hunt | f59d36b | 2016-10-04 19:05:53 -0700 | [diff] [blame] | 30 | import org.onosproject.net.config.basics.BasicRegionConfig; |
Simon Hunt | d7395c8 | 2016-10-20 17:54:01 -0700 | [diff] [blame] | 31 | import org.onosproject.net.config.basics.BasicUiTopoLayoutConfig; |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 32 | import org.onosproject.net.config.basics.DeviceAnnotationConfig; |
Rafał Szalecki | de5cf84 | 2018-11-17 13:30:01 +0100 | [diff] [blame^] | 33 | import org.onosproject.net.config.basics.HostAnnotationConfig; |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 34 | import org.onosproject.net.config.basics.InterfaceConfig; |
Yuta HIGUCHI | 7438f5a | 2017-02-15 22:09:46 -0800 | [diff] [blame] | 35 | import org.onosproject.net.config.basics.PortAnnotationConfig; |
Rafał Szalecki | de5cf84 | 2018-11-17 13:30:01 +0100 | [diff] [blame^] | 36 | import org.onosproject.net.config.basics.PortDescriptionsConfig; |
Thomas Vachuska | 4998caa | 2015-08-26 13:28:38 -0700 | [diff] [blame] | 37 | import org.onosproject.net.config.basics.SubjectFactories; |
Simon Hunt | f59d36b | 2016-10-04 19:05:53 -0700 | [diff] [blame] | 38 | import org.onosproject.net.region.RegionId; |
Simon Hunt | d7395c8 | 2016-10-20 17:54:01 -0700 | [diff] [blame] | 39 | import org.onosproject.ui.model.topo.UiTopoLayoutId; |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 40 | import org.osgi.service.component.annotations.Activate; |
| 41 | import org.osgi.service.component.annotations.Component; |
| 42 | import org.osgi.service.component.annotations.Deactivate; |
| 43 | import org.osgi.service.component.annotations.Reference; |
| 44 | import org.osgi.service.component.annotations.ReferenceCardinality; |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 45 | import org.slf4j.Logger; |
| 46 | import org.slf4j.LoggerFactory; |
| 47 | |
| 48 | import java.util.Set; |
| 49 | |
Simon Hunt | f59d36b | 2016-10-04 19:05:53 -0700 | [diff] [blame] | 50 | import static org.onosproject.net.config.basics.SubjectFactories.CONNECT_POINT_SUBJECT_FACTORY; |
| 51 | import static org.onosproject.net.config.basics.SubjectFactories.DEVICE_SUBJECT_FACTORY; |
| 52 | import static org.onosproject.net.config.basics.SubjectFactories.HOST_SUBJECT_FACTORY; |
Simon Hunt | d7395c8 | 2016-10-20 17:54:01 -0700 | [diff] [blame] | 53 | import static org.onosproject.net.config.basics.SubjectFactories.LAYOUT_SUBJECT_FACTORY; |
Simon Hunt | f59d36b | 2016-10-04 19:05:53 -0700 | [diff] [blame] | 54 | import static org.onosproject.net.config.basics.SubjectFactories.LINK_SUBJECT_FACTORY; |
| 55 | import static org.onosproject.net.config.basics.SubjectFactories.REGION_SUBJECT_FACTORY; |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 56 | |
| 57 | /** |
| 58 | * Component for registration of builtin basic network configurations. |
| 59 | */ |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 60 | @Component(immediate = true, service = BasicNetworkConfigService.class) |
Jonathan Hart | c43fd1c | 2016-01-18 20:02:20 -0800 | [diff] [blame] | 61 | public class BasicNetworkConfigs implements BasicNetworkConfigService { |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 62 | |
Simon Hunt | f59d36b | 2016-10-04 19:05:53 -0700 | [diff] [blame] | 63 | private static final String BASIC = "basic"; |
| 64 | private static final String INTERFACES = "interfaces"; |
Andrea Campanella | 75ef9f5 | 2017-07-27 20:14:32 +0200 | [diff] [blame] | 65 | private static final String PORTS = "ports"; |
Simon Hunt | f59d36b | 2016-10-04 19:05:53 -0700 | [diff] [blame] | 66 | |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 67 | private final Logger log = LoggerFactory.getLogger(getClass()); |
| 68 | |
| 69 | private final Set<ConfigFactory> factories = ImmutableSet.of( |
| 70 | new ConfigFactory<DeviceId, BasicDeviceConfig>(DEVICE_SUBJECT_FACTORY, |
Palash Kala | a06a616 | 2017-11-15 20:42:40 +0900 | [diff] [blame] | 71 | BasicDeviceConfig.class, |
| 72 | BASIC) { |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 73 | @Override |
| 74 | public BasicDeviceConfig createConfig() { |
| 75 | return new BasicDeviceConfig(); |
| 76 | } |
| 77 | }, |
Jonathan Hart | eb8c947 | 2015-08-05 07:43:13 -0700 | [diff] [blame] | 78 | new ConfigFactory<ConnectPoint, InterfaceConfig>(CONNECT_POINT_SUBJECT_FACTORY, |
Palash Kala | a06a616 | 2017-11-15 20:42:40 +0900 | [diff] [blame] | 79 | InterfaceConfig.class, |
| 80 | INTERFACES, |
| 81 | true) { |
Jonathan Hart | 111b42b | 2015-07-14 13:28:05 -0700 | [diff] [blame] | 82 | @Override |
Jonathan Hart | eb8c947 | 2015-08-05 07:43:13 -0700 | [diff] [blame] | 83 | public InterfaceConfig createConfig() { |
| 84 | return new InterfaceConfig(); |
Jonathan Hart | 111b42b | 2015-07-14 13:28:05 -0700 | [diff] [blame] | 85 | } |
| 86 | }, |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 87 | new ConfigFactory<HostId, BasicHostConfig>(HOST_SUBJECT_FACTORY, |
Palash Kala | a06a616 | 2017-11-15 20:42:40 +0900 | [diff] [blame] | 88 | BasicHostConfig.class, |
| 89 | BASIC) { |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 90 | @Override |
| 91 | public BasicHostConfig createConfig() { |
| 92 | return new BasicHostConfig(); |
| 93 | } |
| 94 | }, |
| 95 | new ConfigFactory<LinkKey, BasicLinkConfig>(LINK_SUBJECT_FACTORY, |
Palash Kala | a06a616 | 2017-11-15 20:42:40 +0900 | [diff] [blame] | 96 | BasicLinkConfig.class, |
| 97 | BasicLinkConfig.CONFIG_KEY) { |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 98 | @Override |
| 99 | public BasicLinkConfig createConfig() { |
| 100 | return new BasicLinkConfig(); |
| 101 | } |
Simon Hunt | f59d36b | 2016-10-04 19:05:53 -0700 | [diff] [blame] | 102 | }, |
| 103 | new ConfigFactory<RegionId, BasicRegionConfig>(REGION_SUBJECT_FACTORY, |
Palash Kala | a06a616 | 2017-11-15 20:42:40 +0900 | [diff] [blame] | 104 | BasicRegionConfig.class, |
| 105 | BASIC) { |
Simon Hunt | f59d36b | 2016-10-04 19:05:53 -0700 | [diff] [blame] | 106 | @Override |
| 107 | public BasicRegionConfig createConfig() { |
| 108 | return new BasicRegionConfig(); |
| 109 | } |
Simon Hunt | d7395c8 | 2016-10-20 17:54:01 -0700 | [diff] [blame] | 110 | }, |
| 111 | new ConfigFactory<UiTopoLayoutId, BasicUiTopoLayoutConfig>(LAYOUT_SUBJECT_FACTORY, |
Palash Kala | a06a616 | 2017-11-15 20:42:40 +0900 | [diff] [blame] | 112 | BasicUiTopoLayoutConfig.class, |
| 113 | BASIC) { |
Simon Hunt | d7395c8 | 2016-10-20 17:54:01 -0700 | [diff] [blame] | 114 | @Override |
| 115 | public BasicUiTopoLayoutConfig createConfig() { |
| 116 | return new BasicUiTopoLayoutConfig(); |
| 117 | } |
Yuta HIGUCHI | 7438f5a | 2017-02-15 22:09:46 -0800 | [diff] [blame] | 118 | }, |
| 119 | new ConfigFactory<ConnectPoint, PortAnnotationConfig>(CONNECT_POINT_SUBJECT_FACTORY, |
Palash Kala | a06a616 | 2017-11-15 20:42:40 +0900 | [diff] [blame] | 120 | PortAnnotationConfig.class, |
| 121 | PortAnnotationConfig.CONFIG_KEY) { |
Yuta HIGUCHI | 7438f5a | 2017-02-15 22:09:46 -0800 | [diff] [blame] | 122 | @Override |
| 123 | public PortAnnotationConfig createConfig() { |
| 124 | return new PortAnnotationConfig(); |
| 125 | } |
Andrea Campanella | 75ef9f5 | 2017-07-27 20:14:32 +0200 | [diff] [blame] | 126 | }, |
| 127 | new ConfigFactory<DeviceId, PortDescriptionsConfig>(DEVICE_SUBJECT_FACTORY, |
Palash Kala | a06a616 | 2017-11-15 20:42:40 +0900 | [diff] [blame] | 128 | PortDescriptionsConfig.class, |
| 129 | PORTS) { |
Andrea Campanella | 75ef9f5 | 2017-07-27 20:14:32 +0200 | [diff] [blame] | 130 | @Override |
| 131 | public PortDescriptionsConfig createConfig() { |
| 132 | return new PortDescriptionsConfig(); |
| 133 | } |
Palash Kala | a06a616 | 2017-11-15 20:42:40 +0900 | [diff] [blame] | 134 | }, |
| 135 | new ConfigFactory<DeviceId, DeviceAnnotationConfig>(DEVICE_SUBJECT_FACTORY, |
| 136 | DeviceAnnotationConfig.class, |
| 137 | DeviceAnnotationConfig.CONFIG_KEY) { |
| 138 | @Override |
| 139 | public DeviceAnnotationConfig createConfig() { |
| 140 | return new DeviceAnnotationConfig(); |
| 141 | } |
Rafał Szalecki | de5cf84 | 2018-11-17 13:30:01 +0100 | [diff] [blame^] | 142 | }, |
| 143 | new ConfigFactory<HostId, HostAnnotationConfig>(HOST_SUBJECT_FACTORY, |
| 144 | HostAnnotationConfig.class, |
| 145 | HostAnnotationConfig.CONFIG_KEY) { |
| 146 | @Override |
| 147 | public HostAnnotationConfig createConfig() { |
| 148 | return new HostAnnotationConfig(); |
| 149 | } |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 150 | } |
Andrea Campanella | 75ef9f5 | 2017-07-27 20:14:32 +0200 | [diff] [blame] | 151 | |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 152 | ); |
| 153 | |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 154 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Thomas Vachuska | 9fadbfc | 2015-07-23 10:56:02 -0700 | [diff] [blame] | 155 | protected CoreService coreService; |
| 156 | |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 157 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 158 | protected NetworkConfigRegistry registry; |
| 159 | |
| 160 | @Activate |
| 161 | public void activate() { |
Thomas Vachuska | 9fadbfc | 2015-07-23 10:56:02 -0700 | [diff] [blame] | 162 | SubjectFactories.setCoreService(coreService); |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 163 | factories.forEach(registry::registerConfigFactory); |
| 164 | log.info("Started"); |
| 165 | } |
| 166 | |
| 167 | @Deactivate |
| 168 | public void deactivate() { |
| 169 | factories.forEach(registry::unregisterConfigFactory); |
| 170 | log.info("Stopped"); |
| 171 | } |
| 172 | |
| 173 | } |