Phaneendra Manda
Committed by Gerrit Code Review

[ONOS-3284]Types added Spi, SI and context header

Change-Id: Ib29d90d401c390d4ff5ac06e17507f2ffbb70f12
......@@ -16,13 +16,15 @@
package org.onosproject.driver.extensions;
import com.google.common.base.MoreObjects;
import java.util.Objects;
import org.onlab.util.KryoNamespace;
import org.onosproject.net.NshContextHeader;
import org.onosproject.net.flow.AbstractExtension;
import org.onosproject.net.flow.instructions.ExtensionTreatment;
import org.onosproject.net.flow.instructions.ExtensionTreatmentType;
import java.util.Objects;
import com.google.common.base.MoreObjects;
/**
* Nicira set NSH Context header extension instruction.
......@@ -30,7 +32,7 @@ import java.util.Objects;
public class NiciraSetNshContextHeader extends AbstractExtension implements
ExtensionTreatment {
private int nshCh;
private NshContextHeader nshCh;
private ExtensionTreatmentType type;
private final KryoNamespace appKryo = new KryoNamespace.Builder().build();
......@@ -41,7 +43,7 @@ public class NiciraSetNshContextHeader extends AbstractExtension implements
* @param type extension treatment type
*/
NiciraSetNshContextHeader(ExtensionTreatmentType type) {
this.nshCh = 0;
this.nshCh = NshContextHeader.of(0);
this.type = type;
}
......@@ -51,7 +53,7 @@ public class NiciraSetNshContextHeader extends AbstractExtension implements
* @param nshCh nsh context header
* @param type extension treatment type
*/
NiciraSetNshContextHeader(int nshCh, ExtensionTreatmentType type) {
NiciraSetNshContextHeader(NshContextHeader nshCh, ExtensionTreatmentType type) {
this.nshCh = nshCh;
this.type = type;
}
......@@ -61,7 +63,7 @@ public class NiciraSetNshContextHeader extends AbstractExtension implements
*
* @return nsh context header
*/
public int nshCh() {
public NshContextHeader nshCh() {
return nshCh;
}
......@@ -72,12 +74,12 @@ public class NiciraSetNshContextHeader extends AbstractExtension implements
@Override
public void deserialize(byte[] data) {
nshCh = appKryo.deserialize(data);
nshCh = NshContextHeader.of(appKryo.deserialize(data));
}
@Override
public byte[] serialize() {
return appKryo.serialize(nshCh);
return appKryo.serialize(nshCh.nshContextHeader());
}
@Override
......
......@@ -16,13 +16,15 @@
package org.onosproject.driver.extensions;
import com.google.common.base.MoreObjects;
import java.util.Objects;
import org.onlab.util.KryoNamespace;
import org.onosproject.net.NshServiceIndex;
import org.onosproject.net.flow.AbstractExtension;
import org.onosproject.net.flow.instructions.ExtensionTreatment;
import org.onosproject.net.flow.instructions.ExtensionTreatmentType;
import java.util.Objects;
import com.google.common.base.MoreObjects;
/**
* Nicira set NSH SI extension instruction.
......@@ -30,7 +32,7 @@ import java.util.Objects;
public class NiciraSetNshSi extends AbstractExtension implements
ExtensionTreatment {
private byte nshSi;
private NshServiceIndex nshSi;
private final KryoNamespace appKryo = new KryoNamespace.Builder().build();
......@@ -38,7 +40,7 @@ public class NiciraSetNshSi extends AbstractExtension implements
* Creates a new set nsh si instruction.
*/
NiciraSetNshSi() {
nshSi = 0;
nshSi = NshServiceIndex.of((short) 0);
}
/**
......@@ -46,7 +48,7 @@ public class NiciraSetNshSi extends AbstractExtension implements
*
* @param nshSi nsh service index
*/
NiciraSetNshSi(byte nshSi) {
NiciraSetNshSi(NshServiceIndex nshSi) {
this.nshSi = nshSi;
}
......@@ -55,7 +57,7 @@ public class NiciraSetNshSi extends AbstractExtension implements
*
* @return nsh service index
*/
public byte nshSi() {
public NshServiceIndex nshSi() {
return nshSi;
}
......@@ -66,12 +68,12 @@ public class NiciraSetNshSi extends AbstractExtension implements
@Override
public void deserialize(byte[] data) {
nshSi = appKryo.deserialize(data);
nshSi = NshServiceIndex.of(appKryo.deserialize(data));
}
@Override
public byte[] serialize() {
return appKryo.serialize(nshSi);
return appKryo.serialize(nshSi.serviceIndex());
}
@Override
......
......@@ -16,13 +16,15 @@
package org.onosproject.driver.extensions;
import com.google.common.base.MoreObjects;
import java.util.Objects;
import org.onlab.util.KryoNamespace;
import org.onosproject.net.NshServicePathId;
import org.onosproject.net.flow.AbstractExtension;
import org.onosproject.net.flow.instructions.ExtensionTreatment;
import org.onosproject.net.flow.instructions.ExtensionTreatmentType;
import java.util.Objects;
import com.google.common.base.MoreObjects;
/**
* Nicira set NSH SPI extension instruction.
......@@ -30,7 +32,7 @@ import java.util.Objects;
public class NiciraSetNshSpi extends AbstractExtension implements
ExtensionTreatment {
private int nshSpi;
private NshServicePathId nshSpi;
private final KryoNamespace appKryo = new KryoNamespace.Builder().build();
......@@ -38,24 +40,24 @@ public class NiciraSetNshSpi extends AbstractExtension implements
* Creates a new set nsh spi instruction.
*/
NiciraSetNshSpi() {
nshSpi = 0;
nshSpi = NshServicePathId.of(0);
}
/**
* Creates a new set nsh spi instruction with given spi.
*
* @param nshSpi nsh service path index
* @param nshSpi nsh service path id
*/
NiciraSetNshSpi(int nshSpi) {
NiciraSetNshSpi(NshServicePathId nshSpi) {
this.nshSpi = nshSpi;
}
/**
* Gets the nsh service path index.
* Gets the nsh service path id.
*
* @return nsh service path index
* @return nsh service path id
*/
public int nshSpi() {
public NshServicePathId nshSpi() {
return nshSpi;
}
......@@ -66,12 +68,12 @@ public class NiciraSetNshSpi extends AbstractExtension implements
@Override
public void deserialize(byte[] data) {
nshSpi = appKryo.deserialize(data);
nshSpi = NshServicePathId.of(appKryo.deserialize(data));
}
@Override
public byte[] serialize() {
return appKryo.serialize(nshSpi);
return appKryo.serialize(nshSpi.servicePathId());
}
@Override
......@@ -95,7 +97,7 @@ public class NiciraSetNshSpi extends AbstractExtension implements
@Override
public String toString() {
return MoreObjects.toStringHelper(getClass())
.add("nshSpi", nshSpi)
.add("nshSpi", nshSpi.toString())
.toString();
}
}
......
......@@ -20,6 +20,7 @@ import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;
import org.junit.Test;
import org.onosproject.net.NshContextHeader;
import org.onosproject.net.flow.instructions.ExtensionTreatmentType;
import com.google.common.testing.EqualsTester;
......@@ -29,15 +30,15 @@ import com.google.common.testing.EqualsTester;
*/
public class NiciraSetNshContextHeaderTest {
final NiciraSetNshContextHeader nshCh1 = new NiciraSetNshContextHeader(10,
final NiciraSetNshContextHeader nshCh1 = new NiciraSetNshContextHeader(NshContextHeader.of(10),
ExtensionTreatmentType.
ExtensionTreatmentTypes.
NICIRA_SET_NSH_CH1.type());
final NiciraSetNshContextHeader sameAsNshCh1 = new NiciraSetNshContextHeader(10,
final NiciraSetNshContextHeader sameAsNshCh1 = new NiciraSetNshContextHeader(NshContextHeader.of(10),
ExtensionTreatmentType.
ExtensionTreatmentTypes.
NICIRA_SET_NSH_CH1.type());
final NiciraSetNshContextHeader nshCh2 = new NiciraSetNshContextHeader(20,
final NiciraSetNshContextHeader nshCh2 = new NiciraSetNshContextHeader(NshContextHeader.of(20),
ExtensionTreatmentType.
ExtensionTreatmentTypes.
NICIRA_SET_NSH_CH1.type());
......@@ -55,12 +56,12 @@ public class NiciraSetNshContextHeaderTest {
*/
@Test
public void testConstruction() {
final NiciraSetNshContextHeader niciraSetNshCh = new NiciraSetNshContextHeader(10,
final NiciraSetNshContextHeader niciraSetNshCh = new NiciraSetNshContextHeader(NshContextHeader.of(10),
ExtensionTreatmentType.
ExtensionTreatmentTypes.
NICIRA_SET_NSH_CH1.type());
assertThat(niciraSetNshCh, is(notNullValue()));
assertThat(niciraSetNshCh.nshCh(), is(10));
assertThat(niciraSetNshCh.nshCh().nshContextHeader(), is(10));
assertThat(niciraSetNshCh.type(), is(ExtensionTreatmentType.
ExtensionTreatmentTypes.
NICIRA_SET_NSH_CH1.type()));
......
......@@ -20,6 +20,7 @@ import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;
import org.junit.Test;
import org.onosproject.net.NshServiceIndex;
import com.google.common.testing.EqualsTester;
......@@ -28,9 +29,9 @@ import com.google.common.testing.EqualsTester;
*/
public class NiciraSetNshSiTest {
final NiciraSetNshSi nshSi1 = new NiciraSetNshSi((byte) 10);
final NiciraSetNshSi sameAsNshSi1 = new NiciraSetNshSi((byte) 10);
final NiciraSetNshSi nshSi2 = new NiciraSetNshSi((byte) 20);
final NiciraSetNshSi nshSi1 = new NiciraSetNshSi(NshServiceIndex.of((short) 10));
final NiciraSetNshSi sameAsNshSi1 = new NiciraSetNshSi(NshServiceIndex.of((short) 10));
final NiciraSetNshSi nshSi2 = new NiciraSetNshSi(NshServiceIndex.of((short) 20));
/**
* Checks the operation of equals() methods.
......@@ -45,8 +46,8 @@ public class NiciraSetNshSiTest {
*/
@Test
public void testConstruction() {
final NiciraSetNshSi niciraSetNshSi = new NiciraSetNshSi((byte) 15);
final NiciraSetNshSi niciraSetNshSi = new NiciraSetNshSi(NshServiceIndex.of((short) 15));
assertThat(niciraSetNshSi, is(notNullValue()));
assertThat(niciraSetNshSi.nshSi(), is((byte) 15));
assertThat(niciraSetNshSi.nshSi().serviceIndex(), is((short) 15));
}
}
......
......@@ -20,6 +20,7 @@ import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;
import org.junit.Test;
import org.onosproject.net.NshServicePathId;
import com.google.common.testing.EqualsTester;
......@@ -28,9 +29,9 @@ import com.google.common.testing.EqualsTester;
*/
public class NiciraSetNshSpiTest {
final NiciraSetNshSpi nshSpi1 = new NiciraSetNshSpi(10);
final NiciraSetNshSpi sameAsNshSpi1 = new NiciraSetNshSpi(10);
final NiciraSetNshSpi nshSpi2 = new NiciraSetNshSpi(20);
final NiciraSetNshSpi nshSpi1 = new NiciraSetNshSpi(NshServicePathId.of(10));
final NiciraSetNshSpi sameAsNshSpi1 = new NiciraSetNshSpi(NshServicePathId.of(10));
final NiciraSetNshSpi nshSpi2 = new NiciraSetNshSpi(NshServicePathId.of(20));
/**
* Checks the operation of equals() methods.
......@@ -45,8 +46,8 @@ public class NiciraSetNshSpiTest {
*/
@Test
public void testConstruction() {
final NiciraSetNshSpi niciraSetNshSpi = new NiciraSetNshSpi(10);
final NiciraSetNshSpi niciraSetNshSpi = new NiciraSetNshSpi(NshServicePathId.of(10));
assertThat(niciraSetNshSpi, is(notNullValue()));
assertThat(niciraSetNshSpi.nshSpi(), is(10));
assertThat(niciraSetNshSpi.nshSpi().servicePathId(), is(10));
}
}
......