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