Phaneendra Manda
Committed by Gerrit Code Review

[ONOS-3284] Add nicira extension of NSH instructions to onos

Change-Id: I569ef85967a22098db3c9821a8731a4ca589eaf6
...@@ -36,7 +36,12 @@ public final class ExtensionTreatmentType { ...@@ -36,7 +36,12 @@ public final class ExtensionTreatmentType {
36 NICIRA_SET_TUNNEL_DST(0), 36 NICIRA_SET_TUNNEL_DST(0),
37 NICIRA_RESUBMIT(1), 37 NICIRA_RESUBMIT(1),
38 NICIRA_SET_NSH_SPI(32), 38 NICIRA_SET_NSH_SPI(32),
39 - NICIRA_RESUBMIT_TABLE(14); 39 + NICIRA_RESUBMIT_TABLE(14),
40 + NICIRA_SET_NSH_SI(33),
41 + NICIRA_SET_NSH_CH1(34),
42 + NICIRA_SET_NSH_CH2(35),
43 + NICIRA_SET_NSH_CH3(36),
44 + NICIRA_SET_NSH_CH4(37);
40 45
41 private ExtensionTreatmentType type; 46 private ExtensionTreatmentType type;
42 47
......
...@@ -46,8 +46,22 @@ public class NiciraExtensionTreatmentInterpreter extends AbstractHandlerBehaviou ...@@ -46,8 +46,22 @@ public class NiciraExtensionTreatmentInterpreter extends AbstractHandlerBehaviou
46 ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_RESUBMIT.type())) { 46 ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_RESUBMIT.type())) {
47 return true; 47 return true;
48 } 48 }
49 - if (extensionTreatmentType.equals( 49 + if (extensionTreatmentType.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_SPI.type())) {
50 - ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_SPI.type())) { 50 + return true;
51 + }
52 + if (extensionTreatmentType.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_SI.type())) {
53 + return true;
54 + }
55 + if (extensionTreatmentType.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH1.type())) {
56 + return true;
57 + }
58 + if (extensionTreatmentType.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH2.type())) {
59 + return true;
60 + }
61 + if (extensionTreatmentType.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH3.type())) {
62 + return true;
63 + }
64 + if (extensionTreatmentType.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH4.type())) {
51 return true; 65 return true;
52 } 66 }
53 if (extensionTreatmentType.equals( 67 if (extensionTreatmentType.equals(
...@@ -66,14 +80,29 @@ public class NiciraExtensionTreatmentInterpreter extends AbstractHandlerBehaviou ...@@ -66,14 +80,29 @@ public class NiciraExtensionTreatmentInterpreter extends AbstractHandlerBehaviou
66 IPv4Address.of(tunnelDst.tunnelDst().toInt()))); 80 IPv4Address.of(tunnelDst.tunnelDst().toInt())));
67 } 81 }
68 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_RESUBMIT.type())) { 82 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_RESUBMIT.type())) {
69 - // TODO this will be implemented later 83 + // TODO this will be implemented later
70 } 84 }
71 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_SPI.type())) { 85 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_SPI.type())) {
72 // TODO this will be implemented later 86 // TODO this will be implemented later
73 } 87 }
74 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_RESUBMIT_TABLE.type())) { 88 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_RESUBMIT_TABLE.type())) {
75 // TODO this will be implemented later 89 // TODO this will be implemented later
76 - } 90 + }
91 + if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_SI.type())) {
92 + // TODO this will be implemented later
93 + }
94 + if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH1.type())) {
95 + // TODO this will be implemented later
96 + }
97 + if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH2.type())) {
98 + // TODO this will be implemented later
99 + }
100 + if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH3.type())) {
101 + // TODO this will be implemented later
102 + }
103 + if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH4.type())) {
104 + // TODO this will be implemented later
105 + }
77 return null; 106 return null;
78 } 107 }
79 108
...@@ -102,11 +131,20 @@ public class NiciraExtensionTreatmentInterpreter extends AbstractHandlerBehaviou ...@@ -102,11 +131,20 @@ public class NiciraExtensionTreatmentInterpreter extends AbstractHandlerBehaviou
102 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_RESUBMIT.type())) { 131 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_RESUBMIT.type())) {
103 return new NiciraResubmit(); 132 return new NiciraResubmit();
104 } 133 }
134 + if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_RESUBMIT_TABLE.type())) {
135 + return new NiciraResubmitTable();
136 + }
105 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_SPI.type())) { 137 if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_SPI.type())) {
106 return new NiciraSetNshSpi(); 138 return new NiciraSetNshSpi();
107 } 139 }
108 - if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_RESUBMIT_TABLE.type())) { 140 + if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_SI.type())) {
109 - return new NiciraResubmitTable(); 141 + return new NiciraSetNshSi();
142 + }
143 + if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH1.type())
144 + || type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH2.type())
145 + || type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH3.type())
146 + || type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH4.type())) {
147 + return new NiciraSetNshContextHeader(type);
110 } 148 }
111 throw new UnsupportedOperationException( 149 throw new UnsupportedOperationException(
112 "Driver does not support extension type " + type.toString()); 150 "Driver does not support extension type " + type.toString());
......
1 +/*
2 + * Copyright 2015 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +
17 +package org.onosproject.driver.extensions;
18 +
19 +import java.util.Objects;
20 +
21 +import org.onlab.util.KryoNamespace;
22 +import org.onosproject.net.flow.instructions.AbstractExtensionTreatment;
23 +import org.onosproject.net.flow.instructions.ExtensionTreatmentType;
24 +
25 +import com.google.common.base.MoreObjects;
26 +
27 +/**
28 + * Nicira set NSH Context header extension instruction.
29 + */
30 +public class NiciraSetNshContextHeader extends AbstractExtensionTreatment {
31 +
32 + private int nshCh;
33 + private ExtensionTreatmentType type;
34 +
35 + private final KryoNamespace appKryo = new KryoNamespace.Builder().build();
36 +
37 + /**
38 + * Creates a new set nsh context header instruction.
39 + *
40 + * @param type extension treatment type
41 + */
42 + NiciraSetNshContextHeader(ExtensionTreatmentType type) {
43 + this.nshCh = 0;
44 + this.type = type;
45 + }
46 +
47 + /**
48 + * Creates a new set nsh context header instruction.
49 + *
50 + * @param nshCh nsh context header
51 + * @param type extension treatment type
52 + */
53 + NiciraSetNshContextHeader(int nshCh, ExtensionTreatmentType type) {
54 + this.nshCh = nshCh;
55 + this.type = type;
56 + }
57 +
58 + /**
59 + * Gets the nsh context header.
60 + *
61 + * @return nsh context header
62 + */
63 + public int nshCh() {
64 + return nshCh;
65 + }
66 +
67 + @Override
68 + public ExtensionTreatmentType type() {
69 + return type;
70 + }
71 +
72 + @Override
73 + public void deserialize(byte[] data) {
74 + nshCh = appKryo.deserialize(data);
75 + }
76 +
77 + @Override
78 + public byte[] serialize() {
79 + return appKryo.serialize(nshCh);
80 + }
81 +
82 + @Override
83 + public int hashCode() {
84 + return Objects.hash(nshCh, type);
85 + }
86 +
87 + @Override
88 + public boolean equals(Object obj) {
89 + if (this == obj) {
90 + return true;
91 + }
92 + if (obj instanceof NiciraSetNshContextHeader) {
93 + NiciraSetNshContextHeader that = (NiciraSetNshContextHeader) obj;
94 + return Objects.equals(nshCh, that.nshCh) && Objects.equals(type, that.type);
95 +
96 + }
97 + return false;
98 + }
99 +
100 + @Override
101 + public String toString() {
102 + return MoreObjects.toStringHelper(getClass())
103 + .add("nshCh", nshCh)
104 + .add("type", type)
105 + .toString();
106 + }
107 +}
1 +/*
2 + * Copyright 2015 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +
17 +package org.onosproject.driver.extensions;
18 +
19 +import java.util.Objects;
20 +
21 +import org.onlab.util.KryoNamespace;
22 +import org.onosproject.net.flow.instructions.AbstractExtensionTreatment;
23 +import org.onosproject.net.flow.instructions.ExtensionTreatmentType;
24 +
25 +import com.google.common.base.MoreObjects;
26 +
27 +/**
28 + * Nicira set NSH SI extension instruction.
29 + */
30 +public class NiciraSetNshSi extends AbstractExtensionTreatment {
31 +
32 + private byte nshSi;
33 +
34 + private final KryoNamespace appKryo = new KryoNamespace.Builder().build();
35 +
36 + /**
37 + * Creates a new set nsh si instruction.
38 + */
39 + NiciraSetNshSi() {
40 + nshSi = 0;
41 + }
42 +
43 + /**
44 + * Creates a new set nsh si instruction with given si.
45 + *
46 + * @param nshSi nsh service index
47 + */
48 + NiciraSetNshSi(byte nshSi) {
49 + this.nshSi = nshSi;
50 + }
51 +
52 + /**
53 + * Gets the nsh service index.
54 + *
55 + * @return nsh service index
56 + */
57 + public byte nshSi() {
58 + return nshSi;
59 + }
60 +
61 + @Override
62 + public ExtensionTreatmentType type() {
63 + return ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_SI.type();
64 + }
65 +
66 + @Override
67 + public void deserialize(byte[] data) {
68 + nshSi = appKryo.deserialize(data);
69 + }
70 +
71 + @Override
72 + public byte[] serialize() {
73 + return appKryo.serialize(nshSi);
74 + }
75 +
76 + @Override
77 + public int hashCode() {
78 + return Objects.hash(nshSi);
79 + }
80 +
81 + @Override
82 + public boolean equals(Object obj) {
83 + if (this == obj) {
84 + return true;
85 + }
86 + if (obj instanceof NiciraSetNshSi) {
87 + NiciraSetNshSi that = (NiciraSetNshSi) obj;
88 + return Objects.equals(nshSi, that.nshSi);
89 +
90 + }
91 + return false;
92 + }
93 +
94 + @Override
95 + public String toString() {
96 + return MoreObjects.toStringHelper(getClass())
97 + .add("nshSi", nshSi)
98 + .toString();
99 + }
100 +}
...@@ -21,7 +21,6 @@ import java.util.Objects; ...@@ -21,7 +21,6 @@ import java.util.Objects;
21 import org.onlab.util.KryoNamespace; 21 import org.onlab.util.KryoNamespace;
22 import org.onosproject.net.flow.instructions.AbstractExtensionTreatment; 22 import org.onosproject.net.flow.instructions.AbstractExtensionTreatment;
23 import org.onosproject.net.flow.instructions.ExtensionTreatmentType; 23 import org.onosproject.net.flow.instructions.ExtensionTreatmentType;
24 -import org.onosproject.store.serializers.Ip4AddressSerializer;
25 24
26 import com.google.common.base.MoreObjects; 25 import com.google.common.base.MoreObjects;
27 26
...@@ -32,10 +31,7 @@ public class NiciraSetNshSpi extends AbstractExtensionTreatment { ...@@ -32,10 +31,7 @@ public class NiciraSetNshSpi extends AbstractExtensionTreatment {
32 31
33 private int nshSpi; 32 private int nshSpi;
34 33
35 - private final KryoNamespace appKryo = new KryoNamespace.Builder() 34 + private final KryoNamespace appKryo = new KryoNamespace.Builder().build();
36 - .register(new Ip4AddressSerializer(), Integer.class)
37 - .register(byte[].class)
38 - .build();
39 35
40 /** 36 /**
41 * Creates a new set nsh spi instruction. 37 * Creates a new set nsh spi instruction.
......
1 +/*
2 + * Copyright 2015 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.driver.extensions;
17 +
18 +import static org.hamcrest.MatcherAssert.assertThat;
19 +import static org.hamcrest.Matchers.is;
20 +import static org.hamcrest.Matchers.notNullValue;
21 +
22 +import org.junit.Test;
23 +import org.onosproject.net.flow.instructions.ExtensionTreatmentType;
24 +
25 +import com.google.common.testing.EqualsTester;
26 +
27 +/**
28 + * Unit tests for NiciraSetNshContextHeader class.
29 + */
30 +public class NiciraSetNshContextHeaderTest {
31 +
32 + final NiciraSetNshContextHeader nshCh1 = new NiciraSetNshContextHeader(10,
33 + ExtensionTreatmentType.
34 + ExtensionTreatmentTypes.
35 + NICIRA_SET_NSH_CH1.type());
36 + final NiciraSetNshContextHeader sameAsNshCh1 = new NiciraSetNshContextHeader(10,
37 + ExtensionTreatmentType.
38 + ExtensionTreatmentTypes.
39 + NICIRA_SET_NSH_CH1.type());
40 + final NiciraSetNshContextHeader nshCh2 = new NiciraSetNshContextHeader(20,
41 + ExtensionTreatmentType.
42 + ExtensionTreatmentTypes.
43 + NICIRA_SET_NSH_CH1.type());
44 +
45 + /**
46 + * Checks the operation of equals() methods.
47 + */
48 + @Test
49 + public void testEquals() {
50 + new EqualsTester().addEqualityGroup(nshCh1, sameAsNshCh1).addEqualityGroup(nshCh2).testEquals();
51 + }
52 +
53 + /**
54 + * Checks the construction of a NiciraSetNshSi object.
55 + */
56 + @Test
57 + public void testConstruction() {
58 + final NiciraSetNshContextHeader niciraSetNshCh = new NiciraSetNshContextHeader(10,
59 + ExtensionTreatmentType.
60 + ExtensionTreatmentTypes.
61 + NICIRA_SET_NSH_CH1.type());
62 + assertThat(niciraSetNshCh, is(notNullValue()));
63 + assertThat(niciraSetNshCh.nshCh(), is(10));
64 + assertThat(niciraSetNshCh.type(), is(ExtensionTreatmentType.
65 + ExtensionTreatmentTypes.
66 + NICIRA_SET_NSH_CH1.type()));
67 + }
68 +}
1 +/*
2 + * Copyright 2015 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.driver.extensions;
17 +
18 +import static org.hamcrest.MatcherAssert.assertThat;
19 +import static org.hamcrest.Matchers.is;
20 +import static org.hamcrest.Matchers.notNullValue;
21 +
22 +import org.junit.Test;
23 +
24 +import com.google.common.testing.EqualsTester;
25 +
26 +/**
27 + * Unit tests for NiciraSetNshSi class.
28 + */
29 +public class NiciraSetNshSiTest {
30 +
31 + final NiciraSetNshSi nshSi1 = new NiciraSetNshSi((byte) 10);
32 + final NiciraSetNshSi sameAsNshSi1 = new NiciraSetNshSi((byte) 10);
33 + final NiciraSetNshSi nshSi2 = new NiciraSetNshSi((byte) 20);
34 +
35 + /**
36 + * Checks the operation of equals() methods.
37 + */
38 + @Test
39 + public void testEquals() {
40 + new EqualsTester().addEqualityGroup(nshSi1, sameAsNshSi1).addEqualityGroup(nshSi2).testEquals();
41 + }
42 +
43 + /**
44 + * Checks the construction of a NiciraSetNshSi object.
45 + */
46 + @Test
47 + public void testConstruction() {
48 + final NiciraSetNshSi niciraSetNshSi = new NiciraSetNshSi((byte) 15);
49 + assertThat(niciraSetNshSi, is(notNullValue()));
50 + assertThat(niciraSetNshSi.nshSi(), is((byte) 15));
51 + }
52 +}
1 +/*
2 + * Copyright 2015 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.driver.extensions;
17 +
18 +import static org.hamcrest.MatcherAssert.assertThat;
19 +import static org.hamcrest.Matchers.is;
20 +import static org.hamcrest.Matchers.notNullValue;
21 +
22 +import org.junit.Test;
23 +
24 +import com.google.common.testing.EqualsTester;
25 +
26 +/**
27 + * Unit tests for NiciraSetNshSpi class.
28 + */
29 +public class NiciraSetNshSpiTest {
30 +
31 + final NiciraSetNshSpi nshSpi1 = new NiciraSetNshSpi(10);
32 + final NiciraSetNshSpi sameAsNshSpi1 = new NiciraSetNshSpi(10);
33 + final NiciraSetNshSpi nshSpi2 = new NiciraSetNshSpi(20);
34 +
35 + /**
36 + * Checks the operation of equals() methods.
37 + */
38 + @Test
39 + public void testEquals() {
40 + new EqualsTester().addEqualityGroup(nshSpi1, sameAsNshSpi1).addEqualityGroup(nshSpi2).testEquals();
41 + }
42 +
43 + /**
44 + * Checks the construction of a NiciraSetNshSpi object.
45 + */
46 + @Test
47 + public void testConstruction() {
48 + final NiciraSetNshSpi niciraSetNshSpi = new NiciraSetNshSpi(10);
49 + assertThat(niciraSetNshSpi, is(notNullValue()));
50 + assertThat(niciraSetNshSpi.nshSpi(), is(10));
51 + }
52 +}