blob: 3e1dd0593ad0ab331df34935ac018558452b2788 [file] [log] [blame]
BitOhenry74dd7e12015-12-01 09:07:19 +08001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
BitOhenry74dd7e12015-12-01 09:07:19 +08003 *
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;
BitOhenry5e2233a2015-12-08 09:26:38 +080020import com.google.common.collect.Maps;
BitOhenry74dd7e12015-12-01 09:07:19 +080021
22import org.onlab.util.KryoNamespace;
23import org.onosproject.net.PortNumber;
Jonathan Hart26a8d952015-12-02 15:16:35 -080024import org.onosproject.net.flow.AbstractExtension;
25import org.onosproject.net.flow.instructions.ExtensionTreatment;
BitOhenry74dd7e12015-12-01 09:07:19 +080026import org.onosproject.net.flow.instructions.ExtensionTreatmentType;
27import org.onosproject.store.serializers.PortNumberSerializer;
28
BitOhenry5e2233a2015-12-08 09:26:38 +080029import java.util.HashMap;
30import java.util.Map;
BitOhenry74dd7e12015-12-01 09:07:19 +080031import java.util.Objects;
32
33import static com.google.common.base.Preconditions.checkNotNull;
34
35/**
36 * Nicira resubmit-table extension instruction.
37 */
Jonathan Hart26a8d952015-12-02 15:16:35 -080038public class NiciraResubmitTable extends AbstractExtension implements
39 ExtensionTreatment {
BitOhenry74dd7e12015-12-01 09:07:19 +080040
BitOhenry5e2233a2015-12-08 09:26:38 +080041 private static final PortNumber DEFAULT_IN_PORT = PortNumber.portNumber(65528);
42
43 private PortNumber inPort;
44 private short table;
BitOhenry74dd7e12015-12-01 09:07:19 +080045
46 private final KryoNamespace appKryo = new KryoNamespace.Builder()
BitOhenry74dd7e12015-12-01 09:07:19 +080047 .register(new PortNumberSerializer(), PortNumber.class)
BitOhenry5e2233a2015-12-08 09:26:38 +080048 .register(Map.class).register(HashMap.class)
BitOhenry74dd7e12015-12-01 09:07:19 +080049 .register(byte[].class)
Charles Chaneefdedf2016-05-23 16:45:45 -070050 .build("NiciraResubmitTable");
BitOhenry74dd7e12015-12-01 09:07:19 +080051
52 /**
53 * Creates a new resubmit-table instruction.
54 */
55 NiciraResubmitTable() {
BitOhenry5e2233a2015-12-08 09:26:38 +080056 inPort = DEFAULT_IN_PORT;
57 table = -1;
BitOhenry74dd7e12015-12-01 09:07:19 +080058 }
59
60 /**
61 * Creates a new resubmit-table instruction with a particular inPort and table.
62 *
BitOhenry5e2233a2015-12-08 09:26:38 +080063 * @param inPort the in port number
64 * @param table table
BitOhenry74dd7e12015-12-01 09:07:19 +080065 */
BitOhenry5e2233a2015-12-08 09:26:38 +080066 public NiciraResubmitTable(PortNumber inPort, short table) {
67 checkNotNull(inPort);
BitOhenry5e2233a2015-12-08 09:26:38 +080068 this.inPort = inPort;
69 this.table = table;
BitOhenry74dd7e12015-12-01 09:07:19 +080070 }
71
72 /**
BitOhenry5e2233a2015-12-08 09:26:38 +080073 * Creates a new resubmit-table instruction with a particular table.
BitOhenry74dd7e12015-12-01 09:07:19 +080074 *
BitOhenry5e2233a2015-12-08 09:26:38 +080075 * @param table table
BitOhenry74dd7e12015-12-01 09:07:19 +080076 */
BitOhenry5e2233a2015-12-08 09:26:38 +080077 public NiciraResubmitTable(short table) {
BitOhenry5e2233a2015-12-08 09:26:38 +080078 this.inPort = DEFAULT_IN_PORT;
79 this.table = table;
80 }
81
82 /**
83 * Gets the inPort.
84 *
85 * @return inPort
86 */
87 public PortNumber inPort() {
88 return inPort;
89 }
90
91 /**
92 * Gets the table.
93 *
94 * @return table
95 */
96 public short table() {
97 return table;
BitOhenry74dd7e12015-12-01 09:07:19 +080098 }
99
100 @Override
101 public ExtensionTreatmentType type() {
102 return ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_RESUBMIT_TABLE.type();
103 }
104
105 @Override
106 public void deserialize(byte[] data) {
BitOhenry5e2233a2015-12-08 09:26:38 +0800107 Map<String, Object> values = appKryo.deserialize(data);
108 inPort = (PortNumber) values.get("inPort");
109 table = (short) values.get("table");
BitOhenry74dd7e12015-12-01 09:07:19 +0800110 }
111
112 @Override
113 public byte[] serialize() {
BitOhenry5e2233a2015-12-08 09:26:38 +0800114 Map<String, Object> values = Maps.newHashMap();
115 values.put("inPort", inPort);
116 values.put("table", table);
117 return appKryo.serialize(values);
BitOhenry74dd7e12015-12-01 09:07:19 +0800118 }
119
120 @Override
121 public int hashCode() {
BitOhenry5e2233a2015-12-08 09:26:38 +0800122 return Objects.hash(inPort, table);
BitOhenry74dd7e12015-12-01 09:07:19 +0800123 }
124
125 @Override
126 public boolean equals(Object obj) {
127 if (this == obj) {
128 return true;
129 }
130 if (obj instanceof NiciraResubmitTable) {
131 NiciraResubmitTable that = (NiciraResubmitTable) obj;
BitOhenry5e2233a2015-12-08 09:26:38 +0800132 return Objects.equals(inPort, that.inPort)
133 && (table == that.table);
BitOhenry74dd7e12015-12-01 09:07:19 +0800134 }
135 return false;
136 }
137
138 @Override
139 public String toString() {
140 return MoreObjects.toStringHelper(getClass())
BitOhenry5e2233a2015-12-08 09:26:38 +0800141 .add("inPort", inPort)
142 .add("table", table)
143 .toString();
BitOhenry74dd7e12015-12-01 09:07:19 +0800144 }
BitOhenry5e2233a2015-12-08 09:26:38 +0800145}