blob: 4325c4ed19b2052afd233f91e2ee138b3b3e0363 [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'Connor67c6e662014-02-17 15:20:44 -080043 // convert flow entries and create pairs
44 for(FlowEntry entry : phase) {
Brian O'Connor488e5ed2014-02-20 19:50:01 -080045 IOFSwitch sw = switches.get(entry.getSwitch());
46 entries.add(new Pair<>(sw, entry.getFlowEntry()));
Brian O'Connor67c6e662014-02-17 15:20:44 -080047 }
Brian O'Connor9b712f62014-02-20 14:22:20 -080048 log.debug("Pushing flow entries: {}", entries);
Brian O'Connor67c6e662014-02-17 15:20:44 -080049 // push flow entries to switches
50 pusher.pushFlowEntries(entries);
51 // TODO: wait for confirmation messages before proceeding
52 }
Brian O'Connor488e5ed2014-02-20 19:50:01 -080053 // TODO: we assume that the plan installation succeeds for now
54 return true;
Brian O'Connor67c6e662014-02-17 15:20:44 -080055 }
56
57}