blob: bc721d32b93cfd3a2cd2a6f7871ab86090094943 [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;
Ray Milkey0068fd02018-10-11 15:45:39 -070020import org.apache.karaf.shell.api.action.Completion;
Ray Milkeyd84f89b2018-08-17 14:54:17 -070021import org.apache.karaf.shell.api.action.lifecycle.Service;
Simon Huntc4ca7102017-04-08 22:28:04 -070022import org.onosproject.cli.AbstractShellCommand;
23import org.onosproject.net.config.NetworkConfigService;
24import org.onosproject.net.config.basics.BasicRegionConfig;
25import 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 Milkeyd84f89b2018-08-17 14:54:17 -070043@Service
Simon Huntc4ca7102017-04-08 22:28:04 -070044@Command(scope = "onos", name = "region-add-peer-loc",
45 description = "Adds a peer location annotation to a region.")
46public 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 Milkey0068fd02018-10-11 15:45:39 -070053 @Completion(RegionIdCompleter.class)
Simon Huntc4ca7102017-04-08 22:28:04 -070054 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 Milkeyd84f89b2018-08-17 14:54:17 -070075 protected void doExecute() {
Simon Huntc4ca7102017-04-08 22:28:04 -070076 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}