Pier Ventre | db252cc | 2016-10-21 21:54:26 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package org.onosproject.driver.extensions; |
| 18 | |
| 19 | import com.google.common.base.MoreObjects; |
| 20 | import org.onlab.util.KryoNamespace; |
| 21 | import org.onosproject.net.flow.AbstractExtension; |
| 22 | import org.onosproject.net.flow.instructions.ExtensionTreatment; |
| 23 | import org.onosproject.net.flow.instructions.ExtensionTreatmentType; |
| 24 | |
| 25 | import java.util.Objects; |
| 26 | |
| 27 | /** |
| 28 | * OFDPA set Qos Index extension instruction. |
| 29 | */ |
| 30 | public class Ofdpa3SetQosIndex extends AbstractExtension implements ExtensionTreatment { |
| 31 | /** |
| 32 | * Byte storing the Qos index. |
| 33 | */ |
| 34 | private int qosIndex; |
| 35 | |
| 36 | private static final KryoNamespace APPKRYO = new KryoNamespace.Builder() |
| 37 | .build(); |
| 38 | |
| 39 | /** |
| 40 | * Constructs a new set Qos index instruction. |
| 41 | */ |
| 42 | protected Ofdpa3SetQosIndex() { |
| 43 | qosIndex = 0x00; |
| 44 | } |
| 45 | |
| 46 | /** |
| 47 | * Constructs a new set Qos index instruction with a given int. |
| 48 | * |
| 49 | * @param qosindex Qos index as integer |
| 50 | */ |
| 51 | public Ofdpa3SetQosIndex(int qosindex) { |
| 52 | qosIndex = qosindex; |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | * Gets the Qos index as int. |
| 57 | * |
| 58 | * @return the Qos index as int. |
| 59 | */ |
| 60 | public int qosIndex() { |
| 61 | return qosIndex; |
| 62 | } |
| 63 | |
| 64 | @Override |
| 65 | public ExtensionTreatmentType type() { |
| 66 | return ExtensionTreatmentType.ExtensionTreatmentTypes.OFDPA_SET_QOS_INDEX.type(); |
| 67 | } |
| 68 | |
| 69 | @Override |
| 70 | public void deserialize(byte[] data) { |
| 71 | qosIndex = APPKRYO.deserialize(data); |
| 72 | } |
| 73 | |
| 74 | @Override |
| 75 | public byte[] serialize() { |
| 76 | return APPKRYO.serialize(qosIndex); |
| 77 | } |
| 78 | |
| 79 | @Override |
| 80 | public int hashCode() { |
| 81 | return Objects.hash(qosIndex); |
| 82 | } |
| 83 | |
| 84 | @Override |
| 85 | public boolean equals(Object obj) { |
| 86 | if (this == obj) { |
| 87 | return true; |
| 88 | } |
| 89 | if (obj instanceof Ofdpa3SetQosIndex) { |
| 90 | Ofdpa3SetQosIndex that = (Ofdpa3SetQosIndex) obj; |
| 91 | return Objects.equals(qosIndex, that.qosIndex); |
| 92 | |
| 93 | } |
| 94 | return false; |
| 95 | } |
| 96 | |
| 97 | @Override |
| 98 | public String toString() { |
| 99 | return MoreObjects.toStringHelper(getClass()) |
| 100 | .add("qosIndex", qosIndex) |
| 101 | .toString(); |
| 102 | } |
| 103 | } |