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; |
| 19 | import org.apache.felix.scr.annotations.Activate; |
| 20 | import org.apache.felix.scr.annotations.Component; |
| 21 | import org.apache.felix.scr.annotations.Deactivate; |
| 22 | import org.apache.felix.scr.annotations.Reference; |
| 23 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
Jonathan Hart | c43fd1c | 2016-01-18 20:02:20 -0800 | [diff] [blame] | 24 | import org.apache.felix.scr.annotations.Service; |
Thomas Vachuska | 9fadbfc | 2015-07-23 10:56:02 -0700 | [diff] [blame] | 25 | import org.onosproject.core.CoreService; |
Jonathan Hart | eb8c947 | 2015-08-05 07:43:13 -0700 | [diff] [blame] | 26 | import org.onosproject.incubator.net.config.basics.InterfaceConfig; |
Andrea Campanella | 75ef9f5 | 2017-07-27 20:14:32 +0200 | [diff] [blame] | 27 | import org.onosproject.incubator.net.config.basics.PortDescriptionsConfig; |
Jonathan Hart | 111b42b | 2015-07-14 13:28:05 -0700 | [diff] [blame] | 28 | import org.onosproject.net.ConnectPoint; |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 29 | import org.onosproject.net.DeviceId; |
| 30 | import org.onosproject.net.HostId; |
| 31 | import org.onosproject.net.LinkKey; |
Jonathan Hart | c43fd1c | 2016-01-18 20:02:20 -0800 | [diff] [blame] | 32 | import org.onosproject.net.config.BasicNetworkConfigService; |
Thomas Vachuska | 4998caa | 2015-08-26 13:28:38 -0700 | [diff] [blame] | 33 | import org.onosproject.net.config.ConfigFactory; |
| 34 | import org.onosproject.net.config.NetworkConfigRegistry; |
| 35 | import org.onosproject.net.config.basics.BasicDeviceConfig; |
| 36 | import org.onosproject.net.config.basics.BasicHostConfig; |
| 37 | import org.onosproject.net.config.basics.BasicLinkConfig; |
Simon Hunt | f59d36b | 2016-10-04 19:05:53 -0700 | [diff] [blame] | 38 | import org.onosproject.net.config.basics.BasicRegionConfig; |
Simon Hunt | d7395c8 | 2016-10-20 17:54:01 -0700 | [diff] [blame] | 39 | import org.onosproject.net.config.basics.BasicUiTopoLayoutConfig; |
Yuta HIGUCHI | 7438f5a | 2017-02-15 22:09:46 -0800 | [diff] [blame] | 40 | import org.onosproject.net.config.basics.PortAnnotationConfig; |
Thomas Vachuska | 4998caa | 2015-08-26 13:28:38 -0700 | [diff] [blame] | 41 | import org.onosproject.net.config.basics.SubjectFactories; |
Simon Hunt | f59d36b | 2016-10-04 19:05:53 -0700 | [diff] [blame] | 42 | import org.onosproject.net.region.RegionId; |
Simon Hunt | d7395c8 | 2016-10-20 17:54:01 -0700 | [diff] [blame] | 43 | import org.onosproject.ui.model.topo.UiTopoLayoutId; |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 44 | import org.slf4j.Logger; |
| 45 | import org.slf4j.LoggerFactory; |
| 46 | |
| 47 | import java.util.Set; |
| 48 | |
Simon Hunt | f59d36b | 2016-10-04 19:05:53 -0700 | [diff] [blame] | 49 | import static org.onosproject.net.config.basics.SubjectFactories.CONNECT_POINT_SUBJECT_FACTORY; |
| 50 | import static org.onosproject.net.config.basics.SubjectFactories.DEVICE_SUBJECT_FACTORY; |
| 51 | import static org.onosproject.net.config.basics.SubjectFactories.HOST_SUBJECT_FACTORY; |
Simon Hunt | d7395c8 | 2016-10-20 17:54:01 -0700 | [diff] [blame] | 52 | import static org.onosproject.net.config.basics.SubjectFactories.LAYOUT_SUBJECT_FACTORY; |
Simon Hunt | f59d36b | 2016-10-04 19:05:53 -0700 | [diff] [blame] | 53 | import static org.onosproject.net.config.basics.SubjectFactories.LINK_SUBJECT_FACTORY; |
| 54 | import static org.onosproject.net.config.basics.SubjectFactories.REGION_SUBJECT_FACTORY; |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 55 | |
| 56 | /** |
| 57 | * Component for registration of builtin basic network configurations. |
| 58 | */ |
Jonathan Hart | c43fd1c | 2016-01-18 20:02:20 -0800 | [diff] [blame] | 59 | @Service |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 60 | @Component(immediate = true) |
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, |
Simon Hunt | f59d36b | 2016-10-04 19:05:53 -0700 | [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, |
Simon Hunt | f59d36b | 2016-10-04 19:05:53 -0700 | [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, |
Simon Hunt | f59d36b | 2016-10-04 19:05:53 -0700 | [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, |
Simon Hunt | f59d36b | 2016-10-04 19:05:53 -0700 | [diff] [blame] | 96 | BasicLinkConfig.class, |
Yuta HIGUCHI | 2103304 | 2017-05-04 17:58:24 -0700 | [diff] [blame] | 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, |
| 104 | BasicRegionConfig.class, |
| 105 | BASIC) { |
| 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, |
| 112 | BasicUiTopoLayoutConfig.class, |
| 113 | BASIC) { |
| 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, |
| 120 | PortAnnotationConfig.class, |
| 121 | PortAnnotationConfig.CONFIG_KEY) { |
| 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, |
| 128 | PortDescriptionsConfig.class, |
| 129 | PORTS) { |
| 130 | @Override |
| 131 | public PortDescriptionsConfig createConfig() { |
| 132 | return new PortDescriptionsConfig(); |
| 133 | } |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 134 | } |
Andrea Campanella | 75ef9f5 | 2017-07-27 20:14:32 +0200 | [diff] [blame] | 135 | |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 136 | ); |
| 137 | |
| 138 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
Thomas Vachuska | 9fadbfc | 2015-07-23 10:56:02 -0700 | [diff] [blame] | 139 | protected CoreService coreService; |
| 140 | |
| 141 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 142 | protected NetworkConfigRegistry registry; |
| 143 | |
| 144 | @Activate |
| 145 | public void activate() { |
Thomas Vachuska | 9fadbfc | 2015-07-23 10:56:02 -0700 | [diff] [blame] | 146 | SubjectFactories.setCoreService(coreService); |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 147 | factories.forEach(registry::registerConfigFactory); |
| 148 | log.info("Started"); |
| 149 | } |
| 150 | |
| 151 | @Deactivate |
| 152 | public void deactivate() { |
| 153 | factories.forEach(registry::unregisterConfigFactory); |
| 154 | log.info("Stopped"); |
| 155 | } |
| 156 | |
| 157 | } |