OpenDaylight Controller functional modules.
[controller.git] / opendaylight / protocol_plugins / openflow / src / main / java / org / opendaylight / controller / protocol_plugin / openflow / internal / TopologyServices.java
1
2 /*
3  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
4  *
5  * This program and the accompanying materials are made available under the
6  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
7  * and is available at http://www.eclipse.org/legal/epl-v10.html
8  */
9
10 package org.opendaylight.controller.protocol_plugin.openflow.internal;
11
12 import java.util.Dictionary;
13 import java.util.Set;
14
15 import org.apache.felix.dm.Component;
16 import org.opendaylight.controller.protocol_plugin.openflow.IRefreshInternalProvider;
17 import org.opendaylight.controller.protocol_plugin.openflow.ITopologyServiceShimListener;
18 import org.slf4j.Logger;
19 import org.slf4j.LoggerFactory;
20
21 import org.opendaylight.controller.sal.core.Edge;
22 import org.opendaylight.controller.sal.core.Property;
23 import org.opendaylight.controller.sal.core.UpdateType;
24 import org.opendaylight.controller.sal.topology.IPluginInTopologyService;
25 import org.opendaylight.controller.sal.topology.IPluginOutTopologyService;
26
27 public class TopologyServices implements ITopologyServiceShimListener,
28         IPluginInTopologyService {
29     protected static final Logger logger = LoggerFactory
30             .getLogger(TopologyServices.class);
31     private IPluginOutTopologyService salTopoService = null;
32     private IRefreshInternalProvider topoRefreshService = null;
33     private String containerName;
34
35     /**
36      * Function called by the dependency manager when all the required
37      * dependencies are satisfied
38      *
39      */
40     @SuppressWarnings("unchecked")
41     void init(Component c) {
42         logger.debug("INIT called!");
43         Dictionary<Object, Object> props = c.getServiceProperties();
44         containerName = (props != null) ? (String) props.get("containerName")
45                 : null;
46     }
47
48     /**
49      * Function called by the dependency manager when at least one
50      * dependency become unsatisfied or when the component is shutting
51      * down because for example bundle is being stopped.
52      *
53      */
54     void destroy() {
55         logger.debug("DESTROY called!");
56     }
57
58     /**
59      * Function called by dependency manager after "init ()" is called
60      * and after the services provided by the class are registered in
61      * the service registry
62      *
63      */
64     void start() {
65         logger.debug("START called!");
66     }
67
68     /**
69      * Function called by the dependency manager before the services
70      * exported by the component are unregistered, this will be
71      * followed by a "destroy ()" calls
72      *
73      */
74     void stop() {
75         logger.debug("STOP called!");
76     }
77
78     /**
79      * Retrieve SAL service IPluginOutTopologyService
80      *
81      * @param s Called by Dependency Manager as soon as the SAL
82      * service is available
83      */
84     public void setPluginOutTopologyService(IPluginOutTopologyService s) {
85         logger.debug("Setting IPluginOutTopologyService to:" + s);
86         this.salTopoService = s;
87     }
88
89     /**
90      * called when SAL service IPluginOutTopologyService is no longer available
91      *
92      * @param s Called by Dependency Manager as soon as the SAL
93      * service is unavailable
94      */
95     public void unsetPluginOutTopologyService(IPluginOutTopologyService s) {
96         if (this.salTopoService == s) {
97             logger.debug("UNSetting IPluginOutTopologyService from:" + s);
98             this.salTopoService = null;
99         }
100     }
101
102     /**
103      * Retrieve OF protocol_plugin service IRefreshInternalProvider
104      *
105      * @param s Called by Dependency Manager as soon as the SAL
106      * service is available
107      */
108     public void setRefreshInternalProvider(IRefreshInternalProvider s) {
109         logger.debug("Setting IRefreshInternalProvider to:" + s);
110         this.topoRefreshService = s;
111     }
112
113     /**
114      * called when OF protocol_plugin service IRefreshInternalProvider
115      * is no longer available
116      *
117      * @param s Called by Dependency Manager as soon as the SAL
118      * service is unavailable
119      */
120     public void unsetRefreshInternalProvider(IRefreshInternalProvider s) {
121         if (this.topoRefreshService == s) {
122             logger.debug("UNSetting IRefreshInternalProvider from:" + s);
123             this.topoRefreshService = null;
124         }
125     }
126
127     @Override
128     public void edgeUpdate(Edge edge, UpdateType type, Set<Property> props) {
129         if (this.salTopoService != null) {
130             this.salTopoService.edgeUpdate(edge, type, props);
131         }
132     }
133
134     @Override
135     public void sollicitRefresh() {
136         logger.debug("Got a request to refresh topology");
137         topoRefreshService.requestRefresh(containerName);
138     }
139
140     @Override
141     public void edgeOverUtilized(Edge edge) {
142         if (this.salTopoService != null) {
143             this.salTopoService.edgeOverUtilized(edge);
144         }
145     }
146
147     @Override
148     public void edgeUtilBackToNormal(Edge edge) {
149         if (this.salTopoService != null) {
150             this.salTopoService.edgeUtilBackToNormal(edge);
151         }
152     }
153 }