Sho SHIMIZU
Committed by Gerrit Code Review

Support ModOchSignalInstruction in InstructionCodec

Resolve ONOS-1875

Change-Id: I63e10aeb4689991bfb5c6df349843ef5aff4d6f7
...@@ -17,6 +17,7 @@ package org.onosproject.codec.impl; ...@@ -17,6 +17,7 @@ package org.onosproject.codec.impl;
17 17
18 import org.onosproject.codec.CodecContext; 18 import org.onosproject.codec.CodecContext;
19 import org.onosproject.codec.JsonCodec; 19 import org.onosproject.codec.JsonCodec;
20 +import org.onosproject.net.OchSignal;
20 import org.onosproject.net.flow.instructions.Instruction; 21 import org.onosproject.net.flow.instructions.Instruction;
21 import org.onosproject.net.flow.instructions.Instructions; 22 import org.onosproject.net.flow.instructions.Instructions;
22 import org.onosproject.net.flow.instructions.L0ModificationInstruction; 23 import org.onosproject.net.flow.instructions.L0ModificationInstruction;
...@@ -52,6 +53,16 @@ public final class InstructionCodec extends JsonCodec<Instruction> { ...@@ -52,6 +53,16 @@ public final class InstructionCodec extends JsonCodec<Instruction> {
52 result.put("lambda", modLambdaInstruction.lambda()); 53 result.put("lambda", modLambdaInstruction.lambda());
53 break; 54 break;
54 55
56 + case OCH:
57 + L0ModificationInstruction.ModOchSignalInstruction ochSignalInstruction =
58 + (L0ModificationInstruction.ModOchSignalInstruction) instruction;
59 + OchSignal ochSignal = ochSignalInstruction.lambda();
60 + result.put("gridType", ochSignal.gridType().name());
61 + result.put("channelSpacing", ochSignal.channelSpacing().name());
62 + result.put("spacingMultiplier", ochSignal.spacingMultiplier());
63 + result.put("slotGranularity", ochSignal.slotGranularity());
64 + break;
65 +
55 default: 66 default:
56 log.info("Cannot convert L0 subtype of {}", instruction.subtype()); 67 log.info("Cannot convert L0 subtype of {}", instruction.subtype());
57 } 68 }
......
...@@ -24,6 +24,9 @@ import org.onlab.packet.MplsLabel; ...@@ -24,6 +24,9 @@ import org.onlab.packet.MplsLabel;
24 import org.onlab.packet.VlanId; 24 import org.onlab.packet.VlanId;
25 import org.onosproject.codec.CodecContext; 25 import org.onosproject.codec.CodecContext;
26 import org.onosproject.codec.JsonCodec; 26 import org.onosproject.codec.JsonCodec;
27 +import org.onosproject.net.ChannelSpacing;
28 +import org.onosproject.net.GridType;
29 +import org.onosproject.net.Lambda;
27 import org.onosproject.net.PortNumber; 30 import org.onosproject.net.PortNumber;
28 import org.onosproject.net.flow.instructions.Instruction; 31 import org.onosproject.net.flow.instructions.Instruction;
29 import org.onosproject.net.flow.instructions.Instructions; 32 import org.onosproject.net.flow.instructions.Instructions;
...@@ -105,6 +108,19 @@ public class InstructionCodecTest { ...@@ -105,6 +108,19 @@ public class InstructionCodecTest {
105 } 108 }
106 109
107 /** 110 /**
111 + * Tests the encoding of mod OCh signal instructions.
112 + */
113 + @Test
114 + public void modOchSignalInstructionTest() {
115 + L0ModificationInstruction.ModOchSignalInstruction instruction =
116 + (L0ModificationInstruction.ModOchSignalInstruction)
117 + Instructions.modL0Lambda(Lambda.ochSignal(GridType.DWDM, ChannelSpacing.CHL_100GHZ, 4, 8));
118 + ObjectNode instructionJson =
119 + instructionCodec.encode(instruction, context);
120 + assertThat(instructionJson, matchesInstruction(instruction));
121 + }
122 +
123 + /**
108 * Tests the encoding of mod ether instructions. 124 * Tests the encoding of mod ether instructions.
109 */ 125 */
110 @Test 126 @Test
......
...@@ -133,6 +133,57 @@ public final class InstructionJsonMatcher extends TypeSafeDiagnosingMatcher<Json ...@@ -133,6 +133,57 @@ public final class InstructionJsonMatcher extends TypeSafeDiagnosingMatcher<Json
133 } 133 }
134 134
135 /** 135 /**
136 + * Matches teh contents of a mod OCh singal instruction.
137 + *
138 + * @param instructionJson JSON instruction to match
139 + * @param description Description object used for recording errors
140 + * @return true if contents matches, false otherwise
141 + */
142 + private boolean matchModOchSingalInstruction(JsonNode instructionJson,
143 + Description description) {
144 + ModOchSignalInstruction instructionToMatch =
145 + (ModOchSignalInstruction) instruction;
146 +
147 + String jsonSubType = instructionJson.get("subtype").textValue();
148 + if (!instructionToMatch.subtype().name().equals(jsonSubType)) {
149 + description.appendText("subtype was " + jsonSubType);
150 + return false;
151 + }
152 +
153 + String jsonType = instructionJson.get("type").textValue();
154 + if (!instructionToMatch.type().name().equals(jsonType)) {
155 + description.appendText("type was " + jsonType);
156 + return false;
157 + }
158 +
159 + String jsonGridType = instructionJson.get("gridType").textValue();
160 + if (!instructionToMatch.lambda().gridType().name().equals(jsonGridType)) {
161 + description.appendText("gridType was " + jsonGridType);
162 + return false;
163 + }
164 +
165 + String jsonChannelSpacing = instructionJson.get("channelSpacing").textValue();
166 + if (!instructionToMatch.lambda().channelSpacing().name().equals(jsonChannelSpacing)) {
167 + description.appendText("channelSpacing was " + jsonChannelSpacing);
168 + return false;
169 + }
170 +
171 + int jsonSpacingMultiplier = instructionJson.get("spacingMultiplier").intValue();
172 + if (instructionToMatch.lambda().spacingMultiplier() != jsonSpacingMultiplier) {
173 + description.appendText("spacingMultiplier was " + jsonSpacingMultiplier);
174 + return false;
175 + }
176 +
177 + int jsonSlotGranularity = instructionJson.get("slotGranularity").intValue();
178 + if (instructionToMatch.lambda().slotGranularity() != jsonSlotGranularity) {
179 + description.appendText("slotGranularity was " + jsonSlotGranularity);
180 + return false;
181 + }
182 +
183 + return true;
184 + }
185 +
186 + /**
136 * Matches the contents of a mod Ethernet instruction. 187 * Matches the contents of a mod Ethernet instruction.
137 * 188 *
138 * @param instructionJson JSON instruction to match 189 * @param instructionJson JSON instruction to match
...@@ -350,6 +401,8 @@ public final class InstructionJsonMatcher extends TypeSafeDiagnosingMatcher<Json ...@@ -350,6 +401,8 @@ public final class InstructionJsonMatcher extends TypeSafeDiagnosingMatcher<Json
350 return matchOutputInstruction(jsonInstruction, description); 401 return matchOutputInstruction(jsonInstruction, description);
351 } else if (instruction instanceof ModLambdaInstruction) { 402 } else if (instruction instanceof ModLambdaInstruction) {
352 return matchModLambdaInstruction(jsonInstruction, description); 403 return matchModLambdaInstruction(jsonInstruction, description);
404 + } else if (instruction instanceof ModOchSignalInstruction) {
405 + return matchModOchSingalInstruction(jsonInstruction, description);
353 } else if (instruction instanceof ModEtherInstruction) { 406 } else if (instruction instanceof ModEtherInstruction) {
354 return matchModEtherInstruction(jsonInstruction, description); 407 return matchModEtherInstruction(jsonInstruction, description);
355 } else if (instruction instanceof ModVlanIdInstruction) { 408 } else if (instruction instanceof ModVlanIdInstruction) {
......