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