Ray Milkey | c95bb9d | 2015-01-06 10:28:24 -0800 | [diff] [blame] | 1 | /* |
| 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 | */ |
| 16 | package org.onosproject.codec.impl; |
| 17 | |
Ray Milkey | c95bb9d | 2015-01-06 10:28:24 -0800 | [diff] [blame] | 18 | import org.onosproject.codec.CodecContext; |
| 19 | import org.onosproject.codec.JsonCodec; |
| 20 | import org.onosproject.net.flow.instructions.Instruction; |
Ray Milkey | c95bb9d | 2015-01-06 10:28:24 -0800 | [diff] [blame] | 21 | import org.slf4j.Logger; |
| 22 | import org.slf4j.LoggerFactory; |
| 23 | |
| 24 | import com.fasterxml.jackson.databind.node.ObjectNode; |
| 25 | |
| 26 | import static com.google.common.base.Preconditions.checkNotNull; |
| 27 | |
| 28 | /** |
| 29 | * Instruction codec. |
| 30 | */ |
Ray Milkey | 540b2ce | 2015-02-04 17:50:20 -0800 | [diff] [blame] | 31 | public final class InstructionCodec extends JsonCodec<Instruction> { |
Ray Milkey | c95bb9d | 2015-01-06 10:28:24 -0800 | [diff] [blame] | 32 | |
| 33 | protected static final Logger log = LoggerFactory.getLogger(InstructionCodec.class); |
| 34 | |
Ray Milkey | d43fe45 | 2015-05-29 09:35:12 -0700 | [diff] [blame] | 35 | protected static final String TYPE = "type"; |
| 36 | protected static final String SUBTYPE = "subtype"; |
| 37 | protected static final String PORT = "port"; |
| 38 | protected static final String MAC = "mac"; |
| 39 | protected static final String VLAN_ID = "vlanId"; |
| 40 | protected static final String VLAN_PCP = "vlanPcp"; |
| 41 | protected static final String MPLS_LABEL = "label"; |
| 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"; |
Yafit Hadar | 5796d97 | 2015-10-15 13:16:11 +0300 | [diff] [blame] | 53 | protected static final String TRIBUTARY_PORT_NUMBER = "tributaryPortNumber"; |
| 54 | protected static final String TRIBUTARY_SLOT_LEN = "tributarySlotLength"; |
| 55 | protected static final String TRIBUTARY_SLOT_BITMAP = "tributarySlotBitmap"; |
Ray Milkey | c95bb9d | 2015-01-06 10:28:24 -0800 | [diff] [blame] | 56 | |
Ray Milkey | d43fe45 | 2015-05-29 09:35:12 -0700 | [diff] [blame] | 57 | protected static final String MISSING_MEMBER_MESSAGE = |
| 58 | " member is required in Instruction"; |
Ray Milkey | c95bb9d | 2015-01-06 10:28:24 -0800 | [diff] [blame] | 59 | |
Ray Milkey | c95bb9d | 2015-01-06 10:28:24 -0800 | [diff] [blame] | 60 | |
| 61 | @Override |
| 62 | public ObjectNode encode(Instruction instruction, CodecContext context) { |
| 63 | checkNotNull(instruction, "Instruction cannot be null"); |
| 64 | |
Ray Milkey | 6d7968e | 2015-07-06 14:30:02 -0700 | [diff] [blame] | 65 | return new EncodeInstructionCodecHelper(instruction, context).encode(); |
Ray Milkey | d43fe45 | 2015-05-29 09:35:12 -0700 | [diff] [blame] | 66 | } |
Ray Milkey | c95bb9d | 2015-01-06 10:28:24 -0800 | [diff] [blame] | 67 | |
Ray Milkey | d43fe45 | 2015-05-29 09:35:12 -0700 | [diff] [blame] | 68 | @Override |
| 69 | public Instruction decode(ObjectNode json, CodecContext context) { |
| 70 | if (json == null || !json.isObject()) { |
| 71 | return null; |
Ray Milkey | c95bb9d | 2015-01-06 10:28:24 -0800 | [diff] [blame] | 72 | } |
Ray Milkey | d43fe45 | 2015-05-29 09:35:12 -0700 | [diff] [blame] | 73 | |
Ray Milkey | 6d7968e | 2015-07-06 14:30:02 -0700 | [diff] [blame] | 74 | return new DecodeInstructionCodecHelper(json).decode(); |
Ray Milkey | c95bb9d | 2015-01-06 10:28:24 -0800 | [diff] [blame] | 75 | } |
| 76 | } |