blob: 0340c7c6fbf077214f0cc8d30586ddf2efe4a02e [file] [log] [blame]
Thomas Vachuska0d933862018-04-06 00:29:30 -07001/*
2 * Copyright 2018-present Open Networking Foundation
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
17package org.onosproject.layout;
18
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.apache.felix.scr.annotations.Service;
25import org.onosproject.net.config.NetworkConfigService;
26import org.onosproject.net.device.DeviceService;
27import org.onosproject.net.host.HostService;
28import org.onosproject.net.link.LinkService;
29import org.slf4j.Logger;
30import org.slf4j.LoggerFactory;
31
32/**
33 * Manages automatic layout of the current network elements into one of several
34 * supported layout variants using roles assigned to network elements using
35 * network configuration.
36 */
37@Component(immediate = true)
38@Service(value = RoleBasedLayoutManager.class)
39public class RoleBasedLayoutManager {
40
41 private Logger log = LoggerFactory.getLogger(getClass());
42
43 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
44 protected NetworkConfigService networkConfigService;
45
46 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
47 protected DeviceService deviceService;
48
49 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
50 protected HostService hostService;
51
52 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
53 protected LinkService linkService;
54
55 @Activate
56 protected void activate() {
57 log.info("Started");
58 }
59
60 @Deactivate
61 protected void deactivate() {
62 log.info("Stopped");
63 }
64
65
66 /**
67 * Executes the specified layout algorithm.
68 *
69 * @param algorithm layout algorithm
70 */
71 public void layout(LayoutAlgorithm algorithm) {
72 algorithm.init(deviceService, hostService, linkService, networkConfigService);
73 algorithm.classify();
74 log.info("Layout classified: {}", algorithm);
75 algorithm.apply();
76 }
77
78}