Yuta HIGUCHI | b9af6b7 | 2016-06-10 10:52:58 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
Yuta HIGUCHI | b9af6b7 | 2016-06-10 10:52:58 -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 | */ |
| 16 | package org.onosproject.net.optical.internal; |
| 17 | |
| 18 | import static org.onosproject.net.config.basics.SubjectFactories.CONNECT_POINT_SUBJECT_FACTORY; |
| 19 | |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 20 | import org.osgi.service.component.annotations.Activate; |
| 21 | import org.osgi.service.component.annotations.Component; |
| 22 | import org.osgi.service.component.annotations.Deactivate; |
| 23 | import org.osgi.service.component.annotations.Reference; |
| 24 | import org.osgi.service.component.annotations.ReferenceCardinality; |
Yuta HIGUCHI | b9af6b7 | 2016-06-10 10:52:58 -0700 | [diff] [blame] | 25 | import org.onosproject.net.ConnectPoint; |
| 26 | import org.onosproject.net.config.ConfigFactory; |
| 27 | import org.onosproject.net.config.NetworkConfigRegistry; |
| 28 | import org.onosproject.net.config.PortConfigOperatorRegistry; |
| 29 | import org.onosproject.net.optical.config.OpticalPortConfig; |
| 30 | import org.onosproject.net.optical.config.OpticalPortOperator; |
| 31 | import org.slf4j.Logger; |
| 32 | import org.slf4j.LoggerFactory; |
| 33 | |
| 34 | /** |
| 35 | * Loader which registers optical model related config, etc. |
| 36 | */ |
| 37 | @Component(immediate = true) |
| 38 | public class OpticalModelLoader { |
| 39 | |
| 40 | private final Logger log = LoggerFactory.getLogger(getClass()); |
| 41 | |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 42 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Yuta HIGUCHI | b9af6b7 | 2016-06-10 10:52:58 -0700 | [diff] [blame] | 43 | protected PortConfigOperatorRegistry portOperatorRegistry; |
| 44 | |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 45 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Yuta HIGUCHI | b9af6b7 | 2016-06-10 10:52:58 -0700 | [diff] [blame] | 46 | protected NetworkConfigRegistry netcfgRegistry; |
| 47 | |
| 48 | |
| 49 | private OpticalPortOperator opticalPortOp; |
| 50 | |
| 51 | private ConfigFactory<ConnectPoint, OpticalPortConfig> |
| 52 | opticalPortConfigFactory = new ConfigFactory<ConnectPoint, OpticalPortConfig>(CONNECT_POINT_SUBJECT_FACTORY, |
| 53 | OpticalPortConfig.class, |
Yuta HIGUCHI | 5ccaefb | 2016-09-07 11:18:13 -0700 | [diff] [blame] | 54 | OpticalPortConfig.CONFIG_KEY) { |
Yuta HIGUCHI | b9af6b7 | 2016-06-10 10:52:58 -0700 | [diff] [blame] | 55 | @Override |
| 56 | public OpticalPortConfig createConfig() { |
| 57 | return new OpticalPortConfig(); |
| 58 | } |
| 59 | }; |
| 60 | |
| 61 | @Activate |
| 62 | protected void activate() { |
| 63 | netcfgRegistry.registerConfigFactory(opticalPortConfigFactory); |
| 64 | |
| 65 | opticalPortOp = new OpticalPortOperator(); |
| 66 | portOperatorRegistry.registerPortConfigOperator(opticalPortOp, |
| 67 | OpticalPortConfig.class); |
| 68 | |
| 69 | log.info("Started"); |
| 70 | } |
| 71 | |
| 72 | @Deactivate |
| 73 | protected void deactivate() { |
| 74 | portOperatorRegistry.unregisterPortConfigOperator(opticalPortOp); |
| 75 | |
| 76 | netcfgRegistry.unregisterConfigFactory(opticalPortConfigFactory); |
| 77 | log.info("Stopped"); |
| 78 | } |
| 79 | } |