blob: b7792ed0c449e393d591df10ba4b7bc0f6609303 [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;
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)
50 .build();
51
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);
68 checkNotNull(table);
69 this.inPort = inPort;
70 this.table = table;
BitOhenry74dd7e12015-12-01 09:07:19 +080071 }
72
73 /**
BitOhenry5e2233a2015-12-08 09:26:38 +080074 * Creates a new resubmit-table instruction with a particular table.
BitOhenry74dd7e12015-12-01 09:07:19 +080075 *
BitOhenry5e2233a2015-12-08 09:26:38 +080076 * @param table table
BitOhenry74dd7e12015-12-01 09:07:19 +080077 */
BitOhenry5e2233a2015-12-08 09:26:38 +080078 public NiciraResubmitTable(short table) {
79 checkNotNull(table);
80 this.inPort = DEFAULT_IN_PORT;
81 this.table = table;
82 }
83
84 /**
85 * Gets the inPort.
86 *
87 * @return inPort
88 */
89 public PortNumber inPort() {
90 return inPort;
91 }
92
93 /**
94 * Gets the table.
95 *
96 * @return table
97 */
98 public short table() {
99 return table;
BitOhenry74dd7e12015-12-01 09:07:19 +0800100 }
101
102 @Override
103 public ExtensionTreatmentType type() {
104 return ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_RESUBMIT_TABLE.type();
105 }
106
107 @Override
108 public void deserialize(byte[] data) {
BitOhenry5e2233a2015-12-08 09:26:38 +0800109 Map<String, Object> values = appKryo.deserialize(data);
110 inPort = (PortNumber) values.get("inPort");
111 table = (short) values.get("table");
BitOhenry74dd7e12015-12-01 09:07:19 +0800112 }
113
114 @Override
115 public byte[] serialize() {
BitOhenry5e2233a2015-12-08 09:26:38 +0800116 Map<String, Object> values = Maps.newHashMap();
117 values.put("inPort", inPort);
118 values.put("table", table);
119 return appKryo.serialize(values);
BitOhenry74dd7e12015-12-01 09:07:19 +0800120 }
121
122 @Override
123 public int hashCode() {
BitOhenry5e2233a2015-12-08 09:26:38 +0800124 return Objects.hash(inPort, table);
BitOhenry74dd7e12015-12-01 09:07:19 +0800125 }
126
127 @Override
128 public boolean equals(Object obj) {
129 if (this == obj) {
130 return true;
131 }
132 if (obj instanceof NiciraResubmitTable) {
133 NiciraResubmitTable that = (NiciraResubmitTable) obj;
BitOhenry5e2233a2015-12-08 09:26:38 +0800134 return Objects.equals(inPort, that.inPort)
135 && (table == that.table);
BitOhenry74dd7e12015-12-01 09:07:19 +0800136 }
137 return false;
138 }
139
140 @Override
141 public String toString() {
142 return MoreObjects.toStringHelper(getClass())
BitOhenry5e2233a2015-12-08 09:26:38 +0800143 .add("inPort", inPort)
144 .add("table", table)
145 .toString();
BitOhenry74dd7e12015-12-01 09:07:19 +0800146 }
BitOhenry5e2233a2015-12-08 09:26:38 +0800147}