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