blob: a52487504c4976bacb408361d66be01066890331 [file] [log] [blame]
Brian O'Connor67c6e662014-02-17 15:20:44 -08001package net.onrc.onos.intent.runtime;
2
3import java.util.HashSet;
4import java.util.List;
5import java.util.Map;
6import java.util.Set;
7
8import net.floodlightcontroller.core.IFloodlightProviderService;
9import net.floodlightcontroller.core.IOFSwitch;
10import net.onrc.onos.intent.FlowEntry;
11import net.onrc.onos.ofcontroller.flowprogrammer.IFlowPusherService;
Brian O'Connor488e5ed2014-02-20 19:50:01 -080012//import net.onrc.onos.ofcontroller.networkgraph.NetworkGraph;
Brian O'Connor67c6e662014-02-17 15:20:44 -080013import net.onrc.onos.ofcontroller.util.Pair;
14
Brian O'Connor9b712f62014-02-20 14:22:20 -080015import org.slf4j.Logger;
16import org.slf4j.LoggerFactory;
17
Brian O'Connor67c6e662014-02-17 15:20:44 -080018/**
19 *
20 * @author Brian O'Connor <bocon@onlab.us>
21 *
22 */
23
Brian O'Connor12861f72014-02-19 20:40:32 -080024public class PlanInstallRuntime {
Brian O'Connor488e5ed2014-02-20 19:50:01 -080025// NetworkGraph graph;
Brian O'Connor67c6e662014-02-17 15:20:44 -080026 IFlowPusherService pusher;
27 IFloodlightProviderService provider;
Brian O'Connor9b712f62014-02-20 14:22:20 -080028 private final static Logger log = LoggerFactory.getLogger(PlanInstallRuntime.class);
Brian O'Connor67c6e662014-02-17 15:20:44 -080029
Brian O'Connor488e5ed2014-02-20 19:50:01 -080030 public PlanInstallRuntime(//NetworkGraph graph,
Brian O'Connor12861f72014-02-19 20:40:32 -080031 IFloodlightProviderService provider,
32 IFlowPusherService pusher) {
Brian O'Connor488e5ed2014-02-20 19:50:01 -080033// this.graph = graph;
Brian O'Connor12861f72014-02-19 20:40:32 -080034 this.provider = provider;
35 this.pusher = pusher;
Brian O'Connor67c6e662014-02-17 15:20:44 -080036 }
37
Brian O'Connor488e5ed2014-02-20 19:50:01 -080038 public boolean installPlan(List<Set<FlowEntry>> plan) {
Brian O'Connorc366e872014-02-24 14:08:31 -080039 long start = System.nanoTime();
Brian O'Connor67c6e662014-02-17 15:20:44 -080040 Map<Long,IOFSwitch> switches = provider.getSwitches();
Brian O'Connor9b712f62014-02-20 14:22:20 -080041 log.debug("IOFSwitches: {}", switches);
Brian O'Connor67c6e662014-02-17 15:20:44 -080042 for(Set<FlowEntry> phase : plan) {
Brian O'Connor12861f72014-02-19 20:40:32 -080043 Set<Pair<IOFSwitch, net.onrc.onos.ofcontroller.util.FlowEntry>> entries = new HashSet<>();
Brian O'Connor067b95d2014-02-21 18:43:27 -080044 Set<IOFSwitch> modifiedSwitches = new HashSet<>();
45
Brian O'Connor67c6e662014-02-17 15:20:44 -080046 // convert flow entries and create pairs
47 for(FlowEntry entry : phase) {
Brian O'Connor488e5ed2014-02-20 19:50:01 -080048 IOFSwitch sw = switches.get(entry.getSwitch());
Brian O'Connor067b95d2014-02-21 18:43:27 -080049 if(sw == null) {
50 // no active switch, skip this flow entry
51 log.debug("Skipping flow entry: {}", entry);
52 continue;
53 }
Brian O'Connor488e5ed2014-02-20 19:50:01 -080054 entries.add(new Pair<>(sw, entry.getFlowEntry()));
Brian O'Connor067b95d2014-02-21 18:43:27 -080055 modifiedSwitches.add(sw);
Brian O'Connor67c6e662014-02-17 15:20:44 -080056 }
Brian O'Connor067b95d2014-02-21 18:43:27 -080057
Brian O'Connor67c6e662014-02-17 15:20:44 -080058 // push flow entries to switches
Brian O'Connor067b95d2014-02-21 18:43:27 -080059 log.debug("Pushing flow entries: {}", entries);
Brian O'Connor67c6e662014-02-17 15:20:44 -080060 pusher.pushFlowEntries(entries);
Brian O'Connor067b95d2014-02-21 18:43:27 -080061
62 // TODO: insert a barrier after each phase on each modifiedSwitch
Brian O'Connor67c6e662014-02-17 15:20:44 -080063 // TODO: wait for confirmation messages before proceeding
64 }
Brian O'Connorc366e872014-02-24 14:08:31 -080065 long end = System.nanoTime();
66 log.error("MEASUREMENT: Install plan: {} ns", (end-start));
Brian O'Connor488e5ed2014-02-20 19:50:01 -080067 // TODO: we assume that the plan installation succeeds for now
68 return true;
Brian O'Connor67c6e662014-02-17 15:20:44 -080069 }
70
71}