These two need to be in genius, not vpnservice or netvirt.
Change-Id: Ia9b186dea4a06efb3febcd9d8a219b44915a6d18
Signed-off-by: Vishal Thapar <vishal.thapar@ericsson.com>
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+Copyright (c) 2015 Ericsson India Global Services Pvt Ltd. 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.genius</groupId>
+ <artifactId>config-parent</artifactId>
+ <version>0.1.0-SNAPSHOT</version>
+ <relativePath>../../commons/config-parent</relativePath>
+ </parent>
+
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.opendaylight.genius</groupId>
+ <artifactId>fcapsapplication-impl</artifactId>
+ <version>${genius.version}</version>
+ <packaging>bundle</packaging>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.opendaylight.controller</groupId>
+ <artifactId>sal-binding-broker-impl</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.controller</groupId>
+ <artifactId>config-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.controller</groupId>
+ <artifactId>sal-binding-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.controller</groupId>
+ <artifactId>sal-binding-config</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>fcapsapplication-jmxapi</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.openflowplugin.model</groupId>
+ <artifactId>model-flow-service</artifactId>
+ <version>${openflowplugin.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.openflowplugin</groupId>
+ <artifactId>openflowplugin-common</artifactId>
+ <version>${openflowplugin.version}</version>
+ </dependency>
+ </dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.opendaylight.yangtools</groupId>
+ <artifactId>yang-maven-plugin</artifactId>
+ </plugin>
+
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>build-helper-maven-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>attach-artifacts</id>
+ <goals>
+ <goal>attach-artifact</goal>
+ </goals>
+ <phase>package</phase>
+ <configuration>
+ <artifacts>
+ <artifact>
+ <file>${project.build.directory}/classes/initial/73-fcaps-app.xml</file>
+ <type>xml</type>
+ <classifier>config</classifier>
+ </artifact>
+ </artifacts>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+</project>
--- /dev/null
+/*
+ * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. 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.genius.fcapsapp;
+
+import com.google.common.base.Preconditions;
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier;
+import org.opendaylight.controller.md.sal.binding.api.NotificationService;
+import org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipService;
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.genius.fcapsapp.performancecounter.FlowNodeConnectorInventoryTranslatorImpl;
+import org.opendaylight.genius.fcapsapp.alarm.AlarmAgent;
+import org.opendaylight.genius.fcapsapp.performancecounter.PMAgent;
+import org.opendaylight.genius.fcapsapp.performancecounter.PacketInCounterHandler;
+import org.opendaylight.genius.fcapsapp.portinfo.PortNameMapping;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class FcapsProvider implements AutoCloseable {
+
+ public static Logger s_logger = LoggerFactory.getLogger(FcapsProvider.class);
+ private final DataBroker dataService;
+ private final NotificationService notificationProviderService;
+ private final EntityOwnershipService entityOwnershipService;
+ private FlowNodeConnectorInventoryTranslatorImpl flowNodeConnectorInventoryTranslatorImpl;
+ private PacketInCounterHandler packetInCounterHandler;
+ private NodeEventListener<FlowCapableNode> nodeNodeEventListener;
+ private final AlarmAgent alarmAgent;
+ private final PMAgent pmAgent;
+
+ /**
+ * Contructor sets the services
+ * @param dataBroker instance of databroker
+ * @param notificationService instance of notificationservice
+ * @param eos instance of EntityOwnershipService
+ */
+ public FcapsProvider(DataBroker dataBroker,NotificationService notificationService,
+ final EntityOwnershipService eos) {
+ this.dataService = Preconditions.checkNotNull(dataBroker, "DataBroker can not be null!");
+ s_logger.info("FcapsProvider dataBroket is set");
+
+ this.notificationProviderService = Preconditions.checkNotNull(notificationService,
+ "notificationService can not be null!");
+ s_logger.info("FcapsProvider notificationProviderService is set");
+
+ this.entityOwnershipService = Preconditions.checkNotNull(eos, "EntityOwnership service can not be null");
+ s_logger.info("FcapsProvider entityOwnershipService is set");
+
+ alarmAgent = new AlarmAgent();
+ pmAgent = new PMAgent();
+
+ alarmAgent.registerAlarmMbean();
+
+ pmAgent.registerMbeanForEFS();
+ pmAgent.registerMbeanForPorts();
+ pmAgent.registerMbeanForPacketIn();
+ PortNameMapping.registerPortMappingBean();
+
+ nodeNodeEventListener = new NodeEventListener<>(entityOwnershipService);
+ registerListener(dataService);
+ flowNodeConnectorInventoryTranslatorImpl = new
+ FlowNodeConnectorInventoryTranslatorImpl(dataService,entityOwnershipService);
+ packetInCounterHandler = new PacketInCounterHandler();
+ notificationProviderService.registerNotificationListener(packetInCounterHandler);
+ }
+
+ private void registerListener(DataBroker dataBroker) {
+ final DataTreeIdentifier<FlowCapableNode> treeId =
+ new DataTreeIdentifier<>(LogicalDatastoreType.OPERATIONAL, getWildCardPath());
+ try {
+ dataBroker.registerDataTreeChangeListener(treeId, nodeNodeEventListener);
+ } catch (Exception e) {
+ s_logger.error("Registeration failed on DataTreeChangeListener {}",e);
+ }
+ }
+
+ private InstanceIdentifier<FlowCapableNode> getWildCardPath() {
+ return InstanceIdentifier.create(Nodes.class)
+ .child(Node.class)
+ .augmentation(FlowCapableNode.class);
+ }
+
+ @Override
+ public void close() throws Exception {
+
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. 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.genius.fcapsapp;
+
+import com.google.common.base.Optional;
+import org.opendaylight.controller.md.sal.binding.api.*;
+
+import org.opendaylight.controller.md.sal.common.api.clustering.Entity;
+import org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipService;
+import org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipState;
+import org.opendaylight.genius.fcapsapp.alarm.AlarmAgent;
+import org.opendaylight.genius.fcapsapp.performancecounter.NodeUpdateCounter;
+import org.opendaylight.genius.fcapsapp.performancecounter.PacketInCounterHandler;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
+import org.opendaylight.yangtools.yang.binding.DataObject;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import java.net.InetAddress;
+import java.util.Collection;
+
+public class NodeEventListener<D extends DataObject> implements ClusteredDataTreeChangeListener<D>,AutoCloseable {
+ private static final Logger LOG = LoggerFactory.getLogger(NodeEventListener.class);
+ public static final AlarmAgent alarmAgent = new AlarmAgent();
+ public static final NodeUpdateCounter nodeUpdateCounter = new NodeUpdateCounter();
+ public static final PacketInCounterHandler packetInCounter = new PacketInCounterHandler();
+ private final EntityOwnershipService entityOwnershipService;
+
+ /**
+ * Construcor set EntityOwnershipService
+ * @param eos
+ */
+ public NodeEventListener(final EntityOwnershipService eos) {
+ this.entityOwnershipService = eos;
+ }
+
+ @Override
+ public void onDataTreeChanged(Collection<DataTreeModification<D>> changes) {
+ for (DataTreeModification<D> change : changes) {
+ final InstanceIdentifier<D> key = change.getRootPath().getRootIdentifier();
+ final DataObjectModification<D> mod = change.getRootNode();
+ final InstanceIdentifier<FlowCapableNode> nodeConnIdent =
+ key.firstIdentifierOf(FlowCapableNode.class);
+ String nodeId = null, hostName = null;
+ try {
+ nodeId = getDpnId(String.valueOf(nodeConnIdent.firstKeyOf(Node.class).getId()));
+ } catch (Exception ex) {
+ LOG.error("Dpn retrieval failed");
+ return;
+ }
+
+ hostName = System.getenv().get("HOSTNAME");
+ if (hostName == null) {
+ try {
+ hostName = InetAddress.getLocalHost().getHostName();
+ } catch (Exception e) {
+ LOG.error("Retrieving hostName failed {}", e);
+ }
+ }
+ LOG.debug("retrieved hostname {}", hostName);
+ if (nodeId != null) {
+ switch (mod.getModificationType()) {
+ case DELETE:
+ LOG.debug("NodeRemoved {} notification is received on host {}", nodeId, hostName);
+ if (nodeUpdateCounter.isDpnConnectedLocal(nodeId)) {
+ alarmAgent.raiseControlPathAlarm(nodeId, hostName);
+ nodeUpdateCounter.nodeRemovedNotification(nodeId, hostName);
+ }
+ packetInCounter.nodeRemovedNotification(nodeId);
+ break;
+ case SUBTREE_MODIFIED:
+ if (isNodeOwner(nodeId)) {
+ LOG.debug("NodeUpdated {} notification is received", nodeId);
+ } else {
+ LOG.debug("UPDATE: Node {} is not connected to host {}", nodeId, hostName);
+ }
+ break;
+ case WRITE:
+ if (mod.getDataBefore() == null) {
+ if (isNodeOwner(nodeId)) {
+ LOG.debug("NodeAdded {} notification is received on host {}", nodeId, hostName);
+ alarmAgent.clearControlPathAlarm(nodeId);
+ nodeUpdateCounter.nodeAddedNotification(nodeId, hostName);
+ } else {
+ LOG.debug("ADD: Node {} is not connected to host {}", nodeId, hostName);
+ }
+ }
+ break;
+ default:
+ LOG.debug("Unhandled Modification type {}", mod.getModificationType());
+ throw new IllegalArgumentException("Unhandled modification type " + mod.getModificationType());
+
+ }
+ } else {
+ LOG.error("DpnID is null");
+ }
+ }
+ }
+
+ private String getDpnId(String node) {
+ //Uri [_value=openflow:1]
+ String temp[] = node.split("=");
+ String dpnId = temp[1].substring(0,temp[1].length() - 1);
+ return dpnId;
+
+ }
+
+ /**
+ * Method checks if *this* instance of controller is owner of
+ * the given openflow node.
+ * @param nodeId DpnId
+ * @return True if owner, else false
+ */
+ public boolean isNodeOwner(String nodeId) {
+ Entity entity = new Entity("openflow", nodeId);
+ Optional<EntityOwnershipState> entityState = this.entityOwnershipService.getOwnershipState(entity);
+ if (entityState.isPresent()) {
+ return entityState.get().isOwner();
+ }
+ return false;
+ }
+
+ @Override
+ public void close() throws Exception {
+ }
+}
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. 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.genius.fcapsapp.alarm;
+
+import org.opendaylight.genius.fcapsappjmx.ControlPathFailureAlarm;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.management.MBeanServer;
+import javax.management.MalformedObjectNameException;
+import javax.management.ObjectName;
+import java.lang.management.ManagementFactory;
+
+public class AlarmAgent {
+ static Logger s_logger = LoggerFactory.getLogger(AlarmAgent.class);
+ private MBeanServer mbs = null;
+ private ObjectName alarmName = null;
+ private static final String BEANNAME = "SDNC.FM:name=ControlPathFailureAlarmBean";
+ private static ControlPathFailureAlarm alarmBean = new ControlPathFailureAlarm();
+
+ /**
+ * constructor get the instance of platform MBeanServer
+ */
+ public AlarmAgent() {
+ mbs = ManagementFactory.getPlatformMBeanServer();
+ try {
+ alarmName = new ObjectName(BEANNAME);
+ } catch (MalformedObjectNameException e) {
+ s_logger.error("ObjectName instance creation failed for BEANAME {} : {}",BEANNAME, e);
+ }
+ }
+
+ /**
+ * Method registers alarm mbean in platform MbeanServer
+ */
+ public void registerAlarmMbean() {
+ try {
+ if (!mbs.isRegistered(alarmName)) {
+ mbs.registerMBean(alarmBean, alarmName);
+ s_logger.info("Registered Mbean {} successfully", alarmName);
+ }
+ } catch (Exception e) {
+ s_logger.error("Registeration failed for Mbean {} :{}", alarmName,e);
+ }
+ }
+
+ /**
+ * Method invoke raise alarm JMX API in platform MbeanServer with alarm details
+ * @param alarmId
+ * alarm to be raised
+ * @param text
+ * Additional details describing about the alarm on which dpnId and hostname
+ * @param src
+ * Source of the alarm ex: dpnId=openflow:1
+ * the source node that caused this alarm
+ */
+ public void invokeFMraisemethod(String alarmId,String text,String src) {
+ try {
+ mbs.invoke(alarmName, "raiseAlarm", new Object[]{alarmId, text, src},
+ new String[]{String.class.getName(), String.class.getName(), String.class.getName()});
+ s_logger.debug("Invoked raiseAlarm function for Mbean {} with source {}", BEANNAME, src);
+ } catch (Exception e) {
+ s_logger.error("Invoking raiseAlarm method failed for Mbean {} :{}", alarmName,e);
+ }
+ }
+
+ /**
+ * Method invoke clear alarm JMX API in platform MbeanServer with alarm details
+ * @param alarmId
+ * alarm to be cleared
+ * @param text
+ * Additional details describing about the alarm on which dpnId and hostname
+ * @param src
+ * Source of the alarm ex: dpn=openflow:1
+ * the source node that caused this alarm
+ */
+ public void invokeFMclearmethod(String alarmId,String text,String src) {
+ try {
+ mbs.invoke(alarmName, "clearAlarm", new Object[]{alarmId, text, src},
+ new String[]{String.class.getName(), String.class.getName(), String.class.getName()});
+ s_logger.debug("Invoked clearAlarm function for Mbean {} with source {}",BEANNAME,src);
+ } catch (Exception e) {
+ s_logger.error("Invoking clearAlarm method failed for Mbean {} :{}", alarmName,e);
+ }
+ }
+
+ /**
+ * Method gets the alarm details to be raised and construct the alarm objects
+ * @param nodeId
+ * Source of the alarm dpnId
+ * @param host
+ * Controller hostname
+ */
+ public void raiseControlPathAlarm(String nodeId,String host) {
+ StringBuilder alarmText = new StringBuilder();
+ StringBuilder source = new StringBuilder();
+
+ if (host != null) {
+ try {
+ alarmText.append("OF Switch ").append(nodeId).append(" lost heart beat communication with controller ")
+ .append(host);
+ source.append("Dpn=").append(nodeId);
+
+ s_logger.debug("Raising ControlPathConnectionFailure alarm... alarmText {} source {} ", alarmText, source);
+ //Invokes JMX raiseAlarm method
+ invokeFMraisemethod("ControlPathConnectionFailure", alarmText.toString(), source.toString());
+ } catch (Exception e) {
+ s_logger.error("Exception before invoking raise method in jmx {}", e);
+ }
+ } else {
+ s_logger.error("Received hostname is null");
+ }
+ }
+
+ /**
+ * Method gets the alarm details to be cleared and construct the alarm objects
+ * @param nodeId
+ * Source of the alarm dpnId
+ */
+ public void clearControlPathAlarm(String nodeId) {
+ StringBuilder source = new StringBuilder();
+
+ try {
+ source.append("Dpn=").append(nodeId);
+ s_logger.debug("Clearing ControlPathConnectionFailure alarm of source {} ", source);
+ //Invokes JMX clearAlarm method
+ invokeFMclearmethod("ControlPathConnectionFailure", "OF Switch gained communication with controller",
+ source.toString());
+ } catch (Exception e) {
+ s_logger.error("Exception before invoking clear method jmx {}", e);
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. 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.genius.fcapsapp.performancecounter;
+
+import org.opendaylight.controller.md.sal.binding.api.ClusteredDataTreeChangeListener;
+import org.opendaylight.controller.md.sal.binding.api.DataTreeChangeListener;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeConnector;
+import org.opendaylight.yangtools.yang.binding.DataObject;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+public interface FlowCapableNodeConnectorCommitter <D extends DataObject> extends AutoCloseable, ClusteredDataTreeChangeListener<D> {
+ /**
+ * Method removes DataObject which is identified by InstanceIdentifier
+ * from device.
+ *
+ * @param identifier - the whole path to DataObject
+ * @param del - DataObject for removing
+ * @param nodeConnIdent NodeConnector InstanceIdentifier
+ */
+ void remove(InstanceIdentifier<D> identifier, D del,
+ InstanceIdentifier<FlowCapableNodeConnector> nodeConnIdent);
+
+ /**
+ * Method updates the original DataObject to the update DataObject
+ * in device. Both are identified by same InstanceIdentifier
+ *
+ * @param identifier - the whole path to DataObject
+ * @param original - original DataObject (for update)
+ * @param update - changed DataObject (contain updates)
+ * @param nodeConnIdent NodeConnector InstanceIdentifier
+ */
+ void update(InstanceIdentifier<D> identifier, D original, D update,
+ InstanceIdentifier<FlowCapableNodeConnector> nodeConnIdent);
+
+ /**
+ * Method adds the DataObject which is identified by InstanceIdentifier
+ * to device.
+ *
+ * @param identifier - the whole path to new DataObject
+ * @param add - new DataObject
+ * @param nodeConnIdent NodeConnector InstanceIdentifier
+ */
+ void add(InstanceIdentifier<D> identifier, D add,
+ InstanceIdentifier<FlowCapableNodeConnector> nodeConnIdent);
+
+}
+
--- /dev/null
+/*
+ * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. 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.genius.fcapsapp.performancecounter;
+
+import com.google.common.base.Optional;
+import com.google.common.base.Preconditions;
+import com.google.common.collect.*;
+import org.opendaylight.controller.md.sal.binding.api.*;
+import org.opendaylight.controller.md.sal.common.api.clustering.Entity;
+import org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipService;
+import org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipState;
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.genius.fcapsapp.portinfo.PortNameMapping;
+import org.opendaylight.openflowplugin.common.wait.SimpleTaskRetryLooper;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeConnector;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
+import org.opendaylight.yangtools.concepts.ListenerRegistration;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import java.lang.String;
+import java.util.HashMap;
+import java.util.Collection;
+import java.util.concurrent.Callable;
+
+public class FlowNodeConnectorInventoryTranslatorImpl extends NodeConnectorEventListener<FlowCapableNodeConnector> {
+ public static final int STARTUP_LOOP_TICK = 500;
+ public static final int STARTUP_LOOP_MAX_RETRIES = 8;
+ private static final Logger LOG = LoggerFactory.getLogger(FlowNodeConnectorInventoryTranslatorImpl.class);
+ private final EntityOwnershipService entityOwnershipService;
+
+ private ListenerRegistration<FlowNodeConnectorInventoryTranslatorImpl> dataTreeChangeListenerRegistration;
+
+ public static final String SEPARATOR = ":";
+ private static final PMAgent pmAgent = new PMAgent();
+
+ private static final InstanceIdentifier<FlowCapableNodeConnector> II_TO_FLOW_CAPABLE_NODE_CONNECTOR
+ = InstanceIdentifier.builder(Nodes.class)
+ .child(Node.class)
+ .child(NodeConnector.class)
+ .augmentation(FlowCapableNodeConnector.class)
+ .build();
+
+ private static Multimap<Long,String> dpnToPortMultiMap = Multimaps.synchronizedListMultimap(ArrayListMultimap.<Long,String>create());
+
+ private static HashMap<String, String> nodeConnectorCountermap = new HashMap<String, String>();
+
+ public FlowNodeConnectorInventoryTranslatorImpl(final DataBroker dataBroker,final EntityOwnershipService eos) {
+ super( FlowCapableNodeConnector.class);
+ Preconditions.checkNotNull(dataBroker, "DataBroker can not be null!");
+
+ entityOwnershipService = eos;
+ final DataTreeIdentifier<FlowCapableNodeConnector> treeId =
+ new DataTreeIdentifier<>(LogicalDatastoreType.OPERATIONAL, getWildCardPath());
+ try {
+ SimpleTaskRetryLooper looper = new SimpleTaskRetryLooper(STARTUP_LOOP_TICK,
+ STARTUP_LOOP_MAX_RETRIES);
+ dataTreeChangeListenerRegistration = looper.loopUntilNoException(new Callable<ListenerRegistration<FlowNodeConnectorInventoryTranslatorImpl>>() {
+ @Override
+ public ListenerRegistration<FlowNodeConnectorInventoryTranslatorImpl> call() throws Exception {
+ return dataBroker.registerDataTreeChangeListener(treeId, FlowNodeConnectorInventoryTranslatorImpl.this);
+ }
+ });
+ } catch (final Exception e) {
+ LOG.warn(" FlowNodeConnectorInventoryTranslatorImpl listener registration fail!");
+ LOG.debug("FlowNodeConnectorInventoryTranslatorImpl DataChange listener registration fail ..", e);
+ throw new IllegalStateException("FlowNodeConnectorInventoryTranslatorImpl startup fail! System needs restart.", e);
+ }
+ }
+
+
+ protected InstanceIdentifier<FlowCapableNodeConnector> getWildCardPath() {
+ return InstanceIdentifier.create(Nodes.class)
+ .child(Node.class)
+ .child(NodeConnector.class)
+ .augmentation(FlowCapableNodeConnector.class);
+ }
+
+ @Override
+ public void close() {
+ if (dataTreeChangeListenerRegistration != null) {
+ try {
+ dataTreeChangeListenerRegistration.close();
+ } catch (final Exception e) {
+ LOG.warn("Error by stop FRM FlowNodeConnectorInventoryTranslatorImpl: {}", e.getMessage());
+ LOG.debug("Error by stop FRM FlowNodeConnectorInventoryTranslatorImpl..", e);
+ }
+ dataTreeChangeListenerRegistration = null;
+ }
+ }
+ @Override
+ public void remove(InstanceIdentifier<FlowCapableNodeConnector> identifier, FlowCapableNodeConnector del, InstanceIdentifier<FlowCapableNodeConnector> nodeConnIdent) {
+ if(compareInstanceIdentifierTail(identifier,II_TO_FLOW_CAPABLE_NODE_CONNECTOR)) {
+ String sNodeConnectorIdentifier = getNodeConnectorId(String.valueOf(nodeConnIdent.firstKeyOf(NodeConnector.class).getId()));
+ long nDpId = getDpIdFromPortName(sNodeConnectorIdentifier);
+ if (dpnToPortMultiMap.containsKey(nDpId)) {
+ LOG.debug("Node Connector {} removed", sNodeConnectorIdentifier);
+ dpnToPortMultiMap.remove(nDpId, sNodeConnectorIdentifier);
+ sendNodeConnectorUpdation(nDpId);
+ PortNameMapping.updatePortMap("openflow:" + nDpId + ":" + del.getName(), sNodeConnectorIdentifier, "DELETE");
+ }
+ }
+ }
+
+ @Override
+ public void update(InstanceIdentifier<FlowCapableNodeConnector> identifier, FlowCapableNodeConnector original, FlowCapableNodeConnector update, InstanceIdentifier<FlowCapableNodeConnector> nodeConnIdent) {
+ if(compareInstanceIdentifierTail(identifier,II_TO_FLOW_CAPABLE_NODE_CONNECTOR)) {
+
+ //donot need to do anything as we are not considering updates here
+ String sNodeConnectorIdentifier = getNodeConnectorId(String.valueOf(nodeConnIdent.firstKeyOf(NodeConnector.class).getId()));
+ long nDpId = getDpIdFromPortName(sNodeConnectorIdentifier);
+ if (isNodeOwner(getNodeId(nDpId))) {
+ boolean original_portstatus = original.getConfiguration().isPORTDOWN();
+ boolean update_portstatus = update.getConfiguration().isPORTDOWN();
+
+ if (update_portstatus == true) {
+ //port has gone down
+ LOG.debug("Node Connector {} updated port is down", sNodeConnectorIdentifier);
+ } else if (original_portstatus == true) {
+ //port has come up
+ LOG.debug("Node Connector {} updated port is up", sNodeConnectorIdentifier);
+ }
+ }
+ }
+ }
+
+ @Override
+ public void add(InstanceIdentifier<FlowCapableNodeConnector> identifier, FlowCapableNodeConnector add, InstanceIdentifier<FlowCapableNodeConnector> nodeConnIdent) {
+ if (compareInstanceIdentifierTail(identifier,II_TO_FLOW_CAPABLE_NODE_CONNECTOR)){
+
+ String sNodeConnectorIdentifier = getNodeConnectorId(String.valueOf(nodeConnIdent.firstKeyOf(NodeConnector.class).getId()));
+ long nDpId = getDpIdFromPortName(sNodeConnectorIdentifier);
+ if (isNodeOwner(getNodeId(nDpId))) {
+ if (!dpnToPortMultiMap.containsEntry(nDpId, sNodeConnectorIdentifier)) {
+ LOG.debug("Node Connector {} added", sNodeConnectorIdentifier);
+ dpnToPortMultiMap.put(nDpId, sNodeConnectorIdentifier);
+ sendNodeConnectorUpdation(nDpId);
+ PortNameMapping.updatePortMap("openflow:" + nDpId + ":" + add.getName(), sNodeConnectorIdentifier, "ADD");
+ } else {
+ LOG.error("Duplicate Event.Node Connector already added");
+ }
+ }
+ }
+ }
+ private String getNodeConnectorId(String node) {
+ //Uri [_value=openflow:1:1]
+ String temp[] = node.split("=");
+ String dpnId = temp[1].substring(0,temp[1].length() - 1);
+ return dpnId;
+ }
+
+ private String getNodeId(Long dpnId){
+ return "openflow:" + dpnId;
+ }
+ /**
+ * Method checks if *this* instance of controller is owner of
+ * the given openflow node.
+ * @param nodeId openflow node Id
+ * @return True if owner, else false
+ */
+ public boolean isNodeOwner(String nodeId) {
+ Entity entity = new Entity("openflow", nodeId);
+ Optional<EntityOwnershipState> eState = this.entityOwnershipService.getOwnershipState(entity);
+ if(eState.isPresent()) {
+ return eState.get().isOwner();
+ }
+ return false;
+ }
+
+ private boolean compareInstanceIdentifierTail(InstanceIdentifier<?> identifier1,
+ InstanceIdentifier<?> identifier2) {
+ return Iterables.getLast(identifier1.getPathArguments()).equals(Iterables.getLast(identifier2.getPathArguments()));
+ }
+
+ private long getDpIdFromPortName(String portName) {
+ String dpId = portName.substring(portName.indexOf(SEPARATOR) + 1, portName.lastIndexOf(SEPARATOR));
+ return Long.parseLong(dpId);
+ }
+
+ private void sendNodeConnectorUpdation(Long dpnId) {
+ Collection<String> portname = dpnToPortMultiMap.get(dpnId);
+ String nodeListPortsCountStr,counterkey;
+ nodeListPortsCountStr = "dpnId_" + dpnId + "_NumberOfOFPorts";
+ counterkey = "NumberOfOFPorts:" + nodeListPortsCountStr;
+
+ if (portname.size()!=0) {
+ nodeConnectorCountermap.put(counterkey, "" + portname.size());
+ } else {
+ nodeConnectorCountermap.remove(counterkey);
+ }
+ LOG.debug("NumberOfOFPorts:" + nodeListPortsCountStr + " portlistsize " + portname.size());
+ pmAgent.connectToPMAgentForNOOfPorts(nodeConnectorCountermap);
+ }
+}
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. 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.genius.fcapsapp.performancecounter;
+
+import org.opendaylight.controller.md.sal.binding.api.*;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeConnector;
+import org.opendaylight.yangtools.yang.binding.DataObject;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import java.util.Collection;
+
+public abstract class NodeConnectorEventListener <T extends DataObject> implements ClusteredDataTreeChangeListener<T>,AutoCloseable,FlowCapableNodeConnectorCommitter<T> {
+ NodeConnectorEventListener(Class<FlowCapableNodeConnector> flowCapableNodeConnectorClass) {
+ }
+
+ @Override
+ public void onDataTreeChanged(Collection<DataTreeModification<T>> changes) {
+ for (DataTreeModification<T> change : changes) {
+ final InstanceIdentifier<T> key = change.getRootPath().getRootIdentifier();
+ final DataObjectModification<T> mod = change.getRootNode();
+ final InstanceIdentifier<FlowCapableNodeConnector> nodeConnIdent =
+ key.firstIdentifierOf(FlowCapableNodeConnector.class);
+
+ switch (mod.getModificationType()) {
+ case DELETE:
+ remove(key, mod.getDataBefore(), nodeConnIdent);
+ break;
+ case SUBTREE_MODIFIED:
+ update(key, mod.getDataBefore(), mod.getDataAfter(), nodeConnIdent);
+ break;
+ case WRITE:
+ if (mod.getDataBefore() == null) {
+ add(key, mod.getDataAfter(), nodeConnIdent);
+ } else {
+ update(key, mod.getDataBefore(), mod.getDataAfter(), nodeConnIdent);
+ }
+ break;
+
+
+ default:
+ throw new IllegalArgumentException("Unhandled modification type " + mod.getModificationType());
+ }
+ }
+ }
+
+ @Override
+ public void close() throws Exception {
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. 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.genius.fcapsapp.performancecounter;
+
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import java.lang.Integer;
+import java.lang.String;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+
+public class NodeUpdateCounter {
+
+ private static final Logger LOG = LoggerFactory.getLogger(NodeUpdateCounter.class);
+ private String nodeListEFSCountStr;
+ private static HashSet<String> dpnList = new HashSet<String>();
+ public static final PMAgent pmagent = new PMAgent();
+ Map<String, String> counter_map = new HashMap<String, String>();
+
+ public NodeUpdateCounter() {
+ }
+
+ public void nodeAddedNotification(String sNode,String hostName) {
+ dpnList.add(sNode);
+ sendNodeUpdation(dpnList.size(),hostName);
+ }
+
+ public void nodeRemovedNotification(String sNode,String hostName) {
+ dpnList.remove(sNode);
+ sendNodeUpdation(dpnList.size(), hostName);
+ }
+
+ private void sendNodeUpdation(Integer count,String hostName) {
+
+ if (hostName != null) {
+ nodeListEFSCountStr = "Node_" + hostName + "_NumberOfEFS";
+ LOG.debug("NumberOfEFS:" + nodeListEFSCountStr + " dpnList.size " + count);
+
+ counter_map.put("NumberOfEFS:" + nodeListEFSCountStr, "" + count);
+ pmagent.connectToPMAgent(counter_map);
+ } else
+ LOG.error("Hostname is null upon NumberOfEFS counter");
+ }
+
+ public boolean isDpnConnectedLocal(String sNode) {
+ if (dpnList.contains(sNode))
+ return true;
+ return false;
+ }
+}
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. 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.genius.fcapsapp.performancecounter;
+
+
+import org.opendaylight.genius.fcapsappjmx.NumberOfOFPorts;
+import org.opendaylight.genius.fcapsappjmx.NumberOfOFSwitchCounter;
+import org.opendaylight.genius.fcapsappjmx.PacketInCounter;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.management.*;
+import java.lang.String;
+import java.lang.management.ManagementFactory;
+import java.util.Map;
+
+public class PMAgent {
+ private static Logger s_logger = LoggerFactory.getLogger(PMAgent.class);
+ private MBeanServer mbs = null;
+ private ObjectName switch_mbeanName = null;
+ private ObjectName port_mbeanName = null;
+ private ObjectName pktIn_mbeanName = null;
+ private static final String SWITCH_BEANNAME = "SDNC.PM:type=NumberOfOFSwitchCounter";
+ private static final String PORTS_BEANNAME = "SDNC.PM:type=NumberOfOFPortsCounter";
+ private static final String PKTIN_BEANNAME = "SDNC.PM:type=InjectedPacketInCounter";
+
+ private static NumberOfOFSwitchCounter switchCounterBean = new NumberOfOFSwitchCounter();
+ private static NumberOfOFPorts PortcounterBean = new NumberOfOFPorts();
+ private static PacketInCounter packetInCounter = new PacketInCounter();
+
+ public PMAgent() {
+ mbs = ManagementFactory.getPlatformMBeanServer();
+ try {
+ switch_mbeanName = new ObjectName(SWITCH_BEANNAME);
+ port_mbeanName = new ObjectName(PORTS_BEANNAME);
+ pktIn_mbeanName = new ObjectName(PKTIN_BEANNAME);
+ } catch (MalformedObjectNameException e) {
+ s_logger.error("ObjectName instance creation failed for BEANAME {}", e);
+
+ }
+ }
+
+ public void registerMbeanForEFS() {
+ try {
+ if (!mbs.isRegistered(switch_mbeanName)) {
+ mbs.registerMBean(switchCounterBean, switch_mbeanName);
+ s_logger.info("Registered Mbean {} successfully", switch_mbeanName);
+ }
+
+ } catch (Exception e) {
+ s_logger.error("Registeration failed for Mbean {} :{}", switch_mbeanName, e);
+ }
+ }
+
+ public void registerMbeanForPorts() {
+ try {
+ if (!mbs.isRegistered(port_mbeanName)) {
+ mbs.registerMBean(PortcounterBean, port_mbeanName);
+ s_logger.info("Registered Mbean {} successfully", port_mbeanName);
+ }
+ } catch (Exception e) {
+ s_logger.error("Registeration failed for Mbean {} :{}", port_mbeanName, e);
+ }
+ }
+
+ public void registerMbeanForPacketIn() {
+ try {
+ if (!mbs.isRegistered(pktIn_mbeanName)) {
+ mbs.registerMBean(packetInCounter,pktIn_mbeanName);
+ s_logger.info("Registered Mbean {} successfully",pktIn_mbeanName );
+ }
+ } catch (Exception e) {
+ s_logger.error("Registeration failed for Mbean {} :{}",pktIn_mbeanName , e);
+ }
+ }
+
+ public void connectToPMAgent(Map map) {
+ switchCounterBean.updateCounter(map);
+ }
+
+ public void connectToPMAgentForNOOfPorts(Map map) {
+ PortcounterBean.updateCounter(map);
+ }
+
+ public void sendPacketInCounterUpdate(Map map){
+ packetInCounter.updateCounter(map);
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. 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.genius.fcapsapp.performancecounter;
+
+import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketProcessingListener;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketReceived;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.HashMap;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.atomic.AtomicLong;
+
+public class PacketInCounterHandler implements PacketProcessingListener {
+ private static final Logger LOG = LoggerFactory.getLogger(PacketInCounterHandler.class);
+ private static ConcurrentHashMap<String,AtomicLong> ingressPacketMap = new ConcurrentHashMap<>();
+ private static HashMap<String,String> packetInMap = new HashMap<>();
+ private static final Integer FIRST_VALUE = 1;
+ private static final PMAgent pmAgent =new PMAgent();
+
+ @Override
+ public void onPacketReceived(PacketReceived notification) {
+ String dpnId = null;
+ String nodeListEgressStr, nodekey;
+ LOG.debug("Ingress packet notification received");
+ try {
+ if (notification.getIngress() == null) {
+ if (LOG.isWarnEnabled()) {
+ LOG.warn("invalid PacketReceived notification");
+ }
+ return;
+ }
+ dpnId = getDpnId(notification.getIngress().getValue().toString());
+ } catch (Exception e) {
+ if (LOG.isWarnEnabled()) {
+ LOG.warn("DPN Parsing failed in onPacketReceived");
+ }
+ }
+ if (dpnId != null) {
+ nodeListEgressStr = "dpnId_" + dpnId + "_InjectedOFMessagesSent";
+ nodekey = "InjectedOFMessagesSent:" + nodeListEgressStr;
+ if (ingressPacketMap.containsKey(dpnId)) {
+ ingressPacketMap.put(dpnId,new AtomicLong(ingressPacketMap.get(dpnId).incrementAndGet()));
+ packetInMap.put(nodekey,""+ingressPacketMap.get(dpnId));
+ } else {
+ ingressPacketMap.put(dpnId, new AtomicLong(FIRST_VALUE));
+ packetInMap.put(nodekey,""+FIRST_VALUE);
+ }
+ connectToPMAgent();
+ } else {
+ LOG.error("DpnId is null");
+ }
+ }
+ private void connectToPMAgent(){
+ pmAgent.sendPacketInCounterUpdate(packetInMap);
+ }
+ /*
+ * Method to extract DpnId
+ */
+ public static String getDpnId(String id) {
+ String[] nodeNo = id.split(":");
+ String[] dpnId = nodeNo[1].split("]");
+ return dpnId[0];
+ }
+
+ public void nodeRemovedNotification(String dpnId){
+ String nodeListEgressStr, nodekey;
+ if (dpnId != null) {
+ dpnId = dpnId.split(":")[1];
+ LOG.debug("Dpnvalue Id {}",dpnId);
+ if (ingressPacketMap.containsKey(dpnId)) {
+ nodeListEgressStr = "dpnId_" + dpnId + "_InjectedOFMessagesSent";
+ nodekey = "InjectedOFMessagesSent:" + nodeListEgressStr;
+ synchronized (this) {
+ ingressPacketMap.remove(dpnId);
+ packetInMap.remove(nodekey);
+ connectToPMAgent();
+ }
+ LOG.debug("Node {} Removed for PacketIn counter", dpnId);
+ }
+ } else {
+ LOG.error("DpnId is null upon nodeRemovedNotification");
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. 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.genius.fcapsapp.portinfo;
+
+import java.lang.String;
+import java.util.HashMap;
+import java.util.Map;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import javax.management.*;
+import java.lang.management.ManagementFactory;
+
+public class PortNameMapping implements PortNameMappingMBean {
+
+ private static final Logger LOG = LoggerFactory.getLogger(PortNameMapping.class);
+
+ private static Map<String,String> portNameToPortIdMap = new HashMap<String,String>();
+
+ @Override
+ public Map<String,String> getPortIdtoPortNameMap() {
+ return portNameToPortIdMap;
+ }
+
+ @Override
+ public String getPortName(String portId){
+ return portNameToPortIdMap.get(portId);
+ }
+
+ public static void updatePortMap(String portName,String portId,String status) {
+ if (status.equals("ADD")){
+ portNameToPortIdMap.put(portId,portName);
+ LOG.debug("PortId {} : portName {} added",portId,portName);
+ } else if(status.equals("DELETE")){
+ portNameToPortIdMap.remove(portId);
+ LOG.debug("PortId {} : portName {} removed",portId,portName);
+ }
+ }
+
+ public static void registerPortMappingBean() {
+ MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
+ ObjectName mbeanName = null;
+ String BEANNAME = "Ports:type=PortNameMapping";
+
+ try {
+ mbeanName = new ObjectName(BEANNAME);
+ } catch (MalformedObjectNameException e) {
+ LOG.error("ObjectName instance creation failed for BEANAME {} : {}", BEANNAME, e);
+
+ }
+ try {
+ if (!mbs.isRegistered(mbeanName)) {
+ mbs.registerMBean(new PortNameMapping(), mbeanName);
+ LOG.debug("Registered Mbean {} successfully", mbeanName);
+ }
+
+ } catch (Exception e) {
+ LOG.error("Registeration failed for Mbean {} :{}", mbeanName, e);
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. 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.genius.fcapsapp.portinfo;
+
+import java.lang.String;
+import java.util.Map;
+
+public interface PortNameMappingMBean {
+ public Map<String,String> getPortIdtoPortNameMap();
+ public String getPortName(String portId);
+}
\ No newline at end of file
--- /dev/null
+package org.opendaylight.yang.gen.v1.urn.opendaylight.genius.fcaps.app.rev160519;
+
+import org.opendaylight.genius.fcapsapp.FcapsProvider;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class FcapsAppModule extends org.opendaylight.yang.gen.v1.urn.opendaylight.genius.fcaps.app.rev160519.AbstractFcapsAppModule {
+
+ private static final Logger LOG = LoggerFactory.getLogger(FcapsAppModule.class);
+ public FcapsAppModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
+ super(identifier, dependencyResolver);
+ }
+
+ public FcapsAppModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver, org.opendaylight.yang.gen.v1.urn.opendaylight.genius.fcaps.app.rev160519.FcapsAppModule oldModule, java.lang.AutoCloseable oldInstance) {
+ super(identifier, dependencyResolver, oldModule, oldInstance);
+ }
+
+ @Override
+ public void customValidation() {
+ // add custom validation form module attributes here.
+ }
+
+ @Override
+ public java.lang.AutoCloseable createInstance() {
+ LOG.info("Fcaps module initialization");
+ return new FcapsProvider(getDataBrokerDependency(),getNotificationAdapterDependency(),getEntityOwnershipServiceDependency());
+ }
+
+}
--- /dev/null
+/*
+* Generated file
+*
+* Generated from: yang module name: fcaps-app yang module local name: fcaps-app
+* Generated by: org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator
+* Generated at: Thu May 19 12:16:14 IST 2016
+*
+* Do not modify this file unless it is present under src/main directory
+*/
+package org.opendaylight.yang.gen.v1.urn.opendaylight.genius.fcaps.app.rev160519;
+public class FcapsAppModuleFactory extends org.opendaylight.yang.gen.v1.urn.opendaylight.genius.fcaps.app.rev160519.AbstractFcapsAppModuleFactory {
+
+}
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- vi: set et smarttab sw=4 tabstop=4: -->
+<!--
+Copyright © 2016 Ericsson India Global Services Pvt Ltd. 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
+-->
+<snapshot>
+ <configuration>
+ <data xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
+ <modules xmlns="urn:opendaylight:params:xml:ns:yang:controller:config">
+ <module>
+ <type xmlns:fcaps="urn:opendaylight:genius:fcaps-app">
+ fcaps:fcaps-app
+ </type>
+ <name>fcaps-app</name>
+
+ <data-broker>
+ <type xmlns:binding="urn:opendaylight:params:xml:ns:yang:controller:md:sal:binding">binding:binding-async-data-broker</type>
+ <name>pingpong-binding-data-broker</name>
+ </data-broker>
+ <rpc-registry>
+ <type xmlns:binding="urn:opendaylight:params:xml:ns:yang:controller:md:sal:binding">binding:binding-rpc-registry</type>
+ <name>binding-rpc-broker</name>
+ </rpc-registry>
+ <notification-adapter>
+ <type xmlns:binding="urn:opendaylight:params:xml:ns:yang:controller:md:sal:binding:impl">binding:binding-new-notification-service</type>
+ <name>binding-notification-adapter</name>
+ </notification-adapter>
+ <entity-ownership-service>
+ <type xmlns:entity-ownership="urn:opendaylight:params:xml:ns:yang:controller:md:sal:core:spi:entity-ownership-service">entity-ownership:entity-ownership-service</type>
+ <name>entity-ownership-service</name>
+ </entity-ownership-service>
+ </module>
+ </modules>
+ </data>
+ </configuration>
+
+ <required-capabilities>
+ <capability>
+ urn:opendaylight:genius:fcaps-app?module=fcaps-app&revision=2016-05-19
+ </capability>
+ <capability>
+ urn:opendaylight:params:xml:ns:yang:controller:config:distributed-entity-ownership-service?module=distributed-entity-ownership-service&revision=2015-08-10
+ </capability>
+ </required-capabilities>
+
+</snapshot>
--- /dev/null
+module fcaps-app {
+
+ yang-version 1;
+ namespace "urn:opendaylight:genius:fcaps-app";
+ prefix "fcaps";
+
+ import config { prefix config; revision-date 2013-04-05; }
+ import opendaylight-md-sal-binding { prefix md-sal-binding; revision-date 2013-10-28; }
+ import opendaylight-sal-binding-broker-impl { prefix sal-broker; revision-date 2013-10-28;}
+ import opendaylight-entity-ownership-service { prefix eos; }
+
+ description
+ "This module contains the base YANG definitions for
+ fcaps-manager implementation.";
+
+ revision "2016-05-19" {
+ description
+ "Initial revision.";
+ }
+
+ identity fcaps-app {
+ base config:module-type;
+ config:java-name-prefix FcapsApp;
+ }
+
+ augment "/config:modules/config:module/config:configuration" {
+ case fcaps-app {
+ when "/config:modules/config:module/config:type = 'fcaps-app'";
+
+ container data-broker {
+ uses config:service-ref {
+ refine type {
+ mandatory true;
+ config:required-identity md-sal-binding:binding-async-data-broker;
+ }
+ }
+ }
+ container rpc-registry {
+ uses config:service-ref {
+ refine type {
+ mandatory true;
+ config:required-identity md-sal-binding:binding-rpc-registry;
+ }
+ }
+ }
+ container notification-adapter {
+ uses config:service-ref {
+ refine type {
+ mandatory true;
+ config:required-identity sal-broker:binding-new-notification-service;
+ }
+ }
+ }
+ container entity-ownership-service {
+ uses config:service-ref {
+ refine type {
+ mandatory true;
+ config:required-identity eos:entity-ownership-service;
+ }
+ }
+ }
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+Copyright (c) 2015 Ericsson India Global Services Pvt Ltd. 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.genius</groupId>
+ <artifactId>config-parent</artifactId>
+ <version>0.1.0-SNAPSHOT</version>
+ <relativePath>../../commons/config-parent</relativePath>
+ </parent>
+
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.opendaylight.genius</groupId>
+ <artifactId>fcapsapplication-jmxapi</artifactId>
+ <version>${genius.version}</version>
+ <packaging>bundle</packaging>
+
+</project>
--- /dev/null
+/*
+ * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. 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.genius.fcapsappjmx;
+
+import javax.management.AttributeChangeNotification;
+import javax.management.Notification;
+import javax.management.NotificationBroadcasterSupport;
+import java.util.ArrayList;
+
+public class ControlPathFailureAlarm extends NotificationBroadcasterSupport implements ControlPathFailureAlarmMBean {
+
+ ArrayList<String> raiseAlarmObject = new ArrayList<String>();
+ ArrayList<String> clearAlarmObject = new ArrayList<String>();
+ private long sequenceNumber = 1;
+
+ public void setRaiseAlarmObject(ArrayList<String> raiseAlarmObject) {
+ this.raiseAlarmObject = raiseAlarmObject;
+
+ Notification notif = new AttributeChangeNotification(this,
+ sequenceNumber++, System.currentTimeMillis(),
+ "raise alarm object notified ", "raiseAlarmObject", "ArrayList",
+ "", this.raiseAlarmObject);
+ sendNotification(notif);
+ }
+
+ public ArrayList<String> getRaiseAlarmObject() {
+ return raiseAlarmObject;
+ }
+
+ public void setClearAlarmObject(ArrayList<String> clearAlarmObject) {
+ this.clearAlarmObject = clearAlarmObject;
+
+ Notification notif = new AttributeChangeNotification(this,
+ sequenceNumber++, System.currentTimeMillis(),
+ "clear alarm object notified ", "clearAlarmObject", "ArrayList",
+ "", this.clearAlarmObject);
+ sendNotification(notif);
+ }
+
+ public ArrayList<String> getClearAlarmObject() {
+ return clearAlarmObject;
+ }
+
+ public synchronized void raiseAlarm(String alarmName, String additionalText, String source) {
+ raiseAlarmObject.add(alarmName);
+ raiseAlarmObject.add(additionalText);
+ raiseAlarmObject.add(source);
+ setRaiseAlarmObject(raiseAlarmObject);
+ raiseAlarmObject.clear();
+ }
+
+ public synchronized void clearAlarm(String alarmName, String additionalText, String source) {
+ clearAlarmObject.add(alarmName);
+ clearAlarmObject.add(additionalText);
+ clearAlarmObject.add(source);
+ setClearAlarmObject(clearAlarmObject);
+ clearAlarmObject.clear();
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. 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.genius.fcapsappjmx;
+
+import java.util.ArrayList;
+
+public interface ControlPathFailureAlarmMBean {
+ public void setRaiseAlarmObject(ArrayList<String> raiseAlarmObject);
+ public ArrayList<String> getRaiseAlarmObject();
+ public void setClearAlarmObject(ArrayList<String> clearAlarmObject);
+ public ArrayList<String> getClearAlarmObject();
+ public void raiseAlarm(String alarmName, String additionalText, String source);
+ public void clearAlarm(String alarmName, String additionalText, String source);
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. 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.genius.fcapsappjmx;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class NumberOfOFPorts implements NumberOfOFPortsMBean {
+ private static Map<String,String> counterCache = new HashMap<String,String>();
+
+ @Override
+ public void updateCounter(Map<String, String> map) {
+ counterCache = map;
+ }
+
+ @Override
+ public Map<String, String> retrieveCounterMap() {
+ return counterCache;
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. 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.genius.fcapsappjmx;
+
+import java.util.Map;
+
+public interface NumberOfOFPortsMBean {
+ //-----------
+ // operations
+ //-----------
+ public void updateCounter(Map<String, String> map);
+ public Map<String, String> retrieveCounterMap();
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. 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.genius.fcapsappjmx;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class NumberOfOFSwitchCounter implements NumberOfOFSwitchCounterMBean {
+ private static Map<String,String> counterCache = new HashMap<String,String>();
+
+ @Override
+ public void updateCounter(Map<String, String> map) {
+ counterCache = map;
+ }
+
+ @Override
+ public Map<String, String> retrieveCounterMap() {
+ return counterCache;
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. 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.genius.fcapsappjmx;
+
+import java.util.Map;
+
+public interface NumberOfOFSwitchCounterMBean {
+ //-----------
+ // operations
+ //-----------
+ public void updateCounter(Map<String, String> map);
+ public Map<String, String> retrieveCounterMap();
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. 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.genius.fcapsappjmx;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class PacketInCounter implements PacketInCounterMBean {
+ private static Map<String,String> counterCache = new HashMap<String,String>();
+
+ @Override
+ public void updateCounter(Map<String, String> map) {
+ counterCache = map;
+ }
+
+ @Override
+ public Map<String, String> retrieveCounterMap() {
+ return counterCache;
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. 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.genius.fcapsappjmx;
+
+import java.util.Map;
+
+public interface PacketInCounterMBean {
+ //-----------
+ // operations
+ //-----------
+ public void updateCounter(Map<String, String> map);
+ public Map<String, String> retrieveCounterMap();
+}
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+Copyright (c) 2015 - 2016 Ericsson India Global Services Pvt Ltd. 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 INTERNAL
+-->
+<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.odlparent</groupId>
+ <artifactId>odlparent</artifactId>
+ <version>1.7.0-SNAPSHOT</version>
+ <relativePath/>
+ </parent>
+
+ <groupId>org.opendaylight.genius</groupId>
+ <artifactId>fcapsapplication</artifactId>
+ <version>0.1.0-SNAPSHOT</version>
+ <name>fcapsapplication</name>
+ <packaging>pom</packaging>
+ <modelVersion>4.0.0</modelVersion>
+ <prerequisites>
+ <maven>3.1.1</maven>
+ </prerequisites>
+ <modules>
+ <module>fcapsapplication-jmxapi</module>
+ <module>fcapsapplication-impl</module>
+ </modules>
+ <!-- DO NOT install or deploy the repo root pom as it's only needed to initiate a build -->
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-deploy-plugin</artifactId>
+ <configuration>
+ <skip>true</skip>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-install-plugin</artifactId>
+ <configuration>
+ <skip>true</skip>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
\ No newline at end of file
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- vi: set et smarttab sw=4 tabstop=4: --><!--
+Copyright (c) 2015 Ericsson India Global Services Pvt Ltd. 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.genius</groupId>
+ <artifactId>config-parent</artifactId>
+ <version>0.1.0-SNAPSHOT</version>
+ <relativePath>../../commons/config-parent</relativePath>
+ </parent>
+
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.opendaylight.genius</groupId>
+ <artifactId>alarmmanager</artifactId>
+ <version>${genius.version}</version>
+ <packaging>bundle</packaging>
+
+ <properties>
+ <maven-bundle-plugin.version>2.5.3</maven-bundle-plugin.version>
+ <osgi.version>5.0.0</osgi.version>
+ </properties>
+ <dependencies>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.core</artifactId>
+ <version>${osgi.version}</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>fcaps-api</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ </dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <version>${maven-bundle-plugin.version}</version>
+ <extensions>true</extensions>
+ <configuration>
+ <instructions>
+ <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
+ <Bundle-Version>${project.version}</Bundle-Version>
+ <Bundle-Activator>org.opendaylight.genius.fcapsmanager.alarmmanager.Activator</Bundle-Activator>
+ <Export-Package>org.opendaylight.genius.fcapsmanager.alarmmanager*;version=${project.version}</Export-Package>
+ <Import-Package>*</Import-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. 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.genius.fcapsmanager.alarmmanager;
+
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class Activator implements BundleActivator {
+ static Logger s_logger = LoggerFactory.getLogger(Activator.class);
+ private Runnable listener;
+ private Thread listenerThread;
+
+ public void start(BundleContext context) {
+ s_logger.info("Starting alarmmanager bundle");
+ AlarmNotificationListeners notificationListeners = new AlarmNotificationListeners(context);
+ try {
+ listener = notificationListeners;
+ listenerThread = new Thread(listener);
+ listenerThread.start();
+ } catch (Exception e) {
+ s_logger.error("Exception in alarm thread {}", e);
+ }
+ }
+
+ public void stop(BundleContext context) {
+ s_logger.info("Stopping alarmmanager bundle");
+ }
+}
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. 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.genius.fcapsmanager.alarmmanager;
+
+import javax.management.*;
+import java.lang.management.ManagementFactory;
+import java.util.*;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.opendaylight.genius.fcapsmanager.AlarmServiceFacade;
+
+public class AlarmNotificationListeners implements Runnable {
+ static Logger s_logger = LoggerFactory.getLogger(AlarmNotificationListeners.class);
+ private MBeanServer mbs = null;
+ private static String DOMAIN = "SDNC.FM";
+
+ private final DelegateListener delegateListener = new DelegateListener();
+ private BundleContext context = null;
+
+ public AlarmNotificationListeners(BundleContext context) {
+ this.context=context;
+ }
+
+ /**
+ * Platform dependent bundle injects its handle and it is retrieved in the method
+ */
+ private AlarmServiceFacade getAlarmServiceSPI (){
+ AlarmServiceFacade service =null;
+ if(context != null) {
+ try {
+ ServiceReference<?> serviceReference = context.
+ getServiceReference(AlarmServiceFacade.class.getName());
+ service = (AlarmServiceFacade) context.
+ getService(serviceReference);
+ }catch (NullPointerException ex){
+ service = null;
+ }catch (Exception e){
+ s_logger.error("Exception {} occurred in getting AlarmServiceSPI",e);
+ }
+ }
+ return service;
+ }
+
+ /**
+ * Gets register notification when a mbean is registered in platform Mbeanserver and checks if it is alarm mbean and add attribute notification listener to it.
+ * Gets attribute notification when alarm mbean is updated by the application.
+ */
+ public class DelegateListener implements NotificationListener {
+ public void handleNotification(Notification notification, Object obj) {
+ if (notification instanceof MBeanServerNotification) {
+ MBeanServerNotification msnotification =
+ (MBeanServerNotification) notification;
+ String nType = msnotification.getType();
+ ObjectName mbn = msnotification.getMBeanName();
+
+ if (nType.equals("JMX.mbean.registered")) {
+ if (mbn.toString().contains(DOMAIN)) {
+ s_logger.debug("Received registeration of Mbean "+mbn);
+ try {
+ mbs.addNotificationListener(mbn,delegateListener, null, null);
+ s_logger.debug("Added attribute notification listener for Mbean "+ mbn);
+ } catch (InstanceNotFoundException e) {
+ s_logger.error("Exception while adding attribute notification of mbean {}", e);
+ }
+ }
+ }
+
+ if (nType.equals("JMX.mbean.unregistered")) {
+ if (mbn.toString().contains(DOMAIN)) {
+ s_logger.debug("Time: " + msnotification.getTimeStamp() + "MBean " + msnotification.getMBeanName()+" unregistered successfully");
+ }
+ }
+ }
+ else if (notification instanceof AttributeChangeNotification) {
+ AttributeChangeNotification acn =
+ (AttributeChangeNotification) notification;
+
+ s_logger.debug("Received attribute notification of Mbean: "
+ + notification.getSource()
+ + " for attribute:" + acn.getAttributeName() );
+
+ if(acn.getAttributeName().toString().equals("raiseAlarmObject")){
+
+ String value=acn.getNewValue().toString();
+ value = value.replace(value.charAt(0), ' ');
+ value = value.replace(value.charAt(value.lastIndexOf("]")), ' ');
+
+ String[] args =value.split(",");
+ s_logger.debug("Receive attribute value :"+args[0].trim()+args[1].trim()+args[2].trim());
+ if(getAlarmServiceSPI() != null ) {
+ getAlarmServiceSPI().raiseAlarm(args[0].trim(),args[1].trim(),args[2].trim());
+ } else {
+ s_logger.debug("Alarm service not available");
+ }
+
+ } else if(acn.getAttributeName().toString().equals("clearAlarmObject")){
+
+ String value=acn.getNewValue().toString();
+ value = value.replace(value.charAt(0), ' ');
+ value = value.replace(value.charAt(value.lastIndexOf("]")), ' ');
+
+ String[] args =value.split(",");
+ s_logger.debug("Receive attribute value :"+args[0].trim()+args[1].trim()+args[2].trim());
+ if(getAlarmServiceSPI() != null )
+ getAlarmServiceSPI().clearAlarm(args[0].trim(), args[1].trim(), args[2].trim());
+ else
+ s_logger.debug("Alarm service not available");
+ }
+ }
+ }
+ }
+
+ /**
+ * Gets the platform MBeanServer instance and registers to get notification whenever alarm mbean is registered in the mbeanserver
+ */
+ @Override
+ public void run() {
+ mbs = ManagementFactory.getPlatformMBeanServer();
+
+ queryMbeans();
+
+ ObjectName delegate = null;
+ try {
+ delegate = new ObjectName("JMImplementation:type=MBeanServerDelegate");
+ } catch (MalformedObjectNameException e) {
+ e.printStackTrace();
+ }
+ NotificationFilterSupport filter = new NotificationFilterSupport();
+ filter.enableType("JMX.mbean.registered");
+ filter.enableType("JMX.mbean.unregistered");
+
+ try {
+ mbs.addNotificationListener(delegate, delegateListener, filter, null);
+ s_logger.debug("Added registeration listener for Mbean {}",delegate);
+ } catch (InstanceNotFoundException e) {
+ s_logger.error("Failed to add registeration listener {}", e);
+ }
+
+ waitForNotification();
+ }
+
+ /**
+ * Pre-provisioning case to handle all alarm mbeans which are registered before installation of framework bundle
+ * Queries the platform Mbeanserver to retrieve registered alarm mbean and add attribute notification listener to it
+ */
+ public void queryMbeans() {
+
+ Set<ObjectName> names =
+ new TreeSet<ObjectName>(mbs.queryNames(null, null));
+ s_logger.debug("Queried MBeanServer for MBeans:");
+ for (ObjectName beanName : names) {
+ if(beanName.toString().contains(DOMAIN)){
+ try {
+ mbs.addNotificationListener(beanName,delegateListener, null, null);
+ s_logger.debug("Added attribute notification listener for Mbean "+ beanName);
+ } catch (InstanceNotFoundException e) {
+ s_logger.error("Failed to add attribute notification for Mbean {}", e);
+ }
+ }
+ }
+ }
+ public void waitForNotification() {
+ while(true){
+ try {
+ Thread.sleep(50);
+ }
+ catch(Exception ex){
+ ex.printStackTrace();
+ }
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- vi: set et smarttab sw=4 tabstop=4: --><!--
+Copyright (c) 2015 Ericsson India Global Services Pvt Ltd. 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.genius</groupId>
+ <artifactId>config-parent</artifactId>
+ <version>0.1.0-SNAPSHOT</version>
+ <relativePath>../../commons/config-parent</relativePath>
+ </parent>
+
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.opendaylight.genius</groupId>
+ <artifactId>countermanager</artifactId>
+ <version>${genius.version}</version>
+ <packaging>bundle</packaging>
+
+ <properties>
+ <maven-bundle-plugin.version>2.5.3</maven-bundle-plugin.version>
+ <osgi.version>5.0.0</osgi.version>
+ </properties>
+ <dependencies>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.core</artifactId>
+ <version>${osgi.version}</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>fcaps-api</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ </dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <version>${maven-bundle-plugin.version}</version>
+ <extensions>true</extensions>
+ <configuration>
+ <instructions>
+ <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
+ <Bundle-Version>${project.version}</Bundle-Version>
+ <Bundle-Activator>org.opendaylight.genius.fcapsmanager.countermanager.Activator</Bundle-Activator>
+ <Export-Package>org.opendaylight.genius.fcapsmanager.countermanager*;version=${project.version}</Export-Package>
+ <Import-Package>*</Import-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. 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.genius.fcapsmanager.countermanager;
+
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.slf4j.LoggerFactory;
+
+import javax.management.InstanceNotFoundException;
+import javax.management.MBeanException;
+import javax.management.MalformedObjectNameException;
+import javax.management.ReflectionException;
+import java.io.IOException;
+
+public class Activator implements BundleActivator {
+ private final static org.slf4j.Logger LOG = LoggerFactory.getLogger(Activator.class);
+ private Runnable listener;
+ private Thread listenerThread;
+
+ public void start(BundleContext context) throws InstanceNotFoundException, MalformedObjectNameException, MBeanException, ReflectionException, IOException {
+ LOG.info("Starting countermanager bundle ");
+ PMRegistrationListener notificationListeners = new PMRegistrationListener(context);
+ try {
+ listener = notificationListeners;
+ listenerThread = new Thread(listener);
+ listenerThread.start();
+ } catch (Exception e) {
+ LOG.error("Exception in counter thread {}", e);
+ }
+ }
+
+ public void stop(BundleContext context) {
+ LOG.info("Stopping countermanager bundle ");
+ }
+}
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. 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.genius.fcapsmanager.countermanager;
+
+import java.lang.management.ManagementFactory;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.TreeSet;
+
+import javax.management.InstanceNotFoundException;
+import javax.management.MBeanServer;
+import javax.management.MBeanServerNotification;
+import javax.management.MalformedObjectNameException;
+import javax.management.Notification;
+import javax.management.NotificationFilterSupport;
+import javax.management.NotificationListener;
+import javax.management.ObjectName;
+
+import org.osgi.framework.BundleContext;
+import org.slf4j.LoggerFactory;
+
+public class PMRegistrationListener implements Runnable {
+ private final static org.slf4j.Logger LOG = LoggerFactory.getLogger(PMRegistrationListener.class);
+ static MBeanServer mbs = null;
+
+ private static String DOMAIN = "SDNC.PM";
+ public static HashSet<ObjectName> beanNames = new HashSet<ObjectName>();
+ private BundleContext context = null;
+
+ public PMRegistrationListener(BundleContext context){
+ this.context=context;
+ }
+
+ /**
+ * Gets register notification when a mbean is registered in platform Mbeanserver and checks if it is counter mbean and add it to the map.
+ */
+ public static class DelegateListener implements NotificationListener {
+ public void handleNotification(Notification notification, Object obj) {
+ if (notification instanceof MBeanServerNotification) {
+ MBeanServerNotification msnotification =
+ (MBeanServerNotification) notification;
+ String nType = msnotification.getType();
+ ObjectName mbn = msnotification.getMBeanName();
+ if (nType.equals("JMX.mbean.registered")) {
+ String mbean = mbn.toString();
+ if(mbean.contains(DOMAIN)) {
+ beanNames.add(mbn);
+ LOG.debug("Beans are " +beanNames);
+ }
+ }
+ if (nType.equals("JMX.mbean.unregistered")) {
+ if(mbn.toString().contains(DOMAIN)) {
+ beanNames.remove(mbn);
+ LOG.debug(mbn +" MBean has been unregistered");
+ }
+ }
+ }
+ }
+ }
+
+ @Override
+ public void run(){
+ mbs = ManagementFactory.getPlatformMBeanServer();
+ queryMbeans();
+ DelegateListener delegateListener = new DelegateListener();
+ ObjectName delegate = null;
+ try {
+ delegate = new ObjectName("JMImplementation:type=MBeanServerDelegate");
+ } catch (MalformedObjectNameException e) {
+ e.printStackTrace();
+ }
+ NotificationFilterSupport filter = new NotificationFilterSupport();
+
+ filter.enableType("JMX.mbean.registered");
+ filter.enableType("JMX.mbean.unregistered");
+
+ LOG.debug("Add PM Registeration Notification Listener");
+ try {
+ mbs.addNotificationListener(delegate, delegateListener, filter,null);
+ }catch (InstanceNotFoundException e) {
+ e.printStackTrace();
+ }
+ Poller poller = new Poller(this.context);
+ poller.polling();
+ waitforNotification();
+ }
+
+ /**
+ * Prepovising case to handle all counter mbeans which are registered before the installation of framework bundle
+ * Queries the platform Mbeanserver to retrieve registered counter mbean and add it to the map
+ */
+ public void queryMbeans() {
+ Set<ObjectName> names =
+ new TreeSet<ObjectName>(mbs.queryNames(null, null));
+ LOG.debug("\nQueried MBeanServer for MBeans:");
+ for (ObjectName name : names) {
+ if(name.toString().contains(DOMAIN)){
+ beanNames.add(name);
+ }
+ }
+ }
+
+ private void waitforNotification() {
+ while(true){
+ try {
+ Thread.sleep(50);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. 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.genius.fcapsmanager.countermanager;
+
+import java.lang.management.ManagementFactory;
+import org.opendaylight.genius.fcapsmanager.PMServiceFacade;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+import org.slf4j.LoggerFactory;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
+
+public class Poller {
+ private final static org.slf4j.Logger LOG = LoggerFactory.getLogger(Poller.class);
+ private static BundleContext context = null;
+ public Poller(){
+ }
+ public Poller(BundleContext bundleContext) {
+ context = bundleContext;
+ }
+ //This method do the Polling every 5 second and retrieves the the counter details
+ //@Override
+ public void polling() {
+ LOG.debug("Poller Polling Mbean List and the content is " + PMRegistrationListener.beanNames);
+ ScheduledExecutorService service = Executors.newSingleThreadScheduledExecutor();
+ service.scheduleAtFixedRate(new Pollerthread(), 0, 5, TimeUnit.SECONDS);
+ }
+
+ /**
+ * Platform dependent bundle injects its handle and it is retrieved in the method
+ */
+ protected PMServiceFacade getPMServiceSPI (){
+ PMServiceFacade service =null;
+ if(context != null) {
+ try {
+ ServiceReference<?> serviceReference = context.
+ getServiceReference(PMServiceFacade.class.getName());
+ service = (PMServiceFacade) context.
+ getService(serviceReference);
+ }catch(NullPointerException ex){
+ service = null;
+ }catch (Exception e){
+ LOG.error("Exception {} occurred in getting PMServiceSPI",e);
+ }
+ }
+ return service;
+ }
+}
+
+class Pollerthread implements Runnable {
+ private final static org.slf4j.Logger LOG = LoggerFactory.getLogger(Pollerthread.class);
+ MBeanServer mbs = null;
+ Map<String,String> getCounter = new HashMap<String,String>();
+ Poller poller = new Poller();
+
+ /**
+ * Retrieve countermap from each counter mbean and send to platform
+ */
+ @SuppressWarnings("unchecked")
+ @Override
+ public void run() {
+ try {
+ mbs = ManagementFactory.getPlatformMBeanServer();
+ for (ObjectName objectName : PMRegistrationListener.beanNames) {
+ getCounter=(Map<String, String>) mbs.invoke(objectName, "retrieveCounterMap",null,null);
+ if(poller.getPMServiceSPI() != null)
+ poller.getPMServiceSPI().connectToPMFactory(getCounter);
+ else
+ LOG.debug("PM service not available");
+ }
+ } catch (Exception e) {
+ LOG.error("Exception caught {} ", e);
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- vi: set et smarttab sw=4 tabstop=4: --><!--
+Copyright (c) 2015 Ericsson India Global Services Pvt Ltd. 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.genius</groupId>
+ <artifactId>config-parent</artifactId>
+ <version>0.1.0-SNAPSHOT</version>
+ <relativePath>../../commons/config-parent</relativePath>
+ </parent>
+
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.opendaylight.genius</groupId>
+ <artifactId>fcaps-api</artifactId>
+ <version>${genius.version}</version>
+ <packaging>bundle</packaging>
+
+ <properties>
+ <maven-bundle-plugin.version>2.5.3</maven-bundle-plugin.version>
+ <osgi.version>5.0.0</osgi.version>
+ </properties>
+ <dependencies>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.core</artifactId>
+ <version>${osgi.version}</version>
+ <scope>provided</scope>
+ </dependency>
+ </dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <version>${maven-bundle-plugin.version}</version>
+ <extensions>true</extensions>
+ <configuration>
+ <instructions>
+ <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
+ <Bundle-Version>${project.version}</Bundle-Version>
+ <Bundle-Activator>org.opendaylight.genius.fcapsmanager.Activator</Bundle-Activator>
+ <Export-Package>org.opendaylight.genius.fcapsmanager*;version=${project.version}</Export-Package>
+ <Import-Package>*</Import-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. 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.genius.fcapsmanager;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+
+public class Activator implements BundleActivator {
+ static Logger s_logger = LoggerFactory.getLogger(Activator.class);
+ public void start(BundleContext context) {
+ s_logger.info("Starting fcapsSPI bundle");
+ }
+
+ public void stop(BundleContext context) {
+ s_logger.info("Stopping fcapsSPI bundle");
+ }
+
+}
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. 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.genius.fcapsmanager;
+
+public interface AlarmServiceFacade {
+ /**
+ * Raises the given alarm in platform environment
+ *
+ * @param alarmName
+ * Alarm to be raised
+ * @param additionalText
+ * Additional details describing about the alarm
+ * @param source
+ * Source of the alarm ex: dpnId=openflow:1
+ * the source node that caused this alarm
+ */
+ public void raiseAlarm(String alarmName, String additionalText, String source);
+
+ /**
+ * Clears the given alarm in platform environment
+ *
+ * @param alarmName
+ * Alarm to be cleared
+ * @param additionalText
+ * Additional details describing about the alarm
+ * @param source
+ * Source of the alarm ex: dpnId=openflow:1
+ * the source node that caused this alarm
+ */
+ public void clearAlarm(String alarmName, String additionalText, String source);
+}
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. 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.genius.fcapsmanager;
+
+import java.util.Map;
+
+public interface PMServiceFacade {
+ public void connectToPMFactory(Map map);
+}
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+Copyright (c) 2015 - 2016 Ericsson India Global Services Pvt Ltd. 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 INTERNAL
+-->
+<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.odlparent</groupId>
+ <artifactId>odlparent</artifactId>
+ <version>1.7.0-SNAPSHOT</version>
+ <relativePath/>
+ </parent>
+
+ <groupId>org.opendaylight.genius</groupId>
+ <artifactId>fcapsmanager</artifactId>
+ <version>0.1.0-SNAPSHOT</version>
+ <name>fcapsmanager</name>
+ <packaging>pom</packaging>
+ <modelVersion>4.0.0</modelVersion>
+ <prerequisites>
+ <maven>3.1.1</maven>
+ </prerequisites>
+ <modules>
+ <module>fcaps-api</module>
+ <module>alarmmanager</module>
+ <module>countermanager</module>
+ </modules>
+ <!-- DO NOT install or deploy the repo root pom as it's only needed to initiate a build -->
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-deploy-plugin</artifactId>
+ <configuration>
+ <skip>true</skip>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-install-plugin</artifactId>
+ <configuration>
+ <skip>true</skip>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
\ No newline at end of file
<artifactId>itm-api</artifactId>
<version>${project.version}</version>
</dependency>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>alarmmanager</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>countermanager</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>fcaps-api</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>fcapsapplication-jmxapi</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>fcapsapplication-impl</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
</dependencies>
</project>
<feature version="${dlux.version}">odl-dlux-yangui</feature>
</feature>
+ <feature name='odl-genius-fcaps-framework' version='${project.version}' description='OpenDaylight :: genius :: fcapsframework'>
+ <bundle>mvn:org.opendaylight.genius/fcaps-api/{{VERSION}}</bundle>
+ <bundle>mvn:org.opendaylight.genius/alarmmanager/{{VERSION}}</bundle>
+ <bundle>mvn:org.opendaylight.genius/countermanager/{{VERSION}}</bundle>
+ </feature>
+
+ <feature name='odl-genius-fcaps-application' version='${project.version}' description='OpenDaylight :: genius :: fcapsapp'>
+ <feature version="${openflowplugin.version}">odl-openflowplugin-all</feature>
+ <bundle>mvn:org.opendaylight.genius/fcapsapplication-jmxapi/{{VERSION}}</bundle>
+ <bundle>mvn:org.opendaylight.genius/fcapsapplication-impl/{{VERSION}}</bundle>
+ <configfile finalname="etc/opendaylight/karaf/73-fcaps-app.xml">mvn:org.opendaylight.genius/fcapsapplication-impl/{{VERSION}}/xml/config
+ </configfile>
+ </feature>
+
</features>
<module>karaf</module>
<module>features</module>
<module>artifacts</module>
+ <module>fcapsmanager</module>
+ <module>fcapsapplication</module>
<!--module>it</module-->
</modules>