blob: 0dbf4a00814df218971ead57d1a817d01f6a95f8 [file] [log] [blame]
Pingping Linde77ee52015-06-03 17:16:07 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2015-present Open Networking Foundation
Pingping Linde77ee52015-06-03 17:16:07 -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 */
16
17package org.onosproject.virtualbng.cli;
18import java.util.Iterator;
19import java.util.Map;
20import java.util.Map.Entry;
21
Ray Milkey86ad7bb2018-09-27 12:32:28 -070022import org.apache.karaf.shell.api.action.Command;
Ray Milkey7a2dee52018-09-28 10:58:28 -070023import org.apache.karaf.shell.api.action.lifecycle.Service;
Pingping Linde77ee52015-06-03 17:16:07 -070024import org.onlab.packet.IpAddress;
25import org.onosproject.cli.AbstractShellCommand;
26import org.onosproject.virtualbng.VbngConfigurationService;
27
28/**
29 * Command to show the list of vBNG IP address mapping entries.
30 */
Ray Milkey7a2dee52018-09-28 10:58:28 -070031@Service
Pingping Linde77ee52015-06-03 17:16:07 -070032@Command(scope = "onos", name = "vbngs",
33 description = "Lists all vBNG IP address mapping entries")
34public class MappingListCommand extends AbstractShellCommand {
35
36 private static final String FORMAT_HEADER =
37 " Private IP - Public IP";
38 private static final String FORMAT_MAPPING =
39 " %s - %s";
40
41 @Override
Ray Milkey86ad7bb2018-09-27 12:32:28 -070042 protected void doExecute() {
Pingping Linde77ee52015-06-03 17:16:07 -070043
44 VbngConfigurationService service =
45 AbstractShellCommand.get(VbngConfigurationService.class);
46
47 // Print all mapping entries
48 printMappingEntries(service.getIpAddressMappings());
49 }
50
51 /**
52 * Prints all vBNG IP address mapping entries.
53 *
54 * @param map the map from private IP address to public address
55 */
56 private void printMappingEntries(Map<IpAddress, IpAddress> map) {
57 print(FORMAT_HEADER);
58
59 Iterator<Entry<IpAddress, IpAddress>> entries =
60 map.entrySet().iterator();
61 while (entries.hasNext()) {
62 Entry<IpAddress, IpAddress> entry = entries.next();
63 print(FORMAT_MAPPING, entry.getKey(), entry.getValue());
64 }
65
66 print("");
67 }
68}