blob: ca0f03d1f0bfdba9844dfb9fd89e28b349ab65fd [file] [log] [blame]
Charles Chancad338a2016-09-16 18:03:11 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
Charles Chancad338a2016-09-16 18:03:11 -07003 *
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 com.google.common.base.MoreObjects;
20import org.onlab.util.KryoNamespace;
21import org.onosproject.net.flow.AbstractExtension;
22import org.onosproject.net.flow.instructions.ExtensionTreatment;
23import org.onosproject.net.flow.instructions.ExtensionTreatmentType;
24
25import java.util.Objects;
26
27import static com.google.common.base.Preconditions.checkNotNull;
28
29/**
30 * OFDPA set MPLS Type extension instruction.
31 */
32public 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) {
52 checkNotNull(mplsType);
53 this.mplsType = mplsType;
54 }
55
56 /**
57 * Constructs a new set MPLS type instruction with given type.
58 *
59 * @param mplsType Ofdpa3MplsType
60 */
61 public Ofdpa3SetMplsType(Ofdpa3MplsType mplsType) {
62 checkNotNull(mplsType);
63 this.mplsType = mplsType.getValue();
64 }
65
66 /**
67 * Gets the MPLS type.
68 *
69 * @return MPLS type
70 */
71 public short mplsType() {
72 return mplsType;
73 }
74
75 @Override
76 public ExtensionTreatmentType type() {
77 return ExtensionTreatmentType.ExtensionTreatmentTypes.OFDPA_SET_MPLS_TYPE.type();
78 }
79
80 @Override
81 public void deserialize(byte[] data) {
82 mplsType = APPKRYO.deserialize(data);
83 }
84
85 @Override
86 public byte[] serialize() {
87 return APPKRYO.serialize(mplsType);
88 }
89
90 @Override
91 public int hashCode() {
92 return Objects.hash(mplsType);
93 }
94
95 @Override
96 public boolean equals(Object obj) {
97 if (this == obj) {
98 return true;
99 }
100 if (obj instanceof Ofdpa3SetMplsType) {
101 Ofdpa3SetMplsType that = (Ofdpa3SetMplsType) obj;
102 return Objects.equals(mplsType, that.mplsType);
103
104 }
105 return false;
106 }
107
108 @Override
109 public String toString() {
110 return MoreObjects.toStringHelper(getClass())
111 .add("mplsType", mplsType)
112 .toString();
113 }
114}