blob: 6213120a91b2431f76d42b57cf6c28f6b52a11f5 [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.criteria.ExtensionSelector;
23import org.onosproject.net.flow.criteria.ExtensionSelectorType;
24
25import java.util.Objects;
26
27/**
28 * OFDPA MPLS L2 Port extension match. MPLS L2 Port
29 * is a logical port and it is represented with an
30 * integer.
31 */
32public class Ofdpa3MatchMplsL2Port extends AbstractExtension implements ExtensionSelector {
33 /**
34 * Integer representing the logical port.
35 */
36 private int mplsL2Port;
37
38 private static final KryoNamespace APPKRYO = new KryoNamespace.Builder()
39 .build();
40
41 /**
42 * OFDPA MPLS L2 Port extension match.
43 */
44 protected Ofdpa3MatchMplsL2Port() {
45 mplsL2Port = 0;
46 }
47
48 /**
49 * Constructs a new MPLS L2 Port match with a given Integer.
50 *
51 * @param mplsl2port the MPLS L2 Port
52 */
53 public Ofdpa3MatchMplsL2Port(int mplsl2port) {
54 this.mplsL2Port = mplsl2port;
55 }
56
57 /**
58 * Gets the MPLS L2 Port.
59 *
60 * @return MPLS L2 Port
61 */
62 public int mplsL2Port() {
63 return mplsL2Port;
64 }
65
66 @Override
67 public ExtensionSelectorType type() {
68 return ExtensionSelectorType.ExtensionSelectorTypes.OFDPA_MATCH_MPLS_L2_PORT.type();
69 }
70
71 @Override
72 public byte[] serialize() {
73 return APPKRYO.serialize(mplsL2Port);
74 }
75
76 @Override
77 public void deserialize(byte[] data) {
78 mplsL2Port = APPKRYO.deserialize(data);
79 }
80
81 @Override
82 public int hashCode() {
83 return Objects.hash(mplsL2Port);
84 }
85
86 @Override
87 public boolean equals(Object obj) {
88 if (this == obj) {
89 return true;
90 }
91 if (obj instanceof Ofdpa3MatchMplsL2Port) {
92 Ofdpa3MatchMplsL2Port that = (Ofdpa3MatchMplsL2Port) obj;
93 return Objects.equals(mplsL2Port, that.mplsL2Port);
94
95 }
96 return false;
97 }
98
99 @Override
100 public String toString() {
101 return MoreObjects.toStringHelper(getClass())
102 .add("mplsL2Port", mplsL2Port)
103 .toString();
104 }
105}