Phaneendra Manda | 8db7d09 | 2016-06-04 00:17:24 +0530 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
Phaneendra Manda | 8db7d09 | 2016-06-04 00:17:24 +0530 | [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 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 EncapEthSrc extension instruction to set encapsulated eth source. |
| 32 | */ |
| 33 | public class NiciraEncapEthSrc extends AbstractExtension implements ExtensionTreatment { |
| 34 | |
| 35 | private MacAddress encapEthSrc; |
| 36 | |
| 37 | private final KryoNamespace appKryo = new KryoNamespace.Builder() |
Jon Hall | 8c7b06a | 2017-02-22 13:37:33 -0800 | [diff] [blame] | 38 | .register(new MacAddressSerializer(), MacAddress.class).register(byte[].class).build(); |
Phaneendra Manda | 8db7d09 | 2016-06-04 00:17:24 +0530 | [diff] [blame] | 39 | |
| 40 | /** |
| 41 | * Creates a new nshEncapEthSrc instruction. |
| 42 | */ |
| 43 | NiciraEncapEthSrc() { |
| 44 | } |
| 45 | |
| 46 | /** |
| 47 | * Creates a new encapEthSrc instruction with given mac address. |
| 48 | * |
| 49 | * @param encapEthSrc encapsulated ethernet source |
| 50 | */ |
| 51 | public NiciraEncapEthSrc(MacAddress encapEthSrc) { |
| 52 | this.encapEthSrc = encapEthSrc; |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | * Gets the encapEthSrc. |
| 57 | * |
| 58 | * @return encapEthSrc |
| 59 | */ |
| 60 | public MacAddress encapEthSrc() { |
| 61 | return encapEthSrc; |
| 62 | } |
| 63 | |
| 64 | @Override |
| 65 | public ExtensionTreatmentType type() { |
| 66 | return ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_ENCAP_ETH_SRC.type(); |
| 67 | } |
| 68 | |
| 69 | @Override |
| 70 | public void deserialize(byte[] data) { |
| 71 | encapEthSrc = appKryo.deserialize(data); |
| 72 | } |
| 73 | |
| 74 | @Override |
| 75 | public byte[] serialize() { |
| 76 | return appKryo.serialize(encapEthSrc); |
| 77 | } |
| 78 | |
| 79 | @Override |
| 80 | public int hashCode() { |
| 81 | return Objects.hash(encapEthSrc); |
| 82 | } |
| 83 | |
| 84 | @Override |
| 85 | public boolean equals(Object obj) { |
| 86 | if (this == obj) { |
| 87 | return true; |
| 88 | } |
| 89 | if (obj instanceof NiciraEncapEthSrc) { |
| 90 | NiciraEncapEthSrc that = (NiciraEncapEthSrc) obj; |
| 91 | return Objects.equals(encapEthSrc, that.encapEthSrc); |
| 92 | |
| 93 | } |
| 94 | return false; |
| 95 | } |
| 96 | |
| 97 | @Override |
| 98 | public String toString() { |
| 99 | return MoreObjects.toStringHelper(getClass()).add("encapEthSrc", encapEthSrc).toString(); |
| 100 | } |
| 101 | } |