blob: 8b7f194736dbcdf3ec8b233201bc9d04f1b0e77a [file] [log] [blame]
Phaneendra Manda8db7d092016-06-04 00:17:24 +05301/*
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 */
16
17package org.onosproject.driver.extensions;
18
19import java.util.Objects;
20
21import org.onlab.util.KryoNamespace;
22import org.onosproject.net.flow.AbstractExtension;
23import org.onosproject.net.flow.instructions.ExtensionTreatment;
24import org.onosproject.net.flow.instructions.ExtensionTreatmentType;
25
26import com.google.common.base.MoreObjects;
27
28/**
29 * Nicira EncapEthType extension instruction to set encapsulated eth type.
30 */
31public class NiciraEncapEthType extends AbstractExtension implements ExtensionTreatment {
32
33 private short encapEthType;
34
35 private final KryoNamespace appKryo = new KryoNamespace.Builder().build();
36
37 /**
38 * Creates a new nshEncapEthType instruction.
39 */
40 NiciraEncapEthType() {
41 encapEthType = (short) 0;
42 }
43
44 /**
45 * Creates a new nshEncapEthType instruction with given eth type.
46 *
47 * @param encapEthType encapsulated ethernet type
48 */
49 public NiciraEncapEthType(short encapEthType) {
50 this.encapEthType = encapEthType;
51 }
52
53 /**
54 * Gets the encapEthType.
55 *
56 * @return encapEthType
57 */
58 public short encapEthType() {
59 return encapEthType;
60 }
61
62 @Override
63 public ExtensionTreatmentType type() {
64 return ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_ENCAP_ETH_TYPE.type();
65 }
66
67 @Override
68 public void deserialize(byte[] data) {
69 encapEthType = (short) (appKryo.deserialize(data));
70 }
71
72 @Override
73 public byte[] serialize() {
74 return appKryo.serialize(encapEthType);
75 }
76
77 @Override
78 public int hashCode() {
79 return Objects.hash(encapEthType);
80 }
81
82 @Override
83 public boolean equals(Object obj) {
84 if (this == obj) {
85 return true;
86 }
87 if (obj instanceof NiciraEncapEthType) {
88 NiciraEncapEthType that = (NiciraEncapEthType) obj;
89 return Objects.equals(encapEthType, that.encapEthType);
90
91 }
92 return false;
93 }
94
95 @Override
96 public String toString() {
97 return MoreObjects.toStringHelper(getClass()).add("encapEthType", encapEthType).toString();
98 }
99}