blob: a7a85fe6fb3cd7b4cc0885668f42f762a85c8de6 [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 EncapEthSrc extension instruction to set encapsulated eth source.
32 */
33public class NiciraEncapEthSrc extends AbstractExtension implements ExtensionTreatment {
34
35 private MacAddress encapEthSrc;
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 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}