Shell Commands to Display Ipv6Service Cache 92/65692/1
authorSridhar Gaddam <sgaddam@redhat.com>
Wed, 11 Oct 2017 07:23:16 +0000 (12:53 +0530)
committerSridhar Gaddam <sgaddam@redhat.com>
Sat, 18 Nov 2017 13:06:27 +0000 (18:36 +0530)
IPv6Service in netvirt maintains a cache of various Neutron resources to
honor the Router Solicitation/Neighbor Solicitation requests (which are
time sensitive) coming from the VMs spawned on the IPv6 Network.

This patch implements the necessary shell commands to dump the ipv6Cache.

Conflicts:
    vpnservice/features/vpnservice-features/pom.xml
    vpnservice/features/vpnservice-features/src/main/features/features.xml

Change-Id: Ie1aed6d47da540e3fd94c6a8cc3eedf7b4954989
Signed-off-by: Sridhar Gaddam <sgaddam@redhat.com>
(cherry picked from commit 156124fda4f55fe7c1f34f1e4e8c0584441ad65f)

vpnservice/features/odl-netvirt-impl/pom.xml
vpnservice/ipv6service/impl/src/main/java/org/opendaylight/netvirt/ipv6service/IfMgr.java
vpnservice/ipv6service/pom.xml
vpnservice/ipv6service/shell/pom.xml [new file with mode: 0644]
vpnservice/ipv6service/shell/src/main/java/org/opendaylight/netvirt/ipv6service/shell/ShowIpv6Command.java [new file with mode: 0644]
vpnservice/ipv6service/shell/src/main/resources/org/opendaylight/blueprint/blueprint.xml [new file with mode: 0644]

index 74de22e20ae02b90e1c07c0123355a27d132ae0a..9af1c995c1a4779f7c9e4aa504c582a31d41ea71 100644 (file)
             <artifactId>ipv6service-impl</artifactId>
             <version>${project.version}</version>
         </dependency>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>ipv6service-shell</artifactId>
+            <version>${project.version}</version>
+        </dependency>
         <dependency>
             <groupId>${project.groupId}</groupId>
             <artifactId>statemanager-impl</artifactId>
index c761dcd902f0b2bed10d0d399f34c4b1ccb2228c..9cba3a127699e0551fb2001187c6f46bb7a0e777 100644 (file)
@@ -696,4 +696,36 @@ public class IfMgr {
         LOG.debug("re-started periodic RA Timer for routerIntf {}, int {}s", port.getIntfUUID(),
                    Ipv6Constants.PERIODIC_RA_INTERVAL);
     }
+
+    public List<VirtualPort> getInterfaceCache() {
+        List<VirtualPort> virtualPorts = new ArrayList<>();
+        for (VirtualPort vport: vintfs.values()) {
+            virtualPorts.add(vport);
+        }
+        return virtualPorts;
+    }
+
+    public List<VirtualNetwork> getNetworkCache() {
+        List<VirtualNetwork> virtualNetworks = new ArrayList<>();
+        for (VirtualNetwork vnet: vnetworks.values()) {
+            virtualNetworks.add(vnet);
+        }
+        return virtualNetworks;
+    }
+
+    public List<VirtualSubnet> getSubnetCache() {
+        List<VirtualSubnet> virtualSubnets = new ArrayList<>();
+        for (VirtualSubnet vsubnet: vsubnets.values()) {
+            virtualSubnets.add(vsubnet);
+        }
+        return virtualSubnets;
+    }
+
+    public List<VirtualRouter> getRouterCache() {
+        List<VirtualRouter> virtualRouter = new ArrayList<>();
+        for (VirtualRouter vrouter: vrouters.values()) {
+            virtualRouter.add(vrouter);
+        }
+        return virtualRouter;
+    }
 }
index 2978cb771886376425bf5b17136b999128b6895c..e521cc7a9a26a14c29156103765558edf4fbecf9 100644 (file)
@@ -25,6 +25,7 @@ and is available at http://www.eclipse.org/legal/epl-v10.html INTERNAL
   <modules>
     <module>api</module>
     <module>impl</module>
+    <module>shell</module>
   </modules>
 
   <!-- DO NOT install or deploy the repo root pom as it's only needed to initiate a build -->
diff --git a/vpnservice/ipv6service/shell/pom.xml b/vpnservice/ipv6service/shell/pom.xml
new file mode 100644 (file)
index 0000000..32e10e8
--- /dev/null
@@ -0,0 +1,72 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- vi: set et smarttab sw=4 tabstop=4: --><!--
+Copyright (c) 2017 Red Hat, Inc. 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>binding-parent</artifactId>
+    <version>0.6.0-SNAPSHOT</version>
+    <relativePath>../../commons/binding-parent</relativePath>
+  </parent>
+
+  <modelVersion>4.0.0</modelVersion>
+  <artifactId>ipv6service-shell</artifactId>
+  <name>ODL :: netvirt :: ${project.artifactId}</name>
+  <packaging>bundle</packaging>
+
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.karaf.shell</groupId>
+      <artifactId>org.apache.karaf.shell.console</artifactId>
+      <scope>provided</scope>
+    </dependency>
+      <dependency>
+          <groupId>org.opendaylight.netvirt</groupId>
+          <artifactId>ipv6service-impl</artifactId>
+          <version>${project.version}</version>
+      </dependency>
+  </dependencies>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.felix</groupId>
+        <artifactId>maven-bundle-plugin</artifactId>
+        <extensions>true</extensions>
+        <configuration>
+          <instructions>
+            <!-- This bundle works with Karaf 3 and 4.0 -->
+            <Import-Package>
+              org.apache.karaf.shell.commands;version="[3.0.0,4.1)",
+              org.apache.karaf.shell.console;version="[3.0.0,4.1)",
+              *
+            </Import-Package>
+          </instructions>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+
+  <!--
+      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>
diff --git a/vpnservice/ipv6service/shell/src/main/java/org/opendaylight/netvirt/ipv6service/shell/ShowIpv6Command.java b/vpnservice/ipv6service/shell/src/main/java/org/opendaylight/netvirt/ipv6service/shell/ShowIpv6Command.java
new file mode 100644 (file)
index 0000000..998a6d2
--- /dev/null
@@ -0,0 +1,95 @@
+/*
+ * Copyright (c) 2017 Red Hat, Inc. 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.ipv6service.shell;
+
+import java.util.List;
+import org.apache.karaf.shell.commands.Argument;
+import org.apache.karaf.shell.commands.Command;
+import org.apache.karaf.shell.console.OsgiCommandSupport;
+import org.opendaylight.infrautils.utils.TablePrinter;
+import org.opendaylight.netvirt.ipv6service.IfMgr;
+import org.opendaylight.netvirt.ipv6service.VirtualNetwork;
+import org.opendaylight.netvirt.ipv6service.VirtualPort;
+import org.opendaylight.netvirt.ipv6service.VirtualRouter;
+import org.opendaylight.netvirt.ipv6service.VirtualSubnet;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Address;
+
+@Command(scope = "ipv6service", name = "ipv6CacheShow", description = "Displays the IPv6Service Cache info")
+public class ShowIpv6Command extends OsgiCommandSupport {
+    private IfMgr ifMgr = null;
+
+
+    @Argument(name = "resource", description = "List the various resource specific cache, where resource "
+            + "could be <networks/subnets/routers>", required = false, multiValued = false)
+    private final String listResource = null;
+
+    private String getPortIpv6Addresses(VirtualPort vport) {
+        List<Ipv6Address> ipv6Addresses = vport.getIpv6Addresses();
+        StringBuffer str = new StringBuffer();
+        for (Ipv6Address ipaddr: ipv6Addresses) {
+            str.append(ipaddr.getValue());
+            str.append("  ");
+        }
+        return str.toString();
+    }
+
+    @Override
+    protected Object doExecute() throws Exception {
+        ifMgr = IfMgr.getIfMgrInstance();
+        TablePrinter tp = new TablePrinter();
+
+        if (listResource != null) {
+            if (listResource.equalsIgnoreCase("networks")
+                    || (listResource.equalsIgnoreCase("net"))) {
+                tp.setTitle("Network Cache List");
+                tp.setColumnNames("Sno", "NetworkId", "dpnId");
+                int count = 1;
+                List<VirtualNetwork> vnetworks = ifMgr.getNetworkCache();
+                for (VirtualNetwork vnet: vnetworks) {
+                    tp.addRow(count++, String.valueOf(vnet.getNetworkUuid().getValue()), vnet.getDpnsHostingNetwork());
+                }
+                session.getConsole().print(tp.toString());
+            } else if (listResource.equalsIgnoreCase("subnets")
+                    || (listResource.equalsIgnoreCase("subnet"))) {
+                tp.setTitle("Subnet Cache List");
+                tp.setColumnNames("Sno", "SubnetId", "SubnetCIDR", "ipVersion");
+                int count = 1;
+                List<VirtualSubnet> vsubnets = ifMgr.getSubnetCache();
+                for (VirtualSubnet vsubnet : vsubnets) {
+                    tp.addRow(count++,   String.valueOf(vsubnet.getSubnetUUID().getValue()),
+                            String.valueOf(vsubnet.getSubnetCidr().getValue()),
+                            vsubnet.getIpVersion());
+                }
+                session.getConsole().print(tp.toString());
+            } else if (listResource.equalsIgnoreCase("routers")
+                    || (listResource.equalsIgnoreCase("router"))) {
+                tp.setTitle("Router Cache List");
+                tp.setColumnNames("Sno", "RouterId");
+                List<VirtualRouter> vrouters = ifMgr.getRouterCache();
+                int count = 1;
+                for (VirtualRouter vrouter : vrouters) {
+                    tp.addRow(count++, String.valueOf(vrouter.getRouterUUID().getValue()));
+                }
+                session.getConsole().print(tp.toString());
+            }
+        } else {
+            tp.setTitle("Interface Cache List");
+            tp.setColumnNames("Sno", "PortId", "Mac Address", "Owner", "dpnId", "FixedIPs");
+            List<VirtualPort> vports = ifMgr.getInterfaceCache();
+            int count = 1;
+            for (VirtualPort vport: vports) {
+                String str = vport.getDeviceOwner();
+                tp.addRow(count++, String.valueOf(vport.getIntfUUID().getValue()), vport.getMacAddress(),
+                        (str.startsWith("network:")) ? str.substring(str.lastIndexOf(':') + 1) : "compute",
+                        vport.getDpId(), getPortIpv6Addresses(vport));
+            }
+            session.getConsole().print(tp.toString());
+        }
+        return null;
+    }
+}
diff --git a/vpnservice/ipv6service/shell/src/main/resources/org/opendaylight/blueprint/blueprint.xml b/vpnservice/ipv6service/shell/src/main/resources/org/opendaylight/blueprint/blueprint.xml
new file mode 100644 (file)
index 0000000..65f0b86
--- /dev/null
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+Copyright (c) 2017 Red Hat, Inc. 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">
+
+  <command-bundle xmlns="http://karaf.apache.org/xmlns/shell/v1.1.0">
+
+    <command>
+      <action class="org.opendaylight.netvirt.ipv6service.shell.ShowIpv6Command">
+      </action>
+    </command>
+
+  </command-bundle>
+
+</blueprint>