blob: 3c6e921963f994762920bb22940945bdb93f5a0c [file] [log] [blame]
Thomas Vachuska96d55b12015-05-11 08:52:03 -07001/*
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 */
16package org.onosproject.incubator.net.config.impl;
17
18import com.google.common.collect.ImmutableSet;
19import org.apache.felix.scr.annotations.Activate;
20import org.apache.felix.scr.annotations.Component;
21import org.apache.felix.scr.annotations.Deactivate;
22import org.apache.felix.scr.annotations.Reference;
23import org.apache.felix.scr.annotations.ReferenceCardinality;
24import org.onosproject.incubator.net.config.ConfigFactory;
25import org.onosproject.incubator.net.config.NetworkConfigRegistry;
26import org.onosproject.incubator.net.config.basics.BasicDeviceConfig;
27import org.onosproject.incubator.net.config.basics.BasicHostConfig;
28import org.onosproject.incubator.net.config.basics.BasicLinkConfig;
29import org.onosproject.net.DeviceId;
30import org.onosproject.net.HostId;
31import org.onosproject.net.LinkKey;
32import org.slf4j.Logger;
33import org.slf4j.LoggerFactory;
34
35import java.util.Set;
36
37import static org.onosproject.incubator.net.config.basics.SubjectFactories.*;
38
39/**
40 * Component for registration of builtin basic network configurations.
41 */
42@Component(immediate = true)
43public class BasicNetworkConfigs {
44
45 private final Logger log = LoggerFactory.getLogger(getClass());
46
47 private final Set<ConfigFactory> factories = ImmutableSet.of(
48 new ConfigFactory<DeviceId, BasicDeviceConfig>(DEVICE_SUBJECT_FACTORY,
49 BasicDeviceConfig.class,
50 "basic") {
51 @Override
52 public BasicDeviceConfig createConfig() {
53 return new BasicDeviceConfig();
54 }
55 },
56 new ConfigFactory<HostId, BasicHostConfig>(HOST_SUBJECT_FACTORY,
57 BasicHostConfig.class,
58 "basic") {
59 @Override
60 public BasicHostConfig createConfig() {
61 return new BasicHostConfig();
62 }
63 },
64 new ConfigFactory<LinkKey, BasicLinkConfig>(LINK_SUBJECT_FACTORY,
65 BasicLinkConfig.class,
66 "basic") {
67 @Override
68 public BasicLinkConfig createConfig() {
69 return new BasicLinkConfig();
70 }
71 }
72 );
73
74 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
75 protected NetworkConfigRegistry registry;
76
77 @Activate
78 public void activate() {
79 factories.forEach(registry::registerConfigFactory);
80 log.info("Started");
81 }
82
83 @Deactivate
84 public void deactivate() {
85 factories.forEach(registry::unregisterConfigFactory);
86 log.info("Stopped");
87 }
88
89}