Frank Wang | 5733c38 | 2017-03-28 10:15:18 +0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2017-present Open Networking Foundation |
Frank Wang | 5733c38 | 2017-03-28 10:15:18 +0800 | [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 com.google.common.collect.Maps; |
| 21 | import org.onlab.util.KryoNamespace; |
| 22 | import org.onosproject.net.flow.AbstractExtension; |
| 23 | import org.onosproject.net.flow.instructions.ExtensionTreatment; |
| 24 | import org.onosproject.net.flow.instructions.ExtensionTreatmentType; |
| 25 | |
| 26 | import java.util.ArrayList; |
| 27 | import java.util.List; |
| 28 | import java.util.Map; |
| 29 | import java.util.Objects; |
| 30 | |
| 31 | /** |
| 32 | * Nicira ct extension instruction. |
| 33 | */ |
| 34 | public class NiciraCt extends AbstractExtension implements ExtensionTreatment { |
| 35 | |
| 36 | private int flags; |
| 37 | private long zoneSrc; |
| 38 | private int zone; |
| 39 | private short recircTable; |
| 40 | private int alg; |
| 41 | private List<ExtensionTreatment> nestedActions; |
| 42 | private final KryoNamespace appKryo = new KryoNamespace.Builder().build(); |
| 43 | |
| 44 | /** |
| 45 | * Creates a new nicicra ct instruction. |
| 46 | */ |
| 47 | public NiciraCt() { |
| 48 | flags = 0; |
| 49 | zoneSrc = 0L; |
| 50 | zone = 0; |
| 51 | alg = 0; |
| 52 | recircTable = 0xFF; |
| 53 | nestedActions = new ArrayList<>(); |
| 54 | } |
| 55 | |
| 56 | /** |
| 57 | * Creates a new nicicra ct instruction. |
| 58 | * @param flags zero or commit(0x01) |
| 59 | * @param zoneSrc If 'zone_src' is nonzero, this specifies that the zone should be |
| 60 | * sourced from a field zone_src[ofs:ofs+nbits]. |
| 61 | * @param zone this is the union of zone_imm and zone_ofs_nbits |
| 62 | * If 'zone_src' is zero, then the value of 'zone_imm' |
| 63 | * will be used as the connection tracking zone |
| 64 | * @param recircTable Recirculate to a specific table or 0xff for no recirculation |
| 65 | * @param alg Well-known port number for the protocol, 0 indicates no ALG is required |
| 66 | * @param actions a sequence of zero or more OpenFlow actions |
| 67 | */ |
| 68 | public NiciraCt(int flags, long zoneSrc, int zone, short recircTable, int alg, List<ExtensionTreatment> actions) { |
| 69 | this.flags = flags; |
| 70 | this.zoneSrc = zoneSrc; |
| 71 | this.zone = zone; |
| 72 | this.recircTable = recircTable; |
| 73 | this.alg = alg; |
| 74 | this.nestedActions = actions; |
| 75 | } |
| 76 | |
| 77 | @Override |
| 78 | public ExtensionTreatmentType type() { |
| 79 | return ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_CT.type(); |
| 80 | } |
| 81 | |
| 82 | /** |
| 83 | * Get Nicira Conntrack flags. |
| 84 | * @return flags |
| 85 | */ |
| 86 | public int niciraCtFlags() { |
| 87 | return flags; |
| 88 | } |
| 89 | |
| 90 | /** |
| 91 | * Get Nicira Conntrack zone. |
| 92 | * @return zone |
| 93 | */ |
| 94 | public int niciraCtZone() { |
| 95 | return zone; |
| 96 | } |
| 97 | |
| 98 | /** |
| 99 | * Get Nicira Conntrack zone src. |
| 100 | * @return zoneSrc |
| 101 | */ |
| 102 | public long niciraCtZoneSrc() { |
| 103 | return zoneSrc; |
| 104 | } |
| 105 | |
| 106 | /** |
| 107 | * Get Nicira Conntrack alg. |
| 108 | * @return alg |
| 109 | */ |
| 110 | public int niciraCtAlg() { |
| 111 | return alg; |
| 112 | } |
| 113 | |
| 114 | /** |
| 115 | * Get Nicira Conntrack Recirc table. |
| 116 | * @return recirc table |
| 117 | */ |
| 118 | public short niciraCtRecircTable() { |
| 119 | return recircTable; |
| 120 | } |
| 121 | |
| 122 | /** |
| 123 | * Get Nicira Conntrack Recirc table. |
| 124 | * @return list extension treatment |
| 125 | */ |
| 126 | public List<ExtensionTreatment> niciraCtNestActions() { |
| 127 | return nestedActions; |
| 128 | } |
| 129 | |
| 130 | @Override |
| 131 | public void deserialize(byte[] data) { |
| 132 | Map<String, Object> values = appKryo.deserialize(data); |
| 133 | flags = (int) values.get("flags"); |
| 134 | zoneSrc = (long) values.get("zoneSrc"); |
| 135 | zone = (int) values.get("zone"); |
| 136 | recircTable = (short) values.get("recircTable"); |
| 137 | alg = (int) values.get("alg"); |
| 138 | nestedActions = (List) values.get("nestedActions"); |
| 139 | } |
| 140 | |
| 141 | @Override |
| 142 | public byte[] serialize() { |
| 143 | Map<String, Object> values = Maps.newHashMap(); |
| 144 | values.put("flags", flags); |
| 145 | values.put("zoneSrc", zoneSrc); |
| 146 | values.put("zone", zone); |
| 147 | values.put("recircTable", recircTable); |
| 148 | values.put("alg", alg); |
| 149 | values.put("nestedActions", nestedActions); |
| 150 | return appKryo.serialize(values); |
| 151 | } |
| 152 | |
| 153 | @Override |
| 154 | public int hashCode() { |
| 155 | return Objects.hash(type(), flags, zone, zoneSrc, alg, recircTable, nestedActions); |
| 156 | } |
| 157 | |
| 158 | @Override |
| 159 | public boolean equals(Object obj) { |
| 160 | if (this == obj) { |
| 161 | return true; |
| 162 | } |
| 163 | if (obj instanceof NiciraCt) { |
| 164 | NiciraCt that = (NiciraCt) obj; |
| 165 | return Objects.equals(flags, that.flags) && |
| 166 | Objects.equals(zone, that.zone) && |
| 167 | Objects.equals(zoneSrc, that.zoneSrc) && |
| 168 | Objects.equals(alg, that.alg) && |
| 169 | Objects.equals(recircTable, that.recircTable) && |
| 170 | Objects.equals(nestedActions, that.nestedActions) && |
| 171 | Objects.equals(this.type(), that.type()); |
| 172 | } |
| 173 | return false; |
| 174 | } |
| 175 | |
| 176 | @Override |
| 177 | public String toString() { |
| 178 | return MoreObjects.toStringHelper(getClass()) |
| 179 | .add("flags", flags) |
| 180 | .add("zoneSrc", zoneSrc) |
| 181 | .add("zone", zone) |
| 182 | .add("recircTable", recircTable) |
| 183 | .add("alg", alg) |
| 184 | .add("nestedActions", nestedActions) |
| 185 | .toString(); |
| 186 | } |
| 187 | } |