Added dumpMsgCount osgi command
[openflowplugin.git] / openflowplugin / src / main / java / org / opendaylight / openflowplugin / openflow / md / core / sal / OpenflowPluginProvider.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.openflow.md.core.sal;
9
10 import java.util.Collection;
11 import java.util.Collections;
12
13 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
14 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ConsumerContext;
15 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
16 import org.opendaylight.controller.sal.binding.api.BindingAwareProvider;
17 import org.opendaylight.openflowjava.protocol.spi.connection.SwitchConnectionProvider;
18 import org.opendaylight.openflowplugin.openflow.md.core.MDController;
19 import org.opendaylight.openflowplugin.openflow.md.core.cmd.MessageCountCommandProvider;
20 import org.opendaylight.openflowplugin.openflow.md.queue.MessageObservatory;
21 import org.opendaylight.openflowplugin.openflow.md.queue.MessageSpyCounterImpl;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
23 import org.opendaylight.yangtools.yang.binding.DataObject;
24 import org.opendaylight.yangtools.yang.binding.RpcService;
25 import org.osgi.framework.BundleContext;
26
27 /**
28  * OFPlugin provider implementation
29  */
30 public class OpenflowPluginProvider implements BindingAwareProvider {
31
32     private BindingAwareBroker broker;
33
34     private BundleContext context;
35
36     private SwitchConnectionProvider switchConnectionProvider;
37
38     private MDController mdController;
39     
40     private MessageCountCommandProvider messageCountCommandProvider;
41
42     private MessageObservatory<OfHeader, DataObject> messageCountProvider;
43     
44     public void unsetSwitchConnectionProvider() {
45         switchConnectionProvider = null;
46     }
47
48     public void setSwitchConnectionProvider(
49             SwitchConnectionProvider switchConnectionProvider) {
50         this.switchConnectionProvider = switchConnectionProvider;
51         registerProvider();
52     }
53
54     public BundleContext getContext() {
55         return context;
56     }
57
58     public void setContext(BundleContext context) {
59         this.context = context;
60     }
61
62     SalRegistrationManager registrationManager = new SalRegistrationManager();
63
64
65     @Override
66     public void onSessionInitiated(ProviderContext session) {
67         messageCountProvider = new MessageSpyCounterImpl();
68         registrationManager.onSessionInitiated(session);
69         mdController = new MDController();
70         mdController.setSwitchConnectionProvider(switchConnectionProvider);
71         mdController.setMessageSpyCounter(messageCountProvider);
72         mdController.init();
73         mdController.start();
74         messageCountCommandProvider = new MessageCountCommandProvider(context, messageCountProvider);
75         messageCountCommandProvider.onSessionInitiated(session);
76     }
77
78     @Override
79     public void onSessionInitialized(ConsumerContext session) {
80         // NOOP
81     }
82
83     @Override
84     public Collection<? extends ProviderFunctionality> getFunctionality() {
85         return Collections.emptySet();
86     }
87
88     @Override
89     public java.util.Collection<? extends RpcService> getImplementations() {
90         return Collections.emptySet();
91     }
92
93     public BindingAwareBroker getBroker() {
94         return broker;
95     }
96
97     public void setBroker(BindingAwareBroker broker) {
98         this.broker = broker;
99         registerProvider();
100     }
101
102     public void unsetBroker(BindingAwareBroker broker) {
103         this.broker = null;
104     }
105
106     private boolean hasAllDependencies(){
107         if(this.broker != null && this.switchConnectionProvider != null) {
108             return true;
109         }
110         return false;
111     }
112     private void registerProvider() {
113         if(hasAllDependencies()) {
114             this.broker.registerProvider(this,context);
115         }
116     }
117  }