Charles Chan | cad338a | 2016-09-16 18:03:11 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
Charles Chan | cad338a | 2016-09-16 18:03:11 -0700 | [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 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 | import static com.google.common.base.Preconditions.checkNotNull; |
| 28 | |
| 29 | /** |
| 30 | * OFDPA set MPLS Type extension instruction. |
| 31 | */ |
| 32 | public class Ofdpa3SetMplsType extends AbstractExtension implements ExtensionTreatment { |
| 33 | private short mplsType; |
| 34 | |
| 35 | private static final KryoNamespace APPKRYO = new KryoNamespace.Builder() |
| 36 | .register(Ofdpa3MplsType.class) |
| 37 | .build(); |
| 38 | |
| 39 | /** |
| 40 | * Constructs a new set MPLS type instruction. |
| 41 | */ |
| 42 | protected Ofdpa3SetMplsType() { |
| 43 | mplsType = Ofdpa3MplsType.NONE.getValue(); |
| 44 | } |
| 45 | |
| 46 | /** |
| 47 | * Constructs a new set MPLS type instruction with given type. |
| 48 | * |
| 49 | * @param mplsType MPLS type in short |
| 50 | */ |
| 51 | public Ofdpa3SetMplsType(short mplsType) { |
Charles Chan | cad338a | 2016-09-16 18:03:11 -0700 | [diff] [blame] | 52 | this.mplsType = mplsType; |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | * Constructs a new set MPLS type instruction with given type. |
| 57 | * |
| 58 | * @param mplsType Ofdpa3MplsType |
| 59 | */ |
| 60 | public Ofdpa3SetMplsType(Ofdpa3MplsType mplsType) { |
| 61 | checkNotNull(mplsType); |
| 62 | this.mplsType = mplsType.getValue(); |
| 63 | } |
| 64 | |
| 65 | /** |
| 66 | * Gets the MPLS type. |
| 67 | * |
| 68 | * @return MPLS type |
| 69 | */ |
| 70 | public short mplsType() { |
| 71 | return mplsType; |
| 72 | } |
| 73 | |
| 74 | @Override |
| 75 | public ExtensionTreatmentType type() { |
| 76 | return ExtensionTreatmentType.ExtensionTreatmentTypes.OFDPA_SET_MPLS_TYPE.type(); |
| 77 | } |
| 78 | |
| 79 | @Override |
| 80 | public void deserialize(byte[] data) { |
| 81 | mplsType = APPKRYO.deserialize(data); |
| 82 | } |
| 83 | |
| 84 | @Override |
| 85 | public byte[] serialize() { |
| 86 | return APPKRYO.serialize(mplsType); |
| 87 | } |
| 88 | |
| 89 | @Override |
| 90 | public int hashCode() { |
| 91 | return Objects.hash(mplsType); |
| 92 | } |
| 93 | |
| 94 | @Override |
| 95 | public boolean equals(Object obj) { |
| 96 | if (this == obj) { |
| 97 | return true; |
| 98 | } |
| 99 | if (obj instanceof Ofdpa3SetMplsType) { |
| 100 | Ofdpa3SetMplsType that = (Ofdpa3SetMplsType) obj; |
| 101 | return Objects.equals(mplsType, that.mplsType); |
| 102 | |
| 103 | } |
| 104 | return false; |
| 105 | } |
| 106 | |
| 107 | @Override |
| 108 | public String toString() { |
| 109 | return MoreObjects.toStringHelper(getClass()) |
| 110 | .add("mplsType", mplsType) |
| 111 | .toString(); |
| 112 | } |
| 113 | } |