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