blob: a20b24797e437a6e0dc69d188f46a6d811bedff3 [file] [log] [blame]
Jonathan Hart3c259162015-10-21 21:31:19 -07001/*
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
17package org.onosproject.driver.extensions;
18
19import com.google.common.base.MoreObjects;
20import org.onlab.packet.Ip4Address;
21import org.onlab.util.KryoNamespace;
22import org.onosproject.net.flow.instructions.AbstractExtensionInstruction;
23import org.onosproject.net.flow.instructions.ExtensionType;
24import org.onosproject.store.serializers.Ip4AddressSerializer;
25
26import java.util.Objects;
27
28import static com.google.common.base.Preconditions.checkNotNull;
29
30/**
31 * Nicira set tunnel destination extension instruction.
32 */
33public class NiciraSetTunnelDst extends AbstractExtensionInstruction {
34
35 private Ip4Address tunnelDst;
36
37 private final KryoNamespace appKryo = new KryoNamespace.Builder()
38 .register(new Ip4AddressSerializer(), Ip4Address.class)
39 .register(byte[].class)
40 .build();
41
42 /**
43 * Creates a new set tunnel destination instruction.
44 */
45 NiciraSetTunnelDst() {
46 tunnelDst = null;
47 }
48
49 /**
50 * Creates a new set tunnel destination instruction with a particular IPv4
51 * address.
Charles Chan30ba4002015-11-05 14:45:16 -080052 *
53 * @param tunnelDst tunnel destination IPv4 address
Jonathan Hart3c259162015-10-21 21:31:19 -070054 */
55 NiciraSetTunnelDst(Ip4Address tunnelDst) {
56 checkNotNull(tunnelDst);
57 this.tunnelDst = tunnelDst;
58 }
59
60 /**
61 * Gets the tunnel destination IPv4 address.
62 *
63 * @return tunnel destination IPv4 address
64 */
65 public Ip4Address tunnelDst() {
66 return tunnelDst;
67 }
68
69 @Override
70 public ExtensionType type() {
71 return ExtensionType.ExtensionTypes.NICIRA_SET_TUNNEL_DST.type();
72 }
73
74 @Override
75 public void deserialize(byte[] data) {
76 tunnelDst = appKryo.deserialize(data);
77 }
78
79 @Override
80 public byte[] serialize() {
81 return appKryo.serialize(tunnelDst);
82 }
83
84 @Override
85 public int hashCode() {
86 return Objects.hash(tunnelDst);
87 }
88
89 @Override
90 public boolean equals(Object obj) {
91 if (this == obj) {
92 return true;
93 }
94 if (obj instanceof NiciraSetTunnelDst) {
95 NiciraSetTunnelDst that = (NiciraSetTunnelDst) obj;
96 return Objects.equals(tunnelDst, that.tunnelDst);
97
98 }
99 return false;
100 }
101
102 @Override
103 public String toString() {
104 return MoreObjects.toStringHelper(getClass())
105 .add("tunnelDst", tunnelDst)
106 .toString();
107 }
108}