Phaneendra Manda | ab5a736 | 2015-12-02 01:10:01 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 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 | |
| 17 | package org.onosproject.driver.extensions; |
| 18 | |
Jonathan Hart | 26a8d95 | 2015-12-02 15:16:35 -0800 | [diff] [blame] | 19 | import com.google.common.base.MoreObjects; |
Phaneendra Manda | ab5a736 | 2015-12-02 01:10:01 +0530 | [diff] [blame] | 20 | import org.onlab.util.KryoNamespace; |
Jonathan Hart | 26a8d95 | 2015-12-02 15:16:35 -0800 | [diff] [blame] | 21 | import org.onosproject.net.flow.AbstractExtension; |
| 22 | import org.onosproject.net.flow.instructions.ExtensionTreatment; |
Phaneendra Manda | ab5a736 | 2015-12-02 01:10:01 +0530 | [diff] [blame] | 23 | import org.onosproject.net.flow.instructions.ExtensionTreatmentType; |
| 24 | |
Jonathan Hart | 26a8d95 | 2015-12-02 15:16:35 -0800 | [diff] [blame] | 25 | import java.util.Objects; |
Phaneendra Manda | ab5a736 | 2015-12-02 01:10:01 +0530 | [diff] [blame] | 26 | |
| 27 | /** |
| 28 | * Nicira set NSH Context header extension instruction. |
| 29 | */ |
Jonathan Hart | 26a8d95 | 2015-12-02 15:16:35 -0800 | [diff] [blame] | 30 | public class NiciraSetNshContextHeader extends AbstractExtension implements |
| 31 | ExtensionTreatment { |
Phaneendra Manda | ab5a736 | 2015-12-02 01:10:01 +0530 | [diff] [blame] | 32 | |
| 33 | private int nshCh; |
| 34 | private ExtensionTreatmentType type; |
| 35 | |
| 36 | private final KryoNamespace appKryo = new KryoNamespace.Builder().build(); |
| 37 | |
| 38 | /** |
| 39 | * Creates a new set nsh context header instruction. |
| 40 | * |
| 41 | * @param type extension treatment type |
| 42 | */ |
| 43 | NiciraSetNshContextHeader(ExtensionTreatmentType type) { |
| 44 | this.nshCh = 0; |
| 45 | this.type = type; |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * Creates a new set nsh context header instruction. |
| 50 | * |
| 51 | * @param nshCh nsh context header |
| 52 | * @param type extension treatment type |
| 53 | */ |
| 54 | NiciraSetNshContextHeader(int nshCh, ExtensionTreatmentType type) { |
| 55 | this.nshCh = nshCh; |
| 56 | this.type = type; |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * Gets the nsh context header. |
| 61 | * |
| 62 | * @return nsh context header |
| 63 | */ |
| 64 | public int nshCh() { |
| 65 | return nshCh; |
| 66 | } |
| 67 | |
| 68 | @Override |
| 69 | public ExtensionTreatmentType type() { |
| 70 | return type; |
| 71 | } |
| 72 | |
| 73 | @Override |
| 74 | public void deserialize(byte[] data) { |
| 75 | nshCh = appKryo.deserialize(data); |
| 76 | } |
| 77 | |
| 78 | @Override |
| 79 | public byte[] serialize() { |
| 80 | return appKryo.serialize(nshCh); |
| 81 | } |
| 82 | |
| 83 | @Override |
| 84 | public int hashCode() { |
| 85 | return Objects.hash(nshCh, type); |
| 86 | } |
| 87 | |
| 88 | @Override |
| 89 | public boolean equals(Object obj) { |
| 90 | if (this == obj) { |
| 91 | return true; |
| 92 | } |
| 93 | if (obj instanceof NiciraSetNshContextHeader) { |
| 94 | NiciraSetNshContextHeader that = (NiciraSetNshContextHeader) obj; |
| 95 | return Objects.equals(nshCh, that.nshCh) && Objects.equals(type, that.type); |
| 96 | |
| 97 | } |
| 98 | return false; |
| 99 | } |
| 100 | |
| 101 | @Override |
| 102 | public String toString() { |
| 103 | return MoreObjects.toStringHelper(getClass()) |
| 104 | .add("nshCh", nshCh) |
| 105 | .add("type", type) |
| 106 | .toString(); |
| 107 | } |
| 108 | } |