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