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