blob: b880dce349f510bfb1e26492c689c4300e616740 [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
22import org.apache.karaf.shell.commands.Command;
23import org.onlab.packet.IpAddress;
24import org.onosproject.cli.AbstractShellCommand;
25import org.onosproject.virtualbng.VbngConfigurationService;
26
27/**
28 * Command to show the list of vBNG IP address mapping entries.
29 */
30@Command(scope = "onos", name = "vbngs",
31 description = "Lists all vBNG IP address mapping entries")
32public class MappingListCommand extends AbstractShellCommand {
33
34 private static final String FORMAT_HEADER =
35 " Private IP - Public IP";
36 private static final String FORMAT_MAPPING =
37 " %s - %s";
38
39 @Override
40 protected void execute() {
41
42 VbngConfigurationService service =
43 AbstractShellCommand.get(VbngConfigurationService.class);
44
45 // Print all mapping entries
46 printMappingEntries(service.getIpAddressMappings());
47 }
48
49 /**
50 * Prints all vBNG IP address mapping entries.
51 *
52 * @param map the map from private IP address to public address
53 */
54 private void printMappingEntries(Map<IpAddress, IpAddress> map) {
55 print(FORMAT_HEADER);
56
57 Iterator<Entry<IpAddress, IpAddress>> entries =
58 map.entrySet().iterator();
59 while (entries.hasNext()) {
60 Entry<IpAddress, IpAddress> entry = entries.next();
61 print(FORMAT_MAPPING, entry.getKey(), entry.getValue());
62 }
63
64 print("");
65 }
66}