blob: b85af4f207fadbb52217f5d2bef9850ed0d43e53 [file] [log] [blame]
BitOhenryb53ac6c2015-11-16 20:58:58 +08001/*
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.util.KryoNamespace;
21import org.onosproject.net.PortNumber;
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;
BitOhenryb53ac6c2015-11-16 20:58:58 +080025import org.onosproject.store.serializers.PortNumberSerializer;
26
27import java.util.Objects;
28
29import static com.google.common.base.Preconditions.checkNotNull;
30
31/**
32 * Nicira resubmit extension instruction.
33 */
Jonathan Hart26a8d952015-12-02 15:16:35 -080034public class NiciraResubmit extends AbstractExtension implements ExtensionTreatment {
BitOhenryb53ac6c2015-11-16 20:58:58 +080035
36 private PortNumber inPort;
37
38 private final KryoNamespace appKryo = new KryoNamespace.Builder()
39 .register(new PortNumberSerializer(), PortNumber.class)
40 .register(byte[].class)
41 .build();
42
43 /**
44 * Creates a new resubmit instruction.
45 */
46 NiciraResubmit() {
47 inPort = null;
48 }
49
50 /**
51 * Creates a new resubmit instruction with a particular inPort.
52 *
53 * @param inPort in port number
54 */
55 public NiciraResubmit(PortNumber inPort) {
56 checkNotNull(inPort);
57 this.inPort = inPort;
58 }
59
60 /**
61 * Gets the inPort.
62 *
63 * @return inPort
64 */
65 public PortNumber inPort() {
66 return inPort;
67 }
68
69 @Override
alshabib880b6442015-11-23 22:13:04 -080070 public ExtensionTreatmentType type() {
71 return ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_RESUBMIT.type();
BitOhenryb53ac6c2015-11-16 20:58:58 +080072 }
73
74 @Override
75 public void deserialize(byte[] data) {
76 inPort = appKryo.deserialize(data);
77 }
78
79 @Override
80 public byte[] serialize() {
81 return appKryo.serialize(inPort);
82 }
83
84 @Override
85 public int hashCode() {
86 return Objects.hash(inPort);
87 }
88
89 @Override
90 public boolean equals(Object obj) {
91 if (this == obj) {
92 return true;
93 }
94 if (obj instanceof NiciraResubmit) {
95 NiciraResubmit that = (NiciraResubmit) obj;
96 return Objects.equals(inPort, that.inPort);
97
98 }
99 return false;
100 }
101
102 @Override
103 public String toString() {
104 return MoreObjects.toStringHelper(getClass())
105 .add("inPort", inPort)
106 .toString();
107 }
108}