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