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