Thomas Vachuska | 0d93386 | 2018-04-06 00:29:30 -0700 | [diff] [blame] | 1 | /* |
| 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 | package org.onosproject.layout; |
| 17 | |
Ray Milkey | 86ad7bb | 2018-09-27 12:32:28 -0700 | [diff] [blame] | 18 | import org.apache.karaf.shell.api.action.Argument; |
| 19 | import org.apache.karaf.shell.api.action.Command; |
Ray Milkey | 7a2dee5 | 2018-09-28 10:58:28 -0700 | [diff] [blame] | 20 | import org.apache.karaf.shell.api.action.lifecycle.Service; |
Thomas Vachuska | 0d93386 | 2018-04-06 00:29:30 -0700 | [diff] [blame] | 21 | import org.onosproject.cli.AbstractShellCommand; |
| 22 | |
| 23 | /** |
Thomas Vachuska | c3a947f | 2018-04-18 15:08:35 -0700 | [diff] [blame] | 24 | * Lays out the elements in the topology using the specified algorithm. |
Thomas Vachuska | 0d93386 | 2018-04-06 00:29:30 -0700 | [diff] [blame] | 25 | */ |
Ray Milkey | 7a2dee5 | 2018-09-28 10:58:28 -0700 | [diff] [blame] | 26 | @Service |
Thomas Vachuska | 0d93386 | 2018-04-06 00:29:30 -0700 | [diff] [blame] | 27 | @Command(scope = "onos", name = "topo-layout", |
| 28 | description = "Lays out the elements in the topology using the specified algorithm") |
| 29 | public class AutoLayoutCommand extends AbstractShellCommand { |
| 30 | |
| 31 | @Argument(index = 0, name = "algorithm", |
Thomas Vachuska | c3a947f | 2018-04-18 15:08:35 -0700 | [diff] [blame] | 32 | description = "Layout algorithm to use for the layout; defaults to 'access'") |
Thomas Vachuska | 0d93386 | 2018-04-06 00:29:30 -0700 | [diff] [blame] | 33 | String algorithm = "access"; |
| 34 | |
| 35 | @Override |
Ray Milkey | 86ad7bb | 2018-09-27 12:32:28 -0700 | [diff] [blame] | 36 | protected void doExecute() { |
Thomas Vachuska | 0d93386 | 2018-04-06 00:29:30 -0700 | [diff] [blame] | 37 | RoleBasedLayoutManager mgr = get(RoleBasedLayoutManager.class); |
| 38 | switch (algorithm) { |
Thomas Vachuska | 0d93386 | 2018-04-06 00:29:30 -0700 | [diff] [blame] | 39 | case "access": |
| 40 | mgr.layout(new AccessNetworkLayout()); |
| 41 | break; |
Thomas Vachuska | c3a947f | 2018-04-18 15:08:35 -0700 | [diff] [blame] | 42 | case "default": |
| 43 | mgr.layout(new DefaultForceLayout()); |
Thomas Vachuska | 0d93386 | 2018-04-06 00:29:30 -0700 | [diff] [blame] | 44 | break; |
| 45 | default: |
| 46 | print("Unsupported layout algorithm %s", algorithm); |
| 47 | } |
| 48 | } |
| 49 | } |