Jonathan Hart | 3c25916 | 2015-10-21 21:31:19 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Laboratory |
Jonathan Hart | 3c25916 | 2015-10-21 21:31:19 -0700 | [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 org.onlab.packet.Ip4Address; |
| 21 | import org.onlab.util.KryoNamespace; |
Jonathan Hart | 26a8d95 | 2015-12-02 15:16:35 -0800 | [diff] [blame] | 22 | import org.onosproject.net.flow.AbstractExtension; |
| 23 | import org.onosproject.net.flow.instructions.ExtensionTreatment; |
alshabib | 880b644 | 2015-11-23 22:13:04 -0800 | [diff] [blame] | 24 | import org.onosproject.net.flow.instructions.ExtensionTreatmentType; |
Jonathan Hart | 3c25916 | 2015-10-21 21:31:19 -0700 | [diff] [blame] | 25 | import org.onosproject.store.serializers.Ip4AddressSerializer; |
| 26 | |
| 27 | import java.util.Objects; |
| 28 | |
| 29 | import static com.google.common.base.Preconditions.checkNotNull; |
| 30 | |
| 31 | /** |
| 32 | * Nicira set tunnel destination extension instruction. |
| 33 | */ |
Jonathan Hart | 26a8d95 | 2015-12-02 15:16:35 -0800 | [diff] [blame] | 34 | public class NiciraSetTunnelDst extends AbstractExtension implements |
| 35 | ExtensionTreatment { |
Jonathan Hart | 3c25916 | 2015-10-21 21:31:19 -0700 | [diff] [blame] | 36 | |
| 37 | private Ip4Address tunnelDst; |
| 38 | |
| 39 | private final KryoNamespace appKryo = new KryoNamespace.Builder() |
| 40 | .register(new Ip4AddressSerializer(), Ip4Address.class) |
| 41 | .register(byte[].class) |
Charles Chan | eefdedf | 2016-05-23 16:45:45 -0700 | [diff] [blame] | 42 | .build("NiciraSetTunnelDst"); |
Jonathan Hart | 3c25916 | 2015-10-21 21:31:19 -0700 | [diff] [blame] | 43 | |
| 44 | /** |
| 45 | * Creates a new set tunnel destination instruction. |
| 46 | */ |
| 47 | NiciraSetTunnelDst() { |
| 48 | tunnelDst = null; |
| 49 | } |
| 50 | |
| 51 | /** |
| 52 | * Creates a new set tunnel destination instruction with a particular IPv4 |
| 53 | * address. |
Charles Chan | 30ba400 | 2015-11-05 14:45:16 -0800 | [diff] [blame] | 54 | * |
| 55 | * @param tunnelDst tunnel destination IPv4 address |
Jonathan Hart | 3c25916 | 2015-10-21 21:31:19 -0700 | [diff] [blame] | 56 | */ |
Jian Li | dab7256 | 2016-04-12 14:10:32 -0700 | [diff] [blame] | 57 | public NiciraSetTunnelDst(Ip4Address tunnelDst) { |
Jonathan Hart | 3c25916 | 2015-10-21 21:31:19 -0700 | [diff] [blame] | 58 | checkNotNull(tunnelDst); |
| 59 | this.tunnelDst = tunnelDst; |
| 60 | } |
| 61 | |
| 62 | /** |
| 63 | * Gets the tunnel destination IPv4 address. |
| 64 | * |
| 65 | * @return tunnel destination IPv4 address |
| 66 | */ |
| 67 | public Ip4Address tunnelDst() { |
| 68 | return tunnelDst; |
| 69 | } |
| 70 | |
| 71 | @Override |
alshabib | 880b644 | 2015-11-23 22:13:04 -0800 | [diff] [blame] | 72 | public ExtensionTreatmentType type() { |
| 73 | return ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_TUNNEL_DST.type(); |
Jonathan Hart | 3c25916 | 2015-10-21 21:31:19 -0700 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | @Override |
| 77 | public void deserialize(byte[] data) { |
| 78 | tunnelDst = appKryo.deserialize(data); |
| 79 | } |
| 80 | |
| 81 | @Override |
| 82 | public byte[] serialize() { |
| 83 | return appKryo.serialize(tunnelDst); |
| 84 | } |
| 85 | |
| 86 | @Override |
| 87 | public int hashCode() { |
| 88 | return Objects.hash(tunnelDst); |
| 89 | } |
| 90 | |
| 91 | @Override |
| 92 | public boolean equals(Object obj) { |
| 93 | if (this == obj) { |
| 94 | return true; |
| 95 | } |
| 96 | if (obj instanceof NiciraSetTunnelDst) { |
| 97 | NiciraSetTunnelDst that = (NiciraSetTunnelDst) obj; |
| 98 | return Objects.equals(tunnelDst, that.tunnelDst); |
| 99 | |
| 100 | } |
| 101 | return false; |
| 102 | } |
| 103 | |
| 104 | @Override |
| 105 | public String toString() { |
| 106 | return MoreObjects.toStringHelper(getClass()) |
| 107 | .add("tunnelDst", tunnelDst) |
| 108 | .toString(); |
| 109 | } |
| 110 | } |