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