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