[ONOS-3284] Add nicira extension of NSH instructions to onos
Change-Id: I569ef85967a22098db3c9821a8731a4ca589eaf6
diff --git a/core/api/src/main/java/org/onosproject/net/flow/instructions/ExtensionTreatmentType.java b/core/api/src/main/java/org/onosproject/net/flow/instructions/ExtensionTreatmentType.java
index f3690da..821c1d9 100644
--- a/core/api/src/main/java/org/onosproject/net/flow/instructions/ExtensionTreatmentType.java
+++ b/core/api/src/main/java/org/onosproject/net/flow/instructions/ExtensionTreatmentType.java
@@ -36,7 +36,12 @@
NICIRA_SET_TUNNEL_DST(0),
NICIRA_RESUBMIT(1),
NICIRA_SET_NSH_SPI(32),
- NICIRA_RESUBMIT_TABLE(14);
+ NICIRA_RESUBMIT_TABLE(14),
+ 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);
private ExtensionTreatmentType type;
diff --git a/drivers/src/main/java/org/onosproject/driver/extensions/NiciraExtensionTreatmentInterpreter.java b/drivers/src/main/java/org/onosproject/driver/extensions/NiciraExtensionTreatmentInterpreter.java
index b6c786c..2297906 100644
--- a/drivers/src/main/java/org/onosproject/driver/extensions/NiciraExtensionTreatmentInterpreter.java
+++ b/drivers/src/main/java/org/onosproject/driver/extensions/NiciraExtensionTreatmentInterpreter.java
@@ -46,8 +46,22 @@
ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_RESUBMIT.type())) {
return true;
}
- if (extensionTreatmentType.equals(
- ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_SPI.type())) {
+ if (extensionTreatmentType.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_SPI.type())) {
+ return true;
+ }
+ if (extensionTreatmentType.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_SI.type())) {
+ return true;
+ }
+ if (extensionTreatmentType.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH1.type())) {
+ return true;
+ }
+ if (extensionTreatmentType.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH2.type())) {
+ return true;
+ }
+ if (extensionTreatmentType.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH3.type())) {
+ return true;
+ }
+ if (extensionTreatmentType.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH4.type())) {
return true;
}
if (extensionTreatmentType.equals(
@@ -66,14 +80,29 @@
IPv4Address.of(tunnelDst.tunnelDst().toInt())));
}
if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_RESUBMIT.type())) {
- // TODO this will be implemented later
+ // TODO this will be implemented later
}
if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_SPI.type())) {
// TODO this will be implemented later
}
if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_RESUBMIT_TABLE.type())) {
// TODO this will be implemented later
- }
+ }
+ if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_SI.type())) {
+ // TODO this will be implemented later
+ }
+ if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH1.type())) {
+ // TODO this will be implemented later
+ }
+ if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH2.type())) {
+ // TODO this will be implemented later
+ }
+ if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH3.type())) {
+ // TODO this will be implemented later
+ }
+ if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH4.type())) {
+ // TODO this will be implemented later
+ }
return null;
}
@@ -102,11 +131,20 @@
if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_RESUBMIT.type())) {
return new NiciraResubmit();
}
+ if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_RESUBMIT_TABLE.type())) {
+ return new NiciraResubmitTable();
+ }
if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_SPI.type())) {
return new NiciraSetNshSpi();
}
- if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_RESUBMIT_TABLE.type())) {
- return new NiciraResubmitTable();
+ if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_SI.type())) {
+ return new NiciraSetNshSi();
+ }
+ if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH1.type())
+ || type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH2.type())
+ || type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH3.type())
+ || type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH4.type())) {
+ return new NiciraSetNshContextHeader(type);
}
throw new UnsupportedOperationException(
"Driver does not support extension type " + type.toString());
diff --git a/drivers/src/main/java/org/onosproject/driver/extensions/NiciraSetNshContextHeader.java b/drivers/src/main/java/org/onosproject/driver/extensions/NiciraSetNshContextHeader.java
new file mode 100644
index 0000000..0aa0f4d
--- /dev/null
+++ b/drivers/src/main/java/org/onosproject/driver/extensions/NiciraSetNshContextHeader.java
@@ -0,0 +1,107 @@
+/*
+ * 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.driver.extensions;
+
+import java.util.Objects;
+
+import org.onlab.util.KryoNamespace;
+import org.onosproject.net.flow.instructions.AbstractExtensionTreatment;
+import org.onosproject.net.flow.instructions.ExtensionTreatmentType;
+
+import com.google.common.base.MoreObjects;
+
+/**
+ * Nicira set NSH Context header extension instruction.
+ */
+public class NiciraSetNshContextHeader extends AbstractExtensionTreatment {
+
+ private int nshCh;
+ private ExtensionTreatmentType type;
+
+ private final KryoNamespace appKryo = new KryoNamespace.Builder().build();
+
+ /**
+ * Creates a new set nsh context header instruction.
+ *
+ * @param type extension treatment type
+ */
+ NiciraSetNshContextHeader(ExtensionTreatmentType type) {
+ this.nshCh = 0;
+ this.type = type;
+ }
+
+ /**
+ * Creates a new set nsh context header instruction.
+ *
+ * @param nshCh nsh context header
+ * @param type extension treatment type
+ */
+ NiciraSetNshContextHeader(int nshCh, ExtensionTreatmentType type) {
+ this.nshCh = nshCh;
+ this.type = type;
+ }
+
+ /**
+ * Gets the nsh context header.
+ *
+ * @return nsh context header
+ */
+ public int nshCh() {
+ return nshCh;
+ }
+
+ @Override
+ public ExtensionTreatmentType type() {
+ return type;
+ }
+
+ @Override
+ public void deserialize(byte[] data) {
+ nshCh = appKryo.deserialize(data);
+ }
+
+ @Override
+ public byte[] serialize() {
+ return appKryo.serialize(nshCh);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(nshCh, type);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj instanceof NiciraSetNshContextHeader) {
+ NiciraSetNshContextHeader that = (NiciraSetNshContextHeader) obj;
+ return Objects.equals(nshCh, that.nshCh) && Objects.equals(type, that.type);
+
+ }
+ return false;
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(getClass())
+ .add("nshCh", nshCh)
+ .add("type", type)
+ .toString();
+ }
+}
diff --git a/drivers/src/main/java/org/onosproject/driver/extensions/NiciraSetNshSi.java b/drivers/src/main/java/org/onosproject/driver/extensions/NiciraSetNshSi.java
new file mode 100644
index 0000000..53cf629
--- /dev/null
+++ b/drivers/src/main/java/org/onosproject/driver/extensions/NiciraSetNshSi.java
@@ -0,0 +1,100 @@
+/*
+ * 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.driver.extensions;
+
+import java.util.Objects;
+
+import org.onlab.util.KryoNamespace;
+import org.onosproject.net.flow.instructions.AbstractExtensionTreatment;
+import org.onosproject.net.flow.instructions.ExtensionTreatmentType;
+
+import com.google.common.base.MoreObjects;
+
+/**
+ * Nicira set NSH SI extension instruction.
+ */
+public class NiciraSetNshSi extends AbstractExtensionTreatment {
+
+ private byte nshSi;
+
+ private final KryoNamespace appKryo = new KryoNamespace.Builder().build();
+
+ /**
+ * Creates a new set nsh si instruction.
+ */
+ NiciraSetNshSi() {
+ nshSi = 0;
+ }
+
+ /**
+ * Creates a new set nsh si instruction with given si.
+ *
+ * @param nshSi nsh service index
+ */
+ NiciraSetNshSi(byte nshSi) {
+ this.nshSi = nshSi;
+ }
+
+ /**
+ * Gets the nsh service index.
+ *
+ * @return nsh service index
+ */
+ public byte nshSi() {
+ return nshSi;
+ }
+
+ @Override
+ public ExtensionTreatmentType type() {
+ return ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_SI.type();
+ }
+
+ @Override
+ public void deserialize(byte[] data) {
+ nshSi = appKryo.deserialize(data);
+ }
+
+ @Override
+ public byte[] serialize() {
+ return appKryo.serialize(nshSi);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(nshSi);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj instanceof NiciraSetNshSi) {
+ NiciraSetNshSi that = (NiciraSetNshSi) obj;
+ return Objects.equals(nshSi, that.nshSi);
+
+ }
+ return false;
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(getClass())
+ .add("nshSi", nshSi)
+ .toString();
+ }
+}
diff --git a/drivers/src/main/java/org/onosproject/driver/extensions/NiciraSetNshSpi.java b/drivers/src/main/java/org/onosproject/driver/extensions/NiciraSetNshSpi.java
index 2535870..1a168d0 100644
--- a/drivers/src/main/java/org/onosproject/driver/extensions/NiciraSetNshSpi.java
+++ b/drivers/src/main/java/org/onosproject/driver/extensions/NiciraSetNshSpi.java
@@ -21,7 +21,6 @@
import org.onlab.util.KryoNamespace;
import org.onosproject.net.flow.instructions.AbstractExtensionTreatment;
import org.onosproject.net.flow.instructions.ExtensionTreatmentType;
-import org.onosproject.store.serializers.Ip4AddressSerializer;
import com.google.common.base.MoreObjects;
@@ -32,10 +31,7 @@
private int nshSpi;
- private final KryoNamespace appKryo = new KryoNamespace.Builder()
- .register(new Ip4AddressSerializer(), Integer.class)
- .register(byte[].class)
- .build();
+ private final KryoNamespace appKryo = new KryoNamespace.Builder().build();
/**
* Creates a new set nsh spi instruction.
diff --git a/drivers/src/test/java/org/onosproject/driver/extensions/NiciraSetNshContextHeaderTest.java b/drivers/src/test/java/org/onosproject/driver/extensions/NiciraSetNshContextHeaderTest.java
new file mode 100644
index 0000000..45d6d94
--- /dev/null
+++ b/drivers/src/test/java/org/onosproject/driver/extensions/NiciraSetNshContextHeaderTest.java
@@ -0,0 +1,68 @@
+/*
+ * 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.driver.extensions;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.notNullValue;
+
+import org.junit.Test;
+import org.onosproject.net.flow.instructions.ExtensionTreatmentType;
+
+import com.google.common.testing.EqualsTester;
+
+/**
+ * Unit tests for NiciraSetNshContextHeader class.
+ */
+public class NiciraSetNshContextHeaderTest {
+
+ final NiciraSetNshContextHeader nshCh1 = new NiciraSetNshContextHeader(10,
+ ExtensionTreatmentType.
+ ExtensionTreatmentTypes.
+ NICIRA_SET_NSH_CH1.type());
+ final NiciraSetNshContextHeader sameAsNshCh1 = new NiciraSetNshContextHeader(10,
+ ExtensionTreatmentType.
+ ExtensionTreatmentTypes.
+ NICIRA_SET_NSH_CH1.type());
+ final NiciraSetNshContextHeader nshCh2 = new NiciraSetNshContextHeader(20,
+ ExtensionTreatmentType.
+ ExtensionTreatmentTypes.
+ NICIRA_SET_NSH_CH1.type());
+
+ /**
+ * Checks the operation of equals() methods.
+ */
+ @Test
+ public void testEquals() {
+ new EqualsTester().addEqualityGroup(nshCh1, sameAsNshCh1).addEqualityGroup(nshCh2).testEquals();
+ }
+
+ /**
+ * Checks the construction of a NiciraSetNshSi object.
+ */
+ @Test
+ public void testConstruction() {
+ final NiciraSetNshContextHeader niciraSetNshCh = new NiciraSetNshContextHeader(10,
+ ExtensionTreatmentType.
+ ExtensionTreatmentTypes.
+ NICIRA_SET_NSH_CH1.type());
+ assertThat(niciraSetNshCh, is(notNullValue()));
+ assertThat(niciraSetNshCh.nshCh(), is(10));
+ assertThat(niciraSetNshCh.type(), is(ExtensionTreatmentType.
+ ExtensionTreatmentTypes.
+ NICIRA_SET_NSH_CH1.type()));
+ }
+}
diff --git a/drivers/src/test/java/org/onosproject/driver/extensions/NiciraSetNshSiTest.java b/drivers/src/test/java/org/onosproject/driver/extensions/NiciraSetNshSiTest.java
new file mode 100644
index 0000000..8541e9f
--- /dev/null
+++ b/drivers/src/test/java/org/onosproject/driver/extensions/NiciraSetNshSiTest.java
@@ -0,0 +1,52 @@
+/*
+ * 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.driver.extensions;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.notNullValue;
+
+import org.junit.Test;
+
+import com.google.common.testing.EqualsTester;
+
+/**
+ * Unit tests for NiciraSetNshSi class.
+ */
+public class NiciraSetNshSiTest {
+
+ final NiciraSetNshSi nshSi1 = new NiciraSetNshSi((byte) 10);
+ final NiciraSetNshSi sameAsNshSi1 = new NiciraSetNshSi((byte) 10);
+ final NiciraSetNshSi nshSi2 = new NiciraSetNshSi((byte) 20);
+
+ /**
+ * Checks the operation of equals() methods.
+ */
+ @Test
+ public void testEquals() {
+ new EqualsTester().addEqualityGroup(nshSi1, sameAsNshSi1).addEqualityGroup(nshSi2).testEquals();
+ }
+
+ /**
+ * Checks the construction of a NiciraSetNshSi object.
+ */
+ @Test
+ public void testConstruction() {
+ final NiciraSetNshSi niciraSetNshSi = new NiciraSetNshSi((byte) 15);
+ assertThat(niciraSetNshSi, is(notNullValue()));
+ assertThat(niciraSetNshSi.nshSi(), is((byte) 15));
+ }
+}
diff --git a/drivers/src/test/java/org/onosproject/driver/extensions/NiciraSetNshSpiTest.java b/drivers/src/test/java/org/onosproject/driver/extensions/NiciraSetNshSpiTest.java
new file mode 100644
index 0000000..197e3bf
--- /dev/null
+++ b/drivers/src/test/java/org/onosproject/driver/extensions/NiciraSetNshSpiTest.java
@@ -0,0 +1,52 @@
+/*
+ * 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.driver.extensions;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.notNullValue;
+
+import org.junit.Test;
+
+import com.google.common.testing.EqualsTester;
+
+/**
+ * Unit tests for NiciraSetNshSpi class.
+ */
+public class NiciraSetNshSpiTest {
+
+ final NiciraSetNshSpi nshSpi1 = new NiciraSetNshSpi(10);
+ final NiciraSetNshSpi sameAsNshSpi1 = new NiciraSetNshSpi(10);
+ final NiciraSetNshSpi nshSpi2 = new NiciraSetNshSpi(20);
+
+ /**
+ * Checks the operation of equals() methods.
+ */
+ @Test
+ public void testEquals() {
+ new EqualsTester().addEqualityGroup(nshSpi1, sameAsNshSpi1).addEqualityGroup(nshSpi2).testEquals();
+ }
+
+ /**
+ * Checks the construction of a NiciraSetNshSpi object.
+ */
+ @Test
+ public void testConstruction() {
+ final NiciraSetNshSpi niciraSetNshSpi = new NiciraSetNshSpi(10);
+ assertThat(niciraSetNshSpi, is(notNullValue()));
+ assertThat(niciraSetNshSpi.nshSpi(), is(10));
+ }
+}