HIGUCHI Yuta | ea60e5f | 2013-06-12 11:10:21 -0700 | [diff] [blame] | 1 | package net.onrc.onos.ofcontroller.bgproute; |
pingping-lin | a2cbfad | 2013-03-07 08:39:21 +0800 | [diff] [blame] | 2 | |
Jonathan Hart | d1f2325 | 2013-06-13 15:17:05 +1200 | [diff] [blame] | 3 | import java.io.File; |
Jonathan Hart | e7e1c6e | 2013-06-04 20:50:23 -0700 | [diff] [blame] | 4 | import java.io.IOException; |
| 5 | import java.net.InetAddress; |
pingping-lin | a2cbfad | 2013-03-07 08:39:21 +0800 | [diff] [blame] | 6 | import java.util.ArrayList; |
Jonathan Hart | 61ba937 | 2013-05-19 20:10:29 -0700 | [diff] [blame] | 7 | import java.util.Collection; |
pingping-lin | a2cbfad | 2013-03-07 08:39:21 +0800 | [diff] [blame] | 8 | import java.util.HashMap; |
Jonathan Hart | 98957bf | 2013-07-01 14:49:24 +1200 | [diff] [blame] | 9 | import java.util.Iterator; |
Jonathan Hart | e7e1c6e | 2013-06-04 20:50:23 -0700 | [diff] [blame] | 10 | import java.util.List; |
Jonathan Hart | 61ba937 | 2013-05-19 20:10:29 -0700 | [diff] [blame] | 11 | import java.util.Map; |
Jonathan Hart | 4dfc365 | 2013-08-02 20:22:36 +1200 | [diff] [blame] | 12 | import java.util.Set; |
Jonathan Hart | 8b9349e | 2013-07-26 15:55:28 +1200 | [diff] [blame] | 13 | import java.util.concurrent.BlockingQueue; |
| 14 | import java.util.concurrent.ExecutorService; |
Jonathan Hart | 98957bf | 2013-07-01 14:49:24 +1200 | [diff] [blame] | 15 | import java.util.concurrent.Executors; |
Jonathan Hart | 8b9349e | 2013-07-26 15:55:28 +1200 | [diff] [blame] | 16 | import java.util.concurrent.LinkedBlockingQueue; |
Jonathan Hart | 98957bf | 2013-07-01 14:49:24 +1200 | [diff] [blame] | 17 | import java.util.concurrent.ScheduledExecutorService; |
| 18 | import java.util.concurrent.TimeUnit; |
pingping-lin | a2cbfad | 2013-03-07 08:39:21 +0800 | [diff] [blame] | 19 | |
Jonathan Hart | 61ba937 | 2013-05-19 20:10:29 -0700 | [diff] [blame] | 20 | import net.floodlightcontroller.core.IFloodlightProviderService; |
Jonathan Hart | e7e1c6e | 2013-06-04 20:50:23 -0700 | [diff] [blame] | 21 | import net.floodlightcontroller.core.IOFSwitch; |
Jonathan Hart | 1236a9b | 2013-06-18 22:10:05 +1200 | [diff] [blame] | 22 | import net.floodlightcontroller.core.IOFSwitchListener; |
pingping-lin | a2cbfad | 2013-03-07 08:39:21 +0800 | [diff] [blame] | 23 | import net.floodlightcontroller.core.module.FloodlightModuleContext; |
| 24 | import net.floodlightcontroller.core.module.FloodlightModuleException; |
| 25 | import net.floodlightcontroller.core.module.IFloodlightModule; |
| 26 | import net.floodlightcontroller.core.module.IFloodlightService; |
Jonathan Hart | 98957bf | 2013-07-01 14:49:24 +1200 | [diff] [blame] | 27 | import net.floodlightcontroller.core.util.SingletonTask; |
Jonathan Hart | e7e1c6e | 2013-06-04 20:50:23 -0700 | [diff] [blame] | 28 | import net.floodlightcontroller.devicemanager.IDeviceService; |
| 29 | import net.floodlightcontroller.packet.Ethernet; |
Jonathan Hart | 832a7cb | 2013-06-24 11:25:35 +1200 | [diff] [blame] | 30 | import net.floodlightcontroller.packet.IPv4; |
pingping-lin | a2cbfad | 2013-03-07 08:39:21 +0800 | [diff] [blame] | 31 | import net.floodlightcontroller.restserver.IRestApiService; |
Jonathan Hart | 98957bf | 2013-07-01 14:49:24 +1200 | [diff] [blame] | 32 | import net.floodlightcontroller.routing.Link; |
pingping-lin | a2cbfad | 2013-03-07 08:39:21 +0800 | [diff] [blame] | 33 | import net.floodlightcontroller.topology.ITopologyListener; |
| 34 | import net.floodlightcontroller.topology.ITopologyService; |
Jonathan Hart | 4dfc365 | 2013-08-02 20:22:36 +1200 | [diff] [blame] | 35 | import net.floodlightcontroller.util.MACAddress; |
Jonathan Hart | 0ee0f02 | 2013-08-03 22:21:54 +1200 | [diff] [blame] | 36 | import net.onrc.onos.ofcontroller.bgproute.RibUpdate.Operation; |
Jonathan Hart | 98957bf | 2013-07-01 14:49:24 +1200 | [diff] [blame] | 37 | import net.onrc.onos.ofcontroller.core.INetMapTopologyService.ITopoLinkService; |
HIGUCHI Yuta | 2051490 | 2013-06-12 11:24:16 -0700 | [diff] [blame] | 38 | import net.onrc.onos.ofcontroller.core.INetMapTopologyService.ITopoRouteService; |
Jonathan Hart | 98957bf | 2013-07-01 14:49:24 +1200 | [diff] [blame] | 39 | import net.onrc.onos.ofcontroller.core.internal.TopoLinkServiceImpl; |
HIGUCHI Yuta | a56fbde | 2013-06-17 14:26:05 -0700 | [diff] [blame] | 40 | import net.onrc.onos.ofcontroller.linkdiscovery.ILinkDiscovery; |
| 41 | import net.onrc.onos.ofcontroller.linkdiscovery.ILinkDiscovery.LDUpdate; |
Jonathan Hart | 4dfc365 | 2013-08-02 20:22:36 +1200 | [diff] [blame] | 42 | import net.onrc.onos.ofcontroller.proxyarp.IArpRequester; |
Jonathan Hart | c7ca35d | 2013-06-25 20:54:25 +1200 | [diff] [blame] | 43 | import net.onrc.onos.ofcontroller.proxyarp.ProxyArpManager; |
Pavlin Radoslavov | ddd01ba | 2013-07-03 15:40:44 -0700 | [diff] [blame] | 44 | import net.onrc.onos.ofcontroller.routing.TopoRouteService; |
HIGUCHI Yuta | 356086e | 2013-06-12 15:21:19 -0700 | [diff] [blame] | 45 | import net.onrc.onos.ofcontroller.util.DataPath; |
Jonathan Hart | 832a7cb | 2013-06-24 11:25:35 +1200 | [diff] [blame] | 46 | import net.onrc.onos.ofcontroller.util.Dpid; |
HIGUCHI Yuta | 356086e | 2013-06-12 15:21:19 -0700 | [diff] [blame] | 47 | import net.onrc.onos.ofcontroller.util.FlowEntry; |
HIGUCHI Yuta | 356086e | 2013-06-12 15:21:19 -0700 | [diff] [blame] | 48 | import net.onrc.onos.ofcontroller.util.Port; |
| 49 | import net.onrc.onos.ofcontroller.util.SwitchPort; |
pingping-lin | e2a09ca | 2013-03-23 09:33:58 +0800 | [diff] [blame] | 50 | import net.sf.json.JSONArray; |
| 51 | import net.sf.json.JSONObject; |
| 52 | import net.sf.json.JSONSerializer; |
pingping-lin | a2cbfad | 2013-03-07 08:39:21 +0800 | [diff] [blame] | 53 | |
Jonathan Hart | d1f2325 | 2013-06-13 15:17:05 +1200 | [diff] [blame] | 54 | import org.codehaus.jackson.JsonParseException; |
| 55 | import org.codehaus.jackson.map.JsonMappingException; |
| 56 | import org.codehaus.jackson.map.ObjectMapper; |
Jonathan Hart | e7e1c6e | 2013-06-04 20:50:23 -0700 | [diff] [blame] | 57 | import org.openflow.protocol.OFFlowMod; |
| 58 | import org.openflow.protocol.OFMatch; |
| 59 | import org.openflow.protocol.OFMessage; |
| 60 | import org.openflow.protocol.OFPacketOut; |
Jonathan Hart | 9575cb6 | 2013-07-05 13:43:49 +1200 | [diff] [blame] | 61 | import org.openflow.protocol.OFPort; |
Jonathan Hart | e7e1c6e | 2013-06-04 20:50:23 -0700 | [diff] [blame] | 62 | import org.openflow.protocol.OFType; |
| 63 | import org.openflow.protocol.action.OFAction; |
| 64 | import org.openflow.protocol.action.OFActionDataLayerDestination; |
| 65 | import org.openflow.protocol.action.OFActionOutput; |
Jonathan Hart | 1236a9b | 2013-06-18 22:10:05 +1200 | [diff] [blame] | 66 | import org.openflow.util.HexString; |
pingping-lin | a2cbfad | 2013-03-07 08:39:21 +0800 | [diff] [blame] | 67 | import org.slf4j.Logger; |
| 68 | import org.slf4j.LoggerFactory; |
| 69 | |
Jonathan Hart | 4dfc365 | 2013-08-02 20:22:36 +1200 | [diff] [blame] | 70 | import com.google.common.collect.HashMultimap; |
Jonathan Hart | 0ee0f02 | 2013-08-03 22:21:54 +1200 | [diff] [blame] | 71 | import com.google.common.collect.Multimap; |
Jonathan Hart | 4dfc365 | 2013-08-02 20:22:36 +1200 | [diff] [blame] | 72 | import com.google.common.collect.Multimaps; |
| 73 | import com.google.common.collect.SetMultimap; |
Jonathan Hart | 8b9349e | 2013-07-26 15:55:28 +1200 | [diff] [blame] | 74 | import com.google.common.util.concurrent.ThreadFactoryBuilder; |
| 75 | |
Jonathan Hart | 1236a9b | 2013-06-18 22:10:05 +1200 | [diff] [blame] | 76 | public class BgpRoute implements IFloodlightModule, IBgpRouteService, |
Jonathan Hart | 4dfc365 | 2013-08-02 20:22:36 +1200 | [diff] [blame] | 77 | ITopologyListener, IOFSwitchListener, |
| 78 | IArpRequester { |
pingping-lin | a2cbfad | 2013-03-07 08:39:21 +0800 | [diff] [blame] | 79 | |
| 80 | protected static Logger log = LoggerFactory.getLogger(BgpRoute.class); |
| 81 | |
| 82 | protected IFloodlightProviderService floodlightProvider; |
| 83 | protected ITopologyService topology; |
Jonathan Hart | e7e1c6e | 2013-06-04 20:50:23 -0700 | [diff] [blame] | 84 | protected ITopoRouteService topoRouteService; |
| 85 | protected IDeviceService devices; |
| 86 | protected IRestApiService restApi; |
| 87 | |
Jonathan Hart | c7ca35d | 2013-06-25 20:54:25 +1200 | [diff] [blame] | 88 | protected ProxyArpManager proxyArp; |
| 89 | |
Jonathan Hart | d7e158d | 2013-08-07 23:04:48 +1200 | [diff] [blame] | 90 | //protected static Ptree ptree; |
Jonathan Hart | 29b972d | 2013-08-12 23:43:51 +1200 | [diff] [blame^] | 91 | protected IPatriciaTrie<RibEntry> ptree; |
Jonathan Hart | 8b9349e | 2013-07-26 15:55:28 +1200 | [diff] [blame] | 92 | protected BlockingQueue<RibUpdate> ribUpdates; |
| 93 | |
Jonathan Hart | 61ba937 | 2013-05-19 20:10:29 -0700 | [diff] [blame] | 94 | protected String bgpdRestIp; |
| 95 | protected String routerId; |
Jonathan Hart | 9575cb6 | 2013-07-05 13:43:49 +1200 | [diff] [blame] | 96 | protected String configFilename = "config.json"; |
Jonathan Hart | e7e1c6e | 2013-06-04 20:50:23 -0700 | [diff] [blame] | 97 | |
| 98 | //We need to identify our flows somehow. But like it says in LearningSwitch.java, |
| 99 | //the controller/OS should hand out cookie IDs to prevent conflicts. |
| 100 | protected final long APP_COOKIE = 0xa0000000000000L; |
| 101 | //Cookie for flows that do L2 forwarding within SDN domain to egress routers |
| 102 | protected final long L2_FWD_COOKIE = APP_COOKIE + 1; |
| 103 | //Cookie for flows in ingress switches that rewrite the MAC address |
| 104 | protected final long MAC_RW_COOKIE = APP_COOKIE + 2; |
Jonathan Hart | 832a7cb | 2013-06-24 11:25:35 +1200 | [diff] [blame] | 105 | //Cookie for flows that setup BGP paths |
| 106 | protected final long BGP_COOKIE = APP_COOKIE + 3; |
Jonathan Hart | 50a8d1e | 2013-06-06 16:00:47 +1200 | [diff] [blame] | 107 | //Forwarding uses priority 0, and the mac rewrite entries in ingress switches |
| 108 | //need to be higher priority than this otherwise the rewrite may not get done |
| 109 | protected final short SDNIP_PRIORITY = 10; |
Jonathan Hart | e7e1c6e | 2013-06-04 20:50:23 -0700 | [diff] [blame] | 110 | |
Jonathan Hart | 832a7cb | 2013-06-24 11:25:35 +1200 | [diff] [blame] | 111 | protected final short BGP_PORT = 179; |
| 112 | |
Jonathan Hart | 98957bf | 2013-07-01 14:49:24 +1200 | [diff] [blame] | 113 | protected final int TOPO_DETECTION_WAIT = 2; //seconds |
| 114 | |
Jonathan Hart | 832a7cb | 2013-06-24 11:25:35 +1200 | [diff] [blame] | 115 | //Configuration stuff |
Jonathan Hart | 1236a9b | 2013-06-18 22:10:05 +1200 | [diff] [blame] | 116 | protected List<String> switches; |
Jonathan Hart | 832a7cb | 2013-06-24 11:25:35 +1200 | [diff] [blame] | 117 | protected Map<String, Interface> interfaces; |
Jonathan Hart | c824ad0 | 2013-07-03 15:58:45 +1200 | [diff] [blame] | 118 | protected Map<InetAddress, BgpPeer> bgpPeers; |
Jonathan Hart | 832a7cb | 2013-06-24 11:25:35 +1200 | [diff] [blame] | 119 | protected SwitchPort bgpdAttachmentPoint; |
Jonathan Hart | 1236a9b | 2013-06-18 22:10:05 +1200 | [diff] [blame] | 120 | |
| 121 | //True when all switches have connected |
| 122 | protected volatile boolean switchesConnected = false; |
| 123 | //True when we have a full mesh of shortest paths between gateways |
| 124 | protected volatile boolean topologyReady = false; |
Jonathan Hart | 98957bf | 2013-07-01 14:49:24 +1200 | [diff] [blame] | 125 | |
Jonathan Hart | 98957bf | 2013-07-01 14:49:24 +1200 | [diff] [blame] | 126 | protected ArrayList<LDUpdate> linkUpdates; |
| 127 | protected SingletonTask topologyChangeDetectorTask; |
| 128 | |
Jonathan Hart | 4dfc365 | 2013-08-02 20:22:36 +1200 | [diff] [blame] | 129 | protected SetMultimap<InetAddress, RibUpdate> prefixesWaitingOnArp; |
| 130 | protected SetMultimap<InetAddress, PathUpdate> pathsWaitingOnArp; |
| 131 | |
Jonathan Hart | 0a46fe4 | 2013-08-10 17:08:47 +1200 | [diff] [blame] | 132 | protected ExecutorService bgpUpdatesExecutor; |
| 133 | |
Jonathan Hart | 0ee0f02 | 2013-08-03 22:21:54 +1200 | [diff] [blame] | 134 | protected Multimap<Prefix, PushedFlowMod> pushedFlows; |
| 135 | |
| 136 | private class PushedFlowMod { |
| 137 | private long dpid; |
| 138 | private OFFlowMod flowMod; |
| 139 | |
| 140 | public PushedFlowMod(long dpid, OFFlowMod flowMod) { |
| 141 | this.dpid = dpid; |
| 142 | this.flowMod = flowMod; |
| 143 | } |
| 144 | |
| 145 | public long getDpid() { |
| 146 | return dpid; |
| 147 | } |
| 148 | |
| 149 | public OFFlowMod getFlowMod() { |
| 150 | return flowMod; |
| 151 | } |
| 152 | } |
| 153 | |
Jonathan Hart | 98957bf | 2013-07-01 14:49:24 +1200 | [diff] [blame] | 154 | protected class TopologyChangeDetector implements Runnable { |
| 155 | @Override |
| 156 | public void run() { |
| 157 | log.debug("Running topology change detection task"); |
| 158 | synchronized (linkUpdates) { |
Jonathan Hart | c824ad0 | 2013-07-03 15:58:45 +1200 | [diff] [blame] | 159 | //This is the model the REST API uses to retrieve network graph info |
Jonathan Hart | 98957bf | 2013-07-01 14:49:24 +1200 | [diff] [blame] | 160 | ITopoLinkService topoLinkService = new TopoLinkServiceImpl(); |
| 161 | |
| 162 | List<Link> activeLinks = topoLinkService.getActiveLinks(); |
Jonathan Hart | 98957bf | 2013-07-01 14:49:24 +1200 | [diff] [blame] | 163 | |
| 164 | Iterator<LDUpdate> it = linkUpdates.iterator(); |
| 165 | while (it.hasNext()){ |
| 166 | LDUpdate ldu = it.next(); |
| 167 | Link l = new Link(ldu.getSrc(), ldu.getSrcPort(), |
| 168 | ldu.getDst(), ldu.getDstPort()); |
| 169 | |
| 170 | if (activeLinks.contains(l)){ |
| 171 | log.debug("Not found: {}", l); |
| 172 | it.remove(); |
| 173 | } |
| 174 | } |
| 175 | } |
| 176 | |
| 177 | if (linkUpdates.isEmpty()){ |
| 178 | //All updates have been seen in network map. |
| 179 | //We can check if topology is ready |
Jonathan Hart | 8b9349e | 2013-07-26 15:55:28 +1200 | [diff] [blame] | 180 | log.debug("No known changes outstanding. Checking topology now"); |
Jonathan Hart | 98957bf | 2013-07-01 14:49:24 +1200 | [diff] [blame] | 181 | checkStatus(); |
| 182 | } |
| 183 | else { |
| 184 | //We know of some link updates that haven't propagated to the database yet |
Jonathan Hart | 8b9349e | 2013-07-26 15:55:28 +1200 | [diff] [blame] | 185 | log.debug("Some changes not found in network map - {} links missing", linkUpdates.size()); |
Jonathan Hart | 98957bf | 2013-07-01 14:49:24 +1200 | [diff] [blame] | 186 | topologyChangeDetectorTask.reschedule(TOPO_DETECTION_WAIT, TimeUnit.SECONDS); |
| 187 | } |
| 188 | } |
| 189 | } |
Jonathan Hart | e7e1c6e | 2013-06-04 20:50:23 -0700 | [diff] [blame] | 190 | |
Jonathan Hart | d1f2325 | 2013-06-13 15:17:05 +1200 | [diff] [blame] | 191 | private void readGatewaysConfiguration(String gatewaysFilename){ |
| 192 | File gatewaysFile = new File(gatewaysFilename); |
| 193 | ObjectMapper mapper = new ObjectMapper(); |
Jonathan Hart | e7e1c6e | 2013-06-04 20:50:23 -0700 | [diff] [blame] | 194 | |
Jonathan Hart | d1f2325 | 2013-06-13 15:17:05 +1200 | [diff] [blame] | 195 | try { |
Jonathan Hart | 1236a9b | 2013-06-18 22:10:05 +1200 | [diff] [blame] | 196 | Configuration config = mapper.readValue(gatewaysFile, Configuration.class); |
| 197 | |
Jonathan Hart | 1236a9b | 2013-06-18 22:10:05 +1200 | [diff] [blame] | 198 | switches = config.getSwitches(); |
Jonathan Hart | 9575cb6 | 2013-07-05 13:43:49 +1200 | [diff] [blame] | 199 | interfaces = new HashMap<String, Interface>(); |
| 200 | for (Interface intf : config.getInterfaces()){ |
| 201 | interfaces.put(intf.getName(), intf); |
| 202 | } |
Jonathan Hart | c824ad0 | 2013-07-03 15:58:45 +1200 | [diff] [blame] | 203 | bgpPeers = new HashMap<InetAddress, BgpPeer>(); |
| 204 | for (BgpPeer peer : config.getPeers()){ |
| 205 | bgpPeers.put(peer.getIpAddress(), peer); |
| 206 | } |
Jonathan Hart | 1236a9b | 2013-06-18 22:10:05 +1200 | [diff] [blame] | 207 | |
Jonathan Hart | 832a7cb | 2013-06-24 11:25:35 +1200 | [diff] [blame] | 208 | bgpdAttachmentPoint = new SwitchPort( |
| 209 | new Dpid(config.getBgpdAttachmentDpid()), |
| 210 | new Port(config.getBgpdAttachmentPort())); |
Jonathan Hart | 1236a9b | 2013-06-18 22:10:05 +1200 | [diff] [blame] | 211 | |
Jonathan Hart | d1f2325 | 2013-06-13 15:17:05 +1200 | [diff] [blame] | 212 | } catch (JsonParseException e) { |
| 213 | log.error("Error in JSON file", e); |
| 214 | System.exit(1); |
| 215 | } catch (JsonMappingException e) { |
| 216 | log.error("Error in JSON file", e); |
| 217 | System.exit(1); |
| 218 | } catch (IOException e) { |
| 219 | log.error("Error reading JSON file", e); |
| 220 | System.exit(1); |
| 221 | } |
Jonathan Hart | e7e1c6e | 2013-06-04 20:50:23 -0700 | [diff] [blame] | 222 | } |
pingping-lin | a2cbfad | 2013-03-07 08:39:21 +0800 | [diff] [blame] | 223 | |
| 224 | @Override |
| 225 | public Collection<Class<? extends IFloodlightService>> getModuleServices() { |
Jonathan Hart | 61ba937 | 2013-05-19 20:10:29 -0700 | [diff] [blame] | 226 | Collection<Class<? extends IFloodlightService>> l |
| 227 | = new ArrayList<Class<? extends IFloodlightService>>(); |
pingping-lin | a2cbfad | 2013-03-07 08:39:21 +0800 | [diff] [blame] | 228 | l.add(IBgpRouteService.class); |
| 229 | return l; |
| 230 | } |
| 231 | |
| 232 | @Override |
| 233 | public Map<Class<? extends IFloodlightService>, IFloodlightService> getServiceImpls() { |
Jonathan Hart | 61ba937 | 2013-05-19 20:10:29 -0700 | [diff] [blame] | 234 | Map<Class<? extends IFloodlightService>, IFloodlightService> m |
| 235 | = new HashMap<Class<? extends IFloodlightService>, IFloodlightService>(); |
pingping-lin | e2a09ca | 2013-03-23 09:33:58 +0800 | [diff] [blame] | 236 | m.put(IBgpRouteService.class, this); |
pingping-lin | a2cbfad | 2013-03-07 08:39:21 +0800 | [diff] [blame] | 237 | return m; |
| 238 | } |
| 239 | |
pingping-lin | a2cbfad | 2013-03-07 08:39:21 +0800 | [diff] [blame] | 240 | @Override |
| 241 | public Collection<Class<? extends IFloodlightService>> getModuleDependencies() { |
Jonathan Hart | 61ba937 | 2013-05-19 20:10:29 -0700 | [diff] [blame] | 242 | Collection<Class<? extends IFloodlightService>> l |
| 243 | = new ArrayList<Class<? extends IFloodlightService>>(); |
pingping-lin | a2cbfad | 2013-03-07 08:39:21 +0800 | [diff] [blame] | 244 | l.add(IFloodlightProviderService.class); |
| 245 | l.add(ITopologyService.class); |
Jonathan Hart | e7e1c6e | 2013-06-04 20:50:23 -0700 | [diff] [blame] | 246 | l.add(IDeviceService.class); |
| 247 | l.add(IRestApiService.class); |
pingping-lin | a2cbfad | 2013-03-07 08:39:21 +0800 | [diff] [blame] | 248 | return l; |
| 249 | } |
| 250 | |
| 251 | @Override |
| 252 | public void init(FloodlightModuleContext context) |
| 253 | throws FloodlightModuleException { |
| 254 | |
Jonathan Hart | d7e158d | 2013-08-07 23:04:48 +1200 | [diff] [blame] | 255 | //ptree = new Ptree(32); |
Jonathan Hart | 29b972d | 2013-08-12 23:43:51 +1200 | [diff] [blame^] | 256 | ptree = new PatriciaTrie<RibEntry>(32); |
Jonathan Hart | 8b9349e | 2013-07-26 15:55:28 +1200 | [diff] [blame] | 257 | |
| 258 | ribUpdates = new LinkedBlockingQueue<RibUpdate>(); |
Jonathan Hart | c824ad0 | 2013-07-03 15:58:45 +1200 | [diff] [blame] | 259 | |
pingping-lin | a2cbfad | 2013-03-07 08:39:21 +0800 | [diff] [blame] | 260 | // Register floodlight provider and REST handler. |
| 261 | floodlightProvider = context.getServiceImpl(IFloodlightProviderService.class); |
pingping-lin | a2cbfad | 2013-03-07 08:39:21 +0800 | [diff] [blame] | 262 | topology = context.getServiceImpl(ITopologyService.class); |
Jonathan Hart | e7e1c6e | 2013-06-04 20:50:23 -0700 | [diff] [blame] | 263 | devices = context.getServiceImpl(IDeviceService.class); |
Jonathan Hart | c7ca35d | 2013-06-25 20:54:25 +1200 | [diff] [blame] | 264 | restApi = context.getServiceImpl(IRestApiService.class); |
| 265 | |
| 266 | //TODO We'll initialise this here for now, but it should really be done as |
| 267 | //part of the controller core |
Jonathan Hart | 6261dcd | 2013-07-22 17:58:35 +1200 | [diff] [blame] | 268 | proxyArp = new ProxyArpManager(floodlightProvider, topology, devices); |
pingping-lin | a2cbfad | 2013-03-07 08:39:21 +0800 | [diff] [blame] | 269 | |
Jonathan Hart | 98957bf | 2013-07-01 14:49:24 +1200 | [diff] [blame] | 270 | linkUpdates = new ArrayList<LDUpdate>(); |
| 271 | ScheduledExecutorService executor = Executors.newScheduledThreadPool(1); |
| 272 | topologyChangeDetectorTask = new SingletonTask(executor, new TopologyChangeDetector()); |
Pavlin Radoslavov | ddd01ba | 2013-07-03 15:40:44 -0700 | [diff] [blame] | 273 | |
| 274 | topoRouteService = new TopoRouteService(""); |
Jonathan Hart | 98957bf | 2013-07-01 14:49:24 +1200 | [diff] [blame] | 275 | |
Jonathan Hart | 4dfc365 | 2013-08-02 20:22:36 +1200 | [diff] [blame] | 276 | pathsWaitingOnArp = Multimaps.synchronizedSetMultimap( |
| 277 | HashMultimap.<InetAddress, PathUpdate>create()); |
| 278 | prefixesWaitingOnArp = Multimaps.synchronizedSetMultimap( |
| 279 | HashMultimap.<InetAddress, RibUpdate>create()); |
| 280 | |
Jonathan Hart | 0ee0f02 | 2013-08-03 22:21:54 +1200 | [diff] [blame] | 281 | pushedFlows = HashMultimap.<Prefix, PushedFlowMod>create(); |
| 282 | |
Jonathan Hart | 0a46fe4 | 2013-08-10 17:08:47 +1200 | [diff] [blame] | 283 | bgpUpdatesExecutor = Executors.newSingleThreadExecutor( |
| 284 | new ThreadFactoryBuilder().setNameFormat("bgp-updates-%d").build()); |
| 285 | |
Jonathan Hart | 61ba937 | 2013-05-19 20:10:29 -0700 | [diff] [blame] | 286 | //Read in config values |
| 287 | bgpdRestIp = context.getConfigParams(this).get("BgpdRestIp"); |
| 288 | if (bgpdRestIp == null){ |
| 289 | log.error("BgpdRestIp property not found in config file"); |
| 290 | System.exit(1); |
| 291 | } |
| 292 | else { |
| 293 | log.info("BgpdRestIp set to {}", bgpdRestIp); |
| 294 | } |
| 295 | |
| 296 | routerId = context.getConfigParams(this).get("RouterId"); |
| 297 | if (routerId == null){ |
| 298 | log.error("RouterId property not found in config file"); |
| 299 | System.exit(1); |
| 300 | } |
| 301 | else { |
| 302 | log.info("RouterId set to {}", routerId); |
| 303 | } |
Jonathan Hart | d1f2325 | 2013-06-13 15:17:05 +1200 | [diff] [blame] | 304 | |
Jonathan Hart | 9575cb6 | 2013-07-05 13:43:49 +1200 | [diff] [blame] | 305 | String configFilenameParameter = context.getConfigParams(this).get("configfile"); |
| 306 | if (configFilenameParameter != null){ |
| 307 | configFilename = configFilenameParameter; |
| 308 | } |
| 309 | log.debug("Config file set to {}", configFilename); |
| 310 | |
| 311 | readGatewaysConfiguration(configFilename); |
pingping-lin | a2cbfad | 2013-03-07 08:39:21 +0800 | [diff] [blame] | 312 | // Test. |
| 313 | //test(); |
| 314 | } |
| 315 | |
Jonathan Hart | d7e158d | 2013-08-07 23:04:48 +1200 | [diff] [blame] | 316 | //public Ptree getPtree() { |
Jonathan Hart | 29b972d | 2013-08-12 23:43:51 +1200 | [diff] [blame^] | 317 | public IPatriciaTrie<RibEntry> getPtree() { |
pingping-lin | a2cbfad | 2013-03-07 08:39:21 +0800 | [diff] [blame] | 318 | return ptree; |
| 319 | } |
Jonathan Hart | 61ba937 | 2013-05-19 20:10:29 -0700 | [diff] [blame] | 320 | |
| 321 | public void clearPtree() { |
| 322 | //ptree = null; |
Jonathan Hart | d7e158d | 2013-08-07 23:04:48 +1200 | [diff] [blame] | 323 | //ptree = new Ptree(32); |
Jonathan Hart | 29b972d | 2013-08-12 23:43:51 +1200 | [diff] [blame^] | 324 | ptree = new PatriciaTrie<RibEntry>(32); |
pingping-lin | e2a09ca | 2013-03-23 09:33:58 +0800 | [diff] [blame] | 325 | } |
Jonathan Hart | 61ba937 | 2013-05-19 20:10:29 -0700 | [diff] [blame] | 326 | |
pingping-lin | e2a09ca | 2013-03-23 09:33:58 +0800 | [diff] [blame] | 327 | public String getBGPdRestIp() { |
Jonathan Hart | 61ba937 | 2013-05-19 20:10:29 -0700 | [diff] [blame] | 328 | return bgpdRestIp; |
pingping-lin | e2a09ca | 2013-03-23 09:33:58 +0800 | [diff] [blame] | 329 | } |
Jonathan Hart | 61ba937 | 2013-05-19 20:10:29 -0700 | [diff] [blame] | 330 | |
pingping-lin | e2a09ca | 2013-03-23 09:33:58 +0800 | [diff] [blame] | 331 | public String getRouterId() { |
Jonathan Hart | 61ba937 | 2013-05-19 20:10:29 -0700 | [diff] [blame] | 332 | return routerId; |
pingping-lin | e2a09ca | 2013-03-23 09:33:58 +0800 | [diff] [blame] | 333 | } |
pingping-lin | a2cbfad | 2013-03-07 08:39:21 +0800 | [diff] [blame] | 334 | |
| 335 | // Return nexthop address as byte array. |
Jonathan Hart | d7e158d | 2013-08-07 23:04:48 +1200 | [diff] [blame] | 336 | /* |
Jonathan Hart | b39a67d | 2013-08-10 23:59:50 +1200 | [diff] [blame] | 337 | public RibEntry lookupRib(byte[] dest) { |
pingping-lin | a2cbfad | 2013-03-07 08:39:21 +0800 | [diff] [blame] | 338 | if (ptree == null) { |
| 339 | log.debug("lookupRib: ptree null"); |
| 340 | return null; |
| 341 | } |
| 342 | |
| 343 | PtreeNode node = ptree.match(dest, 32); |
| 344 | if (node == null) { |
| 345 | log.debug("lookupRib: ptree node null"); |
| 346 | return null; |
| 347 | } |
Jonathan Hart | 61ba937 | 2013-05-19 20:10:29 -0700 | [diff] [blame] | 348 | |
pingping-lin | a2cbfad | 2013-03-07 08:39:21 +0800 | [diff] [blame] | 349 | if (node.rib == null) { |
| 350 | log.debug("lookupRib: ptree rib null"); |
| 351 | return null; |
| 352 | } |
Jonathan Hart | 61ba937 | 2013-05-19 20:10:29 -0700 | [diff] [blame] | 353 | |
pingping-lin | a2cbfad | 2013-03-07 08:39:21 +0800 | [diff] [blame] | 354 | ptree.delReference(node); |
| 355 | |
| 356 | return node.rib; |
| 357 | } |
Jonathan Hart | d7e158d | 2013-08-07 23:04:48 +1200 | [diff] [blame] | 358 | */ |
pingping-lin | a2cbfad | 2013-03-07 08:39:21 +0800 | [diff] [blame] | 359 | |
Jonathan Hart | d7e158d | 2013-08-07 23:04:48 +1200 | [diff] [blame] | 360 | /* |
Jonathan Hart | 61ba937 | 2013-05-19 20:10:29 -0700 | [diff] [blame] | 361 | //TODO looks like this should be a unit test |
pingping-lin | a2cbfad | 2013-03-07 08:39:21 +0800 | [diff] [blame] | 362 | @SuppressWarnings("unused") |
Jonathan Hart | 61ba937 | 2013-05-19 20:10:29 -0700 | [diff] [blame] | 363 | private void test() throws UnknownHostException { |
pingping-lin | a2cbfad | 2013-03-07 08:39:21 +0800 | [diff] [blame] | 364 | System.out.println("Here it is"); |
| 365 | Prefix p = new Prefix("128.0.0.0", 8); |
| 366 | Prefix q = new Prefix("8.0.0.0", 8); |
| 367 | Prefix r = new Prefix("10.0.0.0", 24); |
| 368 | Prefix a = new Prefix("10.0.0.1", 32); |
| 369 | |
Jonathan Hart | d1b9d87 | 2013-07-23 12:17:21 +1200 | [diff] [blame] | 370 | ptree.acquire(p.getAddress(), p.getPrefixLength()); |
| 371 | ptree.acquire(q.getAddress(), q.getPrefixLength()); |
| 372 | ptree.acquire(r.getAddress(), r.getPrefixLength()); |
pingping-lin | a2cbfad | 2013-03-07 08:39:21 +0800 | [diff] [blame] | 373 | |
| 374 | System.out.println("Traverse start"); |
| 375 | for (PtreeNode node = ptree.begin(); node != null; node = ptree.next(node)) { |
| 376 | Prefix p_result = new Prefix(node.key, node.keyBits); |
| 377 | } |
| 378 | |
Jonathan Hart | d1b9d87 | 2013-07-23 12:17:21 +1200 | [diff] [blame] | 379 | PtreeNode n = ptree.match(a.getAddress(), a.getPrefixLength()); |
pingping-lin | a2cbfad | 2013-03-07 08:39:21 +0800 | [diff] [blame] | 380 | if (n != null) { |
| 381 | System.out.println("Matched prefix for 10.0.0.1:"); |
| 382 | Prefix x = new Prefix(n.key, n.keyBits); |
| 383 | ptree.delReference(n); |
| 384 | } |
| 385 | |
Jonathan Hart | d1b9d87 | 2013-07-23 12:17:21 +1200 | [diff] [blame] | 386 | n = ptree.lookup(p.getAddress(), p.getPrefixLength()); |
pingping-lin | a2cbfad | 2013-03-07 08:39:21 +0800 | [diff] [blame] | 387 | if (n != null) { |
| 388 | ptree.delReference(n); |
| 389 | ptree.delReference(n); |
| 390 | } |
| 391 | System.out.println("Traverse start"); |
| 392 | for (PtreeNode node = ptree.begin(); node != null; node = ptree.next(node)) { |
| 393 | Prefix p_result = new Prefix(node.key, node.keyBits); |
| 394 | } |
| 395 | |
Jonathan Hart | d1b9d87 | 2013-07-23 12:17:21 +1200 | [diff] [blame] | 396 | n = ptree.lookup(q.getAddress(), q.getPrefixLength()); |
pingping-lin | a2cbfad | 2013-03-07 08:39:21 +0800 | [diff] [blame] | 397 | if (n != null) { |
| 398 | ptree.delReference(n); |
| 399 | ptree.delReference(n); |
| 400 | } |
| 401 | System.out.println("Traverse start"); |
| 402 | for (PtreeNode node = ptree.begin(); node != null; node = ptree.next(node)) { |
| 403 | Prefix p_result = new Prefix(node.key, node.keyBits); |
| 404 | } |
| 405 | |
Jonathan Hart | d1b9d87 | 2013-07-23 12:17:21 +1200 | [diff] [blame] | 406 | n = ptree.lookup(r.getAddress(), r.getPrefixLength()); |
pingping-lin | a2cbfad | 2013-03-07 08:39:21 +0800 | [diff] [blame] | 407 | if (n != null) { |
| 408 | ptree.delReference(n); |
| 409 | ptree.delReference(n); |
| 410 | } |
| 411 | System.out.println("Traverse start"); |
| 412 | for (PtreeNode node = ptree.begin(); node != null; node = ptree.next(node)) { |
| 413 | Prefix p_result = new Prefix(node.key, node.keyBits); |
| 414 | } |
| 415 | |
| 416 | } |
Jonathan Hart | d7e158d | 2013-08-07 23:04:48 +1200 | [diff] [blame] | 417 | */ |
pingping-lin | a2cbfad | 2013-03-07 08:39:21 +0800 | [diff] [blame] | 418 | |
Jonathan Hart | df6ec33 | 2013-08-04 01:37:14 +1200 | [diff] [blame] | 419 | //TODO once the Ptree is object oriented this can go |
Jonathan Hart | 0a46fe4 | 2013-08-10 17:08:47 +1200 | [diff] [blame] | 420 | /* |
Jonathan Hart | 1236a9b | 2013-06-18 22:10:05 +1200 | [diff] [blame] | 421 | private String getPrefixFromPtree(PtreeNode node){ |
| 422 | InetAddress address = null; |
| 423 | try { |
| 424 | address = InetAddress.getByAddress(node.key); |
| 425 | } catch (UnknownHostException e1) { |
| 426 | //Should never happen is the reverse conversion has already been done |
| 427 | log.error("Malformed IP address"); |
| 428 | return ""; |
| 429 | } |
| 430 | return address.toString() + "/" + node.rib.masklen; |
| 431 | } |
Jonathan Hart | 0a46fe4 | 2013-08-10 17:08:47 +1200 | [diff] [blame] | 432 | */ |
Jonathan Hart | 1236a9b | 2013-06-18 22:10:05 +1200 | [diff] [blame] | 433 | |
Jonathan Hart | 61ba937 | 2013-05-19 20:10:29 -0700 | [diff] [blame] | 434 | private void retrieveRib(){ |
| 435 | String url = "http://" + bgpdRestIp + "/wm/bgp/" + routerId; |
| 436 | String response = RestClient.get(url); |
| 437 | |
| 438 | if (response.equals("")){ |
| 439 | return; |
| 440 | } |
| 441 | |
| 442 | response = response.replaceAll("\"", "'"); |
| 443 | JSONObject jsonObj = (JSONObject) JSONSerializer.toJSON(response); |
| 444 | JSONArray rib_json_array = jsonObj.getJSONArray("rib"); |
| 445 | String router_id = jsonObj.getString("router-id"); |
| 446 | |
| 447 | int size = rib_json_array.size(); |
| 448 | |
| 449 | log.info("Retrived RIB of {} entries from BGPd", size); |
| 450 | |
| 451 | for (int j = 0; j < size; j++) { |
| 452 | JSONObject second_json_object = rib_json_array.getJSONObject(j); |
| 453 | String prefix = second_json_object.getString("prefix"); |
| 454 | String nexthop = second_json_object.getString("nexthop"); |
| 455 | |
| 456 | //insert each rib entry into the local rib; |
| 457 | String[] substring = prefix.split("/"); |
| 458 | String prefix1 = substring[0]; |
| 459 | String mask1 = substring[1]; |
| 460 | |
| 461 | Prefix p; |
| 462 | try { |
| 463 | p = new Prefix(prefix1, Integer.valueOf(mask1)); |
| 464 | } catch (NumberFormatException e) { |
| 465 | log.warn("Wrong mask format in RIB JSON: {}", mask1); |
| 466 | continue; |
Jonathan Hart | 32e1822 | 2013-08-07 22:05:42 +1200 | [diff] [blame] | 467 | } catch (IllegalArgumentException e1) { |
Jonathan Hart | 61ba937 | 2013-05-19 20:10:29 -0700 | [diff] [blame] | 468 | log.warn("Wrong prefix format in RIB JSON: {}", prefix1); |
| 469 | continue; |
| 470 | } |
| 471 | |
Jonathan Hart | d7e158d | 2013-08-07 23:04:48 +1200 | [diff] [blame] | 472 | //PtreeNode node = ptree.acquire(p.getAddress(), p.getPrefixLength()); |
Jonathan Hart | b39a67d | 2013-08-10 23:59:50 +1200 | [diff] [blame] | 473 | RibEntry rib = new RibEntry(router_id, nexthop); |
Jonathan Hart | 61ba937 | 2013-05-19 20:10:29 -0700 | [diff] [blame] | 474 | |
Jonathan Hart | d7e158d | 2013-08-07 23:04:48 +1200 | [diff] [blame] | 475 | /* |
Jonathan Hart | 61ba937 | 2013-05-19 20:10:29 -0700 | [diff] [blame] | 476 | if (node.rib != null) { |
| 477 | node.rib = null; |
| 478 | ptree.delReference(node); |
| 479 | } |
| 480 | |
| 481 | node.rib = rib; |
Jonathan Hart | d7e158d | 2013-08-07 23:04:48 +1200 | [diff] [blame] | 482 | */ |
| 483 | |
Jonathan Hart | 0a46fe4 | 2013-08-10 17:08:47 +1200 | [diff] [blame] | 484 | //ptree.put(p, rib); |
Jonathan Hart | e7e1c6e | 2013-06-04 20:50:23 -0700 | [diff] [blame] | 485 | |
Jonathan Hart | 0a46fe4 | 2013-08-10 17:08:47 +1200 | [diff] [blame] | 486 | //addPrefixFlows(p, rib); |
| 487 | try { |
| 488 | ribUpdates.put(new RibUpdate(Operation.UPDATE, p, rib)); |
| 489 | } catch (InterruptedException e) { |
| 490 | log.debug("Interrupted while pushing onto update queue"); |
| 491 | } |
Jonathan Hart | 61ba937 | 2013-05-19 20:10:29 -0700 | [diff] [blame] | 492 | } |
| 493 | } |
| 494 | |
Jonathan Hart | 8b9349e | 2013-07-26 15:55:28 +1200 | [diff] [blame] | 495 | @Override |
| 496 | public void newRibUpdate(RibUpdate update) { |
Jonathan Hart | 9ea3121 | 2013-08-12 21:40:34 +1200 | [diff] [blame] | 497 | try { |
| 498 | ribUpdates.put(update); |
| 499 | } catch (InterruptedException e) { |
| 500 | // TODO Auto-generated catch block |
| 501 | log.debug(" ", e); |
| 502 | } |
Jonathan Hart | 8b9349e | 2013-07-26 15:55:28 +1200 | [diff] [blame] | 503 | } |
| 504 | |
Jonathan Hart | 0a46fe4 | 2013-08-10 17:08:47 +1200 | [diff] [blame] | 505 | public synchronized void processRibAdd(RibUpdate update) { |
Jonathan Hart | 8b9349e | 2013-07-26 15:55:28 +1200 | [diff] [blame] | 506 | Prefix prefix = update.getPrefix(); |
| 507 | |
Jonathan Hart | 9ea3121 | 2013-08-12 21:40:34 +1200 | [diff] [blame] | 508 | log.debug("Processing prefix add {}", prefix); |
| 509 | |
Jonathan Hart | d7e158d | 2013-08-07 23:04:48 +1200 | [diff] [blame] | 510 | //PtreeNode node = ptree.acquire(prefix.getAddress(), prefix.getPrefixLength()); |
Jonathan Hart | b39a67d | 2013-08-10 23:59:50 +1200 | [diff] [blame] | 511 | RibEntry rib = ptree.put(prefix, update.getRibEntry()); |
Jonathan Hart | 8b9349e | 2013-07-26 15:55:28 +1200 | [diff] [blame] | 512 | |
Jonathan Hart | d7e158d | 2013-08-07 23:04:48 +1200 | [diff] [blame] | 513 | //if (node.rib != null) { |
Jonathan Hart | 0a46fe4 | 2013-08-10 17:08:47 +1200 | [diff] [blame] | 514 | if (rib != null && !rib.equals(update.getRibEntry())) { |
Jonathan Hart | 2f74078 | 2013-08-04 00:49:21 +1200 | [diff] [blame] | 515 | //There was an existing nexthop for this prefix. This update supersedes that, |
| 516 | //so we need to remove the old flows for this prefix from the switches |
| 517 | deletePrefixFlows(prefix); |
| 518 | |
| 519 | //Then remove the old nexthop from the Ptree |
Jonathan Hart | d7e158d | 2013-08-07 23:04:48 +1200 | [diff] [blame] | 520 | //node.rib = null; |
| 521 | //ptree.delReference(node); |
Jonathan Hart | 8b9349e | 2013-07-26 15:55:28 +1200 | [diff] [blame] | 522 | } |
Jonathan Hart | 2f74078 | 2013-08-04 00:49:21 +1200 | [diff] [blame] | 523 | |
| 524 | //Put the new nexthop in the Ptree |
Jonathan Hart | d7e158d | 2013-08-07 23:04:48 +1200 | [diff] [blame] | 525 | //node.rib = update.getRibEntry(); |
Jonathan Hart | 8b9349e | 2013-07-26 15:55:28 +1200 | [diff] [blame] | 526 | |
Jonathan Hart | 2f74078 | 2013-08-04 00:49:21 +1200 | [diff] [blame] | 527 | //Push flows for the new <prefix, nexthop> |
Jonathan Hart | 2f74078 | 2013-08-04 00:49:21 +1200 | [diff] [blame] | 528 | addPrefixFlows(prefix, update.getRibEntry()); |
Jonathan Hart | 8b9349e | 2013-07-26 15:55:28 +1200 | [diff] [blame] | 529 | } |
| 530 | |
Jonathan Hart | 0a46fe4 | 2013-08-10 17:08:47 +1200 | [diff] [blame] | 531 | public synchronized void processRibDelete(RibUpdate update) { |
Jonathan Hart | 8b9349e | 2013-07-26 15:55:28 +1200 | [diff] [blame] | 532 | Prefix prefix = update.getPrefix(); |
| 533 | |
Jonathan Hart | d7e158d | 2013-08-07 23:04:48 +1200 | [diff] [blame] | 534 | //PtreeNode node = ptree.lookup(prefix.getAddress(), prefix.getPrefixLength()); |
Jonathan Hart | 8b9349e | 2013-07-26 15:55:28 +1200 | [diff] [blame] | 535 | |
| 536 | /* |
| 537 | * Remove the flows from the switches before the rib is lost |
| 538 | * Theory: we could get a delete for a prefix not in the Ptree. |
| 539 | * This would result in a null node being returned. We could get a delete for |
| 540 | * a node that's not actually there, but is a aggregate node. This would result |
| 541 | * in a non-null node with a null rib. Only a non-null node with a non-null |
| 542 | * rib is an actual prefix in the Ptree. |
| 543 | */ |
Jonathan Hart | 8b9349e | 2013-07-26 15:55:28 +1200 | [diff] [blame] | 544 | |
Jonathan Hart | d7e158d | 2013-08-07 23:04:48 +1200 | [diff] [blame] | 545 | /* |
Jonathan Hart | 8b9349e | 2013-07-26 15:55:28 +1200 | [diff] [blame] | 546 | if (node != null && node.rib != null) { |
| 547 | if (update.getRibEntry().equals(node.rib)) { |
| 548 | node.rib = null; |
Jonathan Hart | 0ee0f02 | 2013-08-03 22:21:54 +1200 | [diff] [blame] | 549 | ptree.delReference(node); |
| 550 | |
Jonathan Hart | 2f74078 | 2013-08-04 00:49:21 +1200 | [diff] [blame] | 551 | deletePrefixFlows(update.getPrefix()); |
Jonathan Hart | 8b9349e | 2013-07-26 15:55:28 +1200 | [diff] [blame] | 552 | } |
| 553 | } |
Jonathan Hart | d7e158d | 2013-08-07 23:04:48 +1200 | [diff] [blame] | 554 | */ |
| 555 | |
| 556 | if (ptree.remove(prefix, update.getRibEntry())) { |
| 557 | /* |
| 558 | * Only delete flows if an entry was actually removed from the trie. |
| 559 | * If no entry was removed, the <prefix, nexthop> wasn't there so |
| 560 | * it's probably already been removed and we don't need to do anything |
| 561 | */ |
| 562 | deletePrefixFlows(prefix); |
| 563 | } |
Jonathan Hart | 8b9349e | 2013-07-26 15:55:28 +1200 | [diff] [blame] | 564 | } |
| 565 | |
Jonathan Hart | 2f74078 | 2013-08-04 00:49:21 +1200 | [diff] [blame] | 566 | //TODO compatibility layer, used by beginRouting() |
Jonathan Hart | d7e158d | 2013-08-07 23:04:48 +1200 | [diff] [blame] | 567 | /*public void prefixAdded(PtreeNode node) { |
Jonathan Hart | 0ee0f02 | 2013-08-03 22:21:54 +1200 | [diff] [blame] | 568 | Prefix prefix = null; |
| 569 | try { |
| 570 | prefix = new Prefix(node.key, node.rib.masklen); |
Jonathan Hart | 32e1822 | 2013-08-07 22:05:42 +1200 | [diff] [blame] | 571 | } catch (IllegalArgumentException e) { |
Jonathan Hart | 0ee0f02 | 2013-08-03 22:21:54 +1200 | [diff] [blame] | 572 | log.error(" ", e); |
| 573 | } |
Jonathan Hart | df6ec33 | 2013-08-04 01:37:14 +1200 | [diff] [blame] | 574 | |
Jonathan Hart | 2f74078 | 2013-08-04 00:49:21 +1200 | [diff] [blame] | 575 | addPrefixFlows(prefix, node.rib); |
Jonathan Hart | d7e158d | 2013-08-07 23:04:48 +1200 | [diff] [blame] | 576 | }*/ |
Jonathan Hart | 0ee0f02 | 2013-08-03 22:21:54 +1200 | [diff] [blame] | 577 | |
Jonathan Hart | b39a67d | 2013-08-10 23:59:50 +1200 | [diff] [blame] | 578 | private void addPrefixFlows(Prefix prefix, RibEntry rib) { |
Jonathan Hart | 1236a9b | 2013-06-18 22:10:05 +1200 | [diff] [blame] | 579 | if (!topologyReady){ |
| 580 | return; |
| 581 | } |
| 582 | |
Jonathan Hart | 0ee0f02 | 2013-08-03 22:21:54 +1200 | [diff] [blame] | 583 | //TODO before we do anything, we have to check that the RIB entry is still in the |
| 584 | //Ptree because it could have been removed while we were waiting for ARP. |
| 585 | //I think we'll have to make prefixAdded and prefixDelete atomic as well |
| 586 | //to protect against the prefix getting deleted while where trying to add it |
Jonathan Hart | 2f74078 | 2013-08-04 00:49:21 +1200 | [diff] [blame] | 587 | |
Jonathan Hart | b39a67d | 2013-08-10 23:59:50 +1200 | [diff] [blame] | 588 | log.debug("New prefix {} added, next hop {}", |
| 589 | prefix, rib.getNextHop().getHostAddress()); |
Jonathan Hart | 1236a9b | 2013-06-18 22:10:05 +1200 | [diff] [blame] | 590 | |
Jonathan Hart | c824ad0 | 2013-07-03 15:58:45 +1200 | [diff] [blame] | 591 | //TODO this is wrong, we shouldn't be dealing with BGP peers here. |
Jonathan Hart | 6261dcd | 2013-07-22 17:58:35 +1200 | [diff] [blame] | 592 | //We need to figure out where the device is attached and what its |
Jonathan Hart | c824ad0 | 2013-07-03 15:58:45 +1200 | [diff] [blame] | 593 | //mac address is by learning. |
| 594 | //The next hop is not necessarily the peer, and the peer's attachment |
| 595 | //point is not necessarily the next hop's attachment point. |
Jonathan Hart | b39a67d | 2013-08-10 23:59:50 +1200 | [diff] [blame] | 596 | BgpPeer peer = bgpPeers.get(rib.getNextHop()); |
Jonathan Hart | e7e1c6e | 2013-06-04 20:50:23 -0700 | [diff] [blame] | 597 | |
Jonathan Hart | c824ad0 | 2013-07-03 15:58:45 +1200 | [diff] [blame] | 598 | if (peer == null){ |
| 599 | //TODO local router isn't in peers list so this will get thrown |
Jonathan Hart | 50a8d1e | 2013-06-06 16:00:47 +1200 | [diff] [blame] | 600 | //Need to work out what to do about local prefixes with next hop 0.0.0.0. |
Jonathan Hart | c824ad0 | 2013-07-03 15:58:45 +1200 | [diff] [blame] | 601 | |
| 602 | //The other scenario is this is a route server route. In that |
| 603 | //case the next hop is not in our configuration |
Jonathan Hart | 0ee0f02 | 2013-08-03 22:21:54 +1200 | [diff] [blame] | 604 | log.error("Couldn't find next hop router in router {} in config", |
Jonathan Hart | b39a67d | 2013-08-10 23:59:50 +1200 | [diff] [blame] | 605 | rib.getNextHop().getHostAddress()); |
Jonathan Hart | e7e1c6e | 2013-06-04 20:50:23 -0700 | [diff] [blame] | 606 | return; //just quit out here? This is probably a configuration error |
| 607 | } |
Jonathan Hart | c824ad0 | 2013-07-03 15:58:45 +1200 | [diff] [blame] | 608 | |
Jonathan Hart | 0ee0f02 | 2013-08-03 22:21:54 +1200 | [diff] [blame] | 609 | //Get MAC address for peer from the ARP module |
| 610 | //TODO separate out the 'ask for MAC' bit to another method |
| 611 | byte[] peerMacAddress = proxyArp.getMacAddress(peer.getIpAddress()); |
| 612 | if (peerMacAddress == null) { |
Jonathan Hart | 2f74078 | 2013-08-04 00:49:21 +1200 | [diff] [blame] | 613 | //A RibUpdate is still a nice way to package them up |
| 614 | prefixesWaitingOnArp.put(peer.getIpAddress(), |
| 615 | new RibUpdate(Operation.UPDATE, prefix, rib)); |
Jonathan Hart | 0ee0f02 | 2013-08-03 22:21:54 +1200 | [diff] [blame] | 616 | proxyArp.sendArpRequest(peer.getIpAddress(), this, true); |
| 617 | return; |
| 618 | } |
| 619 | |
Jonathan Hart | c824ad0 | 2013-07-03 15:58:45 +1200 | [diff] [blame] | 620 | Interface peerInterface = interfaces.get(peer.getInterfaceName()); |
Jonathan Hart | 50a8d1e | 2013-06-06 16:00:47 +1200 | [diff] [blame] | 621 | |
Jonathan Hart | c824ad0 | 2013-07-03 15:58:45 +1200 | [diff] [blame] | 622 | //Add a flow to rewrite mac for this prefix to all border switches |
| 623 | for (Interface srcInterface : interfaces.values()) { |
| 624 | if (srcInterface == peerInterface) { |
| 625 | //Don't push a flow for the switch where this peer is attached |
Jonathan Hart | e7e1c6e | 2013-06-04 20:50:23 -0700 | [diff] [blame] | 626 | continue; |
| 627 | } |
Jonathan Hart | c824ad0 | 2013-07-03 15:58:45 +1200 | [diff] [blame] | 628 | |
Jonathan Hart | e7e1c6e | 2013-06-04 20:50:23 -0700 | [diff] [blame] | 629 | DataPath shortestPath = topoRouteService.getShortestPath( |
Jonathan Hart | c824ad0 | 2013-07-03 15:58:45 +1200 | [diff] [blame] | 630 | srcInterface.getSwitchPort(), |
| 631 | peerInterface.getSwitchPort()); |
Jonathan Hart | e7e1c6e | 2013-06-04 20:50:23 -0700 | [diff] [blame] | 632 | |
| 633 | if (shortestPath == null){ |
| 634 | log.debug("Shortest path between {} and {} not found", |
Jonathan Hart | c824ad0 | 2013-07-03 15:58:45 +1200 | [diff] [blame] | 635 | srcInterface.getSwitchPort(), |
| 636 | peerInterface.getSwitchPort()); |
Jonathan Hart | e7e1c6e | 2013-06-04 20:50:23 -0700 | [diff] [blame] | 637 | return; // just quit here? |
| 638 | } |
| 639 | |
Jonathan Hart | e7e1c6e | 2013-06-04 20:50:23 -0700 | [diff] [blame] | 640 | //Set up the flow mod |
| 641 | OFFlowMod fm = |
| 642 | (OFFlowMod) floodlightProvider.getOFMessageFactory() |
| 643 | .getMessage(OFType.FLOW_MOD); |
| 644 | |
| 645 | fm.setIdleTimeout((short)0) |
| 646 | .setHardTimeout((short)0) |
| 647 | .setBufferId(OFPacketOut.BUFFER_ID_NONE) |
| 648 | .setCookie(MAC_RW_COOKIE) |
| 649 | .setCommand(OFFlowMod.OFPFC_ADD) |
Jonathan Hart | 50a8d1e | 2013-06-06 16:00:47 +1200 | [diff] [blame] | 650 | .setPriority(SDNIP_PRIORITY) |
Jonathan Hart | e7e1c6e | 2013-06-04 20:50:23 -0700 | [diff] [blame] | 651 | .setLengthU(OFFlowMod.MINIMUM_LENGTH |
| 652 | + OFActionDataLayerDestination.MINIMUM_LENGTH |
| 653 | + OFActionOutput.MINIMUM_LENGTH); |
| 654 | |
| 655 | OFMatch match = new OFMatch(); |
| 656 | match.setDataLayerType(Ethernet.TYPE_IPv4); |
Jonathan Hart | 50a8d1e | 2013-06-06 16:00:47 +1200 | [diff] [blame] | 657 | match.setWildcards(match.getWildcards() & ~OFMatch.OFPFW_DL_TYPE); |
Jonathan Hart | e7e1c6e | 2013-06-04 20:50:23 -0700 | [diff] [blame] | 658 | |
Jonathan Hart | 0a46fe4 | 2013-08-10 17:08:47 +1200 | [diff] [blame] | 659 | /* |
Jonathan Hart | 50a8d1e | 2013-06-06 16:00:47 +1200 | [diff] [blame] | 660 | InetAddress address = null; |
| 661 | try { |
Jonathan Hart | 2f74078 | 2013-08-04 00:49:21 +1200 | [diff] [blame] | 662 | address = InetAddress.getByAddress(prefix.getAddress()); |
Jonathan Hart | 50a8d1e | 2013-06-06 16:00:47 +1200 | [diff] [blame] | 663 | } catch (UnknownHostException e1) { |
| 664 | //Should never happen is the reverse conversion has already been done |
| 665 | log.error("Malformed IP address"); |
| 666 | return; |
Jonathan Hart | 0a46fe4 | 2013-08-10 17:08:47 +1200 | [diff] [blame] | 667 | }*/ |
Jonathan Hart | 50a8d1e | 2013-06-06 16:00:47 +1200 | [diff] [blame] | 668 | |
Jonathan Hart | 0a46fe4 | 2013-08-10 17:08:47 +1200 | [diff] [blame] | 669 | //match.setFromCIDR(address.getHostAddress() + "/" + |
| 670 | // prefix.getPrefixLength(), OFMatch.STR_NW_DST); |
| 671 | match.setFromCIDR(prefix.toString(), OFMatch.STR_NW_DST); |
Jonathan Hart | 50a8d1e | 2013-06-06 16:00:47 +1200 | [diff] [blame] | 672 | fm.setMatch(match); |
Jonathan Hart | e7e1c6e | 2013-06-04 20:50:23 -0700 | [diff] [blame] | 673 | |
| 674 | //Set up MAC rewrite action |
| 675 | OFActionDataLayerDestination macRewriteAction = new OFActionDataLayerDestination(); |
Jonathan Hart | c824ad0 | 2013-07-03 15:58:45 +1200 | [diff] [blame] | 676 | //TODO the peer's mac address is not necessarily the next hop's... |
Jonathan Hart | 0ee0f02 | 2013-08-03 22:21:54 +1200 | [diff] [blame] | 677 | macRewriteAction.setDataLayerAddress(peerMacAddress); |
Jonathan Hart | e7e1c6e | 2013-06-04 20:50:23 -0700 | [diff] [blame] | 678 | |
| 679 | //Set up output action |
| 680 | OFActionOutput outputAction = new OFActionOutput(); |
Jonathan Hart | 832a7cb | 2013-06-24 11:25:35 +1200 | [diff] [blame] | 681 | outputAction.setMaxLength((short)0xffff); |
Jonathan Hart | e7e1c6e | 2013-06-04 20:50:23 -0700 | [diff] [blame] | 682 | |
Jonathan Hart | 50a8d1e | 2013-06-06 16:00:47 +1200 | [diff] [blame] | 683 | Port outputPort = shortestPath.flowEntries().get(0).outPort(); |
| 684 | outputAction.setPort(outputPort.value()); |
| 685 | |
Jonathan Hart | e7e1c6e | 2013-06-04 20:50:23 -0700 | [diff] [blame] | 686 | List<OFAction> actions = new ArrayList<OFAction>(); |
| 687 | actions.add(macRewriteAction); |
| 688 | actions.add(outputAction); |
| 689 | fm.setActions(actions); |
| 690 | |
| 691 | //Write to switch |
| 692 | IOFSwitch sw = floodlightProvider.getSwitches() |
Jonathan Hart | c824ad0 | 2013-07-03 15:58:45 +1200 | [diff] [blame] | 693 | .get(srcInterface.getDpid()); |
Jonathan Hart | e7e1c6e | 2013-06-04 20:50:23 -0700 | [diff] [blame] | 694 | |
| 695 | if (sw == null){ |
| 696 | log.warn("Switch not found when pushing flow mod"); |
| 697 | continue; |
| 698 | } |
| 699 | |
Jonathan Hart | 0ee0f02 | 2013-08-03 22:21:54 +1200 | [diff] [blame] | 700 | //TODO if prefix Added/Deleted are synchronized this shouldn't have to be |
Jonathan Hart | 2f74078 | 2013-08-04 00:49:21 +1200 | [diff] [blame] | 701 | pushedFlows.put(prefix, new PushedFlowMod(sw.getId(), fm)); |
Jonathan Hart | 0ee0f02 | 2013-08-03 22:21:54 +1200 | [diff] [blame] | 702 | |
Jonathan Hart | e7e1c6e | 2013-06-04 20:50:23 -0700 | [diff] [blame] | 703 | List<OFMessage> msglist = new ArrayList<OFMessage>(); |
| 704 | msglist.add(fm); |
| 705 | try { |
| 706 | sw.write(msglist, null); |
| 707 | sw.flush(); |
| 708 | } catch (IOException e) { |
| 709 | log.error("Failure writing flow mod", e); |
| 710 | } |
| 711 | } |
| 712 | } |
| 713 | |
Jonathan Hart | 0ee0f02 | 2013-08-03 22:21:54 +1200 | [diff] [blame] | 714 | //TODO test next-hop changes |
Jonathan Hart | 2f74078 | 2013-08-04 00:49:21 +1200 | [diff] [blame] | 715 | //TODO check delete/add synchronization |
Jonathan Hart | 2f74078 | 2013-08-04 00:49:21 +1200 | [diff] [blame] | 716 | |
| 717 | private void deletePrefixFlows(Prefix prefix) { |
Jonathan Hart | 0ee0f02 | 2013-08-03 22:21:54 +1200 | [diff] [blame] | 718 | if (!topologyReady) { |
| 719 | return; |
| 720 | } |
| 721 | |
Jonathan Hart | df6ec33 | 2013-08-04 01:37:14 +1200 | [diff] [blame] | 722 | log.debug("In deletePrefixFlows for {}", prefix); |
Jonathan Hart | 2f74078 | 2013-08-04 00:49:21 +1200 | [diff] [blame] | 723 | |
| 724 | /*for (Map.Entry<Prefix, PushedFlowMod> entry : pushedFlows.entries()) { |
| 725 | log.debug("Pushed flow: {} => {}", entry.getKey(), entry.getValue()); |
| 726 | }*/ |
Jonathan Hart | 0ee0f02 | 2013-08-03 22:21:54 +1200 | [diff] [blame] | 727 | |
| 728 | Collection<PushedFlowMod> pushedFlowMods |
Jonathan Hart | 2f74078 | 2013-08-04 00:49:21 +1200 | [diff] [blame] | 729 | = pushedFlows.removeAll(prefix); |
Jonathan Hart | 0ee0f02 | 2013-08-03 22:21:54 +1200 | [diff] [blame] | 730 | |
| 731 | for (PushedFlowMod pfm : pushedFlowMods) { |
| 732 | log.debug("Pushing a DELETE flow mod to {}, matches prefix {} with mac-rewrite {}", |
| 733 | new Object[] {HexString.toHexString(pfm.getDpid()), |
| 734 | pfm.getFlowMod().getMatch().getNetworkDestination() + |
| 735 | pfm.getFlowMod().getMatch().getNetworkDestinationMaskLen(), |
| 736 | HexString.toHexString(((OFActionDataLayerDestination)pfm.getFlowMod().getActions().get(0)) |
| 737 | .getDataLayerAddress())}); |
| 738 | |
| 739 | OFFlowMod fm = pfm.getFlowMod(); |
| 740 | |
| 741 | fm.setCommand(OFFlowMod.OFPFC_DELETE) |
Jonathan Hart | 2f74078 | 2013-08-04 00:49:21 +1200 | [diff] [blame] | 742 | .setOutPort(OFPort.OFPP_NONE) |
Jonathan Hart | 0ee0f02 | 2013-08-03 22:21:54 +1200 | [diff] [blame] | 743 | .setLengthU(OFFlowMod.MINIMUM_LENGTH); |
| 744 | |
| 745 | fm.getActions().clear(); |
| 746 | |
| 747 | IOFSwitch sw = floodlightProvider.getSwitches().get(pfm.getDpid()); |
| 748 | if (sw == null) { |
| 749 | log.warn("Switch not found when pushing delete flow mod"); |
| 750 | continue; |
| 751 | } |
| 752 | |
| 753 | try { |
| 754 | sw.write(fm, null); |
| 755 | sw.flush(); |
| 756 | } catch (IOException e) { |
| 757 | log.error("Failure writing flow mod", e); |
| 758 | } |
| 759 | } |
| 760 | } |
| 761 | |
Jonathan Hart | e7e1c6e | 2013-06-04 20:50:23 -0700 | [diff] [blame] | 762 | /* |
| 763 | * On startup we need to calculate a full mesh of paths between all gateway |
| 764 | * switches |
| 765 | */ |
Jonathan Hart | 1236a9b | 2013-06-18 22:10:05 +1200 | [diff] [blame] | 766 | private void setupFullMesh(){ |
Jonathan Hart | e7e1c6e | 2013-06-04 20:50:23 -0700 | [diff] [blame] | 767 | //For each border router, calculate and install a path from every other |
| 768 | //border switch to said border router. However, don't install the entry |
| 769 | //in to the first hop switch, as we need to install an entry to rewrite |
| 770 | //for each prefix received. This will be done later when prefixes have |
| 771 | //actually been received. |
| 772 | |
Jonathan Hart | c824ad0 | 2013-07-03 15:58:45 +1200 | [diff] [blame] | 773 | for (BgpPeer peer : bgpPeers.values()) { |
| 774 | Interface peerInterface = interfaces.get(peer.getInterfaceName()); |
Jonathan Hart | 4dfc365 | 2013-08-02 20:22:36 +1200 | [diff] [blame] | 775 | |
| 776 | //See if we know the MAC address of the peer. If not we can't |
| 777 | //do anything until we learn it |
| 778 | byte[] mac = proxyArp.getMacAddress(peer.getIpAddress()); |
| 779 | if (mac == null) { |
| 780 | log.debug("Don't know MAC for {}", peer.getIpAddress().getHostAddress()); |
| 781 | //Put in the pending paths list first |
| 782 | pathsWaitingOnArp.put(peer.getIpAddress(), |
| 783 | new PathUpdate(peerInterface, peer.getIpAddress())); |
Jonathan Hart | e7e1c6e | 2013-06-04 20:50:23 -0700 | [diff] [blame] | 784 | |
Jonathan Hart | 4dfc365 | 2013-08-02 20:22:36 +1200 | [diff] [blame] | 785 | proxyArp.sendArpRequest(peer.getIpAddress(), this, true); |
| 786 | continue; |
Jonathan Hart | e7e1c6e | 2013-06-04 20:50:23 -0700 | [diff] [blame] | 787 | } |
Jonathan Hart | 4dfc365 | 2013-08-02 20:22:36 +1200 | [diff] [blame] | 788 | |
| 789 | //If we know the MAC, lets go ahead and push the paths to this peer |
| 790 | calculateAndPushPath(peerInterface, MACAddress.valueOf(mac)); |
Jonathan Hart | e7e1c6e | 2013-06-04 20:50:23 -0700 | [diff] [blame] | 791 | } |
| 792 | } |
| 793 | |
Jonathan Hart | 4dfc365 | 2013-08-02 20:22:36 +1200 | [diff] [blame] | 794 | private void calculateAndPushPath(Interface dstInterface, MACAddress dstMacAddress) { |
| 795 | for (Interface srcInterface : interfaces.values()) { |
| 796 | if (dstInterface.equals(srcInterface.getName())){ |
| 797 | continue; |
| 798 | } |
| 799 | |
| 800 | DataPath shortestPath = topoRouteService.getShortestPath( |
| 801 | srcInterface.getSwitchPort(), dstInterface.getSwitchPort()); |
| 802 | |
| 803 | if (shortestPath == null){ |
| 804 | log.debug("Shortest path between {} and {} not found", |
| 805 | srcInterface.getSwitchPort(), dstInterface.getSwitchPort()); |
| 806 | return; // just quit here? |
| 807 | } |
| 808 | |
Jonathan Hart | 4dfc365 | 2013-08-02 20:22:36 +1200 | [diff] [blame] | 809 | installPath(shortestPath.flowEntries(), dstMacAddress); |
| 810 | } |
| 811 | } |
| 812 | |
| 813 | private void installPath(List<FlowEntry> flowEntries, MACAddress dstMacAddress){ |
Jonathan Hart | e7e1c6e | 2013-06-04 20:50:23 -0700 | [diff] [blame] | 814 | //Set up the flow mod |
| 815 | OFFlowMod fm = |
| 816 | (OFFlowMod) floodlightProvider.getOFMessageFactory() |
| 817 | .getMessage(OFType.FLOW_MOD); |
| 818 | |
| 819 | OFActionOutput action = new OFActionOutput(); |
| 820 | action.setMaxLength((short)0xffff); |
| 821 | List<OFAction> actions = new ArrayList<OFAction>(); |
| 822 | actions.add(action); |
| 823 | |
| 824 | fm.setIdleTimeout((short)0) |
| 825 | .setHardTimeout((short)0) |
| 826 | .setBufferId(OFPacketOut.BUFFER_ID_NONE) |
| 827 | .setCookie(L2_FWD_COOKIE) |
| 828 | .setCommand(OFFlowMod.OFPFC_ADD) |
Jonathan Hart | e7e1c6e | 2013-06-04 20:50:23 -0700 | [diff] [blame] | 829 | .setActions(actions) |
| 830 | .setLengthU(OFFlowMod.MINIMUM_LENGTH+OFActionOutput.MINIMUM_LENGTH); |
| 831 | |
| 832 | //Don't push the first flow entry. We need to push entries in the |
| 833 | //first switch based on IP prefix which we don't know yet. |
| 834 | for (int i = 1; i < flowEntries.size(); i++){ |
| 835 | FlowEntry flowEntry = flowEntries.get(i); |
| 836 | |
| 837 | OFMatch match = new OFMatch(); |
Jonathan Hart | c824ad0 | 2013-07-03 15:58:45 +1200 | [diff] [blame] | 838 | //TODO Again using MAC address from configuration |
Jonathan Hart | 4dfc365 | 2013-08-02 20:22:36 +1200 | [diff] [blame] | 839 | match.setDataLayerDestination(dstMacAddress.toBytes()); |
Jonathan Hart | e7e1c6e | 2013-06-04 20:50:23 -0700 | [diff] [blame] | 840 | match.setWildcards(match.getWildcards() & ~OFMatch.OFPFW_DL_DST); |
| 841 | ((OFActionOutput) fm.getActions().get(0)).setPort(flowEntry.outPort().value()); |
| 842 | |
| 843 | fm.setMatch(match); |
| 844 | |
| 845 | IOFSwitch sw = floodlightProvider.getSwitches().get(flowEntry.dpid().value()); |
| 846 | |
| 847 | if (sw == null){ |
| 848 | log.warn("Switch not found when pushing flow mod"); |
| 849 | continue; |
| 850 | } |
| 851 | |
| 852 | List<OFMessage> msglist = new ArrayList<OFMessage>(); |
| 853 | msglist.add(fm); |
| 854 | try { |
| 855 | sw.write(msglist, null); |
| 856 | sw.flush(); |
| 857 | } catch (IOException e) { |
| 858 | log.error("Failure writing flow mod", e); |
| 859 | } |
| 860 | |
| 861 | try { |
| 862 | fm = fm.clone(); |
| 863 | } catch (CloneNotSupportedException e1) { |
| 864 | log.error("Failure cloning flow mod", e1); |
| 865 | } |
| 866 | } |
| 867 | } |
| 868 | |
Jonathan Hart | 832a7cb | 2013-06-24 11:25:35 +1200 | [diff] [blame] | 869 | private void setupBgpPaths(){ |
Jonathan Hart | c824ad0 | 2013-07-03 15:58:45 +1200 | [diff] [blame] | 870 | for (BgpPeer bgpPeer : bgpPeers.values()){ |
Jonathan Hart | 832a7cb | 2013-06-24 11:25:35 +1200 | [diff] [blame] | 871 | Interface peerInterface = interfaces.get(bgpPeer.getInterfaceName()); |
| 872 | |
| 873 | DataPath path = topoRouteService.getShortestPath( |
| 874 | peerInterface.getSwitchPort(), bgpdAttachmentPoint); |
| 875 | |
| 876 | if (path == null){ |
| 877 | log.debug("Unable to compute path for BGP traffic for {}", |
| 878 | bgpPeer.getIpAddress()); |
| 879 | continue; |
| 880 | } |
| 881 | |
| 882 | //Set up the flow mod |
| 883 | OFFlowMod fm = |
| 884 | (OFFlowMod) floodlightProvider.getOFMessageFactory() |
| 885 | .getMessage(OFType.FLOW_MOD); |
| 886 | |
| 887 | OFActionOutput action = new OFActionOutput(); |
| 888 | action.setMaxLength((short)0xffff); |
| 889 | List<OFAction> actions = new ArrayList<OFAction>(); |
| 890 | actions.add(action); |
| 891 | |
| 892 | fm.setIdleTimeout((short)0) |
| 893 | .setHardTimeout((short)0) |
| 894 | .setBufferId(OFPacketOut.BUFFER_ID_NONE) |
| 895 | .setCookie(BGP_COOKIE) |
| 896 | .setCommand(OFFlowMod.OFPFC_ADD) |
| 897 | .setPriority(SDNIP_PRIORITY) |
| 898 | .setActions(actions) |
| 899 | .setLengthU(OFFlowMod.MINIMUM_LENGTH+OFActionOutput.MINIMUM_LENGTH); |
| 900 | |
| 901 | //Forward = gateway -> bgpd, reverse = bgpd -> gateway |
| 902 | OFMatch forwardMatchSrc = new OFMatch(); |
| 903 | |
Jonathan Hart | 832a7cb | 2013-06-24 11:25:35 +1200 | [diff] [blame] | 904 | String interfaceCidrAddress = peerInterface.getIpAddress().getHostAddress() |
| 905 | + "/32"; |
| 906 | String peerCidrAddress = bgpPeer.getIpAddress().getHostAddress() |
| 907 | + "/32"; |
Jonathan Hart | 38c8493 | 2013-08-10 17:49:27 +1200 | [diff] [blame] | 908 | |
Jonathan Hart | 832a7cb | 2013-06-24 11:25:35 +1200 | [diff] [blame] | 909 | //Common match fields |
| 910 | forwardMatchSrc.setDataLayerType(Ethernet.TYPE_IPv4); |
| 911 | //forwardMatch.setWildcards(forwardMatch.getWildcards() & ~OFMatch.OFPFW_DL_TYPE); |
| 912 | forwardMatchSrc.setNetworkProtocol(IPv4.PROTOCOL_TCP); |
| 913 | forwardMatchSrc.setTransportDestination(BGP_PORT); |
| 914 | forwardMatchSrc.setWildcards(forwardMatchSrc.getWildcards() & ~OFMatch.OFPFW_IN_PORT |
| 915 | & ~OFMatch.OFPFW_DL_TYPE & ~OFMatch.OFPFW_NW_PROTO); |
| 916 | |
| 917 | |
| 918 | OFMatch reverseMatchSrc = forwardMatchSrc.clone(); |
| 919 | |
| 920 | forwardMatchSrc.setFromCIDR(peerCidrAddress, OFMatch.STR_NW_SRC); |
| 921 | forwardMatchSrc.setFromCIDR(interfaceCidrAddress, OFMatch.STR_NW_DST); |
| 922 | |
| 923 | OFMatch forwardMatchDst = forwardMatchSrc.clone(); |
| 924 | |
| 925 | forwardMatchSrc.setTransportSource(BGP_PORT); |
| 926 | forwardMatchSrc.setWildcards(forwardMatchSrc.getWildcards() & ~OFMatch.OFPFW_TP_SRC); |
| 927 | forwardMatchDst.setTransportDestination(BGP_PORT); |
| 928 | forwardMatchDst.setWildcards(forwardMatchDst.getWildcards() & ~OFMatch.OFPFW_TP_DST); |
| 929 | |
| 930 | reverseMatchSrc.setFromCIDR(interfaceCidrAddress, OFMatch.STR_NW_SRC); |
| 931 | reverseMatchSrc.setFromCIDR(peerCidrAddress, OFMatch.STR_NW_DST); |
| 932 | |
| 933 | OFMatch reverseMatchDst = reverseMatchSrc.clone(); |
| 934 | |
| 935 | reverseMatchSrc.setTransportSource(BGP_PORT); |
| 936 | reverseMatchSrc.setWildcards(forwardMatchSrc.getWildcards() & ~OFMatch.OFPFW_TP_SRC); |
| 937 | reverseMatchDst.setTransportDestination(BGP_PORT); |
| 938 | reverseMatchDst.setWildcards(forwardMatchDst.getWildcards() & ~OFMatch.OFPFW_TP_DST); |
| 939 | |
| 940 | fm.setMatch(forwardMatchSrc); |
| 941 | |
Jonathan Hart | 38c8493 | 2013-08-10 17:49:27 +1200 | [diff] [blame] | 942 | OFMatch forwardIcmpMatch = new OFMatch(); |
| 943 | forwardIcmpMatch.setDataLayerType(Ethernet.TYPE_IPv4); |
| 944 | forwardIcmpMatch.setNetworkProtocol(IPv4.PROTOCOL_ICMP); |
| 945 | forwardIcmpMatch.setWildcards(forwardIcmpMatch.getWildcards() & |
| 946 | ~OFMatch.OFPFW_DL_TYPE & ~OFMatch.OFPFW_NW_PROTO); |
| 947 | |
| 948 | OFMatch reverseIcmpMatch = forwardIcmpMatch.clone(); |
| 949 | forwardIcmpMatch.setFromCIDR(interfaceCidrAddress, OFMatch.STR_NW_DST); |
| 950 | reverseIcmpMatch.setFromCIDR(interfaceCidrAddress, OFMatch.STR_NW_SRC); |
| 951 | |
Jonathan Hart | 832a7cb | 2013-06-24 11:25:35 +1200 | [diff] [blame] | 952 | for (FlowEntry flowEntry : path.flowEntries()){ |
| 953 | OFFlowMod forwardFlowModSrc, forwardFlowModDst; |
| 954 | OFFlowMod reverseFlowModSrc, reverseFlowModDst; |
Jonathan Hart | 38c8493 | 2013-08-10 17:49:27 +1200 | [diff] [blame] | 955 | OFFlowMod forwardIcmp, reverseIcmp; |
Jonathan Hart | 832a7cb | 2013-06-24 11:25:35 +1200 | [diff] [blame] | 956 | try { |
| 957 | forwardFlowModSrc = fm.clone(); |
| 958 | forwardFlowModDst = fm.clone(); |
| 959 | reverseFlowModSrc = fm.clone(); |
| 960 | reverseFlowModDst = fm.clone(); |
Jonathan Hart | 38c8493 | 2013-08-10 17:49:27 +1200 | [diff] [blame] | 961 | forwardIcmp = fm.clone(); |
| 962 | reverseIcmp = fm.clone(); |
Jonathan Hart | 832a7cb | 2013-06-24 11:25:35 +1200 | [diff] [blame] | 963 | } catch (CloneNotSupportedException e) { |
| 964 | log.warn("Clone failed", e); |
| 965 | continue; |
| 966 | } |
| 967 | |
| 968 | forwardMatchSrc.setInputPort(flowEntry.inPort().value()); |
| 969 | forwardFlowModSrc.setMatch(forwardMatchSrc); |
| 970 | ((OFActionOutput)forwardFlowModSrc.getActions().get(0)) |
| 971 | .setPort(flowEntry.outPort().value()); |
| 972 | |
| 973 | forwardMatchDst.setInputPort(flowEntry.inPort().value()); |
| 974 | forwardFlowModDst.setMatch(forwardMatchDst); |
| 975 | ((OFActionOutput)forwardFlowModDst.getActions().get(0)) |
| 976 | .setPort(flowEntry.outPort().value()); |
| 977 | |
| 978 | reverseMatchSrc.setInputPort(flowEntry.outPort().value()); |
| 979 | reverseFlowModSrc.setMatch(reverseMatchSrc); |
| 980 | ((OFActionOutput)reverseFlowModSrc.getActions().get(0)) |
| 981 | .setPort(flowEntry.inPort().value()); |
| 982 | |
| 983 | reverseMatchDst.setInputPort(flowEntry.outPort().value()); |
| 984 | reverseFlowModDst.setMatch(reverseMatchDst); |
| 985 | ((OFActionOutput)reverseFlowModDst.getActions().get(0)) |
| 986 | .setPort(flowEntry.inPort().value()); |
| 987 | |
Jonathan Hart | 38c8493 | 2013-08-10 17:49:27 +1200 | [diff] [blame] | 988 | ((OFActionOutput)forwardIcmp.getActions().get(0)) |
| 989 | .setPort(flowEntry.outPort().value()); |
| 990 | forwardIcmp.setMatch(forwardIcmpMatch); |
| 991 | |
| 992 | ((OFActionOutput)reverseIcmp.getActions().get(0)) |
| 993 | .setPort(flowEntry.inPort().value()); |
| 994 | reverseIcmp.setMatch(reverseIcmpMatch); |
| 995 | |
| 996 | |
Jonathan Hart | 832a7cb | 2013-06-24 11:25:35 +1200 | [diff] [blame] | 997 | IOFSwitch sw = floodlightProvider.getSwitches().get(flowEntry.dpid().value()); |
| 998 | |
Jonathan Hart | 38c8493 | 2013-08-10 17:49:27 +1200 | [diff] [blame] | 999 | if (sw == null) { |
| 1000 | log.warn("Switch not found when pushing BGP paths"); |
| 1001 | return; |
| 1002 | } |
| 1003 | |
Jonathan Hart | 832a7cb | 2013-06-24 11:25:35 +1200 | [diff] [blame] | 1004 | List<OFMessage> msgList = new ArrayList<OFMessage>(2); |
| 1005 | msgList.add(forwardFlowModSrc); |
| 1006 | msgList.add(forwardFlowModDst); |
| 1007 | msgList.add(reverseFlowModSrc); |
| 1008 | msgList.add(reverseFlowModDst); |
Jonathan Hart | 38c8493 | 2013-08-10 17:49:27 +1200 | [diff] [blame] | 1009 | msgList.add(forwardIcmp); |
| 1010 | msgList.add(reverseIcmp); |
Jonathan Hart | 832a7cb | 2013-06-24 11:25:35 +1200 | [diff] [blame] | 1011 | |
| 1012 | try { |
| 1013 | sw.write(msgList, null); |
| 1014 | sw.flush(); |
| 1015 | } catch (IOException e) { |
| 1016 | log.error("Failure writing flow mod", e); |
| 1017 | } |
| 1018 | } |
| 1019 | } |
| 1020 | } |
Jonathan Hart | 1236a9b | 2013-06-18 22:10:05 +1200 | [diff] [blame] | 1021 | |
Jonathan Hart | 4dfc365 | 2013-08-02 20:22:36 +1200 | [diff] [blame] | 1022 | @Override |
| 1023 | public void arpResponse(InetAddress ipAddress, byte[] macAddress) { |
| 1024 | log.debug("Received ARP response: {} => {}", ipAddress.getHostAddress(), |
| 1025 | MACAddress.valueOf(macAddress).toString()); |
| 1026 | |
| 1027 | Set<PathUpdate> pathsToPush = pathsWaitingOnArp.removeAll(ipAddress); |
| 1028 | |
| 1029 | for (PathUpdate update : pathsToPush) { |
| 1030 | log.debug("Pushing path to {} at {} on {}", new Object[] { |
| 1031 | update.getDstIpAddress().getHostAddress(), |
| 1032 | MACAddress.valueOf(macAddress), |
| 1033 | update.getDstInterface().getSwitchPort()}); |
| 1034 | calculateAndPushPath(update.getDstInterface(), |
| 1035 | MACAddress.valueOf(macAddress)); |
| 1036 | } |
Jonathan Hart | 0ee0f02 | 2013-08-03 22:21:54 +1200 | [diff] [blame] | 1037 | |
| 1038 | Set<RibUpdate> prefixesToPush = prefixesWaitingOnArp.removeAll(ipAddress); |
| 1039 | |
Jonathan Hart | 0a46fe4 | 2013-08-10 17:08:47 +1200 | [diff] [blame] | 1040 | /* |
| 1041 | * We synchronize on this to prevent changes to the ptree while we're pushing |
| 1042 | * flows to the switches. If the ptree changes, the ptree and switches |
| 1043 | * could get out of sync. |
| 1044 | */ |
| 1045 | synchronized (this) { |
| 1046 | for (RibUpdate update : prefixesToPush) { |
| 1047 | //These will always be adds |
| 1048 | |
| 1049 | //addPrefixFlows(update.getPrefix(), update.getRibEntry()); |
| 1050 | //processRibAdd(update); |
Jonathan Hart | b39a67d | 2013-08-10 23:59:50 +1200 | [diff] [blame] | 1051 | RibEntry rib = ptree.lookup(update.getPrefix()); |
Jonathan Hart | 0a46fe4 | 2013-08-10 17:08:47 +1200 | [diff] [blame] | 1052 | if (rib != null && rib.equals(update.getRibEntry())) { |
| 1053 | log.debug("Pushing prefix {} next hop {}", update.getPrefix(), |
Jonathan Hart | b39a67d | 2013-08-10 23:59:50 +1200 | [diff] [blame] | 1054 | rib.getNextHop().getHostAddress()); |
Jonathan Hart | 0a46fe4 | 2013-08-10 17:08:47 +1200 | [diff] [blame] | 1055 | //We only push prefix flows if the prefix is still in the ptree |
| 1056 | //and the next hop is the same as our update. The prefix could |
| 1057 | //have been removed while we were waiting for the ARP, or the |
| 1058 | //next hop could have changed. |
| 1059 | addPrefixFlows(update.getPrefix(), rib); |
| 1060 | } else { |
| 1061 | log.debug("Received ARP response, but {},{} is no longer in ptree", |
| 1062 | update.getPrefix(), update.getRibEntry()); |
| 1063 | } |
| 1064 | } |
Jonathan Hart | 0ee0f02 | 2013-08-03 22:21:54 +1200 | [diff] [blame] | 1065 | } |
Jonathan Hart | 4dfc365 | 2013-08-02 20:22:36 +1200 | [diff] [blame] | 1066 | } |
| 1067 | |
Jonathan Hart | 1236a9b | 2013-06-18 22:10:05 +1200 | [diff] [blame] | 1068 | private void beginRouting(){ |
| 1069 | log.debug("Topology is now ready, beginning routing function"); |
Jonathan Hart | 832a7cb | 2013-06-24 11:25:35 +1200 | [diff] [blame] | 1070 | setupBgpPaths(); |
Jonathan Hart | 98957bf | 2013-07-01 14:49:24 +1200 | [diff] [blame] | 1071 | setupFullMesh(); |
Jonathan Hart | 1236a9b | 2013-06-18 22:10:05 +1200 | [diff] [blame] | 1072 | |
Jonathan Hart | 832a7cb | 2013-06-24 11:25:35 +1200 | [diff] [blame] | 1073 | //Traverse ptree and create flows for all routes |
Jonathan Hart | d7e158d | 2013-08-07 23:04:48 +1200 | [diff] [blame] | 1074 | /* |
Jonathan Hart | 1236a9b | 2013-06-18 22:10:05 +1200 | [diff] [blame] | 1075 | for (PtreeNode node = ptree.begin(); node != null; node = ptree.next(node)){ |
| 1076 | if (node.rib != null){ |
| 1077 | prefixAdded(node); |
| 1078 | } |
| 1079 | } |
Jonathan Hart | d7e158d | 2013-08-07 23:04:48 +1200 | [diff] [blame] | 1080 | */ |
| 1081 | |
Jonathan Hart | 0a46fe4 | 2013-08-10 17:08:47 +1200 | [diff] [blame] | 1082 | /* |
Jonathan Hart | d7e158d | 2013-08-07 23:04:48 +1200 | [diff] [blame] | 1083 | synchronized (ptree) { |
| 1084 | Iterator<IPatriciaTrie.Entry> it = ptree.iterator(); |
| 1085 | while (it.hasNext()) { |
| 1086 | IPatriciaTrie.Entry entry = it.next(); |
| 1087 | addPrefixFlows(entry.getPrefix(), entry.getRib()); |
| 1088 | } |
| 1089 | } |
Jonathan Hart | 0a46fe4 | 2013-08-10 17:08:47 +1200 | [diff] [blame] | 1090 | */ |
| 1091 | |
| 1092 | bgpUpdatesExecutor.execute(new Runnable() { |
| 1093 | @Override |
| 1094 | public void run() { |
| 1095 | doUpdatesThread(); |
| 1096 | } |
| 1097 | }); |
Jonathan Hart | d7e158d | 2013-08-07 23:04:48 +1200 | [diff] [blame] | 1098 | |
Jonathan Hart | 1236a9b | 2013-06-18 22:10:05 +1200 | [diff] [blame] | 1099 | } |
| 1100 | |
| 1101 | private void checkSwitchesConnected(){ |
| 1102 | for (String dpid : switches){ |
| 1103 | if (floodlightProvider.getSwitches().get(HexString.toLong(dpid)) == null){ |
| 1104 | log.debug("Not all switches are here yet"); |
| 1105 | return; |
| 1106 | } |
| 1107 | } |
| 1108 | switchesConnected = true; |
| 1109 | } |
| 1110 | |
Jonathan Hart | c824ad0 | 2013-07-03 15:58:45 +1200 | [diff] [blame] | 1111 | //Actually we only need to go half way round to verify full mesh connectivity |
| 1112 | //(n^2)/2 |
Jonathan Hart | 1236a9b | 2013-06-18 22:10:05 +1200 | [diff] [blame] | 1113 | private void checkTopologyReady(){ |
Jonathan Hart | c824ad0 | 2013-07-03 15:58:45 +1200 | [diff] [blame] | 1114 | for (Interface dstInterface : interfaces.values()) { |
| 1115 | for (Interface srcInterface : interfaces.values()) { |
| 1116 | if (dstInterface == srcInterface) { |
Jonathan Hart | 1236a9b | 2013-06-18 22:10:05 +1200 | [diff] [blame] | 1117 | continue; |
| 1118 | } |
| 1119 | |
Jonathan Hart | 1236a9b | 2013-06-18 22:10:05 +1200 | [diff] [blame] | 1120 | DataPath shortestPath = topoRouteService.getShortestPath( |
Jonathan Hart | c824ad0 | 2013-07-03 15:58:45 +1200 | [diff] [blame] | 1121 | srcInterface.getSwitchPort(), dstInterface.getSwitchPort()); |
Jonathan Hart | 1236a9b | 2013-06-18 22:10:05 +1200 | [diff] [blame] | 1122 | |
| 1123 | if (shortestPath == null){ |
| 1124 | log.debug("Shortest path between {} and {} not found", |
Jonathan Hart | c824ad0 | 2013-07-03 15:58:45 +1200 | [diff] [blame] | 1125 | srcInterface.getSwitchPort(), dstInterface.getSwitchPort()); |
Jonathan Hart | 1236a9b | 2013-06-18 22:10:05 +1200 | [diff] [blame] | 1126 | return; |
| 1127 | } |
| 1128 | } |
| 1129 | } |
| 1130 | topologyReady = true; |
| 1131 | } |
| 1132 | |
| 1133 | private void checkStatus(){ |
| 1134 | log.debug("In checkStatus, swC {}, toRe {}", switchesConnected, topologyReady); |
| 1135 | |
| 1136 | if (!switchesConnected){ |
| 1137 | checkSwitchesConnected(); |
| 1138 | } |
| 1139 | boolean oldTopologyReadyStatus = topologyReady; |
| 1140 | if (switchesConnected && !topologyReady){ |
| 1141 | checkTopologyReady(); |
| 1142 | } |
| 1143 | if (!oldTopologyReadyStatus && topologyReady){ |
| 1144 | beginRouting(); |
| 1145 | } |
| 1146 | } |
| 1147 | |
pingping-lin | a2cbfad | 2013-03-07 08:39:21 +0800 | [diff] [blame] | 1148 | @Override |
| 1149 | public void startUp(FloodlightModuleContext context) { |
pingping-lin | e2a09ca | 2013-03-23 09:33:58 +0800 | [diff] [blame] | 1150 | restApi.addRestletRoutable(new BgpRouteWebRoutable()); |
Jonathan Hart | 1236a9b | 2013-06-18 22:10:05 +1200 | [diff] [blame] | 1151 | floodlightProvider.addOFSwitchListener(this); |
Jonathan Hart | 61ba937 | 2013-05-19 20:10:29 -0700 | [diff] [blame] | 1152 | topology.addListener(this); |
pingping-lin | e2a09ca | 2013-03-23 09:33:58 +0800 | [diff] [blame] | 1153 | |
Jonathan Hart | c7ca35d | 2013-06-25 20:54:25 +1200 | [diff] [blame] | 1154 | floodlightProvider.addOFMessageListener(OFType.PACKET_IN, proxyArp); |
| 1155 | |
Jonathan Hart | 61ba937 | 2013-05-19 20:10:29 -0700 | [diff] [blame] | 1156 | //Retrieve the RIB from BGPd during startup |
| 1157 | retrieveRib(); |
pingping-lin | a2cbfad | 2013-03-07 08:39:21 +0800 | [diff] [blame] | 1158 | } |
Jonathan Hart | 8b9349e | 2013-07-26 15:55:28 +1200 | [diff] [blame] | 1159 | |
| 1160 | private void doUpdatesThread() { |
| 1161 | boolean interrupted = false; |
| 1162 | try { |
| 1163 | while (true) { |
| 1164 | try { |
| 1165 | RibUpdate update = ribUpdates.take(); |
| 1166 | switch (update.getOperation()){ |
| 1167 | case UPDATE: |
Jonathan Hart | 2f74078 | 2013-08-04 00:49:21 +1200 | [diff] [blame] | 1168 | processRibAdd(update); |
Jonathan Hart | 8b9349e | 2013-07-26 15:55:28 +1200 | [diff] [blame] | 1169 | break; |
| 1170 | case DELETE: |
Jonathan Hart | 2f74078 | 2013-08-04 00:49:21 +1200 | [diff] [blame] | 1171 | processRibDelete(update); |
Jonathan Hart | 8b9349e | 2013-07-26 15:55:28 +1200 | [diff] [blame] | 1172 | break; |
| 1173 | } |
| 1174 | } catch (InterruptedException e) { |
Jonathan Hart | 9ea3121 | 2013-08-12 21:40:34 +1200 | [diff] [blame] | 1175 | log.debug("interrupted", e); |
Jonathan Hart | 8b9349e | 2013-07-26 15:55:28 +1200 | [diff] [blame] | 1176 | interrupted = true; |
| 1177 | } |
| 1178 | } |
| 1179 | } finally { |
| 1180 | if (interrupted) { |
| 1181 | Thread.currentThread().interrupt(); |
| 1182 | } |
| 1183 | } |
| 1184 | } |
pingping-lin | a2cbfad | 2013-03-07 08:39:21 +0800 | [diff] [blame] | 1185 | |
| 1186 | @Override |
Jonathan Hart | 1236a9b | 2013-06-18 22:10:05 +1200 | [diff] [blame] | 1187 | public void topologyChanged() { |
Jonathan Hart | 1236a9b | 2013-06-18 22:10:05 +1200 | [diff] [blame] | 1188 | boolean refreshNeeded = false; |
| 1189 | for (LDUpdate ldu : topology.getLastLinkUpdates()){ |
| 1190 | if (!ldu.getOperation().equals(ILinkDiscovery.UpdateOperation.LINK_UPDATED)){ |
| 1191 | //We don't need to recalculate anything for just link updates |
Jonathan Hart | b39a67d | 2013-08-10 23:59:50 +1200 | [diff] [blame] | 1192 | //They happen very frequently |
Jonathan Hart | 1236a9b | 2013-06-18 22:10:05 +1200 | [diff] [blame] | 1193 | refreshNeeded = true; |
| 1194 | } |
Jonathan Hart | 98957bf | 2013-07-01 14:49:24 +1200 | [diff] [blame] | 1195 | |
Jonathan Hart | 1236a9b | 2013-06-18 22:10:05 +1200 | [diff] [blame] | 1196 | log.debug("Topo change {}", ldu.getOperation()); |
Jonathan Hart | c824ad0 | 2013-07-03 15:58:45 +1200 | [diff] [blame] | 1197 | |
Jonathan Hart | 98957bf | 2013-07-01 14:49:24 +1200 | [diff] [blame] | 1198 | if (ldu.getOperation().equals(ILinkDiscovery.UpdateOperation.LINK_ADDED)){ |
| 1199 | synchronized (linkUpdates) { |
| 1200 | linkUpdates.add(ldu); |
| 1201 | } |
| 1202 | } |
Jonathan Hart | 1236a9b | 2013-06-18 22:10:05 +1200 | [diff] [blame] | 1203 | } |
| 1204 | |
| 1205 | if (refreshNeeded){ |
Jonathan Hart | 98957bf | 2013-07-01 14:49:24 +1200 | [diff] [blame] | 1206 | topologyChangeDetectorTask.reschedule(TOPO_DETECTION_WAIT, TimeUnit.SECONDS); |
pingping-lin | a2cbfad | 2013-03-07 08:39:21 +0800 | [diff] [blame] | 1207 | } |
Jonathan Hart | 1236a9b | 2013-06-18 22:10:05 +1200 | [diff] [blame] | 1208 | } |
pingping-lin | a2cbfad | 2013-03-07 08:39:21 +0800 | [diff] [blame] | 1209 | |
Jonathan Hart | 1236a9b | 2013-06-18 22:10:05 +1200 | [diff] [blame] | 1210 | //TODO determine whether we need to listen for switch joins |
| 1211 | @Override |
| 1212 | public void addedSwitch(IOFSwitch sw) { |
| 1213 | //checkStatus(); |
| 1214 | } |
| 1215 | |
| 1216 | @Override |
| 1217 | public void removedSwitch(IOFSwitch sw) { |
| 1218 | // TODO Auto-generated method stub |
| 1219 | } |
| 1220 | |
| 1221 | @Override |
| 1222 | public void switchPortChanged(Long switchId) {} |
Jonathan Hart | 1236a9b | 2013-06-18 22:10:05 +1200 | [diff] [blame] | 1223 | |
| 1224 | @Override |
| 1225 | public String getName() { |
| 1226 | return "BgpRoute"; |
pingping-lin | a2cbfad | 2013-03-07 08:39:21 +0800 | [diff] [blame] | 1227 | } |
| 1228 | } |