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