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