HIGUCHI Yuta | 60a1014 | 2013-06-14 15:50:10 -0700 | [diff] [blame] | 1 | package net.onrc.onos.ofcontroller.flowmanager; |
Pavlin Radoslavov | 9e5344c | 2013-02-18 09:58:30 -0800 | [diff] [blame] | 2 | |
| 3 | import java.util.ArrayList; |
| 4 | import java.util.Collection; |
| 5 | import java.util.HashMap; |
Masayoshi Kobayashi | c9da09e | 2013-03-26 20:52:02 +0000 | [diff] [blame] | 6 | import java.util.LinkedList; |
Pavlin Radoslavov | ab3f886 | 2013-12-04 18:35:53 -0800 | [diff] [blame] | 7 | import java.util.List; |
Pavlin Radoslavov | 9e5344c | 2013-02-18 09:58:30 -0800 | [diff] [blame] | 8 | import java.util.Map; |
Pavlin Radoslavov | 0b22d0e | 2013-04-02 01:12:46 +0000 | [diff] [blame] | 9 | import java.util.Random; |
Pavlin Radoslavov | 5321980 | 2013-12-06 11:02:04 -0800 | [diff] [blame] | 10 | import java.util.SortedMap; |
Pavlin Radoslavov | 584bd11 | 2013-11-21 20:59:33 -0800 | [diff] [blame] | 11 | import java.util.concurrent.BlockingQueue; |
Pavlin Radoslavov | 584bd11 | 2013-11-21 20:59:33 -0800 | [diff] [blame] | 12 | import java.util.concurrent.LinkedBlockingQueue; |
Pavlin Radoslavov | 9e5344c | 2013-02-18 09:58:30 -0800 | [diff] [blame] | 13 | |
Pavlin Radoslavov | b6f5354 | 2013-03-01 16:02:14 -0800 | [diff] [blame] | 14 | import net.floodlightcontroller.core.IFloodlightProviderService; |
Pavlin Radoslavov | b6f5354 | 2013-03-01 16:02:14 -0800 | [diff] [blame] | 15 | import net.floodlightcontroller.core.IOFSwitch; |
Pavlin Radoslavov | 9e5344c | 2013-02-18 09:58:30 -0800 | [diff] [blame] | 16 | import net.floodlightcontroller.core.module.FloodlightModuleContext; |
| 17 | import net.floodlightcontroller.core.module.FloodlightModuleException; |
| 18 | import net.floodlightcontroller.core.module.IFloodlightModule; |
| 19 | import net.floodlightcontroller.core.module.IFloodlightService; |
Pavlin Radoslavov | 9e5344c | 2013-02-18 09:58:30 -0800 | [diff] [blame] | 20 | import net.floodlightcontroller.restserver.IRestApiService; |
Pavlin Radoslavov | 0537827 | 2013-10-19 23:23:05 -0700 | [diff] [blame] | 21 | import net.onrc.onos.datagrid.IDatagridService; |
Pankaj Berde | 38646d6 | 2013-06-21 11:34:04 -0700 | [diff] [blame] | 22 | import net.onrc.onos.graph.GraphDBOperation; |
HIGUCHI Yuta | 2051490 | 2013-06-12 11:24:16 -0700 | [diff] [blame] | 23 | import net.onrc.onos.ofcontroller.core.INetMapStorage; |
Pavlin Radoslavov | e9a3ef9 | 2013-10-18 18:46:45 -0700 | [diff] [blame] | 24 | import net.onrc.onos.ofcontroller.floodlightlistener.INetworkGraphService; |
HIGUCHI Yuta | 60a1014 | 2013-06-14 15:50:10 -0700 | [diff] [blame] | 25 | import net.onrc.onos.ofcontroller.flowmanager.web.FlowWebRoutable; |
Brian O'Connor | 8c166a7 | 2013-11-14 18:41:48 -0800 | [diff] [blame] | 26 | import net.onrc.onos.ofcontroller.flowprogrammer.IFlowPusherService; |
Pavlin Radoslavov | c086266 | 2013-12-10 15:31:49 -0800 | [diff] [blame] | 27 | import net.onrc.onos.ofcontroller.forwarding.IForwardingService; |
Pavlin Radoslavov | 15954d4 | 2013-10-19 15:29:04 -0700 | [diff] [blame] | 28 | import net.onrc.onos.ofcontroller.topology.Topology; |
Pavlin Radoslavov | 63e4260 | 2013-12-12 12:54:05 -0800 | [diff] [blame] | 29 | import net.onrc.onos.ofcontroller.util.Dpid; |
| 30 | import net.onrc.onos.ofcontroller.util.FlowEntry; |
| 31 | import net.onrc.onos.ofcontroller.util.FlowEntrySwitchState; |
| 32 | import net.onrc.onos.ofcontroller.util.FlowEntryUserState; |
| 33 | import net.onrc.onos.ofcontroller.util.FlowEntryId; |
| 34 | import net.onrc.onos.ofcontroller.util.FlowId; |
| 35 | import net.onrc.onos.ofcontroller.util.FlowPath; |
| 36 | import net.onrc.onos.ofcontroller.util.FlowPathUserState; |
| 37 | import net.onrc.onos.ofcontroller.util.Pair; |
Pavlin Radoslavov | da8d723 | 2013-12-12 12:48:14 -0800 | [diff] [blame] | 38 | import net.onrc.onos.ofcontroller.util.serializers.KryoFactory; |
| 39 | |
Pavlin Radoslavov | 262e683 | 2013-12-18 14:37:35 -0800 | [diff] [blame] | 40 | import com.thinkaurelius.titan.core.TitanException; |
| 41 | |
Pavlin Radoslavov | da8d723 | 2013-12-12 12:48:14 -0800 | [diff] [blame] | 42 | import com.esotericsoftware.kryo2.Kryo; |
Pavlin Radoslavov | b6f5354 | 2013-03-01 16:02:14 -0800 | [diff] [blame] | 43 | |
Pavlin Radoslavov | 9e5344c | 2013-02-18 09:58:30 -0800 | [diff] [blame] | 44 | import org.slf4j.Logger; |
| 45 | import org.slf4j.LoggerFactory; |
| 46 | |
admin | 944ef4f | 2013-10-08 17:48:37 -0700 | [diff] [blame] | 47 | /** |
HIGUCHI Yuta | eb567aa | 2013-10-08 19:27:35 -0700 | [diff] [blame] | 48 | * Flow Manager class for handling the network flows. |
admin | 944ef4f | 2013-10-08 17:48:37 -0700 | [diff] [blame] | 49 | */ |
Pavlin Radoslavov | 5adf152 | 2013-04-04 17:43:41 -0700 | [diff] [blame] | 50 | public class FlowManager implements IFloodlightModule, IFlowService, INetMapStorage { |
Pavlin Radoslavov | 8252fee | 2014-01-07 17:24:29 -0800 | [diff] [blame] | 51 | |
Pavlin Radoslavov | db1f91c | 2014-01-08 16:04:17 -0800 | [diff] [blame] | 52 | private boolean enableOnrc2014MeasurementsFlows = true; |
Pavlin Radoslavov | 8252fee | 2014-01-07 17:24:29 -0800 | [diff] [blame] | 53 | |
Pavlin Radoslavov | bc96ae1 | 2013-11-05 08:44:02 -0800 | [diff] [blame] | 54 | protected GraphDBOperation dbHandlerApi; |
| 55 | protected GraphDBOperation dbHandlerInner; |
Pavlin Radoslavov | 9e5344c | 2013-02-18 09:58:30 -0800 | [diff] [blame] | 56 | |
Jonathan Hart | 50a9498 | 2013-04-10 14:49:51 -0700 | [diff] [blame] | 57 | protected volatile IFloodlightProviderService floodlightProvider; |
Pavlin Radoslavov | 0537827 | 2013-10-19 23:23:05 -0700 | [diff] [blame] | 58 | protected volatile IDatagridService datagridService; |
| 59 | protected IRestApiService restApi; |
Pavlin Radoslavov | 571cff9 | 2013-03-20 02:01:32 -0700 | [diff] [blame] | 60 | protected FloodlightModuleContext context; |
Pavlin Radoslavov | 9a85902 | 2013-10-30 10:08:24 -0700 | [diff] [blame] | 61 | protected FlowEventHandler flowEventHandler; |
Pavlin Radoslavov | b6f5354 | 2013-03-01 16:02:14 -0800 | [diff] [blame] | 62 | |
Brian O'Connor | 8c166a7 | 2013-11-14 18:41:48 -0800 | [diff] [blame] | 63 | protected IFlowPusherService pusher; |
Pavlin Radoslavov | 7208e9a | 2013-12-11 14:31:07 -0800 | [diff] [blame] | 64 | protected IForwardingService forwardingService; |
Pavlin Radoslavov | da8d723 | 2013-12-12 12:48:14 -0800 | [diff] [blame] | 65 | |
| 66 | private KryoFactory kryoFactory = new KryoFactory(); |
| 67 | |
Pavlin Radoslavov | 0b22d0e | 2013-04-02 01:12:46 +0000 | [diff] [blame] | 68 | // Flow Entry ID generation state |
| 69 | private static Random randomGenerator = new Random(); |
| 70 | private static int nextFlowEntryIdPrefix = 0; |
| 71 | private static int nextFlowEntryIdSuffix = 0; |
Pavlin Radoslavov | 0b22d0e | 2013-04-02 01:12:46 +0000 | [diff] [blame] | 72 | |
Pavlin Radoslavov | 9e5344c | 2013-02-18 09:58:30 -0800 | [diff] [blame] | 73 | /** The logger. */ |
Yuta HIGUCHI | 6ac8d18 | 2013-10-22 15:24:56 -0700 | [diff] [blame] | 74 | private final static Logger log = LoggerFactory.getLogger(FlowManager.class); |
Pavlin Radoslavov | b6f5354 | 2013-03-01 16:02:14 -0800 | [diff] [blame] | 75 | |
Pavlin Radoslavov | 584bd11 | 2013-11-21 20:59:33 -0800 | [diff] [blame] | 76 | // The queue to write Flow Entries to the database |
Pavlin Radoslavov | 2fca8d1 | 2013-12-04 09:39:06 -0800 | [diff] [blame] | 77 | private BlockingQueue<FlowPath> flowPathsToDatabaseQueue = |
| 78 | new LinkedBlockingQueue<FlowPath>(); |
Pavlin Radoslavov | 584bd11 | 2013-11-21 20:59:33 -0800 | [diff] [blame] | 79 | FlowDatabaseWriter flowDatabaseWriter; |
| 80 | |
admin | 944ef4f | 2013-10-08 17:48:37 -0700 | [diff] [blame] | 81 | /** |
| 82 | * Initialize the Flow Manager. |
| 83 | * |
| 84 | * @param conf the Graph Database configuration string. |
| 85 | */ |
Pavlin Radoslavov | b6f5354 | 2013-03-01 16:02:14 -0800 | [diff] [blame] | 86 | @Override |
| 87 | public void init(String conf) { |
Pavlin Radoslavov | bc96ae1 | 2013-11-05 08:44:02 -0800 | [diff] [blame] | 88 | dbHandlerApi = new GraphDBOperation(conf); |
| 89 | dbHandlerInner = new GraphDBOperation(conf); |
Pavlin Radoslavov | b6f5354 | 2013-03-01 16:02:14 -0800 | [diff] [blame] | 90 | } |
| 91 | |
admin | 944ef4f | 2013-10-08 17:48:37 -0700 | [diff] [blame] | 92 | /** |
| 93 | * Shutdown the Flow Manager operation. |
| 94 | */ |
Yuta HIGUCHI | 3ab1fd0 | 2013-12-17 11:01:02 -0800 | [diff] [blame] | 95 | @Override |
Yuta HIGUCHI | 67a7a3e | 2014-01-03 14:51:34 -0800 | [diff] [blame] | 96 | protected void finalize() { |
Toshio Koide | 9fe1cb2 | 2013-06-13 13:51:11 -0700 | [diff] [blame] | 97 | close(); |
Pavlin Radoslavov | b6f5354 | 2013-03-01 16:02:14 -0800 | [diff] [blame] | 98 | } |
| 99 | |
admin | 944ef4f | 2013-10-08 17:48:37 -0700 | [diff] [blame] | 100 | /** |
| 101 | * Shutdown the Flow Manager operation. |
| 102 | */ |
Pavlin Radoslavov | b6f5354 | 2013-03-01 16:02:14 -0800 | [diff] [blame] | 103 | @Override |
| 104 | public void close() { |
Pavlin Radoslavov | cc75716 | 2014-01-10 16:26:38 -0800 | [diff] [blame] | 105 | floodlightProvider.removeOFSwitchListener(flowEventHandler); |
Pavlin Radoslavov | 9a85902 | 2013-10-30 10:08:24 -0700 | [diff] [blame] | 106 | datagridService.deregisterFlowEventHandlerService(flowEventHandler); |
Pavlin Radoslavov | bc96ae1 | 2013-11-05 08:44:02 -0800 | [diff] [blame] | 107 | dbHandlerApi.close(); |
| 108 | dbHandlerInner.close(); |
Pavlin Radoslavov | b6f5354 | 2013-03-01 16:02:14 -0800 | [diff] [blame] | 109 | } |
Pavlin Radoslavov | 9e5344c | 2013-02-18 09:58:30 -0800 | [diff] [blame] | 110 | |
admin | 944ef4f | 2013-10-08 17:48:37 -0700 | [diff] [blame] | 111 | /** |
| 112 | * Get the collection of offered module services. |
| 113 | * |
| 114 | * @return the collection of offered module services. |
| 115 | */ |
Pavlin Radoslavov | 9e5344c | 2013-02-18 09:58:30 -0800 | [diff] [blame] | 116 | @Override |
| 117 | public Collection<Class<? extends IFloodlightService>> getModuleServices() { |
Yuta HIGUCHI | 3ab1fd0 | 2013-12-17 11:01:02 -0800 | [diff] [blame] | 118 | Collection<Class<? extends IFloodlightService>> l = |
Pavlin Radoslavov | 9e5344c | 2013-02-18 09:58:30 -0800 | [diff] [blame] | 119 | new ArrayList<Class<? extends IFloodlightService>>(); |
| 120 | l.add(IFlowService.class); |
| 121 | return l; |
| 122 | } |
| 123 | |
admin | 944ef4f | 2013-10-08 17:48:37 -0700 | [diff] [blame] | 124 | /** |
| 125 | * Get the collection of implemented services. |
| 126 | * |
| 127 | * @return the collection of implemented services. |
| 128 | */ |
Pavlin Radoslavov | 9e5344c | 2013-02-18 09:58:30 -0800 | [diff] [blame] | 129 | @Override |
Yuta HIGUCHI | 3ab1fd0 | 2013-12-17 11:01:02 -0800 | [diff] [blame] | 130 | public Map<Class<? extends IFloodlightService>, IFloodlightService> |
Pavlin Radoslavov | 9e5344c | 2013-02-18 09:58:30 -0800 | [diff] [blame] | 131 | getServiceImpls() { |
| 132 | Map<Class<? extends IFloodlightService>, |
Pavlin Radoslavov | e9a3ef9 | 2013-10-18 18:46:45 -0700 | [diff] [blame] | 133 | IFloodlightService> m = |
| 134 | new HashMap<Class<? extends IFloodlightService>, |
| 135 | IFloodlightService>(); |
Pavlin Radoslavov | 9e5344c | 2013-02-18 09:58:30 -0800 | [diff] [blame] | 136 | m.put(IFlowService.class, this); |
| 137 | return m; |
| 138 | } |
| 139 | |
admin | 944ef4f | 2013-10-08 17:48:37 -0700 | [diff] [blame] | 140 | /** |
| 141 | * Get the collection of modules this module depends on. |
| 142 | * |
| 143 | * @return the collection of modules this module depends on. |
| 144 | */ |
Pavlin Radoslavov | 9e5344c | 2013-02-18 09:58:30 -0800 | [diff] [blame] | 145 | @Override |
Yuta HIGUCHI | 3ab1fd0 | 2013-12-17 11:01:02 -0800 | [diff] [blame] | 146 | public Collection<Class<? extends IFloodlightService>> |
Pavlin Radoslavov | 50e532e | 2013-10-20 02:07:51 -0700 | [diff] [blame] | 147 | getModuleDependencies() { |
Pavlin Radoslavov | 9e5344c | 2013-02-18 09:58:30 -0800 | [diff] [blame] | 148 | Collection<Class<? extends IFloodlightService>> l = |
| 149 | new ArrayList<Class<? extends IFloodlightService>>(); |
Pavlin Radoslavov | b6f5354 | 2013-03-01 16:02:14 -0800 | [diff] [blame] | 150 | l.add(IFloodlightProviderService.class); |
Pavlin Radoslavov | e9a3ef9 | 2013-10-18 18:46:45 -0700 | [diff] [blame] | 151 | l.add(INetworkGraphService.class); |
Pavlin Radoslavov | 0537827 | 2013-10-19 23:23:05 -0700 | [diff] [blame] | 152 | l.add(IDatagridService.class); |
Pavlin Radoslavov | 9e5344c | 2013-02-18 09:58:30 -0800 | [diff] [blame] | 153 | l.add(IRestApiService.class); |
Pavlin Radoslavov | c086266 | 2013-12-10 15:31:49 -0800 | [diff] [blame] | 154 | l.add(IFlowPusherService.class); |
Pavlin Radoslavov | 63c2d05 | 2013-12-18 18:17:55 -0800 | [diff] [blame] | 155 | // |
| 156 | // TODO: Comment-out the dependency on the IForwardingService, |
| 157 | // because it is an optional module. Apparently, adding the dependency |
| 158 | // here automatically enables the module. |
| 159 | // |
| 160 | // l.add(IForwardingService.class); |
Pavlin Radoslavov | 9e5344c | 2013-02-18 09:58:30 -0800 | [diff] [blame] | 161 | return l; |
| 162 | } |
| 163 | |
admin | 944ef4f | 2013-10-08 17:48:37 -0700 | [diff] [blame] | 164 | /** |
| 165 | * Initialize the module. |
| 166 | * |
| 167 | * @param context the module context to use for the initialization. |
| 168 | */ |
Pavlin Radoslavov | 9e5344c | 2013-02-18 09:58:30 -0800 | [diff] [blame] | 169 | @Override |
| 170 | public void init(FloodlightModuleContext context) |
| 171 | throws FloodlightModuleException { |
Pavlin Radoslavov | 571cff9 | 2013-03-20 02:01:32 -0700 | [diff] [blame] | 172 | this.context = context; |
Pavlin Radoslavov | b6f5354 | 2013-03-01 16:02:14 -0800 | [diff] [blame] | 173 | floodlightProvider = context.getServiceImpl(IFloodlightProviderService.class); |
Pavlin Radoslavov | 0537827 | 2013-10-19 23:23:05 -0700 | [diff] [blame] | 174 | datagridService = context.getServiceImpl(IDatagridService.class); |
Pavlin Radoslavov | 9e5344c | 2013-02-18 09:58:30 -0800 | [diff] [blame] | 175 | restApi = context.getServiceImpl(IRestApiService.class); |
Pavlin Radoslavov | 939ca6b | 2013-12-03 12:35:37 -0800 | [diff] [blame] | 176 | pusher = context.getServiceImpl(IFlowPusherService.class); |
Pavlin Radoslavov | 7208e9a | 2013-12-11 14:31:07 -0800 | [diff] [blame] | 177 | forwardingService = context.getServiceImpl(IForwardingService.class); |
Brian O'Connor | 8c166a7 | 2013-11-14 18:41:48 -0800 | [diff] [blame] | 178 | |
Pavlin Radoslavov | 50e532e | 2013-10-20 02:07:51 -0700 | [diff] [blame] | 179 | this.init(""); |
Pavlin Radoslavov | 9e5344c | 2013-02-18 09:58:30 -0800 | [diff] [blame] | 180 | } |
| 181 | |
admin | 944ef4f | 2013-10-08 17:48:37 -0700 | [diff] [blame] | 182 | /** |
| 183 | * Get the next Flow Entry ID to use. |
| 184 | * |
| 185 | * @return the next Flow Entry ID to use. |
| 186 | */ |
Naoki Shiota | 4e77de9 | 2013-11-18 17:29:54 -0800 | [diff] [blame] | 187 | @Override |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 188 | public synchronized long getNextFlowEntryId() { |
Pavlin Radoslavov | 0b22d0e | 2013-04-02 01:12:46 +0000 | [diff] [blame] | 189 | // |
| 190 | // Generate the next Flow Entry ID. |
| 191 | // NOTE: For now, the higher 32 bits are random, and |
| 192 | // the lower 32 bits are sequential. |
| 193 | // In the future, we need a better allocation mechanism. |
| 194 | // |
| 195 | if ((nextFlowEntryIdSuffix & 0xffffffffL) == 0xffffffffL) { |
| 196 | nextFlowEntryIdPrefix = randomGenerator.nextInt(); |
| 197 | nextFlowEntryIdSuffix = 0; |
| 198 | } else { |
| 199 | nextFlowEntryIdSuffix++; |
| 200 | } |
| 201 | long result = (long)nextFlowEntryIdPrefix << 32; |
| 202 | result = result | (0xffffffffL & nextFlowEntryIdSuffix); |
| 203 | return result; |
| 204 | } |
| 205 | |
admin | 944ef4f | 2013-10-08 17:48:37 -0700 | [diff] [blame] | 206 | /** |
| 207 | * Startup module operation. |
| 208 | * |
| 209 | * @param context the module context to use for the startup. |
| 210 | */ |
Pavlin Radoslavov | 9e5344c | 2013-02-18 09:58:30 -0800 | [diff] [blame] | 211 | @Override |
| 212 | public void startUp(FloodlightModuleContext context) { |
admin | 944ef4f | 2013-10-08 17:48:37 -0700 | [diff] [blame] | 213 | restApi.addRestletRoutable(new FlowWebRoutable()); |
Pavlin Radoslavov | 50e532e | 2013-10-20 02:07:51 -0700 | [diff] [blame] | 214 | |
admin | 944ef4f | 2013-10-08 17:48:37 -0700 | [diff] [blame] | 215 | // Initialize the Flow Entry ID generator |
| 216 | nextFlowEntryIdPrefix = randomGenerator.nextInt(); |
Pavlin Radoslavov | 584bd11 | 2013-11-21 20:59:33 -0800 | [diff] [blame] | 217 | |
| 218 | // |
| 219 | // The thread to write to the database |
| 220 | // |
| 221 | flowDatabaseWriter = new FlowDatabaseWriter(this, |
Pavlin Radoslavov | 2fca8d1 | 2013-12-04 09:39:06 -0800 | [diff] [blame] | 222 | flowPathsToDatabaseQueue); |
Pavlin Radoslavov | 584bd11 | 2013-11-21 20:59:33 -0800 | [diff] [blame] | 223 | flowDatabaseWriter.start(); |
| 224 | |
Pavlin Radoslavov | 6b79f2b | 2013-10-26 21:31:10 -0700 | [diff] [blame] | 225 | // |
Pavlin Radoslavov | c9da532 | 2013-11-22 11:59:46 -0800 | [diff] [blame] | 226 | // The Flow Event Handler thread: |
| 227 | // - create |
| 228 | // - register with the Datagrid Service |
| 229 | // - startup |
Pavlin Radoslavov | 6b79f2b | 2013-10-26 21:31:10 -0700 | [diff] [blame] | 230 | // |
Pavlin Radoslavov | 8252fee | 2014-01-07 17:24:29 -0800 | [diff] [blame] | 231 | flowEventHandler = new FlowEventHandler(this, datagridService); |
Pavlin Radoslavov | cc75716 | 2014-01-10 16:26:38 -0800 | [diff] [blame] | 232 | floodlightProvider.addOFSwitchListener(flowEventHandler); |
Pavlin Radoslavov | 9a85902 | 2013-10-30 10:08:24 -0700 | [diff] [blame] | 233 | datagridService.registerFlowEventHandlerService(flowEventHandler); |
Pavlin Radoslavov | 9a85902 | 2013-10-30 10:08:24 -0700 | [diff] [blame] | 234 | flowEventHandler.start(); |
Pavlin Radoslavov | 9e5344c | 2013-02-18 09:58:30 -0800 | [diff] [blame] | 235 | } |
| 236 | |
| 237 | /** |
| 238 | * Add a flow. |
| 239 | * |
Pavlin Radoslavov | 9e5344c | 2013-02-18 09:58:30 -0800 | [diff] [blame] | 240 | * @param flowPath the Flow Path to install. |
Pavlin Radoslavov | 051abb4 | 2013-12-05 17:24:50 -0800 | [diff] [blame] | 241 | * @return the Flow ID on success, otherwise null. |
Pavlin Radoslavov | 9e5344c | 2013-02-18 09:58:30 -0800 | [diff] [blame] | 242 | */ |
| 243 | @Override |
Pavlin Radoslavov | 051abb4 | 2013-12-05 17:24:50 -0800 | [diff] [blame] | 244 | public FlowId addFlow(FlowPath flowPath) { |
| 245 | |
| 246 | // Allocate the Flow ID if necessary |
Pavlin Radoslavov | 892dd18 | 2013-12-05 23:33:15 -0800 | [diff] [blame] | 247 | if (! flowPath.isValidFlowId()) { |
Pavlin Radoslavov | 051abb4 | 2013-12-05 17:24:50 -0800 | [diff] [blame] | 248 | long id = getNextFlowEntryId(); |
| 249 | flowPath.setFlowId(new FlowId(id)); |
| 250 | } |
| 251 | |
Pavlin Radoslavov | ebc8b19 | 2013-10-29 15:35:35 -0700 | [diff] [blame] | 252 | // |
Pavlin Radoslavov | 1c24f22 | 2013-10-30 13:56:46 -0700 | [diff] [blame] | 253 | // NOTE: We need to explicitly initialize some of the state, |
Pavlin Radoslavov | ebc8b19 | 2013-10-29 15:35:35 -0700 | [diff] [blame] | 254 | // in case the application didn't do it. |
| 255 | // |
| 256 | for (FlowEntry flowEntry : flowPath.flowEntries()) { |
Pavlin Radoslavov | 07d22b4 | 2013-12-15 16:33:33 -0800 | [diff] [blame] | 257 | // The Flow Entry switch state |
Pavlin Radoslavov | ebc8b19 | 2013-10-29 15:35:35 -0700 | [diff] [blame] | 258 | if (flowEntry.flowEntrySwitchState() == |
| 259 | FlowEntrySwitchState.FE_SWITCH_UNKNOWN) { |
| 260 | flowEntry.setFlowEntrySwitchState(FlowEntrySwitchState.FE_SWITCH_NOT_UPDATED); |
| 261 | } |
Pavlin Radoslavov | 07d22b4 | 2013-12-15 16:33:33 -0800 | [diff] [blame] | 262 | // The Flow Entry ID |
| 263 | if (! flowEntry.isValidFlowEntryId()) { |
| 264 | long id = getNextFlowEntryId(); |
| 265 | flowEntry.setFlowEntryId(new FlowEntryId(id)); |
| 266 | } |
| 267 | // The Flow ID |
Pavlin Radoslavov | 1c24f22 | 2013-10-30 13:56:46 -0700 | [diff] [blame] | 268 | if (! flowEntry.isValidFlowId()) |
| 269 | flowEntry.setFlowId(new FlowId(flowPath.flowId().value())); |
Pavlin Radoslavov | ebc8b19 | 2013-10-29 15:35:35 -0700 | [diff] [blame] | 270 | } |
| 271 | |
Pavlin Radoslavov | 051abb4 | 2013-12-05 17:24:50 -0800 | [diff] [blame] | 272 | if (FlowDatabaseOperation.addFlow(dbHandlerApi, flowPath)) { |
Pavlin Radoslavov | 8252fee | 2014-01-07 17:24:29 -0800 | [diff] [blame] | 273 | if (enableOnrc2014MeasurementsFlows) { |
Pavlin Radoslavov | 2194d11 | 2014-01-10 13:36:00 -0800 | [diff] [blame] | 274 | datagridService.notificationSendFlowIdAdded(flowPath.flowId(), |
| 275 | flowPath.dataPath().srcPort().dpid()); |
Pavlin Radoslavov | 8252fee | 2014-01-07 17:24:29 -0800 | [diff] [blame] | 276 | } else { |
| 277 | datagridService.notificationSendFlowAdded(flowPath); |
| 278 | } |
| 279 | |
Pavlin Radoslavov | 051abb4 | 2013-12-05 17:24:50 -0800 | [diff] [blame] | 280 | return flowPath.flowId(); |
Pavlin Radoslavov | 1308dc6 | 2013-10-25 15:54:31 -0700 | [diff] [blame] | 281 | } |
Pavlin Radoslavov | 051abb4 | 2013-12-05 17:24:50 -0800 | [diff] [blame] | 282 | return null; |
Pavlin Radoslavov | 9e5344c | 2013-02-18 09:58:30 -0800 | [diff] [blame] | 283 | } |
| 284 | |
| 285 | /** |
Pavlin Radoslavov | baea924 | 2013-05-08 00:20:09 +0000 | [diff] [blame] | 286 | * Delete all previously added flows. |
| 287 | * |
| 288 | * @return true on success, otherwise false. |
| 289 | */ |
| 290 | @Override |
| 291 | public boolean deleteAllFlows() { |
Pavlin Radoslavov | bc96ae1 | 2013-11-05 08:44:02 -0800 | [diff] [blame] | 292 | if (FlowDatabaseOperation.deleteAllFlows(dbHandlerApi)) { |
Pavlin Radoslavov | 8252fee | 2014-01-07 17:24:29 -0800 | [diff] [blame] | 293 | if (enableOnrc2014MeasurementsFlows) { |
| 294 | datagridService.notificationSendAllFlowIdsRemoved(); |
| 295 | } else { |
| 296 | datagridService.notificationSendAllFlowsRemoved(); |
| 297 | } |
Pavlin Radoslavov | 1308dc6 | 2013-10-25 15:54:31 -0700 | [diff] [blame] | 298 | return true; |
| 299 | } |
| 300 | return false; |
Pavlin Radoslavov | baea924 | 2013-05-08 00:20:09 +0000 | [diff] [blame] | 301 | } |
| 302 | |
| 303 | /** |
Pavlin Radoslavov | 9e5344c | 2013-02-18 09:58:30 -0800 | [diff] [blame] | 304 | * Delete a previously added flow. |
| 305 | * |
| 306 | * @param flowId the Flow ID of the flow to delete. |
| 307 | * @return true on success, otherwise false. |
| 308 | */ |
| 309 | @Override |
| 310 | public boolean deleteFlow(FlowId flowId) { |
Pavlin Radoslavov | bc96ae1 | 2013-11-05 08:44:02 -0800 | [diff] [blame] | 311 | if (FlowDatabaseOperation.deleteFlow(dbHandlerApi, flowId)) { |
Pavlin Radoslavov | 8252fee | 2014-01-07 17:24:29 -0800 | [diff] [blame] | 312 | if (enableOnrc2014MeasurementsFlows) { |
| 313 | datagridService.notificationSendFlowIdRemoved(flowId); |
| 314 | } else { |
| 315 | datagridService.notificationSendFlowRemoved(flowId); |
| 316 | } |
Pavlin Radoslavov | 1308dc6 | 2013-10-25 15:54:31 -0700 | [diff] [blame] | 317 | return true; |
| 318 | } |
| 319 | return false; |
Pavlin Radoslavov | 916832f | 2013-03-14 17:48:41 -0700 | [diff] [blame] | 320 | } |
| 321 | |
| 322 | /** |
Pavlin Radoslavov | 9e5344c | 2013-02-18 09:58:30 -0800 | [diff] [blame] | 323 | * Get a previously added flow. |
| 324 | * |
| 325 | * @param flowId the Flow ID of the flow to get. |
Pavlin Radoslavov | b6f5354 | 2013-03-01 16:02:14 -0800 | [diff] [blame] | 326 | * @return the Flow Path if found, otherwise null. |
Pavlin Radoslavov | 9e5344c | 2013-02-18 09:58:30 -0800 | [diff] [blame] | 327 | */ |
| 328 | @Override |
Pavlin Radoslavov | b6f5354 | 2013-03-01 16:02:14 -0800 | [diff] [blame] | 329 | public FlowPath getFlow(FlowId flowId) { |
Pavlin Radoslavov | bc96ae1 | 2013-11-05 08:44:02 -0800 | [diff] [blame] | 330 | return FlowDatabaseOperation.getFlow(dbHandlerApi, flowId); |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 331 | } |
Pavlin Radoslavov | b6f5354 | 2013-03-01 16:02:14 -0800 | [diff] [blame] | 332 | |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 333 | /** |
Pavlin Radoslavov | 52119fa | 2014-01-09 13:37:52 -0800 | [diff] [blame] | 334 | * Get a previously added flow entry. |
| 335 | * |
| 336 | * @param flowEntryId the Flow Entry ID of the flow entry to get. |
| 337 | * @return the Flow Entry if found, otherwise null. |
| 338 | */ |
| 339 | public FlowEntry getFlowEntry(FlowEntryId flowEntryId) { |
| 340 | return FlowDatabaseOperation.getFlowEntry(dbHandlerApi, flowEntryId); |
| 341 | } |
| 342 | |
| 343 | /** |
Pavlin Radoslavov | 8252fee | 2014-01-07 17:24:29 -0800 | [diff] [blame] | 344 | * Get the source switch DPID of a previously added flow. |
| 345 | * |
| 346 | * @param flowId the Flow ID of the flow to get. |
| 347 | * @return the source switch DPID if found, otherwise null. |
| 348 | */ |
| 349 | public Dpid getFlowSourceDpid(FlowId flowId) { |
| 350 | return FlowDatabaseOperation.getFlowSourceDpid(dbHandlerApi, flowId); |
| 351 | } |
| 352 | |
| 353 | /** |
Pavlin Radoslavov | 661c86f | 2013-10-21 12:40:40 -0700 | [diff] [blame] | 354 | * Get all installed flows by all installers. |
| 355 | * |
| 356 | * @return the Flow Paths if found, otherwise null. |
| 357 | */ |
| 358 | @Override |
| 359 | public ArrayList<FlowPath> getAllFlows() { |
Pavlin Radoslavov | bc96ae1 | 2013-11-05 08:44:02 -0800 | [diff] [blame] | 360 | return FlowDatabaseOperation.getAllFlows(dbHandlerApi); |
Pavlin Radoslavov | 706df05 | 2013-03-06 10:49:07 -0800 | [diff] [blame] | 361 | } |
| 362 | |
| 363 | /** |
Pavlin Radoslavov | 16b761d | 2014-01-08 09:47:14 -0800 | [diff] [blame] | 364 | * Get all installed flows whose Source Switch is controlled by this |
| 365 | * instance. |
| 366 | * |
| 367 | * @param mySwitches the collection of the switches controlled by this |
| 368 | * instance. |
| 369 | * @return the Flow Paths if found, otherwise null. |
| 370 | */ |
| 371 | public ArrayList<FlowPath> getAllMyFlows(Map<Long, IOFSwitch> mySwitches) { |
| 372 | return FlowDatabaseOperation.getAllMyFlows(dbHandlerApi, mySwitches); |
| 373 | } |
| 374 | |
| 375 | /** |
admin | 944ef4f | 2013-10-08 17:48:37 -0700 | [diff] [blame] | 376 | * Get summary of all installed flows by all installers in a given range. |
Umesh Krishnaswamy | 57a32a9 | 2013-03-21 14:21:15 -0700 | [diff] [blame] | 377 | * |
admin | 944ef4f | 2013-10-08 17:48:37 -0700 | [diff] [blame] | 378 | * @param flowId the Flow ID of the first flow in the flow range to get. |
HIGUCHI Yuta | eb567aa | 2013-10-08 19:27:35 -0700 | [diff] [blame] | 379 | * @param maxFlows the maximum number of flows to be returned. |
Umesh Krishnaswamy | 57a32a9 | 2013-03-21 14:21:15 -0700 | [diff] [blame] | 380 | * @return the Flow Paths if found, otherwise null. |
| 381 | */ |
| 382 | @Override |
Pavlin Radoslavov | 4ef6ba2 | 2013-11-22 19:32:58 -0800 | [diff] [blame] | 383 | public ArrayList<FlowPath> getAllFlowsSummary(FlowId flowId, |
| 384 | int maxFlows) { |
Pavlin Radoslavov | 5321980 | 2013-12-06 11:02:04 -0800 | [diff] [blame] | 385 | ArrayList<FlowPath> flowPaths = new ArrayList<FlowPath>(); |
| 386 | SortedMap<Long, FlowPath> sortedFlowPaths = |
| 387 | flowEventHandler.getAllFlowPathsCopy(); |
Pavlin Radoslavov | e79c19a | 2013-12-06 09:28:15 -0800 | [diff] [blame] | 388 | |
Pavlin Radoslavov | 5321980 | 2013-12-06 11:02:04 -0800 | [diff] [blame] | 389 | // |
Pavlin Radoslavov | e79c19a | 2013-12-06 09:28:15 -0800 | [diff] [blame] | 390 | // Truncate each Flow Path and Flow Entry |
Pavlin Radoslavov | 5321980 | 2013-12-06 11:02:04 -0800 | [diff] [blame] | 391 | // |
| 392 | for (FlowPath flowPath : sortedFlowPaths.values()) { |
| 393 | // |
| 394 | // TODO: Add only the Flow Paths that have been successfully |
| 395 | // installed. |
| 396 | // |
Pavlin Radoslavov | e79c19a | 2013-12-06 09:28:15 -0800 | [diff] [blame] | 397 | flowPath.setFlowEntryMatch(null); |
| 398 | flowPath.setFlowEntryActions(null); |
| 399 | for (FlowEntry flowEntry : flowPath.flowEntries()) { |
| 400 | flowEntry.setFlowEntryMatch(null); |
| 401 | flowEntry.setFlowEntryActions(null); |
| 402 | } |
Pavlin Radoslavov | 5321980 | 2013-12-06 11:02:04 -0800 | [diff] [blame] | 403 | flowPaths.add(flowPath); |
Pavlin Radoslavov | e79c19a | 2013-12-06 09:28:15 -0800 | [diff] [blame] | 404 | } |
| 405 | |
Pavlin Radoslavov | e79c19a | 2013-12-06 09:28:15 -0800 | [diff] [blame] | 406 | return flowPaths; |
Umesh Krishnaswamy | 57a32a9 | 2013-03-21 14:21:15 -0700 | [diff] [blame] | 407 | } |
Pavlin Radoslavov | b9fe6b4 | 2013-03-27 16:25:05 -0700 | [diff] [blame] | 408 | |
| 409 | /** |
Pavlin Radoslavov | 9f33edb | 2013-11-06 18:24:37 -0800 | [diff] [blame] | 410 | * Get the collection of my switches. |
| 411 | * |
| 412 | * @return the collection of my switches. |
| 413 | */ |
| 414 | public Map<Long, IOFSwitch> getMySwitches() { |
| 415 | return floodlightProvider.getSwitches(); |
| 416 | } |
| 417 | |
| 418 | /** |
Pavlin Radoslavov | ed0f4a8 | 2013-11-04 16:38:36 -0800 | [diff] [blame] | 419 | * Get the network topology. |
| 420 | * |
| 421 | * @return the network topology. |
| 422 | */ |
Yuta HIGUCHI | 3ab1fd0 | 2013-12-17 11:01:02 -0800 | [diff] [blame] | 423 | @Override |
Pavlin Radoslavov | ed0f4a8 | 2013-11-04 16:38:36 -0800 | [diff] [blame] | 424 | public Topology getTopology() { |
| 425 | return flowEventHandler.getTopology(); |
| 426 | } |
| 427 | |
| 428 | /** |
Pavlin Radoslavov | 4df85ae | 2013-11-26 14:48:32 -0800 | [diff] [blame] | 429 | * Inform the Flow Manager that a Flow Entry on switch expired. |
| 430 | * |
Pavlin Radoslavov | 3bd5ccf | 2013-11-26 15:10:21 -0800 | [diff] [blame] | 431 | * @param sw the switch the Flow Entry expired on. |
Pavlin Radoslavov | 4df85ae | 2013-11-26 14:48:32 -0800 | [diff] [blame] | 432 | * @param flowEntryId the Flow Entry ID of the expired Flow Entry. |
| 433 | */ |
Yuta HIGUCHI | 3ab1fd0 | 2013-12-17 11:01:02 -0800 | [diff] [blame] | 434 | @Override |
Pavlin Radoslavov | c5718e7 | 2013-12-10 15:47:10 -0800 | [diff] [blame] | 435 | public void flowEntryOnSwitchExpired(IOFSwitch sw, |
| 436 | FlowEntryId flowEntryId) { |
| 437 | // Find the Flow Entry |
| 438 | FlowEntry flowEntry = datagridService.getFlowEntry(flowEntryId); |
Pavlin Radoslavov | ac0fabc | 2013-12-13 10:47:56 -0800 | [diff] [blame] | 439 | if (flowEntry == null) |
Pavlin Radoslavov | c5718e7 | 2013-12-10 15:47:10 -0800 | [diff] [blame] | 440 | return; // Flow Entry not found |
| 441 | |
| 442 | // Find the Flow Path |
| 443 | FlowPath flowPath = datagridService.getFlow(flowEntry.flowId()); |
| 444 | if (flowPath == null) |
| 445 | return; // Flow Path not found |
| 446 | |
| 447 | // |
| 448 | // Remove the Flow if the Flow Entry expired on the first switch |
| 449 | // |
| 450 | Dpid srcDpid = flowPath.dataPath().srcPort().dpid(); |
| 451 | if (srcDpid.value() != sw.getId()) |
| 452 | return; |
| 453 | deleteFlow(flowPath.flowId()); |
Pavlin Radoslavov | 4df85ae | 2013-11-26 14:48:32 -0800 | [diff] [blame] | 454 | } |
| 455 | |
| 456 | /** |
Pavlin Radoslavov | ab3f886 | 2013-12-04 18:35:53 -0800 | [diff] [blame] | 457 | * Inform the Flow Manager that a collection of Flow Entries have been |
| 458 | * pushed to a switch. |
Pavlin Radoslavov | da0ab44 | 2013-12-04 14:08:58 -0800 | [diff] [blame] | 459 | * |
Pavlin Radoslavov | ab3f886 | 2013-12-04 18:35:53 -0800 | [diff] [blame] | 460 | * @param entries the collection of <IOFSwitch, FlowEntry> pairs |
| 461 | * that have been pushed. |
Pavlin Radoslavov | da0ab44 | 2013-12-04 14:08:58 -0800 | [diff] [blame] | 462 | */ |
Yuta HIGUCHI | 3ab1fd0 | 2013-12-17 11:01:02 -0800 | [diff] [blame] | 463 | @Override |
Pavlin Radoslavov | ab3f886 | 2013-12-04 18:35:53 -0800 | [diff] [blame] | 464 | public void flowEntriesPushedToSwitch( |
| 465 | Collection<Pair<IOFSwitch, FlowEntry>> entries) { |
Pavlin Radoslavov | da0ab44 | 2013-12-04 14:08:58 -0800 | [diff] [blame] | 466 | |
Pavlin Radoslavov | 8252fee | 2014-01-07 17:24:29 -0800 | [diff] [blame] | 467 | if (enableOnrc2014MeasurementsFlows) |
| 468 | return; |
| 469 | |
Pavlin Radoslavov | da0ab44 | 2013-12-04 14:08:58 -0800 | [diff] [blame] | 470 | // |
Pavlin Radoslavov | ab3f886 | 2013-12-04 18:35:53 -0800 | [diff] [blame] | 471 | // Process all entries |
Pavlin Radoslavov | da0ab44 | 2013-12-04 14:08:58 -0800 | [diff] [blame] | 472 | // |
Pavlin Radoslavov | 237fde7 | 2013-12-17 22:21:06 -0800 | [diff] [blame] | 473 | // TODO: For now we have to create an explicit FlowEntry copy so |
| 474 | // we don't modify the original FlowEntry. |
| 475 | // This should go away after we start using the OpenFlow Barrier |
| 476 | // mechnanism in the FlowPusher. |
| 477 | // |
| 478 | Kryo kryo = kryoFactory.newKryo(); |
Pavlin Radoslavov | ab3f886 | 2013-12-04 18:35:53 -0800 | [diff] [blame] | 479 | for (Pair<IOFSwitch, FlowEntry> entry : entries) { |
Pavlin Radoslavov | 4535bc1 | 2013-12-05 10:43:49 -0800 | [diff] [blame] | 480 | FlowEntry flowEntry = entry.second; |
Pavlin Radoslavov | ab3f886 | 2013-12-04 18:35:53 -0800 | [diff] [blame] | 481 | |
| 482 | // |
| 483 | // Mark the Flow Entry that it has been pushed to the switch |
| 484 | // |
Pavlin Radoslavov | 237fde7 | 2013-12-17 22:21:06 -0800 | [diff] [blame] | 485 | FlowEntry copyFlowEntry = kryo.copy(flowEntry); |
| 486 | copyFlowEntry.setFlowEntrySwitchState(FlowEntrySwitchState.FE_SWITCH_UPDATED); |
Pavlin Radoslavov | ab3f886 | 2013-12-04 18:35:53 -0800 | [diff] [blame] | 487 | |
| 488 | // |
| 489 | // Write the Flow Entry to the Datagrid |
| 490 | // |
Pavlin Radoslavov | 237fde7 | 2013-12-17 22:21:06 -0800 | [diff] [blame] | 491 | switch (copyFlowEntry.flowEntryUserState()) { |
Pavlin Radoslavov | ab3f886 | 2013-12-04 18:35:53 -0800 | [diff] [blame] | 492 | case FE_USER_ADD: |
Pavlin Radoslavov | 237fde7 | 2013-12-17 22:21:06 -0800 | [diff] [blame] | 493 | datagridService.notificationSendFlowEntryAdded(copyFlowEntry); |
Pavlin Radoslavov | ab3f886 | 2013-12-04 18:35:53 -0800 | [diff] [blame] | 494 | break; |
| 495 | case FE_USER_MODIFY: |
Pavlin Radoslavov | 237fde7 | 2013-12-17 22:21:06 -0800 | [diff] [blame] | 496 | datagridService.notificationSendFlowEntryUpdated(copyFlowEntry); |
Pavlin Radoslavov | ab3f886 | 2013-12-04 18:35:53 -0800 | [diff] [blame] | 497 | break; |
| 498 | case FE_USER_DELETE: |
Pavlin Radoslavov | 237fde7 | 2013-12-17 22:21:06 -0800 | [diff] [blame] | 499 | datagridService.notificationSendFlowEntryRemoved(copyFlowEntry.flowEntryId()); |
Pavlin Radoslavov | ab3f886 | 2013-12-04 18:35:53 -0800 | [diff] [blame] | 500 | break; |
Pavlin Radoslavov | 4839f6d | 2013-12-11 12:49:45 -0800 | [diff] [blame] | 501 | case FE_USER_UNKNOWN: |
| 502 | assert(false); |
| 503 | break; |
Pavlin Radoslavov | ab3f886 | 2013-12-04 18:35:53 -0800 | [diff] [blame] | 504 | } |
Pavlin Radoslavov | da0ab44 | 2013-12-04 14:08:58 -0800 | [diff] [blame] | 505 | } |
Pavlin Radoslavov | 237fde7 | 2013-12-17 22:21:06 -0800 | [diff] [blame] | 506 | kryoFactory.deleteKryo(kryo); |
Pavlin Radoslavov | da0ab44 | 2013-12-04 14:08:58 -0800 | [diff] [blame] | 507 | } |
| 508 | |
| 509 | /** |
Pavlin Radoslavov | 7208e9a | 2013-12-11 14:31:07 -0800 | [diff] [blame] | 510 | * Generate a notification that a collection of Flow Paths has been |
| 511 | * installed in the network. |
| 512 | * |
| 513 | * @param flowPaths the collection of installed Flow Paths. |
| 514 | */ |
| 515 | void notificationFlowPathsInstalled(Collection<FlowPath> flowPaths) { |
Pavlin Radoslavov | 63c2d05 | 2013-12-18 18:17:55 -0800 | [diff] [blame] | 516 | // |
| 517 | // TODO: Add an explicit check for null pointer, because |
| 518 | // the IForwardingService is optional. Remove the "if" statement |
| 519 | // after hte Forwarding Module becomes mandatory. |
| 520 | // |
| 521 | if (forwardingService != null) |
| 522 | forwardingService.flowsInstalled(flowPaths); |
Pavlin Radoslavov | 7208e9a | 2013-12-11 14:31:07 -0800 | [diff] [blame] | 523 | } |
| 524 | |
| 525 | /** |
Pavlin Radoslavov | a0c1636 | 2013-12-04 13:18:08 -0800 | [diff] [blame] | 526 | * Push modified Flow-related state as appropriate. |
| 527 | * |
| 528 | * @param modifiedFlowPaths the collection of modified Flow Paths. |
| 529 | * @param modifiedFlowEntries the collection of modified Flow Entries. |
| 530 | */ |
Pavlin Radoslavov | da0ab44 | 2013-12-04 14:08:58 -0800 | [diff] [blame] | 531 | void pushModifiedFlowState(Collection<FlowPath> modifiedFlowPaths, |
| 532 | Collection<FlowEntry> modifiedFlowEntries) { |
Pavlin Radoslavov | a0c1636 | 2013-12-04 13:18:08 -0800 | [diff] [blame] | 533 | // |
| 534 | // Push the modified Flow state: |
| 535 | // - Flow Entries to switches and the datagrid |
| 536 | // - Flow Paths to the database |
| 537 | // |
| 538 | pushModifiedFlowEntriesToSwitches(modifiedFlowEntries); |
Pavlin Radoslavov | 3a7cc90 | 2014-01-09 02:32:08 -0800 | [diff] [blame] | 539 | if (enableOnrc2014MeasurementsFlows) { |
| 540 | writeModifiedFlowPathsToDatabase(modifiedFlowPaths); |
| 541 | } else { |
| 542 | pushModifiedFlowPathsToDatabase(modifiedFlowPaths); |
Pavlin Radoslavov | 8252fee | 2014-01-07 17:24:29 -0800 | [diff] [blame] | 543 | cleanupDeletedFlowEntriesFromDatagrid(modifiedFlowEntries); |
| 544 | } |
Pavlin Radoslavov | a0c1636 | 2013-12-04 13:18:08 -0800 | [diff] [blame] | 545 | } |
| 546 | |
| 547 | /** |
Pavlin Radoslavov | 9f33edb | 2013-11-06 18:24:37 -0800 | [diff] [blame] | 548 | * Push modified Flow Entries to switches. |
Pavlin Radoslavov | ebc8b19 | 2013-10-29 15:35:35 -0700 | [diff] [blame] | 549 | * |
Pavlin Radoslavov | 9f33edb | 2013-11-06 18:24:37 -0800 | [diff] [blame] | 550 | * NOTE: Only the Flow Entries to switches controlled by this instance |
Pavlin Radoslavov | ebc8b19 | 2013-10-29 15:35:35 -0700 | [diff] [blame] | 551 | * are pushed. |
| 552 | * |
Pavlin Radoslavov | 9f33edb | 2013-11-06 18:24:37 -0800 | [diff] [blame] | 553 | * @param modifiedFlowEntries the collection of modified Flow Entries. |
Pavlin Radoslavov | ebc8b19 | 2013-10-29 15:35:35 -0700 | [diff] [blame] | 554 | */ |
Pavlin Radoslavov | 7847db7 | 2014-01-10 11:35:21 -0800 | [diff] [blame] | 555 | void pushModifiedFlowEntriesToSwitches( |
Pavlin Radoslavov | afc4aa9 | 2013-12-04 12:44:23 -0800 | [diff] [blame] | 556 | Collection<FlowEntry> modifiedFlowEntries) { |
Pavlin Radoslavov | 9f33edb | 2013-11-06 18:24:37 -0800 | [diff] [blame] | 557 | if (modifiedFlowEntries.isEmpty()) |
| 558 | return; |
Pavlin Radoslavov | ebc8b19 | 2013-10-29 15:35:35 -0700 | [diff] [blame] | 559 | |
Pavlin Radoslavov | ab3f886 | 2013-12-04 18:35:53 -0800 | [diff] [blame] | 560 | List<Pair<IOFSwitch, FlowEntry>> entries = |
| 561 | new LinkedList<Pair<IOFSwitch, FlowEntry>>(); |
| 562 | |
Pavlin Radoslavov | 9f33edb | 2013-11-06 18:24:37 -0800 | [diff] [blame] | 563 | Map<Long, IOFSwitch> mySwitches = getMySwitches(); |
| 564 | |
Pavlin Radoslavov | ab3f886 | 2013-12-04 18:35:53 -0800 | [diff] [blame] | 565 | // |
| 566 | // Create a collection of my Flow Entries to push |
| 567 | // |
Pavlin Radoslavov | afc4aa9 | 2013-12-04 12:44:23 -0800 | [diff] [blame] | 568 | for (FlowEntry flowEntry : modifiedFlowEntries) { |
Pavlin Radoslavov | 6311717 | 2013-11-07 02:18:37 -0800 | [diff] [blame] | 569 | IOFSwitch mySwitch = mySwitches.get(flowEntry.dpid().value()); |
| 570 | if (mySwitch == null) |
| 571 | continue; |
| 572 | |
Pavlin Radoslavov | d1b728c | 2013-12-18 21:39:58 -0800 | [diff] [blame] | 573 | if (flowEntry.flowEntrySwitchState() == |
| 574 | FlowEntrySwitchState.FE_SWITCH_UPDATED) { |
| 575 | // |
| 576 | // Don't push again Flow Entries that were already already |
| 577 | // installed into the switches. |
| 578 | // |
| 579 | continue; |
| 580 | } |
| 581 | |
Pavlin Radoslavov | aca49d1 | 2013-12-04 19:49:17 -0800 | [diff] [blame] | 582 | // |
| 583 | // Assign Flow Entry IDs if missing. |
| 584 | // |
| 585 | // NOTE: This is an additional safeguard, in case the |
| 586 | // mySwitches set has changed (after the Flow Entry IDs |
| 587 | // assignments by the caller). |
| 588 | // |
| 589 | if (! flowEntry.isValidFlowEntryId()) { |
| 590 | long id = getNextFlowEntryId(); |
| 591 | flowEntry.setFlowEntryId(new FlowEntryId(id)); |
| 592 | } |
| 593 | |
Yuta HIGUCHI | 5302ddf | 2014-01-06 12:53:35 -0800 | [diff] [blame] | 594 | log.debug("Pushing Flow Entry To Switch: {}", flowEntry); |
Pavlin Radoslavov | ab3f886 | 2013-12-04 18:35:53 -0800 | [diff] [blame] | 595 | entries.add(new Pair<IOFSwitch, FlowEntry>(mySwitch, flowEntry)); |
Pavlin Radoslavov | 6311717 | 2013-11-07 02:18:37 -0800 | [diff] [blame] | 596 | } |
Pavlin Radoslavov | ab3f886 | 2013-12-04 18:35:53 -0800 | [diff] [blame] | 597 | |
| 598 | pusher.pushFlowEntries(entries); |
Pavlin Radoslavov | 6311717 | 2013-11-07 02:18:37 -0800 | [diff] [blame] | 599 | } |
Pavlin Radoslavov | ebc8b19 | 2013-10-29 15:35:35 -0700 | [diff] [blame] | 600 | |
Pavlin Radoslavov | 6311717 | 2013-11-07 02:18:37 -0800 | [diff] [blame] | 601 | /** |
Pavlin Radoslavov | da0ab44 | 2013-12-04 14:08:58 -0800 | [diff] [blame] | 602 | * Cleanup deleted Flow Entries from the datagrid. |
| 603 | * |
| 604 | * NOTE: We cleanup only the Flow Entries that are not for our switches. |
| 605 | * This is needed to handle the case a switch going down: |
| 606 | * It has no Master controller instance, hence no controller instance |
| 607 | * will cleanup its flow entries. |
| 608 | * This is sub-optimal: we need to elect a controller instance to handle |
| 609 | * the cleanup of such orphaned flow entries. |
Pavlin Radoslavov | 6311717 | 2013-11-07 02:18:37 -0800 | [diff] [blame] | 610 | * |
| 611 | * @param modifiedFlowEntries the collection of modified Flow Entries. |
| 612 | */ |
Pavlin Radoslavov | da0ab44 | 2013-12-04 14:08:58 -0800 | [diff] [blame] | 613 | private void cleanupDeletedFlowEntriesFromDatagrid( |
Pavlin Radoslavov | afc4aa9 | 2013-12-04 12:44:23 -0800 | [diff] [blame] | 614 | Collection<FlowEntry> modifiedFlowEntries) { |
Pavlin Radoslavov | 6311717 | 2013-11-07 02:18:37 -0800 | [diff] [blame] | 615 | if (modifiedFlowEntries.isEmpty()) |
| 616 | return; |
| 617 | |
| 618 | Map<Long, IOFSwitch> mySwitches = getMySwitches(); |
| 619 | |
Pavlin Radoslavov | afc4aa9 | 2013-12-04 12:44:23 -0800 | [diff] [blame] | 620 | for (FlowEntry flowEntry : modifiedFlowEntries) { |
Pavlin Radoslavov | da0ab44 | 2013-12-04 14:08:58 -0800 | [diff] [blame] | 621 | // |
| 622 | // Process only Flow Entries that should be deleted and have |
| 623 | // a valid Flow Entry ID. |
| 624 | // |
Pavlin Radoslavov | 426a853 | 2013-12-02 17:32:21 -0800 | [diff] [blame] | 625 | if (! flowEntry.isValidFlowEntryId()) |
| 626 | continue; |
Pavlin Radoslavov | da0ab44 | 2013-12-04 14:08:58 -0800 | [diff] [blame] | 627 | if (flowEntry.flowEntryUserState() != |
| 628 | FlowEntryUserState.FE_USER_DELETE) { |
| 629 | continue; |
Pavlin Radoslavov | 9f33edb | 2013-11-06 18:24:37 -0800 | [diff] [blame] | 630 | } |
| 631 | |
Pavlin Radoslavov | da0ab44 | 2013-12-04 14:08:58 -0800 | [diff] [blame] | 632 | // |
| 633 | // NOTE: The deletion of Flow Entries for my switches is handled |
| 634 | // elsewhere. |
| 635 | // |
| 636 | IOFSwitch mySwitch = mySwitches.get(flowEntry.dpid().value()); |
| 637 | if (mySwitch != null) |
| 638 | continue; |
| 639 | |
Yuta HIGUCHI | 5302ddf | 2014-01-06 12:53:35 -0800 | [diff] [blame] | 640 | log.debug("Pushing cleanup of Flow Entry To Datagrid: {}", flowEntry); |
Pavlin Radoslavov | da0ab44 | 2013-12-04 14:08:58 -0800 | [diff] [blame] | 641 | |
Pavlin Radoslavov | 9f33edb | 2013-11-06 18:24:37 -0800 | [diff] [blame] | 642 | // |
| 643 | // Write the Flow Entry to the Datagrid |
| 644 | // |
Pavlin Radoslavov | da0ab44 | 2013-12-04 14:08:58 -0800 | [diff] [blame] | 645 | datagridService.notificationSendFlowEntryRemoved(flowEntry.flowEntryId()); |
Pavlin Radoslavov | 9f33edb | 2013-11-06 18:24:37 -0800 | [diff] [blame] | 646 | } |
| 647 | } |
Pavlin Radoslavov | ebc8b19 | 2013-10-29 15:35:35 -0700 | [diff] [blame] | 648 | |
Pavlin Radoslavov | 9f33edb | 2013-11-06 18:24:37 -0800 | [diff] [blame] | 649 | /** |
Pavlin Radoslavov | 584bd11 | 2013-11-21 20:59:33 -0800 | [diff] [blame] | 650 | * Class to implement writing to the database in a separate thread. |
| 651 | */ |
| 652 | class FlowDatabaseWriter extends Thread { |
| 653 | private FlowManager flowManager; |
Pavlin Radoslavov | 2fca8d1 | 2013-12-04 09:39:06 -0800 | [diff] [blame] | 654 | private BlockingQueue<FlowPath> blockingQueue; |
Pavlin Radoslavov | 584bd11 | 2013-11-21 20:59:33 -0800 | [diff] [blame] | 655 | |
| 656 | /** |
| 657 | * Constructor. |
| 658 | * |
| 659 | * @param flowManager the Flow Manager to use. |
| 660 | * @param blockingQueue the blocking queue to use. |
| 661 | */ |
| 662 | FlowDatabaseWriter(FlowManager flowManager, |
Pavlin Radoslavov | 2fca8d1 | 2013-12-04 09:39:06 -0800 | [diff] [blame] | 663 | BlockingQueue<FlowPath> blockingQueue) { |
Pavlin Radoslavov | 584bd11 | 2013-11-21 20:59:33 -0800 | [diff] [blame] | 664 | this.flowManager = flowManager; |
| 665 | this.blockingQueue = blockingQueue; |
| 666 | } |
| 667 | |
| 668 | /** |
| 669 | * Run the thread. |
| 670 | */ |
| 671 | @Override |
| 672 | public void run() { |
| 673 | // |
| 674 | // The main loop |
| 675 | // |
Pavlin Radoslavov | 2fca8d1 | 2013-12-04 09:39:06 -0800 | [diff] [blame] | 676 | Collection<FlowPath> collection = new LinkedList<FlowPath>(); |
Yuta HIGUCHI | 61509a4 | 2013-12-17 10:41:04 -0800 | [diff] [blame] | 677 | this.setName("FlowDatabaseWriter " + this.getId() ); |
Pavlin Radoslavov | 584bd11 | 2013-11-21 20:59:33 -0800 | [diff] [blame] | 678 | try { |
| 679 | while (true) { |
Pavlin Radoslavov | 2fca8d1 | 2013-12-04 09:39:06 -0800 | [diff] [blame] | 680 | FlowPath flowPath = blockingQueue.take(); |
| 681 | collection.add(flowPath); |
Pavlin Radoslavov | 584bd11 | 2013-11-21 20:59:33 -0800 | [diff] [blame] | 682 | blockingQueue.drainTo(collection); |
Pavlin Radoslavov | 2fca8d1 | 2013-12-04 09:39:06 -0800 | [diff] [blame] | 683 | flowManager.writeModifiedFlowPathsToDatabase(collection); |
Pavlin Radoslavov | 584bd11 | 2013-11-21 20:59:33 -0800 | [diff] [blame] | 684 | collection.clear(); |
| 685 | } |
| 686 | } catch (Exception exception) { |
| 687 | log.debug("Exception writing to the Database: ", exception); |
| 688 | } |
| 689 | } |
| 690 | } |
| 691 | |
| 692 | /** |
Pavlin Radoslavov | 2fca8d1 | 2013-12-04 09:39:06 -0800 | [diff] [blame] | 693 | * Push Flow Paths to the Network MAP. |
Pavlin Radoslavov | 9f33edb | 2013-11-06 18:24:37 -0800 | [diff] [blame] | 694 | * |
Pavlin Radoslavov | 2fca8d1 | 2013-12-04 09:39:06 -0800 | [diff] [blame] | 695 | * NOTE: The complete Flow Paths are pushed only on the instance |
| 696 | * responsible for the first switch. This is to avoid database errors |
| 697 | * when multiple instances are writing Flow Entries for the same Flow Path. |
Pavlin Radoslavov | 6311717 | 2013-11-07 02:18:37 -0800 | [diff] [blame] | 698 | * |
Pavlin Radoslavov | 2fca8d1 | 2013-12-04 09:39:06 -0800 | [diff] [blame] | 699 | * @param modifiedFlowPaths the collection of Flow Paths to push. |
Pavlin Radoslavov | 9f33edb | 2013-11-06 18:24:37 -0800 | [diff] [blame] | 700 | */ |
Pavlin Radoslavov | a0c1636 | 2013-12-04 13:18:08 -0800 | [diff] [blame] | 701 | private void pushModifiedFlowPathsToDatabase( |
Pavlin Radoslavov | 2fca8d1 | 2013-12-04 09:39:06 -0800 | [diff] [blame] | 702 | Collection<FlowPath> modifiedFlowPaths) { |
Pavlin Radoslavov | da8d723 | 2013-12-12 12:48:14 -0800 | [diff] [blame] | 703 | List<FlowPath> copiedFlowPaths = new LinkedList<FlowPath>(); |
| 704 | |
| 705 | // |
| 706 | // Create a copy of the Flow Paths to push, because the pushing |
| 707 | // itself will happen on a separate thread. |
| 708 | // |
| 709 | Kryo kryo = kryoFactory.newKryo(); |
| 710 | for (FlowPath flowPath : modifiedFlowPaths) { |
| 711 | FlowPath copyFlowPath = kryo.copy(flowPath); |
| 712 | copiedFlowPaths.add(copyFlowPath); |
| 713 | } |
| 714 | kryoFactory.deleteKryo(kryo); |
| 715 | |
Pavlin Radoslavov | 584bd11 | 2013-11-21 20:59:33 -0800 | [diff] [blame] | 716 | // |
Pavlin Radoslavov | 2fca8d1 | 2013-12-04 09:39:06 -0800 | [diff] [blame] | 717 | // We only add the Flow Paths to the Database Queue. |
Pavlin Radoslavov | 584bd11 | 2013-11-21 20:59:33 -0800 | [diff] [blame] | 718 | // The FlowDatabaseWriter thread is responsible for the actual writing. |
| 719 | // |
Pavlin Radoslavov | da8d723 | 2013-12-12 12:48:14 -0800 | [diff] [blame] | 720 | flowPathsToDatabaseQueue.addAll(copiedFlowPaths); |
Pavlin Radoslavov | 584bd11 | 2013-11-21 20:59:33 -0800 | [diff] [blame] | 721 | } |
| 722 | |
| 723 | /** |
Pavlin Radoslavov | 2fca8d1 | 2013-12-04 09:39:06 -0800 | [diff] [blame] | 724 | * Write Flow Paths to the Network MAP. |
Pavlin Radoslavov | 584bd11 | 2013-11-21 20:59:33 -0800 | [diff] [blame] | 725 | * |
Pavlin Radoslavov | 2fca8d1 | 2013-12-04 09:39:06 -0800 | [diff] [blame] | 726 | * NOTE: The complete Flow Paths are pushed only on the instance |
| 727 | * responsible for the first switch. This is to avoid database errors |
| 728 | * when multiple instances are writing Flow Entries for the same Flow Path. |
Pavlin Radoslavov | 584bd11 | 2013-11-21 20:59:33 -0800 | [diff] [blame] | 729 | * |
Pavlin Radoslavov | 2fca8d1 | 2013-12-04 09:39:06 -0800 | [diff] [blame] | 730 | * @param modifiedFlowPaths the collection of Flow Paths to write. |
Pavlin Radoslavov | 584bd11 | 2013-11-21 20:59:33 -0800 | [diff] [blame] | 731 | */ |
Pavlin Radoslavov | 417398f | 2014-01-10 13:04:33 -0800 | [diff] [blame] | 732 | void writeModifiedFlowPathsToDatabase( |
Pavlin Radoslavov | 2fca8d1 | 2013-12-04 09:39:06 -0800 | [diff] [blame] | 733 | Collection<FlowPath> modifiedFlowPaths) { |
| 734 | if (modifiedFlowPaths.isEmpty()) |
Pavlin Radoslavov | 9f33edb | 2013-11-06 18:24:37 -0800 | [diff] [blame] | 735 | return; |
Pavlin Radoslavov | ebc8b19 | 2013-10-29 15:35:35 -0700 | [diff] [blame] | 736 | |
Pavlin Radoslavov | 9f33edb | 2013-11-06 18:24:37 -0800 | [diff] [blame] | 737 | Map<Long, IOFSwitch> mySwitches = getMySwitches(); |
Pavlin Radoslavov | ebc8b19 | 2013-10-29 15:35:35 -0700 | [diff] [blame] | 738 | |
Pavlin Radoslavov | 2fca8d1 | 2013-12-04 09:39:06 -0800 | [diff] [blame] | 739 | for (FlowPath flowPath : modifiedFlowPaths) { |
Pavlin Radoslavov | 9f33edb | 2013-11-06 18:24:37 -0800 | [diff] [blame] | 740 | // |
Pavlin Radoslavov | 6311717 | 2013-11-07 02:18:37 -0800 | [diff] [blame] | 741 | // Push the changes only on the instance responsible for the |
| 742 | // first switch. |
Pavlin Radoslavov | 9f33edb | 2013-11-06 18:24:37 -0800 | [diff] [blame] | 743 | // |
Pavlin Radoslavov | 6311717 | 2013-11-07 02:18:37 -0800 | [diff] [blame] | 744 | Dpid srcDpid = flowPath.dataPath().srcPort().dpid(); |
| 745 | IOFSwitch mySrcSwitch = mySwitches.get(srcDpid.value()); |
| 746 | if (mySrcSwitch == null) |
| 747 | continue; |
Pavlin Radoslavov | 9f33edb | 2013-11-06 18:24:37 -0800 | [diff] [blame] | 748 | |
| 749 | // |
Pavlin Radoslavov | ef54505 | 2013-12-05 15:17:25 -0800 | [diff] [blame] | 750 | // Delete the Flow Path from the Network Map |
| 751 | // |
| 752 | if (flowPath.flowPathUserState() == |
| 753 | FlowPathUserState.FP_USER_DELETE) { |
Yuta HIGUCHI | 5302ddf | 2014-01-06 12:53:35 -0800 | [diff] [blame] | 754 | log.debug("Deleting Flow Path From Database: {}", flowPath); |
Pavlin Radoslavov | ef54505 | 2013-12-05 15:17:25 -0800 | [diff] [blame] | 755 | |
Pavlin Radoslavov | 262e683 | 2013-12-18 14:37:35 -0800 | [diff] [blame] | 756 | boolean retry = false; |
| 757 | do { |
| 758 | retry = false; |
| 759 | try { |
| 760 | if (! FlowDatabaseOperation.deleteFlow( |
| 761 | dbHandlerInner, |
| 762 | flowPath.flowId())) { |
| 763 | log.error("Cannot delete Flow Path {} from Network Map", |
| 764 | flowPath.flowId()); |
| 765 | retry = true; |
| 766 | } |
| 767 | } catch (TitanException te) { |
| 768 | log.error("Titan Exception deleting Flow Path from Network MAP: {}", te); |
| 769 | retry = true; |
| 770 | } catch (Exception e) { |
| 771 | log.error("Exception deleting Flow Path from Network MAP: {}", e); |
Yuta HIGUCHI | 67a7a3e | 2014-01-03 14:51:34 -0800 | [diff] [blame] | 772 | } |
Pavlin Radoslavov | 262e683 | 2013-12-18 14:37:35 -0800 | [diff] [blame] | 773 | } while (retry); |
| 774 | |
Pavlin Radoslavov | ef54505 | 2013-12-05 15:17:25 -0800 | [diff] [blame] | 775 | continue; |
| 776 | } |
| 777 | |
| 778 | // |
Pavlin Radoslavov | 2fca8d1 | 2013-12-04 09:39:06 -0800 | [diff] [blame] | 779 | // Test whether all Flow Entries are valid |
Pavlin Radoslavov | 9f33edb | 2013-11-06 18:24:37 -0800 | [diff] [blame] | 780 | // |
Pavlin Radoslavov | 2fca8d1 | 2013-12-04 09:39:06 -0800 | [diff] [blame] | 781 | boolean allValid = true; |
| 782 | for (FlowEntry flowEntry : flowPath.flowEntries()) { |
| 783 | if (flowEntry.flowEntryUserState() == |
| 784 | FlowEntryUserState.FE_USER_DELETE) { |
| 785 | continue; |
Pavlin Radoslavov | ebc8b19 | 2013-10-29 15:35:35 -0700 | [diff] [blame] | 786 | } |
Pavlin Radoslavov | 2fca8d1 | 2013-12-04 09:39:06 -0800 | [diff] [blame] | 787 | if (! flowEntry.isValidFlowEntryId()) { |
| 788 | allValid = false; |
| 789 | break; |
| 790 | } |
Pavlin Radoslavov | 8252fee | 2014-01-07 17:24:29 -0800 | [diff] [blame] | 791 | if (! enableOnrc2014MeasurementsFlows) { |
| 792 | if (flowEntry.flowEntrySwitchState() != |
| 793 | FlowEntrySwitchState.FE_SWITCH_UPDATED) { |
| 794 | allValid = false; |
| 795 | break; |
| 796 | } |
Pavlin Radoslavov | 237fde7 | 2013-12-17 22:21:06 -0800 | [diff] [blame] | 797 | } |
Pavlin Radoslavov | 2fca8d1 | 2013-12-04 09:39:06 -0800 | [diff] [blame] | 798 | } |
| 799 | if (! allValid) |
| 800 | continue; |
| 801 | |
Yuta HIGUCHI | 5302ddf | 2014-01-06 12:53:35 -0800 | [diff] [blame] | 802 | log.debug("Pushing Flow Path To Database: {}", flowPath); |
Pavlin Radoslavov | 2fca8d1 | 2013-12-04 09:39:06 -0800 | [diff] [blame] | 803 | |
| 804 | // |
| 805 | // Write the Flow Path to the Network Map |
| 806 | // |
Pavlin Radoslavov | 262e683 | 2013-12-18 14:37:35 -0800 | [diff] [blame] | 807 | boolean retry = false; |
| 808 | do { |
| 809 | retry = false; |
| 810 | try { |
| 811 | if (! FlowDatabaseOperation.addFlow(dbHandlerInner, flowPath)) { |
Yuta HIGUCHI | 5302ddf | 2014-01-06 12:53:35 -0800 | [diff] [blame] | 812 | log.error("Cannot write to Network Map Flow Path {}", flowPath.flowId()); |
Pavlin Radoslavov | 262e683 | 2013-12-18 14:37:35 -0800 | [diff] [blame] | 813 | retry = true; |
| 814 | } |
| 815 | } catch (TitanException te) { |
| 816 | log.error("Titan Exception writing Flow Path to Network MAP: ", te); |
| 817 | retry = true; |
| 818 | } catch (Exception e) { |
| 819 | log.error("Exception writing Flow Path to Network MAP: ", e); |
Pavlin Radoslavov | 2fca8d1 | 2013-12-04 09:39:06 -0800 | [diff] [blame] | 820 | } |
Pavlin Radoslavov | 262e683 | 2013-12-18 14:37:35 -0800 | [diff] [blame] | 821 | } while (retry); |
Pavlin Radoslavov | 8252fee | 2014-01-07 17:24:29 -0800 | [diff] [blame] | 822 | |
| 823 | if (enableOnrc2014MeasurementsFlows) { |
Pavlin Radoslavov | f4bdf26 | 2014-01-09 13:51:40 -0800 | [diff] [blame] | 824 | // Send the notifications |
Pavlin Radoslavov | 7847db7 | 2014-01-10 11:35:21 -0800 | [diff] [blame] | 825 | |
Pavlin Radoslavov | f4bdf26 | 2014-01-09 13:51:40 -0800 | [diff] [blame] | 826 | for (FlowEntry flowEntry : flowPath.flowEntries()) { |
Pavlin Radoslavov | 8edd441 | 2014-01-10 11:37:32 -0800 | [diff] [blame] | 827 | if (flowEntry.flowEntrySwitchState() != |
Pavlin Radoslavov | f4bdf26 | 2014-01-09 13:51:40 -0800 | [diff] [blame] | 828 | FlowEntrySwitchState.FE_SWITCH_NOT_UPDATED) { |
Pavlin Radoslavov | 8edd441 | 2014-01-10 11:37:32 -0800 | [diff] [blame] | 829 | continue; |
Pavlin Radoslavov | f4bdf26 | 2014-01-09 13:51:40 -0800 | [diff] [blame] | 830 | } |
Pavlin Radoslavov | 8edd441 | 2014-01-10 11:37:32 -0800 | [diff] [blame] | 831 | // datagridService.notificationSendFlowEntryIdAdded(flowEntry.flowEntryId(), flowEntry.dpid()); |
Pavlin Radoslavov | 7847db7 | 2014-01-10 11:35:21 -0800 | [diff] [blame] | 832 | |
| 833 | // |
| 834 | // Write the Flow Entry to the Datagrid |
| 835 | // |
| 836 | switch (flowEntry.flowEntryUserState()) { |
| 837 | case FE_USER_ADD: |
| 838 | datagridService.notificationSendFlowEntryAdded(flowEntry); |
| 839 | break; |
| 840 | case FE_USER_MODIFY: |
| 841 | datagridService.notificationSendFlowEntryUpdated(flowEntry); |
| 842 | break; |
| 843 | case FE_USER_DELETE: |
| 844 | datagridService.notificationSendFlowEntryRemoved(flowEntry.flowEntryId()); |
| 845 | break; |
| 846 | case FE_USER_UNKNOWN: |
| 847 | assert(false); |
| 848 | break; |
| 849 | } |
Pavlin Radoslavov | f4bdf26 | 2014-01-09 13:51:40 -0800 | [diff] [blame] | 850 | } |
Pavlin Radoslavov | 8252fee | 2014-01-07 17:24:29 -0800 | [diff] [blame] | 851 | } |
Pavlin Radoslavov | ebc8b19 | 2013-10-29 15:35:35 -0700 | [diff] [blame] | 852 | } |
Pavlin Radoslavov | ebc8b19 | 2013-10-29 15:35:35 -0700 | [diff] [blame] | 853 | } |
Pavlin Radoslavov | 9e5344c | 2013-02-18 09:58:30 -0800 | [diff] [blame] | 854 | } |