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