Jonathan Hart | 0961fe8 | 2014-04-03 09:56:25 -0700 | [diff] [blame] | 1 | package net.onrc.onos.apps.forwarding; |
Jonathan Hart | 1caaa93 | 2013-11-04 15:28:28 -0800 | [diff] [blame] | 2 | |
Jonathan Hart | 41d1e91 | 2013-11-24 16:50:25 -0800 | [diff] [blame] | 3 | import java.util.ArrayList; |
Jonathan Hart | e93aed4 | 2013-12-05 18:39:50 -0800 | [diff] [blame] | 4 | import java.util.Collection; |
Jonathan Hart | d33a6cf | 2013-12-10 14:29:08 -0800 | [diff] [blame] | 5 | import java.util.HashMap; |
Jonathan Hart | 1caaa93 | 2013-11-04 15:28:28 -0800 | [diff] [blame] | 6 | import java.util.Iterator; |
TeruU | f911165 | 2014-05-14 23:10:35 -0700 | [diff] [blame] | 7 | import java.util.LinkedList; |
Jonathan Hart | 41d1e91 | 2013-11-24 16:50:25 -0800 | [diff] [blame] | 8 | import java.util.List; |
Jonathan Hart | e93aed4 | 2013-12-05 18:39:50 -0800 | [diff] [blame] | 9 | import java.util.Map; |
TeruU | 417fe02 | 2014-02-04 12:59:30 -0800 | [diff] [blame] | 10 | import java.util.concurrent.Executors; |
| 11 | import java.util.concurrent.ScheduledExecutorService; |
| 12 | import java.util.concurrent.TimeUnit; |
Jonathan Hart | 1caaa93 | 2013-11-04 15:28:28 -0800 | [diff] [blame] | 13 | |
Jonathan Hart | e93aed4 | 2013-12-05 18:39:50 -0800 | [diff] [blame] | 14 | import net.floodlightcontroller.core.module.FloodlightModuleContext; |
| 15 | import net.floodlightcontroller.core.module.IFloodlightModule; |
| 16 | import net.floodlightcontroller.core.module.IFloodlightService; |
Jonathan Hart | 1caaa93 | 2013-11-04 15:28:28 -0800 | [diff] [blame] | 17 | import net.floodlightcontroller.util.MACAddress; |
Jonathan Hart | f5bd258 | 2014-04-09 17:43:41 -0700 | [diff] [blame] | 18 | import net.onrc.onos.api.packet.IPacketListener; |
| 19 | import net.onrc.onos.api.packet.IPacketService; |
Jonathan Hart | 0961fe8 | 2014-04-03 09:56:25 -0700 | [diff] [blame] | 20 | import net.onrc.onos.apps.proxyarp.IProxyArpService; |
Jonathan Hart | 23701d1 | 2014-04-03 10:45:48 -0700 | [diff] [blame] | 21 | import net.onrc.onos.core.devicemanager.IOnosDeviceService; |
Jonathan Hart | aa38097 | 2014-04-03 10:24:46 -0700 | [diff] [blame] | 22 | import net.onrc.onos.core.intent.Intent; |
Jonathan Hart | a99ec67 | 2014-04-03 11:30:34 -0700 | [diff] [blame] | 23 | import net.onrc.onos.core.intent.Intent.IntentState; |
Jonathan Hart | aa38097 | 2014-04-03 10:24:46 -0700 | [diff] [blame] | 24 | import net.onrc.onos.core.intent.IntentMap; |
TeruU | f911165 | 2014-05-14 23:10:35 -0700 | [diff] [blame] | 25 | import net.onrc.onos.core.intent.IntentMap.ChangedEvent; |
| 26 | import net.onrc.onos.core.intent.IntentMap.ChangedListener; |
Jonathan Hart | aa38097 | 2014-04-03 10:24:46 -0700 | [diff] [blame] | 27 | import net.onrc.onos.core.intent.IntentOperation; |
| 28 | import net.onrc.onos.core.intent.IntentOperationList; |
| 29 | import net.onrc.onos.core.intent.PathIntent; |
| 30 | import net.onrc.onos.core.intent.ShortestPathIntent; |
Jonathan Hart | aa38097 | 2014-04-03 10:24:46 -0700 | [diff] [blame] | 31 | import net.onrc.onos.core.intent.runtime.IPathCalcRuntimeService; |
Jonathan Hart | deda0ba | 2014-04-03 11:14:12 -0700 | [diff] [blame] | 32 | import net.onrc.onos.core.packet.Ethernet; |
| 33 | import net.onrc.onos.core.registry.IControllerRegistryService; |
Jonathan Hart | 472062d | 2014-04-03 10:56:48 -0700 | [diff] [blame] | 34 | import net.onrc.onos.core.topology.Device; |
Jonathan Hart | e37e4e2 | 2014-05-13 19:12:02 -0700 | [diff] [blame] | 35 | import net.onrc.onos.core.topology.ITopologyService; |
Jonathan Hart | 472062d | 2014-04-03 10:56:48 -0700 | [diff] [blame] | 36 | import net.onrc.onos.core.topology.LinkEvent; |
Jonathan Hart | f5bd258 | 2014-04-09 17:43:41 -0700 | [diff] [blame] | 37 | import net.onrc.onos.core.topology.Port; |
Jonathan Hart | 472062d | 2014-04-03 10:56:48 -0700 | [diff] [blame] | 38 | import net.onrc.onos.core.topology.Switch; |
TeruU | f911165 | 2014-05-14 23:10:35 -0700 | [diff] [blame] | 39 | import net.onrc.onos.core.topology.Topology; |
Jonathan Hart | 23701d1 | 2014-04-03 10:45:48 -0700 | [diff] [blame] | 40 | import net.onrc.onos.core.util.Dpid; |
| 41 | import net.onrc.onos.core.util.FlowPath; |
Yuta HIGUCHI | fb56450 | 2014-06-16 21:29:00 -0700 | [diff] [blame] | 42 | import net.onrc.onos.core.util.PortNumber; |
Jonathan Hart | 23701d1 | 2014-04-03 10:45:48 -0700 | [diff] [blame] | 43 | import net.onrc.onos.core.util.SwitchPort; |
Jonathan Hart | 1caaa93 | 2013-11-04 15:28:28 -0800 | [diff] [blame] | 44 | |
Jonathan Hart | 1caaa93 | 2013-11-04 15:28:28 -0800 | [diff] [blame] | 45 | import org.openflow.util.HexString; |
| 46 | import org.slf4j.Logger; |
| 47 | import org.slf4j.LoggerFactory; |
| 48 | |
Jonathan Hart | d857ad6 | 2013-12-14 18:08:17 -0800 | [diff] [blame] | 49 | import com.google.common.collect.LinkedListMultimap; |
| 50 | import com.google.common.collect.ListMultimap; |
Jonathan Hart | 5e44878 | 2013-12-10 12:36:35 -0800 | [diff] [blame] | 51 | |
Jonathan Hart | f5bd258 | 2014-04-09 17:43:41 -0700 | [diff] [blame] | 52 | public class Forwarding implements /*IOFMessageListener,*/ IFloodlightModule, |
TeruU | f911165 | 2014-05-14 23:10:35 -0700 | [diff] [blame] | 53 | IForwardingService, IPacketListener, ChangedListener { |
Ray Milkey | ec83894 | 2014-04-09 11:28:43 -0700 | [diff] [blame] | 54 | private static final Logger log = LoggerFactory.getLogger(Forwarding.class); |
TeruU | 7feef8a | 2014-04-03 00:15:49 -0700 | [diff] [blame] | 55 | |
Ray Milkey | 2476cac | 2014-04-08 11:03:21 -0700 | [diff] [blame] | 56 | private static final int SLEEP_TIME_FOR_DB_DEVICE_INSTALLED = 100; // milliseconds |
Ray Milkey | ec83894 | 2014-04-09 11:28:43 -0700 | [diff] [blame] | 57 | private static final int NUMBER_OF_THREAD_FOR_EXECUTOR = 1; |
TeruU | 30c0c93 | 2014-05-15 16:47:41 -0700 | [diff] [blame] | 58 | private static final int SRC_SWITCH_TIMEOUT_ADJUST_SECOND = 2; |
| 59 | private static final int DEFAULT_IDLE_TIMEOUT = 5; |
| 60 | private int idleTimeout = DEFAULT_IDLE_TIMEOUT; |
Pavlin Radoslavov | 902fe52 | 2014-03-31 10:11:31 -0700 | [diff] [blame] | 61 | |
Jonathan Hart | c00f5c2 | 2014-06-10 15:14:40 -0700 | [diff] [blame] | 62 | private static final ScheduledExecutorService EXECUTOR_SERVICE = |
| 63 | Executors.newScheduledThreadPool(NUMBER_OF_THREAD_FOR_EXECUTOR); |
Jonathan Hart | e93aed4 | 2013-12-05 18:39:50 -0800 | [diff] [blame] | 64 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 65 | private final String callerId = "Forwarding"; |
Jonathan Hart | e93aed4 | 2013-12-05 18:39:50 -0800 | [diff] [blame] | 66 | |
TeruU | 435df32 | 2014-06-16 23:45:13 -0700 | [diff] [blame] | 67 | private final HighLevelIntentChangedHandler highLevelIntentChangedHandler = |
| 68 | new HighLevelIntentChangedHandler(); |
| 69 | |
Jonathan Hart | f5bd258 | 2014-04-09 17:43:41 -0700 | [diff] [blame] | 70 | private IPacketService packetService; |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 71 | private IControllerRegistryService controllerRegistryService; |
| 72 | |
Jonathan Hart | e37e4e2 | 2014-05-13 19:12:02 -0700 | [diff] [blame] | 73 | private ITopologyService topologyService; |
| 74 | private Topology topology; |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 75 | private IPathCalcRuntimeService pathRuntime; |
TeruU | 9e53066 | 2014-05-18 11:49:37 -0700 | [diff] [blame] | 76 | private IntentMap pathIntentMap; |
| 77 | private IntentMap highLevelIntentMap; |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 78 | |
| 79 | // TODO it seems there is a Guava collection that will time out entries. |
| 80 | // We should see if this will work here. |
| 81 | private Map<Path, PushedFlow> pendingFlows; |
| 82 | private ListMultimap<String, PacketToPush> waitingPackets; |
| 83 | |
| 84 | private final Object lock = new Object(); |
| 85 | |
TeruU | 435df32 | 2014-06-16 23:45:13 -0700 | [diff] [blame] | 86 | private class HighLevelIntentChangedHandler implements ChangedListener { |
| 87 | |
| 88 | @Override |
| 89 | public void intentsChange(LinkedList<ChangedEvent> events) { |
| 90 | for (ChangedEvent event : events) { |
| 91 | ShortestPathIntent spfIntent = null; |
| 92 | if (event.intent instanceof ShortestPathIntent) { |
| 93 | spfIntent = (ShortestPathIntent) event.intent; |
| 94 | log.trace("ShortestPathIntent {}", spfIntent); |
| 95 | } |
| 96 | |
| 97 | if (spfIntent == null) { |
| 98 | log.trace("ShortestPathIntent is null. Skip."); |
| 99 | continue; |
| 100 | } |
| 101 | |
| 102 | switch(event.eventType) { |
| 103 | case ADDED: |
| 104 | break; |
| 105 | case REMOVED: |
| 106 | break; |
| 107 | case STATE_CHANGED: |
| 108 | if (spfIntent.getState() == IntentState.INST_NACK) { |
| 109 | flowRemoved(spfIntent); |
| 110 | } |
| 111 | break; |
| 112 | default: |
| 113 | break; |
| 114 | } |
| 115 | } |
| 116 | } |
| 117 | |
| 118 | } |
| 119 | |
Jonathan Hart | 8ed69c5 | 2014-04-09 13:29:16 -0700 | [diff] [blame] | 120 | private static class PacketToPush { |
Jonathan Hart | f5bd258 | 2014-04-09 17:43:41 -0700 | [diff] [blame] | 121 | public final Ethernet eth; |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 122 | public final long dpid; |
| 123 | |
Jonathan Hart | f5bd258 | 2014-04-09 17:43:41 -0700 | [diff] [blame] | 124 | public PacketToPush(Ethernet eth, long dpid) { |
| 125 | this.eth = eth; |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 126 | this.dpid = dpid; |
| 127 | } |
| 128 | } |
| 129 | |
Jonathan Hart | 8ed69c5 | 2014-04-09 13:29:16 -0700 | [diff] [blame] | 130 | private static class PushedFlow { |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 131 | public final String intentId; |
| 132 | public boolean installed = false; |
| 133 | public short firstOutPort; |
| 134 | |
| 135 | public PushedFlow(String flowId) { |
| 136 | this.intentId = flowId; |
| 137 | } |
| 138 | } |
| 139 | |
Jonathan Hart | 8ed69c5 | 2014-04-09 13:29:16 -0700 | [diff] [blame] | 140 | private static final class Path { |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 141 | public final MACAddress srcMac; |
| 142 | public final MACAddress dstMac; |
| 143 | |
| 144 | public Path(MACAddress srcMac, MACAddress dstMac) { |
| 145 | this.srcMac = srcMac; |
| 146 | this.dstMac = dstMac; |
| 147 | } |
| 148 | |
| 149 | @Override |
| 150 | public boolean equals(Object other) { |
| 151 | if (!(other instanceof Path)) { |
| 152 | return false; |
| 153 | } |
| 154 | |
| 155 | Path otherPath = (Path) other; |
| 156 | return srcMac.equals(otherPath.srcMac) && |
| 157 | dstMac.equals(otherPath.dstMac); |
| 158 | } |
| 159 | |
| 160 | @Override |
| 161 | public int hashCode() { |
| 162 | int hash = 17; |
| 163 | hash = 31 * hash + srcMac.hashCode(); |
| 164 | hash = 31 * hash + dstMac.hashCode(); |
| 165 | return hash; |
| 166 | } |
| 167 | |
| 168 | @Override |
| 169 | public String toString() { |
| 170 | return "(" + srcMac + ") => (" + dstMac + ")"; |
| 171 | } |
| 172 | } |
| 173 | |
| 174 | @Override |
| 175 | public Collection<Class<? extends IFloodlightService>> getModuleServices() { |
| 176 | List<Class<? extends IFloodlightService>> services = |
| 177 | new ArrayList<Class<? extends IFloodlightService>>(1); |
| 178 | services.add(IForwardingService.class); |
| 179 | return services; |
| 180 | } |
| 181 | |
| 182 | @Override |
| 183 | public Map<Class<? extends IFloodlightService>, IFloodlightService> getServiceImpls() { |
| 184 | Map<Class<? extends IFloodlightService>, IFloodlightService> impls = |
| 185 | new HashMap<Class<? extends IFloodlightService>, IFloodlightService>(1); |
| 186 | impls.put(IForwardingService.class, this); |
| 187 | return impls; |
| 188 | } |
| 189 | |
| 190 | @Override |
| 191 | public Collection<Class<? extends IFloodlightService>> getModuleDependencies() { |
| 192 | List<Class<? extends IFloodlightService>> dependencies = |
| 193 | new ArrayList<Class<? extends IFloodlightService>>(); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 194 | dependencies.add(IControllerRegistryService.class); |
| 195 | dependencies.add(IOnosDeviceService.class); |
Jonathan Hart | e37e4e2 | 2014-05-13 19:12:02 -0700 | [diff] [blame] | 196 | dependencies.add(ITopologyService.class); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 197 | dependencies.add(IPathCalcRuntimeService.class); |
| 198 | // We don't use the IProxyArpService directly, but reactive forwarding |
| 199 | // requires it to be loaded and answering ARP requests |
| 200 | dependencies.add(IProxyArpService.class); |
Jonathan Hart | f5bd258 | 2014-04-09 17:43:41 -0700 | [diff] [blame] | 201 | dependencies.add(IPacketService.class); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 202 | return dependencies; |
| 203 | } |
| 204 | |
| 205 | @Override |
| 206 | public void init(FloodlightModuleContext context) { |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 207 | controllerRegistryService = context.getServiceImpl(IControllerRegistryService.class); |
Jonathan Hart | e37e4e2 | 2014-05-13 19:12:02 -0700 | [diff] [blame] | 208 | topologyService = context.getServiceImpl(ITopologyService.class); |
TeruU | 7feef8a | 2014-04-03 00:15:49 -0700 | [diff] [blame] | 209 | pathRuntime = context.getServiceImpl(IPathCalcRuntimeService.class); |
Jonathan Hart | f5bd258 | 2014-04-09 17:43:41 -0700 | [diff] [blame] | 210 | packetService = context.getServiceImpl(IPacketService.class); |
TeruU | 7feef8a | 2014-04-03 00:15:49 -0700 | [diff] [blame] | 211 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 212 | pendingFlows = new HashMap<Path, PushedFlow>(); |
| 213 | waitingPackets = LinkedListMultimap.create(); |
| 214 | } |
Jonathan Hart | 1caaa93 | 2013-11-04 15:28:28 -0800 | [diff] [blame] | 215 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 216 | @Override |
| 217 | public void startUp(FloodlightModuleContext context) { |
TeruU | 30c0c93 | 2014-05-15 16:47:41 -0700 | [diff] [blame] | 218 | Map<String, String> configOptions = context.getConfigParams(this); |
| 219 | |
| 220 | try { |
| 221 | if (Integer.parseInt(configOptions.get("idletimeout")) > 0) { |
| 222 | idleTimeout = Integer.parseInt(configOptions.get("idletimeout")); |
| 223 | log.info("idle_timeout for Forwarding is set to {}.", idleTimeout); |
| 224 | } else { |
| 225 | log.info("idle_timeout for Forwarding is less than 0. Use default {}.", idleTimeout); |
| 226 | } |
| 227 | } catch (NumberFormatException e) { |
| 228 | log.info("idle_timeout related config options were not set. Use default."); |
| 229 | } |
| 230 | |
Jonathan Hart | f5bd258 | 2014-04-09 17:43:41 -0700 | [diff] [blame] | 231 | packetService.registerPacketListener(this); |
Jonathan Hart | 1caaa93 | 2013-11-04 15:28:28 -0800 | [diff] [blame] | 232 | |
Jonathan Hart | e37e4e2 | 2014-05-13 19:12:02 -0700 | [diff] [blame] | 233 | topology = topologyService.getTopology(); |
TeruU | 9e53066 | 2014-05-18 11:49:37 -0700 | [diff] [blame] | 234 | highLevelIntentMap = pathRuntime.getHighLevelIntents(); |
TeruU | 435df32 | 2014-06-16 23:45:13 -0700 | [diff] [blame] | 235 | highLevelIntentMap.addChangeListener(highLevelIntentChangedHandler); |
TeruU | 9e53066 | 2014-05-18 11:49:37 -0700 | [diff] [blame] | 236 | pathIntentMap = pathRuntime.getPathIntents(); |
| 237 | pathIntentMap.addChangeListener(this); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 238 | } |
Jonathan Hart | 1caaa93 | 2013-11-04 15:28:28 -0800 | [diff] [blame] | 239 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 240 | @Override |
Jonathan Hart | f5bd258 | 2014-04-09 17:43:41 -0700 | [diff] [blame] | 241 | public void receive(Switch sw, Port inPort, Ethernet eth) { |
TeruU | f911165 | 2014-05-14 23:10:35 -0700 | [diff] [blame] | 242 | if (log.isTraceEnabled()) { |
| 243 | log.trace("Receive PACKET_IN swId {}, portId {}", sw.getDpid(), inPort.getNumber()); |
| 244 | } |
TeruU | 417fe02 | 2014-02-04 12:59:30 -0800 | [diff] [blame] | 245 | |
Ray Milkey | 5c9f2db | 2014-04-09 10:31:21 -0700 | [diff] [blame] | 246 | if (eth.getEtherType() != Ethernet.TYPE_IPV4) { |
Jonathan Hart | f5bd258 | 2014-04-09 17:43:41 -0700 | [diff] [blame] | 247 | // Only handle IPv4 packets right now |
| 248 | return; |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 249 | } |
TeruU | 417fe02 | 2014-02-04 12:59:30 -0800 | [diff] [blame] | 250 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 251 | if (eth.isBroadcast() || eth.isMulticast()) { |
Jonathan Hart | f5bd258 | 2014-04-09 17:43:41 -0700 | [diff] [blame] | 252 | handleBroadcast(sw, inPort, eth); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 253 | } else { |
| 254 | // Unicast |
Jonathan Hart | f5bd258 | 2014-04-09 17:43:41 -0700 | [diff] [blame] | 255 | handlePacketIn(sw, inPort, eth); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 256 | } |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 257 | } |
TeruU | 417fe02 | 2014-02-04 12:59:30 -0800 | [diff] [blame] | 258 | |
Jonathan Hart | f5bd258 | 2014-04-09 17:43:41 -0700 | [diff] [blame] | 259 | private void handleBroadcast(Switch sw, Port inPort, Ethernet eth) { |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 260 | if (log.isTraceEnabled()) { |
| 261 | log.trace("Sending broadcast packet to other ONOS instances"); |
| 262 | } |
Jonathan Hart | 0444d93 | 2014-01-22 15:06:17 -0800 | [diff] [blame] | 263 | |
Jonathan Hart | e3702f2 | 2014-04-29 02:56:56 -0700 | [diff] [blame] | 264 | packetService.broadcastPacketOutEdge(eth, |
Yuta HIGUCHI | 8f3dfa3 | 2014-06-25 00:14:25 -0700 | [diff] [blame^] | 265 | new SwitchPort(sw.getDpid(), inPort.getNumber())); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 266 | } |
Pavlin Radoslavov | a3818db | 2014-03-20 19:26:08 -0700 | [diff] [blame] | 267 | |
Jonathan Hart | f5bd258 | 2014-04-09 17:43:41 -0700 | [diff] [blame] | 268 | private void handlePacketIn(Switch sw, Port inPort, Ethernet eth) { |
TeruU | f911165 | 2014-05-14 23:10:35 -0700 | [diff] [blame] | 269 | if (log.isTraceEnabled()) { |
| 270 | log.trace("Start handlePacketIn swId {}, portId {}", sw.getDpid(), inPort.getNumber()); |
| 271 | } |
TeruU | 7feef8a | 2014-04-03 00:15:49 -0700 | [diff] [blame] | 272 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 273 | String destinationMac = |
| 274 | HexString.toHexString(eth.getDestinationMACAddress()); |
Jonathan Hart | 0444d93 | 2014-01-22 15:06:17 -0800 | [diff] [blame] | 275 | |
Jonathan Hart | c00f5c2 | 2014-06-10 15:14:40 -0700 | [diff] [blame] | 276 | // FIXME getDeviceByMac() is a blocking call, so it may be better way |
| 277 | // to handle it to avoid the condition. |
| 278 | Device deviceObject = topology.getDeviceByMac( |
| 279 | MACAddress.valueOf(destinationMac)); |
TeruU | 6464af0 | 2014-02-06 21:38:45 -0800 | [diff] [blame] | 280 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 281 | if (deviceObject == null) { |
| 282 | log.debug("No device entry found for {}", |
| 283 | destinationMac); |
Jonathan Hart | 1caaa93 | 2013-11-04 15:28:28 -0800 | [diff] [blame] | 284 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 285 | //Device is not in the DB, so wait it until the device is added. |
Jonathan Hart | c00f5c2 | 2014-06-10 15:14:40 -0700 | [diff] [blame] | 286 | EXECUTOR_SERVICE.schedule(new WaitDeviceArp(sw, inPort, eth), |
| 287 | SLEEP_TIME_FOR_DB_DEVICE_INSTALLED, TimeUnit.MILLISECONDS); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 288 | return; |
| 289 | } |
Pavlin Radoslavov | 7208e9a | 2013-12-11 14:31:07 -0800 | [diff] [blame] | 290 | |
Jonathan Hart | f5bd258 | 2014-04-09 17:43:41 -0700 | [diff] [blame] | 291 | continueHandlePacketIn(sw, inPort, eth, deviceObject); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 292 | } |
TeruU | 417fe02 | 2014-02-04 12:59:30 -0800 | [diff] [blame] | 293 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 294 | private class WaitDeviceArp implements Runnable { |
Jonathan Hart | f5bd258 | 2014-04-09 17:43:41 -0700 | [diff] [blame] | 295 | Switch sw; |
| 296 | Port inPort; |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 297 | Ethernet eth; |
TeruU | 417fe02 | 2014-02-04 12:59:30 -0800 | [diff] [blame] | 298 | |
Jonathan Hart | f5bd258 | 2014-04-09 17:43:41 -0700 | [diff] [blame] | 299 | public WaitDeviceArp(Switch sw, Port inPort, Ethernet eth) { |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 300 | super(); |
| 301 | this.sw = sw; |
Jonathan Hart | f5bd258 | 2014-04-09 17:43:41 -0700 | [diff] [blame] | 302 | this.inPort = inPort; |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 303 | this.eth = eth; |
| 304 | } |
TeruU | 417fe02 | 2014-02-04 12:59:30 -0800 | [diff] [blame] | 305 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 306 | @Override |
| 307 | public void run() { |
Jonathan Hart | e37e4e2 | 2014-05-13 19:12:02 -0700 | [diff] [blame] | 308 | Device deviceObject = topology.getDeviceByMac(MACAddress.valueOf(eth.getDestinationMACAddress())); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 309 | if (deviceObject == null) { |
Jonathan Hart | c00f5c2 | 2014-06-10 15:14:40 -0700 | [diff] [blame] | 310 | log.debug("wait {}ms and device was not found. " + |
| 311 | "Send broadcast packet and the thread finish.", |
| 312 | SLEEP_TIME_FOR_DB_DEVICE_INSTALLED); |
Jonathan Hart | f5bd258 | 2014-04-09 17:43:41 -0700 | [diff] [blame] | 313 | handleBroadcast(sw, inPort, eth); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 314 | return; |
| 315 | } |
Jonathan Hart | c00f5c2 | 2014-06-10 15:14:40 -0700 | [diff] [blame] | 316 | log.debug("wait {}ms and device {} was found, continue", |
| 317 | SLEEP_TIME_FOR_DB_DEVICE_INSTALLED, deviceObject.getMacAddress()); |
Jonathan Hart | f5bd258 | 2014-04-09 17:43:41 -0700 | [diff] [blame] | 318 | continueHandlePacketIn(sw, inPort, eth, deviceObject); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 319 | } |
| 320 | } |
Jonathan Hart | 0444d93 | 2014-01-22 15:06:17 -0800 | [diff] [blame] | 321 | |
Jonathan Hart | f5bd258 | 2014-04-09 17:43:41 -0700 | [diff] [blame] | 322 | private void continueHandlePacketIn(Switch sw, Port inPort, Ethernet eth, Device deviceObject) { |
TeruU | 7feef8a | 2014-04-03 00:15:49 -0700 | [diff] [blame] | 323 | |
TeruU | 9e53066 | 2014-05-18 11:49:37 -0700 | [diff] [blame] | 324 | log.trace("Start continuehandlePacketIn"); |
TeruU | 7feef8a | 2014-04-03 00:15:49 -0700 | [diff] [blame] | 325 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 326 | //Iterator<IPortObject> ports = deviceObject.getAttachedPorts().iterator(); |
| 327 | Iterator<net.onrc.onos.core.topology.Port> ports = deviceObject.getAttachmentPoints().iterator(); |
| 328 | if (!ports.hasNext()) { |
| 329 | log.debug("No attachment point found for device {} - broadcasting packet", |
| 330 | deviceObject.getMacAddress()); |
Jonathan Hart | f5bd258 | 2014-04-09 17:43:41 -0700 | [diff] [blame] | 331 | handleBroadcast(sw, inPort, eth); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 332 | return; |
| 333 | } |
TeruU | 7feef8a | 2014-04-03 00:15:49 -0700 | [diff] [blame] | 334 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 335 | //This code assumes the device has only one port. It should be problem. |
Yuta HIGUCHI | 8f3dfa3 | 2014-06-25 00:14:25 -0700 | [diff] [blame^] | 336 | Port destinationPort = ports.next(); |
| 337 | short destinationPortNum = destinationPort.getNumber().value(); |
| 338 | Switch destinationSw = destinationPort.getSwitch(); |
| 339 | long destinationDpid = destinationSw.getDpid().value(); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 340 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 341 | SwitchPort srcSwitchPort = new SwitchPort( |
Yuta HIGUCHI | 8f3dfa3 | 2014-06-25 00:14:25 -0700 | [diff] [blame^] | 342 | sw.getDpid(), |
| 343 | inPort.getNumber()); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 344 | SwitchPort dstSwitchPort = new SwitchPort( |
Yuta HIGUCHI | 8f3dfa3 | 2014-06-25 00:14:25 -0700 | [diff] [blame^] | 345 | destinationSw.getDpid(), |
| 346 | destinationPort.getNumber()); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 347 | |
| 348 | MACAddress srcMacAddress = MACAddress.valueOf(eth.getSourceMACAddress()); |
| 349 | MACAddress dstMacAddress = MACAddress.valueOf(eth.getDestinationMACAddress()); |
TeruU | 9e53066 | 2014-05-18 11:49:37 -0700 | [diff] [blame] | 350 | Path pathspec = new Path(srcMacAddress, dstMacAddress); |
| 351 | IntentOperationList operations = new IntentOperationList(); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 352 | |
| 353 | synchronized (lock) { |
| 354 | //TODO check concurrency |
TeruU | 9e53066 | 2014-05-18 11:49:37 -0700 | [diff] [blame] | 355 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 356 | PushedFlow existingFlow = pendingFlows.get(pathspec); |
| 357 | |
| 358 | //A path is installed side by side to reduce a path timeout and a wrong state. |
| 359 | if (existingFlow != null) { |
| 360 | // We've already start to install a flow for this pair of MAC addresses |
| 361 | if (log.isDebugEnabled()) { |
| 362 | log.debug("Found existing the same pathspec {}, intent ID is {}", |
| 363 | pathspec, |
| 364 | existingFlow.intentId); |
| 365 | } |
| 366 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 367 | // Find the correct port here. We just assume the PI is from |
| 368 | // the first hop switch, but this is definitely not always |
| 369 | // the case. We'll have to retrieve the flow from HZ every time |
| 370 | // because it could change (be rerouted) sometimes. |
| 371 | if (existingFlow.installed) { |
| 372 | // Flow has been sent to the switches so it is safe to |
| 373 | // send a packet out now |
| 374 | |
TeruU | 9e53066 | 2014-05-18 11:49:37 -0700 | [diff] [blame] | 375 | // TODO Here highLevelIntentMap and pathIntentMap would be problem, |
| 376 | // because it doesn't have global information as of May 2014. |
| 377 | // However usually these lines here is used when we got packet-in and this class think |
| 378 | // the path for the packet is installed already, so it is pretty rare. |
| 379 | // I will leave it for now, and will work in the next step. |
| 380 | Intent highLevelIntent = highLevelIntentMap.getIntent(existingFlow.intentId); |
| 381 | if (highLevelIntent == null) { |
| 382 | log.debug("Intent ID {} is null in HighLevelIntentMap. return.", existingFlow.intentId); |
| 383 | return; |
| 384 | } |
| 385 | |
| 386 | if (highLevelIntent.getState() != IntentState.INST_ACK) { |
| 387 | log.debug("Intent ID {}'s state is not INST_ACK. return.", existingFlow.intentId); |
| 388 | return; |
| 389 | } |
| 390 | |
| 391 | ShortestPathIntent spfIntent = null; |
| 392 | if (highLevelIntent instanceof ShortestPathIntent) { |
| 393 | spfIntent = (ShortestPathIntent) highLevelIntent; |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 394 | } else { |
TeruU | f911165 | 2014-05-14 23:10:35 -0700 | [diff] [blame] | 395 | log.debug("Intent ID {} is not PathIntent or null. return.", existingFlow.intentId); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 396 | return; |
| 397 | } |
| 398 | |
TeruU | 9e53066 | 2014-05-18 11:49:37 -0700 | [diff] [blame] | 399 | PathIntent pathIntent = (PathIntent) pathIntentMap.getIntent(spfIntent.getPathIntentId()); |
| 400 | if (pathIntent == null) { |
| 401 | log.debug("PathIntent ID {} is null in PathIntentMap. return.", existingFlow.intentId); |
| 402 | return; |
| 403 | } |
| 404 | |
| 405 | if (pathIntent.getState() != IntentState.INST_ACK) { |
| 406 | log.debug("Intent ID {}'s state is not INST_ACK. return.", existingFlow.intentId); |
| 407 | return; |
| 408 | } |
| 409 | |
| 410 | boolean isflowEntryForThisSwitch = false; |
Yuta HIGUCHI | 1fc395e | 2014-05-13 14:06:28 -0700 | [diff] [blame] | 411 | net.onrc.onos.core.intent.Path path = pathIntent.getPath(); |
TeruU | 9e53066 | 2014-05-18 11:49:37 -0700 | [diff] [blame] | 412 | long outPort = -1; |
| 413 | |
Yuta HIGUCHI | 8f3dfa3 | 2014-06-25 00:14:25 -0700 | [diff] [blame^] | 414 | if (spfIntent.getDstSwitchDpid() == sw.getDpid().value()) { |
TeruU | 9e53066 | 2014-05-18 11:49:37 -0700 | [diff] [blame] | 415 | log.trace("The packet-in sw dpid {} is on the path.", sw.getDpid()); |
| 416 | isflowEntryForThisSwitch = true; |
| 417 | outPort = spfIntent.getDstPortNumber(); |
| 418 | } |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 419 | |
Ray Milkey | 7f1567c | 2014-04-08 13:53:32 -0700 | [diff] [blame] | 420 | for (Iterator<LinkEvent> i = path.iterator(); i.hasNext();) { |
Ray Milkey | 149693c | 2014-05-20 14:58:53 -0700 | [diff] [blame] | 421 | LinkEvent le = i.next(); |
TeruU | 9e53066 | 2014-05-18 11:49:37 -0700 | [diff] [blame] | 422 | |
Yuta HIGUCHI | 8f3dfa3 | 2014-06-25 00:14:25 -0700 | [diff] [blame^] | 423 | if (new Dpid(le.getSrc().dpid).equals(sw.getDpid())) { |
TeruU | 9e53066 | 2014-05-18 11:49:37 -0700 | [diff] [blame] | 424 | log.trace("The packet-in sw dpid {} is on the path.", sw.getDpid()); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 425 | isflowEntryForThisSwitch = true; |
Yuta HIGUCHI | 8f3dfa3 | 2014-06-25 00:14:25 -0700 | [diff] [blame^] | 426 | outPort = le.getSrc().getNumber().value(); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 427 | break; |
| 428 | } |
| 429 | } |
| 430 | |
Ray Milkey | 6c4f2fe | 2014-04-11 09:47:23 -0700 | [diff] [blame] | 431 | if (!isflowEntryForThisSwitch) { |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 432 | // If we don't find a flow entry for that switch, then we're |
| 433 | // in the middle of a rerouting (or something's gone wrong). |
| 434 | // This packet will be dropped as a victim of the rerouting. |
| 435 | log.debug("Dropping packet on flow {} between {}-{}", |
| 436 | existingFlow.intentId, |
| 437 | srcMacAddress, dstMacAddress); |
| 438 | } else { |
TeruU | 9e53066 | 2014-05-18 11:49:37 -0700 | [diff] [blame] | 439 | if (outPort < 0) { |
| 440 | outPort = existingFlow.firstOutPort; |
| 441 | } |
Jonathan Hart | f5bd258 | 2014-04-09 17:43:41 -0700 | [diff] [blame] | 442 | |
TeruU | 9e53066 | 2014-05-18 11:49:37 -0700 | [diff] [blame] | 443 | log.debug("Sending packet out from sw {}, outport{}", sw.getDpid(), outPort); |
Jonathan Hart | e3702f2 | 2014-04-29 02:56:56 -0700 | [diff] [blame] | 444 | packetService.sendPacket(eth, new SwitchPort( |
Yuta HIGUCHI | 8f3dfa3 | 2014-06-25 00:14:25 -0700 | [diff] [blame^] | 445 | sw.getDpid(), new PortNumber((short) outPort))); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 446 | } |
| 447 | } else { |
| 448 | // Flow path has not yet been installed to switches so save the |
| 449 | // packet out for later |
TeruU | 9e53066 | 2014-05-18 11:49:37 -0700 | [diff] [blame] | 450 | log.trace("Put a packet into the waiting list. flowId {}", existingFlow.intentId); |
Yuta HIGUCHI | 8f3dfa3 | 2014-06-25 00:14:25 -0700 | [diff] [blame^] | 451 | waitingPackets.put(existingFlow.intentId, new PacketToPush(eth, sw.getDpid().value())); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 452 | } |
| 453 | return; |
| 454 | } |
| 455 | |
TeruU | 9e53066 | 2014-05-18 11:49:37 -0700 | [diff] [blame] | 456 | String intentId = Long.toString(controllerRegistryService.getNextUniqueId()); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 457 | ShortestPathIntent intent = new ShortestPathIntent(intentId, |
Yuta HIGUCHI | 8f3dfa3 | 2014-06-25 00:14:25 -0700 | [diff] [blame^] | 458 | sw.getDpid().value(), inPort.getNumber().value(), srcMacAddress.toLong(), |
| 459 | destinationDpid, destinationPortNum, dstMacAddress.toLong()); |
Ray Milkey | ff73514 | 2014-05-22 19:06:02 -0700 | [diff] [blame] | 460 | |
TeruU | 30c0c93 | 2014-05-15 16:47:41 -0700 | [diff] [blame] | 461 | intent.setIdleTimeout(idleTimeout + SRC_SWITCH_TIMEOUT_ADJUST_SECOND); |
| 462 | intent.setFirstSwitchIdleTimeout(idleTimeout); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 463 | IntentOperation.Operator operator = IntentOperation.Operator.ADD; |
| 464 | operations.add(operator, intent); |
TeruU | 9e53066 | 2014-05-18 11:49:37 -0700 | [diff] [blame] | 465 | log.debug("Adding new flow between {} at {} and {} at {}", |
| 466 | new Object[]{srcMacAddress, srcSwitchPort, dstMacAddress, dstSwitchPort}); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 467 | |
TeruU | 9e53066 | 2014-05-18 11:49:37 -0700 | [diff] [blame] | 468 | // Add to waiting lists |
Yuta HIGUCHI | 8f3dfa3 | 2014-06-25 00:14:25 -0700 | [diff] [blame^] | 469 | waitingPackets.put(intentId, new PacketToPush(eth, sw.getDpid().value())); |
TeruU | 9e53066 | 2014-05-18 11:49:37 -0700 | [diff] [blame] | 470 | log.trace("Put a Packet in the wating list. intent ID {}, related pathspec {}", intentId, pathspec); |
| 471 | pendingFlows.put(pathspec, new PushedFlow(intentId)); |
| 472 | log.trace("Put a Path {} in the pending flow, intent ID {}", pathspec, intentId); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 473 | } |
TeruU | 9e53066 | 2014-05-18 11:49:37 -0700 | [diff] [blame] | 474 | pathRuntime.executeIntentOperations(operations); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 475 | } |
| 476 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 477 | @Override |
| 478 | public void flowsInstalled(Collection<FlowPath> installedFlowPaths) { |
| 479 | } |
| 480 | |
| 481 | @Override |
| 482 | public void flowRemoved(FlowPath removedFlowPath) { |
| 483 | } |
| 484 | |
TeruU | 435df32 | 2014-06-16 23:45:13 -0700 | [diff] [blame] | 485 | public void flowRemoved(ShortestPathIntent spfIntent) { |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 486 | if (log.isTraceEnabled()) { |
TeruU | 435df32 | 2014-06-16 23:45:13 -0700 | [diff] [blame] | 487 | log.trace("ShortestPathIntent {} was removed", spfIntent.getId()); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 488 | } |
| 489 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 490 | MACAddress srcMacAddress = MACAddress.valueOf(spfIntent.getSrcMac()); |
| 491 | MACAddress dstMacAddress = MACAddress.valueOf(spfIntent.getDstMac()); |
| 492 | Path removedPath = new Path(srcMacAddress, dstMacAddress); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 493 | synchronized (lock) { |
| 494 | // There *shouldn't* be any packets queued if the flow has |
| 495 | // just been removed. |
| 496 | List<PacketToPush> packets = waitingPackets.removeAll(spfIntent.getId()); |
| 497 | if (!packets.isEmpty()) { |
| 498 | log.warn("Removed flow {} has packets queued.", spfIntent.getId()); |
| 499 | } |
TeruU | 9e53066 | 2014-05-18 11:49:37 -0700 | [diff] [blame] | 500 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 501 | pendingFlows.remove(removedPath); |
| 502 | log.debug("Removed from the pendingFlow: Path {}, Flow ID {}", removedPath, spfIntent.getId()); |
| 503 | } |
| 504 | } |
| 505 | |
| 506 | private void flowInstalled(PathIntent installedPath) { |
| 507 | if (log.isTraceEnabled()) { |
Jonathan Hart | c00f5c2 | 2014-06-10 15:14:40 -0700 | [diff] [blame] | 508 | log.trace("Installed intent ID {}, path {}", |
| 509 | installedPath.getParentIntent().getId(), installedPath.getPath()); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 510 | } |
| 511 | |
| 512 | ShortestPathIntent spfIntent = (ShortestPathIntent) installedPath.getParentIntent(); |
| 513 | MACAddress srcMacAddress = MACAddress.valueOf(spfIntent.getSrcMac()); |
| 514 | MACAddress dstMacAddress = MACAddress.valueOf(spfIntent.getDstMac()); |
| 515 | Path path = new Path(srcMacAddress, dstMacAddress); |
| 516 | log.debug("Path spec {}", path); |
| 517 | |
| 518 | // TODO waiting packets should time out. We could request a path that |
| 519 | // can't be installed right now because of a network partition. The path |
| 520 | // may eventually be installed, but we may have received thousands of |
| 521 | // packets in the meantime and probably don't want to send very old packets. |
| 522 | |
| 523 | List<PacketToPush> packets = null; |
Yuta HIGUCHI | 1fc395e | 2014-05-13 14:06:28 -0700 | [diff] [blame] | 524 | net.onrc.onos.core.intent.Path graphPath = installedPath.getPath(); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 525 | |
TeruU | 220c45e | 2014-04-10 18:56:26 -0700 | [diff] [blame] | 526 | short outPort; |
| 527 | if (graphPath.isEmpty()) { |
| 528 | outPort = (short) spfIntent.getDstPortNumber(); |
| 529 | log.debug("Path is empty. Maybe devices on the same switch. outPort {}", outPort); |
| 530 | } else { |
Yuta HIGUCHI | 8f3dfa3 | 2014-06-25 00:14:25 -0700 | [diff] [blame^] | 531 | outPort = graphPath.get(0).getSrc().getNumber().value(); |
TeruU | 220c45e | 2014-04-10 18:56:26 -0700 | [diff] [blame] | 532 | log.debug("path{}, outPort {}", graphPath, outPort); |
| 533 | } |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 534 | |
| 535 | PushedFlow existingFlow = null; |
| 536 | |
| 537 | synchronized (lock) { |
| 538 | existingFlow = pendingFlows.get(path); |
| 539 | |
| 540 | if (existingFlow != null) { |
| 541 | existingFlow.installed = true; |
| 542 | existingFlow.firstOutPort = outPort; |
| 543 | } else { |
| 544 | log.debug("ExistingFlow {} is null", path); |
| 545 | return; |
| 546 | } |
| 547 | |
| 548 | //Check both existing flow are installed status. |
| 549 | if (existingFlow.installed) { |
| 550 | packets = waitingPackets.removeAll(existingFlow.intentId); |
| 551 | if (log.isDebugEnabled()) { |
| 552 | log.debug("removed my packets {} to push from waitingPackets. outPort {} size {}", |
| 553 | existingFlow.intentId, existingFlow.firstOutPort, packets.size()); |
| 554 | } |
| 555 | } else { |
| 556 | log.debug("Forward or reverse flows hasn't been pushed yet. return"); |
| 557 | return; |
| 558 | } |
| 559 | } |
| 560 | |
| 561 | for (PacketToPush packet : packets) { |
TeruU | bd5b90e | 2014-06-16 14:29:33 -0700 | [diff] [blame] | 562 | log.debug("Start packetToPush to sw {}, outPort {}, path {}", |
| 563 | packet.dpid, existingFlow.firstOutPort, path); |
Jonathan Hart | e3702f2 | 2014-04-29 02:56:56 -0700 | [diff] [blame] | 564 | packetService.sendPacket(packet.eth, new SwitchPort( |
| 565 | packet.dpid, existingFlow.firstOutPort)); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 566 | } |
| 567 | } |
| 568 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 569 | @Override |
TeruU | f911165 | 2014-05-14 23:10:35 -0700 | [diff] [blame] | 570 | public void intentsChange(LinkedList<ChangedEvent> events) { |
| 571 | for (ChangedEvent event : events) { |
| 572 | log.debug("path intent ID {}, eventType {}", event.intent.getId() , event.eventType); |
TeruU | bd5b90e | 2014-06-16 14:29:33 -0700 | [diff] [blame] | 573 | |
| 574 | PathIntent pathIntent = null; |
| 575 | if (event.intent instanceof PathIntent) { |
| 576 | pathIntent = (PathIntent) event.intent; |
| 577 | log.trace("pathIntent {}", pathIntent); |
| 578 | } |
| 579 | |
Ray Milkey | b29e626 | 2014-04-09 16:02:14 -0700 | [diff] [blame] | 580 | if (pathIntent == null) { |
TeruU | 435df32 | 2014-06-16 23:45:13 -0700 | [diff] [blame] | 581 | log.trace("pathIntent is null. Skip."); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 582 | continue; |
Ray Milkey | b29e626 | 2014-04-09 16:02:14 -0700 | [diff] [blame] | 583 | } |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 584 | |
Ray Milkey | b29e626 | 2014-04-09 16:02:14 -0700 | [diff] [blame] | 585 | if (!(pathIntent.getParentIntent() instanceof ShortestPathIntent)) { |
TeruU | 435df32 | 2014-06-16 23:45:13 -0700 | [diff] [blame] | 586 | log.trace("parentIntent is not ShortestPathIntent. Skip."); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 587 | continue; |
Ray Milkey | b29e626 | 2014-04-09 16:02:14 -0700 | [diff] [blame] | 588 | } |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 589 | |
TeruU | f911165 | 2014-05-14 23:10:35 -0700 | [diff] [blame] | 590 | switch(event.eventType) { |
| 591 | case ADDED: |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 592 | break; |
TeruU | f911165 | 2014-05-14 23:10:35 -0700 | [diff] [blame] | 593 | case REMOVED: |
TeruU | 435df32 | 2014-06-16 23:45:13 -0700 | [diff] [blame] | 594 | flowRemoved((ShortestPathIntent) pathIntent.getParentIntent()); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 595 | break; |
TeruU | f911165 | 2014-05-14 23:10:35 -0700 | [diff] [blame] | 596 | case STATE_CHANGED: |
| 597 | IntentState state = pathIntent.getState(); |
TeruU | 5d2c939 | 2014-06-09 20:02:02 -0700 | [diff] [blame] | 598 | log.debug("This is STATE_CHANGED. intent id {} is now state {}", |
| 599 | pathIntent.getId() , state); |
TeruU | f911165 | 2014-05-14 23:10:35 -0700 | [diff] [blame] | 600 | switch (state) { |
| 601 | case INST_REQ: |
| 602 | break; |
| 603 | case INST_ACK: |
| 604 | flowInstalled(pathIntent); |
| 605 | break; |
| 606 | case INST_NACK: |
TeruU | 435df32 | 2014-06-16 23:45:13 -0700 | [diff] [blame] | 607 | flowRemoved((ShortestPathIntent) pathIntent.getParentIntent()); |
TeruU | f911165 | 2014-05-14 23:10:35 -0700 | [diff] [blame] | 608 | break; |
| 609 | case DEL_REQ: |
| 610 | break; |
| 611 | case DEL_ACK: |
TeruU | 435df32 | 2014-06-16 23:45:13 -0700 | [diff] [blame] | 612 | flowRemoved((ShortestPathIntent) pathIntent.getParentIntent()); |
TeruU | f911165 | 2014-05-14 23:10:35 -0700 | [diff] [blame] | 613 | break; |
| 614 | case DEL_PENDING: |
| 615 | break; |
TeruU | bd5b90e | 2014-06-16 14:29:33 -0700 | [diff] [blame] | 616 | case REROUTE_REQ: |
| 617 | break; |
TeruU | f911165 | 2014-05-14 23:10:35 -0700 | [diff] [blame] | 618 | default: |
| 619 | break; |
| 620 | } |
Ray Milkey | 149693c | 2014-05-20 14:58:53 -0700 | [diff] [blame] | 621 | break; |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 622 | default: |
| 623 | break; |
| 624 | } |
| 625 | } |
| 626 | } |
Jonathan Hart | 1caaa93 | 2013-11-04 15:28:28 -0800 | [diff] [blame] | 627 | } |