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