Ray Milkey | c95bb9d | 2015-01-06 10:28:24 -0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Laboratory |
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 | |
| 32 | protected static final Logger log = LoggerFactory.getLogger(InstructionCodec.class); |
| 33 | |
Ray Milkey | d43fe45 | 2015-05-29 09:35:12 -0700 | [diff] [blame] | 34 | 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 Chan | fbaabae | 2016-03-18 10:44:44 -0700 | [diff] [blame] | 41 | protected static final String MPLS_BOS = "bos"; |
Ray Milkey | d43fe45 | 2015-05-29 09:35:12 -0700 | [diff] [blame] | 42 | 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 Moon | 7080a0d | 2015-08-14 19:18:48 -0700 | [diff] [blame] | 50 | protected static final String TUNNEL_ID = "tunnelId"; |
Hyunsun Moon | fab2950 | 2015-08-25 13:39:16 -0700 | [diff] [blame] | 51 | protected static final String TCP_PORT = "tcpPort"; |
| 52 | protected static final String UDP_PORT = "udpPort"; |
Jian Li | 1ef82db | 2016-03-03 14:43:21 -0800 | [diff] [blame] | 53 | protected static final String TABLE_ID = "tableId"; |
Jian Li | ce8c560 | 2016-03-03 21:43:24 -0800 | [diff] [blame] | 54 | protected static final String GROUP_ID = "groupId"; |
Jian Li | 47b2623 | 2016-03-07 09:59:59 -0800 | [diff] [blame] | 55 | protected static final String METER_ID = "meterId"; |
Jian Li | 70dffe4 | 2016-03-08 22:23:02 -0800 | [diff] [blame] | 56 | protected static final String QUEUE_ID = "queueId"; |
Yafit Hadar | 5796d97 | 2015-10-15 13:16:11 +0300 | [diff] [blame] | 57 | 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"; |
Ray Milkey | c95bb9d | 2015-01-06 10:28:24 -0800 | [diff] [blame] | 60 | |
Ray Milkey | d43fe45 | 2015-05-29 09:35:12 -0700 | [diff] [blame] | 61 | protected static final String MISSING_MEMBER_MESSAGE = |
| 62 | " member is required in Instruction"; |
Ray Milkey | c95bb9d | 2015-01-06 10:28:24 -0800 | [diff] [blame] | 63 | |
Ray Milkey | c95bb9d | 2015-01-06 10:28:24 -0800 | [diff] [blame] | 64 | |
| 65 | @Override |
| 66 | public ObjectNode encode(Instruction instruction, CodecContext context) { |
| 67 | checkNotNull(instruction, "Instruction cannot be null"); |
| 68 | |
Ray Milkey | 6d7968e | 2015-07-06 14:30:02 -0700 | [diff] [blame] | 69 | return new EncodeInstructionCodecHelper(instruction, context).encode(); |
Ray Milkey | d43fe45 | 2015-05-29 09:35:12 -0700 | [diff] [blame] | 70 | } |
Ray Milkey | c95bb9d | 2015-01-06 10:28:24 -0800 | [diff] [blame] | 71 | |
Ray Milkey | d43fe45 | 2015-05-29 09:35:12 -0700 | [diff] [blame] | 72 | @Override |
| 73 | public Instruction decode(ObjectNode json, CodecContext context) { |
| 74 | if (json == null || !json.isObject()) { |
| 75 | return null; |
Ray Milkey | c95bb9d | 2015-01-06 10:28:24 -0800 | [diff] [blame] | 76 | } |
Ray Milkey | d43fe45 | 2015-05-29 09:35:12 -0700 | [diff] [blame] | 77 | |
Ray Milkey | 6d7968e | 2015-07-06 14:30:02 -0700 | [diff] [blame] | 78 | return new DecodeInstructionCodecHelper(json).decode(); |
Ray Milkey | c95bb9d | 2015-01-06 10:28:24 -0800 | [diff] [blame] | 79 | } |
| 80 | } |