blob: ab609098c35ad92e3ec708faf92731684e7ee897 [file] [log] [blame]
Ray Milkeyc95bb9d2015-01-06 10:28:24 -08001/*
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 */
16package org.onosproject.codec.impl;
17
Jian Li1ef82db2016-03-03 14:43:21 -080018import com.fasterxml.jackson.databind.node.ObjectNode;
Ray Milkeyc95bb9d2015-01-06 10:28:24 -080019import org.onosproject.codec.CodecContext;
20import org.onosproject.codec.JsonCodec;
21import org.onosproject.net.flow.instructions.Instruction;
Ray Milkeyc95bb9d2015-01-06 10:28:24 -080022import org.slf4j.Logger;
23import org.slf4j.LoggerFactory;
24
Ray Milkeyc95bb9d2015-01-06 10:28:24 -080025import static com.google.common.base.Preconditions.checkNotNull;
26
27/**
28 * Instruction codec.
29 */
Ray Milkey540b2ce2015-02-04 17:50:20 -080030public final class InstructionCodec extends JsonCodec<Instruction> {
Ray Milkeyc95bb9d2015-01-06 10:28:24 -080031
32 protected static final Logger log = LoggerFactory.getLogger(InstructionCodec.class);
33
Ray Milkeyd43fe452015-05-29 09:35:12 -070034 protected static final String TYPE = "type";
35 protected static final String SUBTYPE = "subtype";
36 protected static final String PORT = "port";
37 protected static final String MAC = "mac";
38 protected static final String VLAN_ID = "vlanId";
39 protected static final String VLAN_PCP = "vlanPcp";
40 protected static final String MPLS_LABEL = "label";
41 protected static final String IP = "ip";
42 protected static final String FLOW_LABEL = "flowLabel";
43 protected static final String LAMBDA = "lambda";
44 protected static final String GRID_TYPE = "gridType";
45 protected static final String CHANNEL_SPACING = "channelSpacing";
46 protected static final String SPACING_MULTIPLIER = "spacingMultiplier";
47 protected static final String SLOT_GRANULARITY = "slotGranularity";
48 protected static final String ETHERNET_TYPE = "ethernetType";
Hyunsun Moon7080a0d2015-08-14 19:18:48 -070049 protected static final String TUNNEL_ID = "tunnelId";
Hyunsun Moonfab29502015-08-25 13:39:16 -070050 protected static final String TCP_PORT = "tcpPort";
51 protected static final String UDP_PORT = "udpPort";
Jian Li1ef82db2016-03-03 14:43:21 -080052 protected static final String TABLE_ID = "tableId";
Jian Lice8c5602016-03-03 21:43:24 -080053 protected static final String GROUP_ID = "groupId";
Yafit Hadar5796d972015-10-15 13:16:11 +030054 protected static final String TRIBUTARY_PORT_NUMBER = "tributaryPortNumber";
55 protected static final String TRIBUTARY_SLOT_LEN = "tributarySlotLength";
56 protected static final String TRIBUTARY_SLOT_BITMAP = "tributarySlotBitmap";
Ray Milkeyc95bb9d2015-01-06 10:28:24 -080057
Ray Milkeyd43fe452015-05-29 09:35:12 -070058 protected static final String MISSING_MEMBER_MESSAGE =
59 " member is required in Instruction";
Ray Milkeyc95bb9d2015-01-06 10:28:24 -080060
Ray Milkeyc95bb9d2015-01-06 10:28:24 -080061
62 @Override
63 public ObjectNode encode(Instruction instruction, CodecContext context) {
64 checkNotNull(instruction, "Instruction cannot be null");
65
Ray Milkey6d7968e2015-07-06 14:30:02 -070066 return new EncodeInstructionCodecHelper(instruction, context).encode();
Ray Milkeyd43fe452015-05-29 09:35:12 -070067 }
Ray Milkeyc95bb9d2015-01-06 10:28:24 -080068
Ray Milkeyd43fe452015-05-29 09:35:12 -070069 @Override
70 public Instruction decode(ObjectNode json, CodecContext context) {
71 if (json == null || !json.isObject()) {
72 return null;
Ray Milkeyc95bb9d2015-01-06 10:28:24 -080073 }
Ray Milkeyd43fe452015-05-29 09:35:12 -070074
Ray Milkey6d7968e2015-07-06 14:30:02 -070075 return new DecodeInstructionCodecHelper(json).decode();
Ray Milkeyc95bb9d2015-01-06 10:28:24 -080076 }
77}