aboutsummaryrefslogtreecommitdiffstats
path: root/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/instructions
diff options
context:
space:
mode:
Diffstat (limited to 'framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/instructions')
-rw-r--r--framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/instructions/AbstractExtensionTreatment.java71
-rw-r--r--framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/instructions/ExtensionTreatment.java53
-rw-r--r--framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/instructions/ExtensionTreatmentType.java17
-rw-r--r--framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/instructions/Instructions.java36
-rw-r--r--framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/instructions/L3ModificationInstruction.java162
5 files changed, 214 insertions, 125 deletions
diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/instructions/AbstractExtensionTreatment.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/instructions/AbstractExtensionTreatment.java
deleted file mode 100644
index ac7c771f..00000000
--- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/instructions/AbstractExtensionTreatment.java
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * Copyright 2015 Open Networking Laboratory
- *
- * 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.net.flow.instructions;
-
-import java.lang.reflect.Field;
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * Abstract implementation of the set/get property methods of ExtensionInstruction.
- */
-public abstract class AbstractExtensionTreatment implements ExtensionTreatment {
-
- private static final String INVALID_KEY = "Invalid property key: ";
- private static final String INVALID_TYPE = "Given type does not match field type: ";
-
- @Override
- public <T> void setPropertyValue(String key, T value) throws ExtensionPropertyException {
- Class<?> clazz = this.getClass();
- try {
- Field field = clazz.getDeclaredField(key);
- field.setAccessible(true);
- field.set(this, value);
- } catch (NoSuchFieldException | IllegalAccessException e) {
- throw new ExtensionPropertyException(INVALID_KEY + key);
- }
- }
-
- @Override
- public <T> T getPropertyValue(String key) throws ExtensionPropertyException {
- Class<?> clazz = this.getClass();
- try {
- Field field = clazz.getDeclaredField(key);
- field.setAccessible(true);
- @SuppressWarnings("unchecked")
- T result = (T) field.get(this);
- return result;
- } catch (NoSuchFieldException | IllegalAccessException e) {
- throw new ExtensionPropertyException(INVALID_KEY + key);
- } catch (ClassCastException e) {
- throw new ExtensionPropertyException(INVALID_TYPE + key);
- }
- }
-
- @Override
- public List<String> getProperties() {
- Class<?> clazz = this.getClass();
-
- List<String> fields = new ArrayList<>();
-
- for (Field field : clazz.getDeclaredFields()) {
- fields.add(field.getName());
- }
-
- return fields;
- }
-}
diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/instructions/ExtensionTreatment.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/instructions/ExtensionTreatment.java
index 0e8885ed..3df152e9 100644
--- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/instructions/ExtensionTreatment.java
+++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/instructions/ExtensionTreatment.java
@@ -16,63 +16,18 @@
package org.onosproject.net.flow.instructions;
-import java.util.List;
+import org.onosproject.net.flow.Extension;
/**
- * An extensible instruction type.
+ * An extension for the treatment API.
*/
-public interface ExtensionTreatment {
+public interface ExtensionTreatment extends Extension {
/**
- * Gets the type of the extension instruction.
+ * Gets the type of the treatment extension.
*
* @return type
*/
ExtensionTreatmentType type();
- /**
- * Sets a property on the extension instruction.
- *
- * @param key property key
- * @param value value to set for the given key
- * @param <T> class of the value
- * @throws ExtensionPropertyException if the given key is not a valid
- * property on this extension instruction
- */
- <T> void setPropertyValue(String key, T value) throws ExtensionPropertyException;
-
- /**
- * Gets a property value of an extension instruction.
- *
- * @param key property key
- * @param <T> class of the value
- * @return value of the property
- * @throws ExtensionPropertyException if the given key is not a valid
- * property on this extension instruction
- */
- <T> T getPropertyValue(String key) throws ExtensionPropertyException;
-
- /**
- * Gets a list of all properties on the extension instruction.
- *
- * @return list of properties
- */
- List<String> getProperties();
-
- /**
- * Serialize the extension instruction to a byte array.
- *
- * @return byte array
- */
- byte[] serialize();
-
- /**
- * Deserialize the extension instruction from a byte array. The properties
- * of this object will be overwritten with the data in the byte array.
- *
- * @param data input byte array
- */
- void deserialize(byte[] data);
-
-
}
diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/instructions/ExtensionTreatmentType.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/instructions/ExtensionTreatmentType.java
index 38fbc279..f597a46c 100644
--- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/instructions/ExtensionTreatmentType.java
+++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/instructions/ExtensionTreatmentType.java
@@ -22,7 +22,7 @@ import com.google.common.base.MoreObjects;
import java.util.Objects;
/**
- * Type of extension instructions.
+ * Type of treatment extensions.
*/
@Beta
public final class ExtensionTreatmentType {
@@ -32,15 +32,24 @@ public final class ExtensionTreatmentType {
* These numbers have no impact on the actual OF type id.
*/
public enum ExtensionTreatmentTypes {
- // TODO fix type numbers to include experimenter id
NICIRA_SET_TUNNEL_DST(0),
NICIRA_RESUBMIT(1),
- NICIRA_SET_NSH_SPI(32);
+ NICIRA_RESUBMIT_TABLE(14),
+ NICIRA_SET_NSH_SPI(32),
+ NICIRA_SET_NSH_SI(33),
+ NICIRA_SET_NSH_CH1(34),
+ NICIRA_SET_NSH_CH2(35),
+ NICIRA_SET_NSH_CH3(36),
+ NICIRA_SET_NSH_CH4(37),
+ NICIRA_MOV_ARP_SHA_TO_THA(2),
+ NICIRA_MOV_ARP_SPA_TO_TPA(3),
+ NICIRA_MOV_ETH_SRC_TO_DST(4),
+ NICIRA_MOV_IP_SRC_TO_DST(5);
private ExtensionTreatmentType type;
/**
- * Creates a new named extension instruction type.
+ * Creates a new named extension treatment type.
*
* @param type type code
*/
diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/instructions/Instructions.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/instructions/Instructions.java
index 4643b315..8ed882c8 100644
--- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/instructions/Instructions.java
+++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/instructions/Instructions.java
@@ -35,6 +35,9 @@ import org.onosproject.net.flow.instructions.L0ModificationInstruction.ModOchSig
import org.onosproject.net.flow.instructions.L1ModificationInstruction.ModOduSignalIdInstruction;
import org.onosproject.net.flow.instructions.L3ModificationInstruction.L3SubType;
import org.onosproject.net.flow.instructions.L3ModificationInstruction.ModIPInstruction;
+import org.onosproject.net.flow.instructions.L3ModificationInstruction.ModArpIPInstruction;
+import org.onosproject.net.flow.instructions.L3ModificationInstruction.ModArpEthInstruction;
+import org.onosproject.net.flow.instructions.L3ModificationInstruction.ModArpOpInstruction;
import org.onosproject.net.flow.instructions.L3ModificationInstruction.ModIPv6FlowLabelInstruction;
import org.onosproject.net.flow.instructions.L3ModificationInstruction.ModTtlInstruction;
import org.onosproject.net.flow.instructions.L4ModificationInstruction.L4SubType;
@@ -299,6 +302,39 @@ public final class Instructions {
}
/**
+ * Creates a L3 ARP IP src modification.
+ *
+ * @param addr the ip address to modify to
+ * @return a L3 modification
+ */
+ public static L3ModificationInstruction modArpSpa(IpAddress addr) {
+ checkNotNull(addr, "Src l3 ARP IP address cannot be null");
+ return new ModArpIPInstruction(L3SubType.ARP_SPA, addr);
+ }
+
+ /**
+ * Creates a l3 ARP Ether src modification.
+ *
+ * @param addr the mac address to modify to
+ * @return a l3 modification
+ */
+ public static L3ModificationInstruction modArpSha(MacAddress addr) {
+ checkNotNull(addr, "Src l3 ARP address cannot be null");
+ return new ModArpEthInstruction(L3SubType.ARP_SHA, addr);
+ }
+
+ /**
+ * Creates a l3 ARP operation modification.
+ *
+ * @param op the ARP operation to modify to
+ * @return a l3 modification
+ */
+ public static L3ModificationInstruction modL3ArpOp(short op) {
+ checkNotNull(op, "Arp operation cannot be null");
+ return new ModArpOpInstruction(L3SubType.ARP_OP, op);
+ }
+
+ /**
* Creates a push MPLS header instruction.
*
* @return a L2 modification.
diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/instructions/L3ModificationInstruction.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/instructions/L3ModificationInstruction.java
index 41819504..0efe9a77 100644
--- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/instructions/L3ModificationInstruction.java
+++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/instructions/L3ModificationInstruction.java
@@ -20,6 +20,7 @@ import static com.google.common.base.MoreObjects.toStringHelper;
import java.util.Objects;
import org.onlab.packet.IpAddress;
+import org.onlab.packet.MacAddress;
/**
* Abstraction of a single traffic treatment step.
@@ -68,7 +69,22 @@ public abstract class L3ModificationInstruction implements Instruction {
/**
* Copy TTL in.
*/
- TTL_IN
+ TTL_IN,
+
+ /**
+ * ARP IP src modification.
+ */
+ ARP_SPA,
+
+ /**
+ * ARP Ether src modification.
+ */
+ ARP_SHA,
+
+ /**
+ * Arp operation modification.
+ */
+ ARP_OP
//TODO: remaining types
}
@@ -133,6 +149,150 @@ public abstract class L3ModificationInstruction implements Instruction {
}
/**
+ * Represents a L3 ARP IP src/dst modification instruction.
+ */
+ public static final class ModArpIPInstruction extends L3ModificationInstruction {
+
+ private final L3SubType subtype;
+ private final IpAddress ip;
+
+ ModArpIPInstruction(L3SubType subType, IpAddress addr) {
+
+ this.subtype = subType;
+ this.ip = addr;
+ }
+
+ @Override
+ public L3SubType subtype() {
+ return this.subtype;
+ }
+
+ public IpAddress ip() {
+ return this.ip;
+ }
+
+ @Override
+ public String toString() {
+ return toStringHelper(subtype().toString())
+ .add("ip", ip).toString();
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(type(), subtype(), ip);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj instanceof ModArpIPInstruction) {
+ ModArpIPInstruction that = (ModArpIPInstruction) obj;
+ return Objects.equals(ip, that.ip) &&
+ Objects.equals(this.subtype(), that.subtype());
+ }
+ return false;
+ }
+ }
+
+ /**
+ * Represents a L3 ARP Ether src/dst modification instruction.
+ */
+ public static final class ModArpEthInstruction extends L3ModificationInstruction {
+
+ private final L3SubType subtype;
+ private final MacAddress mac;
+
+ ModArpEthInstruction(L3SubType subType, MacAddress addr) {
+
+ this.subtype = subType;
+ this.mac = addr;
+ }
+
+ @Override
+ public L3SubType subtype() {
+ return this.subtype;
+ }
+
+ public MacAddress mac() {
+ return this.mac;
+ }
+
+ @Override
+ public String toString() {
+ return toStringHelper(subtype().toString())
+ .add("mac", mac).toString();
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(type(), subtype(), mac);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj instanceof ModArpEthInstruction) {
+ ModArpEthInstruction that = (ModArpEthInstruction) obj;
+ return Objects.equals(mac, that.mac) &&
+ Objects.equals(this.subtype(), that.subtype());
+ }
+ return false;
+ }
+ }
+
+ /**
+ * Represents a L3 ARP operation modification instruction.
+ */
+ public static final class ModArpOpInstruction extends L3ModificationInstruction {
+
+ private final L3SubType subtype;
+ private final short op;
+
+ ModArpOpInstruction(L3SubType subType, short op) {
+
+ this.subtype = subType;
+ this.op = op;
+ }
+
+ @Override
+ public L3SubType subtype() {
+ return this.subtype;
+ }
+
+ public long op() {
+ return this.op;
+ }
+
+ @Override
+ public String toString() {
+ return toStringHelper(subtype().toString())
+ .add("op", op).toString();
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(type(), subtype(), op);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj instanceof ModArpOpInstruction) {
+ ModArpOpInstruction that = (ModArpOpInstruction) obj;
+ return Objects.equals(op, that.op) &&
+ Objects.equals(this.subtype(), that.subtype());
+ }
+ return false;
+ }
+ }
+
+ /**
* Represents a L3 IPv6 Flow Label (RFC 6437) modification instruction
* (20 bits unsigned integer).
*/