<artifactId>neutronvpn-shell</artifactId>
<version>${neutronvpn.version}</version>
</dependency>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>vpnmanager-shell</artifactId>
+ <version>${vpnmanager.version}</version>
+ </dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>neutronvpn-impl</artifactId>
<bundle>mvn:org.opendaylight.netvirt/bgpmanager-api/{{VERSION}}</bundle>
<bundle>mvn:org.opendaylight.netvirt/bgpmanager-impl/{{VERSION}}</bundle>
<bundle>mvn:org.opendaylight.netvirt/vpnmanager-impl/{{VERSION}}</bundle>
+ <bundle>mvn:org.opendaylight.netvirt/vpnmanager-shell/{{VERSION}}</bundle>
<bundle>mvn:org.opendaylight.netvirt/fibmanager-impl/{{VERSION}}</bundle>
<bundle>mvn:org.opendaylight.netvirt/fibmanager-shell/{{VERSION}}</bundle>
<bundle>mvn:org.opendaylight.netvirt/neutronvpn-impl/{{VERSION}}</bundle>
<artifactId>neutronvpn-api</artifactId>
<version>${vpnservices.version}</version>
</dependency>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>vpnmanager-api</artifactId>
+ <version>${vpnservices.version}</version>
+ </dependency>
<dependency>
<groupId>org.apache.karaf.shell</groupId>
<artifactId>org.apache.karaf.shell.console</artifactId>
--- /dev/null
+/*
+ * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.netvirt.neutronvpn.shell;
+
+import com.google.common.base.Optional;
+import org.apache.karaf.shell.commands.Argument;
+import org.apache.karaf.shell.commands.Command;
+import org.apache.karaf.shell.console.OsgiCommandSupport;
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.NeutronVpnPortipPortData;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.neutron.vpn.portip.port.data.VpnPortipToPort;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.neutron.vpn.portip.port.data.VpnPortipToPortKey;
+import org.opendaylight.yangtools.yang.binding.DataObject;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.ArrayList;
+import java.util.List;
+
+@Command(scope = "vpnservice", name = "neutronvpn-ports-show", description = "Displays all ports configured by neutron per vpn instance")
+public class ShowNeutronVpnPort extends OsgiCommandSupport {
+
+ @Argument(index = 0, name = "--vpn-name", description = "Name of the Vpn Instance", required = false, multiValued = false)
+ private String vpnName;
+ @Argument(index = 1, name = "--ip-address", description = "Ip address assigned to the port", required = false, multiValued = false)
+ private String portFixedIp;
+
+ final Logger LOG = LoggerFactory.getLogger(ShowNeutronVpnPort.class);
+ private DataBroker dataBroker;
+ List<VpnPortipToPort> vpnPortipToPortList = new ArrayList<>();
+
+ public void setDataBroker(DataBroker broker) {
+ this.dataBroker = broker;
+ }
+ @Override
+ protected Object doExecute() throws Exception{
+
+ try{
+ if (vpnName == null && portFixedIp == null) {
+ getNeutronVpnPort();
+ System.out.println(vpnPortipToPortList.size() + " Entries are present: ");
+ System.out.println("-----------------------------------------------------------------------");
+ System.out.println(String.format(" %s %24s", "VpnName", "PortFixedip"));
+ System.out.println("-----------------------------------------------------------------------");
+ for (VpnPortipToPort vpnPortipToPort : vpnPortipToPortList){
+ System.out.println(String.format("%-32s %-10s", vpnPortipToPort.getVpnName(), vpnPortipToPort.getPortFixedip()));
+ }
+ System.out.println("\n" + getshowVpnCLIHelp());
+ }else if (portFixedIp == null || vpnName == null) {
+ System.out.println("Insufficient arguments" + "\nCorrect Usage : neutronvpn-port-show [<vpnName> <portFixedIp>]");
+ }else{
+ InstanceIdentifier<VpnPortipToPort> id = InstanceIdentifier.builder(NeutronVpnPortipPortData.class).child
+ (VpnPortipToPort.class, new VpnPortipToPortKey(portFixedIp, vpnName)).build();
+ Optional<VpnPortipToPort> vpnPortipToPortData = read(LogicalDatastoreType.OPERATIONAL, id);
+ if (vpnPortipToPortData == null) {
+ System.out.println(" Data not present");
+ }else {
+ VpnPortipToPort data = vpnPortipToPortData.get();
+ System.out.println("\n-------------------------------------------------------------------------------------------");
+ System.out.println("Key: " + data.getKey() + "\nMacAddress: " + data.getMacAddress() + "\nPortFixedip: " +
+ data.getPortFixedip() + "\nPortName: " + data.getPortName() + "\nVpnName: " + data.getVpnName());
+ System.out.println("-------------------------------------------------------------------------------------------");
+ }
+ }
+ }catch (Exception e) {
+ System.out.println("Error fetching vpnPortIpToPortData for [vpnName=" + vpnName + ", portFixedip=" + portFixedIp + "]");
+ LOG.error("Error Fetching Data",e);
+ }
+
+ return null;
+ }
+
+ private <T extends DataObject> Optional<T> read(LogicalDatastoreType datastoreType,
+ InstanceIdentifier<T> path) {
+
+ ReadOnlyTransaction tx = dataBroker.newReadOnlyTransaction();
+
+ Optional<T> result = Optional.absent();
+ try {
+ result = tx.read(datastoreType, path).get();
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+
+ return result;
+ }
+
+ private void getNeutronVpnPort(){
+
+ InstanceIdentifier<NeutronVpnPortipPortData> neutronVpnPortipPortDataIdentifier = InstanceIdentifier
+ .builder(NeutronVpnPortipPortData.class).build();
+ Optional<NeutronVpnPortipPortData> optionalNeutronVpnPort = read(LogicalDatastoreType.OPERATIONAL,
+ neutronVpnPortipPortDataIdentifier);
+ if (!optionalNeutronVpnPort.isPresent()) {
+ System.out.println("No NeutronVpnPortIpData configured.");
+ }else {
+ vpnPortipToPortList = optionalNeutronVpnPort.get().getVpnPortipToPort();
+ }
+ }
+
+ private String getshowVpnCLIHelp() {
+ StringBuilder help = new StringBuilder("Usage:");
+ help.append("To display ports and their associated vpn instances neutronvpn-port-show [<vpnName> <portFixedIp>]");
+ return help.toString();
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.netvirt.neutronvpn.shell;
+
+import com.google.common.base.Optional;
+import org.apache.karaf.shell.commands.Command;
+import org.apache.karaf.shell.commands.Option;
+import org.apache.karaf.shell.console.OsgiCommandSupport;
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.Subnetmaps;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.SubnetmapKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.SubnetOpData;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.subnet.op.data.SubnetOpDataEntry;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.subnet.op.data.SubnetOpDataEntryKey;
+import org.opendaylight.yangtools.yang.binding.DataObject;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+@Command(scope = "vpnservice", name = "subnet-show", description = "Comparison of data present in subnetMap and subnetOpDataEntry")
+public class ShowSubnet extends OsgiCommandSupport {
+
+ @Option(name = "--subnetmap", aliases = {"--subnetmap"}, description = "Display subnetMap details for given subnetId",
+ required = false, multiValued = false)
+ String subnetmap;
+ @Option(name = "--subnetopdata", aliases = {"--subnetopdata"}, description = "Display subnetOpData details for given subnetId",
+ required = false, multiValued = false)
+ String subnetopdata;
+
+ final Logger LOG = LoggerFactory.getLogger(ShowSubnet.class);
+ private DataBroker dataBroker;
+ List<Subnetmap> subnetmapList = new ArrayList<>();
+ Map<Uuid, SubnetOpDataEntry> subnetOpDataEntryMap = new HashMap<>();
+
+ public void setDataBroker(DataBroker broker) {
+ this.dataBroker = broker;
+ }
+
+ @Override
+ protected Object doExecute() throws Exception{
+
+ try{
+ if ((subnetmap == null) && (subnetopdata == null)) {
+ getSubnet();
+ System.out.println("Following subnetId is present in both subnetMap and subnetOpDataEntry\n");
+ for (Subnetmap subnetmap : subnetmapList){
+ SubnetOpDataEntry data = subnetOpDataEntryMap.get(subnetmap.getId());
+ if (data != null) {
+ System.out.println(subnetmap.getId().toString() + "\n");
+ }
+ }
+ System.out.println("\n\nFollowing subnetId is present in subnetMap but not in subnetOpDataEntry\n");
+ for (Subnetmap subnetmap : subnetmapList) {
+ SubnetOpDataEntry data = subnetOpDataEntryMap.get(subnetmap.getId());
+ if (data == null) {
+ System.out.println(subnetmap.getId().toString() + "\n");
+ }
+ }
+ getshowVpnCLIHelp();
+ }else if (subnetmap == null && subnetopdata != null) {
+ InstanceIdentifier<SubnetOpDataEntry> subOpIdentifier = InstanceIdentifier.builder(SubnetOpData.class).
+ child(SubnetOpDataEntry.class, new SubnetOpDataEntryKey(new Uuid(subnetopdata))).build();
+ Optional<SubnetOpDataEntry> optionalSubs = read(LogicalDatastoreType.OPERATIONAL, subOpIdentifier);
+ SubnetOpDataEntry data = optionalSubs.get();
+ System.out.println("Fetching subnetmap for given subnetId\n");
+ System.out.println("------------------------------------------------------------------------------");
+ System.out.println("Key: " + data.getKey() + "\n" + "VrfId: " + data.getVrfId() + "\n" + "ElanTag: " +
+ "" + data.getElanTag() +"\n" + "NhDpnId: " + data.getNhDpnId() + "\n" + "RouteAdvState: " +
+ data.getRouteAdvState() + "\n" + "SubnetCidr: " + data.getSubnetCidr() + "\n" +
+ "SubnetToDpnList: " + data.getSubnetToDpn() + "\n" + "VpnName: " + data.getVpnName() + "\n");
+ System.out.println("------------------------------------------------------------------------------");
+ }else if (subnetmap != null && subnetopdata == null) {
+ InstanceIdentifier<Subnetmap> id = InstanceIdentifier.builder(Subnetmaps.class)
+ .child(Subnetmap.class, new SubnetmapKey(new Uuid(subnetmap))).build();
+ Optional<Subnetmap> sn = read(LogicalDatastoreType.CONFIGURATION, id);
+ Subnetmap data = sn.get();
+ System.out.println("Fetching subnetopdataentry for given subnetId\n");
+ System.out.println("------------------------------------------------------------------------------");
+ System.out.println("Key: " + data.getKey() + "\n" + "VpnId: " + data.getVpnId() + "\n" +
+ "DirectPortList: " + data.getDirectPortList() + "\n" + "NetworkId: " + data.getNetworkId()
+ + "\n" + "PortList: " + data.getPortList() + "\n" + "RouterInterfaceFixedIps: " + data
+ .getRouterInterfaceFixedIps() + "\n" + "RouterInterfaceName: " + data.getRouterInterfaceName
+ () + "\n" + "RouterIntfMacAddress: " + data.getRouterIntfMacAddress() + "\n" + "SubnetIp: "
+ + data.getSubnetIp() + "\n" + "TenantId: " + data.getTenantId() + "\n");
+ System.out.println("------------------------------------------------------------------------------");
+ }
+ }catch (Exception e) {
+ System.out.println("Error fetching data for given subnetId ");
+ LOG.error("Error Fetching Data",e);
+ }
+
+ return null;
+ }
+
+ private <T extends DataObject> Optional<T> read(LogicalDatastoreType datastoreType,
+ InstanceIdentifier<T> path) {
+
+ ReadOnlyTransaction tx = dataBroker.newReadOnlyTransaction();
+
+ Optional<T> result = Optional.absent();
+ try {
+ result = tx.read(datastoreType, path).get();
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+
+ return result;
+ }
+
+ private void getSubnet(){
+
+ List<SubnetOpDataEntry> subnetOpDataEntryList = new ArrayList<>();
+ InstanceIdentifier<Subnetmaps> subnetmapsid = InstanceIdentifier.builder(Subnetmaps.class).build();
+ InstanceIdentifier<SubnetOpData> subOpIdentifier = InstanceIdentifier.builder(SubnetOpData.class).build();
+ Optional<Subnetmaps> optionalSubnetmaps = read(LogicalDatastoreType.CONFIGURATION, subnetmapsid);
+ if (!optionalSubnetmaps.isPresent()) {
+ System.out.println("No Subnetmaps configured.");
+ }else{
+ subnetmapList = optionalSubnetmaps.get().getSubnetmap();
+ }
+
+ Optional<SubnetOpData> optionalSubnetOpData = read(LogicalDatastoreType.OPERATIONAL, subOpIdentifier);
+ if (!optionalSubnetOpData.isPresent()) {
+ System.out.println("No SubnetOpData configured.");
+ }else{
+ subnetOpDataEntryList = optionalSubnetOpData.get().getSubnetOpDataEntry();
+ }
+
+ for (SubnetOpDataEntry subnetOpDataEntry : subnetOpDataEntryList) {
+ subnetOpDataEntryMap.put(subnetOpDataEntry.getSubnetId(), subnetOpDataEntry);
+ }
+ }
+
+ private void getshowVpnCLIHelp() {
+ System.out.println("\nUsage 1: " + "To display subnetMaps for a given subnetId subnet-show --subnetmap [<subnetId>]\n");
+ System.out.println("Usage 2: " + "To display subnetOpDataEntry for a given subnetId subnet-show --subnetopdata [<subnetId>]");
+ }
+
+}
</action>
</command>
+ <command>
+ <action class="org.opendaylight.netvirt.neutronvpn.shell.ShowNeutronVpnPort">
+ <property name="dataBroker" ref="dataBrokerRef"/>
+ </action>
+ </command>
+
+ <command>
+ <action class="org.opendaylight.netvirt.neutronvpn.shell.ShowSubnet">
+ <property name="dataBroker" ref="dataBrokerRef"/>
+ </action>
+ </command>
+
</command-bundle>
</blueprint>
<modules>
<module>vpnmanager-api</module>
<module>vpnmanager-impl</module>
+ <module>vpnmanager-shell</module>
</modules>
<!-- DO NOT install or deploy the repo root pom as it's only needed to initiate a build -->
<build>
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
+
+This program and the accompanying materials are made available under the
+terms of the Eclipse Public License v1.0 which accompanies this distribution,
+and is available at http://www.eclipse.org/legal/epl-v10.html
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+ <parent>
+ <groupId>org.opendaylight.netvirt</groupId>
+ <artifactId>config-parent</artifactId>
+ <version>0.3.1-SNAPSHOT</version>
+ <relativePath>../../commons/config-parent</relativePath>
+ </parent>
+
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.opendaylight.netvirt</groupId>
+ <artifactId>vpnmanager-shell</artifactId>
+ <version>${vpnservices.version}</version>
+
+ <packaging>bundle</packaging>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.karaf.shell</groupId>
+ <artifactId>org.apache.karaf.shell.console</artifactId>
+ <version>${karaf.shell.console.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>vpnmanager-api</artifactId>
+ <version>${vpnservices.version}</version>
+ </dependency>
+ </dependencies>
+
+ <!--
+ Maven Site Configuration
+
+ The following configuration is necessary for maven-site-plugin to
+ correctly identify the correct deployment path for OpenDaylight Maven
+ sites.
+ -->
+ <url>${odl.site.url}/${project.groupId}/${stream}/${project.artifactId}/</url>
+
+ <distributionManagement>
+ <site>
+ <id>opendaylight-site</id>
+ <url>${nexus.site.url}/${project.artifactId}/</url>
+ </site>
+ </distributionManagement>
+</project>
--- /dev/null
+/*
+ * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.netvirt.vpnmanager.shell;
+
+import com.google.common.base.Optional;
+import org.apache.karaf.shell.commands.Command;
+import org.apache.karaf.shell.commands.Option;
+import org.apache.karaf.shell.console.OsgiCommandSupport;
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.VpnInstances;
+import org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.VpnInterfaces;
+import org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.instances.VpnInstance;
+import org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.VpnInterface;
+import org.opendaylight.yangtools.yang.binding.DataObject;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+@Command(scope = "vpnservice", name = "vpn-show", description = "Display all present vpnInstances with their " +
+ "respective count of oper and config vpnInterfaces")
+public class ShowVpn extends OsgiCommandSupport {
+
+ @Option(name = "--detail", aliases = {"--vpninstance"}, description = "Display oper and config interfaces for " +
+ "given vpnInstanceName", required = false, multiValued = false)
+ String detail;
+
+ final Logger LOG = LoggerFactory.getLogger(ShowVpn.class);
+ private DataBroker dataBroker;
+ int configCount = 0;
+ int operCount = 0;
+ int totalOperCount = 0;
+ int totalConfigCount = 0;
+ Integer ifPresent ;
+ List<org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.instances.VpnInstance> vpnInstanceList = new ArrayList<>();
+ List<VpnInterface> vpnInterfaceConfigList = new ArrayList<>();
+ List<VpnInterface> vpnInterfaceOperList = new ArrayList<>();
+
+ public void setDataBroker(DataBroker broker) {
+ this.dataBroker = broker;
+ }
+
+ @Override
+ protected Object doExecute() throws Exception{
+ try{
+
+ Map<String, Integer> instanceNameToConfigInterfaceMap = new HashMap<>();
+ Map<String, Integer> instanceNameToOperInterfaceMap = new HashMap<>();
+ if (detail == null) {
+ showVpn();
+ for (VpnInterface vpnInterface : vpnInterfaceConfigList) {
+ ifPresent = instanceNameToConfigInterfaceMap.get(vpnInterface.getVpnInstanceName());
+ if(ifPresent == null) {
+ instanceNameToConfigInterfaceMap.put(vpnInterface.getVpnInstanceName(), 1);
+ }
+ else {instanceNameToConfigInterfaceMap.put(vpnInterface.getVpnInstanceName(),
+ instanceNameToConfigInterfaceMap.get(vpnInterface.getVpnInstanceName())+1);
+ }
+ }
+ for (VpnInterface vpnInterface : vpnInterfaceOperList) {
+ ifPresent = instanceNameToOperInterfaceMap.get(vpnInterface.getVpnInstanceName());
+ if(ifPresent == null) {
+ instanceNameToOperInterfaceMap.put(vpnInterface.getVpnInstanceName(), 1);
+ }
+ else {instanceNameToOperInterfaceMap.put(vpnInterface.getVpnInstanceName(),
+ instanceNameToOperInterfaceMap.get(vpnInterface.getVpnInstanceName())+1);
+ }
+ }
+ System.out.println("-----------------------------------------------------------------------");
+ System.out.println(String.format(" %s %14s %5s %5s", "VpnInstanceName", "RD", "Config " +
+ "Count", "Oper Count"));
+ System.out.println("\n-----------------------------------------------------------------------");
+ for (VpnInstance vpnInstance : vpnInstanceList) {
+ configCount = 0; operCount = 0;
+ Integer count = instanceNameToConfigInterfaceMap.get(vpnInstance.getVpnInstanceName());
+ if(count != null) {
+ configCount = instanceNameToConfigInterfaceMap.get(vpnInstance.getVpnInstanceName());
+ totalConfigCount = totalConfigCount + configCount;
+ }
+ count = instanceNameToOperInterfaceMap.get(vpnInstance.getVpnInstanceName());
+ if (count != null) {
+ operCount = instanceNameToOperInterfaceMap.get(vpnInstance.getVpnInstanceName());
+ totalOperCount = totalOperCount + operCount;
+ }
+ System.out.println(String.format("%-32s %-10s %-10s %-10s", vpnInstance.getVpnInstanceName(),
+ vpnInstance.getIpv4Family().getRouteDistinguisher(), configCount, operCount));
+ }
+ System.out.println("-----------------------------------------------------------------------");
+ System.out.println(String.format("Total Count: %19s %8s", totalConfigCount,
+ totalOperCount));
+ System.out.println(getshowVpnCLIHelp());
+ }else {
+ showVpn();
+ System.out.println("Present Config VpnInterfaces are:");
+ for (VpnInterface vpnInterface : vpnInterfaceConfigList) {
+ if (vpnInterface.getVpnInstanceName().equals(detail)) {
+ System.out.println(vpnInterface.getName());
+ }
+ }
+ System.out.println("Present Oper VpnInterfaces are:");
+ for (VpnInterface vpnInterface : vpnInterfaceOperList) {
+ if (vpnInterface.getVpnInstanceName().equals(detail)) {
+ System.out.println(vpnInterface.getName());
+ }
+ }
+ }
+ }catch (Exception e) {
+ System.out.println("Error while fetching vpnInterfaces for " + detail);
+ LOG.error("Failed to fetch parameters",e);
+ }
+ return null;
+ }
+
+ private <T extends DataObject> Optional<T> read(LogicalDatastoreType datastoreType,
+ InstanceIdentifier<T> path) {
+
+ ReadOnlyTransaction tx = dataBroker.newReadOnlyTransaction();
+
+ Optional<T> result = Optional.absent();
+ try {
+ result = tx.read(datastoreType, path).get();
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+
+ return result;
+ }
+
+ private void showVpn(){
+ InstanceIdentifier<VpnInstances> vpnsIdentifier = InstanceIdentifier.builder(VpnInstances.class).build();
+ InstanceIdentifier<VpnInterfaces> vpnInterfacesIdentifier = InstanceIdentifier.builder(VpnInterfaces
+ .class).build();
+ Optional<VpnInstances> optionalVpnInstances = read( LogicalDatastoreType.CONFIGURATION, vpnsIdentifier);
+
+ if (!optionalVpnInstances.isPresent()) {
+ LOG.trace("No VPNInstances configured.");
+ System.out.println("No VPNInstances configured.");
+ }else{
+ vpnInstanceList = optionalVpnInstances.get().getVpnInstance();
+ }
+
+ Optional<VpnInterfaces> optionalVpnInterfacesConfig = read(LogicalDatastoreType.CONFIGURATION, vpnInterfacesIdentifier);
+
+ if (!optionalVpnInterfacesConfig.isPresent()) {
+ LOG.trace("No Config VpnInterface is present");
+ System.out.println("No Config VpnInterface is present");
+ }else{
+ vpnInterfaceConfigList = optionalVpnInterfacesConfig.get().getVpnInterface();
+ }
+
+ Optional<VpnInterfaces> optionalVpnInterfacesOper = read(LogicalDatastoreType.OPERATIONAL, vpnInterfacesIdentifier);
+
+ if (!optionalVpnInterfacesOper.isPresent()) {
+ LOG.trace("No Oper VpnInterface is present");
+ System.out.println("No Oper VpnInterface is present");
+ }else{
+ vpnInterfaceOperList = optionalVpnInterfacesOper.get().getVpnInterface();
+ }
+ }
+
+ private String getshowVpnCLIHelp() {
+ StringBuilder help = new StringBuilder("\nUsage:");
+ help.append("To display vpn-interfaces for a particular vpnInstance vpn-show --detail [<vpnInstanceName>]");
+ return help.toString();
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.netvirt.vpnmanager.shell;
+
+import com.google.common.base.Optional;
+import org.apache.karaf.shell.commands.Command;
+import org.apache.karaf.shell.commands.Option;
+import org.apache.karaf.shell.console.OsgiCommandSupport;
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.VpnInstances;
+import org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.instances.VpnInstance;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.VpnInstanceOpData;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op.data.VpnInstanceOpDataEntry;
+import org.opendaylight.yangtools.yang.binding.DataObject;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+@Command(scope = "vpnservice", name = "vpninstance-op-show", description = "List name of all vpnInstances that is " +
+ "present or absent in vpnInstanceOpDataEntry")
+public class ShowVpnInstanceOpData extends OsgiCommandSupport {
+
+ @Option(name = "--detail", aliases = {"--vpnInstanceOp"}, description = "Display vpnInstanceOpDataEntry detail " +
+ "for" +
+ " given vpnInstanceName", required = false, multiValued = false)
+ String detail;
+ final Logger LOG = LoggerFactory.getLogger(ShowVpnInstanceOpData.class);
+ private DataBroker dataBroker;
+ List<VpnInstance> vpnInstanceList = new ArrayList<>();
+ Map<String, VpnInstanceOpDataEntry> vpnInstanceOpDataEntryMap = new HashMap<>();
+
+ public void setDataBroker(DataBroker broker) {
+ this.dataBroker = broker;
+ }
+
+ @Override
+ protected Object doExecute() throws Exception{
+ try{
+ if (detail == null) {
+ getVpnInstanceOpData();
+ System.out.println("For following vpnInstances vpnInstanceOpDataEntry is present: \n");
+ for (VpnInstance vpnInstance : vpnInstanceList) {
+ VpnInstanceOpDataEntry check = vpnInstanceOpDataEntryMap.get(vpnInstance.getVpnInstanceName());
+ if (check != null) {
+ System.out.println(vpnInstance.getVpnInstanceName() + "\n");
+ }
+ }
+ System.out.println("\n\nFor following vpnInstances vpnInstanceOpDataEntry is not present: \n");
+ for (VpnInstance vpnInstance : vpnInstanceList) {
+ VpnInstanceOpDataEntry check = vpnInstanceOpDataEntryMap.get(vpnInstance.getVpnInstanceName());
+ if (check == null) {
+ System.out.println(vpnInstance.getVpnInstanceName() + "\n");
+ }
+ }
+ System.out.println(getshowVpnCLIHelp());
+ } else {
+ getVpnInstanceOpData();
+ System.out.println("Fetching details of given vpnInstance\n");
+ System.out.println("------------------------------------------------------------------------------");
+ VpnInstanceOpDataEntry check = vpnInstanceOpDataEntryMap.get(detail);
+ System.out.println("VpnInstanceName: " + check.getVpnInstanceName() + "\n" + "VpnId: " + check
+ .getVpnId() + "\n" + "VrfId: " + check.getVrfId() + "\n" + "Key: " + check.getKey() + "\n" +
+ "VpnInterfaceCount: " + check.getVpnInterfaceCount() + "\n" + "VpnToDpnList: " + check.getVpnToDpnList() +
+ "\n");
+ System.out.println("------------------------------------------------------------------------------");
+ }
+
+ }catch (Exception e) {
+ System.out.println("Error fetching vpnInstanceOpDataEntry for " + detail);
+ LOG.error("Failed to fetch parameters",e);
+ }
+
+ return null;
+ }
+
+ private void getVpnInstanceOpData(){
+ List<VpnInstanceOpDataEntry> vpnInstanceOpDataEntryList = new ArrayList<>();
+ InstanceIdentifier<VpnInstances> vpnsIdentifier = InstanceIdentifier.builder(VpnInstances.class).build();
+ InstanceIdentifier<VpnInstanceOpData> vpnInstanceOpDataEntryIdentifier = InstanceIdentifier.builder
+ (VpnInstanceOpData.class).build();
+ Optional<VpnInstances> optionalVpnInstances = read( LogicalDatastoreType.CONFIGURATION, vpnsIdentifier);
+
+ if (!optionalVpnInstances.isPresent() || optionalVpnInstances.get().getVpnInstance() == null ||
+ optionalVpnInstances.get().getVpnInstance().isEmpty()) {
+ LOG.trace("No VPNInstances configured.");
+ System.out.println("No VPNInstances configured.");
+ }else {
+ vpnInstanceList = optionalVpnInstances.get().getVpnInstance();
+ }
+
+ Optional<VpnInstanceOpData> optionalOpData = read(LogicalDatastoreType.OPERATIONAL,
+ vpnInstanceOpDataEntryIdentifier);
+
+ if (!optionalOpData.isPresent()) {
+ LOG.trace("No VPNInstanceOpDataEntry present.");
+ System.out.println("No VPNInstanceOpDataEntry present.");
+ }else {
+ vpnInstanceOpDataEntryList = optionalOpData.get().getVpnInstanceOpDataEntry();
+ }
+
+ for(VpnInstanceOpDataEntry vpnInstanceOpDataEntry : vpnInstanceOpDataEntryList){
+ vpnInstanceOpDataEntryMap.put(vpnInstanceOpDataEntry.getVpnInstanceName(), vpnInstanceOpDataEntry);
+ }
+ }
+
+ private <T extends DataObject> Optional<T> read(LogicalDatastoreType datastoreType,
+ InstanceIdentifier<T> path) {
+
+ ReadOnlyTransaction tx = dataBroker.newReadOnlyTransaction();
+
+ Optional<T> result = Optional.absent();
+ try {
+ result = tx.read(datastoreType, path).get();
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+
+ return result;
+ }
+
+ private String getshowVpnCLIHelp() {
+ StringBuilder help = new StringBuilder("\nUsage:");
+ help.append("To display vpn-instance-op-data for given vpnInstanceName vpnInstanceOpData-show --detail [<vpnInstanceName>]");
+ return help.toString();
+ }
+}
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
+
+This program and the accompanying materials are made available under the
+terms of the Eclipse Public License v1.0 which accompanies this distribution,
+and is available at http://www.eclipse.org/legal/epl-v10.html
+-->
+
+<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
+
+ <reference id="dataBrokerRef" interface="org.opendaylight.controller.md.sal.binding.api.DataBroker"
+ availability="optional"/>
+ <command-bundle xmlns="http://karaf.apache.org/xmlns/shell/v1.1.0">
+
+ <command>
+ <action class="org.opendaylight.netvirt.vpnmanager.shell.ShowVpn">
+ <property name="dataBroker" ref="dataBrokerRef"/>
+ </action>
+ </command>
+ <command>
+ <action class="org.opendaylight.netvirt.vpnmanager.shell.ShowVpnInstanceOpData">
+ <property name="dataBroker" ref="dataBrokerRef"/>
+ </action>
+ </command>
+ </command-bundle>
+
+</blueprint>