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