blob: d32a00b2e38c07ef6c8ffcd795de159851862ae0 [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 */
16package org.onosproject.layout;
17
Ray Milkey86ad7bb2018-09-27 12:32:28 -070018import org.apache.karaf.shell.api.action.Argument;
19import org.apache.karaf.shell.api.action.Command;
Thomas Vachuska0d933862018-04-06 00:29:30 -070020import org.onosproject.cli.AbstractShellCommand;
21
22/**
Thomas Vachuskac3a947f2018-04-18 15:08:35 -070023 * Lays out the elements in the topology using the specified algorithm.
Thomas Vachuska0d933862018-04-06 00:29:30 -070024 */
25@Command(scope = "onos", name = "topo-layout",
26 description = "Lays out the elements in the topology using the specified algorithm")
27public class AutoLayoutCommand extends AbstractShellCommand {
28
29 @Argument(index = 0, name = "algorithm",
Thomas Vachuskac3a947f2018-04-18 15:08:35 -070030 description = "Layout algorithm to use for the layout; defaults to 'access'")
Thomas Vachuska0d933862018-04-06 00:29:30 -070031 String algorithm = "access";
32
33 @Override
Ray Milkey86ad7bb2018-09-27 12:32:28 -070034 protected void doExecute() {
Thomas Vachuska0d933862018-04-06 00:29:30 -070035 RoleBasedLayoutManager mgr = get(RoleBasedLayoutManager.class);
36 switch (algorithm) {
Thomas Vachuska0d933862018-04-06 00:29:30 -070037 case "access":
38 mgr.layout(new AccessNetworkLayout());
39 break;
Thomas Vachuskac3a947f2018-04-18 15:08:35 -070040 case "default":
41 mgr.layout(new DefaultForceLayout());
Thomas Vachuska0d933862018-04-06 00:29:30 -070042 break;
43 default:
44 print("Unsupported layout algorithm %s", algorithm);
45 }
46 }
47}