blob: 82e0d2373605981eec84b151f5cfcda1ebdbe600 [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;
12import net.onrc.onos.ofcontroller.networkgraph.NetworkGraph;
13import 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'Connor67c6e662014-02-17 15:20:44 -080025 NetworkGraph graph;
26 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'Connor12861f72014-02-19 20:40:32 -080030 public PlanInstallRuntime(NetworkGraph graph,
31 IFloodlightProviderService provider,
32 IFlowPusherService pusher) {
Brian O'Connor67c6e662014-02-17 15:20:44 -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
38 public void 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) {
45 entries.add(new Pair<>(switches.get(entry.getSwitch().getDpid()),
46 entry.getFlowEntry()));
47 }
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 }
53 }
54
55}