blob: df7ff1c642906dd5b6604c9c8b8ed057314622ae [file] [log] [blame]
Ray Milkeyc95bb9d2015-01-06 10:28:24 -08001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2015-present Open Networking Foundation
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
Ray Milkey9c9cde42018-01-12 14:22:06 -080032 private static final Logger log = LoggerFactory.getLogger(InstructionCodec.class);
Ray Milkeyc95bb9d2015-01-06 10:28:24 -080033
Ray Milkey9c9cde42018-01-12 14:22:06 -080034 static final String TYPE = "type";
35 static final String SUBTYPE = "subtype";
36 static final String PORT = "port";
37 static final String MAC = "mac";
38 static final String VLAN_ID = "vlanId";
39 static final String VLAN_PCP = "vlanPcp";
40 static final String MPLS_LABEL = "label";
41 static final String MPLS_BOS = "bos";
42 static final String IP = "ip";
43 static final String FLOW_LABEL = "flowLabel";
44 static final String LAMBDA = "lambda";
45 static final String GRID_TYPE = "gridType";
46 static final String CHANNEL_SPACING = "channelSpacing";
47 static final String SPACING_MULTIPLIER = "spacingMultiplier";
48 static final String SLOT_GRANULARITY = "slotGranularity";
49 static final String ETHERNET_TYPE = "ethernetType";
50 static final String TUNNEL_ID = "tunnelId";
51 static final String TCP_PORT = "tcpPort";
52 static final String UDP_PORT = "udpPort";
53 static final String TABLE_ID = "tableId";
54 static final String GROUP_ID = "groupId";
55 static final String METER_ID = "meterId";
56 static final String QUEUE_ID = "queueId";
57 static final String TRIBUTARY_PORT_NUMBER = "tributaryPortNumber";
58 static final String TRIBUTARY_SLOT_LEN = "tributarySlotLength";
59 static final String TRIBUTARY_SLOT_BITMAP = "tributarySlotBitmap";
60 static final String EXTENSION = "extension";
61 static final String DEVICE_ID = "deviceId";
62 static final String STAT_TRIGGER_FLAG = "statTriggerFlag";
63 static final String STAT_THRESHOLDS = "statThreshold";
64 static final String STAT_BYTE_COUNT = "byteCount";
65 static final String STAT_PACKET_COUNT = "packetCount";
66 static final String STAT_DURATION = "duration";
Ray Milkeyc95bb9d2015-01-06 10:28:24 -080067
Frank Wang74ce2c12018-04-11 20:26:45 +080068 static final String PI_ACTION_ID = "actionId";
Carmelo Casconecb4327a2018-09-11 15:17:23 -070069 static final String PI_ACTION_PROFILE_GROUP_ID = "groupId";
70 static final String PI_ACTION_PROFILE_MEMBER_ID = "memberId";
Frank Wang74ce2c12018-04-11 20:26:45 +080071 static final String PI_ACTION_PARAMS = "actionParams";
72
Ray Milkey9c9cde42018-01-12 14:22:06 -080073 static final String MISSING_MEMBER_MESSAGE =
Ray Milkeyd43fe452015-05-29 09:35:12 -070074 " member is required in Instruction";
Ray Milkey9c9cde42018-01-12 14:22:06 -080075 static final String ERROR_MESSAGE =
Jayasree Ghosh8aca6772016-10-04 03:32:11 +053076 " not specified in Instruction";
Ray Milkeyc95bb9d2015-01-06 10:28:24 -080077
Ray Milkeyc95bb9d2015-01-06 10:28:24 -080078
79 @Override
80 public ObjectNode encode(Instruction instruction, CodecContext context) {
81 checkNotNull(instruction, "Instruction cannot be null");
82
Ray Milkey6d7968e2015-07-06 14:30:02 -070083 return new EncodeInstructionCodecHelper(instruction, context).encode();
Ray Milkeyd43fe452015-05-29 09:35:12 -070084 }
Ray Milkeyc95bb9d2015-01-06 10:28:24 -080085
Ray Milkeyd43fe452015-05-29 09:35:12 -070086 @Override
87 public Instruction decode(ObjectNode json, CodecContext context) {
88 if (json == null || !json.isObject()) {
89 return null;
Ray Milkeyc95bb9d2015-01-06 10:28:24 -080090 }
Ray Milkeyd43fe452015-05-29 09:35:12 -070091
Jonathan Harte3bcfc32016-08-16 17:12:49 -070092 return new DecodeInstructionCodecHelper(json, context).decode();
Ray Milkeyc95bb9d2015-01-06 10:28:24 -080093 }
94}