Jonathan Hart | 382623d | 2014-04-03 09:48:11 -0700 | [diff] [blame] | 1 | package net.onrc.onos.apps.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 | e7e1c6e | 2013-06-04 20:50:23 -0700 | [diff] [blame] | 9 | import java.util.List; |
Jonathan Hart | 61ba937 | 2013-05-19 20:10:29 -0700 | [diff] [blame] | 10 | import java.util.Map; |
Jonathan Hart | 4dfc365 | 2013-08-02 20:22:36 +1200 | [diff] [blame] | 11 | import java.util.Set; |
Jonathan Hart | 8b9349e | 2013-07-26 15:55:28 +1200 | [diff] [blame] | 12 | import java.util.concurrent.BlockingQueue; |
| 13 | import java.util.concurrent.ExecutorService; |
Jonathan Hart | 98957bf | 2013-07-01 14:49:24 +1200 | [diff] [blame] | 14 | import java.util.concurrent.Executors; |
Jonathan Hart | 8b9349e | 2013-07-26 15:55:28 +1200 | [diff] [blame] | 15 | import java.util.concurrent.LinkedBlockingQueue; |
Jonathan Hart | 98957bf | 2013-07-01 14:49:24 +1200 | [diff] [blame] | 16 | import java.util.concurrent.ScheduledExecutorService; |
| 17 | import java.util.concurrent.TimeUnit; |
pingping-lin | a2cbfad | 2013-03-07 08:39:21 +0800 | [diff] [blame] | 18 | |
Jonathan Hart | 61ba937 | 2013-05-19 20:10:29 -0700 | [diff] [blame] | 19 | import net.floodlightcontroller.core.IFloodlightProviderService; |
Jonathan Hart | e7e1c6e | 2013-06-04 20:50:23 -0700 | [diff] [blame] | 20 | import net.floodlightcontroller.core.IOFSwitch; |
Jonathan Hart | 64c0b20 | 2013-08-20 15:45:07 +1200 | [diff] [blame] | 21 | import net.floodlightcontroller.core.IOFSwitchListener; |
pingping-lin | a2cbfad | 2013-03-07 08:39:21 +0800 | [diff] [blame] | 22 | import net.floodlightcontroller.core.module.FloodlightModuleContext; |
| 23 | import net.floodlightcontroller.core.module.FloodlightModuleException; |
| 24 | import net.floodlightcontroller.core.module.IFloodlightModule; |
| 25 | import net.floodlightcontroller.core.module.IFloodlightService; |
Jonathan Hart | 98957bf | 2013-07-01 14:49:24 +1200 | [diff] [blame] | 26 | import net.floodlightcontroller.core.util.SingletonTask; |
pingping-lin | a2cbfad | 2013-03-07 08:39:21 +0800 | [diff] [blame] | 27 | import net.floodlightcontroller.restserver.IRestApiService; |
Jonathan Hart | 4dfc365 | 2013-08-02 20:22:36 +1200 | [diff] [blame] | 28 | import net.floodlightcontroller.util.MACAddress; |
Jonathan Hart | 382623d | 2014-04-03 09:48:11 -0700 | [diff] [blame] | 29 | import net.onrc.onos.apps.bgproute.RibUpdate.Operation; |
Jonathan Hart | 0961fe8 | 2014-04-03 09:56:25 -0700 | [diff] [blame] | 30 | import net.onrc.onos.apps.proxyarp.IArpRequester; |
| 31 | import net.onrc.onos.apps.proxyarp.IProxyArpService; |
Jonathan Hart | 23701d1 | 2014-04-03 10:45:48 -0700 | [diff] [blame] | 32 | import net.onrc.onos.core.linkdiscovery.ILinkDiscovery.LDUpdate; |
Jonathan Hart | a99ec67 | 2014-04-03 11:30:34 -0700 | [diff] [blame] | 33 | import net.onrc.onos.core.linkdiscovery.ILinkDiscoveryService; |
Jonathan Hart | 51f6f5b | 2014-04-03 10:32:10 -0700 | [diff] [blame] | 34 | import net.onrc.onos.core.main.config.IConfigInfoService; |
Jonathan Hart | deda0ba | 2014-04-03 11:14:12 -0700 | [diff] [blame] | 35 | import net.onrc.onos.core.packet.Ethernet; |
| 36 | import net.onrc.onos.core.packet.IPv4; |
Jonathan Hart | 23701d1 | 2014-04-03 10:45:48 -0700 | [diff] [blame] | 37 | import net.onrc.onos.core.util.CallerId; |
| 38 | import net.onrc.onos.core.util.DataPath; |
| 39 | import net.onrc.onos.core.util.Dpid; |
| 40 | import net.onrc.onos.core.util.FlowEntryAction; |
| 41 | import net.onrc.onos.core.util.FlowEntryActions; |
| 42 | import net.onrc.onos.core.util.FlowEntryMatch; |
| 43 | import net.onrc.onos.core.util.FlowId; |
| 44 | import net.onrc.onos.core.util.FlowPath; |
| 45 | import net.onrc.onos.core.util.FlowPathFlags; |
| 46 | import net.onrc.onos.core.util.FlowPathType; |
| 47 | import net.onrc.onos.core.util.FlowPathUserState; |
| 48 | import net.onrc.onos.core.util.IPv4Net; |
| 49 | import net.onrc.onos.core.util.Port; |
| 50 | import net.onrc.onos.core.util.SwitchPort; |
pingping-lin | e2a09ca | 2013-03-23 09:33:58 +0800 | [diff] [blame] | 51 | import net.sf.json.JSONArray; |
| 52 | import net.sf.json.JSONObject; |
| 53 | import net.sf.json.JSONSerializer; |
pingping-lin | a2cbfad | 2013-03-07 08:39:21 +0800 | [diff] [blame] | 54 | |
Jonathan Hart | ec9ee2e | 2014-04-08 22:45:44 -0700 | [diff] [blame] | 55 | import org.apache.commons.configuration.ConfigurationRuntimeException; |
Jonathan Hart | d1f2325 | 2013-06-13 15:17:05 +1200 | [diff] [blame] | 56 | import org.codehaus.jackson.JsonParseException; |
| 57 | import org.codehaus.jackson.map.JsonMappingException; |
| 58 | import org.codehaus.jackson.map.ObjectMapper; |
Jonathan Hart | e7e1c6e | 2013-06-04 20:50:23 -0700 | [diff] [blame] | 59 | import org.openflow.protocol.OFFlowMod; |
| 60 | import org.openflow.protocol.OFMatch; |
Jonathan Hart | e7e1c6e | 2013-06-04 20:50:23 -0700 | [diff] [blame] | 61 | import org.openflow.protocol.OFPacketOut; |
Jonathan Hart | 9575cb6 | 2013-07-05 13:43:49 +1200 | [diff] [blame] | 62 | import org.openflow.protocol.OFPort; |
Jonathan Hart | e7e1c6e | 2013-06-04 20:50:23 -0700 | [diff] [blame] | 63 | import org.openflow.protocol.action.OFAction; |
Jonathan Hart | e7e1c6e | 2013-06-04 20:50:23 -0700 | [diff] [blame] | 64 | import org.openflow.protocol.action.OFActionOutput; |
Jonathan Hart | 1236a9b | 2013-06-18 22:10:05 +1200 | [diff] [blame] | 65 | import org.openflow.util.HexString; |
pingping-lin | a2cbfad | 2013-03-07 08:39:21 +0800 | [diff] [blame] | 66 | import org.slf4j.Logger; |
| 67 | import org.slf4j.LoggerFactory; |
| 68 | |
Jonathan Hart | 4dfc365 | 2013-08-02 20:22:36 +1200 | [diff] [blame] | 69 | import com.google.common.collect.HashMultimap; |
Jonathan Hart | 0ee0f02 | 2013-08-03 22:21:54 +1200 | [diff] [blame] | 70 | import com.google.common.collect.Multimap; |
Jonathan Hart | 4dfc365 | 2013-08-02 20:22:36 +1200 | [diff] [blame] | 71 | import com.google.common.collect.Multimaps; |
| 72 | import com.google.common.collect.SetMultimap; |
Jonathan Hart | 309889c | 2013-08-13 23:26:24 +1200 | [diff] [blame] | 73 | import com.google.common.net.InetAddresses; |
Jonathan Hart | 8b9349e | 2013-07-26 15:55:28 +1200 | [diff] [blame] | 74 | import com.google.common.util.concurrent.ThreadFactoryBuilder; |
| 75 | |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 76 | public class BgpRoute implements IFloodlightModule, IBgpRouteService, |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 77 | IArpRequester, |
| 78 | IOFSwitchListener, IConfigInfoService { |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 79 | |
Ray Milkey | ec83894 | 2014-04-09 11:28:43 -0700 | [diff] [blame] | 80 | private static final Logger log = LoggerFactory.getLogger(BgpRoute.class); |
pingping-lin | a2cbfad | 2013-03-07 08:39:21 +0800 | [diff] [blame] | 81 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 82 | private IFloodlightProviderService floodlightProvider; |
| 83 | private ILinkDiscoveryService linkDiscoveryService; |
| 84 | private IRestApiService restApi; |
| 85 | private IProxyArpService proxyArp; |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 86 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 87 | private IPatriciaTrie<RibEntry> ptree; |
| 88 | private IPatriciaTrie<Interface> interfacePtrie; |
| 89 | private BlockingQueue<RibUpdate> ribUpdates; |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 90 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 91 | private String bgpdRestIp; |
| 92 | private String routerId; |
| 93 | private String configFilename = "config.json"; |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 94 | |
Ray Milkey | 2476cac | 2014-04-08 11:03:21 -0700 | [diff] [blame] | 95 | private static final short ARP_PRIORITY = 20; |
Ray Milkey | 5d40601 | 2014-04-08 14:44:41 -0700 | [diff] [blame] | 96 | |
Jonathan Hart | 938a015 | 2014-04-07 18:27:31 -0700 | [diff] [blame] | 97 | // The fields below are unused after the move to FlowManager. |
| 98 | // Remove them if no longer needed. |
| 99 | /* |
| 100 | // We need to identify our flows somehow, in lieu of an OS-wide mechanism |
| 101 | // to hand out cookie IDs to prevent conflicts. |
| 102 | private static final long APP_COOKIE = 0xa0000000000000L; |
| 103 | // Cookie for flows that do L2 forwarding within SDN domain to egress routers |
| 104 | private static final long L2_FWD_COOKIE = APP_COOKIE + 1; |
| 105 | // Cookie for flows in ingress switches that rewrite the MAC address |
| 106 | private static final long MAC_RW_COOKIE = APP_COOKIE + 2; |
| 107 | // Cookie for flows that setup BGP paths |
| 108 | private static final long BGP_COOKIE = APP_COOKIE + 3; |
| 109 | // Forwarding uses priority 0, and the mac rewrite entries in ingress switches |
| 110 | // need to be higher priority than this otherwise the rewrite may not get done |
| 111 | private static final short SDNIP_PRIORITY = 10; |
| 112 | */ |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 113 | |
Ray Milkey | 2476cac | 2014-04-08 11:03:21 -0700 | [diff] [blame] | 114 | private static final short BGP_PORT = 179; |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 115 | |
Jonathan Hart | 938a015 | 2014-04-07 18:27:31 -0700 | [diff] [blame] | 116 | private static final int TOPO_DETECTION_WAIT = 2; // seconds |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 117 | |
Jonathan Hart | 938a015 | 2014-04-07 18:27:31 -0700 | [diff] [blame] | 118 | // Configuration stuff |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 119 | private List<String> switches; |
| 120 | private Map<String, Interface> interfaces; |
| 121 | private Map<InetAddress, BgpPeer> bgpPeers; |
| 122 | private SwitchPort bgpdAttachmentPoint; |
| 123 | private MACAddress bgpdMacAddress; |
| 124 | private short vlan; |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 125 | |
Jonathan Hart | 938a015 | 2014-04-07 18:27:31 -0700 | [diff] [blame] | 126 | // True when all switches have connected |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 127 | private volatile boolean switchesConnected = false; |
Jonathan Hart | 938a015 | 2014-04-07 18:27:31 -0700 | [diff] [blame] | 128 | // True when we have a full mesh of shortest paths between gateways |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 129 | private volatile boolean topologyReady = false; |
Jonathan Hart | 98957bf | 2013-07-01 14:49:24 +1200 | [diff] [blame] | 130 | |
Jonathan Hart | 938a015 | 2014-04-07 18:27:31 -0700 | [diff] [blame] | 131 | private List<LDUpdate> linkUpdates; |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 132 | private SingletonTask topologyChangeDetectorTask; |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 133 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 134 | private SetMultimap<InetAddress, RibUpdate> prefixesWaitingOnArp; |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 135 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 136 | private Map<InetAddress, Path> pathsWaitingOnArp; |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 137 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 138 | private ExecutorService bgpUpdatesExecutor; |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 139 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 140 | private Map<InetAddress, Path> pushedPaths; |
| 141 | private Map<Prefix, Path> prefixToPath; |
| 142 | // private Multimap<Prefix, PushedFlowMod> pushedFlows; |
| 143 | private Multimap<Prefix, FlowId> pushedFlowIds; |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 144 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 145 | private FlowCache flowCache; |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 146 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 147 | // TODO: Fix for the new Topology Network Graph |
| 148 | // private volatile Topology topology = null; |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 149 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 150 | private class TopologyChangeDetector implements Runnable { |
| 151 | @Override |
| 152 | public void run() { |
| 153 | log.debug("Running topology change detection task"); |
Jonathan Hart | ec9ee2e | 2014-04-08 22:45:44 -0700 | [diff] [blame] | 154 | // TODO: Fix the code below after topoLinkService was removed |
| 155 | /* |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 156 | synchronized (linkUpdates) { |
Jonathan Hart | ec9ee2e | 2014-04-08 22:45:44 -0700 | [diff] [blame] | 157 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 158 | ITopoLinkService topoLinkService = new TopoLinkServiceImpl(); |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 159 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 160 | List<Link> activeLinks = topoLinkService.getActiveLinks(); |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 161 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 162 | Iterator<LDUpdate> it = linkUpdates.iterator(); |
| 163 | while (it.hasNext()){ |
| 164 | LDUpdate ldu = it.next(); |
| 165 | Link l = new Link(ldu.getSrc(), ldu.getSrcPort(), |
| 166 | ldu.getDst(), ldu.getDstPort()); |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 167 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 168 | if (activeLinks.contains(l)){ |
| 169 | it.remove(); |
| 170 | } |
| 171 | } |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 172 | } |
Jonathan Hart | ec9ee2e | 2014-04-08 22:45:44 -0700 | [diff] [blame] | 173 | */ |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 174 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 175 | if (!topologyReady) { |
| 176 | if (linkUpdates.isEmpty()) { |
Jonathan Hart | 938a015 | 2014-04-07 18:27:31 -0700 | [diff] [blame] | 177 | // All updates have been seen in network map. |
| 178 | // We can check if topology is ready |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 179 | log.debug("No known changes outstanding. Checking topology now"); |
| 180 | checkStatus(); |
| 181 | } else { |
Jonathan Hart | 938a015 | 2014-04-07 18:27:31 -0700 | [diff] [blame] | 182 | // We know of some link updates that haven't propagated to the database yet |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 183 | log.debug("Some changes not found in network map - {} links missing", linkUpdates.size()); |
| 184 | topologyChangeDetectorTask.reschedule(TOPO_DETECTION_WAIT, TimeUnit.SECONDS); |
| 185 | } |
| 186 | } |
| 187 | } |
| 188 | } |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 189 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 190 | private void readConfiguration(String configFilename) { |
| 191 | File gatewaysFile = new File(configFilename); |
| 192 | ObjectMapper mapper = new ObjectMapper(); |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 193 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 194 | try { |
| 195 | Configuration config = mapper.readValue(gatewaysFile, Configuration.class); |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 196 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 197 | switches = config.getSwitches(); |
| 198 | interfaces = new HashMap<String, Interface>(); |
| 199 | for (Interface intf : config.getInterfaces()) { |
| 200 | interfaces.put(intf.getName(), intf); |
| 201 | } |
| 202 | bgpPeers = new HashMap<InetAddress, BgpPeer>(); |
| 203 | for (BgpPeer peer : config.getPeers()) { |
| 204 | bgpPeers.put(peer.getIpAddress(), peer); |
| 205 | } |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 206 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 207 | bgpdAttachmentPoint = new SwitchPort( |
| 208 | new Dpid(config.getBgpdAttachmentDpid()), |
| 209 | new Port(config.getBgpdAttachmentPort())); |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 210 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 211 | bgpdMacAddress = config.getBgpdMacAddress(); |
| 212 | vlan = config.getVlan(); |
| 213 | } catch (JsonParseException e) { |
| 214 | log.error("Error in JSON file", e); |
Jonathan Hart | ec9ee2e | 2014-04-08 22:45:44 -0700 | [diff] [blame] | 215 | throw new ConfigurationRuntimeException("Error in JSON file", e); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 216 | } catch (JsonMappingException e) { |
| 217 | log.error("Error in JSON file", e); |
Jonathan Hart | ec9ee2e | 2014-04-08 22:45:44 -0700 | [diff] [blame] | 218 | throw new ConfigurationRuntimeException("Error in JSON file", e); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 219 | } catch (IOException e) { |
| 220 | log.error("Error reading JSON file", e); |
Jonathan Hart | ec9ee2e | 2014-04-08 22:45:44 -0700 | [diff] [blame] | 221 | throw new ConfigurationRuntimeException("Error in JSON file", e); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 222 | } |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 223 | |
Jonathan Hart | 938a015 | 2014-04-07 18:27:31 -0700 | [diff] [blame] | 224 | // Populate the interface Patricia Trie |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 225 | for (Interface intf : interfaces.values()) { |
| 226 | Prefix prefix = new Prefix(intf.getIpAddress().getAddress(), intf.getPrefixLength()); |
| 227 | interfacePtrie.put(prefix, intf); |
| 228 | } |
| 229 | } |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 230 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 231 | @Override |
| 232 | public Collection<Class<? extends IFloodlightService>> getModuleServices() { |
| 233 | Collection<Class<? extends IFloodlightService>> l |
| 234 | = new ArrayList<Class<? extends IFloodlightService>>(); |
| 235 | l.add(IBgpRouteService.class); |
| 236 | l.add(IConfigInfoService.class); |
| 237 | return l; |
| 238 | } |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 239 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 240 | @Override |
| 241 | public Map<Class<? extends IFloodlightService>, IFloodlightService> getServiceImpls() { |
| 242 | Map<Class<? extends IFloodlightService>, IFloodlightService> m |
| 243 | = new HashMap<Class<? extends IFloodlightService>, IFloodlightService>(); |
| 244 | m.put(IBgpRouteService.class, this); |
| 245 | m.put(IConfigInfoService.class, this); |
| 246 | return m; |
| 247 | } |
pingping-lin | a2cbfad | 2013-03-07 08:39:21 +0800 | [diff] [blame] | 248 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 249 | @Override |
| 250 | public Collection<Class<? extends IFloodlightService>> getModuleDependencies() { |
| 251 | Collection<Class<? extends IFloodlightService>> l |
| 252 | = new ArrayList<Class<? extends IFloodlightService>>(); |
| 253 | l.add(IFloodlightProviderService.class); |
| 254 | l.add(IRestApiService.class); |
| 255 | return l; |
| 256 | } |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 257 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 258 | @Override |
| 259 | public void init(FloodlightModuleContext context) |
| 260 | throws FloodlightModuleException { |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 261 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 262 | ptree = new PatriciaTrie<RibEntry>(32); |
| 263 | interfacePtrie = new PatriciaTrie<Interface>(32); |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 264 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 265 | ribUpdates = new LinkedBlockingQueue<RibUpdate>(); |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 266 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 267 | // Register floodlight provider and REST handler. |
| 268 | floodlightProvider = context.getServiceImpl(IFloodlightProviderService.class); |
| 269 | linkDiscoveryService = context.getServiceImpl(ILinkDiscoveryService.class); |
| 270 | restApi = context.getServiceImpl(IRestApiService.class); |
| 271 | proxyArp = context.getServiceImpl(IProxyArpService.class); |
pingping-lin | ba5c52f | 2014-02-11 16:52:01 -0800 | [diff] [blame] | 272 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 273 | linkUpdates = new ArrayList<LDUpdate>(); |
| 274 | ScheduledExecutorService executor = Executors.newScheduledThreadPool(1); |
| 275 | topologyChangeDetectorTask = new SingletonTask(executor, new TopologyChangeDetector()); |
Pavlin Radoslavov | ddd01ba | 2013-07-03 15:40:44 -0700 | [diff] [blame] | 276 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 277 | pathsWaitingOnArp = new HashMap<InetAddress, Path>(); |
| 278 | prefixesWaitingOnArp = Multimaps.synchronizedSetMultimap( |
| 279 | HashMultimap.<InetAddress, RibUpdate>create()); |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 280 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 281 | pushedPaths = new HashMap<InetAddress, Path>(); |
| 282 | prefixToPath = new HashMap<Prefix, Path>(); |
| 283 | // pushedFlows = HashMultimap.<Prefix, PushedFlowMod>create(); |
| 284 | pushedFlowIds = HashMultimap.<Prefix, FlowId>create(); |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 285 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 286 | flowCache = new FlowCache(floodlightProvider); |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 287 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 288 | bgpUpdatesExecutor = Executors.newSingleThreadExecutor( |
| 289 | new ThreadFactoryBuilder().setNameFormat("bgp-updates-%d").build()); |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 290 | |
Jonathan Hart | 938a015 | 2014-04-07 18:27:31 -0700 | [diff] [blame] | 291 | // Read in config values |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 292 | bgpdRestIp = context.getConfigParams(this).get("BgpdRestIp"); |
| 293 | if (bgpdRestIp == null) { |
| 294 | log.error("BgpdRestIp property not found in config file"); |
Jonathan Hart | ec9ee2e | 2014-04-08 22:45:44 -0700 | [diff] [blame] | 295 | throw new ConfigurationRuntimeException( |
| 296 | "BgpdRestIp property not found in config file"); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 297 | } else { |
| 298 | log.info("BgpdRestIp set to {}", bgpdRestIp); |
| 299 | } |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 300 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 301 | routerId = context.getConfigParams(this).get("RouterId"); |
| 302 | if (routerId == null) { |
| 303 | log.error("RouterId property not found in config file"); |
Jonathan Hart | ec9ee2e | 2014-04-08 22:45:44 -0700 | [diff] [blame] | 304 | throw new ConfigurationRuntimeException( |
| 305 | "RouterId property not found in config file"); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 306 | } else { |
| 307 | log.info("RouterId set to {}", routerId); |
| 308 | } |
pingping-lin | ba5c52f | 2014-02-11 16:52:01 -0800 | [diff] [blame] | 309 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 310 | String configFilenameParameter = context.getConfigParams(this).get("configfile"); |
| 311 | if (configFilenameParameter != null) { |
| 312 | configFilename = configFilenameParameter; |
| 313 | } |
| 314 | log.debug("Config file set to {}", configFilename); |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 315 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 316 | readConfiguration(configFilename); |
| 317 | } |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 318 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 319 | @Override |
| 320 | public void startUp(FloodlightModuleContext context) { |
| 321 | restApi.addRestletRoutable(new BgpRouteWebRoutable()); |
| 322 | floodlightProvider.addOFSwitchListener(this); |
pingping-lin | ba5c52f | 2014-02-11 16:52:01 -0800 | [diff] [blame] | 323 | |
Jonathan Hart | 938a015 | 2014-04-07 18:27:31 -0700 | [diff] [blame] | 324 | // Retrieve the RIB from BGPd during startup |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 325 | retrieveRib(); |
| 326 | } |
pingping-lin | a2cbfad | 2013-03-07 08:39:21 +0800 | [diff] [blame] | 327 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 328 | @Override |
| 329 | public IPatriciaTrie<RibEntry> getPtree() { |
| 330 | return ptree; |
| 331 | } |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 332 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 333 | @Override |
| 334 | public void clearPtree() { |
| 335 | ptree = new PatriciaTrie<RibEntry>(32); |
| 336 | } |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 337 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 338 | @Override |
| 339 | public String getBGPdRestIp() { |
| 340 | return bgpdRestIp; |
| 341 | } |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 342 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 343 | @Override |
| 344 | public String getRouterId() { |
| 345 | return routerId; |
| 346 | } |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 347 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 348 | private void retrieveRib() { |
| 349 | String url = "http://" + bgpdRestIp + "/wm/bgp/" + routerId; |
| 350 | String response = RestClient.get(url); |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 351 | |
Jonathan Hart | 938a015 | 2014-04-07 18:27:31 -0700 | [diff] [blame] | 352 | if ("".equals(response)) { |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 353 | return; |
| 354 | } |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 355 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 356 | response = response.replaceAll("\"", "'"); |
| 357 | JSONObject jsonObj = (JSONObject) JSONSerializer.toJSON(response); |
Jonathan Hart | 938a015 | 2014-04-07 18:27:31 -0700 | [diff] [blame] | 358 | JSONArray ribArray = jsonObj.getJSONArray("rib"); |
Ray Milkey | 2476cac | 2014-04-08 11:03:21 -0700 | [diff] [blame] | 359 | String routerId = jsonObj.getString("router-id"); |
Jonathan Hart | 61ba937 | 2013-05-19 20:10:29 -0700 | [diff] [blame] | 360 | |
Jonathan Hart | 938a015 | 2014-04-07 18:27:31 -0700 | [diff] [blame] | 361 | int size = ribArray.size(); |
Jonathan Hart | 61ba937 | 2013-05-19 20:10:29 -0700 | [diff] [blame] | 362 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 363 | log.info("Retrived RIB of {} entries from BGPd", size); |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 364 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 365 | for (int j = 0; j < size; j++) { |
Jonathan Hart | 938a015 | 2014-04-07 18:27:31 -0700 | [diff] [blame] | 366 | JSONObject ribEntry = ribArray.getJSONObject(j); |
| 367 | String prefix = ribEntry.getString("prefix"); |
| 368 | String nexthop = ribEntry.getString("nexthop"); |
Jonathan Hart | 61ba937 | 2013-05-19 20:10:29 -0700 | [diff] [blame] | 369 | |
Jonathan Hart | 938a015 | 2014-04-07 18:27:31 -0700 | [diff] [blame] | 370 | // Insert each rib entry into the local rib |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 371 | String[] substring = prefix.split("/"); |
| 372 | String prefix1 = substring[0]; |
| 373 | String mask1 = substring[1]; |
Jonathan Hart | 61ba937 | 2013-05-19 20:10:29 -0700 | [diff] [blame] | 374 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 375 | Prefix p; |
| 376 | try { |
| 377 | p = new Prefix(prefix1, Integer.valueOf(mask1)); |
| 378 | } catch (NumberFormatException e) { |
| 379 | log.warn("Wrong mask format in RIB JSON: {}", mask1); |
| 380 | continue; |
| 381 | } catch (IllegalArgumentException e1) { |
| 382 | log.warn("Wrong prefix format in RIB JSON: {}", prefix1); |
| 383 | continue; |
| 384 | } |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 385 | |
Ray Milkey | 2476cac | 2014-04-08 11:03:21 -0700 | [diff] [blame] | 386 | RibEntry rib = new RibEntry(routerId, nexthop); |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 387 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 388 | try { |
| 389 | ribUpdates.put(new RibUpdate(Operation.UPDATE, p, rib)); |
| 390 | } catch (InterruptedException e) { |
| 391 | log.debug("Interrupted while pushing onto update queue"); |
| 392 | } |
| 393 | } |
| 394 | } |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 395 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 396 | @Override |
| 397 | public void newRibUpdate(RibUpdate update) { |
| 398 | try { |
| 399 | ribUpdates.put(update); |
| 400 | } catch (InterruptedException e) { |
| 401 | log.debug("Interrupted while putting on ribUpdates queue", e); |
| 402 | Thread.currentThread().interrupt(); |
| 403 | } |
| 404 | } |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 405 | |
Jonathan Hart | 938a015 | 2014-04-07 18:27:31 -0700 | [diff] [blame] | 406 | public void processRibAdd(RibUpdate update) { |
| 407 | synchronized (this) { |
| 408 | Prefix prefix = update.getPrefix(); |
Ray Milkey | 5d40601 | 2014-04-08 14:44:41 -0700 | [diff] [blame] | 409 | |
Jonathan Hart | 938a015 | 2014-04-07 18:27:31 -0700 | [diff] [blame] | 410 | log.debug("Processing prefix add {}", prefix); |
Ray Milkey | 5d40601 | 2014-04-08 14:44:41 -0700 | [diff] [blame] | 411 | |
Jonathan Hart | 938a015 | 2014-04-07 18:27:31 -0700 | [diff] [blame] | 412 | RibEntry rib = ptree.put(prefix, update.getRibEntry()); |
Ray Milkey | 5d40601 | 2014-04-08 14:44:41 -0700 | [diff] [blame] | 413 | |
Jonathan Hart | 938a015 | 2014-04-07 18:27:31 -0700 | [diff] [blame] | 414 | if (rib != null && !rib.equals(update.getRibEntry())) { |
| 415 | // There was an existing nexthop for this prefix. This update supersedes that, |
| 416 | // so we need to remove the old flows for this prefix from the switches |
Ray Milkey | 7531a34 | 2014-04-11 15:08:12 -0700 | [diff] [blame] | 417 | executeDeletePrefix(prefix, rib); |
Jonathan Hart | 938a015 | 2014-04-07 18:27:31 -0700 | [diff] [blame] | 418 | } |
Ray Milkey | 5d40601 | 2014-04-08 14:44:41 -0700 | [diff] [blame] | 419 | |
Jonathan Hart | 938a015 | 2014-04-07 18:27:31 -0700 | [diff] [blame] | 420 | if (update.getRibEntry().getNextHop().equals( |
| 421 | InetAddresses.forString("0.0.0.0"))) { |
| 422 | // Route originated by SDN domain |
| 423 | // We don't handle these at the moment |
| 424 | log.debug("Own route {} to {}", prefix, |
| 425 | update.getRibEntry().getNextHop().getHostAddress()); |
| 426 | return; |
| 427 | } |
Ray Milkey | 5d40601 | 2014-04-08 14:44:41 -0700 | [diff] [blame] | 428 | |
Ray Milkey | 7531a34 | 2014-04-11 15:08:12 -0700 | [diff] [blame] | 429 | executeRibAdd(update); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 430 | } |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 431 | } |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 432 | |
Ray Milkey | 7531a34 | 2014-04-11 15:08:12 -0700 | [diff] [blame] | 433 | private void executeRibAdd(RibUpdate update) { |
Pavlin Radoslavov | 9fc535a | 2014-04-11 13:00:12 -0700 | [diff] [blame^] | 434 | // TODO: Fix the code below. Note that "deviceStorage" was removed. |
| 435 | |
| 436 | /* |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 437 | Prefix prefix = update.getPrefix(); |
| 438 | RibEntry rib = update.getRibEntry(); |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 439 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 440 | InetAddress dstIpAddress = rib.getNextHop(); |
| 441 | MACAddress nextHopMacAddress = null; |
pingping-lin | ba5c52f | 2014-02-11 16:52:01 -0800 | [diff] [blame] | 442 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 443 | // See if we know the MAC address of the next hop |
| 444 | // TODO if we do not treat the next hop as a device in the future, we need to update this |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 445 | IDeviceObject nextHopDevice = |
| 446 | deviceStorage.getDeviceByIP(InetAddresses.coerceToInteger(dstIpAddress)); |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 447 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 448 | if (nextHopDevice == null){ |
| 449 | log.debug("NextHopDevice for IP: {} is null", dstIpAddress); |
| 450 | prefixesWaitingOnArp.put(dstIpAddress, |
| 451 | new RibUpdate(Operation.UPDATE, prefix, rib)); |
| 452 | proxyArp.sendArpRequest(dstIpAddress, this, true); |
| 453 | return; |
pingping-lin | ba5c52f | 2014-02-11 16:52:01 -0800 | [diff] [blame] | 454 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 455 | } |
| 456 | nextHopMacAddress = MACAddress.valueOf(nextHopDevice.getMACAddress()); |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 457 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 458 | // Find the attachment point (egress interface) of the next hop |
| 459 | Interface egressInterface = null; |
| 460 | if (bgpPeers.containsKey(dstIpAddress)) { |
| 461 | //Route to a peer |
| 462 | log.debug("Route to peer {}", dstIpAddress); |
| 463 | BgpPeer peer = bgpPeers.get(dstIpAddress); |
| 464 | egressInterface = interfaces.get(peer.getInterfaceName()); |
| 465 | } else { |
| 466 | //Route to non-peer |
| 467 | log.debug("Route to non-peer {}", dstIpAddress); |
| 468 | egressInterface = interfacePtrie.match( |
| 469 | new Prefix(dstIpAddress.getAddress(), 32)); |
| 470 | if (egressInterface == null) { |
| 471 | log.warn("No outgoing interface found for {}", dstIpAddress.getHostAddress()); |
| 472 | return; |
| 473 | } |
| 474 | } |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 475 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 476 | if (nextHopMacAddress == null) { |
| 477 | prefixesWaitingOnArp.put(dstIpAddress, |
| 478 | new RibUpdate(Operation.UPDATE, prefix, rib)); |
| 479 | proxyArp.sendArpRequest(dstIpAddress, this, true); |
| 480 | return; |
| 481 | } else { |
| 482 | if (!bgpPeers.containsKey(dstIpAddress)) { |
| 483 | //If the prefix is for a non-peer we need to ensure there's a path, |
| 484 | //and push one if there isn't. |
| 485 | Path path = pushedPaths.get(dstIpAddress); |
| 486 | if (path == null) { |
| 487 | path = new Path(egressInterface, dstIpAddress); |
| 488 | calculateAndPushPath(path, nextHopMacAddress); |
| 489 | pushedPaths.put(dstIpAddress, path); |
| 490 | } |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 491 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 492 | path.incrementUsers(); |
| 493 | prefixToPath.put(prefix, path); |
| 494 | } |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 495 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 496 | //For all prefixes we need to add the first-hop mac-rewriting flows |
| 497 | addPrefixFlows(prefix, egressInterface, nextHopMacAddress); |
| 498 | } |
Pavlin Radoslavov | 9fc535a | 2014-04-11 13:00:12 -0700 | [diff] [blame^] | 499 | */ |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 500 | } |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 501 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 502 | /** |
| 503 | * Add a flow to match dst-IP prefix and rewrite MAC for one IP prefix |
Ray Milkey | b41100a | 2014-04-10 10:42:15 -0700 | [diff] [blame] | 504 | * to all other border switches. |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 505 | */ |
| 506 | private void addPrefixFlows(Prefix prefix, Interface egressInterface, |
| 507 | MACAddress nextHopMacAddress) { |
| 508 | log.debug("Adding flows for prefix {}, next hop mac {}", |
| 509 | prefix, nextHopMacAddress); |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 510 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 511 | FlowPath flowPath = new FlowPath(); |
| 512 | flowPath.setInstallerId(new CallerId("SDNIP")); |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 513 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 514 | // Set flowPath FlowPathType and FlowPathUserState |
| 515 | flowPath.setFlowPathType(FlowPathType.FP_TYPE_SHORTEST_PATH); |
| 516 | flowPath.setFlowPathUserState(FlowPathUserState.FP_USER_ADD); |
pingping-lin | ba5c52f | 2014-02-11 16:52:01 -0800 | [diff] [blame] | 517 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 518 | // Insert dst-ip prefix based forwarding and MAC rewrite flow entry |
| 519 | // only to the first-host switches |
| 520 | FlowPathFlags flowPathFlags = new FlowPathFlags(); |
| 521 | flowPathFlags.setFlags(FlowPathFlags.KEEP_ONLY_FIRST_HOP_ENTRY); |
| 522 | flowPath.setFlowPathFlags(flowPathFlags); |
pingping-lin | ba5c52f | 2014-02-11 16:52:01 -0800 | [diff] [blame] | 523 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 524 | // Create the DataPath object: dstSwitchPort |
Pavlin Radoslavov | 29a2a88 | 2014-04-08 17:40:54 -0700 | [diff] [blame] | 525 | SwitchPort dstPort = |
| 526 | new SwitchPort(new Dpid(egressInterface.getDpid()), |
| 527 | new Port(egressInterface.getPort())); |
pingping-lin | ba5c52f | 2014-02-11 16:52:01 -0800 | [diff] [blame] | 528 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 529 | // We only need one flow mod per switch, so pick one interface on each switch |
| 530 | Map<Long, Interface> srcInterfaces = new HashMap<Long, Interface>(); |
| 531 | for (Interface intf : interfaces.values()) { |
| 532 | if (!srcInterfaces.containsKey(intf.getDpid()) |
| 533 | && !intf.equals(egressInterface)) { |
| 534 | srcInterfaces.put(intf.getDpid(), intf); |
| 535 | } |
| 536 | } |
| 537 | for (Interface srcInterface : srcInterfaces.values()) { |
pingping-lin | ba5c52f | 2014-02-11 16:52:01 -0800 | [diff] [blame] | 538 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 539 | if (egressInterface.equals(srcInterface)) { |
| 540 | continue; |
| 541 | } |
pingping-lin | ba5c52f | 2014-02-11 16:52:01 -0800 | [diff] [blame] | 542 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 543 | // Create flowPath FlowId |
| 544 | flowPath.setFlowId(new FlowId()); |
pingping-lin | ba5c52f | 2014-02-11 16:52:01 -0800 | [diff] [blame] | 545 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 546 | // Create DataPath object: srcSwitchPort |
Pavlin Radoslavov | 29a2a88 | 2014-04-08 17:40:54 -0700 | [diff] [blame] | 547 | SwitchPort srcPort = |
| 548 | new SwitchPort(new Dpid(srcInterface.getDpid()), |
| 549 | new Port(srcInterface.getPort())); |
pingping-lin | ba5c52f | 2014-02-11 16:52:01 -0800 | [diff] [blame] | 550 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 551 | DataPath dataPath = new DataPath(); |
| 552 | dataPath.setSrcPort(srcPort); |
| 553 | dataPath.setDstPort(dstPort); |
| 554 | flowPath.setDataPath(dataPath); |
pingping-lin | ba5c52f | 2014-02-11 16:52:01 -0800 | [diff] [blame] | 555 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 556 | // Create flow path matching condition(s): IPv4 Prefix |
| 557 | FlowEntryMatch flowEntryMatch = new FlowEntryMatch(); |
Ray Milkey | 5c9f2db | 2014-04-09 10:31:21 -0700 | [diff] [blame] | 558 | flowEntryMatch.enableEthernetFrameType(Ethernet.TYPE_IPV4); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 559 | IPv4Net dstIPv4Net = new IPv4Net(prefix.toString()); |
| 560 | flowEntryMatch.enableDstIPv4Net(dstIPv4Net); |
| 561 | flowPath.setFlowEntryMatch(flowEntryMatch); |
Jonathan Hart | 1912afc | 2013-10-11 12:02:44 +1300 | [diff] [blame] | 562 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 563 | /* |
| 564 | * Create the Flow Entry Action(s): dst-MAC rewrite action |
| 565 | */ |
| 566 | FlowEntryActions flowEntryActions = new FlowEntryActions(); |
| 567 | FlowEntryAction flowEntryAction1 = new FlowEntryAction(); |
| 568 | flowEntryAction1.setActionSetEthernetDstAddr(nextHopMacAddress); |
| 569 | // flowEntryAction1.actionSetEthernetDstAddr(nextHopMacAddress); |
| 570 | flowEntryActions.addAction(flowEntryAction1); |
| 571 | flowPath.setFlowEntryActions(flowEntryActions); |
pingping-lin | ba5c52f | 2014-02-11 16:52:01 -0800 | [diff] [blame] | 572 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 573 | // Flow Path installation, only to first hop switches |
| 574 | // TODO: Add the flow by using the new Path Intent framework |
| 575 | /* |
| 576 | if (flowManagerService.addFlow(flowPath) == null) { |
| 577 | log.error("Failed to install flow path to the first hop for " + |
| 578 | "prefix: {}, nextHopMacAddress: {}", prefix.getAddress(), |
| 579 | nextHopMacAddress); |
| 580 | } |
| 581 | else { |
| 582 | log.debug("Successfully installed flow path to the first hop " + |
| 583 | "for prefix: {}, nextHopMacAddress: {}", prefix.getAddress(), |
| 584 | nextHopMacAddress); |
pingping-lin | ba5c52f | 2014-02-11 16:52:01 -0800 | [diff] [blame] | 585 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 586 | pushedFlowIds.put(prefix, flowPath.flowId()); |
| 587 | } |
| 588 | */ |
| 589 | } |
| 590 | } |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 591 | |
Jonathan Hart | 938a015 | 2014-04-07 18:27:31 -0700 | [diff] [blame] | 592 | public void processRibDelete(RibUpdate update) { |
| 593 | synchronized (this) { |
| 594 | Prefix prefix = update.getPrefix(); |
Ray Milkey | 5d40601 | 2014-04-08 14:44:41 -0700 | [diff] [blame] | 595 | |
Jonathan Hart | 938a015 | 2014-04-07 18:27:31 -0700 | [diff] [blame] | 596 | if (ptree.remove(prefix, update.getRibEntry())) { |
| 597 | /* |
| 598 | * Only delete flows if an entry was actually removed from the trie. |
| 599 | * If no entry was removed, the <prefix, nexthop> wasn't there so |
| 600 | * it's probably already been removed and we don't need to do anything |
| 601 | */ |
Ray Milkey | 7531a34 | 2014-04-11 15:08:12 -0700 | [diff] [blame] | 602 | executeDeletePrefix(prefix, update.getRibEntry()); |
Jonathan Hart | 938a015 | 2014-04-07 18:27:31 -0700 | [diff] [blame] | 603 | } |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 604 | } |
| 605 | } |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 606 | |
Ray Milkey | 7531a34 | 2014-04-11 15:08:12 -0700 | [diff] [blame] | 607 | private void executeDeletePrefix(Prefix prefix, RibEntry ribEntry) { |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 608 | deletePrefixFlows(prefix); |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 609 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 610 | log.debug("Deleting {} to {}", prefix, ribEntry.getNextHop()); |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 611 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 612 | if (!bgpPeers.containsKey(ribEntry.getNextHop())) { |
| 613 | log.debug("Getting path for route with non-peer nexthop"); |
| 614 | Path path = prefixToPath.remove(prefix); |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 615 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 616 | if (path != null) { |
| 617 | //path could be null if we added to the Ptree but didn't push |
| 618 | //flows yet because we were waiting to resolve ARP |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 619 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 620 | path.decrementUsers(); |
| 621 | if (path.getUsers() <= 0 && !path.isPermanent()) { |
| 622 | deletePath(path); |
| 623 | pushedPaths.remove(path.getDstIpAddress()); |
| 624 | } |
| 625 | } |
| 626 | } |
| 627 | } |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 628 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 629 | // TODO have not tested this module |
| 630 | private void deletePrefixFlows(Prefix prefix) { |
| 631 | log.debug("Deleting flows for prefix {}", prefix); |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 632 | |
Pavlin Radoslavov | 3255ae5 | 2014-04-09 13:01:54 -0700 | [diff] [blame] | 633 | // |
| 634 | // TODO: Delete the flow by using the new Path Intent framework |
| 635 | // NOTE: During the refactoring of the code below, if obtaining |
| 636 | // the values of the removed flowIds is needed, the first |
| 637 | // removeAll() statement should be replaced with the second removeAll() |
| 638 | // statement. |
| 639 | // |
| 640 | pushedFlowIds.removeAll(prefix); |
| 641 | /* |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 642 | Collection<FlowId> flowIds = pushedFlowIds.removeAll(prefix); |
| 643 | for (FlowId flowId : flowIds) { |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 644 | if (log.isTraceEnabled()) { |
| 645 | //Trace the flow status by flowPath in the switch before deleting it |
| 646 | log.trace("Pushing a DELETE flow mod to flowPath : {}", |
| 647 | flowManagerService.getFlow(flowId).toString()); |
| 648 | } |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 649 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 650 | if( flowManagerService.deleteFlow(flowId)) |
| 651 | { |
| 652 | log.debug("Successfully deleted FlowId: {}",flowId); |
| 653 | } |
| 654 | else |
| 655 | { |
| 656 | log.debug("Failed to delete FlowId: {}",flowId); |
| 657 | } |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 658 | } |
Pavlin Radoslavov | 3255ae5 | 2014-04-09 13:01:54 -0700 | [diff] [blame] | 659 | */ |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 660 | } |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 661 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 662 | // TODO need to record the path and then delete here |
| 663 | private void deletePath(Path path) { |
| 664 | log.debug("Deleting flows for path to {}", |
| 665 | path.getDstIpAddress().getHostAddress()); |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 666 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 667 | // TODO need update |
| 668 | /*for (PushedFlowMod pfm : path.getFlowMods()) { |
| 669 | if (log.isTraceEnabled()) { |
| 670 | log.trace("Pushing a DELETE flow mod to {}, dst MAC {}", |
| 671 | new Object[] {HexString.toHexString(pfm.getDpid()), |
| 672 | HexString.toHexString(pfm.getFlowMod().getMatch().getDataLayerDestination()) |
| 673 | }); |
| 674 | } |
pingping-lin | ba5c52f | 2014-02-11 16:52:01 -0800 | [diff] [blame] | 675 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 676 | sendDeleteFlowMod(pfm.getFlowMod(), pfm.getDpid()); |
| 677 | }*/ |
| 678 | } |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 679 | |
| 680 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 681 | //TODO test next-hop changes |
| 682 | //TODO check delete/add synchronization |
pingping-lin | ba5c52f | 2014-02-11 16:52:01 -0800 | [diff] [blame] | 683 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 684 | /** |
| 685 | * On startup, we need to calculate a full mesh of paths between all gateway |
Ray Milkey | b41100a | 2014-04-10 10:42:15 -0700 | [diff] [blame] | 686 | * switches. |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 687 | */ |
| 688 | private void setupFullMesh() { |
Pavlin Radoslavov | 9fc535a | 2014-04-11 13:00:12 -0700 | [diff] [blame^] | 689 | // TODO: Fix the code below. Note that "deviceStorage" was removed. |
| 690 | |
| 691 | /* |
| 692 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 693 | //For each border router, calculate and install a path from every other |
| 694 | //border switch to said border router. However, don't install the entry |
| 695 | //in to the first hop switch, as we need to install an entry to rewrite |
| 696 | //for each prefix received. This will be done later when prefixes have |
| 697 | //actually been received. |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 698 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 699 | for (BgpPeer peer : bgpPeers.values()) { |
| 700 | Interface peerInterface = interfaces.get(peer.getInterfaceName()); |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 701 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 702 | //We know there's not already a Path here pushed, because this is |
| 703 | //called before all other routing |
| 704 | Path path = new Path(peerInterface, peer.getIpAddress()); |
| 705 | path.setPermanent(); |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 706 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 707 | //See if we know the MAC address of the peer. If not we can't |
| 708 | //do anything until we learn it |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 709 | MACAddress macAddress = null; |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 710 | IDeviceObject nextHopDevice = |
| 711 | deviceStorage.getDeviceByIP(InetAddresses.coerceToInteger(peer.getIpAddress())); |
pingping-lin | ba5c52f | 2014-02-11 16:52:01 -0800 | [diff] [blame] | 712 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 713 | if(nextHopDevice == null){ |
| 714 | log.debug("There is no DeviceObject for {}", peer.getIpAddress().getHostAddress()); |
| 715 | //Put in the pending paths list first |
| 716 | pathsWaitingOnArp.put(peer.getIpAddress(), path); |
| 717 | proxyArp.sendArpRequest(peer.getIpAddress(), this, true); |
| 718 | continue; |
| 719 | } |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 720 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 721 | macAddress = MACAddress.valueOf(nextHopDevice.getMACAddress()); |
pingping-lin | ba5c52f | 2014-02-11 16:52:01 -0800 | [diff] [blame] | 722 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 723 | if (macAddress == null) { |
| 724 | log.debug("Don't know MAC for {}", peer.getIpAddress().getHostAddress()); |
| 725 | //Put in the pending paths list first |
| 726 | pathsWaitingOnArp.put(peer.getIpAddress(), path); |
| 727 | proxyArp.sendArpRequest(peer.getIpAddress(), this, true); |
| 728 | continue; |
| 729 | } |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 730 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 731 | //If we know the MAC, lets go ahead and push the paths to this peer |
| 732 | calculateAndPushPath(path, macAddress); |
| 733 | } |
Pavlin Radoslavov | 9fc535a | 2014-04-11 13:00:12 -0700 | [diff] [blame^] | 734 | */ |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 735 | } |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 736 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 737 | private void calculateAndPushPath(Path path, MACAddress dstMacAddress) { |
| 738 | Interface dstInterface = path.getDstInterface(); |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 739 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 740 | log.debug("Setting up path to {}, {}", path.getDstIpAddress().getHostAddress(), |
| 741 | dstMacAddress); |
pingping-lin | ba5c52f | 2014-02-11 16:52:01 -0800 | [diff] [blame] | 742 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 743 | FlowPath flowPath = new FlowPath(); |
pingping-lin | ba5c52f | 2014-02-11 16:52:01 -0800 | [diff] [blame] | 744 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 745 | flowPath.setInstallerId(new CallerId("SDNIP")); |
pingping-lin | ba5c52f | 2014-02-11 16:52:01 -0800 | [diff] [blame] | 746 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 747 | // Set flowPath FlowPathType and FlowPathUserState |
| 748 | flowPath.setFlowPathType(FlowPathType.FP_TYPE_SHORTEST_PATH); |
| 749 | flowPath.setFlowPathUserState(FlowPathUserState.FP_USER_ADD); |
pingping-lin | ba5c52f | 2014-02-11 16:52:01 -0800 | [diff] [blame] | 750 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 751 | // Insert the dest-mac based forwarding flow entry to the non-first-hop switches |
| 752 | FlowPathFlags flowPathFlags = new FlowPathFlags(); |
| 753 | flowPathFlags.setFlags(FlowPathFlags.DISCARD_FIRST_HOP_ENTRY); |
| 754 | flowPath.setFlowPathFlags(flowPathFlags); |
| 755 | |
| 756 | // Create the DataPath object: dstSwitchPort |
Pavlin Radoslavov | 29a2a88 | 2014-04-08 17:40:54 -0700 | [diff] [blame] | 757 | SwitchPort dstPort = |
| 758 | new SwitchPort(new Dpid(dstInterface.getDpid()), |
| 759 | new Port(dstInterface.getPort())); |
pingping-lin | ba5c52f | 2014-02-11 16:52:01 -0800 | [diff] [blame] | 760 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 761 | for (Interface srcInterface : interfaces.values()) { |
pingping-lin | ba5c52f | 2014-02-11 16:52:01 -0800 | [diff] [blame] | 762 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 763 | if (dstInterface.equals(srcInterface)) { |
| 764 | continue; |
| 765 | } |
pingping-lin | ba5c52f | 2014-02-11 16:52:01 -0800 | [diff] [blame] | 766 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 767 | // Create flowPath FlowId |
| 768 | flowPath.setFlowId(new FlowId()); |
pingping-lin | ba5c52f | 2014-02-11 16:52:01 -0800 | [diff] [blame] | 769 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 770 | // Create the DataPath object: srcSwitchPort |
Pavlin Radoslavov | 29a2a88 | 2014-04-08 17:40:54 -0700 | [diff] [blame] | 771 | SwitchPort srcPort = |
| 772 | new SwitchPort(new Dpid(srcInterface.getDpid()), |
| 773 | new Port(srcInterface.getPort())); |
pingping-lin | ba5c52f | 2014-02-11 16:52:01 -0800 | [diff] [blame] | 774 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 775 | DataPath dataPath = new DataPath(); |
| 776 | dataPath.setSrcPort(srcPort); |
| 777 | dataPath.setDstPort(dstPort); |
| 778 | flowPath.setDataPath(dataPath); |
pingping-lin | ba5c52f | 2014-02-11 16:52:01 -0800 | [diff] [blame] | 779 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 780 | // Create the Flow Path Match condition(s) |
| 781 | FlowEntryMatch flowEntryMatch = new FlowEntryMatch(); |
Ray Milkey | 5c9f2db | 2014-04-09 10:31:21 -0700 | [diff] [blame] | 782 | flowEntryMatch.enableEthernetFrameType(Ethernet.TYPE_IPV4); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 783 | flowEntryMatch.enableDstMac(dstMacAddress); |
| 784 | flowPath.setFlowEntryMatch(flowEntryMatch); |
pingping-lin | ba5c52f | 2014-02-11 16:52:01 -0800 | [diff] [blame] | 785 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 786 | // NOTE: No need to add ACTION_OUTPUT. It is implied when creating |
| 787 | // Shortest Path Flow, and is always the last action for the Flow Entries |
| 788 | log.debug("FlowPath of MAC based forwarding: {}", flowPath.toString()); |
| 789 | // TODO: Add the flow by using the new Path Intent framework |
| 790 | /* |
| 791 | if (flowManagerService.addFlow(flowPath) == null) { |
| 792 | log.error("Failed to set up MAC based forwarding path to {}, {}", |
| 793 | path.getDstIpAddress().getHostAddress(),dstMacAddress); |
| 794 | } |
| 795 | else { |
| 796 | log.debug("Successfully set up MAC based forwarding path to {}, {}", |
| 797 | path.getDstIpAddress().getHostAddress(),dstMacAddress); |
| 798 | } |
| 799 | */ |
| 800 | } |
| 801 | } |
pingping-lin | ba5c52f | 2014-02-11 16:52:01 -0800 | [diff] [blame] | 802 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 803 | /** |
Jonathan Hart | 938a015 | 2014-04-07 18:27:31 -0700 | [diff] [blame] | 804 | * Proactively install all BGP traffic paths from BGP host attachment point |
Ray Milkey | b41100a | 2014-04-10 10:42:15 -0700 | [diff] [blame] | 805 | * in SDN network to all the virtual gateways to BGP peers in other networks. |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 806 | */ |
| 807 | private void setupBgpPaths() { |
Jonathan Hart | 832a7cb | 2013-06-24 11:25:35 +1200 | [diff] [blame] | 808 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 809 | for (BgpPeer bgpPeer : bgpPeers.values()) { |
pingping-lin | ba5c52f | 2014-02-11 16:52:01 -0800 | [diff] [blame] | 810 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 811 | FlowPath flowPath = new FlowPath(); |
| 812 | flowPath.setInstallerId(new CallerId("SDNIP")); |
pingping-lin | ba5c52f | 2014-02-11 16:52:01 -0800 | [diff] [blame] | 813 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 814 | // Set flowPath FlowPathType and FlowPathUserState |
| 815 | flowPath.setFlowPathType(FlowPathType.FP_TYPE_SHORTEST_PATH); |
| 816 | flowPath.setFlowPathUserState(FlowPathUserState.FP_USER_ADD); |
pingping-lin | ba5c52f | 2014-02-11 16:52:01 -0800 | [diff] [blame] | 817 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 818 | // Install flow paths between BGPd and its peers |
| 819 | // There is no need to set the FlowPathFlags |
| 820 | flowPath.setFlowPathFlags(new FlowPathFlags(0)); |
pingping-lin | ba5c52f | 2014-02-11 16:52:01 -0800 | [diff] [blame] | 821 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 822 | Interface peerInterface = interfaces.get(bgpPeer.getInterfaceName()); |
pingping-lin | ba5c52f | 2014-02-11 16:52:01 -0800 | [diff] [blame] | 823 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 824 | // Create the Flow Path Match condition(s) |
| 825 | FlowEntryMatch flowEntryMatch = new FlowEntryMatch(); |
Ray Milkey | 5c9f2db | 2014-04-09 10:31:21 -0700 | [diff] [blame] | 826 | flowEntryMatch.enableEthernetFrameType(Ethernet.TYPE_IPV4); |
pingping-lin | ba5c52f | 2014-02-11 16:52:01 -0800 | [diff] [blame] | 827 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 828 | // Match both source address and dest address |
| 829 | IPv4Net dstIPv4Net = new IPv4Net(bgpPeer.getIpAddress().getHostAddress() + "/32"); |
| 830 | flowEntryMatch.enableDstIPv4Net(dstIPv4Net); |
pingping-lin | ba5c52f | 2014-02-11 16:52:01 -0800 | [diff] [blame] | 831 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 832 | IPv4Net srcIPv4Net = new IPv4Net(peerInterface.getIpAddress().getHostAddress() + "/32"); |
| 833 | flowEntryMatch.enableSrcIPv4Net(srcIPv4Net); |
pingping-lin | ba5c52f | 2014-02-11 16:52:01 -0800 | [diff] [blame] | 834 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 835 | // Match TCP protocol |
| 836 | flowEntryMatch.enableIpProto(IPv4.PROTOCOL_TCP); |
pingping-lin | ba5c52f | 2014-02-11 16:52:01 -0800 | [diff] [blame] | 837 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 838 | // Match destination TCP port |
| 839 | flowEntryMatch.enableDstTcpUdpPort(BGP_PORT); |
| 840 | flowPath.setFlowEntryMatch(flowEntryMatch); |
pingping-lin | ba5c52f | 2014-02-11 16:52:01 -0800 | [diff] [blame] | 841 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 842 | /** |
| 843 | * Create the DataPath: BGP -> BGP peer |
| 844 | */ |
| 845 | // Flow path for src-TCP-port |
| 846 | DataPath dataPath = new DataPath(); |
pingping-lin | ba5c52f | 2014-02-11 16:52:01 -0800 | [diff] [blame] | 847 | |
Pavlin Radoslavov | 29a2a88 | 2014-04-08 17:40:54 -0700 | [diff] [blame] | 848 | SwitchPort srcPort = |
| 849 | new SwitchPort(bgpdAttachmentPoint.dpid(), |
| 850 | bgpdAttachmentPoint.port()); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 851 | dataPath.setSrcPort(srcPort); |
pingping-lin | ba5c52f | 2014-02-11 16:52:01 -0800 | [diff] [blame] | 852 | |
Pavlin Radoslavov | 29a2a88 | 2014-04-08 17:40:54 -0700 | [diff] [blame] | 853 | SwitchPort dstPort = |
| 854 | new SwitchPort(new Dpid(peerInterface.getDpid()), |
| 855 | new Port(peerInterface.getSwitchPort().port())); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 856 | dataPath.setDstPort(dstPort); |
pingping-lin | ba5c52f | 2014-02-11 16:52:01 -0800 | [diff] [blame] | 857 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 858 | flowPath.setDataPath(dataPath); |
pingping-lin | ba5c52f | 2014-02-11 16:52:01 -0800 | [diff] [blame] | 859 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 860 | // TODO: Add the flow by using the new Path Intent framework |
| 861 | /* |
| 862 | if (flowManagerService.addFlow(flowPath) == null) { |
| 863 | log.error("Failed to set up path BGP -> peer {}"+"; dst-TCP-port:179", |
| 864 | bgpPeer.getIpAddress().getHostAddress()); |
| 865 | } |
| 866 | else { |
| 867 | log.debug("Successfully set up path BGP -> peer {}"+"; dst-TCP-port:179", |
| 868 | bgpPeer.getIpAddress().getHostAddress()); |
| 869 | } |
| 870 | */ |
pingping-lin | ba5c52f | 2014-02-11 16:52:01 -0800 | [diff] [blame] | 871 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 872 | // Disable dst-TCP-port, and set src-TCP-port |
| 873 | flowEntryMatch.disableDstTcpUdpPort(); |
| 874 | flowEntryMatch.enableSrcTcpUdpPort(BGP_PORT); |
| 875 | flowPath.setFlowEntryMatch(flowEntryMatch); |
pingping-lin | ba5c52f | 2014-02-11 16:52:01 -0800 | [diff] [blame] | 876 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 877 | // Create a new FlowId |
| 878 | flowPath.setFlowId(new FlowId()); |
pingping-lin | ba5c52f | 2014-02-11 16:52:01 -0800 | [diff] [blame] | 879 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 880 | // TODO: Add the flow by using the new Path Intent framework |
| 881 | /* |
| 882 | if (flowManagerService.addFlow(flowPath) == null) { |
| 883 | log.error("Failed to set up path BGP -> Peer {}" + "; src-TCP-port:179", |
| 884 | bgpPeer.getIpAddress().getHostAddress()); |
| 885 | } |
| 886 | else { |
| 887 | log.debug("Successfully set up path BGP -> Peer {}" + "; src-TCP-port:179", |
| 888 | bgpPeer.getIpAddress().getHostAddress()); |
| 889 | } |
| 890 | */ |
pingping-lin | ba5c52f | 2014-02-11 16:52:01 -0800 | [diff] [blame] | 891 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 892 | /** |
| 893 | * Create the DataPath: BGP <-BGP peer |
| 894 | */ |
| 895 | // Reversed BGP flow path for src-TCP-port |
| 896 | flowPath.setFlowId(new FlowId()); |
pingping-lin | ba5c52f | 2014-02-11 16:52:01 -0800 | [diff] [blame] | 897 | |
Ray Milkey | 2476cac | 2014-04-08 11:03:21 -0700 | [diff] [blame] | 898 | DataPath reverseDataPath = new DataPath(); |
pingping-lin | ba5c52f | 2014-02-11 16:52:01 -0800 | [diff] [blame] | 899 | |
Pavlin Radoslavov | 29a2a88 | 2014-04-08 17:40:54 -0700 | [diff] [blame] | 900 | SwitchPort reverseDstPort = |
| 901 | new SwitchPort(bgpdAttachmentPoint.dpid(), |
| 902 | bgpdAttachmentPoint.port()); |
Ray Milkey | 2476cac | 2014-04-08 11:03:21 -0700 | [diff] [blame] | 903 | reverseDataPath.setDstPort(reverseDstPort); |
pingping-lin | ba5c52f | 2014-02-11 16:52:01 -0800 | [diff] [blame] | 904 | |
Pavlin Radoslavov | 29a2a88 | 2014-04-08 17:40:54 -0700 | [diff] [blame] | 905 | SwitchPort reverseSrcPort = |
| 906 | new SwitchPort(new Dpid(peerInterface.getDpid()), |
| 907 | new Port(peerInterface.getSwitchPort().port())); |
Ray Milkey | 2476cac | 2014-04-08 11:03:21 -0700 | [diff] [blame] | 908 | reverseDataPath.setSrcPort(reverseSrcPort); |
| 909 | flowPath.setDataPath(reverseDataPath); |
pingping-lin | ba5c52f | 2014-02-11 16:52:01 -0800 | [diff] [blame] | 910 | |
Jonathan Hart | 938a015 | 2014-04-07 18:27:31 -0700 | [diff] [blame] | 911 | // Reverse the dst IP and src IP addresses |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 912 | flowEntryMatch.enableDstIPv4Net(srcIPv4Net); |
| 913 | flowEntryMatch.enableSrcIPv4Net(dstIPv4Net); |
| 914 | flowPath.setFlowEntryMatch(flowEntryMatch); |
pingping-lin | ba5c52f | 2014-02-11 16:52:01 -0800 | [diff] [blame] | 915 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 916 | log.debug("Reversed BGP FlowPath: {}", flowPath.toString()); |
pingping-lin | ba5c52f | 2014-02-11 16:52:01 -0800 | [diff] [blame] | 917 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 918 | // TODO: Add the flow by using the new Path Intent framework |
| 919 | /* |
| 920 | if (flowManagerService.addFlow(flowPath) == null) { |
pingping-lin | ba5c52f | 2014-02-11 16:52:01 -0800 | [diff] [blame] | 921 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 922 | log.error("Failed to set up path BGP <- Peer {}" + "; src-TCP-port:179", |
| 923 | bgpPeer.getIpAddress().getHostAddress()); |
| 924 | } |
| 925 | else { |
| 926 | log.debug("Successfully set up path BGP <- Peer {}" + "; src-TCP-port:179", |
| 927 | bgpPeer.getIpAddress().getHostAddress()); |
| 928 | } |
| 929 | */ |
pingping-lin | ba5c52f | 2014-02-11 16:52:01 -0800 | [diff] [blame] | 930 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 931 | // Reversed BGP flow path for dst-TCP-port |
| 932 | flowPath.setFlowId(new FlowId()); |
pingping-lin | ba5c52f | 2014-02-11 16:52:01 -0800 | [diff] [blame] | 933 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 934 | // Disable src-TCP-port, and set the dst-TCP-port |
| 935 | flowEntryMatch.disableSrcTcpUdpPort(); |
| 936 | flowEntryMatch.enableDstTcpUdpPort(BGP_PORT); |
| 937 | flowPath.setFlowEntryMatch(flowEntryMatch); |
pingping-lin | ba5c52f | 2014-02-11 16:52:01 -0800 | [diff] [blame] | 938 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 939 | log.debug("Reversed BGP FlowPath: {}", flowPath.toString()); |
pingping-lin | ba5c52f | 2014-02-11 16:52:01 -0800 | [diff] [blame] | 940 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 941 | // TODO: Add the flow by using the new Path Intent framework |
| 942 | /* |
| 943 | if (flowManagerService.addFlow(flowPath) == null) { |
| 944 | log.error("Failed to setting up path BGP <- Peer {}" + "; dst-TCP-port:179", |
| 945 | bgpPeer.getIpAddress().getHostAddress()); |
| 946 | } |
| 947 | else { |
| 948 | log.debug("Successfully setting up path BGP <- Peer {}" + "; dst-TCP-port:179", |
| 949 | bgpPeer.getIpAddress().getHostAddress()); |
| 950 | } |
| 951 | */ |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 952 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 953 | /** |
| 954 | * ICMP paths between BGPd and its peers |
| 955 | */ |
Jonathan Hart | 938a015 | 2014-04-07 18:27:31 -0700 | [diff] [blame] | 956 | // match ICMP protocol BGP <- Peer |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 957 | flowPath.setFlowId(new FlowId()); |
pingping-lin | ba5c52f | 2014-02-11 16:52:01 -0800 | [diff] [blame] | 958 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 959 | flowEntryMatch.enableIpProto(IPv4.PROTOCOL_ICMP); |
| 960 | flowEntryMatch.disableSrcTcpUdpPort(); |
| 961 | flowEntryMatch.disableDstTcpUdpPort(); |
pingping-lin | ba5c52f | 2014-02-11 16:52:01 -0800 | [diff] [blame] | 962 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 963 | flowPath.setFlowEntryMatch(flowEntryMatch); |
pingping-lin | ba5c52f | 2014-02-11 16:52:01 -0800 | [diff] [blame] | 964 | |
Ray Milkey | 2476cac | 2014-04-08 11:03:21 -0700 | [diff] [blame] | 965 | flowPath.setDataPath(reverseDataPath); |
pingping-lin | ba5c52f | 2014-02-11 16:52:01 -0800 | [diff] [blame] | 966 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 967 | log.debug("Reversed ICMP FlowPath: {}", flowPath.toString()); |
pingping-lin | ba5c52f | 2014-02-11 16:52:01 -0800 | [diff] [blame] | 968 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 969 | // TODO: Add the flow by using the new Path Intent framework |
| 970 | /* |
| 971 | if (flowManagerService.addFlow(flowPath) == null) { |
pingping-lin | ba5c52f | 2014-02-11 16:52:01 -0800 | [diff] [blame] | 972 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 973 | log.error("Failed to set up ICMP path BGP <- Peer {}", |
| 974 | bgpPeer.getIpAddress().getHostAddress()); |
| 975 | } |
| 976 | else { |
| 977 | log.debug("Successfully set up ICMP path BGP <- Peer {}", |
| 978 | bgpPeer.getIpAddress().getHostAddress()); |
| 979 | } |
| 980 | */ |
pingping-lin | ba5c52f | 2014-02-11 16:52:01 -0800 | [diff] [blame] | 981 | |
Jonathan Hart | 938a015 | 2014-04-07 18:27:31 -0700 | [diff] [blame] | 982 | // match ICMP protocol BGP -> Peer |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 983 | flowPath.setFlowId(new FlowId()); |
pingping-lin | ba5c52f | 2014-02-11 16:52:01 -0800 | [diff] [blame] | 984 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 985 | flowEntryMatch.enableDstIPv4Net(dstIPv4Net); |
| 986 | flowEntryMatch.enableSrcIPv4Net(srcIPv4Net); |
| 987 | flowPath.setFlowEntryMatch(flowEntryMatch); |
pingping-lin | ba5c52f | 2014-02-11 16:52:01 -0800 | [diff] [blame] | 988 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 989 | flowPath.setDataPath(dataPath); |
pingping-lin | ba5c52f | 2014-02-11 16:52:01 -0800 | [diff] [blame] | 990 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 991 | log.debug("ICMP flowPath: {}", flowPath.toString()); |
pingping-lin | ba5c52f | 2014-02-11 16:52:01 -0800 | [diff] [blame] | 992 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 993 | // TODO: Add the flow by using the new Path Intent framework |
| 994 | /* |
| 995 | if (flowManagerService.addFlow(flowPath) == null) { |
pingping-lin | ba5c52f | 2014-02-11 16:52:01 -0800 | [diff] [blame] | 996 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 997 | log.error("Failed to set up ICMP path BGP -> Peer {}", |
| 998 | bgpPeer.getIpAddress().getHostAddress()); |
| 999 | } |
| 1000 | else { |
| 1001 | log.debug("Successfully set up ICMP path BGP -> Peer {}", |
| 1002 | bgpPeer.getIpAddress().getHostAddress()); |
| 1003 | } |
| 1004 | */ |
| 1005 | } |
| 1006 | } |
pingping-lin | ba5c52f | 2014-02-11 16:52:01 -0800 | [diff] [blame] | 1007 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 1008 | @Override |
| 1009 | public void arpResponse(InetAddress ipAddress, MACAddress macAddress) { |
| 1010 | log.debug("Received ARP response: {} => {}", |
| 1011 | ipAddress.getHostAddress(), macAddress); |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 1012 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 1013 | /* |
| 1014 | * We synchronize on this to prevent changes to the ptree while we're pushing |
| 1015 | * flows to the switches. If the ptree changes, the ptree and switches |
| 1016 | * could get out of sync. |
| 1017 | */ |
| 1018 | synchronized (this) { |
| 1019 | Path path = pathsWaitingOnArp.remove(ipAddress); |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 1020 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 1021 | if (path != null) { |
| 1022 | log.debug("Pushing path to {} at {} on {}", new Object[]{ |
| 1023 | path.getDstIpAddress().getHostAddress(), macAddress, |
| 1024 | path.getDstInterface().getSwitchPort()}); |
Jonathan Hart | 938a015 | 2014-04-07 18:27:31 -0700 | [diff] [blame] | 1025 | // These paths should always be to BGP peers. Paths to non-peers are |
| 1026 | // handled once the first prefix is ready to push |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 1027 | if (pushedPaths.containsKey(path.getDstIpAddress())) { |
Jonathan Hart | 938a015 | 2014-04-07 18:27:31 -0700 | [diff] [blame] | 1028 | // A path already got pushed to this endpoint while we were waiting |
| 1029 | // for ARP. We'll copy over the permanent attribute if it is set on this path. |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 1030 | if (path.isPermanent()) { |
| 1031 | pushedPaths.get(path.getDstIpAddress()).setPermanent(); |
| 1032 | } |
| 1033 | } else { |
| 1034 | calculateAndPushPath(path, macAddress); |
| 1035 | pushedPaths.put(path.getDstIpAddress(), path); |
| 1036 | } |
| 1037 | } |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 1038 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 1039 | Set<RibUpdate> prefixesToPush = prefixesWaitingOnArp.removeAll(ipAddress); |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 1040 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 1041 | for (RibUpdate update : prefixesToPush) { |
Jonathan Hart | 938a015 | 2014-04-07 18:27:31 -0700 | [diff] [blame] | 1042 | // These will always be adds |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 1043 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 1044 | RibEntry rib = ptree.lookup(update.getPrefix()); |
| 1045 | if (rib != null && rib.equals(update.getRibEntry())) { |
| 1046 | log.debug("Pushing prefix {} next hop {}", update.getPrefix(), |
| 1047 | rib.getNextHop().getHostAddress()); |
Jonathan Hart | 938a015 | 2014-04-07 18:27:31 -0700 | [diff] [blame] | 1048 | // We only push prefix flows if the prefix is still in the ptree |
| 1049 | // and the next hop is the same as our update. The prefix could |
| 1050 | // have been removed while we were waiting for the ARP, or the |
| 1051 | // next hop could have changed. |
Ray Milkey | 7531a34 | 2014-04-11 15:08:12 -0700 | [diff] [blame] | 1052 | executeRibAdd(update); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 1053 | } else { |
| 1054 | log.debug("Received ARP response, but {},{} is no longer in ptree", |
| 1055 | update.getPrefix(), update.getRibEntry()); |
| 1056 | } |
| 1057 | } |
| 1058 | } |
| 1059 | } |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 1060 | |
Jonathan Hart | 938a015 | 2014-04-07 18:27:31 -0700 | [diff] [blame] | 1061 | // TODO wait the priority module of the flow Manager |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 1062 | private void setupArpFlows() { |
| 1063 | OFMatch match = new OFMatch(); |
| 1064 | match.setDataLayerType(Ethernet.TYPE_ARP); |
| 1065 | match.setWildcards(match.getWildcards() & ~OFMatch.OFPFW_DL_TYPE); |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 1066 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 1067 | OFFlowMod fm = new OFFlowMod(); |
| 1068 | fm.setMatch(match); |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 1069 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 1070 | OFActionOutput action = new OFActionOutput(); |
| 1071 | action.setPort(OFPort.OFPP_CONTROLLER.getValue()); |
| 1072 | action.setMaxLength((short) 0xffff); |
| 1073 | List<OFAction> actions = new ArrayList<OFAction>(1); |
| 1074 | actions.add(action); |
| 1075 | fm.setActions(actions); |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 1076 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 1077 | fm.setIdleTimeout((short) 0) |
| 1078 | .setHardTimeout((short) 0) |
| 1079 | .setBufferId(OFPacketOut.BUFFER_ID_NONE) |
| 1080 | .setCookie(0) |
| 1081 | .setCommand(OFFlowMod.OFPFC_ADD) |
| 1082 | .setPriority(ARP_PRIORITY) |
| 1083 | .setLengthU(OFFlowMod.MINIMUM_LENGTH + OFActionOutput.MINIMUM_LENGTH); |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 1084 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 1085 | for (String strdpid : switches) { |
| 1086 | flowCache.write(HexString.toLong(strdpid), fm); |
| 1087 | } |
| 1088 | } |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 1089 | |
Jonathan Hart | 938a015 | 2014-04-07 18:27:31 -0700 | [diff] [blame] | 1090 | // TODO need update, waiting for the priority feature from flow Manager |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 1091 | private void setupDefaultDropFlows() { |
| 1092 | OFFlowMod fm = new OFFlowMod(); |
| 1093 | fm.setMatch(new OFMatch()); |
Jonathan Hart | 938a015 | 2014-04-07 18:27:31 -0700 | [diff] [blame] | 1094 | fm.setActions(new ArrayList<OFAction>()); // No action means drop |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 1095 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 1096 | fm.setIdleTimeout((short) 0) |
| 1097 | .setHardTimeout((short) 0) |
| 1098 | .setBufferId(OFPacketOut.BUFFER_ID_NONE) |
| 1099 | .setCookie(0) |
| 1100 | .setCommand(OFFlowMod.OFPFC_ADD) |
| 1101 | .setPriority((short) 0) |
| 1102 | .setLengthU(OFFlowMod.MINIMUM_LENGTH); |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 1103 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 1104 | OFFlowMod fmLLDP; |
| 1105 | OFFlowMod fmBDDP; |
| 1106 | try { |
| 1107 | fmLLDP = fm.clone(); |
| 1108 | fmBDDP = fm.clone(); |
| 1109 | } catch (CloneNotSupportedException e1) { |
| 1110 | log.error("Error cloning flow mod", e1); |
| 1111 | return; |
| 1112 | } |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 1113 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 1114 | OFMatch matchLLDP = new OFMatch(); |
| 1115 | matchLLDP.setDataLayerType((short) 0x88cc); |
| 1116 | matchLLDP.setWildcards(matchLLDP.getWildcards() & ~OFMatch.OFPFW_DL_TYPE); |
| 1117 | fmLLDP.setMatch(matchLLDP); |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 1118 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 1119 | OFMatch matchBDDP = new OFMatch(); |
| 1120 | matchBDDP.setDataLayerType((short) 0x8942); |
| 1121 | matchBDDP.setWildcards(matchBDDP.getWildcards() & ~OFMatch.OFPFW_DL_TYPE); |
| 1122 | fmBDDP.setMatch(matchBDDP); |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 1123 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 1124 | OFActionOutput action = new OFActionOutput(); |
| 1125 | action.setPort(OFPort.OFPP_CONTROLLER.getValue()); |
| 1126 | action.setMaxLength((short) 0xffff); |
| 1127 | List<OFAction> actions = new ArrayList<OFAction>(1); |
| 1128 | actions.add(action); |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 1129 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 1130 | fmLLDP.setActions(actions); |
| 1131 | fmBDDP.setActions(actions); |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 1132 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 1133 | fmLLDP.setPriority(ARP_PRIORITY); |
| 1134 | fmLLDP.setLengthU(OFFlowMod.MINIMUM_LENGTH + OFActionOutput.MINIMUM_LENGTH); |
| 1135 | fmBDDP.setPriority(ARP_PRIORITY); |
| 1136 | fmBDDP.setLengthU(OFFlowMod.MINIMUM_LENGTH + OFActionOutput.MINIMUM_LENGTH); |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 1137 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 1138 | List<OFFlowMod> flowModList = new ArrayList<OFFlowMod>(3); |
| 1139 | flowModList.add(fm); |
| 1140 | flowModList.add(fmLLDP); |
| 1141 | flowModList.add(fmBDDP); |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 1142 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 1143 | for (String strdpid : switches) { |
| 1144 | flowCache.write(HexString.toLong(strdpid), flowModList); |
| 1145 | } |
| 1146 | } |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 1147 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 1148 | private void beginRouting() { |
| 1149 | log.debug("Topology is now ready, beginning routing function"); |
| 1150 | // TODO: Fix for the new Topology Network Graph |
| 1151 | // topology = topologyNetService.newDatabaseTopology(); |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 1152 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 1153 | // Wait Pavlin's API. We need the following functions. |
| 1154 | /*setupArpFlows(); |
| 1155 | setupDefaultDropFlows();*/ |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 1156 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 1157 | setupBgpPaths(); |
| 1158 | setupFullMesh(); |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 1159 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 1160 | //Suppress link discovery on external-facing router ports |
| 1161 | for (Interface intf : interfaces.values()) { |
Pavlin Radoslavov | 7d21c0a | 2014-04-10 10:32:59 -0700 | [diff] [blame] | 1162 | linkDiscoveryService.addToSuppressLLDPs(intf.getDpid(), intf.getPort()); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 1163 | } |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 1164 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 1165 | bgpUpdatesExecutor.execute(new Runnable() { |
| 1166 | @Override |
| 1167 | public void run() { |
| 1168 | doUpdatesThread(); |
| 1169 | } |
| 1170 | }); |
| 1171 | } |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 1172 | |
Jonathan Hart | 938a015 | 2014-04-07 18:27:31 -0700 | [diff] [blame] | 1173 | // Before inserting the paths for BGP traffic, we should check whether |
| 1174 | // all the switches in the configuration file are discovered by ONOS |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 1175 | private void checkSwitchesConnected() { |
Jonathan Hart | 938a015 | 2014-04-07 18:27:31 -0700 | [diff] [blame] | 1176 | // TODO: Fix the code below after topoSwitchSerice was removed |
| 1177 | /* |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 1178 | for (String dpid : switches) { |
Ray Milkey | 5d40601 | 2014-04-08 14:44:41 -0700 | [diff] [blame] | 1179 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 1180 | Iterator<ISwitchObject> activeSwitches = topoSwitchService. |
| 1181 | getActiveSwitches().iterator(); |
| 1182 | while(activeSwitches.hasNext()) |
| 1183 | { |
| 1184 | ISwitchObject switchObject = activeSwitches.next(); |
| 1185 | if (switchObject.getDPID().equals(dpid)) { |
| 1186 | break; |
| 1187 | } |
| 1188 | if(activeSwitches.hasNext() == false) { |
| 1189 | log.debug("Not all switches are here yet"); |
| 1190 | return; |
| 1191 | } |
| 1192 | } |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 1193 | } |
| 1194 | switchesConnected = true; |
Jonathan Hart | 938a015 | 2014-04-07 18:27:31 -0700 | [diff] [blame] | 1195 | */ |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 1196 | } |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 1197 | |
Jonathan Hart | 938a015 | 2014-04-07 18:27:31 -0700 | [diff] [blame] | 1198 | // Actually we only need to go half way round to verify full mesh connectivity |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 1199 | private void checkTopologyReady() { |
| 1200 | for (Interface dstInterface : interfaces.values()) { |
| 1201 | for (Interface srcInterface : interfaces.values()) { |
| 1202 | if (dstInterface.equals(srcInterface)) { |
| 1203 | continue; |
| 1204 | } |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 1205 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 1206 | // TODO: Fix for the new Topology Network Graph |
| 1207 | /* |
| 1208 | DataPath shortestPath = topologyNetService.getDatabaseShortestPath( |
| 1209 | srcInterface.getSwitchPort(), dstInterface.getSwitchPort()); |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 1210 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 1211 | if (shortestPath == null){ |
| 1212 | log.debug("Shortest path between {} and {} not found", |
| 1213 | srcInterface.getSwitchPort(), dstInterface.getSwitchPort()); |
| 1214 | return; |
| 1215 | } |
| 1216 | */ |
| 1217 | } |
| 1218 | } |
| 1219 | topologyReady = true; |
| 1220 | } |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 1221 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 1222 | private void checkStatus() { |
| 1223 | if (!switchesConnected) { |
| 1224 | checkSwitchesConnected(); |
| 1225 | } |
| 1226 | boolean oldTopologyReadyStatus = topologyReady; |
| 1227 | if (switchesConnected && !topologyReady) { |
| 1228 | checkTopologyReady(); |
| 1229 | } |
| 1230 | if (!oldTopologyReadyStatus && topologyReady) { |
| 1231 | beginRouting(); |
| 1232 | } |
| 1233 | } |
Jonathan Hart | a23ffdb | 2013-08-14 14:36:54 +1200 | [diff] [blame] | 1234 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 1235 | private void doUpdatesThread() { |
| 1236 | boolean interrupted = false; |
| 1237 | try { |
| 1238 | while (true) { |
| 1239 | try { |
| 1240 | RibUpdate update = ribUpdates.take(); |
| 1241 | switch (update.getOperation()) { |
| 1242 | case UPDATE: |
| 1243 | if (validateUpdate(update)) { |
| 1244 | processRibAdd(update); |
| 1245 | } else { |
| 1246 | log.debug("Rib UPDATE out of order: {} via {}", |
| 1247 | update.getPrefix(), update.getRibEntry().getNextHop()); |
| 1248 | } |
| 1249 | break; |
| 1250 | case DELETE: |
| 1251 | if (validateUpdate(update)) { |
| 1252 | processRibDelete(update); |
| 1253 | } else { |
| 1254 | log.debug("Rib DELETE out of order: {} via {}", |
| 1255 | update.getPrefix(), update.getRibEntry().getNextHop()); |
| 1256 | } |
| 1257 | break; |
| 1258 | } |
| 1259 | } catch (InterruptedException e) { |
| 1260 | log.debug("Interrupted while taking from updates queue", e); |
| 1261 | interrupted = true; |
| 1262 | } catch (Exception e) { |
| 1263 | log.debug("exception", e); |
| 1264 | } |
| 1265 | } |
| 1266 | } finally { |
| 1267 | if (interrupted) { |
| 1268 | Thread.currentThread().interrupt(); |
| 1269 | } |
| 1270 | } |
| 1271 | } |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 1272 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 1273 | private boolean validateUpdate(RibUpdate update) { |
| 1274 | RibEntry newEntry = update.getRibEntry(); |
| 1275 | RibEntry oldEntry = ptree.lookup(update.getPrefix()); |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 1276 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 1277 | //If there is no existing entry we must assume this is the most recent |
| 1278 | //update. However this might not always be the case as we might have a |
| 1279 | //POST then DELETE reordering. |
| 1280 | //if (oldEntry == null || !newEntry.getNextHop().equals(oldEntry.getNextHop())) { |
| 1281 | if (oldEntry == null) { |
| 1282 | return true; |
| 1283 | } |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 1284 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 1285 | // This handles the case where routes are gathered in the initial |
| 1286 | // request because they don't have sequence number info |
| 1287 | if (newEntry.getSysUpTime() == -1 && newEntry.getSequenceNum() == -1) { |
| 1288 | return true; |
| 1289 | } |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 1290 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 1291 | if (newEntry.getSysUpTime() > oldEntry.getSysUpTime()) { |
| 1292 | return true; |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 1293 | } |
Ray Milkey | 4985f21 | 2014-04-10 16:57:05 -0700 | [diff] [blame] | 1294 | |
| 1295 | return newEntry.getSysUpTime() == oldEntry.getSysUpTime() && |
| 1296 | newEntry.getSequenceNum() > oldEntry.getSequenceNum(); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 1297 | } |
pingping-lin | a2cbfad | 2013-03-07 08:39:21 +0800 | [diff] [blame] | 1298 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 1299 | // The code below should be reimplemented after removal of Floodlight's |
| 1300 | // ITopologyService API. It should be implemented on top of network graph |
| 1301 | // notifications. (It was pretty hacky anyway...) |
| 1302 | /* |
| 1303 | @Override |
| 1304 | public void topologyChanged() { |
| 1305 | if (topologyReady) { |
| 1306 | return; |
| 1307 | } |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 1308 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 1309 | boolean refreshNeeded = false; |
| 1310 | for (LDUpdate ldu : topologyService.getLastLinkUpdates()){ |
| 1311 | if (!ldu.getOperation().equals(ILinkDiscovery.UpdateOperation.LINK_UPDATED)){ |
| 1312 | //We don't need to recalculate anything for just link updates |
| 1313 | //They happen very frequently |
| 1314 | refreshNeeded = true; |
| 1315 | } |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 1316 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 1317 | log.debug("Topo change {}", ldu.getOperation()); |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 1318 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 1319 | if (ldu.getOperation().equals(ILinkDiscovery.UpdateOperation.LINK_ADDED)){ |
| 1320 | synchronized (linkUpdates) { |
| 1321 | linkUpdates.add(ldu); |
| 1322 | } |
| 1323 | } |
| 1324 | } |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 1325 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 1326 | if (refreshNeeded && !topologyReady){ |
| 1327 | topologyChangeDetectorTask.reschedule(TOPO_DETECTION_WAIT, TimeUnit.SECONDS); |
| 1328 | } |
| 1329 | } |
| 1330 | */ |
Jonathan Hart | 64c0b20 | 2013-08-20 15:45:07 +1200 | [diff] [blame] | 1331 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 1332 | @Override |
| 1333 | public void addedSwitch(IOFSwitch sw) { |
| 1334 | if (!topologyReady) { |
| 1335 | sw.clearAllFlowMods(); |
| 1336 | } |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 1337 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 1338 | flowCache.switchConnected(sw); |
| 1339 | } |
Jonathan Hart | 64c0b20 | 2013-08-20 15:45:07 +1200 | [diff] [blame] | 1340 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 1341 | @Override |
| 1342 | public void removedSwitch(IOFSwitch sw) { |
Jonathan Hart | 938a015 | 2014-04-07 18:27:31 -0700 | [diff] [blame] | 1343 | // Not used |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 1344 | } |
Jonathan Hart | 64c0b20 | 2013-08-20 15:45:07 +1200 | [diff] [blame] | 1345 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 1346 | @Override |
| 1347 | public void switchPortChanged(Long switchId) { |
Jonathan Hart | 938a015 | 2014-04-07 18:27:31 -0700 | [diff] [blame] | 1348 | // Not used |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 1349 | } |
Jonathan Hart | 64c0b20 | 2013-08-20 15:45:07 +1200 | [diff] [blame] | 1350 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 1351 | @Override |
| 1352 | public String getName() { |
| 1353 | return "BgpRoute"; |
| 1354 | } |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 1355 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 1356 | /* |
| 1357 | * IConfigInfoService methods |
| 1358 | */ |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 1359 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 1360 | @Override |
| 1361 | public boolean isInterfaceAddress(InetAddress address) { |
| 1362 | Interface intf = interfacePtrie.match(new Prefix(address.getAddress(), 32)); |
| 1363 | return (intf != null && intf.getIpAddress().equals(address)); |
| 1364 | } |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 1365 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 1366 | @Override |
| 1367 | public boolean inConnectedNetwork(InetAddress address) { |
| 1368 | Interface intf = interfacePtrie.match(new Prefix(address.getAddress(), 32)); |
| 1369 | return (intf != null && !intf.getIpAddress().equals(address)); |
| 1370 | } |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 1371 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 1372 | @Override |
| 1373 | public boolean fromExternalNetwork(long inDpid, short inPort) { |
| 1374 | for (Interface intf : interfaces.values()) { |
| 1375 | if (intf.getDpid() == inDpid && intf.getPort() == inPort) { |
| 1376 | return true; |
| 1377 | } |
| 1378 | } |
| 1379 | return false; |
| 1380 | } |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 1381 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 1382 | @Override |
| 1383 | public Interface getOutgoingInterface(InetAddress dstIpAddress) { |
| 1384 | return interfacePtrie.match(new Prefix(dstIpAddress.getAddress(), 32)); |
| 1385 | } |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 1386 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 1387 | @Override |
| 1388 | public boolean hasLayer3Configuration() { |
| 1389 | return !interfaces.isEmpty(); |
| 1390 | } |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 1391 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 1392 | @Override |
| 1393 | public MACAddress getRouterMacAddress() { |
| 1394 | return bgpdMacAddress; |
| 1395 | } |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 1396 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 1397 | @Override |
| 1398 | public short getVlan() { |
| 1399 | return vlan; |
| 1400 | } |
pingping-lin | a2cbfad | 2013-03-07 08:39:21 +0800 | [diff] [blame] | 1401 | } |