blob: b2f65f3c26f5e36bb9f4113402a78bf973c56835 [file] [log] [blame]
Carmelo Cascone17fc9e42016-05-31 11:29:21 -07001/*
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.bmv2.api.runtime;
18
Carmelo Cascone9e39e312016-06-16 14:47:09 -070019import com.google.common.annotations.Beta;
Carmelo Cascone17fc9e42016-05-31 11:29:21 -070020import com.google.common.base.MoreObjects;
21import com.google.common.base.Objects;
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;
26
27import static org.onosproject.net.flow.instructions.ExtensionTreatmentType.ExtensionTreatmentTypes.BMV2_ACTION;
28
29/**
30 * Extension treatment for BMv2 used as a wrapper for a {@link Bmv2Action}.
31 */
Carmelo Cascone9e39e312016-06-16 14:47:09 -070032@Beta
Carmelo Cascone17fc9e42016-05-31 11:29:21 -070033public final class Bmv2ExtensionTreatment extends AbstractExtension implements ExtensionTreatment {
34
35 private final KryoNamespace appKryo = new KryoNamespace.Builder().build();
36 private Bmv2Action action;
37
Carmelo Cascone9e39e312016-06-16 14:47:09 -070038 /**
39 * Creates a new extension treatment for the given BMv2 action.
40 *
41 * @param action an action
42 */
Carmelo Cascone17fc9e42016-05-31 11:29:21 -070043 public Bmv2ExtensionTreatment(Bmv2Action action) {
44 this.action = action;
45 }
46
Carmelo Cascone9e39e312016-06-16 14:47:09 -070047 /**
48 * Returns the action contained by this extension selector.
49 *
50 * @return an action
51 */
52 public Bmv2Action action() {
Carmelo Cascone17fc9e42016-05-31 11:29:21 -070053 return action;
54 }
55
56 @Override
57 public ExtensionTreatmentType type() {
58 return BMV2_ACTION.type();
59 }
60
61 @Override
62 public byte[] serialize() {
63 return appKryo.serialize(action);
64 }
65
66 @Override
67 public void deserialize(byte[] data) {
68 action = appKryo.deserialize(data);
69 }
70
71 @Override
72 public int hashCode() {
73 return Objects.hashCode(action);
74 }
75
76 @Override
77 public boolean equals(Object obj) {
78 if (this == obj) {
79 return true;
80 }
81 if (obj == null || getClass() != obj.getClass()) {
82 return false;
83 }
84 final Bmv2ExtensionTreatment other = (Bmv2ExtensionTreatment) obj;
85 return Objects.equal(this.action, other.action);
86 }
87
88 @Override
89 public String toString() {
90 return MoreObjects.toStringHelper(this)
91 .add("action", action)
92 .toString();
93 }
94}