[ONOS-7675] Initial implementation of IntProgrammable
Change-Id: I277ea7a56bb3a38debbb2959823df394a4103541
diff --git a/apps/inbandtelemetry/api/BUCK b/apps/inbandtelemetry/api/BUCK
new file mode 100644
index 0000000..97564d9
--- /dev/null
+++ b/apps/inbandtelemetry/api/BUCK
@@ -0,0 +1,14 @@
+COMPILE_DEPS = [
+ '//lib:CORE_DEPS',
+ '//lib:KRYO',
+ '//core/store/serializers:onos-core-serializers',
+]
+
+TEST_DEPS = [
+ '//lib:TEST_ADAPTERS',
+]
+
+osgi_jar_with_tests (
+ deps = COMPILE_DEPS,
+ test_deps = TEST_DEPS,
+)
diff --git a/apps/inbandtelemetry/api/pom.xml b/apps/inbandtelemetry/api/pom.xml
new file mode 100644
index 0000000..a6c79aa
--- /dev/null
+++ b/apps/inbandtelemetry/api/pom.xml
@@ -0,0 +1,47 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Copyright 2016-present Open Networking Foundation
+ ~
+ ~ Licensed under the Apache License, Version 2.0 (the "License");
+ ~ you may not use this file except in compliance with the License.
+ ~ You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ~ See the License for the specific language governing permissions and
+ ~ limitations under the License.
+ -->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <artifactId>onos-apps-inbandtelemetry</artifactId>
+ <groupId>org.onosproject</groupId>
+ <version>1.14.0-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>onos-apps-inbandtelemetry-api</artifactId>
+ <packaging>bundle</packaging>
+
+ <url>http://onosproject.org</url>
+
+ <description>P4 INT Management Application API</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.onosproject</groupId>
+ <artifactId>onlab-junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.onosproject</groupId>
+ <artifactId>onos-core-serializers</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ </dependencies>
+</project>
diff --git a/apps/inbandtelemetry/intmgr/src/main/java/org/onosproject/inbandtelemetry/api/IntConfig.java b/apps/inbandtelemetry/api/src/main/java/org/onosproject/inbandtelemetry/api/IntConfig.java
similarity index 85%
rename from apps/inbandtelemetry/intmgr/src/main/java/org/onosproject/inbandtelemetry/api/IntConfig.java
rename to apps/inbandtelemetry/api/src/main/java/org/onosproject/inbandtelemetry/api/IntConfig.java
index dc93312..a3e6148 100644
--- a/apps/inbandtelemetry/intmgr/src/main/java/org/onosproject/inbandtelemetry/api/IntConfig.java
+++ b/apps/inbandtelemetry/api/src/main/java/org/onosproject/inbandtelemetry/api/IntConfig.java
@@ -18,7 +18,9 @@
import com.google.common.annotations.Beta;
import org.onlab.packet.IpAddress;
import org.onlab.packet.MacAddress;
-import org.onosproject.net.Port;
+import org.onlab.packet.TpPort;
+
+import static com.google.common.base.Preconditions.checkNotNull;
/**
* Network-level INT configuration.
@@ -46,14 +48,14 @@
}
private final IpAddress collectorIp;
- private final Port collectorPort;
+ private final TpPort collectorPort;
private final MacAddress collectorNextHopMac;
private final IpAddress sinkIp;
private final MacAddress sinkMac;
private final TelemetrySpec spec;
private boolean enabled;
- private IntConfig(IpAddress collectorIp, Port collectorPort, MacAddress collectorNextHopMac,
+ private IntConfig(IpAddress collectorIp, TpPort collectorPort, MacAddress collectorNextHopMac,
IpAddress sinkIp, MacAddress sinkMac, TelemetrySpec spec, boolean enabled) {
this.collectorIp = collectorIp;
this.collectorPort = collectorPort;
@@ -82,7 +84,7 @@
*
* @return collector UDP port number
*/
- public Port collectorPort() {
+ public TpPort collectorPort() {
return collectorPort;
}
@@ -125,7 +127,7 @@
}
/**
- * Returns the type of telemetry spec (P4INT or IOAM).
+ * Returns the type of telemetry spec as per {@link TelemetrySpec}.
*
* @return telemetry spec
*/
@@ -143,12 +145,21 @@
}
/**
+ * Returns a new builder.
+ *
+ * @return new builder
+ */
+ public static Builder builder() {
+ return new Builder();
+ }
+
+ /**
* An IntConfig object builder.
*/
public static final class Builder {
private IpAddress collectorIp;
- private Port collectorPort;
+ private TpPort collectorPort;
private MacAddress collectorNextHopMac;
private IpAddress sinkIp;
private MacAddress sinkMac;
@@ -172,7 +183,7 @@
* @param collectorPort UDP port number of the collector
* @return an IntConfig builder
*/
- public IntConfig.Builder withCollectorPort(Port collectorPort) {
+ public IntConfig.Builder withCollectorPort(TpPort collectorPort) {
this.collectorPort = collectorPort;
return this;
}
@@ -229,17 +240,22 @@
* @param enabled the status of INT
* @return an IntConfig builder
*/
- public IntConfig.Builder withEnabled(boolean enabled) {
+ public IntConfig.Builder enabled(boolean enabled) {
this.enabled = enabled;
return this;
}
/**
- * Bulids the IntConfig object.
+ * Builds the IntConfig object.
*
* @return an IntConfig object
*/
public IntConfig build() {
+ checkNotNull(collectorIp, "Collector IP should be specified.");
+ checkNotNull(collectorPort, "Collector port number should be specified.");
+ checkNotNull(collectorNextHopMac, "Next hop MAC address for report packets should be provided.");
+ checkNotNull(sinkIp, "Sink IP address for report packets should be specified.");
+ checkNotNull(sinkMac, "Sink MAC address for report packets should be specified.");
return new IntConfig(collectorIp, collectorPort, collectorNextHopMac,
sinkIp, sinkMac, spec, enabled);
}
diff --git a/apps/inbandtelemetry/intmgr/src/main/java/org/onosproject/inbandtelemetry/api/IntIntent.java b/apps/inbandtelemetry/api/src/main/java/org/onosproject/inbandtelemetry/api/IntIntent.java
similarity index 98%
rename from apps/inbandtelemetry/intmgr/src/main/java/org/onosproject/inbandtelemetry/api/IntIntent.java
rename to apps/inbandtelemetry/api/src/main/java/org/onosproject/inbandtelemetry/api/IntIntent.java
index 4cc1ff2..21d5381 100644
--- a/apps/inbandtelemetry/intmgr/src/main/java/org/onosproject/inbandtelemetry/api/IntIntent.java
+++ b/apps/inbandtelemetry/api/src/main/java/org/onosproject/inbandtelemetry/api/IntIntent.java
@@ -204,6 +204,15 @@
}
/**
+ * Returns a new builder.
+ *
+ * @return new builder
+ */
+ public static Builder builder() {
+ return new Builder();
+ }
+
+ /**
* An IntIntent builder.
*/
public static final class Builder {
diff --git a/apps/inbandtelemetry/api/src/main/java/org/onosproject/inbandtelemetry/api/IntIntentId.java b/apps/inbandtelemetry/api/src/main/java/org/onosproject/inbandtelemetry/api/IntIntentId.java
new file mode 100644
index 0000000..293cbdb
--- /dev/null
+++ b/apps/inbandtelemetry/api/src/main/java/org/onosproject/inbandtelemetry/api/IntIntentId.java
@@ -0,0 +1,51 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.inbandtelemetry.api;
+
+import org.onlab.util.Identifier;
+
+/**
+ * Representation of a IntIntent ID.
+ */
+public final class IntIntentId extends Identifier<Long> {
+ private IntIntentId(long id) {
+ super(id);
+ }
+
+ /**
+ * Creates an IntIntent ID from a given long value.
+ *
+ * @param id long value
+ * @return IntIntent ID
+ */
+ public static IntIntentId valueOf(long id) {
+ return new IntIntentId(id);
+ }
+
+ /**
+ * Gets the IntIntent ID value.
+ *
+ * @return IntIntent ID value as long
+ */
+ public long value() {
+ return this.identifier;
+ }
+
+ @Override
+ public String toString() {
+ return Long.toHexString(this.identifier);
+ }
+}
diff --git a/apps/inbandtelemetry/api/src/main/java/org/onosproject/inbandtelemetry/api/IntObjective.java b/apps/inbandtelemetry/api/src/main/java/org/onosproject/inbandtelemetry/api/IntObjective.java
new file mode 100644
index 0000000..da8dc29
--- /dev/null
+++ b/apps/inbandtelemetry/api/src/main/java/org/onosproject/inbandtelemetry/api/IntObjective.java
@@ -0,0 +1,135 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.inbandtelemetry.api;
+
+import org.onosproject.net.flow.DefaultTrafficSelector;
+import org.onosproject.net.flow.TrafficSelector;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import static com.google.common.base.Preconditions.checkArgument;
+import static com.google.common.base.Preconditions.checkNotNull;
+import static org.onosproject.inbandtelemetry.api.IntIntent.IntMetadataType;
+import static org.onosproject.inbandtelemetry.api.IntIntent.IntHeaderType;
+
+public final class IntObjective {
+
+ private static final int DEFAULT_PRIORITY = 10;
+
+ // TrafficSelector to describe target flows to monitor
+ private final TrafficSelector selector;
+ // Set of metadata types to collect
+ private final Set<IntMetadataType> metadataTypes;
+ // Type of header (either hop-by-hop or destination)
+ private final IntHeaderType headerType;
+
+ /**
+ * Creates an IntObjective.
+ *
+ * @param selector the traffic selector that identifies traffic to enable INT
+ * @param metadataTypes a set of metadata types to collect
+ * @param headerType the type of INT header
+ */
+ private IntObjective(TrafficSelector selector, Set<IntMetadataType> metadataTypes,
+ IntHeaderType headerType) {
+ this.selector = selector;
+ this.metadataTypes = metadataTypes;
+ this.headerType = headerType;
+ }
+
+ /**
+ * Returns traffic selector of this objective.
+ *
+ * @return traffic selector
+ */
+ public TrafficSelector selector() {
+ return selector;
+ }
+
+ /**
+ * Returns a set of metadata types specified in this objective.
+ *
+ * @return instruction bitmap
+ */
+ public Set<IntMetadataType> metadataTypes() {
+ return metadataTypes;
+ }
+
+ /**
+ * Returns a INT header type specified in this objective.
+ *
+ * @return INT header type
+ */
+ public IntHeaderType headerType() {
+ return headerType;
+ }
+
+ /**
+ * An IntObjective builder.
+ */
+ public static final class Builder {
+ private TrafficSelector selector = DefaultTrafficSelector.emptySelector();
+ private Set<IntMetadataType> metadataTypes = new HashSet<>();
+ private IntHeaderType headerType = IntHeaderType.HOP_BY_HOP;
+
+ /**
+ * Assigns a selector to the IntObjective.
+ *
+ * @param selector a traffic selector
+ * @return an IntObjective builder
+ */
+ public IntObjective.Builder withSelector(TrafficSelector selector) {
+ this.selector = selector;
+ return this;
+ }
+
+ /**
+ * Add a metadata type to the IntObjective.
+ *
+ * @param metadataTypes a set of metadata types
+ * @return an IntObjective builder
+ */
+ public IntObjective.Builder withMetadataTypes(Set<IntMetadataType> metadataTypes) {
+ this.metadataTypes.addAll(metadataTypes);
+ return this;
+ }
+
+ /**
+ * Assigns a header type to the IntObjective.
+ *
+ * @param headerType a header type
+ * @return an IntObjective builder
+ */
+ public IntObjective.Builder withHeaderType(IntHeaderType headerType) {
+ this.headerType = headerType;
+ return this;
+ }
+
+ /**
+ * Builds the IntObjective.
+ *
+ * @return an IntObjective
+ */
+ public IntObjective build() {
+ checkArgument(!selector.criteria().isEmpty(), "Empty selector cannot match any flow.");
+ checkArgument(!metadataTypes.isEmpty(), "Metadata types cannot be empty");
+ checkNotNull(headerType, "Header type cannot be null.");
+
+ return new IntObjective(selector, metadataTypes, headerType);
+ }
+ }
+}
diff --git a/apps/inbandtelemetry/api/src/main/java/org/onosproject/inbandtelemetry/api/IntProgrammable.java b/apps/inbandtelemetry/api/src/main/java/org/onosproject/inbandtelemetry/api/IntProgrammable.java
new file mode 100644
index 0000000..452b787
--- /dev/null
+++ b/apps/inbandtelemetry/api/src/main/java/org/onosproject/inbandtelemetry/api/IntProgrammable.java
@@ -0,0 +1,57 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.inbandtelemetry.api;
+
+import com.google.common.annotations.Beta;
+import org.onosproject.net.driver.HandlerBehaviour;
+
+import java.util.concurrent.CompletableFuture;
+
+@Beta
+public interface IntProgrammable extends HandlerBehaviour {
+
+ /**
+ * Initializes the pipeline, by installing required flow rules
+ * not relevant to specific watchlist, report and event.
+ */
+ void init();
+
+ /**
+ * Adds a given IntObjective to the device.
+ *
+ * @param obj an IntObjective
+ * @return true if the objective is successfully added; false otherwise.
+ */
+ CompletableFuture<Boolean> addIntObjective(IntObjective obj);
+
+ /**
+ * Removes a given IntObjective entry from the device.
+ *
+ * @param obj an IntObjective
+ * @return true if the objective is successfully removed; false otherwise.
+ */
+ CompletableFuture<Boolean> removeIntObjective(IntObjective obj);
+
+ /**
+ * Set up report-related configuration.
+ *
+ * @param config a configuration regarding to the collector
+ * @return true if the objective is successfully added; false otherwise.
+ */
+ CompletableFuture<Boolean> setupIntConfig(IntConfig config);
+
+ //TODO: [ONOS-7616] Design IntEvent and related APIs
+}
diff --git a/apps/inbandtelemetry/intmgr/src/main/java/org/onosproject/inbandtelemetry/api/IntService.java b/apps/inbandtelemetry/api/src/main/java/org/onosproject/inbandtelemetry/api/IntService.java
similarity index 84%
rename from apps/inbandtelemetry/intmgr/src/main/java/org/onosproject/inbandtelemetry/api/IntService.java
rename to apps/inbandtelemetry/api/src/main/java/org/onosproject/inbandtelemetry/api/IntService.java
index a666a1b..ef2e1ad 100644
--- a/apps/inbandtelemetry/intmgr/src/main/java/org/onosproject/inbandtelemetry/api/IntService.java
+++ b/apps/inbandtelemetry/api/src/main/java/org/onosproject/inbandtelemetry/api/IntService.java
@@ -18,6 +18,7 @@
import com.google.common.annotations.Beta;
import org.onosproject.net.DeviceId;
+import java.util.Map;
import java.util.Set;
/**
@@ -88,24 +89,31 @@
* Installs an IntIntent to devices.
*
* @param intIntent an IntIntent
- * @return an ID corresponding to given intIntent
+ * @return an IntIntent ID corresponding to given intIntent
*/
- int installIntIntent(IntIntent intIntent);
+ IntIntentId installIntIntent(IntIntent intIntent);
/**
* Removes an IntIntent from devices.
*
* @param intentId ID of the intIntent to remove
*/
- void removeIntIntent(int intentId);
+ void removeIntIntent(IntIntentId intentId);
/**
- * Returns an intIntent for given intent ID.
+ * Returns an IntIntent for given intent ID.
*
- * @param intentId id of the intIntent to retrieve
+ * @param intentId ID of the intIntent to retrieve
* @return an IntIntent
*/
- IntIntent getIntIntent(int intentId);
+ IntIntent getIntIntent(IntIntentId intentId);
+
+ /**
+ * Returns all IntIntents installed in the network.
+ *
+ * @return an IntIntent
+ */
+ Map<IntIntentId, IntIntent> getIntIntents();
//TODO: [ONOS-7616] Design IntEvent and related APIs
}
\ No newline at end of file
diff --git a/apps/inbandtelemetry/intmgr/src/main/java/org/onosproject/inbandtelemetry/api/package-info.java b/apps/inbandtelemetry/api/src/main/java/org/onosproject/inbandtelemetry/api/package-info.java
similarity index 100%
rename from apps/inbandtelemetry/intmgr/src/main/java/org/onosproject/inbandtelemetry/api/package-info.java
rename to apps/inbandtelemetry/api/src/main/java/org/onosproject/inbandtelemetry/api/package-info.java
diff --git a/apps/inbandtelemetry/pom.xml b/apps/inbandtelemetry/pom.xml
new file mode 100644
index 0000000..0105fbe
--- /dev/null
+++ b/apps/inbandtelemetry/pom.xml
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Copyright 2015-present Open Networking Foundation
+ ~
+ ~ Licensed under the Apache License, Version 2.0 (the "License");
+ ~ you may not use this file except in compliance with the License.
+ ~ You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ~ See the License for the specific language governing permissions and
+ ~ limitations under the License.
+ -->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.onosproject</groupId>
+ <artifactId>onos-apps</artifactId>
+ <version>1.14.0-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>onos-apps-inbandtelemetry</artifactId>
+ <packaging>pom</packaging>
+
+ <description>ONOS In-band Network Telemetry applications</description>
+
+ <modules>
+ <module>api</module>
+ <module>impl</module>
+ </modules>
+</project>
diff --git a/pipelines/basic/BUCK b/pipelines/basic/BUCK
index 1b6cc47..26e74dd 100644
--- a/pipelines/basic/BUCK
+++ b/pipelines/basic/BUCK
@@ -4,10 +4,12 @@
'//drivers/default:onos-drivers-default',
'//protocols/p4runtime/model:onos-protocols-p4runtime-model',
'//protocols/p4runtime/api:onos-protocols-p4runtime-api',
+ '//apps/inbandtelemetry/api:onos-apps-inbandtelemetry-api',
]
BUNDLES = [
'//pipelines/basic:onos-pipelines-basic',
+ '//apps/inbandtelemetry/api:onos-apps-inbandtelemetry-api',
]
osgi_jar(
diff --git a/pipelines/basic/pom.xml b/pipelines/basic/pom.xml
index c6dd90e..ad08d38 100644
--- a/pipelines/basic/pom.xml
+++ b/pipelines/basic/pom.xml
@@ -47,5 +47,11 @@
<artifactId>onos-drivers-default</artifactId>
<version>${project.version}</version>
</dependency>
+
+ <dependency>
+ <groupId>org.onosproject</groupId>
+ <artifactId>onos-apps-inbandtelemetry-api</artifactId>
+ <version>${project.version}</version>
+ </dependency>
</dependencies>
</project>
diff --git a/pipelines/basic/src/main/java/org/onosproject/pipelines/basic/IntConstants.java b/pipelines/basic/src/main/java/org/onosproject/pipelines/basic/IntConstants.java
index 8ae743d..2f86688 100644
--- a/pipelines/basic/src/main/java/org/onosproject/pipelines/basic/IntConstants.java
+++ b/pipelines/basic/src/main/java/org/onosproject/pipelines/basic/IntConstants.java
@@ -34,11 +34,13 @@
}
// Strings
+ private static final String EGRESS = "egress";
private static final String CTRL_SET_SOURCE_SINK = EGRESS + DOT + "process_set_source_sink";
private static final String CTRL_INT_SOURCE = EGRESS + DOT + "process_int_source";
private static final String CTRL_INT_TRANSIT = EGRESS + DOT + "process_int_transit";
private static final String CTRL_INT_SINK = EGRESS + DOT + "process_int_sink";
private static final String CTRL_INT_OUTER_ENCAP = EGRESS + DOT + "process_int_outer_encap";
+ private static final String CTRL_INT_REPORT = EGRESS + DOT + "process_int_report";
private static final String INT_METADATA = "int_meta";
private static final String INT_HDR = "int_header";
@@ -55,6 +57,8 @@
PiMatchFieldId.of(HDR + DOT + INT_HDR + DOT + "instruction_mask_0407");
public static final PiMatchFieldId HDR_OUT_PORT_ID =
PiMatchFieldId.of(STANDARD_METADATA + DOT + "egress_port");
+ public static final PiMatchFieldId STD_META_INSTANCE_TYPE_ID =
+ PiMatchFieldId.of(STANDARD_METADATA + DOT + "instance_type");
// Table IDs
public static final PiTableId TBL_SET_SOURCE_ID =
@@ -69,6 +73,8 @@
PiTableId.of(CTRL_INT_TRANSIT + DOT + "tb_int_inst_0003");
public static final PiTableId TBL_INT_INST_0407_ID =
PiTableId.of(CTRL_INT_TRANSIT + DOT + "tb_int_inst_0407");
+ public static final PiTableId TBL_GENERATE_REPORT_ID =
+ PiTableId.of(CTRL_INT_REPORT + DOT + "tb_generate_report");
// Counter IDs
public static final PiCounterId CNT_SET_SOURCE_SINK_ID =
@@ -167,6 +173,8 @@
PiActionId.of(CTRL_INT_SINK + DOT + "restore_header");
public static final PiActionId ACT_INT_SINK_ID =
PiActionId.of(CTRL_INT_SINK + DOT + "int_sink");
+ public static final PiActionId ACT_DO_REPORT_ENCAP_ID =
+ PiActionId.of(CTRL_INT_REPORT + DOT + "do_report_encapsulation");
// Action param IDs
public static final PiActionParamId ACT_PRM_MAX_HOP_ID = PiActionParamId.of("max_hop");
@@ -174,4 +182,10 @@
public static final PiActionParamId ACT_PRM_INS_MASK0003_ID = PiActionParamId.of("ins_mask0003");
public static final PiActionParamId ACT_PRM_INS_MASK0407_ID = PiActionParamId.of("ins_mask0407");
public static final PiActionParamId ACT_PRM_SWITCH_ID = PiActionParamId.of("switch_id");
+ public static final PiActionParamId ACT_PRM_SRC_MAC_ID = PiActionParamId.of("src_mac");
+ public static final PiActionParamId ACT_PRM_MON_MAC_ID = PiActionParamId.of("mon_mac");
+ public static final PiActionParamId ACT_PRM_SRC_IP_ID = PiActionParamId.of("src_ip");
+ public static final PiActionParamId ACT_PRM_MON_IP_ID = PiActionParamId.of("mon_ip");
+ public static final PiActionParamId ACT_PRM_MON_PORT_ID = PiActionParamId.of("mon_port");
+
}
diff --git a/pipelines/basic/src/main/java/org/onosproject/pipelines/basic/IntProgrammableImpl.java b/pipelines/basic/src/main/java/org/onosproject/pipelines/basic/IntProgrammableImpl.java
new file mode 100644
index 0000000..417043d
--- /dev/null
+++ b/pipelines/basic/src/main/java/org/onosproject/pipelines/basic/IntProgrammableImpl.java
@@ -0,0 +1,527 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.pipelines.basic;
+
+import com.google.common.collect.ImmutableBiMap;
+import com.google.common.collect.Sets;
+import org.apache.felix.scr.annotations.Reference;
+import org.apache.felix.scr.annotations.ReferenceCardinality;
+import org.onlab.util.ImmutableByteSequence;
+import org.onlab.util.SharedExecutors;
+import org.onosproject.core.ApplicationId;
+import org.onosproject.core.CoreService;
+import org.onosproject.inbandtelemetry.api.IntConfig;
+import org.onosproject.inbandtelemetry.api.IntIntent;
+import org.onosproject.inbandtelemetry.api.IntObjective;
+import org.onosproject.inbandtelemetry.api.IntProgrammable;
+import org.onosproject.net.ConnectPoint;
+import org.onosproject.net.DeviceId;
+import org.onosproject.net.Port;
+import org.onosproject.net.PortNumber;
+import org.onosproject.net.device.DeviceService;
+import org.onosproject.net.driver.AbstractHandlerBehaviour;
+import org.onosproject.net.flow.DefaultFlowRule;
+import org.onosproject.net.flow.DefaultTrafficSelector;
+import org.onosproject.net.flow.DefaultTrafficTreatment;
+import org.onosproject.net.flow.FlowRule;
+import org.onosproject.net.flow.FlowRuleService;
+import org.onosproject.net.flow.TrafficSelector;
+import org.onosproject.net.flow.TrafficTreatment;
+import org.onosproject.net.flow.criteria.Criterion;
+import org.onosproject.net.flow.criteria.IPCriterion;
+import org.onosproject.net.flow.criteria.PiCriterion;
+import org.onosproject.net.flow.criteria.TcpPortCriterion;
+import org.onosproject.net.flow.criteria.UdpPortCriterion;
+import org.onosproject.net.host.HostService;
+import org.onosproject.net.pi.model.PiActionId;
+import org.onosproject.net.pi.model.PiMatchFieldId;
+import org.onosproject.net.pi.model.PiTableId;
+import org.onosproject.net.pi.runtime.PiAction;
+import org.onosproject.net.pi.runtime.PiActionParam;
+import org.slf4j.Logger;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+import java.util.concurrent.CompletableFuture;
+import java.util.stream.Collectors;
+
+import static org.slf4j.LoggerFactory.getLogger;
+
+public class IntProgrammableImpl extends AbstractHandlerBehaviour implements IntProgrammable {
+
+ // TODO: change this value to the value of diameter of a network.
+ private static final int MAXHOP = 64;
+ private static final int PORTMASK = 0xffff;
+ private static final int IDLE_TIMEOUT = 100;
+ private static final int PKT_INSTANCE_TYPE_INGRESS_CLONE = 1;
+ // Application name of the pipeline which adds this implementation to the pipeconf
+ private static final String PIPELINE_APP_NAME = "org.onosproject.pipelines.basic";
+ private final Logger log = getLogger(getClass());
+ private ApplicationId appId;
+
+ private static final Set<Criterion.Type> SUPPORTED_CRITERION = Sets.newHashSet(
+ Criterion.Type.IPV4_DST, Criterion.Type.IPV4_SRC,
+ Criterion.Type.UDP_SRC, Criterion.Type.UDP_DST,
+ Criterion.Type.TCP_SRC, Criterion.Type.TCP_DST,
+ Criterion.Type.IP_PROTO);
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ private FlowRuleService flowRuleService;
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ private DeviceService deviceService;
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ private HostService hostService;
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ private CoreService coreService;
+
+ private DeviceId deviceId;
+ private static final int DEFAULT_PRIORITY = 10000;
+ private static final ImmutableBiMap<Integer, PiActionId> INST_0003_ACTION_MAP =
+ ImmutableBiMap.<Integer, PiActionId>builder()
+ .put(0, IntConstants.ACT_INT_SET_HEADER_0003_I0_ID)
+ .put(1, IntConstants.ACT_INT_SET_HEADER_0003_I1_ID)
+ .put(2, IntConstants.ACT_INT_SET_HEADER_0003_I2_ID)
+ .put(3, IntConstants.ACT_INT_SET_HEADER_0003_I3_ID)
+ .put(4, IntConstants.ACT_INT_SET_HEADER_0003_I4_ID)
+ .put(5, IntConstants.ACT_INT_SET_HEADER_0003_I5_ID)
+ .put(6, IntConstants.ACT_INT_SET_HEADER_0003_I6_ID)
+ .put(7, IntConstants.ACT_INT_SET_HEADER_0003_I7_ID)
+ .put(8, IntConstants.ACT_INT_SET_HEADER_0003_I8_ID)
+ .put(9, IntConstants.ACT_INT_SET_HEADER_0003_I9_ID)
+ .put(10, IntConstants.ACT_INT_SET_HEADER_0003_I10_ID)
+ .put(11, IntConstants.ACT_INT_SET_HEADER_0003_I11_ID)
+ .put(12, IntConstants.ACT_INT_SET_HEADER_0003_I12_ID)
+ .put(13, IntConstants.ACT_INT_SET_HEADER_0003_I13_ID)
+ .put(14, IntConstants.ACT_INT_SET_HEADER_0003_I14_ID)
+ .put(15, IntConstants.ACT_INT_SET_HEADER_0003_I15_ID)
+ .build();
+
+ private static final ImmutableBiMap<Integer, PiActionId> INST_0407_ACTION_MAP =
+ ImmutableBiMap.<Integer, PiActionId>builder()
+ .put(0, IntConstants.ACT_INT_SET_HEADER_0407_I0_ID)
+ .put(1, IntConstants.ACT_INT_SET_HEADER_0407_I1_ID)
+ .put(2, IntConstants.ACT_INT_SET_HEADER_0407_I2_ID)
+ .put(3, IntConstants.ACT_INT_SET_HEADER_0407_I3_ID)
+ .put(4, IntConstants.ACT_INT_SET_HEADER_0407_I4_ID)
+ .put(5, IntConstants.ACT_INT_SET_HEADER_0407_I5_ID)
+ .put(6, IntConstants.ACT_INT_SET_HEADER_0407_I6_ID)
+ .put(7, IntConstants.ACT_INT_SET_HEADER_0407_I7_ID)
+ .put(8, IntConstants.ACT_INT_SET_HEADER_0407_I8_ID)
+ .put(9, IntConstants.ACT_INT_SET_HEADER_0407_I9_ID)
+ .put(10, IntConstants.ACT_INT_SET_HEADER_0407_I10_ID)
+ .put(11, IntConstants.ACT_INT_SET_HEADER_0407_I11_ID)
+ .put(12, IntConstants.ACT_INT_SET_HEADER_0407_I12_ID)
+ .put(13, IntConstants.ACT_INT_SET_HEADER_0407_I13_ID)
+ .put(14, IntConstants.ACT_INT_SET_HEADER_0407_I14_ID)
+ .put(15, IntConstants.ACT_INT_SET_HEADER_0407_I15_ID)
+ .build();
+
+ @Override
+ public void init() {
+ deviceId = this.data().deviceId();
+ flowRuleService = handler().get(FlowRuleService.class);
+ deviceService = handler().get(DeviceService.class);
+ hostService = handler().get(HostService.class);
+ coreService = handler().get(CoreService.class);
+ appId = coreService.getAppId(PIPELINE_APP_NAME);
+ if (appId == null) {
+ log.warn("Application ID is null. Cannot initialize INT-pipeline.");
+ return;
+ }
+
+ Set<PortNumber> hostPorts = deviceService.getPorts(deviceId).stream().filter(port ->
+ hostService.getConnectedHosts(new ConnectPoint(deviceId, port.number())).size() > 0
+ ).map(Port::number).collect(Collectors.toSet());
+ List<FlowRule> flowRules = new ArrayList<>();
+
+ // process_int_transit.tb_int_insert
+ PiActionParam transitIdParam = new PiActionParam(
+ IntConstants.ACT_PRM_SWITCH_ID,
+ ImmutableByteSequence.copyFrom(
+ Integer.parseInt(deviceId.toString().substring(
+ deviceId.toString().length() - 2))));
+ PiAction transitAction = PiAction.builder()
+ .withId(IntConstants.ACT_INT_TRANSIT_ID)
+ .withParameter(transitIdParam)
+ .build();
+ TrafficTreatment treatment = DefaultTrafficTreatment.builder()
+ .piTableAction(transitAction)
+ .build();
+
+ FlowRule transitFlowRule = DefaultFlowRule.builder()
+ .withTreatment(treatment)
+ .fromApp(appId)
+ .withPriority(DEFAULT_PRIORITY)
+ .makePermanent()
+ .forDevice(deviceId)
+ .forTable(IntConstants.TBL_INT_INSERT_ID)
+ .build();
+ flowRules.add(transitFlowRule);
+
+ for (PortNumber portNumber: hostPorts) {
+ // process_set_source_sink.tb_set_source for each host-facing port
+ PiCriterion ingressCriterion = PiCriterion.builder()
+ .matchExact(BasicConstants.HDR_IN_PORT_ID, portNumber.toLong())
+ .build();
+ TrafficSelector srcSelector = DefaultTrafficSelector.builder()
+ .matchPi(ingressCriterion)
+ .build();
+ PiAction setSourceAct = PiAction.builder()
+ .withId(IntConstants.ACT_INT_SET_SOURCE_ID)
+ .build();
+ TrafficTreatment srcTreatment = DefaultTrafficTreatment.builder()
+ .piTableAction(setSourceAct)
+ .build();
+ FlowRule srcFlowRule = DefaultFlowRule.builder()
+ .withSelector(srcSelector)
+ .withTreatment(srcTreatment)
+ .fromApp(appId)
+ .withPriority(DEFAULT_PRIORITY)
+ .makePermanent()
+ .forDevice(deviceId)
+ .forTable(IntConstants.TBL_SET_SOURCE_ID)
+ .build();
+ flowRules.add(srcFlowRule);
+
+ // process_set_source_sink.tb_set_sink
+ PiCriterion egressCriterion = PiCriterion.builder()
+ .matchExact(IntConstants.HDR_OUT_PORT_ID, portNumber.toLong())
+ .build();
+ TrafficSelector sinkSelector = DefaultTrafficSelector.builder()
+ .matchPi(egressCriterion)
+ .build();
+ PiAction setSinkAct = PiAction.builder()
+ .withId(IntConstants.ACT_INT_SET_SINK_ID)
+ .build();
+ TrafficTreatment sinkTreatment = DefaultTrafficTreatment.builder()
+ .piTableAction(setSinkAct)
+ .build();
+ FlowRule sinkFlowRule = DefaultFlowRule.builder()
+ .withSelector(sinkSelector)
+ .withTreatment(sinkTreatment)
+ .fromApp(appId)
+ .withPriority(DEFAULT_PRIORITY)
+ .makePermanent()
+ .forDevice(deviceId)
+ .forTable(IntConstants.TBL_SET_SINK_ID)
+ .build();
+ flowRules.add(sinkFlowRule);
+ }
+ flowRules.forEach(flowRule -> flowRuleService.applyFlowRules(flowRule));
+
+ // Populate tb_int_inst_0003 table
+ INST_0003_ACTION_MAP.forEach((matchValue, actionId) ->
+ populateInstTableEntry(IntConstants.TBL_INT_INST_0003_ID,
+ IntConstants.INT_HDR_INST_MASK_0003_ID,
+ matchValue,
+ actionId,
+ appId));
+ // Populate tb_int_inst_0407 table
+ INST_0407_ACTION_MAP.forEach((matchValue, actionId) ->
+ populateInstTableEntry(IntConstants.TBL_INT_INST_0407_ID,
+ IntConstants.INT_HDR_INST_MASK_0407_ID,
+ matchValue,
+ actionId,
+ appId));
+ }
+
+ @Override
+ public CompletableFuture<Boolean> addIntObjective(IntObjective obj) {
+ // TODO: support different types of watchlist other than flow watchlist
+
+ return CompletableFuture.supplyAsync(
+ () -> processIntObjective(obj, true),
+ SharedExecutors.getPoolThreadExecutor()
+ );
+ }
+
+ @Override
+ public CompletableFuture<Boolean> removeIntObjective(IntObjective obj) {
+ return CompletableFuture.supplyAsync(
+ () -> processIntObjective(obj, false),
+ SharedExecutors.getPoolThreadExecutor()
+ );
+ }
+
+ @Override
+ public CompletableFuture<Boolean> setupIntConfig(IntConfig config) {
+ return CompletableFuture.supplyAsync(
+ () -> setupIntReportInternal(config),
+ SharedExecutors.getPoolThreadExecutor()
+ );
+ }
+
+ private void populateInstTableEntry(PiTableId tableId, PiMatchFieldId matchFieldId,
+ int matchValue, PiActionId actionId, ApplicationId appId) {
+ PiCriterion instCriterion = PiCriterion.builder()
+ .matchExact(matchFieldId, matchValue)
+ .build();
+ TrafficSelector instSelector = DefaultTrafficSelector.builder()
+ .matchPi(instCriterion)
+ .build();
+ PiAction instAction = PiAction.builder()
+ .withId(actionId)
+ .build();
+ TrafficTreatment instTreatment = DefaultTrafficTreatment.builder()
+ .piTableAction(instAction)
+ .build();
+
+ FlowRule instFlowRule = DefaultFlowRule.builder()
+ .withSelector(instSelector)
+ .withTreatment(instTreatment)
+ .withPriority(DEFAULT_PRIORITY)
+ .makePermanent()
+ .forDevice(deviceId)
+ .forTable(tableId)
+ .fromApp(appId)
+ .build();
+
+ flowRuleService.applyFlowRules(instFlowRule);
+ }
+
+ private FlowRule buildWatchlistEntry(IntObjective obj) {
+ coreService = handler().get(CoreService.class);
+ appId = coreService.getAppId(PIPELINE_APP_NAME);
+ if (appId == null) {
+ log.warn("Application ID is null. Cannot initialize INT-pipeline.");
+ return null;
+ }
+ int instructionBitmap = buildInstructionBitmap(obj.metadataTypes());
+ PiActionParam maxHopParam = new PiActionParam(
+ IntConstants.ACT_PRM_MAX_HOP_ID,
+ ImmutableByteSequence.copyFrom(MAXHOP));
+ PiActionParam instCntParam = new PiActionParam(
+ IntConstants.ACT_PRM_INS_CNT_ID,
+ ImmutableByteSequence.copyFrom(Integer.bitCount(instructionBitmap)));
+ PiActionParam inst0003Param = new PiActionParam(
+ IntConstants.ACT_PRM_INS_MASK0003_ID,
+ ImmutableByteSequence.copyFrom((instructionBitmap >> 12) & 0xF));
+ PiActionParam inst0407Param = new PiActionParam(
+ IntConstants.ACT_PRM_INS_MASK0407_ID,
+ ImmutableByteSequence.copyFrom((instructionBitmap >> 8) & 0xF));
+
+ PiAction intSourceAction = PiAction.builder()
+ .withId(IntConstants.ACT_INT_SOURCE_DSCP_ID)
+ .withParameter(maxHopParam)
+ .withParameter(instCntParam)
+ .withParameter(inst0003Param)
+ .withParameter(inst0407Param)
+ .build();
+
+ TrafficTreatment instTreatment = DefaultTrafficTreatment.builder()
+ .piTableAction(intSourceAction)
+ .build();
+
+ TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder();
+ for (Criterion criterion : obj.selector().criteria()) {
+ switch (criterion.type()) {
+ case IPV4_SRC:
+ sBuilder.matchIPSrc(((IPCriterion) criterion).ip());
+ break;
+ case IPV4_DST:
+ sBuilder.matchIPDst(((IPCriterion) criterion).ip());
+ break;
+ case TCP_SRC:
+ sBuilder.matchPi(
+ PiCriterion.builder().matchTernary(
+ IntConstants.LOCAL_META_SRC_PORT_ID,
+ ((TcpPortCriterion) criterion).tcpPort().toInt(), PORTMASK)
+ .build());
+ break;
+ case UDP_SRC:
+ sBuilder.matchPi(
+ PiCriterion.builder().matchTernary(
+ IntConstants.LOCAL_META_SRC_PORT_ID,
+ ((UdpPortCriterion) criterion).udpPort().toInt(), PORTMASK)
+ .build());
+ break;
+ case TCP_DST:
+ sBuilder.matchPi(
+ PiCriterion.builder().matchTernary(
+ IntConstants.LOCAL_META_DST_PORT_ID,
+ ((TcpPortCriterion) criterion).tcpPort().toInt(), PORTMASK)
+ .build());
+ break;
+ case UDP_DST:
+ sBuilder.matchPi(
+ PiCriterion.builder().matchTernary(
+ IntConstants.LOCAL_META_DST_PORT_ID,
+ ((UdpPortCriterion) criterion).udpPort().toInt(), PORTMASK)
+ .build());
+ break;
+ default:
+ log.warn("Unsupported criterion type: {}", criterion.type());
+ }
+ }
+
+ return DefaultFlowRule.builder()
+ .forDevice(this.data().deviceId())
+ .withSelector(sBuilder.build())
+ .withTreatment(instTreatment)
+ .withPriority(DEFAULT_PRIORITY)
+ .forTable(IntConstants.TBL_INT_SOURCE_ID)
+ .fromApp(appId)
+ .withIdleTimeout(IDLE_TIMEOUT)
+ .build();
+ }
+
+ private int buildInstructionBitmap(Set<IntIntent.IntMetadataType> metadataTypes) {
+ int instBitmap = 0;
+ for (IntIntent.IntMetadataType metadataType : metadataTypes) {
+ switch (metadataType) {
+ case SWITCH_ID:
+ instBitmap |= (1 << 15);
+ break;
+ case L1_PORT_ID:
+ instBitmap |= (1 << 14);
+ break;
+ case HOP_LATENCY:
+ instBitmap |= (1 << 13);
+ break;
+ case QUEUE_OCCUPANCY:
+ instBitmap |= (1 << 12);
+ break;
+ case INGRESS_TIMESTAMP:
+ instBitmap |= (1 << 11);
+ break;
+ case EGRESS_TIMESTAMP:
+ instBitmap |= (1 << 10);
+ break;
+ case L2_PORT_ID:
+ instBitmap |= (1 << 9);
+ break;
+ case EGRESS_TX_UTIL:
+ instBitmap |= (1 << 8);
+ break;
+ default:
+ log.info("Unsupported metadata type {}. Ignoring...", metadataType);
+ break;
+ }
+ }
+ return instBitmap;
+ }
+
+ /**
+ * Returns a subset of Criterion from given selector,
+ * which is unsupported by this INT pipeline.
+ *
+ * @param selector a traffic selector
+ * @return a subset of Criterion from given selector, unsupported by this INT pipeline,
+ * empty if all criteria are supported.
+ */
+ private Set<Criterion> unsupportedSelectors(TrafficSelector selector) {
+ return selector.criteria().stream()
+ .filter(criterion -> !SUPPORTED_CRITERION.contains(criterion.type()))
+ .collect(Collectors.toSet());
+ }
+
+ private boolean processIntObjective(IntObjective obj, boolean install) {
+ flowRuleService = handler().get(FlowRuleService.class);
+ deviceId = this.data().deviceId();
+ if (install && !unsupportedSelectors(obj.selector()).isEmpty()) {
+ log.warn("Device {} does not support criteria {} for INT.",
+ deviceId, unsupportedSelectors(obj.selector()));
+ return false;
+ }
+
+ FlowRule flowRule = buildWatchlistEntry(obj);
+ if (flowRule != null) {
+ if (install) {
+ flowRuleService.applyFlowRules(flowRule);
+ } else {
+ flowRuleService.removeFlowRules(flowRule);
+ }
+ log.debug("IntObjective {} has been {} {}",
+ obj, install ? "installed to" : "removed from", deviceId);
+ return true;
+ } else {
+ log.warn("Failed to {} IntObjective {} on {}",
+ install ? "install" : "remove", obj, deviceId);
+ return false;
+ }
+ }
+
+ private boolean setupIntReportInternal(IntConfig cfg) {
+ flowRuleService = handler().get(FlowRuleService.class);
+
+ FlowRule reportRule = buildReportEntry(cfg, PKT_INSTANCE_TYPE_INGRESS_CLONE);
+ if (reportRule != null) {
+ flowRuleService.applyFlowRules(reportRule);
+ log.info("Report entry {} has been added to {}", reportRule, this.data().deviceId());
+ return true;
+ } else {
+ log.warn("Failed to add report entry on {}", this.data().deviceId());
+ return false;
+ }
+ }
+
+ private FlowRule buildReportEntry(IntConfig cfg, int type) {
+ coreService = handler().get(CoreService.class);
+ appId = coreService.getAppId(PIPELINE_APP_NAME);
+ if (appId == null) {
+ log.warn("Application ID is null. Cannot build report entry.");
+ return null;
+ }
+
+ PiCriterion instTypeCriterion = PiCriterion.builder()
+ .matchExact(IntConstants.STD_META_INSTANCE_TYPE_ID, type)
+ .build();
+ TrafficSelector selector = DefaultTrafficSelector.builder()
+ .matchPi(instTypeCriterion)
+ .build();
+ PiActionParam srcMacParam = new PiActionParam(
+ IntConstants.ACT_PRM_SRC_MAC_ID,
+ ImmutableByteSequence.copyFrom(cfg.sinkMac().toBytes()));
+ PiActionParam nextHopMacParam = new PiActionParam(
+ IntConstants.ACT_PRM_MON_MAC_ID,
+ ImmutableByteSequence.copyFrom(cfg.collectorNextHopMac().toBytes()));
+ PiActionParam srcIpParam = new PiActionParam(
+ IntConstants.ACT_PRM_SRC_IP_ID,
+ ImmutableByteSequence.copyFrom(cfg.sinkIp().toOctets()));
+ PiActionParam monIpParam = new PiActionParam(
+ IntConstants.ACT_PRM_MON_IP_ID,
+ ImmutableByteSequence.copyFrom(cfg.collectorIp().toOctets()));
+ PiActionParam monPortParam = new PiActionParam(
+ IntConstants.ACT_PRM_MON_PORT_ID,
+ ImmutableByteSequence.copyFrom(cfg.collectorPort().toInt()));
+ PiAction reportAction = PiAction.builder()
+ .withId(IntConstants.ACT_DO_REPORT_ENCAP_ID)
+ .withParameter(srcMacParam)
+ .withParameter(nextHopMacParam)
+ .withParameter(srcIpParam)
+ .withParameter(monIpParam)
+ .withParameter(monPortParam)
+ .build();
+ TrafficTreatment treatment = DefaultTrafficTreatment.builder()
+ .piTableAction(reportAction)
+ .build();
+
+ return DefaultFlowRule.builder()
+ .withSelector(selector)
+ .withTreatment(treatment)
+ .fromApp(appId)
+ .withPriority(DEFAULT_PRIORITY)
+ .makePermanent()
+ .forDevice(this.data().deviceId())
+ .forTable(IntConstants.TBL_GENERATE_REPORT_ID)
+ .build();
+ }
+
+}
diff --git a/pipelines/basic/src/main/java/org/onosproject/pipelines/basic/PipeconfLoader.java b/pipelines/basic/src/main/java/org/onosproject/pipelines/basic/PipeconfLoader.java
index 4c2364c..0fbc3a9 100644
--- a/pipelines/basic/src/main/java/org/onosproject/pipelines/basic/PipeconfLoader.java
+++ b/pipelines/basic/src/main/java/org/onosproject/pipelines/basic/PipeconfLoader.java
@@ -22,7 +22,9 @@
import org.apache.felix.scr.annotations.Deactivate;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.ReferenceCardinality;
+import org.onosproject.core.CoreService;
import org.onosproject.driver.pipeline.DefaultSingleTablePipeline;
+import org.onosproject.inbandtelemetry.api.IntProgrammable;
import org.onosproject.net.behaviour.Pipeliner;
import org.onosproject.net.device.PortStatisticsDiscovery;
import org.onosproject.net.pi.model.DefaultPiPipeconf;
@@ -46,6 +48,7 @@
@Component(immediate = true)
public final class PipeconfLoader {
+ private static final String APP_NAME = "org.onosproject.pipelines.basic";
private static final PiPipeconfId BASIC_PIPECONF_ID = new PiPipeconfId("org.onosproject.pipelines.basic");
private static final String BASIC_JSON_PATH = "/p4c-out/bmv2/basic.json";
private static final String BASIC_P4INFO = "/p4c-out/bmv2/basic.p4info";
@@ -63,8 +66,12 @@
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
private PiPipeconfService piPipeconfService;
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ private CoreService coreService;
+
@Activate
public void activate() {
+ coreService.registerApplication(APP_NAME);
// Registers all pipeconf at component activation.
ALL_PIPECONFS.forEach(piPipeconfService::register);
}
@@ -103,6 +110,7 @@
.addBehaviour(PiPipelineInterpreter.class, BasicInterpreterImpl.class)
.addBehaviour(Pipeliner.class, DefaultSingleTablePipeline.class)
.addBehaviour(PortStatisticsDiscovery.class, PortStatisticsDiscoveryImpl.class)
+ .addBehaviour(IntProgrammable.class, IntProgrammableImpl.class)
.addExtension(P4_INFO_TEXT, p4InfoUrl)
.addExtension(BMV2_JSON, jsonUrl)
.build();