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