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; |
Brian O'Connor | 488e5ed | 2014-02-20 19:50:01 -0800 | [diff] [blame] | 12 | //import net.onrc.onos.ofcontroller.networkgraph.NetworkGraph; |
Brian O'Connor | 67c6e66 | 2014-02-17 15:20:44 -0800 | [diff] [blame] | 13 | import net.onrc.onos.ofcontroller.util.Pair; |
| 14 | |
Brian O'Connor | 9b712f6 | 2014-02-20 14:22:20 -0800 | [diff] [blame] | 15 | import org.slf4j.Logger; |
| 16 | import org.slf4j.LoggerFactory; |
| 17 | |
Brian O'Connor | 67c6e66 | 2014-02-17 15:20:44 -0800 | [diff] [blame] | 18 | /** |
| 19 | * |
| 20 | * @author Brian O'Connor <bocon@onlab.us> |
| 21 | * |
| 22 | */ |
| 23 | |
Brian O'Connor | 12861f7 | 2014-02-19 20:40:32 -0800 | [diff] [blame] | 24 | public class PlanInstallRuntime { |
Brian O'Connor | 488e5ed | 2014-02-20 19:50:01 -0800 | [diff] [blame] | 25 | // NetworkGraph graph; |
Brian O'Connor | 67c6e66 | 2014-02-17 15:20:44 -0800 | [diff] [blame] | 26 | IFlowPusherService pusher; |
| 27 | IFloodlightProviderService provider; |
Brian O'Connor | 9b712f6 | 2014-02-20 14:22:20 -0800 | [diff] [blame] | 28 | private final static Logger log = LoggerFactory.getLogger(PlanInstallRuntime.class); |
Brian O'Connor | 67c6e66 | 2014-02-17 15:20:44 -0800 | [diff] [blame] | 29 | |
Brian O'Connor | 488e5ed | 2014-02-20 19:50:01 -0800 | [diff] [blame] | 30 | public PlanInstallRuntime(//NetworkGraph graph, |
Brian O'Connor | 12861f7 | 2014-02-19 20:40:32 -0800 | [diff] [blame] | 31 | IFloodlightProviderService provider, |
| 32 | IFlowPusherService pusher) { |
Brian O'Connor | 488e5ed | 2014-02-20 19:50:01 -0800 | [diff] [blame] | 33 | // this.graph = graph; |
Brian O'Connor | 12861f7 | 2014-02-19 20:40:32 -0800 | [diff] [blame] | 34 | this.provider = provider; |
| 35 | this.pusher = pusher; |
Brian O'Connor | 67c6e66 | 2014-02-17 15:20:44 -0800 | [diff] [blame] | 36 | } |
| 37 | |
Brian O'Connor | 488e5ed | 2014-02-20 19:50:01 -0800 | [diff] [blame] | 38 | public boolean installPlan(List<Set<FlowEntry>> plan) { |
Brian O'Connor | 67c6e66 | 2014-02-17 15:20:44 -0800 | [diff] [blame] | 39 | Map<Long,IOFSwitch> switches = provider.getSwitches(); |
Brian O'Connor | 9b712f6 | 2014-02-20 14:22:20 -0800 | [diff] [blame] | 40 | log.debug("IOFSwitches: {}", switches); |
Brian O'Connor | 67c6e66 | 2014-02-17 15:20:44 -0800 | [diff] [blame] | 41 | for(Set<FlowEntry> phase : plan) { |
Brian O'Connor | 12861f7 | 2014-02-19 20:40:32 -0800 | [diff] [blame] | 42 | Set<Pair<IOFSwitch, net.onrc.onos.ofcontroller.util.FlowEntry>> entries = new HashSet<>(); |
Brian O'Connor | 067b95d | 2014-02-21 18:43:27 -0800 | [diff] [blame] | 43 | Set<IOFSwitch> modifiedSwitches = new HashSet<>(); |
| 44 | |
Brian O'Connor | 67c6e66 | 2014-02-17 15:20:44 -0800 | [diff] [blame] | 45 | // convert flow entries and create pairs |
| 46 | for(FlowEntry entry : phase) { |
Brian O'Connor | 488e5ed | 2014-02-20 19:50:01 -0800 | [diff] [blame] | 47 | IOFSwitch sw = switches.get(entry.getSwitch()); |
Brian O'Connor | 067b95d | 2014-02-21 18:43:27 -0800 | [diff] [blame] | 48 | if(sw == null) { |
| 49 | // no active switch, skip this flow entry |
| 50 | log.debug("Skipping flow entry: {}", entry); |
| 51 | continue; |
| 52 | } |
Brian O'Connor | 488e5ed | 2014-02-20 19:50:01 -0800 | [diff] [blame] | 53 | entries.add(new Pair<>(sw, entry.getFlowEntry())); |
Brian O'Connor | 067b95d | 2014-02-21 18:43:27 -0800 | [diff] [blame] | 54 | modifiedSwitches.add(sw); |
Brian O'Connor | 67c6e66 | 2014-02-17 15:20:44 -0800 | [diff] [blame] | 55 | } |
Brian O'Connor | 067b95d | 2014-02-21 18:43:27 -0800 | [diff] [blame] | 56 | |
Brian O'Connor | 67c6e66 | 2014-02-17 15:20:44 -0800 | [diff] [blame] | 57 | // push flow entries to switches |
Brian O'Connor | 067b95d | 2014-02-21 18:43:27 -0800 | [diff] [blame] | 58 | log.debug("Pushing flow entries: {}", entries); |
Brian O'Connor | 67c6e66 | 2014-02-17 15:20:44 -0800 | [diff] [blame] | 59 | pusher.pushFlowEntries(entries); |
Brian O'Connor | 067b95d | 2014-02-21 18:43:27 -0800 | [diff] [blame] | 60 | |
| 61 | // TODO: insert a barrier after each phase on each modifiedSwitch |
Brian O'Connor | 67c6e66 | 2014-02-17 15:20:44 -0800 | [diff] [blame] | 62 | // TODO: wait for confirmation messages before proceeding |
| 63 | } |
Brian O'Connor | 488e5ed | 2014-02-20 19:50:01 -0800 | [diff] [blame] | 64 | // TODO: we assume that the plan installation succeeds for now |
| 65 | return true; |
Brian O'Connor | 67c6e66 | 2014-02-17 15:20:44 -0800 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | } |