blob: 5f928c5158ad76392290905c23bf2bea26032be5 [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;
Ray Milkey7a2dee52018-09-28 10:58:28 -070020import org.apache.karaf.shell.api.action.lifecycle.Service;
Thomas Vachuska0d933862018-04-06 00:29:30 -070021import org.onosproject.cli.AbstractShellCommand;
22
23/**
Thomas Vachuskac3a947f2018-04-18 15:08:35 -070024 * Lays out the elements in the topology using the specified algorithm.
Thomas Vachuska0d933862018-04-06 00:29:30 -070025 */
Ray Milkey7a2dee52018-09-28 10:58:28 -070026@Service
Thomas Vachuska0d933862018-04-06 00:29:30 -070027@Command(scope = "onos", name = "topo-layout",
28 description = "Lays out the elements in the topology using the specified algorithm")
29public class AutoLayoutCommand extends AbstractShellCommand {
30
31 @Argument(index = 0, name = "algorithm",
Thomas Vachuskac3a947f2018-04-18 15:08:35 -070032 description = "Layout algorithm to use for the layout; defaults to 'access'")
Thomas Vachuska0d933862018-04-06 00:29:30 -070033 String algorithm = "access";
34
35 @Override
Ray Milkey86ad7bb2018-09-27 12:32:28 -070036 protected void doExecute() {
Thomas Vachuska0d933862018-04-06 00:29:30 -070037 RoleBasedLayoutManager mgr = get(RoleBasedLayoutManager.class);
38 switch (algorithm) {
Thomas Vachuska0d933862018-04-06 00:29:30 -070039 case "access":
40 mgr.layout(new AccessNetworkLayout());
41 break;
Thomas Vachuskac3a947f2018-04-18 15:08:35 -070042 case "default":
43 mgr.layout(new DefaultForceLayout());
Thomas Vachuska0d933862018-04-06 00:29:30 -070044 break;
45 default:
46 print("Unsupported layout algorithm %s", algorithm);
47 }
48 }
49}