blob: 844e620edb97bf6d2d4c10c6cc0a98e7ade1fd0b [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'Connor67c6e662014-02-17 15:20:44 -080039 Map<Long,IOFSwitch> switches = provider.getSwitches();
Brian O'Connor9b712f62014-02-20 14:22:20 -080040 log.debug("IOFSwitches: {}", switches);
Brian O'Connor67c6e662014-02-17 15:20:44 -080041 for(Set<FlowEntry> phase : plan) {
Brian O'Connor12861f72014-02-19 20:40:32 -080042 Set<Pair<IOFSwitch, net.onrc.onos.ofcontroller.util.FlowEntry>> entries = new HashSet<>();
Brian O'Connor067b95d2014-02-21 18:43:27 -080043 Set<IOFSwitch> modifiedSwitches = new HashSet<>();
44
Brian O'Connor67c6e662014-02-17 15:20:44 -080045 // convert flow entries and create pairs
46 for(FlowEntry entry : phase) {
Brian O'Connor488e5ed2014-02-20 19:50:01 -080047 IOFSwitch sw = switches.get(entry.getSwitch());
Brian O'Connor067b95d2014-02-21 18:43:27 -080048 if(sw == null) {
49 // no active switch, skip this flow entry
50 log.debug("Skipping flow entry: {}", entry);
51 continue;
52 }
Brian O'Connor488e5ed2014-02-20 19:50:01 -080053 entries.add(new Pair<>(sw, entry.getFlowEntry()));
Brian O'Connor067b95d2014-02-21 18:43:27 -080054 modifiedSwitches.add(sw);
Brian O'Connor67c6e662014-02-17 15:20:44 -080055 }
Brian O'Connor067b95d2014-02-21 18:43:27 -080056
Brian O'Connor67c6e662014-02-17 15:20:44 -080057 // push flow entries to switches
Brian O'Connor067b95d2014-02-21 18:43:27 -080058 log.debug("Pushing flow entries: {}", entries);
Brian O'Connor67c6e662014-02-17 15:20:44 -080059 pusher.pushFlowEntries(entries);
Brian O'Connor067b95d2014-02-21 18:43:27 -080060
61 // TODO: insert a barrier after each phase on each modifiedSwitch
Brian O'Connor67c6e662014-02-17 15:20:44 -080062 // TODO: wait for confirmation messages before proceeding
63 }
Brian O'Connor488e5ed2014-02-20 19:50:01 -080064 // TODO: we assume that the plan installation succeeds for now
65 return true;
Brian O'Connor67c6e662014-02-17 15:20:44 -080066 }
67
68}