Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 1 | package org.onlab.onos.net.intent.impl; |
| 2 | |
| 3 | import java.util.Iterator; |
| 4 | |
| 5 | import org.apache.felix.scr.annotations.Activate; |
| 6 | import org.apache.felix.scr.annotations.Component; |
| 7 | import org.apache.felix.scr.annotations.Deactivate; |
| 8 | import org.apache.felix.scr.annotations.Reference; |
| 9 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
| 10 | import org.onlab.onos.ApplicationId; |
| 11 | import org.onlab.onos.net.ConnectPoint; |
| 12 | import org.onlab.onos.net.Link; |
| 13 | import org.onlab.onos.net.flow.DefaultFlowRule; |
| 14 | import org.onlab.onos.net.flow.DefaultTrafficSelector; |
| 15 | import org.onlab.onos.net.flow.DefaultTrafficTreatment; |
| 16 | import org.onlab.onos.net.flow.FlowRule; |
| 17 | import org.onlab.onos.net.flow.FlowRuleService; |
| 18 | import org.onlab.onos.net.flow.TrafficSelector; |
| 19 | import org.onlab.onos.net.flow.TrafficTreatment; |
| 20 | import org.onlab.onos.net.flow.criteria.Criterion; |
| 21 | import org.onlab.onos.net.intent.IntentExtensionService; |
| 22 | import org.onlab.onos.net.intent.IntentInstaller; |
| 23 | import org.onlab.onos.net.intent.PathIntent; |
| 24 | |
| 25 | /** |
| 26 | * An intent installer for {@link PathIntent}. |
| 27 | */ |
| 28 | @Component(immediate = true) |
| 29 | public class PathIntentInstaller |
| 30 | implements IntentInstaller<PathIntent> { |
| 31 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 32 | protected IntentExtensionService intentManager; |
| 33 | |
| 34 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 35 | private FlowRuleService flowRuleService; |
| 36 | |
| 37 | private final ApplicationId appId = ApplicationId.valueOf(1); |
| 38 | |
| 39 | @Activate |
| 40 | public void activate() { |
| 41 | intentManager.registerInstaller(PathIntent.class, this); |
| 42 | } |
| 43 | |
| 44 | @Deactivate |
| 45 | public void deactivate() { |
| 46 | intentManager.unregisterInstaller(PathIntent.class); |
| 47 | } |
| 48 | |
| 49 | @Override |
| 50 | public void install(PathIntent intent) { |
| 51 | TrafficSelector.Builder builder = new DefaultTrafficSelector.Builder(); |
| 52 | TrafficSelector selector = intent.getTrafficSelector(); |
| 53 | for (Criterion c : selector.criteria()) { |
| 54 | builder.add(c); |
| 55 | } |
| 56 | |
| 57 | Iterator<Link> links = intent.getPath().links().iterator(); |
| 58 | ConnectPoint prev = links.next().dst(); |
| 59 | while (links.hasNext()) { |
| 60 | builder.matchInport(prev.port()); |
| 61 | Link link = links.next(); |
| 62 | |
| 63 | TrafficTreatment.Builder treat = new DefaultTrafficTreatment.Builder(); |
| 64 | treat.setOutput(link.src().port()); |
| 65 | |
| 66 | FlowRule f = new DefaultFlowRule(link.src().deviceId(), |
tom | 008126b | 2014-10-02 21:31:37 -0700 | [diff] [blame^] | 67 | builder.build(), treat.build(), 0, appId, 0); |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 68 | flowRuleService.applyFlowRules(f); |
| 69 | |
| 70 | prev = link.dst(); |
| 71 | } |
| 72 | |
| 73 | } |
| 74 | |
| 75 | @Override |
| 76 | public void uninstall(PathIntent intent) { |
| 77 | //TODO |
| 78 | } |
| 79 | } |