Andreas Pantelopoulos | fdcfe53 | 2018-04-02 10:59:23 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018-present Open Networking Foundation |
| 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 copy field extension instruction. |
| 29 | */ |
| 30 | public class Ofdpa3CopyField extends AbstractExtension implements ExtensionTreatment { |
Jonghwan Hyun | 800d9d0 | 2018-04-09 09:40:50 -0700 | [diff] [blame] | 31 | // OXM ID of VLAN_VID field from OF-DPA spec. |
| 32 | public static final int OXM_ID_VLAN_VID = 0x80000c02; |
| 33 | // OXM ID of PACKET_REG(1) field from OF-DPA spec. |
| 34 | public static final int OXM_ID_PACKET_REG_1 = 0x80010200; |
| 35 | |
Andreas Pantelopoulos | fdcfe53 | 2018-04-02 10:59:23 -0700 | [diff] [blame] | 36 | private int nBits; |
| 37 | private int srcOffset; |
| 38 | private int dstOffset; |
| 39 | private int src; |
| 40 | private int dst; |
| 41 | |
| 42 | private static final KryoNamespace APPKRYO = new KryoNamespace.Builder() |
| 43 | .register(Ofdpa3AllowVlanTranslationType.class) |
| 44 | .build(); |
| 45 | |
| 46 | public Ofdpa3CopyField() { |
| 47 | nBits = 0; |
| 48 | srcOffset = 0; |
| 49 | dstOffset = 0; |
Jonghwan Hyun | 800d9d0 | 2018-04-09 09:40:50 -0700 | [diff] [blame] | 50 | src = OXM_ID_VLAN_VID; |
| 51 | dst = OXM_ID_PACKET_REG_1; |
Andreas Pantelopoulos | fdcfe53 | 2018-04-02 10:59:23 -0700 | [diff] [blame] | 52 | |
| 53 | } |
| 54 | |
| 55 | public Ofdpa3CopyField(int nBits, int srcOffset, int dstOffset, int src, int dst) { |
| 56 | this.nBits = nBits; |
| 57 | this.srcOffset = srcOffset; |
| 58 | this.dstOffset = dstOffset; |
| 59 | this.src = src; |
| 60 | this.dst = dst; |
| 61 | } |
| 62 | |
| 63 | /** |
| 64 | * Returns the nBits value. |
| 65 | * @return nBits value. |
| 66 | */ |
| 67 | public int getnBits() { |
| 68 | return nBits; |
| 69 | } |
| 70 | |
| 71 | /** |
| 72 | * Returns the srcOffset value. |
| 73 | * @return srcOffset value. |
| 74 | */ |
| 75 | public int getSrcOffset() { |
| 76 | return srcOffset; |
| 77 | } |
| 78 | |
| 79 | /** |
| 80 | * Returns the dstOffset value. |
| 81 | * @return dstOffset value. |
| 82 | */ |
| 83 | public int getDstOffset() { |
| 84 | return dstOffset; |
| 85 | } |
| 86 | |
| 87 | /** |
| 88 | * Returns the src value. |
| 89 | * @return src value. |
| 90 | */ |
| 91 | public int getSrc() { |
| 92 | return src; |
| 93 | } |
| 94 | |
| 95 | /** |
| 96 | * Returns the dst value. |
| 97 | * @return dst value. |
| 98 | */ |
| 99 | public int getDst() { |
| 100 | return dst; |
| 101 | } |
| 102 | |
| 103 | @Override |
| 104 | public ExtensionTreatmentType type() { |
| 105 | return ExtensionTreatmentType.ExtensionTreatmentTypes.ONF_COPY_FIELD.type(); |
| 106 | } |
| 107 | |
| 108 | @Override |
| 109 | public void deserialize(byte[] data) { |
| 110 | } |
| 111 | |
| 112 | @Override |
| 113 | public byte[] serialize() { |
| 114 | return APPKRYO.serialize(this); |
| 115 | } |
| 116 | |
| 117 | @Override |
| 118 | public int hashCode() { |
| 119 | return Objects.hash(this); |
| 120 | } |
| 121 | |
| 122 | @Override |
| 123 | public boolean equals(Object obj) { |
| 124 | if (this == obj) { |
| 125 | return true; |
| 126 | } |
| 127 | if (obj instanceof Ofdpa3CopyField) { |
| 128 | Ofdpa3CopyField that = (Ofdpa3CopyField) obj; |
| 129 | return Objects.equals(nBits, that.nBits) && |
| 130 | Objects.equals(srcOffset, that.srcOffset) && |
| 131 | Objects.equals(dstOffset, that.dstOffset) && |
| 132 | Objects.equals(src, that.src) && |
| 133 | Objects.equals(dst, that.dst); |
| 134 | } |
| 135 | return false; |
| 136 | } |
| 137 | |
| 138 | @Override |
| 139 | public String toString() { |
| 140 | return MoreObjects.toStringHelper(getClass()) |
| 141 | .add("nBits", nBits) |
| 142 | .add("srcOffset", Integer.toHexString(srcOffset)) |
| 143 | .add("dstOffset", Integer.toHexString(dstOffset)) |
| 144 | .add("src", Integer.toHexString(src)) |
| 145 | .add("dst", Integer.toHexString(dst)) |
| 146 | .toString(); |
| 147 | } |
| 148 | } |