Ray Milkey | c95bb9d | 2015-01-06 10:28:24 -0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Foundation |
Ray Milkey | c95bb9d | 2015-01-06 10:28:24 -0800 | [diff] [blame] | 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 | */ |
| 16 | package org.onosproject.codec.impl; |
| 17 | |
Jian Li | 1ef82db | 2016-03-03 14:43:21 -0800 | [diff] [blame] | 18 | import com.fasterxml.jackson.databind.node.ObjectNode; |
Ray Milkey | c95bb9d | 2015-01-06 10:28:24 -0800 | [diff] [blame] | 19 | import org.onosproject.codec.CodecContext; |
| 20 | import org.onosproject.codec.JsonCodec; |
| 21 | import org.onosproject.net.flow.instructions.Instruction; |
Ray Milkey | c95bb9d | 2015-01-06 10:28:24 -0800 | [diff] [blame] | 22 | import org.slf4j.Logger; |
| 23 | import org.slf4j.LoggerFactory; |
| 24 | |
Ray Milkey | c95bb9d | 2015-01-06 10:28:24 -0800 | [diff] [blame] | 25 | import static com.google.common.base.Preconditions.checkNotNull; |
| 26 | |
| 27 | /** |
| 28 | * Instruction codec. |
| 29 | */ |
Ray Milkey | 540b2ce | 2015-02-04 17:50:20 -0800 | [diff] [blame] | 30 | public final class InstructionCodec extends JsonCodec<Instruction> { |
Ray Milkey | c95bb9d | 2015-01-06 10:28:24 -0800 | [diff] [blame] | 31 | |
Ray Milkey | 9c9cde4 | 2018-01-12 14:22:06 -0800 | [diff] [blame] | 32 | private static final Logger log = LoggerFactory.getLogger(InstructionCodec.class); |
Ray Milkey | c95bb9d | 2015-01-06 10:28:24 -0800 | [diff] [blame] | 33 | |
Ray Milkey | 9c9cde4 | 2018-01-12 14:22:06 -0800 | [diff] [blame] | 34 | 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 Milkey | c95bb9d | 2015-01-06 10:28:24 -0800 | [diff] [blame] | 67 | |
Frank Wang | 74ce2c1 | 2018-04-11 20:26:45 +0800 | [diff] [blame] | 68 | static final String PI_ACTION_ID = "actionId"; |
| 69 | static final String PI_ACTION_GROUP_ID = "groupId"; |
| 70 | static final String PI_ACTION_GROUP_MEMBER_ID = "memberId"; |
| 71 | static final String PI_ACTION_PARAMS = "actionParams"; |
| 72 | |
Ray Milkey | 9c9cde4 | 2018-01-12 14:22:06 -0800 | [diff] [blame] | 73 | static final String MISSING_MEMBER_MESSAGE = |
Ray Milkey | d43fe45 | 2015-05-29 09:35:12 -0700 | [diff] [blame] | 74 | " member is required in Instruction"; |
Ray Milkey | 9c9cde4 | 2018-01-12 14:22:06 -0800 | [diff] [blame] | 75 | static final String ERROR_MESSAGE = |
Jayasree Ghosh | 8aca677 | 2016-10-04 03:32:11 +0530 | [diff] [blame] | 76 | " not specified in Instruction"; |
Ray Milkey | c95bb9d | 2015-01-06 10:28:24 -0800 | [diff] [blame] | 77 | |
Ray Milkey | c95bb9d | 2015-01-06 10:28:24 -0800 | [diff] [blame] | 78 | |
| 79 | @Override |
| 80 | public ObjectNode encode(Instruction instruction, CodecContext context) { |
| 81 | checkNotNull(instruction, "Instruction cannot be null"); |
| 82 | |
Ray Milkey | 6d7968e | 2015-07-06 14:30:02 -0700 | [diff] [blame] | 83 | return new EncodeInstructionCodecHelper(instruction, context).encode(); |
Ray Milkey | d43fe45 | 2015-05-29 09:35:12 -0700 | [diff] [blame] | 84 | } |
Ray Milkey | c95bb9d | 2015-01-06 10:28:24 -0800 | [diff] [blame] | 85 | |
Ray Milkey | d43fe45 | 2015-05-29 09:35:12 -0700 | [diff] [blame] | 86 | @Override |
| 87 | public Instruction decode(ObjectNode json, CodecContext context) { |
| 88 | if (json == null || !json.isObject()) { |
| 89 | return null; |
Ray Milkey | c95bb9d | 2015-01-06 10:28:24 -0800 | [diff] [blame] | 90 | } |
Ray Milkey | d43fe45 | 2015-05-29 09:35:12 -0700 | [diff] [blame] | 91 | |
Jonathan Hart | e3bcfc3 | 2016-08-16 17:12:49 -0700 | [diff] [blame] | 92 | return new DecodeInstructionCodecHelper(json, context).decode(); |
Ray Milkey | c95bb9d | 2015-01-06 10:28:24 -0800 | [diff] [blame] | 93 | } |
| 94 | } |