2 * Copyright (c) 2016, 2017 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.genius.fcapsapp;
10 import com.google.common.base.Preconditions;
11 import javax.annotation.PostConstruct;
12 import javax.annotation.PreDestroy;
13 import javax.inject.Inject;
14 import javax.inject.Singleton;
15 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
16 import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier;
17 import org.opendaylight.controller.md.sal.binding.api.NotificationService;
18 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
19 import org.opendaylight.genius.fcapsapp.performancecounter.PacketInCounterHandler;
20 import org.opendaylight.genius.fcapsapp.portinfo.PortNameMapping;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
24 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
29 public class FcapsProvider implements AutoCloseable {
30 private final DataBroker dataBroker;
31 private final NotificationService notificationService;
32 private final PacketInCounterHandler packetInCounterHandler;
33 private final NodeEventListener<FlowCapableNode> nodeEventListener;
35 public static final Logger LOG = LoggerFactory.getLogger(FcapsProvider.class);
38 * Constructor sets the services.
41 * instance of databroker
42 * @param notificationService
43 * instance of notificationservice
44 * @param packetInCounterHandler
45 * instance of PacketInCounterHandler
46 * @param nodeEventListener
47 * instance of NodeEventListener
50 public FcapsProvider(final DataBroker dataBroker, final NotificationService notificationService,
51 final PacketInCounterHandler packetInCounterHandler,
52 final NodeEventListener nodeEventListener) {
53 this.dataBroker = Preconditions.checkNotNull(dataBroker, "DataBroker can not be null!");
54 LOG.info("FcapsProvider dataBroker is set");
56 this.notificationService = Preconditions.checkNotNull(notificationService,
57 "notificationService can not be null!");
58 LOG.info("FcapsProvider notificationProviderService is set");
60 this.packetInCounterHandler = packetInCounterHandler;
61 this.nodeEventListener = nodeEventListener;
65 public void start() throws Exception {
66 PortNameMapping.registerPortMappingBean();
68 notificationService.registerNotificationListener(packetInCounterHandler);
69 LOG.info("FcapsProvider started");
74 public void close() throws Exception {
75 LOG.info("FcapsProvider closed");
78 private void registerListener() {
79 final DataTreeIdentifier<FlowCapableNode> treeId = new DataTreeIdentifier<>(LogicalDatastoreType.OPERATIONAL,
81 dataBroker.registerDataTreeChangeListener(treeId, nodeEventListener);
84 private InstanceIdentifier<FlowCapableNode> getWildCardPath() {
85 return InstanceIdentifier.create(Nodes.class).child(Node.class).augmentation(FlowCapableNode.class);