blob: 9da240d58aa45db3e3c9cfd4f8c9faed94e0ae80 [file] [log] [blame]
Ray Milkeyc95bb9d2015-01-06 10:28:24 -08001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
Ray Milkeyc95bb9d2015-01-06 10:28:24 -08003 *
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";
Charles Chanfbaabae2016-03-18 10:44:44 -070041 protected static final String MPLS_BOS = "bos";
Ray Milkeyd43fe452015-05-29 09:35:12 -070042 protected static final String IP = "ip";
43 protected static final String FLOW_LABEL = "flowLabel";
44 protected static final String LAMBDA = "lambda";
45 protected static final String GRID_TYPE = "gridType";
46 protected static final String CHANNEL_SPACING = "channelSpacing";
47 protected static final String SPACING_MULTIPLIER = "spacingMultiplier";
48 protected static final String SLOT_GRANULARITY = "slotGranularity";
49 protected static final String ETHERNET_TYPE = "ethernetType";
Hyunsun Moon7080a0d2015-08-14 19:18:48 -070050 protected static final String TUNNEL_ID = "tunnelId";
Hyunsun Moonfab29502015-08-25 13:39:16 -070051 protected static final String TCP_PORT = "tcpPort";
52 protected static final String UDP_PORT = "udpPort";
Jian Li1ef82db2016-03-03 14:43:21 -080053 protected static final String TABLE_ID = "tableId";
Jian Lice8c5602016-03-03 21:43:24 -080054 protected static final String GROUP_ID = "groupId";
Jian Li47b26232016-03-07 09:59:59 -080055 protected static final String METER_ID = "meterId";
Jian Li70dffe42016-03-08 22:23:02 -080056 protected static final String QUEUE_ID = "queueId";
Yafit Hadar5796d972015-10-15 13:16:11 +030057 protected static final String TRIBUTARY_PORT_NUMBER = "tributaryPortNumber";
58 protected static final String TRIBUTARY_SLOT_LEN = "tributarySlotLength";
59 protected static final String TRIBUTARY_SLOT_BITMAP = "tributarySlotBitmap";
Jian Lidab72562016-04-12 14:10:32 -070060 protected static final String EXTENSION = "extension";
61 protected static final String DEVICE_ID = "deviceId";
Ray Milkeyc95bb9d2015-01-06 10:28:24 -080062
Ray Milkeyd43fe452015-05-29 09:35:12 -070063 protected static final String MISSING_MEMBER_MESSAGE =
64 " member is required in Instruction";
Ray Milkeyc95bb9d2015-01-06 10:28:24 -080065
Ray Milkeyc95bb9d2015-01-06 10:28:24 -080066
67 @Override
68 public ObjectNode encode(Instruction instruction, CodecContext context) {
69 checkNotNull(instruction, "Instruction cannot be null");
70
Ray Milkey6d7968e2015-07-06 14:30:02 -070071 return new EncodeInstructionCodecHelper(instruction, context).encode();
Ray Milkeyd43fe452015-05-29 09:35:12 -070072 }
Ray Milkeyc95bb9d2015-01-06 10:28:24 -080073
Ray Milkeyd43fe452015-05-29 09:35:12 -070074 @Override
75 public Instruction decode(ObjectNode json, CodecContext context) {
76 if (json == null || !json.isObject()) {
77 return null;
Ray Milkeyc95bb9d2015-01-06 10:28:24 -080078 }
Ray Milkeyd43fe452015-05-29 09:35:12 -070079
Jonathan Harte3bcfc32016-08-16 17:12:49 -070080 return new DecodeInstructionCodecHelper(json, context).decode();
Ray Milkeyc95bb9d2015-01-06 10:28:24 -080081 }
82}