Pingping Lin
Committed by Gerrit Code Review

add CLI for vBNG to show IP address mappings

Change-Id: I50035a69de43fcbe374bdceacfa2d2ba8f1af130
...@@ -39,6 +39,15 @@ ...@@ -39,6 +39,15 @@
39 <dependencies> 39 <dependencies>
40 <dependency> 40 <dependency>
41 <groupId>org.onosproject</groupId> 41 <groupId>org.onosproject</groupId>
42 + <artifactId>onos-cli</artifactId>
43 + <version>${project.version}</version>
44 + </dependency>
45 + <dependency>
46 + <groupId>org.apache.karaf.shell</groupId>
47 + <artifactId>org.apache.karaf.shell.console</artifactId>
48 + </dependency>
49 + <dependency>
50 + <groupId>org.onosproject</groupId>
42 <artifactId>onlab-rest</artifactId> 51 <artifactId>onlab-rest</artifactId>
43 <version>${project.version}</version> 52 <version>${project.version}</version>
44 </dependency> 53 </dependency>
...@@ -68,6 +77,7 @@ ...@@ -68,6 +77,7 @@
68 com.sun.jersey.spi.container.servlet, 77 com.sun.jersey.spi.container.servlet,
69 com.sun.jersey.server.impl.container.servlet, 78 com.sun.jersey.server.impl.container.servlet,
70 com.fasterxml.jackson.databind, 79 com.fasterxml.jackson.databind,
80 + org.apache.karaf.shell.commands,
71 com.google.common.*, 81 com.google.common.*,
72 org.onlab.packet.*, 82 org.onlab.packet.*,
73 org.onlab.rest.*, 83 org.onlab.rest.*,
......
...@@ -20,6 +20,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; ...@@ -20,6 +20,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
20 import java.io.File; 20 import java.io.File;
21 import java.io.FileNotFoundException; 21 import java.io.FileNotFoundException;
22 import java.io.IOException; 22 import java.io.IOException;
23 +import java.util.Collections;
23 import java.util.Iterator; 24 import java.util.Iterator;
24 import java.util.Map; 25 import java.util.Map;
25 import java.util.Map.Entry; 26 import java.util.Map.Entry;
...@@ -199,10 +200,16 @@ public class VbngConfigurationManager implements VbngConfigurationService { ...@@ -199,10 +200,16 @@ public class VbngConfigurationManager implements VbngConfigurationService {
199 updateIpPrefixStatus(prefixEntry.getKey(), true); 200 updateIpPrefixStatus(prefixEntry.getKey(), true);
200 } 201 }
201 } 202 }
202 - 203 + log.info("[DELETE] Private IP to Public IP mapping: {} --> {}",
204 + privateIpAddress, publicIpAddress);
203 return publicIpAddress; 205 return publicIpAddress;
204 } 206 }
205 207
208 + @Override
209 + public Map<IpAddress, IpAddress> getIpAddressMappings() {
210 + return Collections.unmodifiableMap(ipAddressMap);
211 + }
212 +
206 /** 213 /**
207 * Generates a new IP address base on a given IP address plus a number to 214 * Generates a new IP address base on a given IP address plus a number to
208 * increase. 215 * increase.
......
...@@ -15,6 +15,8 @@ ...@@ -15,6 +15,8 @@
15 */ 15 */
16 package org.onosproject.virtualbng; 16 package org.onosproject.virtualbng;
17 17
18 +import java.util.Map;
19 +
18 import org.onlab.packet.IpAddress; 20 import org.onlab.packet.IpAddress;
19 import org.onlab.packet.MacAddress; 21 import org.onlab.packet.MacAddress;
20 22
...@@ -71,4 +73,12 @@ public interface VbngConfigurationService { ...@@ -71,4 +73,12 @@ public interface VbngConfigurationService {
71 * @return the assigned public IP address if it exists, otherwise null 73 * @return the assigned public IP address if it exists, otherwise null
72 */ 74 */
73 IpAddress recycleAssignedPublicIpAddress(IpAddress privateIpAddress); 75 IpAddress recycleAssignedPublicIpAddress(IpAddress privateIpAddress);
76 +
77 + /**
78 + * Gets all the mapping entries from private IP address to public IP
79 + * address.
80 + *
81 + * @return the address map from private IP address to public IP address
82 + */
83 + Map<IpAddress, IpAddress> getIpAddressMappings();
74 } 84 }
......
...@@ -121,7 +121,7 @@ public class VbngManager implements VbngService { ...@@ -121,7 +121,7 @@ public class VbngManager implements VbngService {
121 log.info("Did not find an available public IP address to use."); 121 log.info("Did not find an available public IP address to use.");
122 return null; 122 return null;
123 } 123 }
124 - log.info("Private IP to Public IP mapping: {} --> {}", 124 + log.info("[ADD] Private IP to Public IP mapping: {} --> {}",
125 privateIpAddress, publicIpAddress); 125 privateIpAddress, publicIpAddress);
126 126
127 // Setup paths between the host configured with private IP and 127 // Setup paths between the host configured with private IP and
......
1 +/*
2 + * Copyright 2015 Open Networking Laboratory
3 + *
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 +
17 +package org.onosproject.virtualbng.cli;
18 +import java.util.Iterator;
19 +import java.util.Map;
20 +import java.util.Map.Entry;
21 +
22 +import org.apache.karaf.shell.commands.Command;
23 +import org.onlab.packet.IpAddress;
24 +import org.onosproject.cli.AbstractShellCommand;
25 +import 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")
32 +public 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 +}
...\ No newline at end of file ...\ No newline at end of file
1 +/*
2 + * Copyright 2015 Open Networking Laboratory
3 + *
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 +
17 +/**
18 + * The CLI of vBNG application.
19 + */
20 +package org.onosproject.virtualbng.cli;
1 +<!--
2 + ~ Copyright 2015 Open Networking Laboratory
3 + ~
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 +<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
17 +
18 + <command-bundle xmlns="http://karaf.apache.org/xmlns/shell/v1.1.0">
19 + <command>
20 + <action class="org.onosproject.virtualbng.cli.MappingListCommand"/>
21 + </command>
22 + </command-bundle>
23 +</blueprint>