Brian O'Connor | 67c6e66 | 2014-02-17 15:20:44 -0800 | [diff] [blame] | 1 | package net.onrc.onos.intent.runtime; |
| 2 | |
| 3 | import java.util.HashSet; |
| 4 | import java.util.List; |
| 5 | import java.util.Map; |
| 6 | import java.util.Set; |
| 7 | |
| 8 | import net.floodlightcontroller.core.IFloodlightProviderService; |
| 9 | import net.floodlightcontroller.core.IOFSwitch; |
| 10 | import net.onrc.onos.intent.FlowEntry; |
| 11 | import net.onrc.onos.ofcontroller.flowprogrammer.IFlowPusherService; |
| 12 | import net.onrc.onos.ofcontroller.networkgraph.NetworkGraph; |
| 13 | import net.onrc.onos.ofcontroller.util.Pair; |
| 14 | |
| 15 | /** |
| 16 | * |
| 17 | * @author Brian O'Connor <bocon@onlab.us> |
| 18 | * |
| 19 | */ |
| 20 | |
Brian O'Connor | 12861f7 | 2014-02-19 20:40:32 -0800 | [diff] [blame^] | 21 | public class PlanInstallRuntime { |
Brian O'Connor | 67c6e66 | 2014-02-17 15:20:44 -0800 | [diff] [blame] | 22 | NetworkGraph graph; |
| 23 | IFlowPusherService pusher; |
| 24 | IFloodlightProviderService provider; |
Brian O'Connor | 67c6e66 | 2014-02-17 15:20:44 -0800 | [diff] [blame] | 25 | |
Brian O'Connor | 12861f7 | 2014-02-19 20:40:32 -0800 | [diff] [blame^] | 26 | public PlanInstallRuntime(NetworkGraph graph, |
| 27 | IFloodlightProviderService provider, |
| 28 | IFlowPusherService pusher) { |
Brian O'Connor | 67c6e66 | 2014-02-17 15:20:44 -0800 | [diff] [blame] | 29 | this.graph = graph; |
Brian O'Connor | 12861f7 | 2014-02-19 20:40:32 -0800 | [diff] [blame^] | 30 | this.provider = provider; |
| 31 | this.pusher = pusher; |
Brian O'Connor | 67c6e66 | 2014-02-17 15:20:44 -0800 | [diff] [blame] | 32 | } |
| 33 | |
| 34 | public void installPlan(List<Set<FlowEntry>> plan) { |
Brian O'Connor | 67c6e66 | 2014-02-17 15:20:44 -0800 | [diff] [blame] | 35 | Map<Long,IOFSwitch> switches = provider.getSwitches(); |
| 36 | for(Set<FlowEntry> phase : plan) { |
Brian O'Connor | 12861f7 | 2014-02-19 20:40:32 -0800 | [diff] [blame^] | 37 | Set<Pair<IOFSwitch, net.onrc.onos.ofcontroller.util.FlowEntry>> entries = new HashSet<>(); |
Brian O'Connor | 67c6e66 | 2014-02-17 15:20:44 -0800 | [diff] [blame] | 38 | // convert flow entries and create pairs |
| 39 | for(FlowEntry entry : phase) { |
| 40 | entries.add(new Pair<>(switches.get(entry.getSwitch().getDpid()), |
| 41 | entry.getFlowEntry())); |
| 42 | } |
| 43 | // push flow entries to switches |
| 44 | pusher.pushFlowEntries(entries); |
| 45 | // TODO: wait for confirmation messages before proceeding |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | } |