From de77ee513d5077c00edd798a9900979356cc1cb8 Mon Sep 17 00:00:00 2001 From: Pingping Lin Date: Wed, 3 Jun 2015 17:16:07 -0700 Subject: [PATCH] add CLI for vBNG to show IP address mappings Change-Id: I50035a69de43fcbe374bdceacfa2d2ba8f1af130 --- apps/virtualbng/pom.xml | 10 +++ .../virtualbng/VbngConfigurationManager.java | 9 ++- .../virtualbng/VbngConfigurationService.java | 10 +++ .../onosproject/virtualbng/VbngManager.java | 2 +- .../virtualbng/cli/MappingListCommand.java | 66 +++++++++++++++++++ .../virtualbng/cli/package-info.java | 20 ++++++ .../OSGI-INF/blueprint/shell-config.xml | 23 +++++++ 7 files changed, 138 insertions(+), 2 deletions(-) create mode 100644 apps/virtualbng/src/main/java/org/onosproject/virtualbng/cli/MappingListCommand.java create mode 100644 apps/virtualbng/src/main/java/org/onosproject/virtualbng/cli/package-info.java create mode 100644 apps/virtualbng/src/main/resources/OSGI-INF/blueprint/shell-config.xml diff --git a/apps/virtualbng/pom.xml b/apps/virtualbng/pom.xml index 25d319a48f..dcedd91c21 100644 --- a/apps/virtualbng/pom.xml +++ b/apps/virtualbng/pom.xml @@ -37,6 +37,15 @@ + + org.onosproject + onos-cli + ${project.version} + + + org.apache.karaf.shell + org.apache.karaf.shell.console + org.onosproject onlab-rest @@ -68,6 +77,7 @@ com.sun.jersey.spi.container.servlet, com.sun.jersey.server.impl.container.servlet, com.fasterxml.jackson.databind, + org.apache.karaf.shell.commands, com.google.common.*, org.onlab.packet.*, org.onlab.rest.*, 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 c449eef84e..35f4542d17 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 com.fasterxml.jackson.databind.ObjectMapper; 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 @@ public class VbngConfigurationManager implements VbngConfigurationService { updateIpPrefixStatus(prefixEntry.getKey(), true); } } - + log.info("[DELETE] Private IP to Public IP mapping: {} --> {}", + privateIpAddress, publicIpAddress); return publicIpAddress; } + @Override + public Map 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 c905020f89..31e6d4fb67 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 @@ public interface VbngConfigurationService { * @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 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 6b2e94309f..37b61a78a6 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 @@ public class VbngManager implements VbngService { 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 0000000000..e8308376fe --- /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 map) { + print(FORMAT_HEADER); + + Iterator> entries = + map.entrySet().iterator(); + while (entries.hasNext()) { + Entry 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 0000000000..9cb53efb1f --- /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; diff --git a/apps/virtualbng/src/main/resources/OSGI-INF/blueprint/shell-config.xml b/apps/virtualbng/src/main/resources/OSGI-INF/blueprint/shell-config.xml new file mode 100644 index 0000000000..48532b3f9f --- /dev/null +++ b/apps/virtualbng/src/main/resources/OSGI-INF/blueprint/shell-config.xml @@ -0,0 +1,23 @@ + + + + + + + + +