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