Yafit Hadar
Committed by Gerrit Code Review

[Emu] Defining classes for ODU SIGID and SIGTYPE Fields in Flow Criteria and Ins…

…truction - Data Model and Tests only

Change-Id: I3a71520caa286a1fcc509c581036ef4848de9b5b
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.net;
17 +
18 +import static com.google.common.base.Preconditions.checkArgument;
19 +
20 +import java.util.Arrays;
21 +import java.util.Objects;
22 +
23 +import org.onlab.util.HexString;
24 +
25 +import com.google.common.base.MoreObjects;
26 +/**
27 + * Implementation of ODU Signal ID.
28 + *
29 + * <p>
30 + * See ITU G.709 "Interfaces for the Optical Transport Network (OTN)".
31 + * </p>
32 + */
33 +public class OduSignalId {
34 +
35 + private final int tributaryPortNumber; // Tributary Port number
36 + private final int tributarySlotLength; // Number of Tributary Slots included in tsmap
37 + private final byte[] tributarySlotBitmap; // Tributary slot bitmap
38 +
39 + public static final int TRIBUTARY_SLOT_BITMAP_SIZE = 10;
40 +
41 + /**
42 + * Creates an instance with the specified arguments.
43 + *
44 + * @param tributaryPortNumber tributary port number
45 + * @param tributarySlotLen tributary slot len
46 + * @param tributarySlotBitmap tributary slot bitmap
47 + */
48 + public OduSignalId(int tributaryPortNumber, int tributarySlotLen,
49 + byte[] tributarySlotBitmap) {
50 +
51 + checkArgument(tributaryPortNumber <= 80 ,
52 + "tributaryPortNumber %s must be <= 80 ",
53 + tributaryPortNumber);
54 +
55 + checkArgument(tributarySlotBitmap.length == TRIBUTARY_SLOT_BITMAP_SIZE,
56 + "number of elements in list " + HexString.toHexString(tributarySlotBitmap)
57 + + " must be equal to " + TRIBUTARY_SLOT_BITMAP_SIZE);
58 +
59 + checkArgument(tributarySlotLen <= 80 ,
60 + "tributarySlotLen %s must be <= 80 ",
61 + tributarySlotLen);
62 +
63 + this.tributaryPortNumber = tributaryPortNumber;
64 + this.tributarySlotLength = tributarySlotLen;
65 + this.tributarySlotBitmap = Arrays.copyOf(tributarySlotBitmap, tributarySlotBitmap.length);
66 + }
67 +
68 + /**
69 + * Returns the OduSignalId representing the specified parameters.
70 + *
71 + * @param tributaryPortNumber tributary port number
72 + * @param tributarySlotLen tributary slot len
73 + * @param tributarySlotBitmap tributary slot bitmap
74 + * @return OduSignalId
75 + */
76 + public static OduSignalId oduSignalId(int tributaryPortNumber, int tributarySlotLen,
77 + byte[] tributarySlotBitmap) {
78 + return new OduSignalId(tributaryPortNumber, tributarySlotLen, tributarySlotBitmap);
79 + }
80 +
81 +
82 + /**
83 + * Returns tributary port number.
84 + *
85 + * @return the tributaryPortNumber
86 + */
87 + public int tributaryPortNumber() {
88 + return tributaryPortNumber;
89 + }
90 +
91 + /**
92 + * Returns tributary slot length.
93 + *
94 + * @return the tributarySlotLen
95 + */
96 + public int tributarySlotLength() {
97 + return tributarySlotLength;
98 + }
99 +
100 + /**
101 + * Returns tributary slot bitmap.
102 + *
103 + * @return the tributarySlotBitmap
104 + */
105 + public byte[] tributarySlotBitmap() {
106 + return Arrays.copyOf(tributarySlotBitmap, tributarySlotBitmap.length);
107 + }
108 +
109 + @Override
110 + public int hashCode() {
111 + return Objects.hash(tributaryPortNumber, tributarySlotLength, Arrays.hashCode(tributarySlotBitmap));
112 + }
113 +
114 + @Override
115 + public boolean equals(Object obj) {
116 + if (this == obj) {
117 + return true;
118 + }
119 + if (!(obj instanceof OduSignalId)) {
120 + return false;
121 + }
122 + final OduSignalId other = (OduSignalId) obj;
123 + return Objects.equals(this.tributaryPortNumber, other.tributaryPortNumber)
124 + && Objects.equals(this.tributarySlotLength, other.tributarySlotLength)
125 + && Arrays.equals(tributarySlotBitmap, other.tributarySlotBitmap);
126 + }
127 +
128 + @Override
129 + public String toString() {
130 + return MoreObjects.toStringHelper(this)
131 + .omitNullValues()
132 + .add("tributaryPortNumber", tributaryPortNumber)
133 + .add("tributarySlotLength", tributarySlotLength)
134 + .add("tributarySlotBitmap", HexString.toHexString(tributarySlotBitmap))
135 + .toString();
136 + }
137 +
138 +}
139 +
...@@ -25,6 +25,8 @@ import org.onlab.packet.VlanId; ...@@ -25,6 +25,8 @@ import org.onlab.packet.VlanId;
25 import org.onosproject.net.IndexedLambda; 25 import org.onosproject.net.IndexedLambda;
26 import org.onosproject.net.Lambda; 26 import org.onosproject.net.Lambda;
27 import org.onosproject.net.OchSignal; 27 import org.onosproject.net.OchSignal;
28 +import org.onosproject.net.OduSignalId;
29 +import org.onosproject.net.OduSignalType;
28 import org.onosproject.net.PortNumber; 30 import org.onosproject.net.PortNumber;
29 import org.onosproject.net.flow.criteria.Criterion.Type; 31 import org.onosproject.net.flow.criteria.Criterion.Type;
30 import org.onosproject.net.OchSignalType; 32 import org.onosproject.net.OchSignalType;
...@@ -486,6 +488,26 @@ public final class Criteria { ...@@ -486,6 +488,26 @@ public final class Criteria {
486 return new OchSignalTypeCriterion(signalType); 488 return new OchSignalTypeCriterion(signalType);
487 } 489 }
488 490
491 + /**
492 + * Creates a match on ODU (Optical channel Data Unit) signal ID using the specified value.
493 + *
494 + * @param oduSignalId ODU Signal Id
495 + * @return match criterion
496 + */
497 + public static Criterion matchOduSignalId(OduSignalId oduSignalId) {
498 + return new OduSignalIdCriterion(oduSignalId);
499 + }
500 +
501 + /**
502 + * Creates a match on ODU (Optical channel Data Unit) signal Type using the specified value.
503 + *
504 + * @param signalType ODU Signal Type
505 + * @return match criterion
506 + */
507 + public static Criterion matchOduSignalType(OduSignalType signalType) {
508 + return new OduSignalTypeCriterion(signalType);
509 + }
510 +
489 public static Criterion dummy() { 511 public static Criterion dummy() {
490 return new DummyCriterion(); 512 return new DummyCriterion();
491 } 513 }
......
...@@ -125,6 +125,10 @@ public interface Criterion { ...@@ -125,6 +125,10 @@ public interface Criterion {
125 OCH_SIGID, 125 OCH_SIGID,
126 /** Optical channel signal type (fixed or flexible). */ 126 /** Optical channel signal type (fixed or flexible). */
127 OCH_SIGTYPE, 127 OCH_SIGTYPE,
128 + /** ODU (Optical channel Data Unit) signal ID. */
129 + ODU_SIGID,
130 + /** ODU (Optical channel Data Unit) signal type. */
131 + ODU_SIGTYPE,
128 132
129 /** 133 /**
130 * An empty criterion. 134 * An empty criterion.
......
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.net.flow.criteria;
17 +
18 +import static com.google.common.base.MoreObjects.toStringHelper;
19 +import static com.google.common.base.Preconditions.checkNotNull;
20 +
21 +import java.util.Objects;
22 +
23 +import org.onosproject.net.OduSignalId;
24 +
25 +/**
26 + * Implementation of ODU (Optical channel Data Unit) signal ID signal criterion.
27 + * This criterion is based on the specification of "OFPXMT_EXP_ODU_SIGID" in
28 + * Open Networking Foundation "Optical Transport Protocol Extension Version 1.0", but
29 + * defined in protocol agnostic way.
30 + */
31 +public final class OduSignalIdCriterion implements Criterion {
32 +
33 + private final OduSignalId oduSignalId;
34 +
35 + /**
36 + * Create an instance with the specified ODU signal ID.
37 + *
38 + * @param oduSignalId - ODU signal ID
39 + */
40 + OduSignalIdCriterion(OduSignalId oduSignalId) {
41 + this.oduSignalId = checkNotNull(oduSignalId);
42 + }
43 +
44 + @Override
45 + public Type type() {
46 + return Type.ODU_SIGID;
47 + }
48 +
49 + /**
50 + * Returns the ODU Signal to match.
51 + *
52 + * @return the ODU signal to match
53 + */
54 + public OduSignalId oduSignalId() {
55 + return oduSignalId;
56 + }
57 +
58 + @Override
59 + public int hashCode() {
60 + return Objects.hash(type(), oduSignalId);
61 + }
62 +
63 + @Override
64 + public boolean equals(Object obj) {
65 + if (this == obj) {
66 + return true;
67 + }
68 + if (!(obj instanceof OduSignalIdCriterion)) {
69 + return false;
70 + }
71 + final OduSignalIdCriterion that = (OduSignalIdCriterion) obj;
72 + return Objects.equals(this.oduSignalId, that.oduSignalId);
73 + }
74 +
75 + @Override
76 + public String toString() {
77 + return toStringHelper(type().toString())
78 + .add("oduSignalId", oduSignalId)
79 + .toString();
80 + }
81 +
82 +}
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.net.flow.criteria;
17 +
18 +import static com.google.common.base.MoreObjects.toStringHelper;
19 +import static com.google.common.base.Preconditions.checkNotNull;
20 +
21 +import java.util.Objects;
22 +
23 +import org.onosproject.net.OduSignalType;
24 +
25 +/**
26 + * Implementation of ODU (Optical channel Data Unit) signal Type criterion.
27 + * This criterion is based on the specification of "OFPXMT_EXP_ODU_SIGTYPE" in
28 + * Open Networking Foundation "Optical Transport Protocol Extension Version 1.0", but
29 + * defined in protocol agnostic way.
30 + */
31 +public final class OduSignalTypeCriterion implements Criterion {
32 +
33 + private final OduSignalType signalType;
34 +
35 + /**
36 + * Create an instance with the specified ODU signal Type.
37 + *
38 + * @param signalType - ODU signal Type
39 + */
40 + OduSignalTypeCriterion(OduSignalType signalType) {
41 + this.signalType = checkNotNull(signalType);
42 + }
43 +
44 + @Override
45 + public Type type() {
46 + return Type.ODU_SIGTYPE;
47 + }
48 +
49 + /**
50 + * Returns the ODU Signal Type to match.
51 + *
52 + * @return the ODU signal Type to match
53 + */
54 + public OduSignalType signalType() {
55 + return signalType;
56 + }
57 +
58 + @Override
59 + public int hashCode() {
60 + return Objects.hash(type(), signalType);
61 + }
62 +
63 + @Override
64 + public boolean equals(Object obj) {
65 + if (this == obj) {
66 + return true;
67 + }
68 + if (!(obj instanceof OduSignalTypeCriterion)) {
69 + return false;
70 + }
71 + final OduSignalTypeCriterion that = (OduSignalTypeCriterion) obj;
72 + return Objects.equals(this.signalType, that.signalType);
73 + }
74 +
75 + @Override
76 + public String toString() {
77 + return toStringHelper(type().toString())
78 + .add("signalType", signalType)
79 + .toString();
80 + }
81 +}
...@@ -59,6 +59,11 @@ public interface Instruction { ...@@ -59,6 +59,11 @@ public interface Instruction {
59 L0MODIFICATION, 59 L0MODIFICATION,
60 60
61 /** 61 /**
62 + * Signifies that the traffic should be modified in L1 way.
63 + */
64 + L1MODIFICATION,
65 +
66 + /**
62 * Signifies that the traffic should be modified in L2 way. 67 * Signifies that the traffic should be modified in L2 way.
63 */ 68 */
64 L2MODIFICATION, 69 L2MODIFICATION,
...@@ -86,6 +91,7 @@ public interface Instruction { ...@@ -86,6 +91,7 @@ public interface Instruction {
86 91
87 /** 92 /**
88 * Returns the type of instruction. 93 * Returns the type of instruction.
94 + *
89 * @return type of instruction 95 * @return type of instruction
90 */ 96 */
91 Type type(); 97 Type type();
......
...@@ -25,10 +25,12 @@ import org.onosproject.core.GroupId; ...@@ -25,10 +25,12 @@ import org.onosproject.core.GroupId;
25 import org.onosproject.net.IndexedLambda; 25 import org.onosproject.net.IndexedLambda;
26 import org.onosproject.net.Lambda; 26 import org.onosproject.net.Lambda;
27 import org.onosproject.net.OchSignal; 27 import org.onosproject.net.OchSignal;
28 +import org.onosproject.net.OduSignalId;
28 import org.onosproject.net.PortNumber; 29 import org.onosproject.net.PortNumber;
29 import org.onosproject.net.flow.instructions.L0ModificationInstruction.L0SubType; 30 import org.onosproject.net.flow.instructions.L0ModificationInstruction.L0SubType;
30 import org.onosproject.net.flow.instructions.L0ModificationInstruction.ModLambdaInstruction; 31 import org.onosproject.net.flow.instructions.L0ModificationInstruction.ModLambdaInstruction;
31 import org.onosproject.net.flow.instructions.L0ModificationInstruction.ModOchSignalInstruction; 32 import org.onosproject.net.flow.instructions.L0ModificationInstruction.ModOchSignalInstruction;
33 +import org.onosproject.net.flow.instructions.L1ModificationInstruction.ModOduSignalIdInstruction;
32 import org.onosproject.net.flow.instructions.L3ModificationInstruction.L3SubType; 34 import org.onosproject.net.flow.instructions.L3ModificationInstruction.L3SubType;
33 import org.onosproject.net.flow.instructions.L3ModificationInstruction.ModIPInstruction; 35 import org.onosproject.net.flow.instructions.L3ModificationInstruction.ModIPInstruction;
34 import org.onosproject.net.flow.instructions.L3ModificationInstruction.ModIPv6FlowLabelInstruction; 36 import org.onosproject.net.flow.instructions.L3ModificationInstruction.ModIPv6FlowLabelInstruction;
...@@ -47,7 +49,6 @@ import static com.google.common.base.Preconditions.checkNotNull; ...@@ -47,7 +49,6 @@ import static com.google.common.base.Preconditions.checkNotNull;
47 */ 49 */
48 public final class Instructions { 50 public final class Instructions {
49 51
50 -
51 // Ban construction 52 // Ban construction
52 private Instructions() {} 53 private Instructions() {}
53 54
...@@ -117,6 +118,16 @@ public final class Instructions { ...@@ -117,6 +118,16 @@ public final class Instructions {
117 } 118 }
118 119
119 /** 120 /**
121 + * Creates an L1 modification with the specified ODU signal Id.
122 + *
123 + * @param oduSignalId ODU Signal Id
124 + * @return a L1 modification
125 + */
126 + public static L1ModificationInstruction modL1OduSignalId(OduSignalId oduSignalId) {
127 + checkNotNull(oduSignalId, "L1 ODU signal ID cannot be null");
128 + return new ModOduSignalIdInstruction(oduSignalId);
129 + }
130 + /**
120 * Creates a l2 src modification. 131 * Creates a l2 src modification.
121 * 132 *
122 * @param addr the mac address to modify to 133 * @param addr the mac address to modify to
......
1 +/*
2 + * Copyright 2014-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.net.flow.instructions;
17 +
18 +import org.onosproject.net.OduSignalId;
19 +
20 +import static com.google.common.base.MoreObjects.toStringHelper;
21 +
22 +import java.util.Objects;
23 +
24 +public abstract class L1ModificationInstruction implements Instruction {
25 +
26 + /**
27 + * Represents the type of traffic treatment.
28 + */
29 + public enum L1SubType {
30 + /**
31 + * ODU (Optical channel Data Unit) Signal Id modification.
32 + */
33 + ODU_SIGID
34 + }
35 +
36 + public abstract L1SubType subtype();
37 +
38 + @Override
39 + public final Type type() {
40 + return Type.L1MODIFICATION;
41 + }
42 +
43 + /**
44 + * Represents an L1 ODU (Optical channel Data Unit) Signal Id modification instruction.
45 + */
46 + public static final class ModOduSignalIdInstruction extends L1ModificationInstruction {
47 +
48 + private final OduSignalId oduSignalId;
49 +
50 + ModOduSignalIdInstruction(OduSignalId oduSignalId) {
51 + this.oduSignalId = oduSignalId;
52 + }
53 +
54 + @Override
55 + public L1SubType subtype() {
56 + return L1SubType.ODU_SIGID;
57 + }
58 +
59 + public OduSignalId oduSignalId() {
60 + return oduSignalId;
61 + }
62 +
63 + @Override
64 + public int hashCode() {
65 + return Objects.hash(oduSignalId);
66 + }
67 +
68 + @Override
69 + public boolean equals(Object obj) {
70 + if (this == obj) {
71 + return true;
72 + }
73 + if (!(obj instanceof ModOduSignalIdInstruction)) {
74 + return false;
75 + }
76 + final ModOduSignalIdInstruction that = (ModOduSignalIdInstruction) obj;
77 + return Objects.equals(this.oduSignalId, that.oduSignalId);
78 + }
79 +
80 + @Override
81 + public String toString() {
82 + return toStringHelper(this)
83 + .add("oduSignalId", oduSignalId)
84 + .toString();
85 + }
86 + }
87 +
88 +}
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.net;
17 +
18 +import com.google.common.testing.EqualsTester;
19 +import org.junit.Test;
20 +import static org.onosproject.net.OduSignalId.oduSignalId;
21 +
22 +/**
23 + * Test for OduSignalId.
24 + */
25 +public class OduSignalIdTest {
26 +
27 + private final OduSignalId odu1 = oduSignalId(7, 80, new byte[] {16, 16, 16, 16, 16, 16, 16, 16, 16, 16});
28 + private final OduSignalId sameOdu1 = oduSignalId(7, 80, new byte[] {16, 16, 16, 16, 16, 16, 16, 16, 16, 16});
29 + private final OduSignalId odu2 = oduSignalId(21, 80, new byte[] {10, 5, 10, 5, 10, 5, 10, 5, 10, 5});
30 + private final OduSignalId sameOdu2 = oduSignalId(21, 80, new byte[] {10, 5, 10, 5, 10, 5, 10, 5, 10, 5});
31 +
32 + @Test
33 + public void testEquality() {
34 + new EqualsTester()
35 + .addEqualityGroup(odu1, sameOdu1)
36 + .addEqualityGroup(odu2, sameOdu2)
37 + .testEquals();
38 + }
39 +}
...@@ -15,6 +15,16 @@ ...@@ -15,6 +15,16 @@
15 */ 15 */
16 package org.onosproject.net.flow.criteria; 16 package org.onosproject.net.flow.criteria;
17 17
18 +import static org.hamcrest.MatcherAssert.assertThat;
19 +import static org.hamcrest.Matchers.equalTo;
20 +import static org.hamcrest.Matchers.instanceOf;
21 +import static org.hamcrest.Matchers.is;
22 +import static org.hamcrest.Matchers.notNullValue;
23 +import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
24 +import static org.onlab.junit.UtilityClassChecker.assertThatClassIsUtility;
25 +import static org.onosproject.net.OduSignalId.oduSignalId;
26 +import static org.onosproject.net.PortNumber.portNumber;
27 +
18 import org.junit.Test; 28 import org.junit.Test;
19 import org.onlab.packet.EthType; 29 import org.onlab.packet.EthType;
20 import org.onlab.packet.Ip6Address; 30 import org.onlab.packet.Ip6Address;
...@@ -26,20 +36,12 @@ import org.onlab.packet.VlanId; ...@@ -26,20 +36,12 @@ import org.onlab.packet.VlanId;
26 import org.onosproject.net.ChannelSpacing; 36 import org.onosproject.net.ChannelSpacing;
27 import org.onosproject.net.GridType; 37 import org.onosproject.net.GridType;
28 import org.onosproject.net.Lambda; 38 import org.onosproject.net.Lambda;
39 +import org.onosproject.net.OchSignalType;
40 +import org.onosproject.net.OduSignalId;
41 +import org.onosproject.net.OduSignalType;
29 import org.onosproject.net.PortNumber; 42 import org.onosproject.net.PortNumber;
30 43
31 import com.google.common.testing.EqualsTester; 44 import com.google.common.testing.EqualsTester;
32 -import org.onosproject.net.OchSignalType;
33 -
34 -import static org.hamcrest.MatcherAssert.assertThat;
35 -import static org.hamcrest.Matchers.equalTo;
36 -import static org.hamcrest.Matchers.instanceOf;
37 -import static org.hamcrest.Matchers.is;
38 -import static org.hamcrest.Matchers.notNullValue;
39 -import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
40 -import static org.onlab.junit.UtilityClassChecker.assertThatClassIsUtility;
41 -import static org.onosproject.net.PortNumber.portNumber;
42 -
43 /** 45 /**
44 * Unit tests for the Criteria class and its subclasses. 46 * Unit tests for the Criteria class and its subclasses.
45 */ 47 */
...@@ -240,6 +242,18 @@ public class CriteriaTest { ...@@ -240,6 +242,18 @@ public class CriteriaTest {
240 Criterion matchOchSignal2 = 242 Criterion matchOchSignal2 =
241 Criteria.matchLambda(Lambda.ochSignal(GridType.DWDM, ChannelSpacing.CHL_50GHZ, 4, 8)); 243 Criteria.matchLambda(Lambda.ochSignal(GridType.DWDM, ChannelSpacing.CHL_50GHZ, 4, 8));
242 244
245 + final OduSignalId odu1 = oduSignalId(1, 80, new byte [] {1, 1, 2, 2, 1, 2, 2, 1, 2, 2});
246 + final OduSignalId odu2 = oduSignalId(3, 8, new byte [] {1, 0, 0, 0, 0, 0, 0, 0, 0, 0});
247 + Criterion matchOduSignalId1 = Criteria.matchOduSignalId(odu1);
248 + Criterion sameAsMatchOduSignalId1 = Criteria.matchOduSignalId(odu1);
249 + Criterion matchOduSignalId2 = Criteria.matchOduSignalId(odu2);
250 +
251 + final OduSignalType oduSigType1 = OduSignalType.ODU2;
252 + final OduSignalType oduSigType2 = OduSignalType.ODU4;
253 + Criterion matchOduSignalType1 = Criteria.matchOduSignalType(oduSigType1);
254 + Criterion sameAsMatchOduSignalType1 = Criteria.matchOduSignalType(oduSigType1);
255 + Criterion matchOduSignalType2 = Criteria.matchOduSignalType(oduSigType2);
256 +
243 /** 257 /**
244 * Checks that a Criterion object has the proper type, and then converts 258 * Checks that a Criterion object has the proper type, and then converts
245 * it to the proper type. 259 * it to the proper type.
...@@ -294,6 +308,8 @@ public class CriteriaTest { ...@@ -294,6 +308,8 @@ public class CriteriaTest {
294 assertThatClassIsImmutable(MplsCriterion.class); 308 assertThatClassIsImmutable(MplsCriterion.class);
295 assertThatClassIsImmutable(IPv6ExthdrFlagsCriterion.class); 309 assertThatClassIsImmutable(IPv6ExthdrFlagsCriterion.class);
296 assertThatClassIsImmutable(LambdaCriterion.class); 310 assertThatClassIsImmutable(LambdaCriterion.class);
311 + assertThatClassIsImmutable(OduSignalIdCriterion.class);
312 + assertThatClassIsImmutable(OduSignalTypeCriterion.class);
297 } 313 }
298 314
299 // PortCriterion class 315 // PortCriterion class
...@@ -1070,4 +1086,57 @@ public class CriteriaTest { ...@@ -1070,4 +1086,57 @@ public class CriteriaTest {
1070 .addEqualityGroup(matchOchSignalType2) 1086 .addEqualityGroup(matchOchSignalType2)
1071 .testEquals(); 1087 .testEquals();
1072 } 1088 }
1089 +
1090 + /**
1091 + * Test the OduSignalId method.
1092 + */
1093 + @Test
1094 + public void testMatchOduSignalIdMethod() {
1095 + OduSignalId odu = oduSignalId(1, 80, new byte[]{2, 1, 1, 3, 1, 1, 3, 1, 1, 3});
1096 +
1097 + Criterion matchoduSignalId = Criteria.matchOduSignalId(odu);
1098 + OduSignalIdCriterion oduSignalIdCriterion =
1099 + checkAndConvert(matchoduSignalId,
1100 + Criterion.Type.ODU_SIGID,
1101 + OduSignalIdCriterion.class);
1102 + assertThat(oduSignalIdCriterion.oduSignalId(), is(equalTo(odu)));
1103 + }
1104 +
1105 + /**
1106 + * Test the equals() method of the OduSignalIdCriterion class.
1107 + */
1108 + @Test
1109 + public void testOduSignalIdCriterionEquals() {
1110 + new EqualsTester()
1111 + .addEqualityGroup(matchOduSignalId1, sameAsMatchOduSignalId1)
1112 + .addEqualityGroup(matchOduSignalId2)
1113 + .testEquals();
1114 + }
1115 +
1116 + // OduSignalTypeCriterion class
1117 +
1118 + /**
1119 + * Test the OduSignalType method.
1120 + */
1121 + @Test
1122 + public void testMatchOduSignalTypeMethod() {
1123 + OduSignalType oduSigType = OduSignalType.ODU2;
1124 + Criterion matchoduSignalType = Criteria.matchOduSignalType(oduSigType);
1125 + OduSignalTypeCriterion oduSignalTypeCriterion =
1126 + checkAndConvert(matchoduSignalType,
1127 + Criterion.Type.ODU_SIGTYPE,
1128 + OduSignalTypeCriterion.class);
1129 + assertThat(oduSignalTypeCriterion.signalType(), is(equalTo(oduSigType)));
1130 + }
1131 +
1132 + /**
1133 + * Test the equals() method of the OduSignalTypeCriterion class.
1134 + */
1135 + @Test
1136 + public void testOduSignalTypeCriterionEquals() {
1137 + new EqualsTester()
1138 + .addEqualityGroup(matchOduSignalType1, sameAsMatchOduSignalType1)
1139 + .addEqualityGroup(matchOduSignalType2)
1140 + .testEquals();
1141 + }
1073 } 1142 }
......
...@@ -25,6 +25,7 @@ import org.onosproject.net.ChannelSpacing; ...@@ -25,6 +25,7 @@ import org.onosproject.net.ChannelSpacing;
25 import org.onosproject.net.GridType; 25 import org.onosproject.net.GridType;
26 import org.onosproject.net.IndexedLambda; 26 import org.onosproject.net.IndexedLambda;
27 import org.onosproject.net.Lambda; 27 import org.onosproject.net.Lambda;
28 +import org.onosproject.net.OduSignalId;
28 import org.onosproject.net.PortNumber; 29 import org.onosproject.net.PortNumber;
29 30
30 import com.google.common.testing.EqualsTester; 31 import com.google.common.testing.EqualsTester;
...@@ -38,6 +39,7 @@ import static org.hamcrest.Matchers.notNullValue; ...@@ -38,6 +39,7 @@ import static org.hamcrest.Matchers.notNullValue;
38 import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable; 39 import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
39 import static org.onlab.junit.UtilityClassChecker.assertThatClassIsUtility; 40 import static org.onlab.junit.UtilityClassChecker.assertThatClassIsUtility;
40 import static org.onosproject.net.PortNumber.portNumber; 41 import static org.onosproject.net.PortNumber.portNumber;
42 +import static org.onosproject.net.OduSignalId.oduSignalId;
41 43
42 /** 44 /**
43 * Unit tests for the Instructions class. 45 * Unit tests for the Instructions class.
...@@ -96,6 +98,7 @@ public class InstructionsTest { ...@@ -96,6 +98,7 @@ public class InstructionsTest {
96 assertThatClassIsImmutable(Instructions.OutputInstruction.class); 98 assertThatClassIsImmutable(Instructions.OutputInstruction.class);
97 assertThatClassIsImmutable(L0ModificationInstruction.ModLambdaInstruction.class); 99 assertThatClassIsImmutable(L0ModificationInstruction.ModLambdaInstruction.class);
98 assertThatClassIsImmutable(L0ModificationInstruction.ModOchSignalInstruction.class); 100 assertThatClassIsImmutable(L0ModificationInstruction.ModOchSignalInstruction.class);
101 + assertThatClassIsImmutable(L1ModificationInstruction.ModOduSignalIdInstruction.class);
99 assertThatClassIsImmutable(L2ModificationInstruction.ModEtherInstruction.class); 102 assertThatClassIsImmutable(L2ModificationInstruction.ModEtherInstruction.class);
100 assertThatClassIsImmutable(L2ModificationInstruction.ModVlanIdInstruction.class); 103 assertThatClassIsImmutable(L2ModificationInstruction.ModVlanIdInstruction.class);
101 assertThatClassIsImmutable(L2ModificationInstruction.ModVlanPcpInstruction.class); 104 assertThatClassIsImmutable(L2ModificationInstruction.ModVlanPcpInstruction.class);
...@@ -259,6 +262,44 @@ public class InstructionsTest { ...@@ -259,6 +262,44 @@ public class InstructionsTest {
259 assertThat(ochInstruction1.hashCode(), is(not(ochInstruction2.hashCode()))); 262 assertThat(ochInstruction1.hashCode(), is(not(ochInstruction2.hashCode())));
260 } 263 }
261 264
265 + // ModOduSignalIdInstruction
266 +
267 + private final OduSignalId odu1 = oduSignalId(1, 80, new byte[] {8, 7, 6, 5, 7, 6, 5, 7, 6, 5});
268 + private final OduSignalId odu2 = oduSignalId(2, 80, new byte[] {1, 1, 2, 2, 1, 2, 2, 1, 2, 2});
269 + private final Instruction oduInstruction1 = Instructions.modL1OduSignalId(odu1);
270 + private final Instruction sameAsOduInstruction1 = Instructions.modL1OduSignalId(odu1);
271 + private final Instruction oduInstruction2 = Instructions.modL1OduSignalId(odu2);
272 +
273 + /**
274 + * Test the modL1OduSignalId().
275 + */
276 + @Test
277 + public void testModL1OduSignalIdMethod() {
278 + Instruction instruction = Instructions.modL1OduSignalId(odu1);
279 + L1ModificationInstruction.ModOduSignalIdInstruction oduInstruction =
280 + checkAndConvert(instruction, Instruction.Type.L1MODIFICATION,
281 + L1ModificationInstruction.ModOduSignalIdInstruction.class);
282 + assertThat(oduInstruction.oduSignalId(), is(odu1));
283 + }
284 +
285 + /**
286 + * Test the equals() method of the ModOduSignalInstruction class.
287 + */
288 + @Test
289 + public void testModOduSignalIdInstructionEquals() {
290 + checkEqualsAndToString(oduInstruction1, sameAsOduInstruction1, oduInstruction2);
291 + }
292 +
293 + /**
294 + * Test the hashCode() method of the ModOduSignalInstruction class.
295 + */
296 + @Test
297 + public void testModOduSignalIdInstructionHashCode() {
298 + assertThat(oduInstruction1.hashCode(), is(sameAsOduInstruction1.hashCode()));
299 + assertThat(oduInstruction1.hashCode(), is(not(oduInstruction2.hashCode())));
300 + }
301 +
302 +
262 // ModEtherInstruction 303 // ModEtherInstruction
263 304
264 private static final String MAC1 = "00:00:00:00:00:01"; 305 private static final String MAC1 = "00:00:00:00:00:01";
......
...@@ -61,6 +61,12 @@ public final class CriterionCodec extends JsonCodec<Criterion> { ...@@ -61,6 +61,12 @@ public final class CriterionCodec extends JsonCodec<Criterion> {
61 protected static final String SLOT_GRANULARITY = "slotGranularity"; 61 protected static final String SLOT_GRANULARITY = "slotGranularity";
62 protected static final String OCH_SIGNAL_ID = "ochSignalId"; 62 protected static final String OCH_SIGNAL_ID = "ochSignalId";
63 protected static final String TUNNEL_ID = "tunnelId"; 63 protected static final String TUNNEL_ID = "tunnelId";
64 + protected static final String OCH_SIGNAL_TYPE = "ochSignalType";
65 + protected static final String ODU_SIGNAL_ID = "oduSignalId";
66 + protected static final String TRIBUTARY_PORT_NUMBER = "tributaryPortNumber";
67 + protected static final String TRIBUTARY_SLOT_LEN = "tributarySlotLen";
68 + protected static final String TRIBUTARY_SLOT_BITMAP = "tributarySlotBitmap";
69 + protected static final String ODU_SIGNAL_TYPE = "oduSignalType";
64 70
65 @Override 71 @Override
66 public ObjectNode encode(Criterion criterion, CodecContext context) { 72 public ObjectNode encode(Criterion criterion, CodecContext context) {
...@@ -73,6 +79,4 @@ public final class CriterionCodec extends JsonCodec<Criterion> { ...@@ -73,6 +79,4 @@ public final class CriterionCodec extends JsonCodec<Criterion> {
73 DecodeCriterionCodecHelper decoder = new DecodeCriterionCodecHelper(json); 79 DecodeCriterionCodecHelper decoder = new DecodeCriterionCodecHelper(json);
74 return decoder.decode(); 80 return decoder.decode();
75 } 81 }
76 -
77 -
78 } 82 }
......
...@@ -38,6 +38,8 @@ import org.onosproject.net.flow.criteria.MetadataCriterion; ...@@ -38,6 +38,8 @@ import org.onosproject.net.flow.criteria.MetadataCriterion;
38 import org.onosproject.net.flow.criteria.MplsCriterion; 38 import org.onosproject.net.flow.criteria.MplsCriterion;
39 import org.onosproject.net.flow.criteria.OchSignalCriterion; 39 import org.onosproject.net.flow.criteria.OchSignalCriterion;
40 import org.onosproject.net.flow.criteria.OchSignalTypeCriterion; 40 import org.onosproject.net.flow.criteria.OchSignalTypeCriterion;
41 +import org.onosproject.net.flow.criteria.OduSignalIdCriterion;
42 +import org.onosproject.net.flow.criteria.OduSignalTypeCriterion;
41 import org.onosproject.net.flow.criteria.PortCriterion; 43 import org.onosproject.net.flow.criteria.PortCriterion;
42 import org.onosproject.net.flow.criteria.SctpPortCriterion; 44 import org.onosproject.net.flow.criteria.SctpPortCriterion;
43 import org.onosproject.net.flow.criteria.TcpPortCriterion; 45 import org.onosproject.net.flow.criteria.TcpPortCriterion;
...@@ -108,7 +110,8 @@ public final class EncodeCriterionCodecHelper { ...@@ -108,7 +110,8 @@ public final class EncodeCriterionCodecHelper {
108 formatMap.put(Criterion.Type.OCH_SIGTYPE, new FormatOchSigType()); 110 formatMap.put(Criterion.Type.OCH_SIGTYPE, new FormatOchSigType());
109 formatMap.put(Criterion.Type.TUNNEL_ID, new FormatTunnelId()); 111 formatMap.put(Criterion.Type.TUNNEL_ID, new FormatTunnelId());
110 formatMap.put(Criterion.Type.DUMMY, new FormatDummyType()); 112 formatMap.put(Criterion.Type.DUMMY, new FormatDummyType());
111 - 113 + formatMap.put(Criterion.Type.ODU_SIGID, new FormatOduSignalId());
114 + formatMap.put(Criterion.Type.ODU_SIGTYPE, new FormatOduSignalType());
112 // Currently unimplemented 115 // Currently unimplemented
113 formatMap.put(Criterion.Type.ARP_OP, new FormatUnknown()); 116 formatMap.put(Criterion.Type.ARP_OP, new FormatUnknown());
114 formatMap.put(Criterion.Type.ARP_SPA, new FormatUnknown()); 117 formatMap.put(Criterion.Type.ARP_SPA, new FormatUnknown());
...@@ -351,7 +354,7 @@ public final class EncodeCriterionCodecHelper { ...@@ -351,7 +354,7 @@ public final class EncodeCriterionCodecHelper {
351 public ObjectNode encodeCriterion(ObjectNode root, Criterion criterion) { 354 public ObjectNode encodeCriterion(ObjectNode root, Criterion criterion) {
352 final OchSignalTypeCriterion ochSignalTypeCriterion = 355 final OchSignalTypeCriterion ochSignalTypeCriterion =
353 (OchSignalTypeCriterion) criterion; 356 (OchSignalTypeCriterion) criterion;
354 - return root.put("ochSignalType", ochSignalTypeCriterion.signalType().name()); 357 + return root.put(CriterionCodec.OCH_SIGNAL_TYPE, ochSignalTypeCriterion.signalType().name());
355 } 358 }
356 } 359 }
357 360
...@@ -364,6 +367,24 @@ public final class EncodeCriterionCodecHelper { ...@@ -364,6 +367,24 @@ public final class EncodeCriterionCodecHelper {
364 } 367 }
365 } 368 }
366 369
370 + private static class FormatOduSignalId implements CriterionTypeFormatter {
371 + @Override
372 + public ObjectNode encodeCriterion(ObjectNode root, Criterion criterion) {
373 + final OduSignalIdCriterion oduSignalIdCriterion =
374 + (OduSignalIdCriterion) criterion;
375 + return root.put(CriterionCodec.ODU_SIGNAL_ID, oduSignalIdCriterion.oduSignalId().toString());
376 + }
377 + }
378 +
379 + private static class FormatOduSignalType implements CriterionTypeFormatter {
380 + @Override
381 + public ObjectNode encodeCriterion(ObjectNode root, Criterion criterion) {
382 + final OduSignalTypeCriterion oduSignalTypeCriterion =
383 + (OduSignalTypeCriterion) criterion;
384 + return root.put(CriterionCodec.ODU_SIGNAL_TYPE, oduSignalTypeCriterion.signalType().name());
385 + }
386 + }
387 +
367 private class FormatDummyType implements CriterionTypeFormatter { 388 private class FormatDummyType implements CriterionTypeFormatter {
368 389
369 @Override 390 @Override
......