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; |
Thomas Vachuska | 4998caa | 2015-08-26 13:28:38 -0700 | [diff] [blame] | 37 | import org.onosproject.net.config.basics.SubjectFactories; |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 38 | import org.slf4j.Logger; |
| 39 | import org.slf4j.LoggerFactory; |
| 40 | |
| 41 | import java.util.Set; |
| 42 | |
Thomas Vachuska | 4998caa | 2015-08-26 13:28:38 -0700 | [diff] [blame] | 43 | import static org.onosproject.net.config.basics.SubjectFactories.*; |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 44 | |
| 45 | /** |
| 46 | * Component for registration of builtin basic network configurations. |
| 47 | */ |
Jonathan Hart | c43fd1c | 2016-01-18 20:02:20 -0800 | [diff] [blame] | 48 | @Service |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 49 | @Component(immediate = true) |
Jonathan Hart | c43fd1c | 2016-01-18 20:02:20 -0800 | [diff] [blame] | 50 | public class BasicNetworkConfigs implements BasicNetworkConfigService { |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 51 | |
| 52 | private final Logger log = LoggerFactory.getLogger(getClass()); |
| 53 | |
| 54 | private final Set<ConfigFactory> factories = ImmutableSet.of( |
| 55 | new ConfigFactory<DeviceId, BasicDeviceConfig>(DEVICE_SUBJECT_FACTORY, |
| 56 | BasicDeviceConfig.class, |
| 57 | "basic") { |
| 58 | @Override |
| 59 | public BasicDeviceConfig createConfig() { |
| 60 | return new BasicDeviceConfig(); |
| 61 | } |
| 62 | }, |
Jonathan Hart | eb8c947 | 2015-08-05 07:43:13 -0700 | [diff] [blame] | 63 | new ConfigFactory<ConnectPoint, InterfaceConfig>(CONNECT_POINT_SUBJECT_FACTORY, |
| 64 | InterfaceConfig.class, |
Jonathan Hart | ed4fdcd | 2015-09-08 14:13:37 -0700 | [diff] [blame] | 65 | "interfaces", |
| 66 | true) { |
Jonathan Hart | 111b42b | 2015-07-14 13:28:05 -0700 | [diff] [blame] | 67 | @Override |
Jonathan Hart | eb8c947 | 2015-08-05 07:43:13 -0700 | [diff] [blame] | 68 | public InterfaceConfig createConfig() { |
| 69 | return new InterfaceConfig(); |
Jonathan Hart | 111b42b | 2015-07-14 13:28:05 -0700 | [diff] [blame] | 70 | } |
| 71 | }, |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 72 | new ConfigFactory<HostId, BasicHostConfig>(HOST_SUBJECT_FACTORY, |
| 73 | BasicHostConfig.class, |
| 74 | "basic") { |
| 75 | @Override |
| 76 | public BasicHostConfig createConfig() { |
| 77 | return new BasicHostConfig(); |
| 78 | } |
| 79 | }, |
| 80 | new ConfigFactory<LinkKey, BasicLinkConfig>(LINK_SUBJECT_FACTORY, |
| 81 | BasicLinkConfig.class, |
| 82 | "basic") { |
| 83 | @Override |
| 84 | public BasicLinkConfig createConfig() { |
| 85 | return new BasicLinkConfig(); |
| 86 | } |
| 87 | } |
| 88 | ); |
| 89 | |
| 90 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
Thomas Vachuska | 9fadbfc | 2015-07-23 10:56:02 -0700 | [diff] [blame] | 91 | protected CoreService coreService; |
| 92 | |
| 93 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 94 | protected NetworkConfigRegistry registry; |
| 95 | |
| 96 | @Activate |
| 97 | public void activate() { |
Thomas Vachuska | 9fadbfc | 2015-07-23 10:56:02 -0700 | [diff] [blame] | 98 | SubjectFactories.setCoreService(coreService); |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 99 | factories.forEach(registry::registerConfigFactory); |
| 100 | log.info("Started"); |
| 101 | } |
| 102 | |
| 103 | @Deactivate |
| 104 | public void deactivate() { |
| 105 | factories.forEach(registry::unregisterConfigFactory); |
| 106 | log.info("Stopped"); |
| 107 | } |
| 108 | |
| 109 | } |