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