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