blob: fd8bd747b3e6343ed29409a5b443e7135690689d [file] [log] [blame]
Ray Milkeyd43fe452015-05-29 09:35:12 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
Ray Milkeyd43fe452015-05-29 09:35:12 -07003 *
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 */
16package org.onosproject.codec.impl;
17
Jian Lidab72562016-04-12 14:10:32 -070018import com.fasterxml.jackson.databind.JsonNode;
Jian Li1ef82db2016-03-03 14:43:21 -080019import com.fasterxml.jackson.databind.node.ObjectNode;
Jian Lidab72562016-04-12 14:10:32 -070020import org.onlab.osgi.DefaultServiceDirectory;
21import org.onlab.osgi.ServiceDirectory;
Konstantinos Kanonakis9215ff22016-11-04 13:28:11 -050022import org.onlab.packet.EthType;
Ray Milkeyd43fe452015-05-29 09:35:12 -070023import org.onlab.packet.IpAddress;
24import org.onlab.packet.MacAddress;
25import org.onlab.packet.MplsLabel;
Hyunsun Moonfab29502015-08-25 13:39:16 -070026import org.onlab.packet.TpPort;
Ray Milkeyd43fe452015-05-29 09:35:12 -070027import org.onlab.packet.VlanId;
Yafit Hadar5796d972015-10-15 13:16:11 +030028import org.onlab.util.HexString;
Jonathan Harte3bcfc32016-08-16 17:12:49 -070029import org.onosproject.codec.CodecContext;
Jian Lidab72562016-04-12 14:10:32 -070030import org.onosproject.codec.ExtensionTreatmentCodec;
Jian Lice8c5602016-03-03 21:43:24 -080031import org.onosproject.core.DefaultGroupId;
32import org.onosproject.core.GroupId;
Ray Milkeyd43fe452015-05-29 09:35:12 -070033import org.onosproject.net.ChannelSpacing;
Jian Lidab72562016-04-12 14:10:32 -070034import org.onosproject.net.Device;
35import org.onosproject.net.DeviceId;
Ray Milkeyd43fe452015-05-29 09:35:12 -070036import org.onosproject.net.GridType;
Ray Milkeyd43fe452015-05-29 09:35:12 -070037import org.onosproject.net.OchSignal;
Yafit Hadar5796d972015-10-15 13:16:11 +030038import org.onosproject.net.OduSignalId;
Ray Milkeyd43fe452015-05-29 09:35:12 -070039import org.onosproject.net.PortNumber;
Jian Lidab72562016-04-12 14:10:32 -070040import org.onosproject.net.device.DeviceService;
41import org.onosproject.net.flow.instructions.ExtensionTreatment;
Ray Milkeyd43fe452015-05-29 09:35:12 -070042import org.onosproject.net.flow.instructions.Instruction;
43import org.onosproject.net.flow.instructions.Instructions;
44import org.onosproject.net.flow.instructions.L0ModificationInstruction;
Yafit Hadar5796d972015-10-15 13:16:11 +030045import org.onosproject.net.flow.instructions.L1ModificationInstruction;
Ray Milkeyd43fe452015-05-29 09:35:12 -070046import org.onosproject.net.flow.instructions.L2ModificationInstruction;
47import org.onosproject.net.flow.instructions.L3ModificationInstruction;
Hyunsun Moonfab29502015-08-25 13:39:16 -070048import org.onosproject.net.flow.instructions.L4ModificationInstruction;
Jian Li47b26232016-03-07 09:59:59 -080049import org.onosproject.net.meter.MeterId;
Jian Lidab72562016-04-12 14:10:32 -070050import org.slf4j.Logger;
Ray Milkeyd43fe452015-05-29 09:35:12 -070051
Konstantinos Kanonakis9215ff22016-11-04 13:28:11 -050052import java.util.regex.Matcher;
53import java.util.regex.Pattern;
54
Jian Li1ef82db2016-03-03 14:43:21 -080055import static org.onlab.util.Tools.nullIsIllegal;
Jian Lidab72562016-04-12 14:10:32 -070056import static org.slf4j.LoggerFactory.getLogger;
Ray Milkeyd43fe452015-05-29 09:35:12 -070057
58/**
59 * Decoding portion of the instruction codec.
60 */
Ray Milkey6d7968e2015-07-06 14:30:02 -070061public final class DecodeInstructionCodecHelper {
Jian Lidab72562016-04-12 14:10:32 -070062 protected static final Logger log = getLogger(DecodeInstructionCodecHelper.class);
Ray Milkeyd43fe452015-05-29 09:35:12 -070063 private final ObjectNode json;
Jonathan Harte3bcfc32016-08-16 17:12:49 -070064 private final CodecContext context;
Konstantinos Kanonakis9215ff22016-11-04 13:28:11 -050065 private static final Pattern ETHTYPE_PATTERN = Pattern.compile("0x([0-9a-fA-F]{4})");
Ray Milkeyd43fe452015-05-29 09:35:12 -070066
67 /**
68 * Creates a decode instruction codec object.
69 *
70 * @param json JSON object to decode
71 */
Jonathan Harte3bcfc32016-08-16 17:12:49 -070072 public DecodeInstructionCodecHelper(ObjectNode json, CodecContext context) {
Ray Milkeyd43fe452015-05-29 09:35:12 -070073 this.json = json;
Jonathan Harte3bcfc32016-08-16 17:12:49 -070074 this.context = context;
Ray Milkeyd43fe452015-05-29 09:35:12 -070075 }
76
77 /**
78 * Decodes a Layer 2 instruction.
79 *
80 * @return instruction object decoded from the JSON
81 * @throws IllegalArgumentException if the JSON is invalid
82 */
83 private Instruction decodeL2() {
Jayasree Ghosh8aca6772016-10-04 03:32:11 +053084 String subType = nullIsIllegal(json.get(InstructionCodec.SUBTYPE),
85 InstructionCodec.SUBTYPE + InstructionCodec.ERROR_MESSAGE).asText();
Ray Milkeyd43fe452015-05-29 09:35:12 -070086
87 if (subType.equals(L2ModificationInstruction.L2SubType.ETH_SRC.name())) {
88 String mac = nullIsIllegal(json.get(InstructionCodec.MAC),
89 InstructionCodec.MAC + InstructionCodec.MISSING_MEMBER_MESSAGE).asText();
90 return Instructions.modL2Src(MacAddress.valueOf(mac));
91 } else if (subType.equals(L2ModificationInstruction.L2SubType.ETH_DST.name())) {
92 String mac = nullIsIllegal(json.get(InstructionCodec.MAC),
93 InstructionCodec.MAC + InstructionCodec.MISSING_MEMBER_MESSAGE).asText();
94 return Instructions.modL2Dst(MacAddress.valueOf(mac));
95 } else if (subType.equals(L2ModificationInstruction.L2SubType.VLAN_ID.name())) {
96 short vlanId = (short) nullIsIllegal(json.get(InstructionCodec.VLAN_ID),
97 InstructionCodec.VLAN_ID + InstructionCodec.MISSING_MEMBER_MESSAGE).asInt();
98 return Instructions.modVlanId(VlanId.vlanId(vlanId));
99 } else if (subType.equals(L2ModificationInstruction.L2SubType.VLAN_PCP.name())) {
100 byte vlanPcp = (byte) nullIsIllegal(json.get(InstructionCodec.VLAN_PCP),
101 InstructionCodec.VLAN_PCP + InstructionCodec.MISSING_MEMBER_MESSAGE).asInt();
102 return Instructions.modVlanPcp(vlanPcp);
103 } else if (subType.equals(L2ModificationInstruction.L2SubType.MPLS_LABEL.name())) {
104 int label = nullIsIllegal(json.get(InstructionCodec.MPLS_LABEL),
105 InstructionCodec.MPLS_LABEL + InstructionCodec.MISSING_MEMBER_MESSAGE).asInt();
106 return Instructions.modMplsLabel(MplsLabel.mplsLabel(label));
107 } else if (subType.equals(L2ModificationInstruction.L2SubType.MPLS_PUSH.name())) {
108 return Instructions.pushMpls();
109 } else if (subType.equals(L2ModificationInstruction.L2SubType.MPLS_POP.name())) {
110 return Instructions.popMpls();
111 } else if (subType.equals(L2ModificationInstruction.L2SubType.DEC_MPLS_TTL.name())) {
112 return Instructions.decMplsTtl();
113 } else if (subType.equals(L2ModificationInstruction.L2SubType.VLAN_POP.name())) {
114 return Instructions.popVlan();
115 } else if (subType.equals(L2ModificationInstruction.L2SubType.VLAN_PUSH.name())) {
Konstantinos Kanonakis9215ff22016-11-04 13:28:11 -0500116 if (json.has(InstructionCodec.ETHERNET_TYPE)) {
117 return Instructions.pushVlan(getEthType());
118 }
Ray Milkeyd43fe452015-05-29 09:35:12 -0700119 return Instructions.pushVlan();
Hyunsun Moon7080a0d2015-08-14 19:18:48 -0700120 } else if (subType.equals(L2ModificationInstruction.L2SubType.TUNNEL_ID.name())) {
121 long tunnelId = nullIsIllegal(json.get(InstructionCodec.TUNNEL_ID),
122 InstructionCodec.TUNNEL_ID + InstructionCodec.MISSING_MEMBER_MESSAGE).asLong();
123 return Instructions.modTunnelId(tunnelId);
Ray Milkeyd43fe452015-05-29 09:35:12 -0700124 }
125 throw new IllegalArgumentException("L2 Instruction subtype "
126 + subType + " is not supported");
127 }
128
129 /**
130 * Decodes a Layer 3 instruction.
131 *
132 * @return instruction object decoded from the JSON
133 * @throws IllegalArgumentException if the JSON is invalid
134 */
135 private Instruction decodeL3() {
Jayasree Ghosh8aca6772016-10-04 03:32:11 +0530136 String subType = nullIsIllegal(json.get(InstructionCodec.SUBTYPE),
137 InstructionCodec.SUBTYPE + InstructionCodec.ERROR_MESSAGE).asText();
Ray Milkeyd43fe452015-05-29 09:35:12 -0700138
139 if (subType.equals(L3ModificationInstruction.L3SubType.IPV4_SRC.name())) {
140 IpAddress ip = IpAddress.valueOf(nullIsIllegal(json.get(InstructionCodec.IP),
141 InstructionCodec.IP + InstructionCodec.MISSING_MEMBER_MESSAGE).asText());
142 return Instructions.modL3Src(ip);
143 } else if (subType.equals(L3ModificationInstruction.L3SubType.IPV4_DST.name())) {
144 IpAddress ip = IpAddress.valueOf(nullIsIllegal(json.get(InstructionCodec.IP),
145 InstructionCodec.IP + InstructionCodec.MISSING_MEMBER_MESSAGE).asText());
146 return Instructions.modL3Dst(ip);
147 } else if (subType.equals(L3ModificationInstruction.L3SubType.IPV6_SRC.name())) {
148 IpAddress ip = IpAddress.valueOf(nullIsIllegal(json.get(InstructionCodec.IP),
149 InstructionCodec.IP + InstructionCodec.MISSING_MEMBER_MESSAGE).asText());
150 return Instructions.modL3IPv6Src(ip);
151 } else if (subType.equals(L3ModificationInstruction.L3SubType.IPV6_DST.name())) {
152 IpAddress ip = IpAddress.valueOf(nullIsIllegal(json.get(InstructionCodec.IP),
153 InstructionCodec.IP + InstructionCodec.MISSING_MEMBER_MESSAGE).asText());
154 return Instructions.modL3IPv6Dst(ip);
155 } else if (subType.equals(L3ModificationInstruction.L3SubType.IPV6_FLABEL.name())) {
156 int flowLabel = nullIsIllegal(json.get(InstructionCodec.FLOW_LABEL),
157 InstructionCodec.FLOW_LABEL + InstructionCodec.MISSING_MEMBER_MESSAGE).asInt();
158 return Instructions.modL3IPv6FlowLabel(flowLabel);
159 }
160 throw new IllegalArgumentException("L3 Instruction subtype "
161 + subType + " is not supported");
162 }
163
164 /**
165 * Decodes a Layer 0 instruction.
166 *
167 * @return instruction object decoded from the JSON
168 * @throws IllegalArgumentException if the JSON is invalid
169 */
170 private Instruction decodeL0() {
Jayasree Ghosh8aca6772016-10-04 03:32:11 +0530171 String subType = nullIsIllegal(json.get(InstructionCodec.SUBTYPE),
172 InstructionCodec.SUBTYPE + InstructionCodec.ERROR_MESSAGE).asText();
Ray Milkeyd43fe452015-05-29 09:35:12 -0700173
Sho SHIMIZUcc137a92016-03-11 15:10:54 -0800174 if (subType.equals(L0ModificationInstruction.L0SubType.OCH.name())) {
Ray Milkeyd43fe452015-05-29 09:35:12 -0700175 String gridTypeString = nullIsIllegal(json.get(InstructionCodec.GRID_TYPE),
176 InstructionCodec.GRID_TYPE + InstructionCodec.MISSING_MEMBER_MESSAGE).asText();
177 GridType gridType = GridType.valueOf(gridTypeString);
178 if (gridType == null) {
179 throw new IllegalArgumentException("Unknown grid type "
180 + gridTypeString);
181 }
182 String channelSpacingString = nullIsIllegal(json.get(InstructionCodec.CHANNEL_SPACING),
183 InstructionCodec.CHANNEL_SPACING + InstructionCodec.MISSING_MEMBER_MESSAGE).asText();
184 ChannelSpacing channelSpacing = ChannelSpacing.valueOf(channelSpacingString);
185 if (channelSpacing == null) {
186 throw new IllegalArgumentException("Unknown channel spacing "
187 + channelSpacingString);
188 }
189 int spacingMultiplier = nullIsIllegal(json.get(InstructionCodec.SPACING_MULTIPLIER),
190 InstructionCodec.SPACING_MULTIPLIER + InstructionCodec.MISSING_MEMBER_MESSAGE).asInt();
191 int slotGranularity = nullIsIllegal(json.get(InstructionCodec.SLOT_GRANULARITY),
192 InstructionCodec.SLOT_GRANULARITY + InstructionCodec.MISSING_MEMBER_MESSAGE).asInt();
193 return Instructions.modL0Lambda(new OchSignal(gridType, channelSpacing,
194 spacingMultiplier, slotGranularity));
195 }
196 throw new IllegalArgumentException("L0 Instruction subtype "
197 + subType + " is not supported");
198 }
199
200 /**
Yafit Hadar5796d972015-10-15 13:16:11 +0300201 * Decodes a Layer 1 instruction.
202 *
203 * @return instruction object decoded from the JSON
204 * @throws IllegalArgumentException if the JSON is invalid
205 */
206 private Instruction decodeL1() {
Jayasree Ghosh8aca6772016-10-04 03:32:11 +0530207 String subType = nullIsIllegal(json.get(InstructionCodec.SUBTYPE),
208 InstructionCodec.SUBTYPE + InstructionCodec.ERROR_MESSAGE).asText();
Yafit Hadar5796d972015-10-15 13:16:11 +0300209 if (subType.equals(L1ModificationInstruction.L1SubType.ODU_SIGID.name())) {
210 int tributaryPortNumber = nullIsIllegal(json.get(InstructionCodec.TRIBUTARY_PORT_NUMBER),
211 InstructionCodec.TRIBUTARY_PORT_NUMBER + InstructionCodec.MISSING_MEMBER_MESSAGE).asInt();
212 int tributarySlotLen = nullIsIllegal(json.get(InstructionCodec.TRIBUTARY_SLOT_LEN),
213 InstructionCodec.TRIBUTARY_SLOT_LEN + InstructionCodec.MISSING_MEMBER_MESSAGE).asInt();
214 byte[] tributarySlotBitmap = null;
215 tributarySlotBitmap = HexString.fromHexString(
216 nullIsIllegal(json.get(InstructionCodec.TRIBUTARY_SLOT_BITMAP),
217 InstructionCodec.TRIBUTARY_SLOT_BITMAP + InstructionCodec.MISSING_MEMBER_MESSAGE).asText());
218 return Instructions.modL1OduSignalId(OduSignalId.oduSignalId(tributaryPortNumber, tributarySlotLen,
219 tributarySlotBitmap));
220 }
221 throw new IllegalArgumentException("L1 Instruction subtype "
222 + subType + " is not supported");
223 }
224
225 /**
Hyunsun Moonfab29502015-08-25 13:39:16 -0700226 * Decodes a Layer 4 instruction.
227 *
228 * @return instruction object decoded from the JSON
229 * @throws IllegalArgumentException if the JSON is invalid
230 */
231 private Instruction decodeL4() {
Jayasree Ghosh8aca6772016-10-04 03:32:11 +0530232 String subType = nullIsIllegal(json.get(InstructionCodec.SUBTYPE),
233 InstructionCodec.SUBTYPE + InstructionCodec.ERROR_MESSAGE).asText();
Hyunsun Moonfab29502015-08-25 13:39:16 -0700234
235 if (subType.equals(L4ModificationInstruction.L4SubType.TCP_DST.name())) {
236 TpPort tcpPort = TpPort.tpPort(nullIsIllegal(json.get(InstructionCodec.TCP_PORT),
237 InstructionCodec.TCP_PORT + InstructionCodec.MISSING_MEMBER_MESSAGE).asInt());
238 return Instructions.modTcpDst(tcpPort);
239 } else if (subType.equals(L4ModificationInstruction.L4SubType.TCP_SRC.name())) {
240 TpPort tcpPort = TpPort.tpPort(nullIsIllegal(json.get(InstructionCodec.TCP_PORT),
241 InstructionCodec.TCP_PORT + InstructionCodec.MISSING_MEMBER_MESSAGE).asInt());
242 return Instructions.modTcpSrc(tcpPort);
243 } else if (subType.equals(L4ModificationInstruction.L4SubType.UDP_DST.name())) {
244 TpPort udpPort = TpPort.tpPort(nullIsIllegal(json.get(InstructionCodec.UDP_PORT),
245 InstructionCodec.UDP_PORT + InstructionCodec.MISSING_MEMBER_MESSAGE).asInt());
246 return Instructions.modUdpDst(udpPort);
247 } else if (subType.equals(L4ModificationInstruction.L4SubType.UDP_SRC.name())) {
248 TpPort udpPort = TpPort.tpPort(nullIsIllegal(json.get(InstructionCodec.UDP_PORT),
249 InstructionCodec.UDP_PORT + InstructionCodec.MISSING_MEMBER_MESSAGE).asInt());
250 return Instructions.modUdpSrc(udpPort);
251 }
252 throw new IllegalArgumentException("L4 Instruction subtype "
253 + subType + " is not supported");
254 }
255
256 /**
Jian Lidab72562016-04-12 14:10:32 -0700257 * Decodes a extension instruction.
258 *
259 * @return extension treatment
260 */
261 private Instruction decodeExtension() {
262 ObjectNode node = (ObjectNode) json.get(InstructionCodec.EXTENSION);
263 if (node != null) {
264 DeviceId deviceId = getDeviceId();
265
266 ServiceDirectory serviceDirectory = new DefaultServiceDirectory();
267 DeviceService deviceService = serviceDirectory.get(DeviceService.class);
268 Device device = deviceService.getDevice(deviceId);
269
Jonathan Harte3bcfc32016-08-16 17:12:49 -0700270 if (device == null) {
271 throw new IllegalArgumentException("Device not found");
272 }
273
Jian Lidab72562016-04-12 14:10:32 -0700274 if (device.is(ExtensionTreatmentCodec.class)) {
275 ExtensionTreatmentCodec treatmentCodec = device.as(ExtensionTreatmentCodec.class);
Jonathan Harte3bcfc32016-08-16 17:12:49 -0700276 ExtensionTreatment treatment = treatmentCodec.decode(node, context);
Jian Lidab72562016-04-12 14:10:32 -0700277 return Instructions.extension(treatment, deviceId);
278 } else {
Jonathan Harte3bcfc32016-08-16 17:12:49 -0700279 throw new IllegalArgumentException(
280 "There is no codec to decode extension for device " + deviceId.toString());
Jian Lidab72562016-04-12 14:10:32 -0700281 }
282 }
283 return null;
284 }
285
286 /**
287 * Returns device identifier.
288 *
289 * @return device identifier
290 * @throws IllegalArgumentException if the JSON is invalid
291 */
292 private DeviceId getDeviceId() {
293 JsonNode deviceIdNode = json.get(InstructionCodec.DEVICE_ID);
294 if (deviceIdNode != null) {
295 return DeviceId.deviceId(deviceIdNode.asText());
296 }
297 throw new IllegalArgumentException("Empty device identifier");
298 }
299
300 /**
Jian Li70dffe42016-03-08 22:23:02 -0800301 * Extracts port number of the given json node.
302 *
303 * @param jsonNode json node
304 * @return port number
305 */
306 private PortNumber getPortNumber(ObjectNode jsonNode) {
307 PortNumber portNumber;
Jayasree Ghosh8aca6772016-10-04 03:32:11 +0530308 JsonNode portNode = nullIsIllegal(jsonNode.get(InstructionCodec.PORT),
309 InstructionCodec.PORT + InstructionCodec.ERROR_MESSAGE);
310 if (portNode.isLong() || portNode.isInt()) {
311 portNumber = PortNumber.portNumber(portNode.asLong());
312 } else if (portNode.isTextual()) {
313 portNumber = PortNumber.fromString(portNode.textValue());
Jian Li70dffe42016-03-08 22:23:02 -0800314 } else {
315 throw new IllegalArgumentException("Port value "
Jayasree Ghosh8aca6772016-10-04 03:32:11 +0530316 + portNode.toString()
Jian Li70dffe42016-03-08 22:23:02 -0800317 + " is not supported");
318 }
319 return portNumber;
320 }
321
322 /**
Konstantinos Kanonakis9215ff22016-11-04 13:28:11 -0500323 * Returns Ethernet type.
324 *
325 * @return ethernet type
326 * @throws IllegalArgumentException if the JSON is invalid
327 */
328 private EthType getEthType() {
329 String ethTypeStr = nullIsIllegal(json.get(InstructionCodec.ETHERNET_TYPE),
330 InstructionCodec.ETHERNET_TYPE + InstructionCodec.MISSING_MEMBER_MESSAGE).asText();
331 Matcher matcher = ETHTYPE_PATTERN.matcher(ethTypeStr);
332 if (!matcher.matches()) {
333 throw new IllegalArgumentException("ETHERNET_TYPE must be a four digit hex string starting with 0x");
334 }
335 short ethernetType = (short) Integer.parseInt(matcher.group(1), 16);
336 return new EthType(ethernetType);
337 }
338
339 /**
Ray Milkeyd43fe452015-05-29 09:35:12 -0700340 * Decodes the JSON into an instruction object.
341 *
342 * @return Criterion object
343 * @throws IllegalArgumentException if the JSON is invalid
344 */
345 public Instruction decode() {
Jayasree Ghosh8aca6772016-10-04 03:32:11 +0530346 String type = nullIsIllegal(json.get(InstructionCodec.TYPE),
347 InstructionCodec.TYPE + InstructionCodec.ERROR_MESSAGE).asText();
Ray Milkeyd43fe452015-05-29 09:35:12 -0700348
349 if (type.equals(Instruction.Type.OUTPUT.name())) {
Jian Li70dffe42016-03-08 22:23:02 -0800350 return Instructions.createOutput(getPortNumber(json));
Ray Milkey2be39ed2016-02-22 15:54:19 -0800351 } else if (type.equals(Instruction.Type.NOACTION.name())) {
352 return Instructions.createNoAction();
Jian Li1ef82db2016-03-03 14:43:21 -0800353 } else if (type.equals(Instruction.Type.TABLE.name())) {
Jayasree Ghosh8aca6772016-10-04 03:32:11 +0530354 return Instructions.transition(nullIsIllegal(json.get(InstructionCodec.TABLE_ID),
355 InstructionCodec.TABLE_ID + InstructionCodec.MISSING_MEMBER_MESSAGE).asInt());
Jian Lice8c5602016-03-03 21:43:24 -0800356 } else if (type.equals(Instruction.Type.GROUP.name())) {
Jayasree Ghosh8aca6772016-10-04 03:32:11 +0530357 GroupId groupId = new DefaultGroupId(nullIsIllegal(json.get(InstructionCodec.GROUP_ID),
358 InstructionCodec.GROUP_ID + InstructionCodec.MISSING_MEMBER_MESSAGE).asInt());
Jian Lice8c5602016-03-03 21:43:24 -0800359 return Instructions.createGroup(groupId);
Jian Li47b26232016-03-07 09:59:59 -0800360 } else if (type.equals(Instruction.Type.METER.name())) {
Jayasree Ghosh8aca6772016-10-04 03:32:11 +0530361 MeterId meterId = MeterId.meterId(nullIsIllegal(json.get(InstructionCodec.METER_ID),
362 InstructionCodec.METER_ID + InstructionCodec.MISSING_MEMBER_MESSAGE).asLong());
Jian Li47b26232016-03-07 09:59:59 -0800363 return Instructions.meterTraffic(meterId);
Jian Li70dffe42016-03-08 22:23:02 -0800364 } else if (type.equals(Instruction.Type.QUEUE.name())) {
Jayasree Ghosh8aca6772016-10-04 03:32:11 +0530365 long queueId = nullIsIllegal(json.get(InstructionCodec.QUEUE_ID),
366 InstructionCodec.QUEUE_ID + InstructionCodec.MISSING_MEMBER_MESSAGE).asLong();
Jian Li70dffe42016-03-08 22:23:02 -0800367 return Instructions.setQueue(queueId, getPortNumber(json));
Ray Milkeyd43fe452015-05-29 09:35:12 -0700368 } else if (type.equals(Instruction.Type.L0MODIFICATION.name())) {
369 return decodeL0();
Yafit Hadar5796d972015-10-15 13:16:11 +0300370 } else if (type.equals(Instruction.Type.L1MODIFICATION.name())) {
371 return decodeL1();
Ray Milkeyd43fe452015-05-29 09:35:12 -0700372 } else if (type.equals(Instruction.Type.L2MODIFICATION.name())) {
373 return decodeL2();
374 } else if (type.equals(Instruction.Type.L3MODIFICATION.name())) {
375 return decodeL3();
Hyunsun Moonfab29502015-08-25 13:39:16 -0700376 } else if (type.equals(Instruction.Type.L4MODIFICATION.name())) {
377 return decodeL4();
Jian Lidab72562016-04-12 14:10:32 -0700378 } else if (type.equals(Instruction.Type.EXTENSION.name())) {
379 return decodeExtension();
Ray Milkeyd43fe452015-05-29 09:35:12 -0700380 }
381 throw new IllegalArgumentException("Instruction type "
382 + type + " is not supported");
383 }
Ray Milkeyd43fe452015-05-29 09:35:12 -0700384}