Mahesh Poojary S
Committed by Mahesh Poojary Huawei

[ONOS-3119] Flow-classifier installer changes

Change-Id: I7437a4dc0611409788d6d5cbfaeb6b69253ceb77
...@@ -20,20 +20,28 @@ import static org.onosproject.net.flow.instructions.ExtensionTreatmentType.Exten ...@@ -20,20 +20,28 @@ import static org.onosproject.net.flow.instructions.ExtensionTreatmentType.Exten
20 import static org.onosproject.net.flow.instructions.ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_SPI; 20 import static org.onosproject.net.flow.instructions.ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_SPI;
21 import static org.slf4j.LoggerFactory.getLogger; 21 import static org.slf4j.LoggerFactory.getLogger;
22 22
23 +import org.apache.felix.scr.annotations.Reference;
24 +import org.apache.felix.scr.annotations.ReferenceCardinality;
25 +import org.apache.felix.scr.annotations.Service;
26 +
23 import java.util.LinkedList; 27 import java.util.LinkedList;
24 import java.util.List; 28 import java.util.List;
25 import java.util.ListIterator; 29 import java.util.ListIterator;
26 30
27 -import org.apache.felix.scr.annotations.Reference; 31 +import org.apache.felix.scr.annotations.Component;
28 -import org.apache.felix.scr.annotations.ReferenceCardinality;
29 import org.onlab.osgi.DefaultServiceDirectory; 32 import org.onlab.osgi.DefaultServiceDirectory;
30 import org.onlab.osgi.ServiceDirectory; 33 import org.onlab.osgi.ServiceDirectory;
34 +import org.onlab.packet.Ethernet;
31 import org.onlab.packet.MacAddress; 35 import org.onlab.packet.MacAddress;
32 import org.onlab.packet.TpPort; 36 import org.onlab.packet.TpPort;
33 import org.onlab.packet.VlanId; 37 import org.onlab.packet.VlanId;
34 import org.onosproject.core.ApplicationId; 38 import org.onosproject.core.ApplicationId;
35 import org.onosproject.net.DeviceId; 39 import org.onosproject.net.DeviceId;
40 +import org.onosproject.net.Host;
41 +import org.onosproject.net.HostId;
36 import org.onosproject.net.NshServicePathId; 42 import org.onosproject.net.NshServicePathId;
43 +import org.onosproject.net.PortNumber;
44 +import org.onosproject.net.device.DeviceService;
37 import org.onosproject.net.behaviour.ExtensionTreatmentResolver; 45 import org.onosproject.net.behaviour.ExtensionTreatmentResolver;
38 import org.onosproject.net.driver.DriverHandler; 46 import org.onosproject.net.driver.DriverHandler;
39 import org.onosproject.net.driver.DriverService; 47 import org.onosproject.net.driver.DriverService;
...@@ -49,6 +57,7 @@ import org.onosproject.net.flowobjective.ForwardingObjective; ...@@ -49,6 +57,7 @@ import org.onosproject.net.flowobjective.ForwardingObjective;
49 import org.onosproject.net.flowobjective.ForwardingObjective.Flag; 57 import org.onosproject.net.flowobjective.ForwardingObjective.Flag;
50 import org.onosproject.net.flowobjective.Objective; 58 import org.onosproject.net.flowobjective.Objective;
51 import org.onosproject.net.flowobjective.Objective.Operation; 59 import org.onosproject.net.flowobjective.Objective.Operation;
60 +import org.onosproject.net.host.HostService;
52 import org.onosproject.sfc.installer.FlowClassifierInstallerService; 61 import org.onosproject.sfc.installer.FlowClassifierInstallerService;
53 import org.onosproject.vtnrsc.FlowClassifier; 62 import org.onosproject.vtnrsc.FlowClassifier;
54 import org.onosproject.vtnrsc.FlowClassifierId; 63 import org.onosproject.vtnrsc.FlowClassifierId;
...@@ -63,11 +72,14 @@ import org.onosproject.vtnrsc.portpair.PortPairService; ...@@ -63,11 +72,14 @@ import org.onosproject.vtnrsc.portpair.PortPairService;
63 import org.onosproject.vtnrsc.portpairgroup.PortPairGroupService; 72 import org.onosproject.vtnrsc.portpairgroup.PortPairGroupService;
64 import org.onosproject.vtnrsc.service.VtnRscService; 73 import org.onosproject.vtnrsc.service.VtnRscService;
65 import org.onosproject.vtnrsc.virtualport.VirtualPortService; 74 import org.onosproject.vtnrsc.virtualport.VirtualPortService;
75 +
66 import org.slf4j.Logger; 76 import org.slf4j.Logger;
67 77
68 /** 78 /**
69 * Provides flow classifier installer implementation. 79 * Provides flow classifier installer implementation.
70 */ 80 */
81 +@Component(immediate = true)
82 +@Service
71 public class FlowClassifierInstallerImpl implements FlowClassifierInstallerService { 83 public class FlowClassifierInstallerImpl implements FlowClassifierInstallerService {
72 84
73 private final Logger log = getLogger(getClass()); 85 private final Logger log = getLogger(getClass());
...@@ -90,6 +102,12 @@ public class FlowClassifierInstallerImpl implements FlowClassifierInstallerServi ...@@ -90,6 +102,12 @@ public class FlowClassifierInstallerImpl implements FlowClassifierInstallerServi
90 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 102 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
91 protected DriverService driverService; 103 protected DriverService driverService;
92 104
105 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
106 + protected DeviceService deviceService;
107 +
108 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
109 + protected HostService hostService;
110 +
93 protected FlowObjectiveService flowObjectiveService; 111 protected FlowObjectiveService flowObjectiveService;
94 protected ApplicationId appId; 112 protected ApplicationId appId;
95 113
...@@ -168,7 +186,7 @@ public class FlowClassifierInstallerImpl implements FlowClassifierInstallerServi ...@@ -168,7 +186,7 @@ public class FlowClassifierInstallerImpl implements FlowClassifierInstallerServi
168 // Vxlan tunnel port for NSH header(Vxlan + NSH). 186 // Vxlan tunnel port for NSH header(Vxlan + NSH).
169 TpPort nshDstPort = TpPort.tpPort(6633); 187 TpPort nshDstPort = TpPort.tpPort(6633);
170 188
171 - if (flowClassifier.srcPort() != null) { 189 + if ((flowClassifier.srcPort() != null) && (!flowClassifier.srcPort().portId().isEmpty())) {
172 deviceIdfromFc = vtnRscService.getSFToSFFMaping(flowClassifier.srcPort()); 190 deviceIdfromFc = vtnRscService.getSFToSFFMaping(flowClassifier.srcPort());
173 deviceId = deviceIdfromFc; 191 deviceId = deviceIdfromFc;
174 } else { 192 } else {
...@@ -197,25 +215,31 @@ public class FlowClassifierInstallerImpl implements FlowClassifierInstallerServi ...@@ -197,25 +215,31 @@ public class FlowClassifierInstallerImpl implements FlowClassifierInstallerServi
197 public TrafficSelector.Builder packTrafficSelector(FlowClassifier flowClassifier) { 215 public TrafficSelector.Builder packTrafficSelector(FlowClassifier flowClassifier) {
198 TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); 216 TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
199 217
200 - if (flowClassifier.srcIpPrefix() != null) { 218 + if ((flowClassifier.srcIpPrefix() != null) && (flowClassifier.srcIpPrefix().prefixLength() != 0)) {
201 selector.matchIPSrc(flowClassifier.srcIpPrefix()); 219 selector.matchIPSrc(flowClassifier.srcIpPrefix());
202 } 220 }
203 - if (flowClassifier.dstIpPrefix() != null) { 221 +
222 + if ((flowClassifier.dstIpPrefix() != null) && (flowClassifier.dstIpPrefix().prefixLength() != 0)) {
204 selector.matchIPDst(flowClassifier.dstIpPrefix()); 223 selector.matchIPDst(flowClassifier.dstIpPrefix());
205 } 224 }
206 225
207 - if (flowClassifier.protocol() != null) { 226 + if ((flowClassifier.protocol() != null) && (!flowClassifier.protocol().isEmpty())) {
208 selector.add(Criteria.matchIPProtocol(Short.parseShort(flowClassifier.protocol()))); 227 selector.add(Criteria.matchIPProtocol(Short.parseShort(flowClassifier.protocol())));
209 } 228 }
210 - if ((flowClassifier.etherType() != null) 229 +
211 - && (flowClassifier.etherType() == "IPv4" || flowClassifier.etherType() == "IPv6")) { 230 + if (((flowClassifier.etherType() != null) && (!flowClassifier.etherType().isEmpty()))
212 - selector.matchEthType(Short.parseShort((flowClassifier.etherType()))); 231 + && (flowClassifier.etherType().equals("IPv4") || flowClassifier.etherType().equals("IPv6"))) {
232 + if (flowClassifier.etherType().equals("IPv4")) {
233 + selector.matchEthType(Ethernet.TYPE_IPV4);
234 + } else {
235 + selector.matchEthType(Ethernet.TYPE_IPV6);
236 + }
213 } 237 }
214 238
215 List<TpPort> srcPortRange = new LinkedList<>(); 239 List<TpPort> srcPortRange = new LinkedList<>();
216 List<TpPort> dstPortRange = new LinkedList<>(); 240 List<TpPort> dstPortRange = new LinkedList<>();
217 - if ((flowClassifier.minSrcPortRange() != NULL) && flowClassifier.maxSrcPortRange() != NULL 241 + if ((flowClassifier.minSrcPortRange() != 0) && flowClassifier.maxSrcPortRange() != 0
218 - && flowClassifier.minDstPortRange() != NULL && flowClassifier.maxDstPortRange() != NULL) { 242 + && flowClassifier.minDstPortRange() != 0 && flowClassifier.maxDstPortRange() != 0) {
219 243
220 for (int port = flowClassifier.minSrcPortRange(); port <= flowClassifier.maxSrcPortRange(); port++) { 244 for (int port = flowClassifier.minSrcPortRange(); port <= flowClassifier.maxSrcPortRange(); port++) {
221 srcPortRange.add(TpPort.tpPort(port)); 245 srcPortRange.add(TpPort.tpPort(port));
...@@ -250,6 +274,17 @@ public class FlowClassifierInstallerImpl implements FlowClassifierInstallerServi ...@@ -250,6 +274,17 @@ public class FlowClassifierInstallerImpl implements FlowClassifierInstallerServi
250 TpPort nshDstPort, DeviceId deviceIdfromFc, DeviceId deviceIdfromPp, 274 TpPort nshDstPort, DeviceId deviceIdfromFc, DeviceId deviceIdfromPp,
251 NshServicePathId nshSPI, FlowClassifier flowClassifier) { 275 NshServicePathId nshSPI, FlowClassifier flowClassifier) {
252 TrafficTreatment.Builder treatmentBuilder = DefaultTrafficTreatment.builder(); 276 TrafficTreatment.Builder treatmentBuilder = DefaultTrafficTreatment.builder();
277 +
278 + Host host = hostService.getHost(HostId.hostId(srcMacAddress));
279 + PortNumber port = host.location().port();
280 + if (deviceIdfromPp != null) {
281 + treatmentBuilder.setOutput(port);
282 + } else if (deviceIdfromFc != null) {
283 + treatmentBuilder.setVlanId((VlanId.vlanId(Short.parseShort((vtnRscService.getL3vni(flowClassifier
284 + .tenantId()).toString())))));
285 + }
286 +
287 + // Set NSH
253 DriverHandler handler = driverService.createHandler(deviceId); 288 DriverHandler handler = driverService.createHandler(deviceId);
254 ExtensionTreatmentResolver resolver = handler.behaviour(ExtensionTreatmentResolver.class); 289 ExtensionTreatmentResolver resolver = handler.behaviour(ExtensionTreatmentResolver.class);
255 ExtensionTreatment nspIdTreatment = resolver.getExtensionInstruction(NICIRA_SET_NSH_SPI.type()); 290 ExtensionTreatment nspIdTreatment = resolver.getExtensionInstruction(NICIRA_SET_NSH_SPI.type());
...@@ -269,13 +304,6 @@ public class FlowClassifierInstallerImpl implements FlowClassifierInstallerServi ...@@ -269,13 +304,6 @@ public class FlowClassifierInstallerImpl implements FlowClassifierInstallerServi
269 } catch (Exception e) { 304 } catch (Exception e) {
270 log.error("Failed to get extension instruction to set Nsh Si Id {}", deviceId); 305 log.error("Failed to get extension instruction to set Nsh Si Id {}", deviceId);
271 } 306 }
272 -
273 - if (deviceIdfromPp != null) {
274 - treatmentBuilder.setEthSrc(srcMacAddress);
275 - } else if (deviceIdfromFc != null) {
276 - treatmentBuilder.setVlanId((VlanId.vlanId(Short.parseShort((vtnRscService.getL3vni(flowClassifier
277 - .tenantId()).toString())))));
278 - }
279 return treatmentBuilder; 307 return treatmentBuilder;
280 } 308 }
281 309
...@@ -290,8 +318,8 @@ public class FlowClassifierInstallerImpl implements FlowClassifierInstallerServi ...@@ -290,8 +318,8 @@ public class FlowClassifierInstallerImpl implements FlowClassifierInstallerServi
290 public void sendServiceFunctionForwarder(TrafficSelector.Builder selector, TrafficTreatment.Builder treatment, 318 public void sendServiceFunctionForwarder(TrafficSelector.Builder selector, TrafficTreatment.Builder treatment,
291 DeviceId deviceId, Objective.Operation type) { 319 DeviceId deviceId, Objective.Operation type) {
292 ForwardingObjective.Builder objective = DefaultForwardingObjective.builder().withTreatment(treatment.build()) 320 ForwardingObjective.Builder objective = DefaultForwardingObjective.builder().withTreatment(treatment.build())
293 - .withSelector(selector.build()).fromApp(appId).makePermanent().withFlag(Flag.SPECIFIC).withPriority( 321 + .withSelector(selector.build()).fromApp(appId).makePermanent().withFlag(Flag.VERSATILE)
294 - L3FWD_PRIORITY); 322 + .withPriority(L3FWD_PRIORITY);
295 323
296 if (type.equals(Objective.Operation.ADD)) { 324 if (type.equals(Objective.Operation.ADD)) {
297 log.debug("flowClassifierRules-->ADD"); 325 log.debug("flowClassifierRules-->ADD");
......