Phaneendra Manda | 8db7d09 | 2016-06-04 00:17:24 +0530 | [diff] [blame] | 1 | /* |
Brian O'Connor | ce2a03d | 2017-08-03 19:21:03 -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 nshNp extension instruction to set next protocol value in nsh header. |
| 30 | */ |
| 31 | public class NiciraNshNp extends AbstractExtension implements ExtensionTreatment { |
| 32 | |
| 33 | private byte nshNp; |
| 34 | |
| 35 | private final KryoNamespace appKryo = new KryoNamespace.Builder().build(); |
| 36 | |
| 37 | /** |
| 38 | * Creates a new nshNp instruction. |
| 39 | */ |
| 40 | NiciraNshNp() { |
| 41 | nshNp = (byte) 0; |
| 42 | } |
| 43 | |
| 44 | /** |
| 45 | * Creates a new nshNp instruction with given nsh np. |
| 46 | * |
| 47 | * @param nshNp nsh next protocol value |
| 48 | */ |
| 49 | public NiciraNshNp(byte nshNp) { |
| 50 | this.nshNp = nshNp; |
| 51 | } |
| 52 | |
| 53 | /** |
| 54 | * Gets the nsh np. |
| 55 | * |
| 56 | * @return nshNp |
| 57 | */ |
| 58 | public byte nshNp() { |
| 59 | return nshNp; |
| 60 | } |
| 61 | |
| 62 | @Override |
| 63 | public ExtensionTreatmentType type() { |
| 64 | return ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_NSH_NP.type(); |
| 65 | } |
| 66 | |
| 67 | @Override |
| 68 | public void deserialize(byte[] data) { |
| 69 | nshNp = (byte) (appKryo.deserialize(data)); |
| 70 | } |
| 71 | |
| 72 | @Override |
| 73 | public byte[] serialize() { |
| 74 | return appKryo.serialize(nshNp); |
| 75 | } |
| 76 | |
| 77 | @Override |
| 78 | public int hashCode() { |
| 79 | return Objects.hash(nshNp); |
| 80 | } |
| 81 | |
| 82 | @Override |
| 83 | public boolean equals(Object obj) { |
| 84 | if (this == obj) { |
| 85 | return true; |
| 86 | } |
| 87 | if (obj instanceof NiciraNshNp) { |
| 88 | NiciraNshNp that = (NiciraNshNp) obj; |
| 89 | return Objects.equals(nshNp, that.nshNp); |
| 90 | |
| 91 | } |
| 92 | return false; |
| 93 | } |
| 94 | |
| 95 | @Override |
| 96 | public String toString() { |
| 97 | return MoreObjects.toStringHelper(getClass()).add("nshNp", nshNp).toString(); |
| 98 | } |
| 99 | } |