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
8 package org.opendaylight.vpnservice.fcapsapp.performancecounter;
10 import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketProcessingListener;
11 import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketReceived;
12 import org.slf4j.Logger;
13 import org.slf4j.LoggerFactory;
15 import java.util.HashMap;
16 import java.util.concurrent.ConcurrentHashMap;
17 import java.util.concurrent.atomic.AtomicLong;
19 public class PacketInCounterHandler implements PacketProcessingListener {
20 private static final Logger LOG = LoggerFactory.getLogger(PacketInCounterHandler.class);
21 private static ConcurrentHashMap<String,AtomicLong> ingressPacketMap = new ConcurrentHashMap<>();
22 private static HashMap<String,String> packetInMap = new HashMap<>();
23 private static final Integer FIRST_VALUE = 1;
24 private static final PMAgent pmAgent =new PMAgent();
27 public void onPacketReceived(PacketReceived notification) {
29 String nodeListEgressStr, nodekey;
30 LOG.debug("Ingress packet notification received");
32 if (notification.getIngress() == null) {
33 if (LOG.isWarnEnabled()) {
34 LOG.warn("invalid PacketReceived notification");
38 dpnId = getDpnId(notification.getIngress().getValue().toString());
39 } catch (Exception e) {
40 if (LOG.isWarnEnabled()) {
41 LOG.warn("DPN Parsing failed in onPacketReceived");
45 nodeListEgressStr = "dpnId_" + dpnId + "_InjectedOFMessagesSent";
46 nodekey = "InjectedOFMessagesSent:" + nodeListEgressStr;
47 if (ingressPacketMap.containsKey(dpnId)) {
48 ingressPacketMap.put(dpnId,new AtomicLong(ingressPacketMap.get(dpnId).incrementAndGet()));
49 packetInMap.put(nodekey,""+ingressPacketMap.get(dpnId));
51 ingressPacketMap.put(dpnId, new AtomicLong(FIRST_VALUE));
52 packetInMap.put(nodekey,""+FIRST_VALUE);
56 LOG.error("DpnId is null");
59 private void connectToPMAgent(){
60 pmAgent.sendPacketInCounterUpdate(packetInMap);
63 * Method to extract DpnId
65 public static String getDpnId(String id) {
66 String[] nodeNo = id.split(":");
67 String[] dpnId = nodeNo[1].split("]");
71 public void nodeRemovedNotification(String dpnId){
72 String nodeListEgressStr, nodekey;
74 dpnId = dpnId.split(":")[1];
75 LOG.debug("Dpnvalue Id {}",dpnId);
76 if (ingressPacketMap.containsKey(dpnId)) {
77 nodeListEgressStr = "dpnId_" + dpnId + "_InjectedOFMessagesSent";
78 nodekey = "InjectedOFMessagesSent:" + nodeListEgressStr;
80 ingressPacketMap.remove(dpnId);
81 packetInMap.remove(nodekey);
84 LOG.debug("Node {} Removed for PacketIn counter", dpnId);
87 LOG.error("DpnId is null upon nodeRemovedNotification");