Frank Wang | 72c5e43 | 2016-09-23 17:20:49 +0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Foundation |
Frank Wang | 72c5e43 | 2016-09-23 17:20:49 +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 | |
| 17 | package org.onosproject.net.flow.instructions; |
| 18 | |
| 19 | import com.google.common.base.MoreObjects; |
| 20 | import org.onosproject.net.flow.AbstractExtension; |
| 21 | import java.util.Arrays; |
Frank Wang | 72c5e43 | 2016-09-23 17:20:49 +0800 | [diff] [blame] | 22 | |
| 23 | /** |
| 24 | * Unresolved extension treatment. |
| 25 | */ |
| 26 | public class UnresolvedExtensionTreatment extends AbstractExtension implements ExtensionTreatment { |
| 27 | |
| 28 | private byte[] bytes; |
| 29 | private ExtensionTreatmentType unresolvedTreatmentType; |
| 30 | |
| 31 | /** |
| 32 | * Creates a new unresolved extension treatment with given data in byte form. |
| 33 | * |
Ray Milkey | ef79434 | 2016-11-09 16:20:29 -0800 | [diff] [blame] | 34 | * @param arraybyte byte data for treatment |
Frank Wang | 72c5e43 | 2016-09-23 17:20:49 +0800 | [diff] [blame] | 35 | * @param type unresolved extension data type |
| 36 | */ |
| 37 | public UnresolvedExtensionTreatment(byte[] arraybyte, ExtensionTreatmentType type) { |
| 38 | this.bytes = arraybyte; |
| 39 | this.unresolvedTreatmentType = type; |
| 40 | } |
| 41 | |
| 42 | @Override |
| 43 | public ExtensionTreatmentType type() { |
jaegonkim | 598e8b8 | 2018-02-16 19:24:40 +0900 | [diff] [blame] | 44 | return unresolvedTreatmentType; |
Frank Wang | 72c5e43 | 2016-09-23 17:20:49 +0800 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | @Override |
| 48 | public void deserialize(byte[] data) { |
| 49 | bytes = data; |
| 50 | } |
| 51 | |
| 52 | @Override |
| 53 | public byte[] serialize() { |
| 54 | return bytes; |
| 55 | } |
| 56 | |
| 57 | @Override |
| 58 | public int hashCode() { |
Yuta HIGUCHI | fbd9ae9 | 2018-01-24 23:39:06 -0800 | [diff] [blame] | 59 | return Arrays.hashCode(bytes); |
Frank Wang | 72c5e43 | 2016-09-23 17:20:49 +0800 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | @Override |
| 63 | public boolean equals(Object obj) { |
| 64 | if (this == obj) { |
| 65 | return true; |
| 66 | } |
| 67 | if (obj instanceof UnresolvedExtensionTreatment) { |
| 68 | UnresolvedExtensionTreatment that = (UnresolvedExtensionTreatment) obj; |
| 69 | return Arrays.equals(bytes, that.bytes); |
| 70 | } |
| 71 | return false; |
| 72 | } |
| 73 | |
| 74 | @Override |
| 75 | public String toString() { |
| 76 | return MoreObjects.toStringHelper(getClass()) |
| 77 | .add("bytes", bytes) |
| 78 | .add("unresolvedTreatmentType", unresolvedTreatmentType) |
| 79 | .toString(); |
| 80 | } |
| 81 | } |