[ONOS-4228]Parase and set priority for sfc classification
Change-Id: I0e25465d47ad1bd6c6035ff309ef631b8ef7c75e
diff --git a/apps/vtn/sfcmgr/src/main/java/org/onosproject/sfc/installer/impl/FlowClassifierInstallerImpl.java b/apps/vtn/sfcmgr/src/main/java/org/onosproject/sfc/installer/impl/FlowClassifierInstallerImpl.java
index dbae14c..ec12553 100644
--- a/apps/vtn/sfcmgr/src/main/java/org/onosproject/sfc/installer/impl/FlowClassifierInstallerImpl.java
+++ b/apps/vtn/sfcmgr/src/main/java/org/onosproject/sfc/installer/impl/FlowClassifierInstallerImpl.java
@@ -223,19 +223,19 @@
// Send the packet to controller
TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder();
treatment.setOutput(PortNumber.CONTROLLER);
- sendServiceFunctionClassifier(selector, treatment, deviceId, type);
+ sendServiceFunctionClassifier(selector, treatment, deviceId, type, flowClassifier.priority());
} else if (deviceId.equals(deviceIdfromPortPair)) {
// classifier and source device are in the same OVS. So directly send packet to first port pair
TrafficTreatment.Builder treatment = packTrafficTreatment(deviceId, port, nshDstPort,
nshSpiId, flowClassifier, true);
// Build forwarding objective and send to OVS.
- sendServiceFunctionClassifier(selector, treatment, deviceId, type);
+ sendServiceFunctionClassifier(selector, treatment, deviceId, type, flowClassifier.priority());
} else {
// classifier and source device are not in the same OVS. Send packet on vlan Tunnel
TrafficTreatment.Builder treatment = packTrafficTreatment(deviceId, port, nshDstPort,
nshSpiId, flowClassifier, false);
// Build forwarding objective and send to OVS.
- sendServiceFunctionClassifier(selector, treatment, deviceId, type);
+ sendServiceFunctionClassifier(selector, treatment, deviceId, type, flowClassifier.priority());
// At the other device get the packet from vlan and send to first port pair
TrafficSelector.Builder selectorDst = DefaultTrafficSelector.builder();
@@ -244,7 +244,8 @@
TrafficTreatment.Builder treatmentDst = DefaultTrafficTreatment.builder();
Host hostDst = hostService.getHost(HostId.hostId(srcMacAddress));
treatmentDst.setOutput(hostDst.location().port());
- sendServiceFunctionClassifier(selectorDst, treatmentDst, deviceIdfromPortPair, type);
+ sendServiceFunctionClassifier(selectorDst, treatmentDst, deviceIdfromPortPair, type,
+ flowClassifier.priority());
}
}
return host.location();
@@ -383,14 +384,15 @@
* @param treatment traffic treatment
* @param deviceId device id
* @param type operation type
+ * @param priority priority of classifier
*/
public void sendServiceFunctionClassifier(TrafficSelector.Builder selector, TrafficTreatment.Builder treatment,
- DeviceId deviceId, Objective.Operation type) {
+ DeviceId deviceId, Objective.Operation type, int priority) {
log.info("Sending flow to service function classifier. Selector {}, Treatment {}",
selector.toString(), treatment.toString());
ForwardingObjective.Builder objective = DefaultForwardingObjective.builder().withTreatment(treatment.build())
.withSelector(selector.build()).fromApp(appId).makePermanent().withFlag(Flag.VERSATILE)
- .withPriority(FLOW_CLASSIFIER_PRIORITY);
+ .withPriority(priority);
if (type.equals(Objective.Operation.ADD)) {
log.debug("flowClassifierRules-->ADD");
diff --git a/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/DefaultFlowClassifier.java b/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/DefaultFlowClassifier.java
index fc360d8..4f3a5a0 100644
--- a/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/DefaultFlowClassifier.java
+++ b/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/DefaultFlowClassifier.java
@@ -34,6 +34,7 @@
private final String description;
private final String etherType;
private final String protocol;
+ private final int priority;
private final int minSrcPortRange;
private final int maxSrcPortRange;
private final int minDstPortRange;
@@ -47,6 +48,7 @@
private static final String TENANT_ID_NOT_NULL = "Tenant id can not be null.";
private static final String NAME_NOT_NULL = "Name can not be null.";
private static final String ETHER_TYPE_NOT_NULL = "Ether Type can not be null.";
+ private static final int DEFAULT_CLASSIFIER_PRIORITY = 0xFFFF;
/**
* Constructor to create default flow classifier.
@@ -57,6 +59,7 @@
* @param description flow classifier description
* @param etherType etherType
* @param protocol IP protocol
+ * @param priority priority for classification
* @param minSrcPortRange Minimum Source port range
* @param maxSrcPortRange Maximum Source port range
* @param minDstPortRange Minimum destination port range
@@ -67,15 +70,17 @@
* @param dstPort destination VirtualPort
*/
private DefaultFlowClassifier(FlowClassifierId flowClassifierId, TenantId tenantId, String name,
- String description, String etherType, String protocol, int minSrcPortRange, int maxSrcPortRange,
- int minDstPortRange, int maxDstPortRange, IpPrefix srcIpPrefix, IpPrefix dstIpPrefix,
- VirtualPortId srcPort, VirtualPortId dstPort) {
+ String description, String etherType, String protocol, int priority,
+ int minSrcPortRange, int maxSrcPortRange, int minDstPortRange, int maxDstPortRange,
+ IpPrefix srcIpPrefix, IpPrefix dstIpPrefix, VirtualPortId srcPort,
+ VirtualPortId dstPort) {
this.flowClassifierId = flowClassifierId;
this.tenantId = tenantId;
this.name = name;
this.description = description;
this.etherType = etherType;
this.protocol = protocol;
+ this.priority = priority;
this.minSrcPortRange = minSrcPortRange;
this.maxSrcPortRange = maxSrcPortRange;
this.minDstPortRange = minDstPortRange;
@@ -117,6 +122,11 @@
}
@Override
+ public int priority() {
+ return priority;
+ }
+
+ @Override
public int minSrcPortRange() {
return minSrcPortRange;
}
@@ -169,6 +179,8 @@
private String etherType;
private String protocol;
private boolean isProtocolSet = false;
+ private int priority;
+ private boolean isPrioritySet = false;
private int minSrcPortRange;
private boolean isMinSrcPortRangeSet = false;
private int maxSrcPortRange;
@@ -195,6 +207,7 @@
checkNotNull(etherType, ETHER_TYPE_NOT_NULL);
String description = null;
String protocol = null;
+ int priority = DEFAULT_CLASSIFIER_PRIORITY;
int minSrcPortRange = NULL_PORT;
int maxSrcPortRange = NULL_PORT;
int minDstPortRange = NULL_PORT;
@@ -210,6 +223,9 @@
if (isProtocolSet) {
protocol = this.protocol;
}
+ if (isPrioritySet) {
+ priority = this.priority;
+ }
if (isMinSrcPortRangeSet) {
minSrcPortRange = this.minSrcPortRange;
}
@@ -236,8 +252,8 @@
}
return new DefaultFlowClassifier(flowClassifierId, tenantId, name, description, etherType, protocol,
- minSrcPortRange, maxSrcPortRange, minDstPortRange, maxDstPortRange, srcIpPrefix, dstIpPrefix,
- srcPort, dstPort);
+ priority, minSrcPortRange, maxSrcPortRange, minDstPortRange,
+ maxDstPortRange, srcIpPrefix, dstIpPrefix, srcPort, dstPort);
}
@Override
@@ -279,6 +295,13 @@
}
@Override
+ public Builder setPriority(int priority) {
+ this.priority = priority;
+ this.isPrioritySet = true;
+ return this;
+ }
+
+ @Override
public Builder setMinSrcPortRange(int minSrcPortRange) {
this.minSrcPortRange = minSrcPortRange;
this.isMinSrcPortRangeSet = true;
@@ -354,6 +377,7 @@
&& Objects.equals(this.description, other.description)
&& Objects.equals(this.etherType, other.etherType)
&& Objects.equals(this.protocol, other.protocol)
+ && Objects.equals(this.priority, other.priority)
&& Objects.equals(this.minSrcPortRange, other.minSrcPortRange)
&& Objects.equals(this.maxSrcPortRange, other.maxSrcPortRange)
&& Objects.equals(this.minDstPortRange, other.minDstPortRange)
@@ -375,6 +399,7 @@
&& Objects.equals(this.description, flowClassifier.description())
&& Objects.equals(this.etherType, flowClassifier.etherType())
&& Objects.equals(this.protocol, flowClassifier.protocol())
+ && Objects.equals(this.priority, flowClassifier.priority())
&& Objects.equals(this.minSrcPortRange, flowClassifier.minSrcPortRange())
&& Objects.equals(this.maxSrcPortRange, flowClassifier.maxSrcPortRange())
&& Objects.equals(this.minDstPortRange, flowClassifier.minDstPortRange())
@@ -394,6 +419,7 @@
.add("Description", description)
.add("String", etherType)
.add("Protocol", protocol)
+ .add("Priority", priority)
.add("MinSrcPortRange", minSrcPortRange)
.add("MaxSrcPortRange", maxSrcPortRange)
.add("MinDstPortRange", minDstPortRange)
diff --git a/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/FlowClassifier.java b/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/FlowClassifier.java
index 26bf718..8903253 100644
--- a/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/FlowClassifier.java
+++ b/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/FlowClassifier.java
@@ -68,6 +68,13 @@
String protocol();
/**
+ * Returns priority.
+ *
+ * @return priority
+ */
+ int priority();
+
+ /**
* Returns minimum source port range.
*
* @return minimum source port range
@@ -193,6 +200,14 @@
Builder setProtocol(String protocol);
/**
+ * Sets priority.
+ *
+ * @param priority priority
+ * @return builder object by setting priority
+ */
+ Builder setPriority(int priority);
+
+ /**
* Set minimum source port range.
*
* @param minRange minimum source port range
diff --git a/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/DefaultFlowClassifierTest.java b/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/DefaultFlowClassifierTest.java
index d312e80..fea2326 100644
--- a/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/DefaultFlowClassifierTest.java
+++ b/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/DefaultFlowClassifierTest.java
@@ -46,6 +46,7 @@
final String description = "FlowClassifier1";
final String ethType = "IPv4";
final String protocol = "tcp";
+ final int priority = 65535;
final int minSrcPortRange = 5;
final int maxSrcPortRange = 10;
final int minDstPortRange = 5;
@@ -60,22 +61,25 @@
DefaultFlowClassifier.Builder flowClassifierBuilder = new DefaultFlowClassifier.Builder();
final FlowClassifier flowClassifier1 = flowClassifierBuilder.setFlowClassifierId(flowClassifierId)
.setTenantId(tenantId).setName(name).setDescription(description).setEtherType(ethType)
- .setProtocol(protocol).setMinSrcPortRange(minSrcPortRange).setMaxSrcPortRange(maxSrcPortRange)
- .setMinDstPortRange(minDstPortRange).setMaxDstPortRange(maxDstPortRange).setSrcIpPrefix(srcIpPrefix)
- .setDstIpPrefix(dstIpPrefix).setSrcPort(virtualSrcPort).setDstPort(virtualDstPort).build();
+ .setProtocol(protocol).setPriority(priority).setMinSrcPortRange(minSrcPortRange)
+ .setMaxSrcPortRange(maxSrcPortRange).setMinDstPortRange(minDstPortRange)
+ .setMaxDstPortRange(maxDstPortRange).setSrcIpPrefix(srcIpPrefix).setDstIpPrefix(dstIpPrefix)
+ .setSrcPort(virtualSrcPort).setDstPort(virtualDstPort).build();
flowClassifierBuilder = new DefaultFlowClassifier.Builder();
final FlowClassifier sameAsFlowClassifier1 = flowClassifierBuilder.setFlowClassifierId(flowClassifierId)
.setTenantId(tenantId).setName(name).setDescription(description).setEtherType(ethType)
- .setProtocol(protocol).setMinSrcPortRange(minSrcPortRange).setMaxSrcPortRange(maxSrcPortRange)
- .setMinDstPortRange(minDstPortRange).setMaxDstPortRange(maxDstPortRange).setSrcIpPrefix(srcIpPrefix)
- .setDstIpPrefix(dstIpPrefix).setSrcPort(virtualSrcPort).setDstPort(virtualDstPort).build();
+ .setProtocol(protocol).setPriority(priority).setMinSrcPortRange(minSrcPortRange)
+ .setMaxSrcPortRange(maxSrcPortRange).setMinDstPortRange(minDstPortRange)
+ .setMaxDstPortRange(maxDstPortRange).setSrcIpPrefix(srcIpPrefix).setDstIpPrefix(dstIpPrefix)
+ .setSrcPort(virtualSrcPort).setDstPort(virtualDstPort).build();
// Create different classifier object.
final String name2 = "FlowClassifier2";
final String description2 = "FlowClassifier2";
final String ethType2 = "IPv6";
final String protocol2 = "udp";
+ final int priority2 = 50000;
final int minSrcPortRange2 = 5;
final int maxSrcPortRange2 = 10;
final int minDstPortRange2 = 5;
@@ -92,7 +96,8 @@
.setTenantId(tenantId2).setName(name2).setDescription(description2).setEtherType(ethType2)
.setProtocol(protocol2).setMinSrcPortRange(minSrcPortRange2).setMaxSrcPortRange(maxSrcPortRange2)
.setMinDstPortRange(minDstPortRange2).setMaxDstPortRange(maxDstPortRange2).setSrcIpPrefix(srcIpPrefix2)
- .setDstIpPrefix(dstIpPrefix2).setSrcPort(virtualSrcPort2).setDstPort(virtualDstPort2).build();
+ .setDstIpPrefix(dstIpPrefix2).setSrcPort(virtualSrcPort2).setDstPort(virtualDstPort2)
+ .setPriority(priority2).build();
new EqualsTester().addEqualityGroup(flowClassifier1, sameAsFlowClassifier1).addEqualityGroup(flowClassifier2)
.testEquals();
@@ -107,6 +112,7 @@
final String description = "FlowClassifier";
final String ethType = "IPv4";
final String protocol = "tcp";
+ final int priority = 30000;
final int minSrcPortRange = 5;
final int maxSrcPortRange = 10;
final int minDstPortRange = 5;
@@ -123,7 +129,8 @@
.setTenantId(tenantId).setName(name).setDescription(description).setEtherType(ethType)
.setProtocol(protocol).setMinSrcPortRange(minSrcPortRange).setMaxSrcPortRange(maxSrcPortRange)
.setMinDstPortRange(minDstPortRange).setMaxDstPortRange(maxDstPortRange).setSrcIpPrefix(srcIpPrefix)
- .setDstIpPrefix(dstIpPrefix).setSrcPort(virtualSrcPort).setDstPort(virtualDstPort).build();
+ .setDstIpPrefix(dstIpPrefix).setSrcPort(virtualSrcPort).setDstPort(virtualDstPort)
+ .setPriority(priority).build();
assertThat(flowClassifierId, is(flowClassifier.flowClassifierId()));
assertThat(tenantId, is(flowClassifier.tenantId()));
@@ -131,6 +138,7 @@
assertThat(description, is(flowClassifier.description()));
assertThat(ethType, is(flowClassifier.etherType()));
assertThat(protocol, is(flowClassifier.protocol()));
+ assertThat(priority, is(flowClassifier.priority()));
assertThat(minSrcPortRange, is(flowClassifier.minSrcPortRange()));
assertThat(maxSrcPortRange, is(flowClassifier.maxSrcPortRange()));
assertThat(minDstPortRange, is(flowClassifier.minDstPortRange()));
diff --git a/apps/vtn/vtnweb/src/main/java/org/onosproject/vtnweb/web/FlowClassifierCodec.java b/apps/vtn/vtnweb/src/main/java/org/onosproject/vtnweb/web/FlowClassifierCodec.java
index 412cefe..94e02db 100644
--- a/apps/vtn/vtnweb/src/main/java/org/onosproject/vtnweb/web/FlowClassifierCodec.java
+++ b/apps/vtn/vtnweb/src/main/java/org/onosproject/vtnweb/web/FlowClassifierCodec.java
@@ -40,6 +40,7 @@
private static final String DESCRIPTION = "description";
private static final String ETHER_TYPE = "ethertype";
private static final String PROTOCOL = "protocol";
+ private static final String PRIORITY = "priority";
private static final String MIN_SRC_PORT_RANGE = "source_port_range_min";
private static final String MAX_SRC_PORT_RANGE = "source_port_range_max";
private static final String MIN_DST_PORT_RANGE = "destination_port_range_min";
@@ -79,6 +80,9 @@
resultBuilder.setProtocol(protocol);
}
+ int priority = (json.get(PRIORITY)).asInt();
+ resultBuilder.setPriority(priority);
+
int minSrcPortRange = (json.get(MIN_SRC_PORT_RANGE)).asInt();
resultBuilder.setMinSrcPortRange(minSrcPortRange);
@@ -123,6 +127,7 @@
.put(DESCRIPTION, flowClassifier.description())
.put(ETHER_TYPE, flowClassifier.etherType())
.put(PROTOCOL, flowClassifier.protocol())
+ .put(PRIORITY, flowClassifier.priority())
.put(MIN_SRC_PORT_RANGE, flowClassifier.minSrcPortRange())
.put(MAX_SRC_PORT_RANGE, flowClassifier.maxSrcPortRange())
.put(MIN_DST_PORT_RANGE, flowClassifier.minDstPortRange())
diff --git a/apps/vtn/vtnweb/src/test/java/org/onosproject/vtnweb/resources/FlowClassifierResourceTest.java b/apps/vtn/vtnweb/src/test/java/org/onosproject/vtnweb/resources/FlowClassifierResourceTest.java
index 673e088..b21a80f 100644
--- a/apps/vtn/vtnweb/src/test/java/org/onosproject/vtnweb/resources/FlowClassifierResourceTest.java
+++ b/apps/vtn/vtnweb/src/test/java/org/onosproject/vtnweb/resources/FlowClassifierResourceTest.java
@@ -65,8 +65,9 @@
VirtualPortId dstPortId1 = VirtualPortId.portId("aef3478a-4a56-2a6e-cd3a-9dee4e2ec345");
final MockFlowClassifier flowClassifier1 = new MockFlowClassifier(flowClassifierId1, tenantId1, "flowClassifier1",
- "Mock flow classifier", "IPv4", "IP", 1001, 1500,
- 5001, 6000, IpPrefix.valueOf("1.1.1.1/16"),
+ "Mock flow classifier", "IPv4", "IP", 10000,
+ 1001, 1500, 5001, 6000,
+ IpPrefix.valueOf("1.1.1.1/16"),
IpPrefix.valueOf("22.12.34.45/16"),
srcPortId1, dstPortId1);
@@ -81,6 +82,7 @@
private final String description;
private final String etherType;
private final String protocol;
+ private final int priority;
private final int minSrcPortRange;
private final int maxSrcPortRange;
private final int minDstPortRange;
@@ -91,15 +93,17 @@
private final VirtualPortId dstPort;
public MockFlowClassifier(FlowClassifierId flowClassifierId, TenantId tenantId, String name,
- String description, String etherType, String protocol, int minSrcPortRange,
- int maxSrcPortRange, int minDstPortRange, int maxDstPortRange, IpPrefix srcIpPrefix,
- IpPrefix dstIpPrefix, VirtualPortId srcPort, VirtualPortId dstPort) {
+ String description, String etherType, String protocol, int priority,
+ int minSrcPortRange, int maxSrcPortRange, int minDstPortRange, int maxDstPortRange,
+ IpPrefix srcIpPrefix, IpPrefix dstIpPrefix, VirtualPortId srcPort,
+ VirtualPortId dstPort) {
this.flowClassifierId = flowClassifierId;
this.tenantId = tenantId;
this.name = name;
this.description = description;
this.etherType = etherType;
this.protocol = protocol;
+ this.priority = priority;
this.minSrcPortRange = minSrcPortRange;
this.maxSrcPortRange = maxSrcPortRange;
this.minDstPortRange = minDstPortRange;
@@ -142,6 +146,11 @@
}
@Override
+ public int priority() {
+ return priority;
+ }
+
+ @Override
public int minSrcPortRange() {
return minSrcPortRange;
}
diff --git a/apps/vtn/vtnweb/src/test/java/org/onosproject/vtnweb/web/FlowClassifierCodecTest.java b/apps/vtn/vtnweb/src/test/java/org/onosproject/vtnweb/web/FlowClassifierCodecTest.java
index 6daec8a..ea28613 100644
--- a/apps/vtn/vtnweb/src/test/java/org/onosproject/vtnweb/web/FlowClassifierCodecTest.java
+++ b/apps/vtn/vtnweb/src/test/java/org/onosproject/vtnweb/web/FlowClassifierCodecTest.java
@@ -89,6 +89,7 @@
assertThat(flowClassifier.tenantId().toString(), is(tenantId.toString()));
assertThat(flowClassifier.description(), is("flow classifier"));
assertThat(flowClassifier.protocol(), is("tcp"));
+ assertThat(flowClassifier.priority(), is(65535));
assertThat(flowClassifier.minSrcPortRange(), is(22));
assertThat(flowClassifier.maxSrcPortRange(), is(4000));
assertThat(flowClassifier.minDstPortRange(), is(80));
diff --git a/apps/vtn/vtnweb/src/test/resources/org/onosproject/vtnweb/resources/post-FlowClassifier.json b/apps/vtn/vtnweb/src/test/resources/org/onosproject/vtnweb/resources/post-FlowClassifier.json
index 6e72e8f..5ed095d 100644
--- a/apps/vtn/vtnweb/src/test/resources/org/onosproject/vtnweb/resources/post-FlowClassifier.json
+++ b/apps/vtn/vtnweb/src/test/resources/org/onosproject/vtnweb/resources/post-FlowClassifier.json
@@ -5,6 +5,7 @@
"description": "flow classifier",
"ethertype": "IPv4",
"protocol": "tcp",
+ "priority": 10000,
"source_port_range_min": 22, "source_port_range_max": 4000,
"destination_port_range_min": 80, "destination_port_range_max": 80,
"source_ip_prefix": "1.1.1.1/16" , "destination_ip_prefix": "22.12.34.45/16",
diff --git a/apps/vtn/vtnweb/src/test/resources/org/onosproject/vtnweb/web/flowClassifier.json b/apps/vtn/vtnweb/src/test/resources/org/onosproject/vtnweb/web/flowClassifier.json
index 0fc0b74..3fd5ac9 100644
--- a/apps/vtn/vtnweb/src/test/resources/org/onosproject/vtnweb/web/flowClassifier.json
+++ b/apps/vtn/vtnweb/src/test/resources/org/onosproject/vtnweb/web/flowClassifier.json
@@ -5,6 +5,7 @@
"description": "flow classifier",
"ethertype": "IPv4",
"protocol": "tcp",
+ "priority": 65535,
"source_port_range_min": 22, "source_port_range_max": 4000,
"destination_port_range_min": 80, "destination_port_range_max": 80,
"source_ip_prefix": "1.1.1.1/16" , "destination_ip_prefix": "22.12.34.45/16"