2 * Copyright (c) 2017 Red Hat, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.netvirt.ipv6service.shell;
10 import java.util.List;
11 import java.util.stream.Collectors;
12 import org.apache.karaf.shell.commands.Argument;
13 import org.apache.karaf.shell.commands.Command;
14 import org.apache.karaf.shell.console.OsgiCommandSupport;
15 import org.eclipse.jdt.annotation.Nullable;
16 import org.opendaylight.infrautils.utils.TablePrinter;
17 import org.opendaylight.netvirt.ipv6service.api.ElementCache;
18 import org.opendaylight.netvirt.ipv6service.api.IVirtualNetwork;
19 import org.opendaylight.netvirt.ipv6service.api.IVirtualPort;
20 import org.opendaylight.netvirt.ipv6service.api.IVirtualRouter;
21 import org.opendaylight.netvirt.ipv6service.api.IVirtualSubnet;
22 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Address;
24 @Command(scope = "ipv6service", name = "ipv6CacheShow", description = "Displays the IPv6Service Cache info")
25 public class ShowIpv6Command extends OsgiCommandSupport {
26 private ElementCache elementCache;
28 @Argument(name = "resource", description = "List the various resource specific cache, where resource "
29 + "could be <networks/subnets/routers>", required = false, multiValued = false)
30 private final String listResource = null;
32 public void setElementCache(ElementCache elementCache) {
33 this.elementCache = elementCache;
36 private static String getPortIpv6Addresses(IVirtualPort vport) {
37 List<Ipv6Address> ipv6Addresses = vport.getIpv6Addresses();
38 return ipv6Addresses.stream().map(Ipv6Address::getValue).collect(Collectors.joining(" "));
43 protected Object doExecute() {
44 TablePrinter tp = new TablePrinter();
46 if (listResource != null) {
47 if (listResource.equalsIgnoreCase("networks")
48 || listResource.equalsIgnoreCase("net")) {
49 tp.setTitle("Network Cache List");
50 tp.setColumnNames("Sno", "NetworkId", "dpnId");
52 List<IVirtualNetwork> vnetworks = elementCache.getNetworkCache();
53 for (IVirtualNetwork vnet: vnetworks) {
54 tp.addRow(count++, String.valueOf(vnet.getNetworkUuid().getValue()), vnet.getDpnsHostingNetwork());
56 session.getConsole().print(tp.toString());
57 } else if (listResource.equalsIgnoreCase("subnets")
58 || listResource.equalsIgnoreCase("subnet")) {
59 tp.setTitle("Subnet Cache List");
60 tp.setColumnNames("Sno", "SubnetId", "SubnetCIDR", "ipVersion");
62 List<IVirtualSubnet> vsubnets = elementCache.getSubnetCache();
63 for (IVirtualSubnet vsubnet : vsubnets) {
64 tp.addRow(count++, String.valueOf(vsubnet.getSubnetUUID().getValue()),
65 vsubnet.getSubnetCidr().stringValue(), vsubnet.getIpVersion());
67 session.getConsole().print(tp.toString());
68 } else if (listResource.equalsIgnoreCase("routers")
69 || listResource.equalsIgnoreCase("router")) {
70 tp.setTitle("Router Cache List");
71 tp.setColumnNames("Sno", "RouterId");
72 List<IVirtualRouter> vrouters = elementCache.getRouterCache();
74 for (IVirtualRouter vrouter : vrouters) {
75 tp.addRow(count++, String.valueOf(vrouter.getRouterUUID().getValue()));
77 session.getConsole().print(tp.toString());
80 tp.setTitle("Interface Cache List");
81 tp.setColumnNames("Sno", "PortId", "Mac Address", "Owner", "dpnId", "FixedIPs");
82 List<IVirtualPort> vports = elementCache.getInterfaceCache();
84 for (IVirtualPort vport: vports) {
85 String str = vport.getDeviceOwner();
86 tp.addRow(count++, String.valueOf(vport.getIntfUUID().getValue()), vport.getMacAddress(),
87 str.startsWith("network:") ? str.substring(str.lastIndexOf(':') + 1) : "compute",
88 vport.getDpId(), getPortIpv6Addresses(vport));
90 session.getConsole().print(tp.toString());