Phaneendra Manda | 8db7d09 | 2016-06-04 00:17:24 +0530 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package org.onosproject.driver.extensions; |
| 18 | |
| 19 | import java.util.Objects; |
| 20 | |
| 21 | import org.onlab.packet.MacAddress; |
| 22 | import org.onlab.util.KryoNamespace; |
| 23 | import org.onosproject.net.flow.AbstractExtension; |
| 24 | import org.onosproject.net.flow.instructions.ExtensionTreatment; |
| 25 | import org.onosproject.net.flow.instructions.ExtensionTreatmentType; |
| 26 | import org.onosproject.store.serializers.MacAddressSerializer; |
| 27 | |
| 28 | import com.google.common.base.MoreObjects; |
| 29 | |
| 30 | /** |
| 31 | * Nicira EncapEthDst extension instruction to set encapsulated eth destination. |
| 32 | */ |
| 33 | public class NiciraEncapEthDst extends AbstractExtension implements ExtensionTreatment { |
| 34 | |
| 35 | private MacAddress encapEthDst; |
| 36 | |
| 37 | private final KryoNamespace appKryo = new KryoNamespace.Builder() |
| 38 | .register(new MacAddressSerializer(), MacAddress.class).register(byte[].class).build();; |
| 39 | |
| 40 | /** |
| 41 | * Creates a new nshEncapEthDst instruction. |
| 42 | */ |
| 43 | NiciraEncapEthDst() { |
| 44 | } |
| 45 | |
| 46 | /** |
| 47 | * Creates a new encapEthDst instruction with given mac address. |
| 48 | * |
| 49 | * @param encapEthDst encapsulated ethernet destination |
| 50 | */ |
| 51 | public NiciraEncapEthDst(MacAddress encapEthDst) { |
| 52 | this.encapEthDst = encapEthDst; |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | * Gets the encapEthDst. |
| 57 | * |
| 58 | * @return encapEthDst |
| 59 | */ |
| 60 | public MacAddress encapEthDst() { |
| 61 | return encapEthDst; |
| 62 | } |
| 63 | |
| 64 | @Override |
| 65 | public ExtensionTreatmentType type() { |
| 66 | return ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_ENCAP_ETH_DST.type(); |
| 67 | } |
| 68 | |
| 69 | @Override |
| 70 | public void deserialize(byte[] data) { |
| 71 | encapEthDst = appKryo.deserialize(data); |
| 72 | } |
| 73 | |
| 74 | @Override |
| 75 | public byte[] serialize() { |
| 76 | return appKryo.serialize(encapEthDst); |
| 77 | } |
| 78 | |
| 79 | @Override |
| 80 | public int hashCode() { |
| 81 | return Objects.hash(encapEthDst); |
| 82 | } |
| 83 | |
| 84 | @Override |
| 85 | public boolean equals(Object obj) { |
| 86 | if (this == obj) { |
| 87 | return true; |
| 88 | } |
| 89 | if (obj instanceof NiciraEncapEthDst) { |
| 90 | NiciraEncapEthDst that = (NiciraEncapEthDst) obj; |
| 91 | return Objects.equals(encapEthDst, that.encapEthDst); |
| 92 | |
| 93 | } |
| 94 | return false; |
| 95 | } |
| 96 | |
| 97 | @Override |
| 98 | public String toString() { |
| 99 | return MoreObjects.toStringHelper(getClass()).add("encapEthDst", encapEthDst).toString(); |
| 100 | } |
| 101 | } |