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