Droptest: unify packet handling
[openflowplugin.git] / drop-test / src / main / java / org / opendaylight / openflowplugin / droptest / 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.droptest;
9
10 import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
11 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.SalFlowService;
12 import org.opendaylight.yangtools.concepts.Registration;
13 import org.opendaylight.yangtools.yang.binding.NotificationListener;
14 import org.slf4j.Logger;
15 import org.slf4j.LoggerFactory;
16
17 @SuppressWarnings("all")
18 public class DropTestRpcProvider implements AutoCloseable {
19     private final static Logger LOG = LoggerFactory.getLogger(DropTestProvider.class);
20
21     private SalFlowService _flowService;
22     private NotificationProviderService _notificationService;
23     private DropTestRpcSender commiter;
24     private Registration<NotificationListener> listenerRegistration;
25
26     public SalFlowService getFlowService() {
27         return this._flowService;
28     }
29
30     public void setFlowService(final SalFlowService flowService) {
31         this._flowService = flowService;
32     }
33
34     public NotificationProviderService getNotificationService() {
35         return this._notificationService;
36     }
37
38     public void setNotificationService(final NotificationProviderService notificationService) {
39         this._notificationService = notificationService;
40     }
41
42     public void start() {
43         this.commiter = new DropTestRpcSender(this.getFlowService());
44         this.listenerRegistration = this.getNotificationService().registerNotificationListener(this.commiter);
45         LOG.debug("DropTestProvider Started.");
46     }
47
48     public DropTestStats getStats() {
49         if(this.commiter != null) {
50             return this.commiter.getStats();
51         } else {
52             return new DropTestStats("Not initialized yet.");
53         }
54     }
55
56     public void clearStats() {
57         if(this.commiter != null) {
58             this.commiter.clearStats();
59         }
60     }
61
62     @Override
63     public void close() {
64         try {
65             LOG.debug("DropTestProvider stopped.");
66             if (this.listenerRegistration != null) {
67                 this.listenerRegistration.close();
68             }
69         } catch (Exception _e) {
70             throw new Error(_e);
71         }
72     }
73 }