Simon Hunt | c4ca710 | 2017-04-08 22:28:04 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2017-present Open Networking Foundation |
Simon Hunt | c4ca710 | 2017-04-08 22:28:04 -0700 | [diff] [blame] | 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.cli.net; |
| 17 | |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 18 | import org.apache.karaf.shell.api.action.Argument; |
| 19 | import org.apache.karaf.shell.api.action.Command; |
Ray Milkey | 0068fd0 | 2018-10-11 15:45:39 -0700 | [diff] [blame] | 20 | import org.apache.karaf.shell.api.action.Completion; |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 21 | import org.apache.karaf.shell.api.action.lifecycle.Service; |
Simon Hunt | c4ca710 | 2017-04-08 22:28:04 -0700 | [diff] [blame] | 22 | import org.onosproject.cli.AbstractShellCommand; |
| 23 | import org.onosproject.net.config.NetworkConfigService; |
| 24 | import org.onosproject.net.config.basics.BasicRegionConfig; |
| 25 | import org.onosproject.net.region.RegionId; |
| 26 | |
| 27 | /** |
| 28 | * Annotate a region with a peer location. That is, when rendering the |
| 29 | * first region, where should the second (peer) region node be |
| 30 | * located on the layout. An example: |
| 31 | * <pre> |
| 32 | * region-add-peer-loc rUK rES 50.4060 -3.3860 |
| 33 | * </pre> |
| 34 | * When rendering the rUK region, the rES peer region node should be located |
| 35 | * at latitude 50.4060 and longitude -3.3860. |
| 36 | * <pre> |
| 37 | * region-add-peer-loc rUK rES 100.0 200.0 grid |
| 38 | * </pre> |
| 39 | * When rendering the rUK region, the rES peer region node should be located |
| 40 | * at grid-Y 100 and grid-X 200. |
| 41 | * |
| 42 | */ |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 43 | @Service |
Simon Hunt | c4ca710 | 2017-04-08 22:28:04 -0700 | [diff] [blame] | 44 | @Command(scope = "onos", name = "region-add-peer-loc", |
| 45 | description = "Adds a peer location annotation to a region.") |
| 46 | public class RegionAddPeerLocCommand extends AbstractShellCommand { |
| 47 | |
| 48 | private static final String GEO = "geo"; |
| 49 | private static final String GRID = "grid"; |
| 50 | |
| 51 | @Argument(index = 0, name = "id", description = "Region ID", |
| 52 | required = true, multiValued = false) |
Ray Milkey | 0068fd0 | 2018-10-11 15:45:39 -0700 | [diff] [blame] | 53 | @Completion(RegionIdCompleter.class) |
Simon Hunt | c4ca710 | 2017-04-08 22:28:04 -0700 | [diff] [blame] | 54 | String id = null; |
| 55 | |
| 56 | @Argument(index = 1, name = "peer", description = "Peer region ID", |
| 57 | required = true, multiValued = false) |
| 58 | String peerId = null; |
| 59 | |
| 60 | @Argument(index = 2, name = "latOrY", |
| 61 | description = "Geo latitude / Grid y-coord", |
| 62 | required = true, multiValued = false) |
| 63 | Double latOrY = null; |
| 64 | |
| 65 | @Argument(index = 3, name = "longOrX", |
| 66 | description = "Geo longitude / Grid x-coord", |
| 67 | required = true, multiValued = false) |
| 68 | Double longOrX = null; |
| 69 | |
| 70 | @Argument(index = 4, name = "locType", description = "Location type {geo|grid}", |
| 71 | required = false, multiValued = false) |
| 72 | String locType = GEO; |
| 73 | |
| 74 | @Override |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 75 | protected void doExecute() { |
Simon Hunt | c4ca710 | 2017-04-08 22:28:04 -0700 | [diff] [blame] | 76 | RegionId regionId = RegionId.regionId(id); |
| 77 | |
| 78 | NetworkConfigService cfgService = get(NetworkConfigService.class); |
| 79 | BasicRegionConfig cfg = cfgService.getConfig(regionId, BasicRegionConfig.class); |
| 80 | |
| 81 | cfg.addPeerLocMapping(peerId, locType, latOrY, longOrX) |
| 82 | .apply(); |
| 83 | } |
| 84 | } |