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; |
Jonathan Hart | 41d1e91 | 2013-11-24 16:50:25 -0800 | [diff] [blame] | 7 | import java.util.List; |
Jonathan Hart | e93aed4 | 2013-12-05 18:39:50 -0800 | [diff] [blame] | 8 | import java.util.Map; |
TeruU | 7feef8a | 2014-04-03 00:15:49 -0700 | [diff] [blame] | 9 | import java.util.Map.Entry; |
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 | |
| 14 | import net.floodlightcontroller.core.FloodlightContext; |
| 15 | import net.floodlightcontroller.core.IFloodlightProviderService; |
| 16 | import net.floodlightcontroller.core.IOFMessageListener; |
| 17 | import net.floodlightcontroller.core.IOFSwitch; |
Jonathan Hart | e93aed4 | 2013-12-05 18:39:50 -0800 | [diff] [blame] | 18 | import net.floodlightcontroller.core.module.FloodlightModuleContext; |
| 19 | import net.floodlightcontroller.core.module.IFloodlightModule; |
| 20 | import net.floodlightcontroller.core.module.IFloodlightService; |
Jonathan Hart | 1caaa93 | 2013-11-04 15:28:28 -0800 | [diff] [blame] | 21 | import net.floodlightcontroller.util.MACAddress; |
Jonathan Hart | 0961fe8 | 2014-04-03 09:56:25 -0700 | [diff] [blame] | 22 | import net.onrc.onos.apps.proxyarp.BroadcastPacketOutNotification; |
| 23 | import net.onrc.onos.apps.proxyarp.IProxyArpService; |
Jonathan Hart | 6df9017 | 2014-04-03 10:13:11 -0700 | [diff] [blame] | 24 | import net.onrc.onos.core.datagrid.IDatagridService; |
| 25 | import net.onrc.onos.core.datagrid.IEventChannel; |
| 26 | import net.onrc.onos.core.datagrid.IEventChannelListener; |
Jonathan Hart | 23701d1 | 2014-04-03 10:45:48 -0700 | [diff] [blame] | 27 | import net.onrc.onos.core.devicemanager.IOnosDeviceService; |
| 28 | import net.onrc.onos.core.flowprogrammer.IFlowPusherService; |
Jonathan Hart | aa38097 | 2014-04-03 10:24:46 -0700 | [diff] [blame] | 29 | import net.onrc.onos.core.intent.Intent; |
| 30 | import net.onrc.onos.core.intent.IntentMap; |
| 31 | import net.onrc.onos.core.intent.IntentOperation; |
| 32 | import net.onrc.onos.core.intent.IntentOperationList; |
| 33 | import net.onrc.onos.core.intent.PathIntent; |
| 34 | import net.onrc.onos.core.intent.ShortestPathIntent; |
| 35 | import net.onrc.onos.core.intent.Intent.IntentState; |
| 36 | import net.onrc.onos.core.intent.runtime.IPathCalcRuntimeService; |
| 37 | import net.onrc.onos.core.intent.runtime.IntentStateList; |
Jonathan Hart | 472062d | 2014-04-03 10:56:48 -0700 | [diff] [blame^] | 38 | import net.onrc.onos.core.topology.Device; |
| 39 | import net.onrc.onos.core.topology.INetworkGraphService; |
| 40 | import net.onrc.onos.core.topology.LinkEvent; |
| 41 | import net.onrc.onos.core.topology.NetworkGraph; |
| 42 | import net.onrc.onos.core.topology.Switch; |
Jonathan Hart | 23701d1 | 2014-04-03 10:45:48 -0700 | [diff] [blame] | 43 | import net.onrc.onos.core.util.Dpid; |
| 44 | import net.onrc.onos.core.util.FlowPath; |
| 45 | import net.onrc.onos.core.util.Port; |
| 46 | import net.onrc.onos.core.util.SwitchPort; |
Jonathan Hart | 96892d1 | 2014-03-26 20:21:29 -0700 | [diff] [blame] | 47 | import net.onrc.onos.packet.Ethernet; |
Pavlin Radoslavov | 52163ed | 2014-03-19 11:39:34 -0700 | [diff] [blame] | 48 | import net.onrc.onos.registry.controller.IControllerRegistryService; |
Jonathan Hart | 1caaa93 | 2013-11-04 15:28:28 -0800 | [diff] [blame] | 49 | |
| 50 | import org.openflow.protocol.OFMessage; |
| 51 | import org.openflow.protocol.OFPacketIn; |
Jonathan Hart | 41d1e91 | 2013-11-24 16:50:25 -0800 | [diff] [blame] | 52 | import org.openflow.protocol.OFPacketOut; |
| 53 | import org.openflow.protocol.OFPort; |
Jonathan Hart | 1caaa93 | 2013-11-04 15:28:28 -0800 | [diff] [blame] | 54 | import org.openflow.protocol.OFType; |
Jonathan Hart | 41d1e91 | 2013-11-24 16:50:25 -0800 | [diff] [blame] | 55 | import org.openflow.protocol.action.OFAction; |
| 56 | import org.openflow.protocol.action.OFActionOutput; |
Jonathan Hart | 1caaa93 | 2013-11-04 15:28:28 -0800 | [diff] [blame] | 57 | import org.openflow.util.HexString; |
| 58 | import org.slf4j.Logger; |
| 59 | import org.slf4j.LoggerFactory; |
| 60 | |
Jonathan Hart | d857ad6 | 2013-12-14 18:08:17 -0800 | [diff] [blame] | 61 | import com.google.common.collect.LinkedListMultimap; |
| 62 | import com.google.common.collect.ListMultimap; |
Jonathan Hart | 5e44878 | 2013-12-10 12:36:35 -0800 | [diff] [blame] | 63 | |
| 64 | public class Forwarding implements IOFMessageListener, IFloodlightModule, |
TeruU | 7feef8a | 2014-04-03 00:15:49 -0700 | [diff] [blame] | 65 | IForwardingService, IEventChannelListener<Long, IntentStateList> { |
Jonathan Hart | 1caaa93 | 2013-11-04 15:28:28 -0800 | [diff] [blame] | 66 | private final static Logger log = LoggerFactory.getLogger(Forwarding.class); |
TeruU | 417fe02 | 2014-02-04 12:59:30 -0800 | [diff] [blame] | 67 | |
TeruU | 417fe02 | 2014-02-04 12:59:30 -0800 | [diff] [blame] | 68 | private final int SLEEP_TIME_FOR_DB_DEVICE_INSTALLED = 100; // milliseconds |
| 69 | private final static int NUMBER_OF_THREAD_FOR_EXECUTOR = 1; |
| 70 | |
| 71 | private final static ScheduledExecutorService executor = Executors.newScheduledThreadPool(NUMBER_OF_THREAD_FOR_EXECUTOR); |
Jonathan Hart | 0444d93 | 2014-01-22 15:06:17 -0800 | [diff] [blame] | 72 | |
TeruU | 7feef8a | 2014-04-03 00:15:49 -0700 | [diff] [blame] | 73 | private final String callerId = "Forwarding"; |
Jonathan Hart | 7e6df36 | 2013-12-10 23:33:59 -0800 | [diff] [blame] | 74 | |
Jonathan Hart | 1caaa93 | 2013-11-04 15:28:28 -0800 | [diff] [blame] | 75 | private IFloodlightProviderService floodlightProvider; |
Jonathan Hart | 7e6df36 | 2013-12-10 23:33:59 -0800 | [diff] [blame] | 76 | private IFlowPusherService flowPusher; |
Jonathan Hart | 1767299 | 2013-12-12 16:15:16 -0800 | [diff] [blame] | 77 | private IDatagridService datagrid; |
TeruU | 7feef8a | 2014-04-03 00:15:49 -0700 | [diff] [blame] | 78 | |
| 79 | private IEventChannel<Long, BroadcastPacketOutNotification> eventChannel; |
| 80 | private static final String SINGLE_PACKET_OUT_CHANNEL_NAME = "onos.forwarding.packet_out"; |
Pavlin Radoslavov | 902fe52 | 2014-03-31 10:11:31 -0700 | [diff] [blame] | 81 | |
Pavlin Radoslavov | 52163ed | 2014-03-19 11:39:34 -0700 | [diff] [blame] | 82 | private IControllerRegistryService controllerRegistryService; |
Jonathan Hart | 1caaa93 | 2013-11-04 15:28:28 -0800 | [diff] [blame] | 83 | |
TeruU | 7feef8a | 2014-04-03 00:15:49 -0700 | [diff] [blame] | 84 | private INetworkGraphService networkGraphService; |
| 85 | private NetworkGraph networkGraph; |
| 86 | private IPathCalcRuntimeService pathRuntime; |
| 87 | private IntentMap intentMap; |
| 88 | |
Jonathan Hart | e789d6e | 2013-12-17 17:50:11 -0800 | [diff] [blame] | 89 | // TODO it seems there is a Guava collection that will time out entries. |
| 90 | // We should see if this will work here. |
| 91 | private Map<Path, PushedFlow> pendingFlows; |
TeruU | 7feef8a | 2014-04-03 00:15:49 -0700 | [diff] [blame] | 92 | private ListMultimap<String, PacketToPush> waitingPackets; |
Jonathan Hart | 5e44878 | 2013-12-10 12:36:35 -0800 | [diff] [blame] | 93 | |
Jonathan Hart | 7e6df36 | 2013-12-10 23:33:59 -0800 | [diff] [blame] | 94 | private final Object lock = new Object(); |
| 95 | |
Jonathan Hart | e789d6e | 2013-12-17 17:50:11 -0800 | [diff] [blame] | 96 | private class PacketToPush { |
Jonathan Hart | 5e44878 | 2013-12-10 12:36:35 -0800 | [diff] [blame] | 97 | public final OFPacketOut packet; |
| 98 | public final long dpid; |
Jonathan Hart | 1caaa93 | 2013-11-04 15:28:28 -0800 | [diff] [blame] | 99 | |
Jonathan Hart | 5e44878 | 2013-12-10 12:36:35 -0800 | [diff] [blame] | 100 | public PacketToPush(OFPacketOut packet, long dpid) { |
| 101 | this.packet = packet; |
| 102 | this.dpid = dpid; |
| 103 | } |
Jonathan Hart | 1caaa93 | 2013-11-04 15:28:28 -0800 | [diff] [blame] | 104 | } |
| 105 | |
Jonathan Hart | e789d6e | 2013-12-17 17:50:11 -0800 | [diff] [blame] | 106 | private class PushedFlow { |
TeruU | 7feef8a | 2014-04-03 00:15:49 -0700 | [diff] [blame] | 107 | public final String intentId; |
Jonathan Hart | 0444d93 | 2014-01-22 15:06:17 -0800 | [diff] [blame] | 108 | public boolean installed = false; |
TeruU | 417fe02 | 2014-02-04 12:59:30 -0800 | [diff] [blame] | 109 | public short firstOutPort; |
Jonathan Hart | e789d6e | 2013-12-17 17:50:11 -0800 | [diff] [blame] | 110 | |
TeruU | 7feef8a | 2014-04-03 00:15:49 -0700 | [diff] [blame] | 111 | public PushedFlow(String flowId) { |
| 112 | this.intentId = flowId; |
Jonathan Hart | e789d6e | 2013-12-17 17:50:11 -0800 | [diff] [blame] | 113 | } |
| 114 | } |
| 115 | |
| 116 | private final class Path { |
Jonathan Hart | e789d6e | 2013-12-17 17:50:11 -0800 | [diff] [blame] | 117 | public final MACAddress srcMac; |
| 118 | public final MACAddress dstMac; |
Jonathan Hart | 5e44878 | 2013-12-10 12:36:35 -0800 | [diff] [blame] | 119 | |
Jonathan Hart | 0444d93 | 2014-01-22 15:06:17 -0800 | [diff] [blame] | 120 | public Path(MACAddress srcMac, MACAddress dstMac) { |
Jonathan Hart | e789d6e | 2013-12-17 17:50:11 -0800 | [diff] [blame] | 121 | this.srcMac = srcMac; |
| 122 | this.dstMac = dstMac; |
Jonathan Hart | 5e44878 | 2013-12-10 12:36:35 -0800 | [diff] [blame] | 123 | } |
| 124 | |
| 125 | @Override |
| 126 | public boolean equals(Object other) { |
| 127 | if (!(other instanceof Path)) { |
| 128 | return false; |
| 129 | } |
| 130 | |
| 131 | Path otherPath = (Path) other; |
Jonathan Hart | 0444d93 | 2014-01-22 15:06:17 -0800 | [diff] [blame] | 132 | return srcMac.equals(otherPath.srcMac) && |
Jonathan Hart | e789d6e | 2013-12-17 17:50:11 -0800 | [diff] [blame] | 133 | dstMac.equals(otherPath.dstMac); |
Jonathan Hart | 5e44878 | 2013-12-10 12:36:35 -0800 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | @Override |
| 137 | public int hashCode() { |
| 138 | int hash = 17; |
Jonathan Hart | e789d6e | 2013-12-17 17:50:11 -0800 | [diff] [blame] | 139 | hash = 31 * hash + srcMac.hashCode(); |
| 140 | hash = 31 * hash + dstMac.hashCode(); |
Jonathan Hart | 5e44878 | 2013-12-10 12:36:35 -0800 | [diff] [blame] | 141 | return hash; |
| 142 | } |
Jonathan Hart | e789d6e | 2013-12-17 17:50:11 -0800 | [diff] [blame] | 143 | |
| 144 | @Override |
| 145 | public String toString() { |
Jonathan Hart | 0444d93 | 2014-01-22 15:06:17 -0800 | [diff] [blame] | 146 | return "(" + srcMac + ") => (" + dstMac + ")"; |
Jonathan Hart | e789d6e | 2013-12-17 17:50:11 -0800 | [diff] [blame] | 147 | } |
Jonathan Hart | 1caaa93 | 2013-11-04 15:28:28 -0800 | [diff] [blame] | 148 | } |
| 149 | |
Jonathan Hart | e93aed4 | 2013-12-05 18:39:50 -0800 | [diff] [blame] | 150 | @Override |
| 151 | public Collection<Class<? extends IFloodlightService>> getModuleServices() { |
Jonathan Hart | d33a6cf | 2013-12-10 14:29:08 -0800 | [diff] [blame] | 152 | List<Class<? extends IFloodlightService>> services = |
| 153 | new ArrayList<Class<? extends IFloodlightService>>(1); |
| 154 | services.add(IForwardingService.class); |
| 155 | return services; |
Jonathan Hart | e93aed4 | 2013-12-05 18:39:50 -0800 | [diff] [blame] | 156 | } |
| 157 | |
| 158 | @Override |
| 159 | public Map<Class<? extends IFloodlightService>, IFloodlightService> getServiceImpls() { |
Jonathan Hart | d33a6cf | 2013-12-10 14:29:08 -0800 | [diff] [blame] | 160 | Map<Class<? extends IFloodlightService>, IFloodlightService> impls = |
| 161 | new HashMap<Class<? extends IFloodlightService>, IFloodlightService>(1); |
| 162 | impls.put(IForwardingService.class, this); |
| 163 | return impls; |
Jonathan Hart | e93aed4 | 2013-12-05 18:39:50 -0800 | [diff] [blame] | 164 | } |
| 165 | |
| 166 | @Override |
| 167 | public Collection<Class<? extends IFloodlightService>> getModuleDependencies() { |
| 168 | List<Class<? extends IFloodlightService>> dependencies = |
| 169 | new ArrayList<Class<? extends IFloodlightService>>(); |
| 170 | dependencies.add(IFloodlightProviderService.class); |
Jonathan Hart | 7e6df36 | 2013-12-10 23:33:59 -0800 | [diff] [blame] | 171 | dependencies.add(IFlowPusherService.class); |
TeruU | 7feef8a | 2014-04-03 00:15:49 -0700 | [diff] [blame] | 172 | dependencies.add(IControllerRegistryService.class); |
Jonathan Hart | d857ad6 | 2013-12-14 18:08:17 -0800 | [diff] [blame] | 173 | dependencies.add(IOnosDeviceService.class); |
TeruU | 7feef8a | 2014-04-03 00:15:49 -0700 | [diff] [blame] | 174 | dependencies.add(IDatagridService.class); |
| 175 | dependencies.add(INetworkGraphService.class); |
| 176 | dependencies.add(IPathCalcRuntimeService.class); |
Jonathan Hart | 7804bea | 2014-01-07 10:50:52 -0800 | [diff] [blame] | 177 | // We don't use the IProxyArpService directly, but reactive forwarding |
| 178 | // requires it to be loaded and answering ARP requests |
| 179 | dependencies.add(IProxyArpService.class); |
Jonathan Hart | e93aed4 | 2013-12-05 18:39:50 -0800 | [diff] [blame] | 180 | return dependencies; |
| 181 | } |
| 182 | |
| 183 | @Override |
| 184 | public void init(FloodlightModuleContext context) { |
Jonathan Hart | 7e6df36 | 2013-12-10 23:33:59 -0800 | [diff] [blame] | 185 | floodlightProvider = |
Jonathan Hart | e93aed4 | 2013-12-05 18:39:50 -0800 | [diff] [blame] | 186 | context.getServiceImpl(IFloodlightProviderService.class); |
Jonathan Hart | 7e6df36 | 2013-12-10 23:33:59 -0800 | [diff] [blame] | 187 | flowPusher = context.getServiceImpl(IFlowPusherService.class); |
Jonathan Hart | 1767299 | 2013-12-12 16:15:16 -0800 | [diff] [blame] | 188 | datagrid = context.getServiceImpl(IDatagridService.class); |
Pavlin Radoslavov | 52163ed | 2014-03-19 11:39:34 -0700 | [diff] [blame] | 189 | controllerRegistryService = context.getServiceImpl(IControllerRegistryService.class); |
TeruU | 7feef8a | 2014-04-03 00:15:49 -0700 | [diff] [blame] | 190 | networkGraphService = context.getServiceImpl(INetworkGraphService.class); |
| 191 | pathRuntime = context.getServiceImpl(IPathCalcRuntimeService.class); |
Jonathan Hart | 1caaa93 | 2013-11-04 15:28:28 -0800 | [diff] [blame] | 192 | |
| 193 | floodlightProvider.addOFMessageListener(OFType.PACKET_IN, this); |
Jonathan Hart | 0444d93 | 2014-01-22 15:06:17 -0800 | [diff] [blame] | 194 | |
Jonathan Hart | e789d6e | 2013-12-17 17:50:11 -0800 | [diff] [blame] | 195 | pendingFlows = new HashMap<Path, PushedFlow>(); |
Jonathan Hart | d857ad6 | 2013-12-14 18:08:17 -0800 | [diff] [blame] | 196 | waitingPackets = LinkedListMultimap.create(); |
Jonathan Hart | 1caaa93 | 2013-11-04 15:28:28 -0800 | [diff] [blame] | 197 | } |
| 198 | |
Jonathan Hart | e93aed4 | 2013-12-05 18:39:50 -0800 | [diff] [blame] | 199 | @Override |
| 200 | public void startUp(FloodlightModuleContext context) { |
TeruU | 7feef8a | 2014-04-03 00:15:49 -0700 | [diff] [blame] | 201 | |
| 202 | eventChannel = datagrid.createChannel(SINGLE_PACKET_OUT_CHANNEL_NAME, |
| 203 | Long.class, |
| 204 | BroadcastPacketOutNotification.class); |
| 205 | networkGraph = networkGraphService.getNetworkGraph(); |
| 206 | intentMap = pathRuntime.getPathIntents(); |
| 207 | datagrid.addListener("onos.pathintent_state", this, Long.class, IntentStateList.class); |
Jonathan Hart | 1caaa93 | 2013-11-04 15:28:28 -0800 | [diff] [blame] | 208 | } |
| 209 | |
| 210 | @Override |
| 211 | public String getName() { |
| 212 | return "onosforwarding"; |
| 213 | } |
| 214 | |
| 215 | @Override |
| 216 | public boolean isCallbackOrderingPrereq(OFType type, String name) { |
| 217 | return (type == OFType.PACKET_IN) && |
Jonathan Hart | d857ad6 | 2013-12-14 18:08:17 -0800 | [diff] [blame] | 218 | (name.equals("devicemanager") || name.equals("proxyarpmanager") |
| 219 | || name.equals("onosdevicemanager")); |
Jonathan Hart | 1caaa93 | 2013-11-04 15:28:28 -0800 | [diff] [blame] | 220 | } |
| 221 | |
| 222 | @Override |
| 223 | public boolean isCallbackOrderingPostreq(OFType type, String name) { |
| 224 | return false; |
| 225 | } |
| 226 | |
| 227 | @Override |
| 228 | public Command receive( |
| 229 | IOFSwitch sw, OFMessage msg, FloodlightContext cntx) { |
| 230 | |
| 231 | if (msg.getType() != OFType.PACKET_IN) { |
| 232 | return Command.CONTINUE; |
| 233 | } |
| 234 | |
| 235 | OFPacketIn pi = (OFPacketIn) msg; |
| 236 | |
| 237 | Ethernet eth = IFloodlightProviderService.bcStore. |
| 238 | get(cntx, IFloodlightProviderService.CONTEXT_PI_PAYLOAD); |
| 239 | |
TeruU | 6464af0 | 2014-02-06 21:38:45 -0800 | [diff] [blame] | 240 | log.debug("Receive PACKET_IN swId {}, portId {}", sw.getId(), pi.getInPort()); |
| 241 | |
Jonathan Hart | 1767299 | 2013-12-12 16:15:16 -0800 | [diff] [blame] | 242 | if (eth.getEtherType() != Ethernet.TYPE_IPv4) { |
Jonathan Hart | 1caaa93 | 2013-11-04 15:28:28 -0800 | [diff] [blame] | 243 | return Command.CONTINUE; |
| 244 | } |
| 245 | |
Jonathan Hart | 1767299 | 2013-12-12 16:15:16 -0800 | [diff] [blame] | 246 | if (eth.isBroadcast() || eth.isMulticast()) { |
| 247 | handleBroadcast(sw, pi, eth); |
Jonathan Hart | 1767299 | 2013-12-12 16:15:16 -0800 | [diff] [blame] | 248 | } |
| 249 | else { |
| 250 | // Unicast |
| 251 | handlePacketIn(sw, pi, eth); |
| 252 | } |
Jonathan Hart | 1caaa93 | 2013-11-04 15:28:28 -0800 | [diff] [blame] | 253 | |
| 254 | return Command.STOP; |
| 255 | } |
| 256 | |
Jonathan Hart | 1767299 | 2013-12-12 16:15:16 -0800 | [diff] [blame] | 257 | private void handleBroadcast(IOFSwitch sw, OFPacketIn pi, Ethernet eth) { |
| 258 | if (log.isTraceEnabled()) { |
| 259 | log.trace("Sending broadcast packet to other ONOS instances"); |
| 260 | } |
Jonathan Hart | 7804bea | 2014-01-07 10:50:52 -0800 | [diff] [blame] | 261 | |
TeruU | 7feef8a | 2014-04-03 00:15:49 -0700 | [diff] [blame] | 262 | //We don't use address information, so 0 is put into the third argument. |
| 263 | BroadcastPacketOutNotification key = |
Pavlin Radoslavov | 902fe52 | 2014-03-31 10:11:31 -0700 | [diff] [blame] | 264 | new BroadcastPacketOutNotification( |
| 265 | eth.serialize(), |
TeruU | 7feef8a | 2014-04-03 00:15:49 -0700 | [diff] [blame] | 266 | 0, sw.getId(), |
Pavlin Radoslavov | 902fe52 | 2014-03-31 10:11:31 -0700 | [diff] [blame] | 267 | pi.getInPort()); |
TeruU | 7feef8a | 2014-04-03 00:15:49 -0700 | [diff] [blame] | 268 | eventChannel.addTransientEntry(eth.getDestinationMAC().toLong(), key); |
Jonathan Hart | 1767299 | 2013-12-12 16:15:16 -0800 | [diff] [blame] | 269 | } |
| 270 | |
TeruU | 417fe02 | 2014-02-04 12:59:30 -0800 | [diff] [blame] | 271 | private void handlePacketIn(IOFSwitch sw, OFPacketIn pi, Ethernet eth){ |
| 272 | log.debug("Start handlePacketIn swId {}, portId {}", sw.getId(), pi.getInPort()); |
| 273 | |
Jonathan Hart | 5e44878 | 2013-12-10 12:36:35 -0800 | [diff] [blame] | 274 | String destinationMac = |
| 275 | HexString.toHexString(eth.getDestinationMACAddress()); |
Jonathan Hart | 1caaa93 | 2013-11-04 15:28:28 -0800 | [diff] [blame] | 276 | |
TeruU | d1ba0e2 | 2014-02-10 11:44:15 -0800 | [diff] [blame] | 277 | //FIXME getDeviceByMac() is a blocking call, so it may be better way to handle it to avoid the condition. |
TeruU | 7feef8a | 2014-04-03 00:15:49 -0700 | [diff] [blame] | 278 | Device deviceObject = networkGraph.getDeviceByMac(MACAddress.valueOf(destinationMac)); |
TeruU | d1ba0e2 | 2014-02-10 11:44:15 -0800 | [diff] [blame] | 279 | |
TeruU | 7feef8a | 2014-04-03 00:15:49 -0700 | [diff] [blame] | 280 | if (deviceObject == null) { |
| 281 | log.debug("No device entry found for {}", |
| 282 | destinationMac); |
TeruU | d1ba0e2 | 2014-02-10 11:44:15 -0800 | [diff] [blame] | 283 | |
TeruU | 7feef8a | 2014-04-03 00:15:49 -0700 | [diff] [blame] | 284 | //Device is not in the DB, so wait it until the device is added. |
| 285 | executor.schedule(new WaitDeviceArp(sw, pi, eth), SLEEP_TIME_FOR_DB_DEVICE_INSTALLED, TimeUnit.MILLISECONDS); |
| 286 | return; |
Jonathan Hart | 1caaa93 | 2013-11-04 15:28:28 -0800 | [diff] [blame] | 287 | } |
TeruU | 7feef8a | 2014-04-03 00:15:49 -0700 | [diff] [blame] | 288 | |
| 289 | continueHandlePacketIn(sw, pi, eth, deviceObject); |
TeruU | 417fe02 | 2014-02-04 12:59:30 -0800 | [diff] [blame] | 290 | } |
| 291 | |
| 292 | private class WaitDeviceArp implements Runnable { |
| 293 | IOFSwitch sw; |
| 294 | OFPacketIn pi; |
| 295 | Ethernet eth; |
| 296 | |
| 297 | public WaitDeviceArp(IOFSwitch sw, OFPacketIn pi, Ethernet eth) { |
| 298 | super(); |
| 299 | this.sw = sw; |
| 300 | this.pi = pi; |
| 301 | this.eth = eth; |
| 302 | } |
| 303 | |
| 304 | @Override |
| 305 | public void run() { |
TeruU | 7feef8a | 2014-04-03 00:15:49 -0700 | [diff] [blame] | 306 | Device deviceObject = networkGraph.getDeviceByMac(MACAddress.valueOf(eth.getDestinationMACAddress())); |
| 307 | if(deviceObject == null){ |
| 308 | log.debug("wait {}ms and device was not found. Send broadcast packet and the thread finish.", SLEEP_TIME_FOR_DB_DEVICE_INSTALLED); |
| 309 | handleBroadcast(sw, pi, eth); |
| 310 | return; |
| 311 | } |
| 312 | log.debug("wait {}ms and device {} was found, continue",SLEEP_TIME_FOR_DB_DEVICE_INSTALLED, deviceObject.getMacAddress()); |
| 313 | continueHandlePacketIn(sw, pi, eth, deviceObject); |
TeruU | 417fe02 | 2014-02-04 12:59:30 -0800 | [diff] [blame] | 314 | } |
| 315 | } |
| 316 | |
TeruU | 7feef8a | 2014-04-03 00:15:49 -0700 | [diff] [blame] | 317 | private void continueHandlePacketIn(IOFSwitch sw, OFPacketIn pi, Ethernet eth, Device deviceObject) { |
TeruU | 417fe02 | 2014-02-04 12:59:30 -0800 | [diff] [blame] | 318 | |
TeruU | 7feef8a | 2014-04-03 00:15:49 -0700 | [diff] [blame] | 319 | log.debug("Start continuehandlePacketIn"); |
| 320 | |
| 321 | //Iterator<IPortObject> ports = deviceObject.getAttachedPorts().iterator(); |
Jonathan Hart | 472062d | 2014-04-03 10:56:48 -0700 | [diff] [blame^] | 322 | Iterator<net.onrc.onos.core.topology.Port> ports = deviceObject.getAttachmentPoints().iterator(); |
Jonathan Hart | 1caaa93 | 2013-11-04 15:28:28 -0800 | [diff] [blame] | 323 | if (!ports.hasNext()) { |
Jonathan Hart | 18ad950 | 2013-12-15 18:28:00 -0800 | [diff] [blame] | 324 | log.debug("No attachment point found for device {} - broadcasting packet", |
TeruU | 7feef8a | 2014-04-03 00:15:49 -0700 | [diff] [blame] | 325 | deviceObject.getMacAddress()); |
Jonathan Hart | 18ad950 | 2013-12-15 18:28:00 -0800 | [diff] [blame] | 326 | handleBroadcast(sw, pi, eth); |
TeruU | 417fe02 | 2014-02-04 12:59:30 -0800 | [diff] [blame] | 327 | return; |
Jonathan Hart | 1caaa93 | 2013-11-04 15:28:28 -0800 | [diff] [blame] | 328 | } |
TeruU | 417fe02 | 2014-02-04 12:59:30 -0800 | [diff] [blame] | 329 | |
| 330 | //This code assumes the device has only one port. It should be problem. |
Jonathan Hart | 472062d | 2014-04-03 10:56:48 -0700 | [diff] [blame^] | 331 | net.onrc.onos.core.topology.Port portObject = ports.next(); |
TeruU | 7feef8a | 2014-04-03 00:15:49 -0700 | [diff] [blame] | 332 | short destinationPort = portObject.getNumber().shortValue(); |
| 333 | Switch switchObject = portObject.getSwitch(); |
| 334 | long destinationDpid = switchObject.getDpid(); |
Jonathan Hart | 1caaa93 | 2013-11-04 15:28:28 -0800 | [diff] [blame] | 335 | |
Jonathan Hart | 41d1e91 | 2013-11-24 16:50:25 -0800 | [diff] [blame] | 336 | // TODO SwitchPort, Dpid and Port should probably be immutable |
Jonathan Hart | 1caaa93 | 2013-11-04 15:28:28 -0800 | [diff] [blame] | 337 | SwitchPort srcSwitchPort = new SwitchPort( |
| 338 | new Dpid(sw.getId()), new Port(pi.getInPort())); |
| 339 | SwitchPort dstSwitchPort = new SwitchPort( |
| 340 | new Dpid(destinationDpid), new Port(destinationPort)); |
Jonathan Hart | dc3ad70 | 2013-11-14 11:34:59 -0800 | [diff] [blame] | 341 | |
| 342 | MACAddress srcMacAddress = MACAddress.valueOf(eth.getSourceMACAddress()); |
| 343 | MACAddress dstMacAddress = MACAddress.valueOf(eth.getDestinationMACAddress()); |
Jonathan Hart | 1caaa93 | 2013-11-04 15:28:28 -0800 | [diff] [blame] | 344 | |
Jonathan Hart | 7e6df36 | 2013-12-10 23:33:59 -0800 | [diff] [blame] | 345 | synchronized (lock) { |
TeruU | 417fe02 | 2014-02-04 12:59:30 -0800 | [diff] [blame] | 346 | //TODO check concurrency |
TeruU | 6464af0 | 2014-02-06 21:38:45 -0800 | [diff] [blame] | 347 | Path pathspec = new Path(srcMacAddress, dstMacAddress); |
Jonathan Hart | e789d6e | 2013-12-17 17:50:11 -0800 | [diff] [blame] | 348 | PushedFlow existingFlow = pendingFlows.get(pathspec); |
Jonathan Hart | 0444d93 | 2014-01-22 15:06:17 -0800 | [diff] [blame] | 349 | |
TeruU | 6464af0 | 2014-02-06 21:38:45 -0800 | [diff] [blame] | 350 | //A path is installed side by side to reduce a path timeout and a wrong state. |
Jonathan Hart | 0444d93 | 2014-01-22 15:06:17 -0800 | [diff] [blame] | 351 | if (existingFlow != null) { |
TeruU | 6464af0 | 2014-02-06 21:38:45 -0800 | [diff] [blame] | 352 | // We've already start to install a flow for this pair of MAC addresses |
| 353 | if(log.isDebugEnabled()) { |
TeruU | 7feef8a | 2014-04-03 00:15:49 -0700 | [diff] [blame] | 354 | log.debug("Found existing the same pathspec {}, intent ID is {}", |
TeruU | 6464af0 | 2014-02-06 21:38:45 -0800 | [diff] [blame] | 355 | pathspec, |
TeruU | 7feef8a | 2014-04-03 00:15:49 -0700 | [diff] [blame] | 356 | existingFlow.intentId); |
TeruU | 6464af0 | 2014-02-06 21:38:45 -0800 | [diff] [blame] | 357 | } |
| 358 | |
Jonathan Hart | 7e6df36 | 2013-12-10 23:33:59 -0800 | [diff] [blame] | 359 | OFPacketOut po = constructPacketOut(pi, sw); |
Jonathan Hart | e789d6e | 2013-12-17 17:50:11 -0800 | [diff] [blame] | 360 | |
Jonathan Hart | 0444d93 | 2014-01-22 15:06:17 -0800 | [diff] [blame] | 361 | // Find the correct port here. We just assume the PI is from |
| 362 | // the first hop switch, but this is definitely not always |
| 363 | // the case. We'll have to retrieve the flow from HZ every time |
| 364 | // because it could change (be rerouted) sometimes. |
| 365 | if (existingFlow.installed) { |
Jonathan Hart | e789d6e | 2013-12-17 17:50:11 -0800 | [diff] [blame] | 366 | // Flow has been sent to the switches so it is safe to |
| 367 | // send a packet out now |
Pavlin Radoslavov | a3818db | 2014-03-20 19:26:08 -0700 | [diff] [blame] | 368 | |
TeruU | 7feef8a | 2014-04-03 00:15:49 -0700 | [diff] [blame] | 369 | Intent intent = intentMap.getIntent(existingFlow.intentId); |
| 370 | PathIntent pathIntent = null; |
| 371 | if(intent instanceof PathIntent) { |
| 372 | pathIntent = (PathIntent)intent; |
| 373 | } else { |
| 374 | log.debug("Intent {} is not PathIntent. Return.", intent.getId()); |
| 375 | return; |
| 376 | } |
Jonathan Hart | 84198d3 | 2014-01-22 17:14:37 -0800 | [diff] [blame] | 377 | |
TeruU | 7feef8a | 2014-04-03 00:15:49 -0700 | [diff] [blame] | 378 | Boolean isflowEntryForThisSwitch = false; |
Jonathan Hart | 472062d | 2014-04-03 10:56:48 -0700 | [diff] [blame^] | 379 | net.onrc.onos.core.topology.Path path = pathIntent.getPath(); |
TeruU | 7feef8a | 2014-04-03 00:15:49 -0700 | [diff] [blame] | 380 | |
| 381 | for(Iterator<LinkEvent> i = path.iterator(); i.hasNext();) { |
| 382 | LinkEvent le = (LinkEvent)i.next(); |
| 383 | if(le.getSrc().dpid == sw.getId()) { |
| 384 | log.debug("src {} dst {}", le.getSrc(), le.getDst()); |
| 385 | isflowEntryForThisSwitch = true; |
| 386 | break; |
Jonathan Hart | 0444d93 | 2014-01-22 15:06:17 -0800 | [diff] [blame] | 387 | } |
| 388 | } |
| 389 | |
TeruU | 7feef8a | 2014-04-03 00:15:49 -0700 | [diff] [blame] | 390 | if (isflowEntryForThisSwitch == false) { |
Jonathan Hart | 0444d93 | 2014-01-22 15:06:17 -0800 | [diff] [blame] | 391 | // If we don't find a flow entry for that switch, then we're |
| 392 | // in the middle of a rerouting (or something's gone wrong). |
| 393 | // This packet will be dropped as a victim of the rerouting. |
TeruU | 7feef8a | 2014-04-03 00:15:49 -0700 | [diff] [blame] | 394 | log.debug("Dropping packet on flow {} between {}-{}", |
| 395 | existingFlow.intentId, |
| 396 | srcMacAddress, dstMacAddress); |
| 397 | } else { |
| 398 | log.debug("Sending packet out from sw {}, outport{}", sw, existingFlow.firstOutPort); |
| 399 | sendPacketOut(sw, po, existingFlow.firstOutPort); |
Jonathan Hart | 0444d93 | 2014-01-22 15:06:17 -0800 | [diff] [blame] | 400 | } |
Jonathan Hart | e789d6e | 2013-12-17 17:50:11 -0800 | [diff] [blame] | 401 | } |
| 402 | else { |
TeruU | 6464af0 | 2014-02-06 21:38:45 -0800 | [diff] [blame] | 403 | // Flow path has not yet been installed to switches so save the |
Jonathan Hart | e789d6e | 2013-12-17 17:50:11 -0800 | [diff] [blame] | 404 | // packet out for later |
TeruU | 7feef8a | 2014-04-03 00:15:49 -0700 | [diff] [blame] | 405 | log.debug("Put a packet into the waitng list. flowId {}", existingFlow.intentId); |
| 406 | waitingPackets.put(existingFlow.intentId, new PacketToPush(po, sw.getId())); |
Jonathan Hart | e789d6e | 2013-12-17 17:50:11 -0800 | [diff] [blame] | 407 | } |
Jonathan Hart | 41d1e91 | 2013-11-24 16:50:25 -0800 | [diff] [blame] | 408 | return; |
| 409 | } |
Jonathan Hart | 0444d93 | 2014-01-22 15:06:17 -0800 | [diff] [blame] | 410 | |
Jonathan Hart | 7e6df36 | 2013-12-10 23:33:59 -0800 | [diff] [blame] | 411 | log.debug("Adding new flow between {} at {} and {} at {}", |
| 412 | new Object[]{srcMacAddress, srcSwitchPort, dstMacAddress, dstSwitchPort}); |
Jonathan Hart | 48c2d31 | 2013-12-05 19:09:59 -0800 | [diff] [blame] | 413 | |
TeruU | 7feef8a | 2014-04-03 00:15:49 -0700 | [diff] [blame] | 414 | String intentId = callerId + ":" + controllerRegistryService.getNextUniqueId(); |
| 415 | IntentOperationList operations = new IntentOperationList(); |
| 416 | ShortestPathIntent intent = new ShortestPathIntent(intentId, |
| 417 | sw.getId(), pi.getInPort(), srcMacAddress.toLong(), |
| 418 | destinationDpid, destinationPort, dstMacAddress.toLong()); |
| 419 | IntentOperation.Operator operator = IntentOperation.Operator.ADD; |
| 420 | operations.add(operator, intent); |
| 421 | pathRuntime.executeIntentOperations(operations); |
TeruU | 6464af0 | 2014-02-06 21:38:45 -0800 | [diff] [blame] | 422 | |
Jonathan Hart | 7e6df36 | 2013-12-10 23:33:59 -0800 | [diff] [blame] | 423 | OFPacketOut po = constructPacketOut(pi, sw); |
Jonathan Hart | 7e6df36 | 2013-12-10 23:33:59 -0800 | [diff] [blame] | 424 | |
| 425 | // Add to waiting lists |
TeruU | 7feef8a | 2014-04-03 00:15:49 -0700 | [diff] [blame] | 426 | pendingFlows.put(pathspec, new PushedFlow(intentId)); |
| 427 | log.debug("Put a Path {} in the pending flow, intent ID {}", pathspec, intentId); |
| 428 | waitingPackets.put(intentId, new PacketToPush(po, sw.getId())); |
TeruU | 6464af0 | 2014-02-06 21:38:45 -0800 | [diff] [blame] | 429 | log.debug("Put a Packet in the wating list. related pathspec {}", pathspec); |
TeruU | 7feef8a | 2014-04-03 00:15:49 -0700 | [diff] [blame] | 430 | |
Jonathan Hart | 41d1e91 | 2013-11-24 16:50:25 -0800 | [diff] [blame] | 431 | } |
Jonathan Hart | 1caaa93 | 2013-11-04 15:28:28 -0800 | [diff] [blame] | 432 | } |
Jonathan Hart | 1caaa93 | 2013-11-04 15:28:28 -0800 | [diff] [blame] | 433 | |
Jonathan Hart | 7e6df36 | 2013-12-10 23:33:59 -0800 | [diff] [blame] | 434 | private OFPacketOut constructPacketOut(OFPacketIn pi, IOFSwitch sw) { |
Jonathan Hart | 41d1e91 | 2013-11-24 16:50:25 -0800 | [diff] [blame] | 435 | OFPacketOut po = new OFPacketOut(); |
| 436 | po.setInPort(OFPort.OFPP_NONE) |
| 437 | .setInPort(pi.getInPort()) |
Jonathan Hart | 5e44878 | 2013-12-10 12:36:35 -0800 | [diff] [blame] | 438 | .setActions(new ArrayList<OFAction>()) |
| 439 | .setLengthU(OFPacketOut.MINIMUM_LENGTH); |
Jonathan Hart | 41d1e91 | 2013-11-24 16:50:25 -0800 | [diff] [blame] | 440 | |
| 441 | if (sw.getBuffers() == 0) { |
| 442 | po.setBufferId(OFPacketOut.BUFFER_ID_NONE) |
| 443 | .setPacketData(pi.getPacketData()) |
| 444 | .setLengthU(po.getLengthU() + po.getPacketData().length); |
| 445 | } |
| 446 | else { |
| 447 | po.setBufferId(pi.getBufferId()); |
| 448 | } |
| 449 | |
Jonathan Hart | 5e44878 | 2013-12-10 12:36:35 -0800 | [diff] [blame] | 450 | return po; |
| 451 | } |
Pavlin Radoslavov | 7208e9a | 2013-12-11 14:31:07 -0800 | [diff] [blame] | 452 | |
Jonathan Hart | 5e44878 | 2013-12-10 12:36:35 -0800 | [diff] [blame] | 453 | @Override |
Pavlin Radoslavov | 7208e9a | 2013-12-11 14:31:07 -0800 | [diff] [blame] | 454 | public void flowsInstalled(Collection<FlowPath> installedFlowPaths) { |
Pavlin Radoslavov | 7208e9a | 2013-12-11 14:31:07 -0800 | [diff] [blame] | 455 | } |
Jonathan Hart | 0444d93 | 2014-01-22 15:06:17 -0800 | [diff] [blame] | 456 | |
| 457 | @Override |
| 458 | public void flowRemoved(FlowPath removedFlowPath) { |
TeruU | 7feef8a | 2014-04-03 00:15:49 -0700 | [diff] [blame] | 459 | } |
| 460 | |
| 461 | public void flowRemoved(PathIntent removedIntent) { |
| 462 | if(log.isTraceEnabled()){ |
| 463 | log.trace("Path {} was removed", removedIntent.getParentIntent().getId()); |
TeruU | 417fe02 | 2014-02-04 12:59:30 -0800 | [diff] [blame] | 464 | } |
| 465 | |
TeruU | 7feef8a | 2014-04-03 00:15:49 -0700 | [diff] [blame] | 466 | ShortestPathIntent spfIntent = (ShortestPathIntent) removedIntent.getParentIntent(); |
| 467 | MACAddress srcMacAddress = MACAddress.valueOf(spfIntent.getSrcMac()); |
| 468 | MACAddress dstMacAddress = MACAddress.valueOf(spfIntent.getDstMac()); |
Jonathan Hart | 0444d93 | 2014-01-22 15:06:17 -0800 | [diff] [blame] | 469 | Path removedPath = new Path(srcMacAddress, dstMacAddress); |
| 470 | |
| 471 | synchronized (lock) { |
Jonathan Hart | 0444d93 | 2014-01-22 15:06:17 -0800 | [diff] [blame] | 472 | // There *shouldn't* be any packets queued if the flow has |
| 473 | // just been removed. |
TeruU | 7feef8a | 2014-04-03 00:15:49 -0700 | [diff] [blame] | 474 | List<PacketToPush> packets = waitingPackets.removeAll(spfIntent.getId()); |
Jonathan Hart | 0444d93 | 2014-01-22 15:06:17 -0800 | [diff] [blame] | 475 | if (!packets.isEmpty()) { |
TeruU | 7feef8a | 2014-04-03 00:15:49 -0700 | [diff] [blame] | 476 | log.warn("Removed flow {} has packets queued.", spfIntent.getId()); |
Jonathan Hart | 0444d93 | 2014-01-22 15:06:17 -0800 | [diff] [blame] | 477 | } |
TeruU | 417fe02 | 2014-02-04 12:59:30 -0800 | [diff] [blame] | 478 | pendingFlows.remove(removedPath); |
TeruU | 7feef8a | 2014-04-03 00:15:49 -0700 | [diff] [blame] | 479 | log.debug("Removed from the pendingFlow: Path {}, Flow ID {}", removedPath, spfIntent.getId()); |
Jonathan Hart | 0444d93 | 2014-01-22 15:06:17 -0800 | [diff] [blame] | 480 | } |
| 481 | } |
TeruU | 7feef8a | 2014-04-03 00:15:49 -0700 | [diff] [blame] | 482 | |
| 483 | private void flowInstalled(PathIntent installedPath) { |
| 484 | if(log.isTraceEnabled()){ |
| 485 | log.trace("Path {} was installed", installedPath.getParentIntent().getId()); |
Jonathan Hart | 0444d93 | 2014-01-22 15:06:17 -0800 | [diff] [blame] | 486 | } |
| 487 | |
TeruU | 7feef8a | 2014-04-03 00:15:49 -0700 | [diff] [blame] | 488 | ShortestPathIntent spfIntent = (ShortestPathIntent) installedPath.getParentIntent(); |
| 489 | MACAddress srcMacAddress = MACAddress.valueOf(spfIntent.getSrcMac()); |
| 490 | MACAddress dstMacAddress = MACAddress.valueOf(spfIntent.getDstMac()); |
| 491 | Path path = new Path(srcMacAddress, dstMacAddress); |
| 492 | log.debug("Path spec {}", path); |
TeruU | 417fe02 | 2014-02-04 12:59:30 -0800 | [diff] [blame] | 493 | |
Jonathan Hart | 0444d93 | 2014-01-22 15:06:17 -0800 | [diff] [blame] | 494 | // TODO waiting packets should time out. We could request a path that |
| 495 | // can't be installed right now because of a network partition. The path |
| 496 | // may eventually be installed, but we may have received thousands of |
| 497 | // packets in the meantime and probably don't want to send very old packets. |
Jonathan Hart | e789d6e | 2013-12-17 17:50:11 -0800 | [diff] [blame] | 498 | |
TeruU | 7feef8a | 2014-04-03 00:15:49 -0700 | [diff] [blame] | 499 | List<PacketToPush> packets = null; |
Jonathan Hart | 472062d | 2014-04-03 10:56:48 -0700 | [diff] [blame^] | 500 | net.onrc.onos.core.topology.Path graphPath = installedPath.getPath(); |
TeruU | 7feef8a | 2014-04-03 00:15:49 -0700 | [diff] [blame] | 501 | |
| 502 | log.debug("path{}", graphPath); |
| 503 | Short outPort = graphPath.get(0).getSrc().getNumber().shortValue(); |
| 504 | |
| 505 | PushedFlow existingFlow = null; |
Jonathan Hart | e789d6e | 2013-12-17 17:50:11 -0800 | [diff] [blame] | 506 | |
Jonathan Hart | 7e6df36 | 2013-12-10 23:33:59 -0800 | [diff] [blame] | 507 | synchronized (lock) { |
TeruU | 7feef8a | 2014-04-03 00:15:49 -0700 | [diff] [blame] | 508 | existingFlow = pendingFlows.get(path); |
TeruU | 417fe02 | 2014-02-04 12:59:30 -0800 | [diff] [blame] | 509 | |
Jonathan Hart | 0444d93 | 2014-01-22 15:06:17 -0800 | [diff] [blame] | 510 | if (existingFlow != null) { |
| 511 | existingFlow.installed = true; |
TeruU | 417fe02 | 2014-02-04 12:59:30 -0800 | [diff] [blame] | 512 | existingFlow.firstOutPort = outPort; |
| 513 | } else { |
TeruU | 7feef8a | 2014-04-03 00:15:49 -0700 | [diff] [blame] | 514 | log.debug("ExistingFlow {} is null", path); |
TeruU | 417fe02 | 2014-02-04 12:59:30 -0800 | [diff] [blame] | 515 | return; |
| 516 | } |
| 517 | |
TeruU | 6464af0 | 2014-02-06 21:38:45 -0800 | [diff] [blame] | 518 | //Check both existing flow are installed status. |
| 519 | if(existingFlow.installed){ |
TeruU | 7feef8a | 2014-04-03 00:15:49 -0700 | [diff] [blame] | 520 | packets = waitingPackets.removeAll(existingFlow.intentId); |
TeruU | 417fe02 | 2014-02-04 12:59:30 -0800 | [diff] [blame] | 521 | if(log.isDebugEnabled()){ |
| 522 | log.debug("removed my packets {} to push from waitingPackets. outPort {} size {}", |
TeruU | 7feef8a | 2014-04-03 00:15:49 -0700 | [diff] [blame] | 523 | existingFlow.intentId, existingFlow.firstOutPort, packets.size()); |
TeruU | 417fe02 | 2014-02-04 12:59:30 -0800 | [diff] [blame] | 524 | } |
TeruU | 417fe02 | 2014-02-04 12:59:30 -0800 | [diff] [blame] | 525 | }else{ |
| 526 | log.debug("Forward or reverse flows hasn't been pushed yet. return"); |
| 527 | return; |
Jonathan Hart | 0444d93 | 2014-01-22 15:06:17 -0800 | [diff] [blame] | 528 | } |
Jonathan Hart | 7e6df36 | 2013-12-10 23:33:59 -0800 | [diff] [blame] | 529 | } |
TeruU | 7feef8a | 2014-04-03 00:15:49 -0700 | [diff] [blame] | 530 | |
Jonathan Hart | 5e44878 | 2013-12-10 12:36:35 -0800 | [diff] [blame] | 531 | for (PacketToPush packet : packets) { |
TeruU | 7feef8a | 2014-04-03 00:15:49 -0700 | [diff] [blame] | 532 | log.debug("Start packetToPush to sw {}, outPort {}, path {}", packet.dpid, existingFlow.firstOutPort, path); |
Jonathan Hart | 5e44878 | 2013-12-10 12:36:35 -0800 | [diff] [blame] | 533 | IOFSwitch sw = floodlightProvider.getSwitches().get(packet.dpid); |
TeruU | 417fe02 | 2014-02-04 12:59:30 -0800 | [diff] [blame] | 534 | sendPacketOut(sw, packet.packet, existingFlow.firstOutPort); |
| 535 | } |
Jonathan Hart | 41d1e91 | 2013-11-24 16:50:25 -0800 | [diff] [blame] | 536 | } |
Jonathan Hart | e789d6e | 2013-12-17 17:50:11 -0800 | [diff] [blame] | 537 | |
| 538 | private void sendPacketOut(IOFSwitch sw, OFPacketOut po, short outPort) { |
| 539 | po.getActions().add(new OFActionOutput(outPort)); |
| 540 | po.setActionsLength((short) |
| 541 | (po.getActionsLength() + OFActionOutput.MINIMUM_LENGTH)); |
| 542 | po.setLengthU(po.getLengthU() + OFActionOutput.MINIMUM_LENGTH); |
| 543 | |
| 544 | flowPusher.add(sw, po); |
| 545 | } |
Jonathan Hart | 0444d93 | 2014-01-22 15:06:17 -0800 | [diff] [blame] | 546 | |
TeruU | 7feef8a | 2014-04-03 00:15:49 -0700 | [diff] [blame] | 547 | @Override |
| 548 | public void entryAdded(IntentStateList value) { |
| 549 | entryUpdated(value); |
| 550 | |
| 551 | } |
| 552 | |
| 553 | @Override |
| 554 | public void entryRemoved(IntentStateList value) { |
| 555 | //no-op |
| 556 | } |
| 557 | |
| 558 | @Override |
| 559 | public void entryUpdated(IntentStateList value) { |
| 560 | for (Entry<String, IntentState> entry: value.entrySet()) { |
| 561 | log.debug("path intent key {}, value {}", entry.getKey(), entry.getValue()); |
| 562 | PathIntent pathIntent = (PathIntent) intentMap.getIntent(entry.getKey()); |
| 563 | if (pathIntent == null) |
| 564 | continue; |
| 565 | |
| 566 | if (!(pathIntent.getParentIntent() instanceof ShortestPathIntent)) |
| 567 | continue; |
| 568 | |
| 569 | IntentState state = entry.getValue(); |
| 570 | switch (state) { |
| 571 | case INST_REQ: |
| 572 | break; |
| 573 | case INST_ACK: |
| 574 | flowInstalled(pathIntent); |
| 575 | break; |
| 576 | case INST_NACK: |
| 577 | break; |
| 578 | case DEL_REQ: |
| 579 | break; |
| 580 | case DEL_ACK: |
| 581 | flowRemoved(pathIntent); |
| 582 | break; |
| 583 | case DEL_PENDING: |
| 584 | break; |
| 585 | default: |
| 586 | break; |
| 587 | } |
| 588 | } |
| 589 | } |
Jonathan Hart | 1caaa93 | 2013-11-04 15:28:28 -0800 | [diff] [blame] | 590 | } |