blob: 236b77ce9f2d53c5fa578c9a6899962d08f061ec [file] [log] [blame]
Jian Li2c4e9a92017-03-13 16:45:53 +09001/*
2 * Copyright 2016-present 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 */
16package org.onosproject.mapping.addresses;
17
18import org.onosproject.net.flow.AbstractExtension;
19
20import java.util.Arrays;
21import java.util.Objects;
22
23import static com.google.common.base.MoreObjects.toStringHelper;
24import static org.onosproject.mapping.addresses.ExtensionMappingAddressType
25 .ExtensionMappingAddressTypes.UNRESOLVED_TYPE;
26
27/**
28 * Unresolved extension mapping address.
29 */
30public class UnresolvedExtensionMappingAddress extends AbstractExtension
31 implements ExtensionMappingAddress {
32
33 private byte[] bytes;
34 private ExtensionMappingAddressType unresolvedAddressType;
35
36 /**
37 * Creates a new unresolved extension mapping address with given data
38 * in byte form.
39 *
40 * @param arrayByte byte data for the extension mapping address
41 * @param type unresolved extension data type
42 */
43 public UnresolvedExtensionMappingAddress(byte[] arrayByte,
44 ExtensionMappingAddressType type) {
45 this.bytes = arrayByte;
46 this.unresolvedAddressType = type;
47 }
48
49 @Override
50 public ExtensionMappingAddressType type() {
51 return UNRESOLVED_TYPE.type();
52 }
53
54 @Override
55 public byte[] serialize() {
56 return bytes;
57 }
58
59 @Override
60 public void deserialize(byte[] data) {
61 bytes = data;
62 }
63
64 @Override
65 public int hashCode() {
66 return Objects.hash(bytes);
67 }
68
69 @Override
70 public boolean equals(Object obj) {
71 if (this == obj) {
72 return true;
73 }
74 if (obj instanceof UnresolvedExtensionMappingAddress) {
75 UnresolvedExtensionMappingAddress that =
76 (UnresolvedExtensionMappingAddress) obj;
77 return Arrays.equals(bytes, that.bytes);
78 }
79 return false;
80 }
81
82 @Override
83 public String toString() {
84 return toStringHelper(type().toString())
85 .add("bytes", bytes)
86 .add("unresolvedAddressType", unresolvedAddressType)
87 .toString();
88 }
89}