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