Pingping Lin
Committed by Gerrit Code Review

add CLI for vBNG to show IP address mappings

Change-Id: I50035a69de43fcbe374bdceacfa2d2ba8f1af130
......@@ -39,6 +39,15 @@
<dependencies>
<dependency>
<groupId>org.onosproject</groupId>
<artifactId>onos-cli</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.karaf.shell</groupId>
<artifactId>org.apache.karaf.shell.console</artifactId>
</dependency>
<dependency>
<groupId>org.onosproject</groupId>
<artifactId>onlab-rest</artifactId>
<version>${project.version}</version>
</dependency>
......@@ -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.*,
......
......@@ -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<IpAddress, IpAddress> getIpAddressMappings() {
return Collections.unmodifiableMap(ipAddressMap);
}
/**
* Generates a new IP address base on a given IP address plus a number to
* increase.
......
......@@ -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<IpAddress, IpAddress> getIpAddressMappings();
}
......
......@@ -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
......
/*
* 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
/*
* 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;
<!--
~ 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.
-->
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
<command-bundle xmlns="http://karaf.apache.org/xmlns/shell/v1.1.0">
<command>
<action class="org.onosproject.virtualbng.cli.MappingListCommand"/>
</command>
</command-bundle>
</blueprint>