add CLI for vBNG to show IP address mappings
Change-Id: I50035a69de43fcbe374bdceacfa2d2ba8f1af130
diff --git a/apps/virtualbng/src/main/java/org/onosproject/virtualbng/VbngConfigurationManager.java b/apps/virtualbng/src/main/java/org/onosproject/virtualbng/VbngConfigurationManager.java
index c449eef..35f4542 100644
--- a/apps/virtualbng/src/main/java/org/onosproject/virtualbng/VbngConfigurationManager.java
+++ b/apps/virtualbng/src/main/java/org/onosproject/virtualbng/VbngConfigurationManager.java
@@ -20,6 +20,7 @@
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
+import java.util.Collections;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
@@ -199,10 +200,16 @@
updateIpPrefixStatus(prefixEntry.getKey(), true);
}
}
-
+ log.info("[DELETE] Private IP to Public IP mapping: {} --> {}",
+ privateIpAddress, publicIpAddress);
return publicIpAddress;
}
+ @Override
+ public Map<IpAddress, IpAddress> getIpAddressMappings() {
+ return Collections.unmodifiableMap(ipAddressMap);
+ }
+
/**
* Generates a new IP address base on a given IP address plus a number to
* increase.
diff --git a/apps/virtualbng/src/main/java/org/onosproject/virtualbng/VbngConfigurationService.java b/apps/virtualbng/src/main/java/org/onosproject/virtualbng/VbngConfigurationService.java
index c905020..31e6d4f 100644
--- a/apps/virtualbng/src/main/java/org/onosproject/virtualbng/VbngConfigurationService.java
+++ b/apps/virtualbng/src/main/java/org/onosproject/virtualbng/VbngConfigurationService.java
@@ -15,6 +15,8 @@
*/
package org.onosproject.virtualbng;
+import java.util.Map;
+
import org.onlab.packet.IpAddress;
import org.onlab.packet.MacAddress;
@@ -71,4 +73,12 @@
* @return the assigned public IP address if it exists, otherwise null
*/
IpAddress recycleAssignedPublicIpAddress(IpAddress privateIpAddress);
+
+ /**
+ * Gets all the mapping entries from private IP address to public IP
+ * address.
+ *
+ * @return the address map from private IP address to public IP address
+ */
+ Map<IpAddress, IpAddress> getIpAddressMappings();
}
diff --git a/apps/virtualbng/src/main/java/org/onosproject/virtualbng/VbngManager.java b/apps/virtualbng/src/main/java/org/onosproject/virtualbng/VbngManager.java
index 6b2e943..37b61a7 100644
--- a/apps/virtualbng/src/main/java/org/onosproject/virtualbng/VbngManager.java
+++ b/apps/virtualbng/src/main/java/org/onosproject/virtualbng/VbngManager.java
@@ -121,7 +121,7 @@
log.info("Did not find an available public IP address to use.");
return null;
}
- log.info("Private IP to Public IP mapping: {} --> {}",
+ log.info("[ADD] Private IP to Public IP mapping: {} --> {}",
privateIpAddress, publicIpAddress);
// Setup paths between the host configured with private IP and
diff --git a/apps/virtualbng/src/main/java/org/onosproject/virtualbng/cli/MappingListCommand.java b/apps/virtualbng/src/main/java/org/onosproject/virtualbng/cli/MappingListCommand.java
new file mode 100644
index 0000000..e830837
--- /dev/null
+++ b/apps/virtualbng/src/main/java/org/onosproject/virtualbng/cli/MappingListCommand.java
@@ -0,0 +1,66 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.virtualbng.cli;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Map.Entry;
+
+import org.apache.karaf.shell.commands.Command;
+import org.onlab.packet.IpAddress;
+import org.onosproject.cli.AbstractShellCommand;
+import org.onosproject.virtualbng.VbngConfigurationService;
+
+/**
+ * Command to show the list of vBNG IP address mapping entries.
+ */
+@Command(scope = "onos", name = "vbngs",
+ description = "Lists all vBNG IP address mapping entries")
+public class MappingListCommand extends AbstractShellCommand {
+
+ private static final String FORMAT_HEADER =
+ " Private IP - Public IP";
+ private static final String FORMAT_MAPPING =
+ " %s - %s";
+
+ @Override
+ protected void execute() {
+
+ VbngConfigurationService service =
+ AbstractShellCommand.get(VbngConfigurationService.class);
+
+ // Print all mapping entries
+ printMappingEntries(service.getIpAddressMappings());
+ }
+
+ /**
+ * Prints all vBNG IP address mapping entries.
+ *
+ * @param map the map from private IP address to public address
+ */
+ private void printMappingEntries(Map<IpAddress, IpAddress> map) {
+ print(FORMAT_HEADER);
+
+ Iterator<Entry<IpAddress, IpAddress>> entries =
+ map.entrySet().iterator();
+ while (entries.hasNext()) {
+ Entry<IpAddress, IpAddress> entry = entries.next();
+ print(FORMAT_MAPPING, entry.getKey(), entry.getValue());
+ }
+
+ print("");
+ }
+}
\ No newline at end of file
diff --git a/apps/virtualbng/src/main/java/org/onosproject/virtualbng/cli/package-info.java b/apps/virtualbng/src/main/java/org/onosproject/virtualbng/cli/package-info.java
new file mode 100644
index 0000000..9cb53ef
--- /dev/null
+++ b/apps/virtualbng/src/main/java/org/onosproject/virtualbng/cli/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * The CLI of vBNG application.
+ */
+package org.onosproject.virtualbng.cli;