0b181b7f0fc1d50d2ffed2409bd6291cd1add1cf
[openflowplugin.git] / test-common / src / main / java / org / opendaylight / openflowplugin / testcommon / DropTestRpcProvider.java
1 /**
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.openflowplugin.testcommon;
9
10 import org.opendaylight.controller.md.sal.binding.api.NotificationService;
11 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.SalFlowService;
12 import org.slf4j.Logger;
13 import org.slf4j.LoggerFactory;
14
15 /**
16  * Provides activation and deactivation of drop responder service - responds on packetIn.
17  */
18 public class DropTestRpcProvider implements AutoCloseable {
19     private static final Logger LOG = LoggerFactory.getLogger(DropTestRpcProvider.class);
20
21     private SalFlowService flowService;
22     private NotificationService notificationService;
23     private final DropTestRpcSender commiter = new DropTestRpcSender();
24     private boolean active = false;
25
26     public void setFlowService(final SalFlowService flowService) {
27         this.flowService = flowService;
28     }
29
30     public void setNotificationService(final NotificationService notificationService) {
31         this.notificationService = notificationService;
32     }
33
34     /**
35      * Activates drop responder.
36      */
37     public void start() {
38         commiter.setFlowService(flowService);
39         commiter.setNotificationService(notificationService);
40         commiter.start();
41         active = true;
42         LOG.debug("DropTestProvider Started.");
43     }
44
45     /**
46      * Returns the message counts.
47      */
48     public DropTestStats getStats() {
49         if (this.commiter != null) {
50             return commiter.getStats();
51         } else {
52             return new DropTestStats("Not initialized yet.");
53         }
54     }
55
56     /**
57      * Reset message counts.
58      */
59     public void clearStats() {
60         if (commiter != null) {
61             commiter.clearStats();
62         }
63     }
64
65     @Override
66     public void close() {
67         LOG.debug("DropTestProvider stopped.");
68         if (commiter != null) {
69             commiter.close();
70             active = false;
71         }
72     }
73
74     /**
75      * Returns the active state.
76      */
77     public boolean isActive() {
78         return active;
79     }
80 }