blob: e72d35936bed68c38a788c66caea1b1ae8dd7469 [file] [log] [blame]
Phaneendra Manda8db7d092016-06-04 00:17:24 +05301/*
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
17package org.onosproject.driver.extensions;
18
19import java.util.Objects;
20
21import org.onlab.packet.MacAddress;
22import org.onlab.util.KryoNamespace;
23import org.onosproject.net.flow.AbstractExtension;
24import org.onosproject.net.flow.instructions.ExtensionTreatment;
25import org.onosproject.net.flow.instructions.ExtensionTreatmentType;
26import org.onosproject.store.serializers.MacAddressSerializer;
27
28import com.google.common.base.MoreObjects;
29
30/**
31 * Nicira EncapEthDst extension instruction to set encapsulated eth destination.
32 */
33public class NiciraEncapEthDst extends AbstractExtension implements ExtensionTreatment {
34
35 private MacAddress encapEthDst;
36
37 private final KryoNamespace appKryo = new KryoNamespace.Builder()
Jon Hall8c7b06a2017-02-22 13:37:33 -080038 .register(new MacAddressSerializer(), MacAddress.class).register(byte[].class).build();
Phaneendra Manda8db7d092016-06-04 00:17:24 +053039
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}