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 |
| 417 | _processDeletePrefix(prefix, rib); |
| 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 | |
Jonathan Hart | 938a015 | 2014-04-07 18:27:31 -0700 | [diff] [blame] | 429 | _processRibAdd(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 | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 433 | private void _processRibAdd(RibUpdate update) { |
| 434 | Prefix prefix = update.getPrefix(); |
| 435 | RibEntry rib = update.getRibEntry(); |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 436 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 437 | InetAddress dstIpAddress = rib.getNextHop(); |
| 438 | MACAddress nextHopMacAddress = null; |
pingping-lin | ba5c52f | 2014-02-11 16:52:01 -0800 | [diff] [blame] | 439 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 440 | // See if we know the MAC address of the next hop |
| 441 | // TODO if we do not treat the next hop as a device in the future, we need to update this |
| 442 | // TODO: Fix the code below after deviceStorage was removed |
| 443 | /* |
| 444 | IDeviceObject nextHopDevice = |
| 445 | deviceStorage.getDeviceByIP(InetAddresses.coerceToInteger(dstIpAddress)); |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 446 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 447 | if (nextHopDevice == null){ |
| 448 | log.debug("NextHopDevice for IP: {} is null", dstIpAddress); |
| 449 | prefixesWaitingOnArp.put(dstIpAddress, |
| 450 | new RibUpdate(Operation.UPDATE, prefix, rib)); |
| 451 | proxyArp.sendArpRequest(dstIpAddress, this, true); |
| 452 | return; |
pingping-lin | ba5c52f | 2014-02-11 16:52:01 -0800 | [diff] [blame] | 453 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 454 | } |
| 455 | nextHopMacAddress = MACAddress.valueOf(nextHopDevice.getMACAddress()); |
| 456 | */ |
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 | } |
| 499 | } |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 500 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 501 | /** |
| 502 | * Add a flow to match dst-IP prefix and rewrite MAC for one IP prefix |
| 503 | * to all other border switches |
| 504 | */ |
| 505 | private void addPrefixFlows(Prefix prefix, Interface egressInterface, |
| 506 | MACAddress nextHopMacAddress) { |
| 507 | log.debug("Adding flows for prefix {}, next hop mac {}", |
| 508 | prefix, nextHopMacAddress); |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 509 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 510 | FlowPath flowPath = new FlowPath(); |
| 511 | flowPath.setInstallerId(new CallerId("SDNIP")); |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 512 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 513 | // Set flowPath FlowPathType and FlowPathUserState |
| 514 | flowPath.setFlowPathType(FlowPathType.FP_TYPE_SHORTEST_PATH); |
| 515 | flowPath.setFlowPathUserState(FlowPathUserState.FP_USER_ADD); |
pingping-lin | ba5c52f | 2014-02-11 16:52:01 -0800 | [diff] [blame] | 516 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 517 | // Insert dst-ip prefix based forwarding and MAC rewrite flow entry |
| 518 | // only to the first-host switches |
| 519 | FlowPathFlags flowPathFlags = new FlowPathFlags(); |
| 520 | flowPathFlags.setFlags(FlowPathFlags.KEEP_ONLY_FIRST_HOP_ENTRY); |
| 521 | flowPath.setFlowPathFlags(flowPathFlags); |
pingping-lin | ba5c52f | 2014-02-11 16:52:01 -0800 | [diff] [blame] | 522 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 523 | // Create the DataPath object: dstSwitchPort |
Pavlin Radoslavov | 29a2a88 | 2014-04-08 17:40:54 -0700 | [diff] [blame] | 524 | SwitchPort dstPort = |
| 525 | new SwitchPort(new Dpid(egressInterface.getDpid()), |
| 526 | new Port(egressInterface.getPort())); |
pingping-lin | ba5c52f | 2014-02-11 16:52:01 -0800 | [diff] [blame] | 527 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 528 | // We only need one flow mod per switch, so pick one interface on each switch |
| 529 | Map<Long, Interface> srcInterfaces = new HashMap<Long, Interface>(); |
| 530 | for (Interface intf : interfaces.values()) { |
| 531 | if (!srcInterfaces.containsKey(intf.getDpid()) |
| 532 | && !intf.equals(egressInterface)) { |
| 533 | srcInterfaces.put(intf.getDpid(), intf); |
| 534 | } |
| 535 | } |
| 536 | for (Interface srcInterface : srcInterfaces.values()) { |
pingping-lin | ba5c52f | 2014-02-11 16:52:01 -0800 | [diff] [blame] | 537 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 538 | if (egressInterface.equals(srcInterface)) { |
| 539 | continue; |
| 540 | } |
pingping-lin | ba5c52f | 2014-02-11 16:52:01 -0800 | [diff] [blame] | 541 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 542 | // Create flowPath FlowId |
| 543 | flowPath.setFlowId(new FlowId()); |
pingping-lin | ba5c52f | 2014-02-11 16:52:01 -0800 | [diff] [blame] | 544 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 545 | // Create DataPath object: srcSwitchPort |
Pavlin Radoslavov | 29a2a88 | 2014-04-08 17:40:54 -0700 | [diff] [blame] | 546 | SwitchPort srcPort = |
| 547 | new SwitchPort(new Dpid(srcInterface.getDpid()), |
| 548 | new Port(srcInterface.getPort())); |
pingping-lin | ba5c52f | 2014-02-11 16:52:01 -0800 | [diff] [blame] | 549 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 550 | DataPath dataPath = new DataPath(); |
| 551 | dataPath.setSrcPort(srcPort); |
| 552 | dataPath.setDstPort(dstPort); |
| 553 | flowPath.setDataPath(dataPath); |
pingping-lin | ba5c52f | 2014-02-11 16:52:01 -0800 | [diff] [blame] | 554 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 555 | // Create flow path matching condition(s): IPv4 Prefix |
| 556 | FlowEntryMatch flowEntryMatch = new FlowEntryMatch(); |
Ray Milkey | 5c9f2db | 2014-04-09 10:31:21 -0700 | [diff] [blame] | 557 | flowEntryMatch.enableEthernetFrameType(Ethernet.TYPE_IPV4); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 558 | IPv4Net dstIPv4Net = new IPv4Net(prefix.toString()); |
| 559 | flowEntryMatch.enableDstIPv4Net(dstIPv4Net); |
| 560 | flowPath.setFlowEntryMatch(flowEntryMatch); |
Jonathan Hart | 1912afc | 2013-10-11 12:02:44 +1300 | [diff] [blame] | 561 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 562 | /* |
| 563 | * Create the Flow Entry Action(s): dst-MAC rewrite action |
| 564 | */ |
| 565 | FlowEntryActions flowEntryActions = new FlowEntryActions(); |
| 566 | FlowEntryAction flowEntryAction1 = new FlowEntryAction(); |
| 567 | flowEntryAction1.setActionSetEthernetDstAddr(nextHopMacAddress); |
| 568 | // flowEntryAction1.actionSetEthernetDstAddr(nextHopMacAddress); |
| 569 | flowEntryActions.addAction(flowEntryAction1); |
| 570 | flowPath.setFlowEntryActions(flowEntryActions); |
pingping-lin | ba5c52f | 2014-02-11 16:52:01 -0800 | [diff] [blame] | 571 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 572 | // Flow Path installation, only to first hop switches |
| 573 | // TODO: Add the flow by using the new Path Intent framework |
| 574 | /* |
| 575 | if (flowManagerService.addFlow(flowPath) == null) { |
| 576 | log.error("Failed to install flow path to the first hop for " + |
| 577 | "prefix: {}, nextHopMacAddress: {}", prefix.getAddress(), |
| 578 | nextHopMacAddress); |
| 579 | } |
| 580 | else { |
| 581 | log.debug("Successfully installed flow path to the first hop " + |
| 582 | "for prefix: {}, nextHopMacAddress: {}", prefix.getAddress(), |
| 583 | nextHopMacAddress); |
pingping-lin | ba5c52f | 2014-02-11 16:52:01 -0800 | [diff] [blame] | 584 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 585 | pushedFlowIds.put(prefix, flowPath.flowId()); |
| 586 | } |
| 587 | */ |
| 588 | } |
| 589 | } |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 590 | |
Jonathan Hart | 938a015 | 2014-04-07 18:27:31 -0700 | [diff] [blame] | 591 | public void processRibDelete(RibUpdate update) { |
| 592 | synchronized (this) { |
| 593 | Prefix prefix = update.getPrefix(); |
Ray Milkey | 5d40601 | 2014-04-08 14:44:41 -0700 | [diff] [blame] | 594 | |
Jonathan Hart | 938a015 | 2014-04-07 18:27:31 -0700 | [diff] [blame] | 595 | if (ptree.remove(prefix, update.getRibEntry())) { |
| 596 | /* |
| 597 | * Only delete flows if an entry was actually removed from the trie. |
| 598 | * If no entry was removed, the <prefix, nexthop> wasn't there so |
| 599 | * it's probably already been removed and we don't need to do anything |
| 600 | */ |
| 601 | _processDeletePrefix(prefix, update.getRibEntry()); |
| 602 | } |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 603 | } |
| 604 | } |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 605 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 606 | private void _processDeletePrefix(Prefix prefix, RibEntry ribEntry) { |
| 607 | deletePrefixFlows(prefix); |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 608 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 609 | log.debug("Deleting {} to {}", prefix, ribEntry.getNextHop()); |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 610 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 611 | if (!bgpPeers.containsKey(ribEntry.getNextHop())) { |
| 612 | log.debug("Getting path for route with non-peer nexthop"); |
| 613 | Path path = prefixToPath.remove(prefix); |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 614 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 615 | if (path != null) { |
| 616 | //path could be null if we added to the Ptree but didn't push |
| 617 | //flows yet because we were waiting to resolve ARP |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 618 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 619 | path.decrementUsers(); |
| 620 | if (path.getUsers() <= 0 && !path.isPermanent()) { |
| 621 | deletePath(path); |
| 622 | pushedPaths.remove(path.getDstIpAddress()); |
| 623 | } |
| 624 | } |
| 625 | } |
| 626 | } |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 627 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 628 | // TODO have not tested this module |
| 629 | private void deletePrefixFlows(Prefix prefix) { |
| 630 | log.debug("Deleting flows for prefix {}", prefix); |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 631 | |
Pavlin Radoslavov | 3255ae5 | 2014-04-09 13:01:54 -0700 | [diff] [blame] | 632 | // |
| 633 | // TODO: Delete the flow by using the new Path Intent framework |
| 634 | // NOTE: During the refactoring of the code below, if obtaining |
| 635 | // the values of the removed flowIds is needed, the first |
| 636 | // removeAll() statement should be replaced with the second removeAll() |
| 637 | // statement. |
| 638 | // |
| 639 | pushedFlowIds.removeAll(prefix); |
| 640 | /* |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 641 | Collection<FlowId> flowIds = pushedFlowIds.removeAll(prefix); |
| 642 | for (FlowId flowId : flowIds) { |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 643 | if (log.isTraceEnabled()) { |
| 644 | //Trace the flow status by flowPath in the switch before deleting it |
| 645 | log.trace("Pushing a DELETE flow mod to flowPath : {}", |
| 646 | flowManagerService.getFlow(flowId).toString()); |
| 647 | } |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 648 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 649 | if( flowManagerService.deleteFlow(flowId)) |
| 650 | { |
| 651 | log.debug("Successfully deleted FlowId: {}",flowId); |
| 652 | } |
| 653 | else |
| 654 | { |
| 655 | log.debug("Failed to delete FlowId: {}",flowId); |
| 656 | } |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 657 | } |
Pavlin Radoslavov | 3255ae5 | 2014-04-09 13:01:54 -0700 | [diff] [blame] | 658 | */ |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 659 | } |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 660 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 661 | // TODO need to record the path and then delete here |
| 662 | private void deletePath(Path path) { |
| 663 | log.debug("Deleting flows for path to {}", |
| 664 | path.getDstIpAddress().getHostAddress()); |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 665 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 666 | // TODO need update |
| 667 | /*for (PushedFlowMod pfm : path.getFlowMods()) { |
| 668 | if (log.isTraceEnabled()) { |
| 669 | log.trace("Pushing a DELETE flow mod to {}, dst MAC {}", |
| 670 | new Object[] {HexString.toHexString(pfm.getDpid()), |
| 671 | HexString.toHexString(pfm.getFlowMod().getMatch().getDataLayerDestination()) |
| 672 | }); |
| 673 | } |
pingping-lin | ba5c52f | 2014-02-11 16:52:01 -0800 | [diff] [blame] | 674 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 675 | sendDeleteFlowMod(pfm.getFlowMod(), pfm.getDpid()); |
| 676 | }*/ |
| 677 | } |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 678 | |
| 679 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 680 | //TODO test next-hop changes |
| 681 | //TODO check delete/add synchronization |
pingping-lin | ba5c52f | 2014-02-11 16:52:01 -0800 | [diff] [blame] | 682 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 683 | /** |
| 684 | * On startup, we need to calculate a full mesh of paths between all gateway |
| 685 | * switches |
| 686 | */ |
| 687 | private void setupFullMesh() { |
| 688 | //For each border router, calculate and install a path from every other |
| 689 | //border switch to said border router. However, don't install the entry |
| 690 | //in to the first hop switch, as we need to install an entry to rewrite |
| 691 | //for each prefix received. This will be done later when prefixes have |
| 692 | //actually been received. |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 693 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 694 | for (BgpPeer peer : bgpPeers.values()) { |
| 695 | Interface peerInterface = interfaces.get(peer.getInterfaceName()); |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 696 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 697 | //We know there's not already a Path here pushed, because this is |
| 698 | //called before all other routing |
| 699 | Path path = new Path(peerInterface, peer.getIpAddress()); |
| 700 | path.setPermanent(); |
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 | //See if we know the MAC address of the peer. If not we can't |
| 703 | //do anything until we learn it |
| 704 | // TODO: Fix the code below after deviceStorage was removed |
| 705 | MACAddress macAddress = null; |
| 706 | /* |
| 707 | IDeviceObject nextHopDevice = |
| 708 | deviceStorage.getDeviceByIP(InetAddresses.coerceToInteger(peer.getIpAddress())); |
pingping-lin | ba5c52f | 2014-02-11 16:52:01 -0800 | [diff] [blame] | 709 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 710 | if(nextHopDevice == null){ |
| 711 | log.debug("There is no DeviceObject for {}", peer.getIpAddress().getHostAddress()); |
| 712 | //Put in the pending paths list first |
| 713 | pathsWaitingOnArp.put(peer.getIpAddress(), path); |
| 714 | proxyArp.sendArpRequest(peer.getIpAddress(), this, true); |
| 715 | continue; |
| 716 | } |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 717 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 718 | macAddress = MACAddress.valueOf(nextHopDevice.getMACAddress()); |
| 719 | */ |
pingping-lin | ba5c52f | 2014-02-11 16:52:01 -0800 | [diff] [blame] | 720 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 721 | if (macAddress == null) { |
| 722 | log.debug("Don't know MAC for {}", peer.getIpAddress().getHostAddress()); |
| 723 | //Put in the pending paths list first |
| 724 | pathsWaitingOnArp.put(peer.getIpAddress(), path); |
| 725 | proxyArp.sendArpRequest(peer.getIpAddress(), this, true); |
| 726 | continue; |
| 727 | } |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 728 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 729 | //If we know the MAC, lets go ahead and push the paths to this peer |
| 730 | calculateAndPushPath(path, macAddress); |
| 731 | } |
| 732 | } |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 733 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 734 | private void calculateAndPushPath(Path path, MACAddress dstMacAddress) { |
| 735 | Interface dstInterface = path.getDstInterface(); |
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 | log.debug("Setting up path to {}, {}", path.getDstIpAddress().getHostAddress(), |
| 738 | dstMacAddress); |
pingping-lin | ba5c52f | 2014-02-11 16:52:01 -0800 | [diff] [blame] | 739 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 740 | FlowPath flowPath = new FlowPath(); |
pingping-lin | ba5c52f | 2014-02-11 16:52:01 -0800 | [diff] [blame] | 741 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 742 | flowPath.setInstallerId(new CallerId("SDNIP")); |
pingping-lin | ba5c52f | 2014-02-11 16:52:01 -0800 | [diff] [blame] | 743 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 744 | // Set flowPath FlowPathType and FlowPathUserState |
| 745 | flowPath.setFlowPathType(FlowPathType.FP_TYPE_SHORTEST_PATH); |
| 746 | flowPath.setFlowPathUserState(FlowPathUserState.FP_USER_ADD); |
pingping-lin | ba5c52f | 2014-02-11 16:52:01 -0800 | [diff] [blame] | 747 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 748 | // Insert the dest-mac based forwarding flow entry to the non-first-hop switches |
| 749 | FlowPathFlags flowPathFlags = new FlowPathFlags(); |
| 750 | flowPathFlags.setFlags(FlowPathFlags.DISCARD_FIRST_HOP_ENTRY); |
| 751 | flowPath.setFlowPathFlags(flowPathFlags); |
| 752 | |
| 753 | // Create the DataPath object: dstSwitchPort |
Pavlin Radoslavov | 29a2a88 | 2014-04-08 17:40:54 -0700 | [diff] [blame] | 754 | SwitchPort dstPort = |
| 755 | new SwitchPort(new Dpid(dstInterface.getDpid()), |
| 756 | new Port(dstInterface.getPort())); |
pingping-lin | ba5c52f | 2014-02-11 16:52:01 -0800 | [diff] [blame] | 757 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 758 | for (Interface srcInterface : interfaces.values()) { |
pingping-lin | ba5c52f | 2014-02-11 16:52:01 -0800 | [diff] [blame] | 759 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 760 | if (dstInterface.equals(srcInterface)) { |
| 761 | continue; |
| 762 | } |
pingping-lin | ba5c52f | 2014-02-11 16:52:01 -0800 | [diff] [blame] | 763 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 764 | // Create flowPath FlowId |
| 765 | flowPath.setFlowId(new FlowId()); |
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 the DataPath object: srcSwitchPort |
Pavlin Radoslavov | 29a2a88 | 2014-04-08 17:40:54 -0700 | [diff] [blame] | 768 | SwitchPort srcPort = |
| 769 | new SwitchPort(new Dpid(srcInterface.getDpid()), |
| 770 | new Port(srcInterface.getPort())); |
pingping-lin | ba5c52f | 2014-02-11 16:52:01 -0800 | [diff] [blame] | 771 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 772 | DataPath dataPath = new DataPath(); |
| 773 | dataPath.setSrcPort(srcPort); |
| 774 | dataPath.setDstPort(dstPort); |
| 775 | flowPath.setDataPath(dataPath); |
pingping-lin | ba5c52f | 2014-02-11 16:52:01 -0800 | [diff] [blame] | 776 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 777 | // Create the Flow Path Match condition(s) |
| 778 | FlowEntryMatch flowEntryMatch = new FlowEntryMatch(); |
Ray Milkey | 5c9f2db | 2014-04-09 10:31:21 -0700 | [diff] [blame] | 779 | flowEntryMatch.enableEthernetFrameType(Ethernet.TYPE_IPV4); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 780 | flowEntryMatch.enableDstMac(dstMacAddress); |
| 781 | flowPath.setFlowEntryMatch(flowEntryMatch); |
pingping-lin | ba5c52f | 2014-02-11 16:52:01 -0800 | [diff] [blame] | 782 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 783 | // NOTE: No need to add ACTION_OUTPUT. It is implied when creating |
| 784 | // Shortest Path Flow, and is always the last action for the Flow Entries |
| 785 | log.debug("FlowPath of MAC based forwarding: {}", flowPath.toString()); |
| 786 | // TODO: Add the flow by using the new Path Intent framework |
| 787 | /* |
| 788 | if (flowManagerService.addFlow(flowPath) == null) { |
| 789 | log.error("Failed to set up MAC based forwarding path to {}, {}", |
| 790 | path.getDstIpAddress().getHostAddress(),dstMacAddress); |
| 791 | } |
| 792 | else { |
| 793 | log.debug("Successfully set up MAC based forwarding path to {}, {}", |
| 794 | path.getDstIpAddress().getHostAddress(),dstMacAddress); |
| 795 | } |
| 796 | */ |
| 797 | } |
| 798 | } |
pingping-lin | ba5c52f | 2014-02-11 16:52:01 -0800 | [diff] [blame] | 799 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 800 | /** |
Jonathan Hart | 938a015 | 2014-04-07 18:27:31 -0700 | [diff] [blame] | 801 | * Proactively install all BGP traffic paths from BGP host attachment point |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 802 | * in SDN network to all the virtual gateways to BGP peers in other networks |
| 803 | */ |
| 804 | private void setupBgpPaths() { |
Jonathan Hart | 832a7cb | 2013-06-24 11:25:35 +1200 | [diff] [blame] | 805 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 806 | for (BgpPeer bgpPeer : bgpPeers.values()) { |
pingping-lin | ba5c52f | 2014-02-11 16:52:01 -0800 | [diff] [blame] | 807 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 808 | FlowPath flowPath = new FlowPath(); |
| 809 | flowPath.setInstallerId(new CallerId("SDNIP")); |
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 | // Set flowPath FlowPathType and FlowPathUserState |
| 812 | flowPath.setFlowPathType(FlowPathType.FP_TYPE_SHORTEST_PATH); |
| 813 | flowPath.setFlowPathUserState(FlowPathUserState.FP_USER_ADD); |
pingping-lin | ba5c52f | 2014-02-11 16:52:01 -0800 | [diff] [blame] | 814 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 815 | // Install flow paths between BGPd and its peers |
| 816 | // There is no need to set the FlowPathFlags |
| 817 | flowPath.setFlowPathFlags(new FlowPathFlags(0)); |
pingping-lin | ba5c52f | 2014-02-11 16:52:01 -0800 | [diff] [blame] | 818 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 819 | Interface peerInterface = interfaces.get(bgpPeer.getInterfaceName()); |
pingping-lin | ba5c52f | 2014-02-11 16:52:01 -0800 | [diff] [blame] | 820 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 821 | // Create the Flow Path Match condition(s) |
| 822 | FlowEntryMatch flowEntryMatch = new FlowEntryMatch(); |
Ray Milkey | 5c9f2db | 2014-04-09 10:31:21 -0700 | [diff] [blame] | 823 | flowEntryMatch.enableEthernetFrameType(Ethernet.TYPE_IPV4); |
pingping-lin | ba5c52f | 2014-02-11 16:52:01 -0800 | [diff] [blame] | 824 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 825 | // Match both source address and dest address |
| 826 | IPv4Net dstIPv4Net = new IPv4Net(bgpPeer.getIpAddress().getHostAddress() + "/32"); |
| 827 | flowEntryMatch.enableDstIPv4Net(dstIPv4Net); |
pingping-lin | ba5c52f | 2014-02-11 16:52:01 -0800 | [diff] [blame] | 828 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 829 | IPv4Net srcIPv4Net = new IPv4Net(peerInterface.getIpAddress().getHostAddress() + "/32"); |
| 830 | flowEntryMatch.enableSrcIPv4Net(srcIPv4Net); |
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 | // Match TCP protocol |
| 833 | flowEntryMatch.enableIpProto(IPv4.PROTOCOL_TCP); |
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 destination TCP port |
| 836 | flowEntryMatch.enableDstTcpUdpPort(BGP_PORT); |
| 837 | flowPath.setFlowEntryMatch(flowEntryMatch); |
pingping-lin | ba5c52f | 2014-02-11 16:52:01 -0800 | [diff] [blame] | 838 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 839 | /** |
| 840 | * Create the DataPath: BGP -> BGP peer |
| 841 | */ |
| 842 | // Flow path for src-TCP-port |
| 843 | DataPath dataPath = new DataPath(); |
pingping-lin | ba5c52f | 2014-02-11 16:52:01 -0800 | [diff] [blame] | 844 | |
Pavlin Radoslavov | 29a2a88 | 2014-04-08 17:40:54 -0700 | [diff] [blame] | 845 | SwitchPort srcPort = |
| 846 | new SwitchPort(bgpdAttachmentPoint.dpid(), |
| 847 | bgpdAttachmentPoint.port()); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 848 | dataPath.setSrcPort(srcPort); |
pingping-lin | ba5c52f | 2014-02-11 16:52:01 -0800 | [diff] [blame] | 849 | |
Pavlin Radoslavov | 29a2a88 | 2014-04-08 17:40:54 -0700 | [diff] [blame] | 850 | SwitchPort dstPort = |
| 851 | new SwitchPort(new Dpid(peerInterface.getDpid()), |
| 852 | new Port(peerInterface.getSwitchPort().port())); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 853 | dataPath.setDstPort(dstPort); |
pingping-lin | ba5c52f | 2014-02-11 16:52:01 -0800 | [diff] [blame] | 854 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 855 | flowPath.setDataPath(dataPath); |
pingping-lin | ba5c52f | 2014-02-11 16:52:01 -0800 | [diff] [blame] | 856 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 857 | // TODO: Add the flow by using the new Path Intent framework |
| 858 | /* |
| 859 | if (flowManagerService.addFlow(flowPath) == null) { |
| 860 | log.error("Failed to set up path BGP -> peer {}"+"; dst-TCP-port:179", |
| 861 | bgpPeer.getIpAddress().getHostAddress()); |
| 862 | } |
| 863 | else { |
| 864 | log.debug("Successfully set up path BGP -> peer {}"+"; dst-TCP-port:179", |
| 865 | bgpPeer.getIpAddress().getHostAddress()); |
| 866 | } |
| 867 | */ |
pingping-lin | ba5c52f | 2014-02-11 16:52:01 -0800 | [diff] [blame] | 868 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 869 | // Disable dst-TCP-port, and set src-TCP-port |
| 870 | flowEntryMatch.disableDstTcpUdpPort(); |
| 871 | flowEntryMatch.enableSrcTcpUdpPort(BGP_PORT); |
| 872 | flowPath.setFlowEntryMatch(flowEntryMatch); |
pingping-lin | ba5c52f | 2014-02-11 16:52:01 -0800 | [diff] [blame] | 873 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 874 | // Create a new FlowId |
| 875 | flowPath.setFlowId(new FlowId()); |
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 | // TODO: Add the flow by using the new Path Intent framework |
| 878 | /* |
| 879 | if (flowManagerService.addFlow(flowPath) == null) { |
| 880 | log.error("Failed to set up path BGP -> Peer {}" + "; src-TCP-port:179", |
| 881 | bgpPeer.getIpAddress().getHostAddress()); |
| 882 | } |
| 883 | else { |
| 884 | log.debug("Successfully set up path BGP -> Peer {}" + "; src-TCP-port:179", |
| 885 | bgpPeer.getIpAddress().getHostAddress()); |
| 886 | } |
| 887 | */ |
pingping-lin | ba5c52f | 2014-02-11 16:52:01 -0800 | [diff] [blame] | 888 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 889 | /** |
| 890 | * Create the DataPath: BGP <-BGP peer |
| 891 | */ |
| 892 | // Reversed BGP flow path for src-TCP-port |
| 893 | flowPath.setFlowId(new FlowId()); |
pingping-lin | ba5c52f | 2014-02-11 16:52:01 -0800 | [diff] [blame] | 894 | |
Ray Milkey | 2476cac | 2014-04-08 11:03:21 -0700 | [diff] [blame] | 895 | DataPath reverseDataPath = new DataPath(); |
pingping-lin | ba5c52f | 2014-02-11 16:52:01 -0800 | [diff] [blame] | 896 | |
Pavlin Radoslavov | 29a2a88 | 2014-04-08 17:40:54 -0700 | [diff] [blame] | 897 | SwitchPort reverseDstPort = |
| 898 | new SwitchPort(bgpdAttachmentPoint.dpid(), |
| 899 | bgpdAttachmentPoint.port()); |
Ray Milkey | 2476cac | 2014-04-08 11:03:21 -0700 | [diff] [blame] | 900 | reverseDataPath.setDstPort(reverseDstPort); |
pingping-lin | ba5c52f | 2014-02-11 16:52:01 -0800 | [diff] [blame] | 901 | |
Pavlin Radoslavov | 29a2a88 | 2014-04-08 17:40:54 -0700 | [diff] [blame] | 902 | SwitchPort reverseSrcPort = |
| 903 | new SwitchPort(new Dpid(peerInterface.getDpid()), |
| 904 | new Port(peerInterface.getSwitchPort().port())); |
Ray Milkey | 2476cac | 2014-04-08 11:03:21 -0700 | [diff] [blame] | 905 | reverseDataPath.setSrcPort(reverseSrcPort); |
| 906 | flowPath.setDataPath(reverseDataPath); |
pingping-lin | ba5c52f | 2014-02-11 16:52:01 -0800 | [diff] [blame] | 907 | |
Jonathan Hart | 938a015 | 2014-04-07 18:27:31 -0700 | [diff] [blame] | 908 | // Reverse the dst IP and src IP addresses |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 909 | flowEntryMatch.enableDstIPv4Net(srcIPv4Net); |
| 910 | flowEntryMatch.enableSrcIPv4Net(dstIPv4Net); |
| 911 | flowPath.setFlowEntryMatch(flowEntryMatch); |
pingping-lin | ba5c52f | 2014-02-11 16:52:01 -0800 | [diff] [blame] | 912 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 913 | log.debug("Reversed BGP FlowPath: {}", flowPath.toString()); |
pingping-lin | ba5c52f | 2014-02-11 16:52:01 -0800 | [diff] [blame] | 914 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 915 | // TODO: Add the flow by using the new Path Intent framework |
| 916 | /* |
| 917 | if (flowManagerService.addFlow(flowPath) == null) { |
pingping-lin | ba5c52f | 2014-02-11 16:52:01 -0800 | [diff] [blame] | 918 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 919 | log.error("Failed to set up path BGP <- Peer {}" + "; src-TCP-port:179", |
| 920 | bgpPeer.getIpAddress().getHostAddress()); |
| 921 | } |
| 922 | else { |
| 923 | log.debug("Successfully set up path BGP <- Peer {}" + "; src-TCP-port:179", |
| 924 | bgpPeer.getIpAddress().getHostAddress()); |
| 925 | } |
| 926 | */ |
pingping-lin | ba5c52f | 2014-02-11 16:52:01 -0800 | [diff] [blame] | 927 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 928 | // Reversed BGP flow path for dst-TCP-port |
| 929 | flowPath.setFlowId(new FlowId()); |
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 | // Disable src-TCP-port, and set the dst-TCP-port |
| 932 | flowEntryMatch.disableSrcTcpUdpPort(); |
| 933 | flowEntryMatch.enableDstTcpUdpPort(BGP_PORT); |
| 934 | flowPath.setFlowEntryMatch(flowEntryMatch); |
pingping-lin | ba5c52f | 2014-02-11 16:52:01 -0800 | [diff] [blame] | 935 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 936 | log.debug("Reversed BGP FlowPath: {}", flowPath.toString()); |
pingping-lin | ba5c52f | 2014-02-11 16:52:01 -0800 | [diff] [blame] | 937 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 938 | // TODO: Add the flow by using the new Path Intent framework |
| 939 | /* |
| 940 | if (flowManagerService.addFlow(flowPath) == null) { |
| 941 | log.error("Failed to setting up path BGP <- Peer {}" + "; dst-TCP-port:179", |
| 942 | bgpPeer.getIpAddress().getHostAddress()); |
| 943 | } |
| 944 | else { |
| 945 | log.debug("Successfully setting up path BGP <- Peer {}" + "; dst-TCP-port:179", |
| 946 | bgpPeer.getIpAddress().getHostAddress()); |
| 947 | } |
| 948 | */ |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 949 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 950 | /** |
| 951 | * ICMP paths between BGPd and its peers |
| 952 | */ |
Jonathan Hart | 938a015 | 2014-04-07 18:27:31 -0700 | [diff] [blame] | 953 | // match ICMP protocol BGP <- Peer |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 954 | flowPath.setFlowId(new FlowId()); |
pingping-lin | ba5c52f | 2014-02-11 16:52:01 -0800 | [diff] [blame] | 955 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 956 | flowEntryMatch.enableIpProto(IPv4.PROTOCOL_ICMP); |
| 957 | flowEntryMatch.disableSrcTcpUdpPort(); |
| 958 | flowEntryMatch.disableDstTcpUdpPort(); |
pingping-lin | ba5c52f | 2014-02-11 16:52:01 -0800 | [diff] [blame] | 959 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 960 | flowPath.setFlowEntryMatch(flowEntryMatch); |
pingping-lin | ba5c52f | 2014-02-11 16:52:01 -0800 | [diff] [blame] | 961 | |
Ray Milkey | 2476cac | 2014-04-08 11:03:21 -0700 | [diff] [blame] | 962 | flowPath.setDataPath(reverseDataPath); |
pingping-lin | ba5c52f | 2014-02-11 16:52:01 -0800 | [diff] [blame] | 963 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 964 | log.debug("Reversed ICMP FlowPath: {}", flowPath.toString()); |
pingping-lin | ba5c52f | 2014-02-11 16:52:01 -0800 | [diff] [blame] | 965 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 966 | // TODO: Add the flow by using the new Path Intent framework |
| 967 | /* |
| 968 | if (flowManagerService.addFlow(flowPath) == null) { |
pingping-lin | ba5c52f | 2014-02-11 16:52:01 -0800 | [diff] [blame] | 969 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 970 | log.error("Failed to set up ICMP path BGP <- Peer {}", |
| 971 | bgpPeer.getIpAddress().getHostAddress()); |
| 972 | } |
| 973 | else { |
| 974 | log.debug("Successfully set up ICMP path BGP <- Peer {}", |
| 975 | bgpPeer.getIpAddress().getHostAddress()); |
| 976 | } |
| 977 | */ |
pingping-lin | ba5c52f | 2014-02-11 16:52:01 -0800 | [diff] [blame] | 978 | |
Jonathan Hart | 938a015 | 2014-04-07 18:27:31 -0700 | [diff] [blame] | 979 | // match ICMP protocol BGP -> Peer |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 980 | flowPath.setFlowId(new FlowId()); |
pingping-lin | ba5c52f | 2014-02-11 16:52:01 -0800 | [diff] [blame] | 981 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 982 | flowEntryMatch.enableDstIPv4Net(dstIPv4Net); |
| 983 | flowEntryMatch.enableSrcIPv4Net(srcIPv4Net); |
| 984 | flowPath.setFlowEntryMatch(flowEntryMatch); |
pingping-lin | ba5c52f | 2014-02-11 16:52:01 -0800 | [diff] [blame] | 985 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 986 | flowPath.setDataPath(dataPath); |
pingping-lin | ba5c52f | 2014-02-11 16:52:01 -0800 | [diff] [blame] | 987 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 988 | log.debug("ICMP flowPath: {}", flowPath.toString()); |
pingping-lin | ba5c52f | 2014-02-11 16:52:01 -0800 | [diff] [blame] | 989 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 990 | // TODO: Add the flow by using the new Path Intent framework |
| 991 | /* |
| 992 | if (flowManagerService.addFlow(flowPath) == null) { |
pingping-lin | ba5c52f | 2014-02-11 16:52:01 -0800 | [diff] [blame] | 993 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 994 | log.error("Failed to set up ICMP path BGP -> Peer {}", |
| 995 | bgpPeer.getIpAddress().getHostAddress()); |
| 996 | } |
| 997 | else { |
| 998 | log.debug("Successfully set up ICMP path BGP -> Peer {}", |
| 999 | bgpPeer.getIpAddress().getHostAddress()); |
| 1000 | } |
| 1001 | */ |
| 1002 | } |
| 1003 | } |
pingping-lin | ba5c52f | 2014-02-11 16:52:01 -0800 | [diff] [blame] | 1004 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 1005 | @Override |
| 1006 | public void arpResponse(InetAddress ipAddress, MACAddress macAddress) { |
| 1007 | log.debug("Received ARP response: {} => {}", |
| 1008 | ipAddress.getHostAddress(), macAddress); |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 1009 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 1010 | /* |
| 1011 | * We synchronize on this to prevent changes to the ptree while we're pushing |
| 1012 | * flows to the switches. If the ptree changes, the ptree and switches |
| 1013 | * could get out of sync. |
| 1014 | */ |
| 1015 | synchronized (this) { |
| 1016 | Path path = pathsWaitingOnArp.remove(ipAddress); |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 1017 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 1018 | if (path != null) { |
| 1019 | log.debug("Pushing path to {} at {} on {}", new Object[]{ |
| 1020 | path.getDstIpAddress().getHostAddress(), macAddress, |
| 1021 | path.getDstInterface().getSwitchPort()}); |
Jonathan Hart | 938a015 | 2014-04-07 18:27:31 -0700 | [diff] [blame] | 1022 | // These paths should always be to BGP peers. Paths to non-peers are |
| 1023 | // handled once the first prefix is ready to push |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 1024 | if (pushedPaths.containsKey(path.getDstIpAddress())) { |
Jonathan Hart | 938a015 | 2014-04-07 18:27:31 -0700 | [diff] [blame] | 1025 | // A path already got pushed to this endpoint while we were waiting |
| 1026 | // 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] | 1027 | if (path.isPermanent()) { |
| 1028 | pushedPaths.get(path.getDstIpAddress()).setPermanent(); |
| 1029 | } |
| 1030 | } else { |
| 1031 | calculateAndPushPath(path, macAddress); |
| 1032 | pushedPaths.put(path.getDstIpAddress(), path); |
| 1033 | } |
| 1034 | } |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 1035 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 1036 | Set<RibUpdate> prefixesToPush = prefixesWaitingOnArp.removeAll(ipAddress); |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 1037 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 1038 | for (RibUpdate update : prefixesToPush) { |
Jonathan Hart | 938a015 | 2014-04-07 18:27:31 -0700 | [diff] [blame] | 1039 | // These will always be adds |
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 | RibEntry rib = ptree.lookup(update.getPrefix()); |
| 1042 | if (rib != null && rib.equals(update.getRibEntry())) { |
| 1043 | log.debug("Pushing prefix {} next hop {}", update.getPrefix(), |
| 1044 | rib.getNextHop().getHostAddress()); |
Jonathan Hart | 938a015 | 2014-04-07 18:27:31 -0700 | [diff] [blame] | 1045 | // We only push prefix flows if the prefix is still in the ptree |
| 1046 | // and the next hop is the same as our update. The prefix could |
| 1047 | // have been removed while we were waiting for the ARP, or the |
| 1048 | // next hop could have changed. |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 1049 | _processRibAdd(update); |
| 1050 | } else { |
| 1051 | log.debug("Received ARP response, but {},{} is no longer in ptree", |
| 1052 | update.getPrefix(), update.getRibEntry()); |
| 1053 | } |
| 1054 | } |
| 1055 | } |
| 1056 | } |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 1057 | |
Jonathan Hart | 938a015 | 2014-04-07 18:27:31 -0700 | [diff] [blame] | 1058 | // TODO wait the priority module of the flow Manager |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 1059 | private void setupArpFlows() { |
| 1060 | OFMatch match = new OFMatch(); |
| 1061 | match.setDataLayerType(Ethernet.TYPE_ARP); |
| 1062 | match.setWildcards(match.getWildcards() & ~OFMatch.OFPFW_DL_TYPE); |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 1063 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 1064 | OFFlowMod fm = new OFFlowMod(); |
| 1065 | fm.setMatch(match); |
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 | OFActionOutput action = new OFActionOutput(); |
| 1068 | action.setPort(OFPort.OFPP_CONTROLLER.getValue()); |
| 1069 | action.setMaxLength((short) 0xffff); |
| 1070 | List<OFAction> actions = new ArrayList<OFAction>(1); |
| 1071 | actions.add(action); |
| 1072 | fm.setActions(actions); |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 1073 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 1074 | fm.setIdleTimeout((short) 0) |
| 1075 | .setHardTimeout((short) 0) |
| 1076 | .setBufferId(OFPacketOut.BUFFER_ID_NONE) |
| 1077 | .setCookie(0) |
| 1078 | .setCommand(OFFlowMod.OFPFC_ADD) |
| 1079 | .setPriority(ARP_PRIORITY) |
| 1080 | .setLengthU(OFFlowMod.MINIMUM_LENGTH + OFActionOutput.MINIMUM_LENGTH); |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 1081 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 1082 | for (String strdpid : switches) { |
| 1083 | flowCache.write(HexString.toLong(strdpid), fm); |
| 1084 | } |
| 1085 | } |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 1086 | |
Jonathan Hart | 938a015 | 2014-04-07 18:27:31 -0700 | [diff] [blame] | 1087 | // TODO need update, waiting for the priority feature from flow Manager |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 1088 | private void setupDefaultDropFlows() { |
| 1089 | OFFlowMod fm = new OFFlowMod(); |
| 1090 | fm.setMatch(new OFMatch()); |
Jonathan Hart | 938a015 | 2014-04-07 18:27:31 -0700 | [diff] [blame] | 1091 | fm.setActions(new ArrayList<OFAction>()); // No action means drop |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 1092 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 1093 | fm.setIdleTimeout((short) 0) |
| 1094 | .setHardTimeout((short) 0) |
| 1095 | .setBufferId(OFPacketOut.BUFFER_ID_NONE) |
| 1096 | .setCookie(0) |
| 1097 | .setCommand(OFFlowMod.OFPFC_ADD) |
| 1098 | .setPriority((short) 0) |
| 1099 | .setLengthU(OFFlowMod.MINIMUM_LENGTH); |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 1100 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 1101 | OFFlowMod fmLLDP; |
| 1102 | OFFlowMod fmBDDP; |
| 1103 | try { |
| 1104 | fmLLDP = fm.clone(); |
| 1105 | fmBDDP = fm.clone(); |
| 1106 | } catch (CloneNotSupportedException e1) { |
| 1107 | log.error("Error cloning flow mod", e1); |
| 1108 | return; |
| 1109 | } |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 1110 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 1111 | OFMatch matchLLDP = new OFMatch(); |
| 1112 | matchLLDP.setDataLayerType((short) 0x88cc); |
| 1113 | matchLLDP.setWildcards(matchLLDP.getWildcards() & ~OFMatch.OFPFW_DL_TYPE); |
| 1114 | fmLLDP.setMatch(matchLLDP); |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 1115 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 1116 | OFMatch matchBDDP = new OFMatch(); |
| 1117 | matchBDDP.setDataLayerType((short) 0x8942); |
| 1118 | matchBDDP.setWildcards(matchBDDP.getWildcards() & ~OFMatch.OFPFW_DL_TYPE); |
| 1119 | fmBDDP.setMatch(matchBDDP); |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 1120 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 1121 | OFActionOutput action = new OFActionOutput(); |
| 1122 | action.setPort(OFPort.OFPP_CONTROLLER.getValue()); |
| 1123 | action.setMaxLength((short) 0xffff); |
| 1124 | List<OFAction> actions = new ArrayList<OFAction>(1); |
| 1125 | actions.add(action); |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 1126 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 1127 | fmLLDP.setActions(actions); |
| 1128 | fmBDDP.setActions(actions); |
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.setPriority(ARP_PRIORITY); |
| 1131 | fmLLDP.setLengthU(OFFlowMod.MINIMUM_LENGTH + OFActionOutput.MINIMUM_LENGTH); |
| 1132 | fmBDDP.setPriority(ARP_PRIORITY); |
| 1133 | fmBDDP.setLengthU(OFFlowMod.MINIMUM_LENGTH + OFActionOutput.MINIMUM_LENGTH); |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 1134 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 1135 | List<OFFlowMod> flowModList = new ArrayList<OFFlowMod>(3); |
| 1136 | flowModList.add(fm); |
| 1137 | flowModList.add(fmLLDP); |
| 1138 | flowModList.add(fmBDDP); |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 1139 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 1140 | for (String strdpid : switches) { |
| 1141 | flowCache.write(HexString.toLong(strdpid), flowModList); |
| 1142 | } |
| 1143 | } |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 1144 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 1145 | private void beginRouting() { |
| 1146 | log.debug("Topology is now ready, beginning routing function"); |
| 1147 | // TODO: Fix for the new Topology Network Graph |
| 1148 | // topology = topologyNetService.newDatabaseTopology(); |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 1149 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 1150 | // Wait Pavlin's API. We need the following functions. |
| 1151 | /*setupArpFlows(); |
| 1152 | setupDefaultDropFlows();*/ |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 1153 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 1154 | setupBgpPaths(); |
| 1155 | setupFullMesh(); |
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 | //Suppress link discovery on external-facing router ports |
| 1158 | for (Interface intf : interfaces.values()) { |
| 1159 | linkDiscoveryService.AddToSuppressLLDPs(intf.getDpid(), intf.getPort()); |
| 1160 | } |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 1161 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 1162 | bgpUpdatesExecutor.execute(new Runnable() { |
| 1163 | @Override |
| 1164 | public void run() { |
| 1165 | doUpdatesThread(); |
| 1166 | } |
| 1167 | }); |
| 1168 | } |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 1169 | |
Jonathan Hart | 938a015 | 2014-04-07 18:27:31 -0700 | [diff] [blame] | 1170 | // Before inserting the paths for BGP traffic, we should check whether |
| 1171 | // all the switches in the configuration file are discovered by ONOS |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 1172 | private void checkSwitchesConnected() { |
Jonathan Hart | 938a015 | 2014-04-07 18:27:31 -0700 | [diff] [blame] | 1173 | // TODO: Fix the code below after topoSwitchSerice was removed |
| 1174 | /* |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 1175 | for (String dpid : switches) { |
Ray Milkey | 5d40601 | 2014-04-08 14:44:41 -0700 | [diff] [blame] | 1176 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 1177 | Iterator<ISwitchObject> activeSwitches = topoSwitchService. |
| 1178 | getActiveSwitches().iterator(); |
| 1179 | while(activeSwitches.hasNext()) |
| 1180 | { |
| 1181 | ISwitchObject switchObject = activeSwitches.next(); |
| 1182 | if (switchObject.getDPID().equals(dpid)) { |
| 1183 | break; |
| 1184 | } |
| 1185 | if(activeSwitches.hasNext() == false) { |
| 1186 | log.debug("Not all switches are here yet"); |
| 1187 | return; |
| 1188 | } |
| 1189 | } |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 1190 | } |
| 1191 | switchesConnected = true; |
Jonathan Hart | 938a015 | 2014-04-07 18:27:31 -0700 | [diff] [blame] | 1192 | */ |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 1193 | } |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 1194 | |
Jonathan Hart | 938a015 | 2014-04-07 18:27:31 -0700 | [diff] [blame] | 1195 | // 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] | 1196 | private void checkTopologyReady() { |
| 1197 | for (Interface dstInterface : interfaces.values()) { |
| 1198 | for (Interface srcInterface : interfaces.values()) { |
| 1199 | if (dstInterface.equals(srcInterface)) { |
| 1200 | continue; |
| 1201 | } |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 1202 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 1203 | // TODO: Fix for the new Topology Network Graph |
| 1204 | /* |
| 1205 | DataPath shortestPath = topologyNetService.getDatabaseShortestPath( |
| 1206 | srcInterface.getSwitchPort(), dstInterface.getSwitchPort()); |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 1207 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 1208 | if (shortestPath == null){ |
| 1209 | log.debug("Shortest path between {} and {} not found", |
| 1210 | srcInterface.getSwitchPort(), dstInterface.getSwitchPort()); |
| 1211 | return; |
| 1212 | } |
| 1213 | */ |
| 1214 | } |
| 1215 | } |
| 1216 | topologyReady = true; |
| 1217 | } |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 1218 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 1219 | private void checkStatus() { |
| 1220 | if (!switchesConnected) { |
| 1221 | checkSwitchesConnected(); |
| 1222 | } |
| 1223 | boolean oldTopologyReadyStatus = topologyReady; |
| 1224 | if (switchesConnected && !topologyReady) { |
| 1225 | checkTopologyReady(); |
| 1226 | } |
| 1227 | if (!oldTopologyReadyStatus && topologyReady) { |
| 1228 | beginRouting(); |
| 1229 | } |
| 1230 | } |
Jonathan Hart | a23ffdb | 2013-08-14 14:36:54 +1200 | [diff] [blame] | 1231 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 1232 | private void doUpdatesThread() { |
| 1233 | boolean interrupted = false; |
| 1234 | try { |
| 1235 | while (true) { |
| 1236 | try { |
| 1237 | RibUpdate update = ribUpdates.take(); |
| 1238 | switch (update.getOperation()) { |
| 1239 | case UPDATE: |
| 1240 | if (validateUpdate(update)) { |
| 1241 | processRibAdd(update); |
| 1242 | } else { |
| 1243 | log.debug("Rib UPDATE out of order: {} via {}", |
| 1244 | update.getPrefix(), update.getRibEntry().getNextHop()); |
| 1245 | } |
| 1246 | break; |
| 1247 | case DELETE: |
| 1248 | if (validateUpdate(update)) { |
| 1249 | processRibDelete(update); |
| 1250 | } else { |
| 1251 | log.debug("Rib DELETE out of order: {} via {}", |
| 1252 | update.getPrefix(), update.getRibEntry().getNextHop()); |
| 1253 | } |
| 1254 | break; |
| 1255 | } |
| 1256 | } catch (InterruptedException e) { |
| 1257 | log.debug("Interrupted while taking from updates queue", e); |
| 1258 | interrupted = true; |
| 1259 | } catch (Exception e) { |
| 1260 | log.debug("exception", e); |
| 1261 | } |
| 1262 | } |
| 1263 | } finally { |
| 1264 | if (interrupted) { |
| 1265 | Thread.currentThread().interrupt(); |
| 1266 | } |
| 1267 | } |
| 1268 | } |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 1269 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 1270 | private boolean validateUpdate(RibUpdate update) { |
| 1271 | RibEntry newEntry = update.getRibEntry(); |
| 1272 | RibEntry oldEntry = ptree.lookup(update.getPrefix()); |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 1273 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 1274 | //If there is no existing entry we must assume this is the most recent |
| 1275 | //update. However this might not always be the case as we might have a |
| 1276 | //POST then DELETE reordering. |
| 1277 | //if (oldEntry == null || !newEntry.getNextHop().equals(oldEntry.getNextHop())) { |
| 1278 | if (oldEntry == null) { |
| 1279 | return true; |
| 1280 | } |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 1281 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 1282 | // This handles the case where routes are gathered in the initial |
| 1283 | // request because they don't have sequence number info |
| 1284 | if (newEntry.getSysUpTime() == -1 && newEntry.getSequenceNum() == -1) { |
| 1285 | return true; |
| 1286 | } |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 1287 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 1288 | if (newEntry.getSysUpTime() > oldEntry.getSysUpTime()) { |
| 1289 | return true; |
| 1290 | } else if (newEntry.getSysUpTime() == oldEntry.getSysUpTime()) { |
| 1291 | if (newEntry.getSequenceNum() > oldEntry.getSequenceNum()) { |
| 1292 | return true; |
| 1293 | } else { |
| 1294 | return false; |
| 1295 | } |
| 1296 | } else { |
| 1297 | return false; |
| 1298 | } |
| 1299 | } |
pingping-lin | a2cbfad | 2013-03-07 08:39:21 +0800 | [diff] [blame] | 1300 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 1301 | // The code below should be reimplemented after removal of Floodlight's |
| 1302 | // ITopologyService API. It should be implemented on top of network graph |
| 1303 | // notifications. (It was pretty hacky anyway...) |
| 1304 | /* |
| 1305 | @Override |
| 1306 | public void topologyChanged() { |
| 1307 | if (topologyReady) { |
| 1308 | return; |
| 1309 | } |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 1310 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 1311 | boolean refreshNeeded = false; |
| 1312 | for (LDUpdate ldu : topologyService.getLastLinkUpdates()){ |
| 1313 | if (!ldu.getOperation().equals(ILinkDiscovery.UpdateOperation.LINK_UPDATED)){ |
| 1314 | //We don't need to recalculate anything for just link updates |
| 1315 | //They happen very frequently |
| 1316 | refreshNeeded = true; |
| 1317 | } |
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 | log.debug("Topo change {}", ldu.getOperation()); |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 1320 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 1321 | if (ldu.getOperation().equals(ILinkDiscovery.UpdateOperation.LINK_ADDED)){ |
| 1322 | synchronized (linkUpdates) { |
| 1323 | linkUpdates.add(ldu); |
| 1324 | } |
| 1325 | } |
| 1326 | } |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 1327 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 1328 | if (refreshNeeded && !topologyReady){ |
| 1329 | topologyChangeDetectorTask.reschedule(TOPO_DETECTION_WAIT, TimeUnit.SECONDS); |
| 1330 | } |
| 1331 | } |
| 1332 | */ |
Jonathan Hart | 64c0b20 | 2013-08-20 15:45:07 +1200 | [diff] [blame] | 1333 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 1334 | @Override |
| 1335 | public void addedSwitch(IOFSwitch sw) { |
| 1336 | if (!topologyReady) { |
| 1337 | sw.clearAllFlowMods(); |
| 1338 | } |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 1339 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 1340 | flowCache.switchConnected(sw); |
| 1341 | } |
Jonathan Hart | 64c0b20 | 2013-08-20 15:45:07 +1200 | [diff] [blame] | 1342 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 1343 | @Override |
| 1344 | public void removedSwitch(IOFSwitch sw) { |
Jonathan Hart | 938a015 | 2014-04-07 18:27:31 -0700 | [diff] [blame] | 1345 | // Not used |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 1346 | } |
Jonathan Hart | 64c0b20 | 2013-08-20 15:45:07 +1200 | [diff] [blame] | 1347 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 1348 | @Override |
| 1349 | public void switchPortChanged(Long switchId) { |
Jonathan Hart | 938a015 | 2014-04-07 18:27:31 -0700 | [diff] [blame] | 1350 | // Not used |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 1351 | } |
Jonathan Hart | 64c0b20 | 2013-08-20 15:45:07 +1200 | [diff] [blame] | 1352 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 1353 | @Override |
| 1354 | public String getName() { |
| 1355 | return "BgpRoute"; |
| 1356 | } |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 1357 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 1358 | /* |
| 1359 | * IConfigInfoService methods |
| 1360 | */ |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 1361 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 1362 | @Override |
| 1363 | public boolean isInterfaceAddress(InetAddress address) { |
| 1364 | Interface intf = interfacePtrie.match(new Prefix(address.getAddress(), 32)); |
| 1365 | return (intf != null && intf.getIpAddress().equals(address)); |
| 1366 | } |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 1367 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 1368 | @Override |
| 1369 | public boolean inConnectedNetwork(InetAddress address) { |
| 1370 | Interface intf = interfacePtrie.match(new Prefix(address.getAddress(), 32)); |
| 1371 | return (intf != null && !intf.getIpAddress().equals(address)); |
| 1372 | } |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 1373 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 1374 | @Override |
| 1375 | public boolean fromExternalNetwork(long inDpid, short inPort) { |
| 1376 | for (Interface intf : interfaces.values()) { |
| 1377 | if (intf.getDpid() == inDpid && intf.getPort() == inPort) { |
| 1378 | return true; |
| 1379 | } |
| 1380 | } |
| 1381 | return false; |
| 1382 | } |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 1383 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 1384 | @Override |
| 1385 | public Interface getOutgoingInterface(InetAddress dstIpAddress) { |
| 1386 | return interfacePtrie.match(new Prefix(dstIpAddress.getAddress(), 32)); |
| 1387 | } |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 1388 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 1389 | @Override |
| 1390 | public boolean hasLayer3Configuration() { |
| 1391 | return !interfaces.isEmpty(); |
| 1392 | } |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 1393 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 1394 | @Override |
| 1395 | public MACAddress getRouterMacAddress() { |
| 1396 | return bgpdMacAddress; |
| 1397 | } |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 1398 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 1399 | @Override |
| 1400 | public short getVlan() { |
| 1401 | return vlan; |
| 1402 | } |
pingping-lin | a2cbfad | 2013-03-07 08:39:21 +0800 | [diff] [blame] | 1403 | } |