Phaneendra Manda | 8db7d09 | 2016-06-04 00:17:24 +0530 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
Phaneendra Manda | 8db7d09 | 2016-06-04 00:17:24 +0530 | [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.driver.extensions; |
| 18 | |
| 19 | import java.util.Objects; |
| 20 | |
| 21 | import org.onlab.util.KryoNamespace; |
| 22 | import org.onosproject.net.flow.AbstractExtension; |
| 23 | import org.onosproject.net.flow.instructions.ExtensionTreatment; |
| 24 | import org.onosproject.net.flow.instructions.ExtensionTreatmentType; |
| 25 | |
| 26 | import com.google.common.base.MoreObjects; |
| 27 | |
| 28 | /** |
| 29 | * Nicira nshMdType extension instruction. |
| 30 | */ |
| 31 | public class NiciraNshMdType extends AbstractExtension implements ExtensionTreatment { |
| 32 | |
| 33 | private byte nshMdType; |
| 34 | |
| 35 | private final KryoNamespace appKryo = new KryoNamespace.Builder().build(); |
| 36 | |
| 37 | /** |
| 38 | * Creates a new nshMdType instruction. |
| 39 | */ |
| 40 | NiciraNshMdType() { |
| 41 | nshMdType = (byte) 0; |
| 42 | } |
| 43 | |
| 44 | /** |
| 45 | * Creates a new nshMdType instruction with given nsh md type. |
| 46 | * |
| 47 | * @param nshMdType nsh md type |
| 48 | */ |
| 49 | public NiciraNshMdType(byte nshMdType) { |
| 50 | this.nshMdType = nshMdType; |
| 51 | } |
| 52 | |
| 53 | /** |
| 54 | * Gets the nsh md type. |
| 55 | * |
| 56 | * @return nshMdType |
| 57 | */ |
| 58 | public byte nshMdType() { |
| 59 | return nshMdType; |
| 60 | } |
| 61 | |
| 62 | @Override |
| 63 | public ExtensionTreatmentType type() { |
| 64 | return ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_NSH_MDTYPE.type(); |
| 65 | } |
| 66 | |
| 67 | @Override |
| 68 | public void deserialize(byte[] data) { |
| 69 | nshMdType = (byte) (appKryo.deserialize(data)); |
| 70 | } |
| 71 | |
| 72 | @Override |
| 73 | public byte[] serialize() { |
| 74 | return appKryo.serialize(nshMdType); |
| 75 | } |
| 76 | |
| 77 | @Override |
| 78 | public int hashCode() { |
| 79 | return Objects.hash(nshMdType); |
| 80 | } |
| 81 | |
| 82 | @Override |
| 83 | public boolean equals(Object obj) { |
| 84 | if (this == obj) { |
| 85 | return true; |
| 86 | } |
| 87 | if (obj instanceof NiciraNshMdType) { |
| 88 | NiciraNshMdType that = (NiciraNshMdType) obj; |
| 89 | return Objects.equals(nshMdType, that.nshMdType); |
| 90 | |
| 91 | } |
| 92 | return false; |
| 93 | } |
| 94 | |
| 95 | @Override |
| 96 | public String toString() { |
| 97 | return MoreObjects.toStringHelper(getClass()).add("nshMdType", nshMdType).toString(); |
| 98 | } |
| 99 | } |