blob: e28a1e24cf1b1b1ba1e1f804a9f7136d87c6cae6 [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;
Jonathan Hart26a8d952015-12-02 15:16:35 -080022import org.onosproject.net.flow.AbstractExtension;
23import org.onosproject.net.flow.instructions.ExtensionTreatment;
alshabib880b6442015-11-23 22:13:04 -080024import org.onosproject.net.flow.instructions.ExtensionTreatmentType;
Jonathan Hart3c259162015-10-21 21:31:19 -070025import org.onosproject.store.serializers.Ip4AddressSerializer;
26
27import java.util.Objects;
28
29import static com.google.common.base.Preconditions.checkNotNull;
30
31/**
32 * Nicira set tunnel destination extension instruction.
33 */
Jonathan Hart26a8d952015-12-02 15:16:35 -080034public class NiciraSetTunnelDst extends AbstractExtension implements
35 ExtensionTreatment {
Jonathan Hart3c259162015-10-21 21:31:19 -070036
37 private Ip4Address tunnelDst;
38
39 private final KryoNamespace appKryo = new KryoNamespace.Builder()
40 .register(new Ip4AddressSerializer(), Ip4Address.class)
41 .register(byte[].class)
42 .build();
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 Chan30ba4002015-11-05 14:45:16 -080054 *
55 * @param tunnelDst tunnel destination IPv4 address
Jonathan Hart3c259162015-10-21 21:31:19 -070056 */
57 NiciraSetTunnelDst(Ip4Address tunnelDst) {
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
alshabib880b6442015-11-23 22:13:04 -080072 public ExtensionTreatmentType type() {
73 return ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_TUNNEL_DST.type();
Jonathan Hart3c259162015-10-21 21:31:19 -070074 }
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}