Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Laboratory |
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; |
Jonathan Hart | 111b42b | 2015-07-14 13:28:05 -0700 | [diff] [blame] | 27 | import org.onosproject.net.ConnectPoint; |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 28 | import org.onosproject.net.DeviceId; |
| 29 | import org.onosproject.net.HostId; |
| 30 | import org.onosproject.net.LinkKey; |
Jonathan Hart | c43fd1c | 2016-01-18 20:02:20 -0800 | [diff] [blame] | 31 | import org.onosproject.net.config.BasicNetworkConfigService; |
Thomas Vachuska | 4998caa | 2015-08-26 13:28:38 -0700 | [diff] [blame] | 32 | import org.onosproject.net.config.ConfigFactory; |
| 33 | import org.onosproject.net.config.NetworkConfigRegistry; |
| 34 | import org.onosproject.net.config.basics.BasicDeviceConfig; |
| 35 | import org.onosproject.net.config.basics.BasicHostConfig; |
| 36 | import org.onosproject.net.config.basics.BasicLinkConfig; |
Simon Hunt | f59d36b | 2016-10-04 19:05:53 -0700 | [diff] [blame] | 37 | import org.onosproject.net.config.basics.BasicRegionConfig; |
Simon Hunt | d7395c8 | 2016-10-20 17:54:01 -0700 | [diff] [blame] | 38 | import org.onosproject.net.config.basics.BasicUiTopoLayoutConfig; |
Yuta HIGUCHI | 7438f5a | 2017-02-15 22:09:46 -0800 | [diff] [blame^] | 39 | import org.onosproject.net.config.basics.PortAnnotationConfig; |
Thomas Vachuska | 4998caa | 2015-08-26 13:28:38 -0700 | [diff] [blame] | 40 | import org.onosproject.net.config.basics.SubjectFactories; |
Simon Hunt | f59d36b | 2016-10-04 19:05:53 -0700 | [diff] [blame] | 41 | import org.onosproject.net.region.RegionId; |
Simon Hunt | d7395c8 | 2016-10-20 17:54:01 -0700 | [diff] [blame] | 42 | import org.onosproject.ui.model.topo.UiTopoLayoutId; |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 43 | import org.slf4j.Logger; |
| 44 | import org.slf4j.LoggerFactory; |
| 45 | |
| 46 | import java.util.Set; |
| 47 | |
Simon Hunt | f59d36b | 2016-10-04 19:05:53 -0700 | [diff] [blame] | 48 | import static org.onosproject.net.config.basics.SubjectFactories.CONNECT_POINT_SUBJECT_FACTORY; |
| 49 | import static org.onosproject.net.config.basics.SubjectFactories.DEVICE_SUBJECT_FACTORY; |
| 50 | import static org.onosproject.net.config.basics.SubjectFactories.HOST_SUBJECT_FACTORY; |
Simon Hunt | d7395c8 | 2016-10-20 17:54:01 -0700 | [diff] [blame] | 51 | import static org.onosproject.net.config.basics.SubjectFactories.LAYOUT_SUBJECT_FACTORY; |
Simon Hunt | f59d36b | 2016-10-04 19:05:53 -0700 | [diff] [blame] | 52 | import static org.onosproject.net.config.basics.SubjectFactories.LINK_SUBJECT_FACTORY; |
| 53 | import static org.onosproject.net.config.basics.SubjectFactories.REGION_SUBJECT_FACTORY; |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 54 | |
| 55 | /** |
| 56 | * Component for registration of builtin basic network configurations. |
| 57 | */ |
Jonathan Hart | c43fd1c | 2016-01-18 20:02:20 -0800 | [diff] [blame] | 58 | @Service |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 59 | @Component(immediate = true) |
Jonathan Hart | c43fd1c | 2016-01-18 20:02:20 -0800 | [diff] [blame] | 60 | public class BasicNetworkConfigs implements BasicNetworkConfigService { |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 61 | |
Simon Hunt | f59d36b | 2016-10-04 19:05:53 -0700 | [diff] [blame] | 62 | private static final String BASIC = "basic"; |
| 63 | private static final String INTERFACES = "interfaces"; |
| 64 | |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 65 | private final Logger log = LoggerFactory.getLogger(getClass()); |
| 66 | |
| 67 | private final Set<ConfigFactory> factories = ImmutableSet.of( |
| 68 | new ConfigFactory<DeviceId, BasicDeviceConfig>(DEVICE_SUBJECT_FACTORY, |
Simon Hunt | f59d36b | 2016-10-04 19:05:53 -0700 | [diff] [blame] | 69 | BasicDeviceConfig.class, |
| 70 | BASIC) { |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 71 | @Override |
| 72 | public BasicDeviceConfig createConfig() { |
| 73 | return new BasicDeviceConfig(); |
| 74 | } |
| 75 | }, |
Jonathan Hart | eb8c947 | 2015-08-05 07:43:13 -0700 | [diff] [blame] | 76 | new ConfigFactory<ConnectPoint, InterfaceConfig>(CONNECT_POINT_SUBJECT_FACTORY, |
Simon Hunt | f59d36b | 2016-10-04 19:05:53 -0700 | [diff] [blame] | 77 | InterfaceConfig.class, |
| 78 | INTERFACES, |
| 79 | true) { |
Jonathan Hart | 111b42b | 2015-07-14 13:28:05 -0700 | [diff] [blame] | 80 | @Override |
Jonathan Hart | eb8c947 | 2015-08-05 07:43:13 -0700 | [diff] [blame] | 81 | public InterfaceConfig createConfig() { |
| 82 | return new InterfaceConfig(); |
Jonathan Hart | 111b42b | 2015-07-14 13:28:05 -0700 | [diff] [blame] | 83 | } |
| 84 | }, |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 85 | new ConfigFactory<HostId, BasicHostConfig>(HOST_SUBJECT_FACTORY, |
Simon Hunt | f59d36b | 2016-10-04 19:05:53 -0700 | [diff] [blame] | 86 | BasicHostConfig.class, |
| 87 | BASIC) { |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 88 | @Override |
| 89 | public BasicHostConfig createConfig() { |
| 90 | return new BasicHostConfig(); |
| 91 | } |
| 92 | }, |
| 93 | new ConfigFactory<LinkKey, BasicLinkConfig>(LINK_SUBJECT_FACTORY, |
Simon Hunt | f59d36b | 2016-10-04 19:05:53 -0700 | [diff] [blame] | 94 | BasicLinkConfig.class, |
| 95 | BASIC) { |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 96 | @Override |
| 97 | public BasicLinkConfig createConfig() { |
| 98 | return new BasicLinkConfig(); |
| 99 | } |
Simon Hunt | f59d36b | 2016-10-04 19:05:53 -0700 | [diff] [blame] | 100 | }, |
| 101 | new ConfigFactory<RegionId, BasicRegionConfig>(REGION_SUBJECT_FACTORY, |
| 102 | BasicRegionConfig.class, |
| 103 | BASIC) { |
| 104 | @Override |
| 105 | public BasicRegionConfig createConfig() { |
| 106 | return new BasicRegionConfig(); |
| 107 | } |
Simon Hunt | d7395c8 | 2016-10-20 17:54:01 -0700 | [diff] [blame] | 108 | }, |
| 109 | new ConfigFactory<UiTopoLayoutId, BasicUiTopoLayoutConfig>(LAYOUT_SUBJECT_FACTORY, |
| 110 | BasicUiTopoLayoutConfig.class, |
| 111 | BASIC) { |
| 112 | @Override |
| 113 | public BasicUiTopoLayoutConfig createConfig() { |
| 114 | return new BasicUiTopoLayoutConfig(); |
| 115 | } |
Yuta HIGUCHI | 7438f5a | 2017-02-15 22:09:46 -0800 | [diff] [blame^] | 116 | }, |
| 117 | new ConfigFactory<ConnectPoint, PortAnnotationConfig>(CONNECT_POINT_SUBJECT_FACTORY, |
| 118 | PortAnnotationConfig.class, |
| 119 | PortAnnotationConfig.CONFIG_KEY) { |
| 120 | @Override |
| 121 | public PortAnnotationConfig createConfig() { |
| 122 | return new PortAnnotationConfig(); |
| 123 | } |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 124 | } |
| 125 | ); |
| 126 | |
| 127 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
Thomas Vachuska | 9fadbfc | 2015-07-23 10:56:02 -0700 | [diff] [blame] | 128 | protected CoreService coreService; |
| 129 | |
| 130 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 131 | protected NetworkConfigRegistry registry; |
| 132 | |
| 133 | @Activate |
| 134 | public void activate() { |
Thomas Vachuska | 9fadbfc | 2015-07-23 10:56:02 -0700 | [diff] [blame] | 135 | SubjectFactories.setCoreService(coreService); |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 136 | factories.forEach(registry::registerConfigFactory); |
| 137 | log.info("Started"); |
| 138 | } |
| 139 | |
| 140 | @Deactivate |
| 141 | public void deactivate() { |
| 142 | factories.forEach(registry::unregisterConfigFactory); |
| 143 | log.info("Stopped"); |
| 144 | } |
| 145 | |
| 146 | } |