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