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