[CORD-2362] dhcp relay v6 counters implementation

Change-Id: I1ec322d6d77ff62ec4ad91632349e3a2c0d058f3
diff --git a/apps/dhcprelay/src/main/java/org/onosproject/dhcprelay/Dhcp6HandlerImpl.java b/apps/dhcprelay/src/main/java/org/onosproject/dhcprelay/Dhcp6HandlerImpl.java
index 654c79d..525aedf 100644
--- a/apps/dhcprelay/src/main/java/org/onosproject/dhcprelay/Dhcp6HandlerImpl.java
+++ b/apps/dhcprelay/src/main/java/org/onosproject/dhcprelay/Dhcp6HandlerImpl.java
@@ -58,6 +58,8 @@
 import org.onosproject.dhcprelay.store.DhcpRelayStore;
 import org.onosproject.dhcprelay.store.DhcpRecord;
 import org.onosproject.dhcprelay.store.DhcpFpmPrefixStore;
+import org.onosproject.dhcprelay.store.DhcpRelayCounters;
+import org.onosproject.dhcprelay.store.DhcpRelayCountersStore;
 import org.onosproject.net.Device;
 import org.onosproject.net.DeviceId;
 import org.onosproject.routing.fpm.api.FpmRecord;
@@ -107,12 +109,12 @@
 import java.util.Optional;
 import java.util.Set;
 import java.util.ArrayList;
-
 import java.util.concurrent.atomic.AtomicInteger;
 import static com.google.common.base.Preconditions.checkNotNull;
 import static com.google.common.base.Preconditions.checkState;
 import static org.onosproject.net.flowobjective.Objective.Operation.ADD;
 import static org.onosproject.net.flowobjective.Objective.Operation.REMOVE;
+import java.util.concurrent.Semaphore;
 
 @Component
 @Service
@@ -121,7 +123,7 @@
     public static final String DHCP_V6_RELAY_APP = "org.onosproject.Dhcp6HandlerImpl";
     public static final ProviderId PROVIDER_ID = new ProviderId("dhcp6", DHCP_V6_RELAY_APP);
     private static final int IGNORE_CONTROL_PRIORITY = PacketPriority.CONTROL.priorityValue() + 1000;
-
+    private String gCount = "global";
     private static final TrafficSelector CLIENT_SERVER_SELECTOR = DefaultTrafficSelector.builder()
             .matchEthType(Ethernet.TYPE_IPV6)
             .matchIPProtocol(IPv6.PROTOCOL_UDP)
@@ -146,6 +148,9 @@
     protected DhcpRelayStore dhcpRelayStore;
 
     @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+    protected DhcpRelayCountersStore dhcpRelayCountersStore;
+
+    @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
     protected PacketService packetService;
 
     @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
@@ -193,7 +198,8 @@
     }
     protected int dhcp6PollInterval = 24 * 3600; // 24 hr period
 
-
+    // max 1 thread
+    static Semaphore recordSemaphore = new Semaphore(1);
 
     // CLIENT message types
     public static final Set<Byte> MSG_TYPE_FROM_CLIENT =
@@ -295,7 +301,6 @@
         MsgType msgType = DHCP6.MsgType.getType(msgTypeVal);
         log.debug("msgType is {}", msgType);
 
-
         ConnectPoint inPort = context.inPacket().receivedFrom();
 
         if (inPort == null) {
@@ -522,10 +527,12 @@
                 leafClientMac = MacAddress.valueOf(clientIdOption.getDuid().getLinkLayerAddress());
             } else {
                 log.warn("Link-Layer Address not supported in CLIENTID option. No DhcpRelay Record created.");
+                dhcpRelayCountersStore.incrementCounter(gCount, DhcpRelayCounters.NO_LINKLOCAL_FAIL);
                 return;
             }
         } else {
             log.warn("CLIENTID option NOT found. Don't create DhcpRelay Record.");
+            dhcpRelayCountersStore.incrementCounter(gCount, DhcpRelayCounters.NO_CLIENTID_FAIL);
             return;
         }
 
@@ -533,6 +540,8 @@
         DhcpRecord record = dhcpRelayStore.getDhcpRecord(leafHostId).orElse(null);
         if (record == null) {
             record = new DhcpRecord(leafHostId);
+        }  else {
+            record = record.clone();
         }
 
         Boolean isMsgRelease = dhcp6HandlerUtil.isDhcp6Release(dhcp6Packet);
@@ -558,6 +567,7 @@
             IpAddress nextHopIp = getFirstIpByHost(directConnFlag, srcMac, vlanId);
             if (nextHopIp == null) {
                 log.warn("Can't find link-local IP address of gateway mac {} vlanId {}", srcMac, vlanId);
+                dhcpRelayCountersStore.incrementCounter(gCount, DhcpRelayCounters.NO_LINKLOCAL_GW);
                 return;
             }
 
@@ -594,7 +604,7 @@
                 }
             }
             leafMsgType = leafDhcp.getMsgType();
-        }
+       }
 
         if (isMsgRelease) {
             log.debug("DHCP6 RELEASE msg.");
@@ -615,6 +625,7 @@
             }
         }
 
+        record.getV6Counters().incrementCounter(dhcp6HandlerUtil.getMsgTypeStr(leafMsgType));
         record.addLocation(new HostLocation(location, System.currentTimeMillis()));
         record.ip6Status(DHCP6.MsgType.getType(leafMsgType));
         record.setDirectlyConnected(directConnFlag);
@@ -624,6 +635,18 @@
         }
         record.updateLastSeen();
         dhcpRelayStore.updateDhcpRecord(leafHostId, record);
+        // TODO Use AtomicInteger for the counters
+        try {
+            recordSemaphore.acquire();
+            try {
+                dhcpRelayCountersStore.incrementCounter(gCount, dhcp6HandlerUtil.getMsgTypeStr(leafMsgType));
+            } finally {
+                // calling release() after a successful acquire()
+                recordSemaphore.release();
+            }
+        } catch (InterruptedException e) {
+            e.printStackTrace();
+        }
     }
 
     /**
@@ -652,16 +675,20 @@
                 leafClientMac = MacAddress.valueOf(clientIdOption.getDuid().getLinkLayerAddress());
             } else {
                 log.warn("Link-Layer Address not supported in CLIENTID option. No DhcpRelay Record created.");
+                dhcpRelayCountersStore.incrementCounter(gCount, DhcpRelayCounters.NO_LINKLOCAL_FAIL);
                 return;
             }
         } else {
             log.warn("CLIENTID option NOT found. No DhcpRelay Record created.");
+            dhcpRelayCountersStore.incrementCounter(gCount, DhcpRelayCounters.NO_CLIENTID_FAIL);
             return;
         }
         HostId leafHostId = HostId.hostId(leafClientMac, vlanId);
         DhcpRecord record = dhcpRelayStore.getDhcpRecord(leafHostId).orElse(null);
         if (record == null) {
             record = new DhcpRecord(HostId.hostId(leafClientMac, vlanId));
+        } else {
+            record = record.clone();
         }
 
         IpAddressInfo ipInfo;
@@ -701,6 +728,7 @@
             IpAddress nextHopIp = getFirstIpByHost(directConnFlag, srcMac, vlanId);
             if (nextHopIp == null) {
                 log.warn("Can't find link-local IP address of gateway mac {} vlanId {}", srcMac, vlanId);
+                dhcpRelayCountersStore.incrementCounter(gCount, DhcpRelayCounters.NO_LINKLOCAL_GW);
                 return;
             }
 
@@ -754,10 +782,23 @@
                 log.debug("IP6 PD address is not returned from server. Maybe only IPAddress is returned.");
             }
         }
+        record.getV6Counters().incrementCounter(dhcp6HandlerUtil.getMsgTypeStr(leafMsgType));
         record.ip6Status(DHCP6.MsgType.getType(leafMsgType));
         record.setDirectlyConnected(directConnFlag);
         record.updateLastSeen();
         dhcpRelayStore.updateDhcpRecord(leafHostId, record);
+        // TODO Use AtomicInteger for the counters
+        try {
+            recordSemaphore.acquire();
+            try {
+                dhcpRelayCountersStore.incrementCounter(gCount, dhcp6HandlerUtil.getMsgTypeStr(leafMsgType));
+            } finally {
+                // calling release() after a successful acquire()
+                recordSemaphore.release();
+            }
+        } catch (InterruptedException e) {
+            e.printStackTrace();
+        }
     }
 
     /**
@@ -778,6 +819,7 @@
             log.warn("Missing DHCP relay agent interface Ipv6 addr config for "
                       + "packet from client on port: {}. Aborting packet processing",
                       clientInterfaces.iterator().next().connectPoint());
+            dhcpRelayCountersStore.incrementCounter(gCount, DhcpRelayCounters.NO_CLIENT_INTF_MAC);
             return null;
         }
 
@@ -852,16 +894,17 @@
                 .map(pld -> (DHCP6) pld)
                 .findFirst()
                 .orElse(null);
-
         ConnectPoint inPort = context.inPacket().receivedFrom();
         DhcpServerInfo foundServerInfo = findServerInfoFromServer(directConnFlag, inPort);
 
         if (foundServerInfo == null) {
             log.warn("Cannot find server info");
+            dhcpRelayCountersStore.incrementCounter(gCount, DhcpRelayCounters.NO_SERVER_INFO);
             return null;
         } else {
             if (dhcp6HandlerUtil.isServerIpEmpty(foundServerInfo)) {
                 log.warn("Cannot find server info's ipaddress");
+                dhcpRelayCountersStore.incrementCounter(gCount, DhcpRelayCounters.NO_SERVER_IP6ADDR);
                 return null;
             }
         }
@@ -873,6 +916,7 @@
                 .orElse(null);
         if (interfaceIdOption == null) {
             log.warn("Interface Id option is not present, abort packet...");
+            dhcpRelayCountersStore.incrementCounter(gCount, DhcpRelayCounters.OPTION_MISSING_FAIL);
             return null;
         }
 
@@ -885,11 +929,13 @@
                 .findFirst().orElse(null);
         if (clientInterface == null) {
             log.warn("Cannot get client interface for from packet, abort... vlan {}", vlanIdInUse.toString());
+            dhcpRelayCountersStore.incrementCounter(gCount, DhcpRelayCounters.NO_MATCHING_INTF);
             return null;
         }
         MacAddress relayAgentMac = clientInterface.mac();
         if (relayAgentMac == null) {
             log.warn("Can not get client interface mac, abort packet..");
+            dhcpRelayCountersStore.incrementCounter(gCount, DhcpRelayCounters.NO_CLIENT_INTF_MAC);
             return null;
         }
         etherReply.setSourceMACAddress(relayAgentMac);
@@ -907,6 +953,7 @@
             clientMac = clients.iterator().next().mac();
             if (clientMac == null) {
                 log.warn("No client mac address found, abort packet...");
+                dhcpRelayCountersStore.incrementCounter(gCount, DhcpRelayCounters.NO_CLIENT_INTF_MAC);
                 return null;
             }
             log.trace("Client mac address found from getHostByIp");
@@ -941,14 +988,12 @@
     @Override
     public void setDefaultDhcpServerConfigs(Collection<DhcpServerConfig> configs) {
         log.debug("setDefaultDhcpServerConfigs is called.");
-
         setDhcpServerConfigs(configs, defaultServerInfoList);
     }
 
     @Override
     public void setIndirectDhcpServerConfigs(Collection<DhcpServerConfig> configs) {
         log.debug("setIndirectDhcpServerConfigs is called.");
-
         setDhcpServerConfigs(configs, indirectServerInfoList);
     }
 
@@ -1126,7 +1171,6 @@
                 .findFirst()
                 .orElse(null);
     }
-
     /**
      * Checks if serverInfo's host info (mac and vlan) is filled in; if not, fills in.
      *
@@ -1436,12 +1480,4 @@
         dhcp6PollInterval = val;
     }
 
-    /**
-     * Get the dhcp6 lease expiry poll interval value.
-     *
-     * @return poll interval value in seconds
-     */
-    public int getDhcp6PollInterval() {
-        return dhcp6PollInterval;
-    }
-}
+ }
diff --git a/apps/dhcprelay/src/main/java/org/onosproject/dhcprelay/Dhcp6HandlerUtil.java b/apps/dhcprelay/src/main/java/org/onosproject/dhcprelay/Dhcp6HandlerUtil.java
index 5eb71b6..6e47a0d 100644
--- a/apps/dhcprelay/src/main/java/org/onosproject/dhcprelay/Dhcp6HandlerUtil.java
+++ b/apps/dhcprelay/src/main/java/org/onosproject/dhcprelay/Dhcp6HandlerUtil.java
@@ -32,6 +32,7 @@
 
 import org.onlab.util.HexString;
 import org.onosproject.dhcprelay.api.DhcpServerInfo;
+import org.onosproject.dhcprelay.store.DhcpRelayCounters;
 import org.onosproject.net.ConnectPoint;
 import org.onosproject.net.host.InterfaceIpAddress;
 import org.onosproject.net.intf.Interface;
@@ -214,33 +215,7 @@
             if (leafDhcp != null) {
                 return getMsgTypeStr(leafDhcp.getMsgType());
             } else {
-                return "INVALID"; //DhcpRelayCounters.INVALID_PACKET;
-            }
-        }
-    }
-
-    /**
-     * find the string of dhcp6 leaf packets's msg type.
-     *
-     * @param fromClient indicate from what side a packet is received
-     * @param directConnFlag boolean value indicating direct/indirect connection
-     * @param dhcp6Packet dhcp6 packet
-     * @return String string value of dhcp6 leaf packet msg type
-     */
-    public String findMsgType(boolean fromClient, boolean directConnFlag, DHCP6  dhcp6Packet) {
-        if (fromClient) {
-            return findLeafMsgType(directConnFlag, dhcp6Packet);
-        } else {
-            DHCP6 embeddedDhcp6 = dhcp6Packet.getOptions().stream()
-                    .filter(opt -> opt instanceof Dhcp6RelayOption)
-                    .map(BasePacket::getPayload)
-                    .map(pld -> (DHCP6) pld)
-                    .findFirst()
-                    .orElse(null);
-            if (embeddedDhcp6 != null) {
-                return findLeafMsgType(directConnFlag, embeddedDhcp6);
-            } else {
-                return "INVALID"; //DhcpRelayCounters.INVALID_PACKET;
+                return DhcpRelayCounters.INVALID_PACKET;
             }
         }
     }
diff --git a/apps/dhcprelay/src/main/java/org/onosproject/dhcprelay/DhcpRelayManager.java b/apps/dhcprelay/src/main/java/org/onosproject/dhcprelay/DhcpRelayManager.java
index 07e5cd9..39123ac 100644
--- a/apps/dhcprelay/src/main/java/org/onosproject/dhcprelay/DhcpRelayManager.java
+++ b/apps/dhcprelay/src/main/java/org/onosproject/dhcprelay/DhcpRelayManager.java
@@ -93,6 +93,11 @@
 import org.osgi.service.component.ComponentContext;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+import static org.onlab.util.Tools.groupedThreads;
+
 
 import com.google.common.collect.ImmutableSet;
 
@@ -153,6 +158,7 @@
             }
     );
 
+
     @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
     protected NetworkConfigRegistry cfgService;
 
@@ -192,14 +198,30 @@
             label = "Enable Address resolution protocol")
     protected boolean arpEnabled = true;
 
+    @Property(name = "dhcpPollInterval", intValue = 24 * 3600,
+            label = "dhcp relay poll interval")
+    protected int dhcpPollInterval = 24 * 3600;
+
     @Property(name = "dhcpFpmEnabled", boolValue = false,
             label = "Enable DhcpRelay Fpm")
     protected boolean dhcpFpmEnabled = false;
 
+
+    private ScheduledExecutorService timerExecutor;
+
     protected DeviceListener deviceListener = new InternalDeviceListener();
     private DhcpRelayPacketProcessor dhcpRelayPacketProcessor = new DhcpRelayPacketProcessor();
     private ApplicationId appId;
 
+    /**
+     *   One second timer.
+     */
+    class Dhcp6Timer implements Runnable {
+        @Override
+        public void run() {
+            v6Handler.timeTick();
+        }
+    };
 
     @Activate
     protected void activate(ComponentContext context) {
@@ -214,6 +236,14 @@
         //add the packet processor
         packetService.addProcessor(dhcpRelayPacketProcessor, PacketProcessor.director(0));
 
+        timerExecutor = Executors.newScheduledThreadPool(1,
+                groupedThreads("dhcpRelay",
+                        "config-reloader-%d", log));
+        timerExecutor.scheduleAtFixedRate(new Dhcp6Timer(),
+                0,
+                dhcpPollInterval,
+                TimeUnit.SECONDS);
+
         modified(context);
 
         // Enable distribute route store
@@ -222,6 +252,9 @@
         compCfgService.registerProperties(getClass());
 
         deviceService.addListener(deviceListener);
+
+
+
         log.info("DHCP-RELAY Started");
     }
 
@@ -233,6 +266,8 @@
         cancelArpPackets();
         compCfgService.unregisterProperties(getClass(), false);
         deviceService.removeListener(deviceListener);
+        timerExecutor.shutdown();
+
         log.info("DHCP-RELAY Stopped");
     }
 
@@ -254,6 +289,21 @@
             cancelArpPackets();
         }
 
+        int intervalVal = Tools.getIntegerProperty(properties, "dhcpPollInterval");
+        log.info("DhcpRelay poll interval new {} old {}", intervalVal, dhcpPollInterval);
+        if (intervalVal !=  dhcpPollInterval) {
+            timerExecutor.shutdown();
+            dhcpPollInterval = intervalVal;
+            timerExecutor = Executors.newScheduledThreadPool(1,
+                    groupedThreads("dhcpRelay",
+                            "config-reloader-%d", log));
+            timerExecutor.scheduleAtFixedRate(new Dhcp6Timer(),
+                        0,
+                        dhcpPollInterval > 1 ? dhcpPollInterval : 1,
+                        TimeUnit.SECONDS);
+            v6Handler.setDhcp6PollInterval(dhcpPollInterval);
+        }
+
         flag = Tools.isPropertyEnabled(properties, "dhcpFpmEnabled");
         if (flag != null) {
             boolean oldValue = dhcpFpmEnabled;
@@ -368,7 +418,10 @@
     public Collection<DhcpRecord> getDhcpRecords() {
         return dhcpRelayStore.getDhcpRecords();
     }
-
+    @Override
+    public void updateDhcpRecord(HostId hostId, DhcpRecord dhcpRecord) {
+        dhcpRelayStore.updateDhcpRecord(hostId, dhcpRecord);
+    }
     @Override
     public Optional<MacAddress> getDhcpServerMacAddress() {
         // TODO: depreated it
@@ -617,4 +670,6 @@
     public Optional<FpmRecord> removeFpmRecord(IpPrefix prefix) {
         return dhcpFpmPrefixStore.removeFpmRecord(prefix);
     }
+
+
 }
diff --git a/apps/dhcprelay/src/main/java/org/onosproject/dhcprelay/api/DhcpHandler.java b/apps/dhcprelay/src/main/java/org/onosproject/dhcprelay/api/DhcpHandler.java
index 49b88e8..b5cabc5 100644
--- a/apps/dhcprelay/src/main/java/org/onosproject/dhcprelay/api/DhcpHandler.java
+++ b/apps/dhcprelay/src/main/java/org/onosproject/dhcprelay/api/DhcpHandler.java
@@ -178,6 +178,19 @@
     void removeIgnoreVlanState(IgnoreDhcpConfig config);
 
     /**
+     * Hander for Dhcp expiration poll timer.
+     *
+     */
+    default void timeTick() { }
+
+    /**
+     * Update Dhcp expiration poll timer value.
+     *
+     * @param val the timer interval value
+     */
+    default void setDhcp6PollInterval(int val) { }
+
+    /**
      * Sets DHCP FPM Enable state.
      *
      * @param dhcpFpmFlag flag indicating dhcpFpmEnable state
diff --git a/apps/dhcprelay/src/main/java/org/onosproject/dhcprelay/api/DhcpRelayService.java b/apps/dhcprelay/src/main/java/org/onosproject/dhcprelay/api/DhcpRelayService.java
index ef700d4..5eb8d9e 100644
--- a/apps/dhcprelay/src/main/java/org/onosproject/dhcprelay/api/DhcpRelayService.java
+++ b/apps/dhcprelay/src/main/java/org/onosproject/dhcprelay/api/DhcpRelayService.java
@@ -43,6 +43,14 @@
     Collection<DhcpRecord> getDhcpRecords();
 
     /**
+     * Updates DHCP record for specific host id (mac + vlan).
+     *
+     * @param hostId the id of host
+     * @param dhcpRecord the DHCP record of the host
+     */
+    void updateDhcpRecord(HostId hostId, DhcpRecord dhcpRecord);
+
+    /**
      * Gets mac address of DHCP server.
      *
      * @return the mac address of DHCP server; empty if not exist
@@ -102,4 +110,5 @@
      * @return boolean value
      */
     public boolean isDhcpFpmEnabled();
+
 }
diff --git a/apps/dhcprelay/src/main/java/org/onosproject/dhcprelay/cli/DhcpRelayAggCountersCommand.java b/apps/dhcprelay/src/main/java/org/onosproject/dhcprelay/cli/DhcpRelayAggCountersCommand.java
new file mode 100644
index 0000000..a91a53a
--- /dev/null
+++ b/apps/dhcprelay/src/main/java/org/onosproject/dhcprelay/cli/DhcpRelayAggCountersCommand.java
@@ -0,0 +1,82 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * 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.dhcprelay.cli;
+
+import org.apache.karaf.shell.commands.Argument;
+import org.apache.karaf.shell.commands.Command;
+import org.onosproject.cli.AbstractShellCommand;
+import org.onosproject.dhcprelay.api.DhcpRelayService;
+import org.onosproject.dhcprelay.store.DhcpRelayCounters;
+import org.onosproject.dhcprelay.store.DhcpRelayCountersStore;
+
+
+import java.util.Map;
+import java.util.Optional;
+
+/**
+ * Prints Dhcp FPM Routes information.
+ */
+@Command(scope = "onos", name = "dhcp-relay-agg-counters",
+         description = "DHCP Relay Aggregate Counters cli.")
+public class DhcpRelayAggCountersCommand extends AbstractShellCommand {
+    @Argument(index = 0, name = "reset",
+            description = "reset counters or not",
+            required = false, multiValued = false)
+    String reset = null;
+
+    private static final String HEADER = "DHCP Relay Aggregate Counters :";
+    private static final String GCOUNT = "global";
+    private static final DhcpRelayService DHCP_RELAY_SERVICE = get(DhcpRelayService.class);
+
+    @Override
+    protected void execute() {
+        boolean toResetFlag;
+
+        if (reset != null) {
+            if (reset.equals("reset") || reset.equals("[reset]")) {
+                toResetFlag = true;
+            } else {
+                print("Last parameter is [reset]");
+                return;
+            }
+        } else {
+            toResetFlag = false;
+        }
+
+        print(HEADER);
+
+        DhcpRelayCountersStore counterStore = AbstractShellCommand.get(DhcpRelayCountersStore.class);
+
+        Optional<DhcpRelayCounters> perClassCounters = counterStore.getCounters(GCOUNT);
+
+        if (perClassCounters.isPresent()) {
+            Map<String, Integer> counters = perClassCounters.get().getCounters();
+            if (counters.size() > 0) {
+                counters.forEach((name, value) -> {
+                    print("%-30s  ............................  %-4d packets", name, value);
+                });
+            } else {
+                print("No counter for {}", GCOUNT);
+            }
+
+            if (toResetFlag) {
+                counterStore.resetCounters(GCOUNT);
+
+            }
+        }
+    }
+}
diff --git a/apps/dhcprelay/src/main/java/org/onosproject/dhcprelay/cli/DhcpRelayCommand.java b/apps/dhcprelay/src/main/java/org/onosproject/dhcprelay/cli/DhcpRelayCommand.java
index e872971..6bf46b8 100644
--- a/apps/dhcprelay/src/main/java/org/onosproject/dhcprelay/cli/DhcpRelayCommand.java
+++ b/apps/dhcprelay/src/main/java/org/onosproject/dhcprelay/cli/DhcpRelayCommand.java
@@ -16,12 +16,15 @@
 
 package org.onosproject.dhcprelay.cli;
 
+
+import org.apache.karaf.shell.commands.Argument;
 import org.apache.karaf.shell.commands.Command;
 import org.onlab.packet.IpAddress;
 import org.onlab.packet.MacAddress;
 import org.onlab.packet.VlanId;
 import org.onlab.util.Tools;
 import org.onosproject.cli.AbstractShellCommand;
+import org.onosproject.dhcprelay.store.DhcpRelayCounters;
 import org.onosproject.dhcprelay.api.DhcpServerInfo;
 import org.onosproject.dhcprelay.api.DhcpRelayService;
 import org.onosproject.dhcprelay.store.DhcpRecord;
@@ -32,12 +35,30 @@
 import java.util.Collection;
 import java.util.List;
 import java.util.function.Predicate;
+import java.util.Map;
+
 
 /**
  * Prints DHCP server and DHCP relay status.
  */
 @Command(scope = "onos", name = "dhcp-relay", description = "DHCP relay app cli.")
 public class DhcpRelayCommand extends AbstractShellCommand {
+    @Argument(index = 0, name = "counter",
+            description = "shows counter values",
+            required = false, multiValued = false)
+    String counter = null;
+
+    @Argument(index = 1, name = "reset",
+            description = "reset counters or not",
+            required = false, multiValued = false)
+    String reset = null;
+
+
+
+    private static final String CONUTER_HEADER = "DHCP Relay Counters :";
+    private static final String COUNTER_HOST = "Counters for id=%s/%s, locations=%s%s";
+
+
     private static final String HEADER = "DHCP relay records ([D]: Directly connected):";
     private static final String NO_RECORDS = "No DHCP relay record found";
     private static final String HOST = "id=%s/%s, locations=%s%s, last-seen=%s, IPv4=%s, IPv6=%s";
@@ -49,14 +70,15 @@
     private static final String NA = "N/A";
     private static final String STATUS_FMT = "[%s, %s]";
     private static final String STATUS_FMT_NH = "[%s via %s, %s]";
-    private static final String STATUS_FMT_V6 = "[%s, %s, %s]";
-    private static final String STATUS_FMT_V6_NH = "[%s, %s via %s, %s]";
+    private static final String STATUS_FMT_V6 = "[%s %d, %d ms %s %d %d ms, %s]";
+    private static final String STATUS_FMT_V6_NH = "[%s %d %d ms, %s %d %d ms via %s, %s]";
     private static final String DEFAULT_SERVERS = "Default DHCP servers:";
     private static final String INDIRECT_SERVERS = "Indirect DHCP servers:";
 
     private static final DhcpRelayService DHCP_RELAY_SERVICE = get(DhcpRelayService.class);
     private static final HostService HOST_SERVICE = get(HostService.class);
 
+
     @Override
     protected void execute() {
         List<DhcpServerInfo> defaultDhcpServerInfoList = DHCP_RELAY_SERVICE.getDefaultDhcpServerInfoList();
@@ -82,6 +104,52 @@
             print(NO_RECORDS);
             return;
         }
+
+        // Handle display of counters
+        boolean toResetFlag;
+
+        if (counter != null) {
+            if (counter.equals("counter") || reset.equals("[counter]")) {
+                print(CONUTER_HEADER);
+            } else {
+                print("first parameter is [counter]");
+                return;
+            }
+            if (reset != null) {
+                if (reset.equals("reset") || reset.equals("[reset]")) {
+                    toResetFlag = true;
+                } else {
+                    print("Last parameter is [reset]");
+                    return;
+                }
+            } else {
+                toResetFlag = false;
+            }
+
+            records.forEach(record -> {
+                print(COUNTER_HOST, record.macAddress(),
+                        record.vlanId(),
+                        record.locations(),
+                        record.directlyConnected() ? DIRECTLY : EMPTY);
+                DhcpRelayCounters v6Counters = record.getV6Counters();
+                Map<String, Integer> countersMap = v6Counters.getCounters();
+                countersMap.forEach((name, value) -> {
+                    print("%-30s  ............................  %-4d packets", name, value);
+                });
+                if (toResetFlag) {
+                    v6Counters.resetCounters();
+                    record.updateLastSeen();
+                    DHCP_RELAY_SERVICE.updateDhcpRecord(HostId.hostId(record.macAddress(), record.vlanId()), record);
+                }
+            });
+
+
+            return;
+        }
+
+
+        // Handle display of records
+
         print(HEADER);
         records.forEach(record -> print(HOST,
                                         record.macAddress(),
@@ -144,12 +212,20 @@
         if (record.directlyConnected()) {
             return String.format(STATUS_FMT_V6,
                     record.ip6Address().map(Object::toString).orElse(NA),
+                    record.addrPrefTime(),
+                    record.getLastIp6Update(),
                     record.pdPrefix().map(Object::toString).orElse(NA),
+                    record.pdPrefTime(),
+                    record.getLastPdUpdate(),
                     record.ip6Status().map(Object::toString).orElse(NA));
         } else {
             return String.format(STATUS_FMT_V6_NH,
                     record.ip6Address().map(Object::toString).orElse(NA),
+                    record.addrPrefTime(),
+                    record.getLastIp6Update(),
                     record.pdPrefix().map(Object::toString).orElse(NA),
+                    record.pdPrefTime(),
+                    record.getLastPdUpdate(),
                     nextHopIp,
                     record.ip6Status().map(Object::toString).orElse(NA));
         }
diff --git a/apps/dhcprelay/src/main/java/org/onosproject/dhcprelay/cli/DhcpRelayCounterCompleter.java b/apps/dhcprelay/src/main/java/org/onosproject/dhcprelay/cli/DhcpRelayCounterCompleter.java
new file mode 100644
index 0000000..8b024a5
--- /dev/null
+++ b/apps/dhcprelay/src/main/java/org/onosproject/dhcprelay/cli/DhcpRelayCounterCompleter.java
@@ -0,0 +1,39 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * 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.dhcprelay.cli;
+
+import org.apache.karaf.shell.console.Completer;
+import org.apache.karaf.shell.console.completer.StringsCompleter;
+
+import java.util.List;
+import java.util.SortedSet;
+
+/**
+ * Dhcp Relay counter completer.
+ */
+public class DhcpRelayCounterCompleter implements Completer {
+
+    @Override
+    public int complete(String buffer, int cursor, List<String> candidates) {
+        // Delegate string completer
+        StringsCompleter delegate = new StringsCompleter();
+        SortedSet<String> strings = delegate.getStrings();
+        strings.add("counter");
+
+        // Now let the completer do the work for figuring out what to offer.
+        return delegate.complete(buffer, cursor, candidates);
+    }
+}
diff --git a/apps/dhcprelay/src/main/java/org/onosproject/dhcprelay/cli/DhcpRelayResetCompleter.java b/apps/dhcprelay/src/main/java/org/onosproject/dhcprelay/cli/DhcpRelayResetCompleter.java
new file mode 100644
index 0000000..3eb4404
--- /dev/null
+++ b/apps/dhcprelay/src/main/java/org/onosproject/dhcprelay/cli/DhcpRelayResetCompleter.java
@@ -0,0 +1,39 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * 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.dhcprelay.cli;
+
+import org.apache.karaf.shell.console.Completer;
+import org.apache.karaf.shell.console.completer.StringsCompleter;
+
+import java.util.List;
+import java.util.SortedSet;
+
+/**
+ * Dhcp Relay reset completer.
+ */
+public class DhcpRelayResetCompleter implements Completer {
+
+    @Override
+    public int complete(String buffer, int cursor, List<String> candidates) {
+        // Delegate string completer
+        StringsCompleter delegate = new StringsCompleter();
+        SortedSet<String> strings = delegate.getStrings();
+        strings.add("reset");
+
+        // Now let the completer do the work for figuring out what to offer.
+        return delegate.complete(buffer, cursor, candidates);
+    }
+}
diff --git a/apps/dhcprelay/src/main/java/org/onosproject/dhcprelay/store/DhcpRecord.java b/apps/dhcprelay/src/main/java/org/onosproject/dhcprelay/store/DhcpRecord.java
index 6f620db..44c6c3c 100644
--- a/apps/dhcprelay/src/main/java/org/onosproject/dhcprelay/store/DhcpRecord.java
+++ b/apps/dhcprelay/src/main/java/org/onosproject/dhcprelay/store/DhcpRecord.java
@@ -53,8 +53,16 @@
     private IpPrefix pdPrefix;
     private DHCP6.MsgType ip6Status;
 
+
     private long lastSeen;
+    private long lastIp6Update;
+    private long lastPdUpdate;
+
     private boolean directlyConnected;
+    private long addrPrefTime;
+    private long pdPrefTime;
+    private DhcpRelayCounters v6Counters;
+
 
     /**
      * Creates a DHCP record for a host (mac + vlan).
@@ -69,6 +77,7 @@
         this.vlanId = hostId.vlanId();
         this.lastSeen = System.currentTimeMillis();
         this.directlyConnected = false;
+        this.v6Counters = new DhcpRelayCounters();
     }
 
     /**
@@ -200,6 +209,84 @@
     }
 
     /**
+     * Gets the latest time this record updated with ip6 Address.
+     *
+     * @return the last time received DHCP packet provide ip6 Address
+     */
+    public long getLastIp6Update() {
+        return lastIp6Update;
+    }
+
+    /**
+     * Updates the update time of this record is given ip6 Address.
+     *
+     * @return the DHCP record
+     */
+    public DhcpRecord updateLastIp6Update() {
+        lastIp6Update = System.currentTimeMillis();
+        return this;
+    }
+
+    /**
+     * Gets the latest time this record updated with pd Prefix.
+     *
+     * @return the last time received DHCP packet provide pd Prefix
+     */
+    public long getLastPdUpdate() {
+        return lastPdUpdate;
+    }
+
+    /**
+     * Updates the update time of this record is given pd Prefix.
+     *
+     * @return the DHCP record
+     */
+    public DhcpRecord updateLastPdUpdate() {
+        lastPdUpdate = System.currentTimeMillis();
+        return this;
+    }
+
+    /**
+     * Gets the IP Address preferred time for this record.
+     *
+     * @return the preferred lease time for this ip address
+     */
+    public long addrPrefTime() {
+        return addrPrefTime;
+    }
+
+    /**
+     * Updates the IP Address preferred time of this record.
+     *
+     * @param prefTime preferred liftme
+     * @return the DHCP record
+     */
+    public DhcpRecord updateAddrPrefTime(long prefTime) {
+        addrPrefTime = prefTime;
+        return this;
+    }
+
+    /**
+     * Gets the PD Prefix preferred time for this record.
+     *
+     * @return the preferred lease time for this PD prefix
+     */
+    public long pdPrefTime() {
+        return pdPrefTime;
+    }
+
+    /**
+     * Updates the PD Prefix preferred time of this record.
+     *
+     * @param prefTime preferred liftme
+     * @return the DHCP record
+     */
+    public DhcpRecord updatePdPrefTime(long prefTime) {
+        pdPrefTime = prefTime;
+        return this;
+    }
+
+    /**
      * Indicated that the host is direct connected to the network or not.
      *
      * @return true if the host is directly connected to the network; false otherwise
@@ -301,6 +388,15 @@
     }
 
     /**
+     * Gets dhcp relay counters.
+     *
+     * @return the counter object
+     */
+    public DhcpRelayCounters getV6Counters() {
+        return v6Counters;
+    }
+
+    /**
      * Clone this DHCP record.
      *
      * @return the DHCP record which cloned
@@ -317,13 +413,20 @@
         newRecord.pdPrefix = pdPrefix;
         newRecord.ip6Status = ip6Status;
         newRecord.lastSeen = lastSeen;
+        newRecord.lastIp6Update = lastIp6Update;
+        newRecord.lastPdUpdate = lastPdUpdate;
+        newRecord.addrPrefTime = addrPrefTime;
+        newRecord.pdPrefTime = pdPrefTime;
+        newRecord.v6Counters = v6Counters;
+
         return newRecord;
     }
 
     @Override
     public int hashCode() {
         return Objects.hash(locations, macAddress, vlanId, ip4Address, ip4Status,
-                            nextHop, nextHopTemp, ip6Address, pdPrefix, ip6Status, lastSeen);
+                nextHop, nextHopTemp, ip6Address, pdPrefix, ip6Status, lastSeen,
+                lastIp6Update, lastPdUpdate, addrPrefTime, pdPrefTime, v6Counters);
     }
 
     @Override
@@ -346,7 +449,12 @@
                 Objects.equals(pdPrefix, that.pdPrefix) &&
                 Objects.equals(ip6Status, that.ip6Status) &&
                 Objects.equals(lastSeen, that.lastSeen) &&
-                Objects.equals(directlyConnected, that.directlyConnected);
+                Objects.equals(lastIp6Update, that.lastIp6Update) &&
+                Objects.equals(lastPdUpdate, that.lastPdUpdate) &&
+                Objects.equals(directlyConnected, that.directlyConnected) &&
+                Objects.equals(addrPrefTime, that.addrPrefTime) &&
+                Objects.equals(pdPrefTime, that.pdPrefTime) &&
+                Objects.equals(v6Counters, that.v6Counters);
     }
 
     @Override
@@ -363,7 +471,12 @@
                 .add("pdPrefix", pdPrefix)
                 .add("ip6State", ip6Status)
                 .add("lastSeen", lastSeen)
+                .add("lastIp6Update", lastIp6Update)
+                .add("lastPdUpdate", lastPdUpdate)
                 .add("directlyConnected", directlyConnected)
+                .add("addPrefTime", addrPrefTime)
+                .add("pdPrefTime", pdPrefTime)
+                .add("v6Counters", v6Counters)
                 .toString();
     }
 }
diff --git a/apps/dhcprelay/src/main/java/org/onosproject/dhcprelay/store/DhcpRelayCounters.java b/apps/dhcprelay/src/main/java/org/onosproject/dhcprelay/store/DhcpRelayCounters.java
new file mode 100644
index 0000000..2a69c21
--- /dev/null
+++ b/apps/dhcprelay/src/main/java/org/onosproject/dhcprelay/store/DhcpRelayCounters.java
@@ -0,0 +1,110 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * 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.dhcprelay.store;
+
+
+import com.google.common.collect.ImmutableSet;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.Map;
+import java.util.Objects;
+
+public class DhcpRelayCounters {
+    // common counters
+
+    // IpV6 specific counters
+    public static final String SOLICIT = "SOLICIT";
+    public static final String ADVERTISE = "ADVERTISE";
+    public static final String REQUEST = "REQUEST";
+    public static final String CONFIRM = "CONFIRM";
+    public static final String RENEW = "RENEW";
+    public static final String REBIND = "REBIND";
+    public static final String REPLY = "REPLY";
+    public static final String RELEASE = "RELEASE";
+    public static final String DECLINE = "DECLINE";
+    public static final String RECONFIGURE = "RECONFIGURE";
+    public static final String INFORMATION_REQUEST = "INFORMATION_REQUEST";
+    public static final String RELAY_FORW = "RELAY_FORW";
+    public static final String RELAY_REPL = "RELAY_REPL";
+
+    public static final String NO_LINKLOCAL_GW = "No link-local in Gateway";
+    public static final String NO_LINKLOCAL_FAIL = "No link-local in CLIENT_ID";
+    public static final String NO_CLIENTID_FAIL = "No CLIENT_ID Found";
+    public static final String SVR_CFG_FAIL = "Server Config Error";
+    public static final String OPTION_MISSING_FAIL = "Expected Option missing";
+    public static final String NO_MATCHING_INTF = "No matching Inteface";
+    public static final String NO_CLIENT_INTF_MAC = "No client interface mac";
+    public static final String NO_SERVER_INFO = "No Server info found";
+    public static final String NO_SERVER_IP6ADDR = "No Server ip6 addr found";
+
+    public static final String INVALID_PACKET = "Invalid Packet";
+
+    public static final Set<String> SUPPORTED_COUNTERS =
+            ImmutableSet.of(SOLICIT, ADVERTISE, REQUEST, CONFIRM, RENEW,
+                    REBIND, REPLY, RELEASE, DECLINE, RECONFIGURE,
+                    INFORMATION_REQUEST, RELAY_FORW, RELAY_REPL,
+                    NO_LINKLOCAL_GW, NO_LINKLOCAL_FAIL, NO_CLIENTID_FAIL, SVR_CFG_FAIL, OPTION_MISSING_FAIL,
+                    NO_MATCHING_INTF, NO_CLIENT_INTF_MAC, NO_SERVER_INFO, NO_SERVER_IP6ADDR,
+                    INVALID_PACKET);
+
+    // TODO Use AtomicInteger for the counters
+    private Map<String, Integer> countersMap = new ConcurrentHashMap<>();
+    public long lastUpdate;
+
+    public void resetCounters() {
+        countersMap.forEach((name, value) -> {
+            countersMap.put(name, 0);
+        });
+    }
+    public boolean incrementCounter(String name) {
+        boolean counterValid = false;
+        if (SUPPORTED_COUNTERS.contains(name)) {
+            Integer counter = countersMap.get(name);
+            if (counter != null) {
+                counter = counter + 1;
+                countersMap.put(name, counter);
+            } else {
+                // this is the first time
+                countersMap.put(name, 1);
+            }
+            lastUpdate = System.currentTimeMillis();
+            counterValid = true;
+        }
+        return counterValid;
+    }
+    public Map<String, Integer> getCounters() {
+        return countersMap;
+    }
+
+    @Override
+    public int hashCode() {
+        return Objects.hash(countersMap, lastUpdate);
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj) {
+            return true;
+        }
+        if (!(obj instanceof DhcpRelayCounters)) {
+            return false;
+        }
+        DhcpRelayCounters that = (DhcpRelayCounters) obj;
+        return Objects.equals(countersMap, that.countersMap) &&
+                Objects.equals(lastUpdate, that.lastUpdate);
+    }
+}
diff --git a/apps/dhcprelay/src/main/java/org/onosproject/dhcprelay/store/DhcpRelayCountersStore.java b/apps/dhcprelay/src/main/java/org/onosproject/dhcprelay/store/DhcpRelayCountersStore.java
new file mode 100644
index 0000000..3534871
--- /dev/null
+++ b/apps/dhcprelay/src/main/java/org/onosproject/dhcprelay/store/DhcpRelayCountersStore.java
@@ -0,0 +1,65 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * 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.dhcprelay.store;
+
+
+import java.util.Optional;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * Stores DHCP Relay Counters records.
+ */
+public interface DhcpRelayCountersStore {
+
+    /**
+     * Creates or updates DHCP record for specific host id (mac + vlan).
+     *
+     * @param counterClass class of counters (direct, indirect, global)
+     * @param counterName name of counter
+     */
+    void incrementCounter(String counterClass, String counterName);
+
+    /**
+     * Gets the DHCP counter record for a given counter class.
+     *
+     * @param counterClass the class of counters (direct, indirect, global)
+     * @return the DHCP counter record for a given counter class; empty if record not exists
+     */
+    Optional<DhcpRelayCounters> getCounters(String counterClass);
+
+    /**
+     * Gets all classes of DHCP counters record from store.
+     *
+     * @return all classes of DHCP counters records from store
+     */
+    Set<Map.Entry<String, DhcpRelayCounters>> getAllCounters();
+
+    /**
+     * Resets counter value for a given counter class.
+     *
+     * @param counterClass the class of counters (direct, indirect, global)
+     */
+    void resetCounters(String counterClass);
+
+    /**
+     * Resets counter value for a all counter classes.
+     *
+     */
+    void resetAllCounters();
+
+}
diff --git a/apps/dhcprelay/src/main/java/org/onosproject/dhcprelay/store/DistributedDhcpRelayCountersStore.java b/apps/dhcprelay/src/main/java/org/onosproject/dhcprelay/store/DistributedDhcpRelayCountersStore.java
new file mode 100644
index 0000000..4b7b26c
--- /dev/null
+++ b/apps/dhcprelay/src/main/java/org/onosproject/dhcprelay/store/DistributedDhcpRelayCountersStore.java
@@ -0,0 +1,130 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * 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.dhcprelay.store;
+
+import org.apache.felix.scr.annotations.Activate;
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Deactivate;
+import org.apache.felix.scr.annotations.Reference;
+import org.apache.felix.scr.annotations.ReferenceCardinality;
+import org.apache.felix.scr.annotations.Service;
+
+import org.onlab.util.KryoNamespace;
+import org.onosproject.core.ApplicationId;
+import org.onosproject.core.CoreService;
+import org.onosproject.store.service.ConsistentMap;
+import org.onosproject.store.service.Serializer;
+import org.onosproject.store.service.StorageService;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.onosproject.store.serializers.KryoNamespaces;
+
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import org.onosproject.store.service.Versioned;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+@Component(immediate = true)
+@Service
+public class DistributedDhcpRelayCountersStore implements DhcpRelayCountersStore {
+    private static final KryoNamespace.Builder APP_KYRO = KryoNamespace.newBuilder()
+            .register(KryoNamespaces.API)
+            .register(DhcpRelayCounters.class);
+
+    private Logger log = LoggerFactory.getLogger(getClass());
+    private ConsistentMap<String, DhcpRelayCounters> counters;
+
+    @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+    protected StorageService storageService;
+
+    @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+    protected CoreService coreService;
+
+
+    @Activate
+    protected void activated() {
+        ApplicationId appId = coreService.getAppId("org.onosproject.Dhcp6HandlerImpl");
+        counters = storageService.<String, DhcpRelayCounters>consistentMapBuilder()
+                .withSerializer(Serializer.using(APP_KYRO.build()))
+                .withName("Dhcp-Relay-Counters")
+                .withApplicationId(appId)
+                .withPurgeOnUninstall()
+                .build();
+    }
+
+    @Deactivate
+    protected void deactivated() {
+        counters.destroy().join();
+    }
+    @Override
+    public void incrementCounter(String coutnerClass, String counterName) {
+        DhcpRelayCounters countersRecord;
+
+        Versioned<DhcpRelayCounters> vCounters = counters.get(coutnerClass);
+        if (vCounters == null) {
+            countersRecord = new DhcpRelayCounters();
+        } else {
+            countersRecord = vCounters.value();
+        }
+        countersRecord.incrementCounter(counterName);
+        counters.put(coutnerClass, countersRecord);
+    }
+
+    @Override
+    public Set<Map.Entry<String, DhcpRelayCounters>> getAllCounters() {
+        final Set<Map.Entry<String, DhcpRelayCounters>> result =
+                new HashSet<Map.Entry<String, DhcpRelayCounters>>();
+        Set<Map.Entry<String, Versioned<DhcpRelayCounters>>> tmpCounters = counters.entrySet();
+        tmpCounters.forEach(entry -> {
+            String key = entry.getKey();
+            DhcpRelayCounters value = entry.getValue().value();
+            ConcurrentHashMap<String, DhcpRelayCounters> newMap = new ConcurrentHashMap();
+            newMap.put(key, value);
+
+            for (Map.Entry m: newMap.entrySet()) {
+                result.add(m);
+            }
+        });
+        return  result;
+    }
+    @Override
+    public Optional<DhcpRelayCounters> getCounters(String counterClass) {
+        DhcpRelayCounters countersRecord;
+        checkNotNull(counterClass, "counter class can't be null");
+        Versioned<DhcpRelayCounters> vCounters = counters.get(counterClass);
+        if (vCounters == null) {
+            return Optional.empty();
+        }
+        return Optional.of(vCounters.value());
+    }
+    @Override
+    public void resetAllCounters() {
+        counters.clear();
+    }
+
+    @Override
+    public void resetCounters(String counterClass) {
+        checkNotNull(counterClass, "counter class can't be null");
+        DhcpRelayCounters countersRecord = counters.get(counterClass).value();
+        countersRecord.resetCounters();
+        counters.put(counterClass, countersRecord);
+    }
+
+}
diff --git a/apps/dhcprelay/src/main/java/org/onosproject/dhcprelay/store/DistributedDhcpRelayStore.java b/apps/dhcprelay/src/main/java/org/onosproject/dhcprelay/store/DistributedDhcpRelayStore.java
index 38c0580..884d9cc 100644
--- a/apps/dhcprelay/src/main/java/org/onosproject/dhcprelay/store/DistributedDhcpRelayStore.java
+++ b/apps/dhcprelay/src/main/java/org/onosproject/dhcprelay/store/DistributedDhcpRelayStore.java
@@ -52,6 +52,7 @@
             .register(DhcpRecord.class)
             .register(DHCP.MsgType.class)
             .register(DHCP6.MsgType.class)
+            .register(DhcpRelayCounters.class)
             .build();
 
     private Logger log = getLogger(getClass());
diff --git a/apps/dhcprelay/src/main/resources/OSGI-INF/blueprint/shell-config.xml b/apps/dhcprelay/src/main/resources/OSGI-INF/blueprint/shell-config.xml
index b178195..c0a4b6f 100644
--- a/apps/dhcprelay/src/main/resources/OSGI-INF/blueprint/shell-config.xml
+++ b/apps/dhcprelay/src/main/resources/OSGI-INF/blueprint/shell-config.xml
@@ -18,6 +18,10 @@
     <command-bundle xmlns="http://karaf.apache.org/xmlns/shell/v1.1.0">
         <command>
             <action class="org.onosproject.dhcprelay.cli.DhcpRelayCommand"/>
+            <completers>
+                <ref component-id="dhcpRelayCounterCompleter"/>
+                <ref component-id="dhcpRelayResetCompleter"/>
+            </completers>
         </command>
         <command>
             <action class="org.onosproject.dhcprelay.cli.DhcpFpmRoutesCommand"/>
@@ -28,5 +32,13 @@
         <command>
             <action class="org.onosproject.dhcprelay.cli.DhcpFpmDeleteCommand"/>
         </command>
+        <command>
+            <action class="org.onosproject.dhcprelay.cli.DhcpRelayAggCountersCommand"/>
+            <completers>
+                <ref component-id="dhcpRelayResetCompleter"/>
+            </completers>
+        </command>
     </command-bundle>
+    <bean id="dhcpRelayCounterCompleter" class="org.onosproject.dhcprelay.cli.DhcpRelayCounterCompleter"/>
+    <bean id="dhcpRelayResetCompleter" class="org.onosproject.dhcprelay.cli.DhcpRelayResetCompleter"/>
 </blueprint>
diff --git a/apps/dhcprelay/src/test/java/org/onosproject/dhcprelay/DhcpRelayManagerTest.java b/apps/dhcprelay/src/test/java/org/onosproject/dhcprelay/DhcpRelayManagerTest.java
index 018c450..65518ee 100644
--- a/apps/dhcprelay/src/test/java/org/onosproject/dhcprelay/DhcpRelayManagerTest.java
+++ b/apps/dhcprelay/src/test/java/org/onosproject/dhcprelay/DhcpRelayManagerTest.java
@@ -56,6 +56,11 @@
 import org.onlab.packet.dhcp.Dhcp6Option;
 import org.onlab.packet.dhcp.Dhcp6ClientIdOption;
 import org.onlab.packet.dhcp.Dhcp6Duid;
+import org.onosproject.dhcprelay.store.DhcpRelayStore;
+import org.onosproject.dhcprelay.store.DhcpRecord;
+import org.onosproject.dhcprelay.store.DhcpRelayStoreEvent;
+import org.onosproject.dhcprelay.store.DhcpRelayCounters;
+import org.onosproject.dhcprelay.store.DhcpRelayCountersStore;
 import org.onosproject.net.ConnectPoint;
 import org.onosproject.TestApplicationId;
 import org.onosproject.cfg.ComponentConfigService;
@@ -65,9 +70,6 @@
 import org.onosproject.dhcprelay.config.DhcpServerConfig;
 import org.onosproject.dhcprelay.config.IgnoreDhcpConfig;
 import org.onosproject.dhcprelay.config.IndirectDhcpRelayConfig;
-import org.onosproject.dhcprelay.store.DhcpRecord;
-import org.onosproject.dhcprelay.store.DhcpRelayStore;
-import org.onosproject.dhcprelay.store.DhcpRelayStoreEvent;
 import org.onosproject.net.Device;
 import org.onosproject.net.DeviceId;
 import org.onosproject.net.behaviour.Pipeliner;
@@ -255,6 +257,7 @@
     private MockPacketService packetService;
     private MockRouteStore mockRouteStore;
     private MockDhcpRelayStore mockDhcpRelayStore;
+    private MockDhcpRelayCountersStore mockDhcpRelayCountersStore;
     private HostProviderService mockHostProviderService;
     private FlowObjectiveService flowObjectiveService;
     private DeviceService deviceService;
@@ -324,9 +327,11 @@
 
         mockRouteStore = new MockRouteStore();
         mockDhcpRelayStore = new MockDhcpRelayStore();
-        manager.dhcpRelayStore = mockDhcpRelayStore;
-        manager.deviceService = deviceService;
+        mockDhcpRelayCountersStore = new MockDhcpRelayCountersStore();
 
+        manager.dhcpRelayStore = mockDhcpRelayStore;
+
+        manager.deviceService = deviceService;
 
         manager.interfaceService = new MockInterfaceService();
         flowObjectiveService = EasyMock.niceMock(FlowObjectiveService.class);
@@ -346,6 +351,7 @@
 
         v6Handler = new Dhcp6HandlerImpl();
         v6Handler.dhcpRelayStore = mockDhcpRelayStore;
+        v6Handler.dhcpRelayCountersStore = mockDhcpRelayCountersStore;
         v6Handler.hostService = manager.hostService;
         v6Handler.interfaceService = manager.interfaceService;
         v6Handler.packetService = manager.packetService;
@@ -1004,6 +1010,48 @@
         }
     }
 
+    private class MockDhcpRelayCountersStore implements DhcpRelayCountersStore {
+        private Map<String, DhcpRelayCounters> counters = Maps.newHashMap();
+
+        public void incrementCounter(String coutnerClass, String counterName) {
+            DhcpRelayCounters countersRecord;
+
+            DhcpRelayCounters classCounters = counters.get(coutnerClass);
+            if (classCounters == null) {
+                classCounters = new DhcpRelayCounters();
+            }
+            classCounters.incrementCounter(counterName);
+            counters.put(coutnerClass, classCounters);
+        }
+
+        @Override
+        public Set<Map.Entry<String, DhcpRelayCounters>> getAllCounters() {
+            return counters.entrySet();
+        }
+
+        @Override
+        public Optional<DhcpRelayCounters> getCounters(String counterClass) {
+            DhcpRelayCounters classCounters = counters.get(counterClass);
+            if (classCounters == null) {
+                return Optional.empty();
+            }
+            return Optional.of(classCounters);
+        }
+
+        @Override
+        public void resetAllCounters() {
+            counters.clear();
+        }
+
+        @Override
+        public void resetCounters(String counterClass) {
+            DhcpRelayCounters classCounters = counters.get(counterClass);
+            classCounters.resetCounters();
+            counters.put(counterClass, classCounters);
+        }
+    }
+
+
     private class MockPacketService extends PacketServiceAdapter {
         Set<PacketProcessor> packetProcessors = Sets.newHashSet();
         OutboundPacket emittedPacket;
diff --git a/apps/dhcprelay/src/test/java/org/onosproject/dhcprelay/store/DhcpRecordTest.java b/apps/dhcprelay/src/test/java/org/onosproject/dhcprelay/store/DhcpRecordTest.java
index ec6ad5c..7aaf65b 100644
--- a/apps/dhcprelay/src/test/java/org/onosproject/dhcprelay/store/DhcpRecordTest.java
+++ b/apps/dhcprelay/src/test/java/org/onosproject/dhcprelay/store/DhcpRecordTest.java
@@ -86,6 +86,12 @@
 
         TestUtils.setField(record, "lastSeen", 0);
         TestUtils.setField(record2, "lastSeen", 0);
+        TestUtils.setField(record, "addrPrefTime", 0);
+        TestUtils.setField(record2, "addrPrefTime", 0);
+        TestUtils.setField(record, "pdPrefTime", 0);
+        TestUtils.setField(record2, "pdPrefTime", 0);
+        TestUtils.setField(record, "v6Counter", null);
+        TestUtils.setField(record2, "v6Counter", null);
 
         assertThat(record, equalTo(record2));
         assertThat(record.hashCode(), equalTo(record2.hashCode()));