blob: 4743d217d8a90d4322f220668e05012645197b45 [file] [log] [blame]
BitOhenry74dd7e12015-12-01 09:07:19 +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;
20
21import org.onlab.util.KryoNamespace;
22import org.onosproject.net.PortNumber;
Jonathan Hart26a8d952015-12-02 15:16:35 -080023import org.onosproject.net.flow.AbstractExtension;
24import org.onosproject.net.flow.instructions.ExtensionTreatment;
BitOhenry74dd7e12015-12-01 09:07:19 +080025import org.onosproject.net.flow.instructions.ExtensionTreatmentType;
26import org.onosproject.store.serializers.PortNumberSerializer;
27
28import java.util.ArrayList;
29import java.util.List;
30import java.util.Objects;
31
32import static com.google.common.base.Preconditions.checkNotNull;
33
34/**
35 * Nicira resubmit-table extension instruction.
36 */
Jonathan Hart26a8d952015-12-02 15:16:35 -080037public class NiciraResubmitTable extends AbstractExtension implements
38 ExtensionTreatment {
BitOhenry74dd7e12015-12-01 09:07:19 +080039
40 //the list of the in port number(PortNumber) and the table(short)
41 private List<Object> inPortAndTable = new ArrayList<Object>();
42
43 private final KryoNamespace appKryo = new KryoNamespace.Builder()
44 .register(ArrayList.class)
45 .register(new PortNumberSerializer(), PortNumber.class)
46 .register(short.class)
47 .register(byte[].class)
48 .build();
49
50 /**
51 * Creates a new resubmit-table instruction.
52 */
53 NiciraResubmitTable() {
54 inPortAndTable = null;
55 }
56
57 /**
58 * Creates a new resubmit-table instruction with a particular inPort and table.
59 *
60 * @param inPortAndTable the list of in port number and table
61 */
62 public NiciraResubmitTable(List<Object> inPortAndTable) {
63 checkNotNull(inPortAndTable);
64 this.inPortAndTable = inPortAndTable;
65 }
66
67 /**
68 * Gets the inPortAndTable.
69 *
70 * @return inPortAndTable
71 */
72 public List<Object> inPortAndTable() {
73 return inPortAndTable;
74 }
75
76 @Override
77 public ExtensionTreatmentType type() {
78 return ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_RESUBMIT_TABLE.type();
79 }
80
81 @Override
82 public void deserialize(byte[] data) {
83 inPortAndTable = appKryo.deserialize(data);
84 }
85
86 @Override
87 public byte[] serialize() {
88 return appKryo.serialize(inPortAndTable);
89 }
90
91 @Override
92 public int hashCode() {
93 return Objects.hash(inPortAndTable);
94 }
95
96 @Override
97 public boolean equals(Object obj) {
98 if (this == obj) {
99 return true;
100 }
101 if (obj instanceof NiciraResubmitTable) {
102 NiciraResubmitTable that = (NiciraResubmitTable) obj;
103 return Objects.equals(inPortAndTable, that.inPortAndTable);
104
105 }
106 return false;
107 }
108
109 @Override
110 public String toString() {
111 return MoreObjects.toStringHelper(getClass())
112 .add("inPortAndTable", inPortAndTable).toString();
113 }
Jonathan Hart26a8d952015-12-02 15:16:35 -0800114}