blob: 7073b158a0ccda8accb04bb87f44c38e8abbaf00 [file] [log] [blame]
Pier Ventre9cf536b2016-10-21 13:30:18 -07001/*
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
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
27/**
28 * OFDPA set MPLS L2 Port extension instruction.
29 */
30public class Ofdpa3SetMplsL2Port extends AbstractExtension implements ExtensionTreatment {
31 /**
32 * Integer representing the logical port.
33 */
34 private int mplsL2Port;
35
36 private static final KryoNamespace APPKRYO = new KryoNamespace.Builder()
37 .build();
38
39 /**
40 * Constructs a new set MPLS L2 Port instruction.
41 */
42 protected Ofdpa3SetMplsL2Port() {
43 mplsL2Port = 0;
44 }
45
46 /**
47 * Constructs a new set MPLS L2 Port instruction with a given integer.
48 *
49 * @param mplsl2port the MPLS L2 Port
50 */
51 public Ofdpa3SetMplsL2Port(Integer mplsl2port) {
52 this.mplsL2Port = mplsl2port;
53 }
54
55 /**
56 * Gets the MPLS L2 Port.
57 *
58 * @return MPLS L2 Port
59 */
60 public int mplsL2Port() {
61 return mplsL2Port;
62 }
63
64 @Override
65 public ExtensionTreatmentType type() {
66 return ExtensionTreatmentType.ExtensionTreatmentTypes.OFDPA_SET_MPLS_L2_PORT.type();
67 }
68
69 @Override
70 public void deserialize(byte[] data) {
71 mplsL2Port = APPKRYO.deserialize(data);
72 }
73
74 @Override
75 public byte[] serialize() {
76 return APPKRYO.serialize(mplsL2Port);
77 }
78
79 @Override
80 public int hashCode() {
81 return Objects.hash(mplsL2Port);
82 }
83
84 @Override
85 public boolean equals(Object obj) {
86 if (this == obj) {
87 return true;
88 }
89 if (obj instanceof Ofdpa3SetMplsL2Port) {
90 Ofdpa3SetMplsL2Port that = (Ofdpa3SetMplsL2Port) obj;
91 return Objects.equals(mplsL2Port, that.mplsL2Port);
92
93 }
94 return false;
95 }
96
97 @Override
98 public String toString() {
99 return MoreObjects.toStringHelper(getClass())
100 .add("mplsL2Port", mplsL2Port)
101 .toString();
102 }
103}