2 * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. 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
9 package org.opendaylight.vpnservice.elan.cli.l2gw;
11 import java.util.concurrent.ConcurrentMap;
13 import org.apache.karaf.shell.commands.Command;
14 import org.apache.karaf.shell.commands.Option;
15 import org.apache.karaf.shell.console.OsgiCommandSupport;
16 import org.opendaylight.elanmanager.utils.ElanL2GwCacheUtils;
17 import org.opendaylight.vpnservice.neutronvpn.api.l2gw.L2GatewayDevice;
18 import org.opendaylight.vpnservice.neutronvpn.api.l2gw.utils.L2GatewayCacheUtils;
19 import org.opendaylight.vpnservice.utils.cache.CacheUtil;
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
23 @Command(scope = "l2gw", name = "show-cache", description = "display l2gateways cache")
24 public class L2GwUtilsCacheCli extends OsgiCommandSupport {
25 private static final Logger logger = LoggerFactory.getLogger(L2GwUtilsCacheCli.class);
27 private static final String DEMARCATION = "=================================";
29 @Option(name = "-cache", aliases = {"--cache"}, description = "cache name",
30 required = false, multiValued = false)
31 String cacheName = null;
33 @Option(name = "-elan", aliases = {"--elan"}, description = "elan name",
34 required = false, multiValued = false)
38 protected Object doExecute() {
40 if (cacheName == null) {
41 System.out.println("Available caches");
42 System.out.println(ElanL2GwCacheUtils.L2GATEWAY_CONN_CACHE_NAME);
43 System.out.println(L2GatewayCacheUtils.L2GATEWAY_CACHE_NAME);
47 case ElanL2GwCacheUtils.L2GATEWAY_CONN_CACHE_NAME:
50 case L2GatewayCacheUtils.L2GATEWAY_CACHE_NAME:
54 } catch (Exception e) {
60 private void dumpL2GwCache() {
61 ConcurrentMap<String, L2GatewayDevice> devices = (ConcurrentMap<String, L2GatewayDevice>) CacheUtil
62 .getCache(L2GatewayCacheUtils.L2GATEWAY_CACHE_NAME);
63 if (devices == null) {
64 System.out.println("no devices are present in cache");
67 for (String deviceName : devices.keySet()) {
68 System.out.println("device "+ devices.get(deviceName));
72 private void dumpElanL2GwCache() {
73 if (elanName == null) {
74 ConcurrentMap<String, ConcurrentMap<String, L2GatewayDevice>> cache =
75 (ConcurrentMap<String, ConcurrentMap<String, L2GatewayDevice>>) CacheUtil.getCache(
78 System.out.println("no devices are present in elan cache");
80 for (String elan : cache.keySet()) {
81 print(elan, cache.get(elan));
82 System.out.println(DEMARCATION);
83 System.out.println(DEMARCATION);
87 ConcurrentMap<String, L2GatewayDevice> elanDevices = ElanL2GwCacheUtils
88 .getInvolvedL2GwDevices(elanName);
89 print(elanName, elanDevices);
92 private void print(String elan,
93 ConcurrentMap<String, L2GatewayDevice> devices) {
94 System.out.println("Elan name : "+elan);
95 System.out.println("No of devices in elan "+devices.keySet().size());
96 for (String deviceName : devices.keySet()) {
97 System.out.println("device "+ devices.get(deviceName));