Pier Ventre
Committed by Gerrit Code Review

Fix [ONOS-4857] and impement [ONOS-5143]

Change-Id: I7159ff9deaacaf10070e1535f4a80f2f846a5784
...@@ -16,7 +16,9 @@ ...@@ -16,7 +16,9 @@
16 package org.onosproject.net.intent.impl.compiler; 16 package org.onosproject.net.intent.impl.compiler;
17 17
18 import com.google.common.collect.HashMultimap; 18 import com.google.common.collect.HashMultimap;
19 +import com.google.common.collect.ImmutableSet;
19 import com.google.common.collect.SetMultimap; 20 import com.google.common.collect.SetMultimap;
21 +import com.google.common.collect.Sets;
20 import org.apache.felix.scr.annotations.Activate; 22 import org.apache.felix.scr.annotations.Activate;
21 import org.apache.felix.scr.annotations.Component; 23 import org.apache.felix.scr.annotations.Component;
22 import org.apache.felix.scr.annotations.Deactivate; 24 import org.apache.felix.scr.annotations.Deactivate;
...@@ -24,14 +26,8 @@ import org.apache.felix.scr.annotations.Reference; ...@@ -24,14 +26,8 @@ import org.apache.felix.scr.annotations.Reference;
24 import org.apache.felix.scr.annotations.ReferenceCardinality; 26 import org.apache.felix.scr.annotations.ReferenceCardinality;
25 import org.onosproject.core.ApplicationId; 27 import org.onosproject.core.ApplicationId;
26 import org.onosproject.core.CoreService; 28 import org.onosproject.core.CoreService;
27 -import org.onosproject.net.ConnectPoint;
28 import org.onosproject.net.DeviceId; 29 import org.onosproject.net.DeviceId;
29 -import org.onosproject.net.Link;
30 import org.onosproject.net.PortNumber; 30 import org.onosproject.net.PortNumber;
31 -import org.onosproject.net.flow.DefaultTrafficSelector;
32 -import org.onosproject.net.flow.DefaultTrafficTreatment;
33 -import org.onosproject.net.flow.TrafficSelector;
34 -import org.onosproject.net.flow.TrafficTreatment;
35 import org.onosproject.net.flowobjective.DefaultForwardingObjective; 31 import org.onosproject.net.flowobjective.DefaultForwardingObjective;
36 import org.onosproject.net.flowobjective.DefaultNextObjective; 32 import org.onosproject.net.flowobjective.DefaultNextObjective;
37 import org.onosproject.net.flowobjective.FlowObjectiveService; 33 import org.onosproject.net.flowobjective.FlowObjectiveService;
...@@ -47,13 +43,14 @@ import java.util.ArrayList; ...@@ -47,13 +43,14 @@ import java.util.ArrayList;
47 import java.util.Collections; 43 import java.util.Collections;
48 import java.util.List; 44 import java.util.List;
49 import java.util.Set; 45 import java.util.Set;
50 -import java.util.stream.Collectors;
51 46
52 /** 47 /**
53 * Compiler to produce flow objectives from link collections. 48 * Compiler to produce flow objectives from link collections.
54 */ 49 */
55 @Component(immediate = true) 50 @Component(immediate = true)
56 -public class LinkCollectionIntentFlowObjectivesCompiler implements IntentCompiler<LinkCollectionIntent> { 51 +public class LinkCollectionIntentFlowObjectiveCompiler
52 + extends LinkCollectionCompiler<Objective>
53 + implements IntentCompiler<LinkCollectionIntent> {
57 54
58 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 55 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
59 protected IntentConfigurableRegistrator registrator; 56 protected IntentConfigurableRegistrator registrator;
...@@ -79,21 +76,11 @@ public class LinkCollectionIntentFlowObjectivesCompiler implements IntentCompile ...@@ -79,21 +76,11 @@ public class LinkCollectionIntentFlowObjectivesCompiler implements IntentCompile
79 76
80 @Override 77 @Override
81 public List<Intent> compile(LinkCollectionIntent intent, List<Intent> installable) { 78 public List<Intent> compile(LinkCollectionIntent intent, List<Intent> installable) {
79 +
82 SetMultimap<DeviceId, PortNumber> inputPorts = HashMultimap.create(); 80 SetMultimap<DeviceId, PortNumber> inputPorts = HashMultimap.create();
83 SetMultimap<DeviceId, PortNumber> outputPorts = HashMultimap.create(); 81 SetMultimap<DeviceId, PortNumber> outputPorts = HashMultimap.create();
84 82
85 - for (Link link : intent.links()) { 83 + computePorts(intent, inputPorts, outputPorts);
86 - inputPorts.put(link.dst().deviceId(), link.dst().port());
87 - outputPorts.put(link.src().deviceId(), link.src().port());
88 - }
89 -
90 - for (ConnectPoint ingressPoint : intent.ingressPoints()) {
91 - inputPorts.put(ingressPoint.deviceId(), ingressPoint.port());
92 - }
93 -
94 - for (ConnectPoint egressPoint : intent.egressPoints()) {
95 - outputPorts.put(egressPoint.deviceId(), egressPoint.port());
96 - }
97 84
98 List<Objective> objectives = new ArrayList<>(); 85 List<Objective> objectives = new ArrayList<>();
99 List<DeviceId> devices = new ArrayList<>(); 86 List<DeviceId> devices = new ArrayList<>();
...@@ -112,49 +99,46 @@ public class LinkCollectionIntentFlowObjectivesCompiler implements IntentCompile ...@@ -112,49 +99,46 @@ public class LinkCollectionIntentFlowObjectivesCompiler implements IntentCompile
112 new FlowObjectiveIntent(appId, devices, objectives, intent.resources())); 99 new FlowObjectiveIntent(appId, devices, objectives, intent.resources()));
113 } 100 }
114 101
115 - private List<Objective> createRules(LinkCollectionIntent intent, DeviceId deviceId, 102 + @Override
103 + protected List<Objective> createRules(LinkCollectionIntent intent, DeviceId deviceId,
116 Set<PortNumber> inPorts, Set<PortNumber> outPorts) { 104 Set<PortNumber> inPorts, Set<PortNumber> outPorts) {
117 - Set<PortNumber> ingressPorts = intent.ingressPoints().stream()
118 - .filter(point -> point.deviceId().equals(deviceId))
119 - .map(ConnectPoint::port)
120 - .collect(Collectors.toSet());
121 105
122 - TrafficTreatment.Builder defaultTreatmentBuilder = DefaultTrafficTreatment.builder(); 106 + Set<PortNumber> ingressPorts = Sets.newHashSet();
123 - outPorts.forEach(defaultTreatmentBuilder::setOutput); 107 + Set<PortNumber> egressPorts = Sets.newHashSet();
124 - TrafficTreatment defaultTreatment = defaultTreatmentBuilder.build();
125 108
126 - TrafficTreatment.Builder ingressTreatmentBuilder = DefaultTrafficTreatment.builder(intent.treatment()); 109 + computePorts(intent, deviceId, ingressPorts, egressPorts);
127 - outPorts.forEach(ingressTreatmentBuilder::setOutput);
128 - TrafficTreatment ingressTreatment = ingressTreatmentBuilder.build();
129 110
130 List<Objective> objectives = new ArrayList<>(inPorts.size()); 111 List<Objective> objectives = new ArrayList<>(inPorts.size());
131 - for (PortNumber inPort: inPorts) { 112 + Set<PortNumber> copyIngressPorts = ImmutableSet.copyOf(ingressPorts);
132 - TrafficSelector selector = DefaultTrafficSelector.builder(intent.selector()).matchInPort(inPort).build(); 113 + Set<PortNumber> copyEgressPorts = ImmutableSet.copyOf(egressPorts);
133 - TrafficTreatment treatment; 114 +
134 - if (ingressPorts.contains(inPort)) { 115 + inPorts.forEach(inport -> {
135 - treatment = ingressTreatment; 116 + ForwardingInstructions instructions = this.createForwardingInstructions(intent,
136 - } else { 117 + inport,
137 - treatment = defaultTreatment; 118 + outPorts,
138 - } 119 + copyIngressPorts,
120 + copyEgressPorts);
139 121
140 NextObjective nextObjective = DefaultNextObjective.builder() 122 NextObjective nextObjective = DefaultNextObjective.builder()
141 .withId(flowObjectiveService.allocateNextId()) 123 .withId(flowObjectiveService.allocateNextId())
142 - .addTreatment(treatment) 124 + .addTreatment(instructions.treatment())
143 .withType(NextObjective.Type.SIMPLE) 125 .withType(NextObjective.Type.SIMPLE)
144 .fromApp(appId) 126 .fromApp(appId)
145 .makePermanent().add(); 127 .makePermanent().add();
146 objectives.add(nextObjective); 128 objectives.add(nextObjective);
147 129
148 objectives.add(DefaultForwardingObjective.builder() 130 objectives.add(DefaultForwardingObjective.builder()
149 - .withSelector(selector) 131 + .withSelector(instructions.selector())
150 .nextStep(nextObjective.id()) 132 .nextStep(nextObjective.id())
151 .withPriority(intent.priority()) 133 .withPriority(intent.priority())
152 .fromApp(appId) 134 .fromApp(appId)
153 .makePermanent() 135 .makePermanent()
154 .withFlag(ForwardingObjective.Flag.SPECIFIC) 136 .withFlag(ForwardingObjective.Flag.SPECIFIC)
155 .add()); 137 .add());
156 - } 138 + }
139 + );
157 140
158 return objectives; 141 return objectives;
159 } 142 }
143 +
160 } 144 }
......