Pavlin Radoslavov | e1b37bc | 2013-10-16 03:57:06 -0700 | [diff] [blame] | 1 | package net.onrc.onos.ofcontroller.topology; |
Pavlin Radoslavov | 382b22a | 2013-01-28 09:24:04 -0800 | [diff] [blame] | 2 | |
Pavlin Radoslavov | 5d8d77e | 2013-10-18 18:49:25 -0700 | [diff] [blame] | 3 | import java.util.ArrayList; |
| 4 | import java.util.Collection; |
Pavlin Radoslavov | d7d8b79 | 2013-02-22 10:24:38 -0800 | [diff] [blame] | 5 | import java.util.HashMap; |
Pavlin Radoslavov | d7d8b79 | 2013-02-22 10:24:38 -0800 | [diff] [blame] | 6 | import java.util.Map; |
Pavlin Radoslavov | 382b22a | 2013-01-28 09:24:04 -0800 | [diff] [blame] | 7 | |
Pavlin Radoslavov | 5d8d77e | 2013-10-18 18:49:25 -0700 | [diff] [blame] | 8 | import net.floodlightcontroller.core.IFloodlightProviderService; |
| 9 | import net.floodlightcontroller.core.module.FloodlightModuleContext; |
| 10 | import net.floodlightcontroller.core.module.FloodlightModuleException; |
| 11 | import net.floodlightcontroller.core.module.IFloodlightModule; |
| 12 | import net.floodlightcontroller.core.module.IFloodlightService; |
Naoki Shiota | b32edf5 | 2013-12-12 14:09:36 -0800 | [diff] [blame] | 13 | import net.floodlightcontroller.restserver.IRestApiService; |
Pavlin Radoslavov | 5d8d77e | 2013-10-18 18:49:25 -0700 | [diff] [blame] | 14 | import net.onrc.onos.datagrid.IDatagridService; |
Pankaj Berde | 38646d6 | 2013-06-21 11:34:04 -0700 | [diff] [blame] | 15 | import net.onrc.onos.graph.GraphDBOperation; |
Pavlin Radoslavov | 5d8d77e | 2013-10-18 18:49:25 -0700 | [diff] [blame] | 16 | import net.onrc.onos.ofcontroller.floodlightlistener.INetworkGraphService; |
Naoki Shiota | b32edf5 | 2013-12-12 14:09:36 -0800 | [diff] [blame] | 17 | import net.onrc.onos.ofcontroller.topology.web.OnosTopologyWebRoutable; |
HIGUCHI Yuta | 356086e | 2013-06-12 15:21:19 -0700 | [diff] [blame] | 18 | import net.onrc.onos.ofcontroller.util.DataPath; |
Pavlin Radoslavov | 3ecd41e | 2013-10-29 14:29:30 -0700 | [diff] [blame] | 19 | import net.onrc.onos.ofcontroller.util.FlowEntry; |
| 20 | import net.onrc.onos.ofcontroller.util.FlowPath; |
| 21 | import net.onrc.onos.ofcontroller.util.Port; |
HIGUCHI Yuta | 356086e | 2013-06-12 15:21:19 -0700 | [diff] [blame] | 22 | import net.onrc.onos.ofcontroller.util.SwitchPort; |
Pavlin Radoslavov | 382b22a | 2013-01-28 09:24:04 -0800 | [diff] [blame] | 23 | |
Pankaj Berde | 1519309 | 2013-03-21 17:30:14 -0700 | [diff] [blame] | 24 | import org.slf4j.Logger; |
| 25 | import org.slf4j.LoggerFactory; |
Pavlin Radoslavov | 382b22a | 2013-01-28 09:24:04 -0800 | [diff] [blame] | 26 | |
Pavlin Radoslavov | a5f167b | 2013-03-21 11:39:27 -0700 | [diff] [blame] | 27 | /** |
Yuta HIGUCHI | e1038fb | 2013-10-30 15:35:18 -0700 | [diff] [blame] | 28 | * A class for obtaining Topology Snapshot |
| 29 | * and PathComputation. |
| 30 | * |
| 31 | * TODO: PathComputation part should be refactored out to separate class. |
Pavlin Radoslavov | c5d2fbc | 2013-06-27 18:15:56 -0700 | [diff] [blame] | 32 | */ |
Pavlin Radoslavov | 5d8d77e | 2013-10-18 18:49:25 -0700 | [diff] [blame] | 33 | public class TopologyManager implements IFloodlightModule, |
| 34 | ITopologyNetService { |
Yuta HIGUCHI | 6ac8d18 | 2013-10-22 15:24:56 -0700 | [diff] [blame] | 35 | private final static Logger log = LoggerFactory.getLogger(TopologyManager.class); |
Pavlin Radoslavov | 5d8d77e | 2013-10-18 18:49:25 -0700 | [diff] [blame] | 36 | protected IFloodlightProviderService floodlightProvider; |
| 37 | |
Pavlin Radoslavov | 15954d4 | 2013-10-19 15:29:04 -0700 | [diff] [blame] | 38 | protected GraphDBOperation dbHandler; |
Naoki Shiota | b32edf5 | 2013-12-12 14:09:36 -0800 | [diff] [blame] | 39 | protected IRestApiService restApi; |
Pavlin Radoslavov | d7d8b79 | 2013-02-22 10:24:38 -0800 | [diff] [blame] | 40 | |
Pavlin Radoslavov | ddd01ba | 2013-07-03 15:40:44 -0700 | [diff] [blame] | 41 | |
Pavlin Radoslavov | c5d2fbc | 2013-06-27 18:15:56 -0700 | [diff] [blame] | 42 | /** |
Pavlin Radoslavov | ddd01ba | 2013-07-03 15:40:44 -0700 | [diff] [blame] | 43 | * Default constructor. |
Pavlin Radoslavov | c5d2fbc | 2013-06-27 18:15:56 -0700 | [diff] [blame] | 44 | */ |
Pavlin Radoslavov | e1b37bc | 2013-10-16 03:57:06 -0700 | [diff] [blame] | 45 | public TopologyManager() { |
Pavlin Radoslavov | d7d8b79 | 2013-02-22 10:24:38 -0800 | [diff] [blame] | 46 | } |
| 47 | |
Pavlin Radoslavov | c5d2fbc | 2013-06-27 18:15:56 -0700 | [diff] [blame] | 48 | /** |
Pavlin Radoslavov | ddd01ba | 2013-07-03 15:40:44 -0700 | [diff] [blame] | 49 | * Constructor for given database configuration file. |
Pavlin Radoslavov | c5d2fbc | 2013-06-27 18:15:56 -0700 | [diff] [blame] | 50 | * |
Pavlin Radoslavov | ddd01ba | 2013-07-03 15:40:44 -0700 | [diff] [blame] | 51 | * @param config the database configuration file to use for |
| 52 | * the initialization. |
Pavlin Radoslavov | c5d2fbc | 2013-06-27 18:15:56 -0700 | [diff] [blame] | 53 | */ |
Pavlin Radoslavov | e1b37bc | 2013-10-16 03:57:06 -0700 | [diff] [blame] | 54 | public TopologyManager(String config) { |
Pavlin Radoslavov | ddd01ba | 2013-07-03 15:40:44 -0700 | [diff] [blame] | 55 | this.init(config); |
Pavlin Radoslavov | d7d8b79 | 2013-02-22 10:24:38 -0800 | [diff] [blame] | 56 | } |
| 57 | |
Pavlin Radoslavov | c5d2fbc | 2013-06-27 18:15:56 -0700 | [diff] [blame] | 58 | /** |
Pavlin Radoslavov | 0367d35 | 2013-10-19 11:04:43 -0700 | [diff] [blame] | 59 | * Constructor for a given database operation handler. |
Pavlin Radoslavov | 5d8d77e | 2013-10-18 18:49:25 -0700 | [diff] [blame] | 60 | * |
Pavlin Radoslavov | 15954d4 | 2013-10-19 15:29:04 -0700 | [diff] [blame] | 61 | * @param dbHandler the database operation handler to use for the |
Pavlin Radoslavov | 5d8d77e | 2013-10-18 18:49:25 -0700 | [diff] [blame] | 62 | * initialization. |
| 63 | */ |
Pavlin Radoslavov | 15954d4 | 2013-10-19 15:29:04 -0700 | [diff] [blame] | 64 | public TopologyManager(GraphDBOperation dbHandler) { |
| 65 | this.dbHandler = dbHandler; |
Pavlin Radoslavov | 5d8d77e | 2013-10-18 18:49:25 -0700 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | /** |
Pavlin Radoslavov | c5d2fbc | 2013-06-27 18:15:56 -0700 | [diff] [blame] | 69 | * Init the module. |
| 70 | * |
Pavlin Radoslavov | ddd01ba | 2013-07-03 15:40:44 -0700 | [diff] [blame] | 71 | * @param config the database configuration file to use for |
| 72 | * the initialization. |
Pavlin Radoslavov | c5d2fbc | 2013-06-27 18:15:56 -0700 | [diff] [blame] | 73 | */ |
Pavlin Radoslavov | ddd01ba | 2013-07-03 15:40:44 -0700 | [diff] [blame] | 74 | public void init(String config) { |
| 75 | try { |
Pavlin Radoslavov | 15954d4 | 2013-10-19 15:29:04 -0700 | [diff] [blame] | 76 | dbHandler = new GraphDBOperation(config); |
Pavlin Radoslavov | ddd01ba | 2013-07-03 15:40:44 -0700 | [diff] [blame] | 77 | } catch (Exception e) { |
| 78 | log.error(e.getMessage()); |
| 79 | } |
Pavlin Radoslavov | d7d8b79 | 2013-02-22 10:24:38 -0800 | [diff] [blame] | 80 | } |
| 81 | |
Pavlin Radoslavov | c5d2fbc | 2013-06-27 18:15:56 -0700 | [diff] [blame] | 82 | /** |
Pavlin Radoslavov | 5d8d77e | 2013-10-18 18:49:25 -0700 | [diff] [blame] | 83 | * Shutdown the Topology Manager operation. |
| 84 | */ |
Yuta HIGUCHI | 67a7a3e | 2014-01-03 14:51:34 -0800 | [diff] [blame] | 85 | @Override |
| 86 | protected void finalize() { |
Pavlin Radoslavov | 5d8d77e | 2013-10-18 18:49:25 -0700 | [diff] [blame] | 87 | close(); |
| 88 | } |
| 89 | |
| 90 | /** |
Pavlin Radoslavov | ddd01ba | 2013-07-03 15:40:44 -0700 | [diff] [blame] | 91 | * Close the service. It will close the corresponding database connection. |
Pavlin Radoslavov | c5d2fbc | 2013-06-27 18:15:56 -0700 | [diff] [blame] | 92 | */ |
Pavlin Radoslavov | ddd01ba | 2013-07-03 15:40:44 -0700 | [diff] [blame] | 93 | public void close() { |
Pavlin Radoslavov | 15954d4 | 2013-10-19 15:29:04 -0700 | [diff] [blame] | 94 | dbHandler.close(); |
Pavlin Radoslavov | d7d8b79 | 2013-02-22 10:24:38 -0800 | [diff] [blame] | 95 | } |
Pavlin Radoslavov | 382b22a | 2013-01-28 09:24:04 -0800 | [diff] [blame] | 96 | |
Pavlin Radoslavov | c5d2fbc | 2013-06-27 18:15:56 -0700 | [diff] [blame] | 97 | /** |
Pavlin Radoslavov | 5d8d77e | 2013-10-18 18:49:25 -0700 | [diff] [blame] | 98 | * Get the collection of offered module services. |
Pavlin Radoslavov | c5d2fbc | 2013-06-27 18:15:56 -0700 | [diff] [blame] | 99 | * |
Pavlin Radoslavov | 5d8d77e | 2013-10-18 18:49:25 -0700 | [diff] [blame] | 100 | * @return the collection of offered module services. |
Pavlin Radoslavov | c5d2fbc | 2013-06-27 18:15:56 -0700 | [diff] [blame] | 101 | */ |
Pavlin Radoslavov | 5d8d77e | 2013-10-18 18:49:25 -0700 | [diff] [blame] | 102 | @Override |
| 103 | public Collection<Class<? extends IFloodlightService>> getModuleServices() { |
Yuta HIGUCHI | 67a7a3e | 2014-01-03 14:51:34 -0800 | [diff] [blame] | 104 | Collection<Class<? extends IFloodlightService>> l = |
Pavlin Radoslavov | 5d8d77e | 2013-10-18 18:49:25 -0700 | [diff] [blame] | 105 | new ArrayList<Class<? extends IFloodlightService>>(); |
| 106 | l.add(ITopologyNetService.class); |
| 107 | return l; |
| 108 | } |
| 109 | |
| 110 | /** |
| 111 | * Get the collection of implemented services. |
| 112 | * |
| 113 | * @return the collection of implemented services. |
| 114 | */ |
| 115 | @Override |
Yuta HIGUCHI | 67a7a3e | 2014-01-03 14:51:34 -0800 | [diff] [blame] | 116 | public Map<Class<? extends IFloodlightService>, IFloodlightService> |
Pavlin Radoslavov | 5d8d77e | 2013-10-18 18:49:25 -0700 | [diff] [blame] | 117 | getServiceImpls() { |
| 118 | Map<Class<? extends IFloodlightService>, |
Yuta HIGUCHI | 67a7a3e | 2014-01-03 14:51:34 -0800 | [diff] [blame] | 119 | IFloodlightService> m = |
Pavlin Radoslavov | 5d8d77e | 2013-10-18 18:49:25 -0700 | [diff] [blame] | 120 | new HashMap<Class<? extends IFloodlightService>, |
| 121 | IFloodlightService>(); |
| 122 | m.put(ITopologyNetService.class, this); |
| 123 | return m; |
| 124 | } |
| 125 | |
| 126 | /** |
| 127 | * Get the collection of modules this module depends on. |
| 128 | * |
| 129 | * @return the collection of modules this module depends on. |
| 130 | */ |
| 131 | @Override |
Yuta HIGUCHI | 67a7a3e | 2014-01-03 14:51:34 -0800 | [diff] [blame] | 132 | public Collection<Class<? extends IFloodlightService>> |
Pavlin Radoslavov | 5d8d77e | 2013-10-18 18:49:25 -0700 | [diff] [blame] | 133 | getModuleDependencies() { |
| 134 | Collection<Class<? extends IFloodlightService>> l = |
| 135 | new ArrayList<Class<? extends IFloodlightService>>(); |
| 136 | l.add(IFloodlightProviderService.class); |
| 137 | l.add(INetworkGraphService.class); |
| 138 | l.add(IDatagridService.class); |
| 139 | return l; |
| 140 | } |
| 141 | |
| 142 | /** |
| 143 | * Initialize the module. |
| 144 | * |
| 145 | * @param context the module context to use for the initialization. |
| 146 | */ |
| 147 | @Override |
| 148 | public void init(FloodlightModuleContext context) |
| 149 | throws FloodlightModuleException { |
| 150 | floodlightProvider = context.getServiceImpl(IFloodlightProviderService.class); |
Naoki Shiota | b32edf5 | 2013-12-12 14:09:36 -0800 | [diff] [blame] | 151 | restApi = context.getServiceImpl(IRestApiService.class); |
Pavlin Radoslavov | 5d8d77e | 2013-10-18 18:49:25 -0700 | [diff] [blame] | 152 | |
| 153 | String conf = ""; |
| 154 | this.init(conf); |
| 155 | } |
| 156 | |
| 157 | /** |
| 158 | * Startup module operation. |
| 159 | * |
| 160 | * @param context the module context to use for the startup. |
| 161 | */ |
| 162 | @Override |
| 163 | public void startUp(FloodlightModuleContext context) { |
Naoki Shiota | b32edf5 | 2013-12-12 14:09:36 -0800 | [diff] [blame] | 164 | restApi.addRestletRoutable(new OnosTopologyWebRoutable()); |
Pavlin Radoslavov | 5d8d77e | 2013-10-18 18:49:25 -0700 | [diff] [blame] | 165 | |
Pavlin Radoslavov | cec899a | 2013-06-27 15:47:50 -0700 | [diff] [blame] | 166 | } |
Pavlin Radoslavov | 382b22a | 2013-01-28 09:24:04 -0800 | [diff] [blame] | 167 | |
Pavlin Radoslavov | a5f167b | 2013-03-21 11:39:27 -0700 | [diff] [blame] | 168 | /** |
| 169 | * Fetch the Switch and Ports info from the Titan Graph |
Pavlin Radoslavov | 9556b14 | 2013-05-20 21:49:04 +0000 | [diff] [blame] | 170 | * and return it for fast access during the shortest path |
Pavlin Radoslavov | a5f167b | 2013-03-21 11:39:27 -0700 | [diff] [blame] | 171 | * computation. |
| 172 | * |
Pavlin Radoslavov | 15954d4 | 2013-10-19 15:29:04 -0700 | [diff] [blame] | 173 | * After fetching the state, method @ref getTopologyShortestPath() |
Pavlin Radoslavov | a5f167b | 2013-03-21 11:39:27 -0700 | [diff] [blame] | 174 | * can be used for fast shortest path computation. |
| 175 | * |
| 176 | * Note: There is certain cost to fetch the state, hence it should |
| 177 | * be used only when there is a large number of shortest path |
| 178 | * computations that need to be done on the same topology. |
Pavlin Radoslavov | 15954d4 | 2013-10-19 15:29:04 -0700 | [diff] [blame] | 179 | * Typically, a single call to @ref newDatabaseTopology() |
Pavlin Radoslavov | a5f167b | 2013-03-21 11:39:27 -0700 | [diff] [blame] | 180 | * should be followed by a large number of calls to |
Pavlin Radoslavov | 15954d4 | 2013-10-19 15:29:04 -0700 | [diff] [blame] | 181 | * method @ref getTopologyShortestPath(). |
| 182 | * After the last @ref getTopologyShortestPath() call, |
| 183 | * method @ref dropTopology() should be used to release |
Pavlin Radoslavov | a5f167b | 2013-03-21 11:39:27 -0700 | [diff] [blame] | 184 | * the internal state that is not needed anymore: |
| 185 | * |
Pavlin Radoslavov | 15954d4 | 2013-10-19 15:29:04 -0700 | [diff] [blame] | 186 | * Topology topology = topologyManager.newDatabaseTopology(); |
Pavlin Radoslavov | a5f167b | 2013-03-21 11:39:27 -0700 | [diff] [blame] | 187 | * for (int i = 0; i < 10000; i++) { |
Pavlin Radoslavov | 15954d4 | 2013-10-19 15:29:04 -0700 | [diff] [blame] | 188 | * dataPath = topologyManager.getTopologyShortestPath(topology, ...); |
Pavlin Radoslavov | a5f167b | 2013-03-21 11:39:27 -0700 | [diff] [blame] | 189 | * ... |
| 190 | * } |
Pavlin Radoslavov | 15954d4 | 2013-10-19 15:29:04 -0700 | [diff] [blame] | 191 | * topologyManager.dropTopology(shortestPathTopo); |
Pavlin Radoslavov | 9556b14 | 2013-05-20 21:49:04 +0000 | [diff] [blame] | 192 | * |
Pavlin Radoslavov | 15954d4 | 2013-10-19 15:29:04 -0700 | [diff] [blame] | 193 | * @return the allocated topology handler. |
Pavlin Radoslavov | a5f167b | 2013-03-21 11:39:27 -0700 | [diff] [blame] | 194 | */ |
Yuta HIGUCHI | 67a7a3e | 2014-01-03 14:51:34 -0800 | [diff] [blame] | 195 | @Override |
Pavlin Radoslavov | 15954d4 | 2013-10-19 15:29:04 -0700 | [diff] [blame] | 196 | public Topology newDatabaseTopology() { |
| 197 | Topology topology = new Topology(); |
| 198 | topology.readFromDatabase(dbHandler); |
Pavlin Radoslavov | a5f167b | 2013-03-21 11:39:27 -0700 | [diff] [blame] | 199 | |
Pavlin Radoslavov | 15954d4 | 2013-10-19 15:29:04 -0700 | [diff] [blame] | 200 | return topology; |
Pavlin Radoslavov | a5f167b | 2013-03-21 11:39:27 -0700 | [diff] [blame] | 201 | } |
| 202 | |
| 203 | /** |
Pavlin Radoslavov | 15954d4 | 2013-10-19 15:29:04 -0700 | [diff] [blame] | 204 | * Release the topology that was populated by |
| 205 | * method @ref newDatabaseTopology(). |
Pavlin Radoslavov | a5f167b | 2013-03-21 11:39:27 -0700 | [diff] [blame] | 206 | * |
Pavlin Radoslavov | 15954d4 | 2013-10-19 15:29:04 -0700 | [diff] [blame] | 207 | * See the documentation for method @ref newDatabaseTopology() |
Pavlin Radoslavov | a5f167b | 2013-03-21 11:39:27 -0700 | [diff] [blame] | 208 | * for additional information and usage. |
Pavlin Radoslavov | 9556b14 | 2013-05-20 21:49:04 +0000 | [diff] [blame] | 209 | * |
Pavlin Radoslavov | 15954d4 | 2013-10-19 15:29:04 -0700 | [diff] [blame] | 210 | * @param topology the topology to release. |
Pavlin Radoslavov | a5f167b | 2013-03-21 11:39:27 -0700 | [diff] [blame] | 211 | */ |
Yuta HIGUCHI | 67a7a3e | 2014-01-03 14:51:34 -0800 | [diff] [blame] | 212 | @Override |
Pavlin Radoslavov | 15954d4 | 2013-10-19 15:29:04 -0700 | [diff] [blame] | 213 | public void dropTopology(Topology topology) { |
| 214 | topology = null; |
Pavlin Radoslavov | a5f167b | 2013-03-21 11:39:27 -0700 | [diff] [blame] | 215 | } |
| 216 | |
| 217 | /** |
Pavlin Radoslavov | 3ecd41e | 2013-10-29 14:29:30 -0700 | [diff] [blame] | 218 | * Compute the network path for a Flow. |
| 219 | * |
| 220 | * @param topology the topology handler to use. |
| 221 | * @param flowPath the Flow to compute the network path for. |
| 222 | * @return the data path with the computed path if found, otherwise null. |
| 223 | */ |
| 224 | public static DataPath computeNetworkPath(Topology topology, |
| 225 | FlowPath flowPath) { |
| 226 | // |
| 227 | // Compute the network path based on the desired Flow Path type |
| 228 | // |
| 229 | switch (flowPath.flowPathType()) { |
| 230 | case FP_TYPE_SHORTEST_PATH: { |
| 231 | SwitchPort src = flowPath.dataPath().srcPort(); |
| 232 | SwitchPort dest = flowPath.dataPath().dstPort(); |
| 233 | return ShortestPath.getTopologyShortestPath(topology, src, dest); |
| 234 | } |
Pavlin Radoslavov | 4839f6d | 2013-12-11 12:49:45 -0800 | [diff] [blame] | 235 | |
Pavlin Radoslavov | 3ecd41e | 2013-10-29 14:29:30 -0700 | [diff] [blame] | 236 | case FP_TYPE_EXPLICIT_PATH: |
| 237 | return flowPath.dataPath(); |
Pavlin Radoslavov | 4839f6d | 2013-12-11 12:49:45 -0800 | [diff] [blame] | 238 | |
| 239 | case FP_TYPE_UNKNOWN: |
| 240 | return null; |
Pavlin Radoslavov | 3ecd41e | 2013-10-29 14:29:30 -0700 | [diff] [blame] | 241 | } |
Pavlin Radoslavov | 4839f6d | 2013-12-11 12:49:45 -0800 | [diff] [blame] | 242 | |
| 243 | return null; |
Pavlin Radoslavov | 3ecd41e | 2013-10-29 14:29:30 -0700 | [diff] [blame] | 244 | } |
| 245 | |
| 246 | /** |
| 247 | * Test whether two Flow Entries represent same points in a data path. |
| 248 | * |
| 249 | * NOTE: Two Flow Entries represent same points in a data path if |
| 250 | * the Switch DPID, incoming port and outgoing port are same. |
| 251 | * |
| 252 | * NOTE: This method is specialized for shortest-path unicast paths, |
| 253 | * and probably should be moved somewhere else. |
| 254 | * |
| 255 | * @param oldFlowEntry the first Flow Entry to compare. |
| 256 | * @param newFlowEntry the second Flow Entry to compare. |
| 257 | * @return true if the two Flow Entries represent same points in a |
| 258 | * data path, otherwise false. |
| 259 | */ |
| 260 | public static boolean isSameFlowEntryDataPath(FlowEntry oldFlowEntry, |
| 261 | FlowEntry newFlowEntry) { |
| 262 | // Test the DPID |
| 263 | if (oldFlowEntry.dpid().value() != newFlowEntry.dpid().value()) |
| 264 | return false; |
| 265 | |
| 266 | // Test the inPort |
| 267 | do { |
| 268 | Port oldPort = oldFlowEntry.inPort(); |
| 269 | Port newPort = newFlowEntry.inPort(); |
| 270 | if ((oldPort != null) && (newPort != null) && |
| 271 | (oldPort.value() == newPort.value())) { |
| 272 | break; |
| 273 | } |
| 274 | if ((oldPort == null) && (newPort == null)) |
| 275 | break; |
| 276 | return false; // inPort is different |
| 277 | } while (false); |
| 278 | |
| 279 | // Test the outPort |
| 280 | do { |
| 281 | Port oldPort = oldFlowEntry.outPort(); |
| 282 | Port newPort = newFlowEntry.outPort(); |
| 283 | if ((oldPort != null) && (newPort != null) && |
| 284 | (oldPort.value() == newPort.value())) { |
| 285 | break; |
| 286 | } |
| 287 | if ((oldPort == null) && (newPort == null)) |
| 288 | break; |
| 289 | return false; // outPort is different |
| 290 | } while (false); |
| 291 | |
| 292 | return true; |
| 293 | } |
| 294 | |
| 295 | /** |
Pavlin Radoslavov | a5f167b | 2013-03-21 11:39:27 -0700 | [diff] [blame] | 296 | * Get the shortest path from a source to a destination by |
| 297 | * using the pre-populated local topology state prepared |
Pavlin Radoslavov | 15954d4 | 2013-10-19 15:29:04 -0700 | [diff] [blame] | 298 | * by method @ref newDatabaseTopology(). |
Pavlin Radoslavov | a5f167b | 2013-03-21 11:39:27 -0700 | [diff] [blame] | 299 | * |
Pavlin Radoslavov | 15954d4 | 2013-10-19 15:29:04 -0700 | [diff] [blame] | 300 | * See the documentation for method @ref newDatabaseTopology() |
Pavlin Radoslavov | a5f167b | 2013-03-21 11:39:27 -0700 | [diff] [blame] | 301 | * for additional information and usage. |
| 302 | * |
Pavlin Radoslavov | 15954d4 | 2013-10-19 15:29:04 -0700 | [diff] [blame] | 303 | * @param topology the topology handler to use. |
Pavlin Radoslavov | a5f167b | 2013-03-21 11:39:27 -0700 | [diff] [blame] | 304 | * @param src the source in the shortest path computation. |
| 305 | * @param dest the destination in the shortest path computation. |
| 306 | * @return the data path with the computed shortest path if |
| 307 | * found, otherwise null. |
| 308 | */ |
Yuta HIGUCHI | 67a7a3e | 2014-01-03 14:51:34 -0800 | [diff] [blame] | 309 | @Override |
Pavlin Radoslavov | 15954d4 | 2013-10-19 15:29:04 -0700 | [diff] [blame] | 310 | public DataPath getTopologyShortestPath(Topology topology, |
| 311 | SwitchPort src, SwitchPort dest) { |
| 312 | return ShortestPath.getTopologyShortestPath(topology, src, dest); |
Pavlin Radoslavov | a5f167b | 2013-03-21 11:39:27 -0700 | [diff] [blame] | 313 | } |
| 314 | |
| 315 | /** |
Pavlin Radoslavov | 15954d4 | 2013-10-19 15:29:04 -0700 | [diff] [blame] | 316 | * Get the shortest path from a source to a destination by using |
| 317 | * the underlying database. |
Pavlin Radoslavov | a5f167b | 2013-03-21 11:39:27 -0700 | [diff] [blame] | 318 | * |
| 319 | * @param src the source in the shortest path computation. |
| 320 | * @param dest the destination in the shortest path computation. |
| 321 | * @return the data path with the computed shortest path if |
| 322 | * found, otherwise null. |
| 323 | */ |
Pavlin Radoslavov | f34c290 | 2013-02-22 10:33:34 -0800 | [diff] [blame] | 324 | @Override |
Pavlin Radoslavov | 15954d4 | 2013-10-19 15:29:04 -0700 | [diff] [blame] | 325 | public DataPath getDatabaseShortestPath(SwitchPort src, SwitchPort dest) { |
| 326 | return ShortestPath.getDatabaseShortestPath(dbHandler, src, dest); |
Pavlin Radoslavov | f34c290 | 2013-02-22 10:33:34 -0800 | [diff] [blame] | 327 | } |
| 328 | |
Pavlin Radoslavov | a5f167b | 2013-03-21 11:39:27 -0700 | [diff] [blame] | 329 | /** |
| 330 | * Test whether a route exists from a source to a destination. |
| 331 | * |
| 332 | * @param src the source node for the test. |
| 333 | * @param dest the destination node for the test. |
| 334 | * @return true if a route exists, otherwise false. |
| 335 | */ |
Pavlin Radoslavov | f34c290 | 2013-02-22 10:33:34 -0800 | [diff] [blame] | 336 | @Override |
Pavlin Radoslavov | f83aa44 | 2013-02-26 14:09:01 -0800 | [diff] [blame] | 337 | public Boolean routeExists(SwitchPort src, SwitchPort dest) { |
Pavlin Radoslavov | 15954d4 | 2013-10-19 15:29:04 -0700 | [diff] [blame] | 338 | DataPath dataPath = getDatabaseShortestPath(src, dest); |
Pavlin Radoslavov | a5f167b | 2013-03-21 11:39:27 -0700 | [diff] [blame] | 339 | return (dataPath != null); |
Pavlin Radoslavov | f34c290 | 2013-02-22 10:33:34 -0800 | [diff] [blame] | 340 | } |
Pavlin Radoslavov | 382b22a | 2013-01-28 09:24:04 -0800 | [diff] [blame] | 341 | } |