blob: e1b5be910da67327f59211ba468a51fd43f5e564 [file] [log] [blame]
BitOhenryb53ac6c2015-11-16 20:58:58 +08001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2016-present Open Networking Laboratory
BitOhenryb53ac6c2015-11-16 20:58:58 +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;
21
BitOhenryb53ac6c2015-11-16 20:58:58 +080022import 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;
alshabib880b6442015-11-23 22:13:04 -080026import org.onosproject.net.flow.instructions.ExtensionTreatmentType;
BitOhenryb53ac6c2015-11-16 20:58:58 +080027import org.onosproject.store.serializers.PortNumberSerializer;
28
BitOhenry5e2233a2015-12-08 09:26:38 +080029import java.util.HashMap;
30import java.util.Map;
BitOhenryb53ac6c2015-11-16 20:58:58 +080031import java.util.Objects;
32
33import static com.google.common.base.Preconditions.checkNotNull;
34
35/**
36 * Nicira resubmit extension instruction.
37 */
Jonathan Hart26a8d952015-12-02 15:16:35 -080038public class NiciraResubmit extends AbstractExtension implements ExtensionTreatment {
BitOhenryb53ac6c2015-11-16 20:58:58 +080039
BitOhenry5e2233a2015-12-08 09:26:38 +080040 private static final short DEFAULT_TABLE_ID = 0;
41
BitOhenryb53ac6c2015-11-16 20:58:58 +080042 private PortNumber inPort;
BitOhenry5e2233a2015-12-08 09:26:38 +080043 private short table;
BitOhenryb53ac6c2015-11-16 20:58:58 +080044
45 private final KryoNamespace appKryo = new KryoNamespace.Builder()
46 .register(new PortNumberSerializer(), PortNumber.class)
BitOhenry5e2233a2015-12-08 09:26:38 +080047 .register(Map.class).register(HashMap.class)
BitOhenryb53ac6c2015-11-16 20:58:58 +080048 .register(byte[].class)
Charles Chaneefdedf2016-05-23 16:45:45 -070049 .build("NiciraResubmit");
BitOhenryb53ac6c2015-11-16 20:58:58 +080050
51 /**
52 * Creates a new resubmit instruction.
53 */
54 NiciraResubmit() {
55 inPort = null;
BitOhenry5e2233a2015-12-08 09:26:38 +080056 table = DEFAULT_TABLE_ID;
BitOhenryb53ac6c2015-11-16 20:58:58 +080057 }
58
59 /**
60 * Creates a new resubmit instruction with a particular inPort.
61 *
62 * @param inPort in port number
63 */
64 public NiciraResubmit(PortNumber inPort) {
65 checkNotNull(inPort);
66 this.inPort = inPort;
BitOhenry5e2233a2015-12-08 09:26:38 +080067 this.table = DEFAULT_TABLE_ID;
BitOhenryb53ac6c2015-11-16 20:58:58 +080068 }
69
70 /**
71 * Gets the inPort.
72 *
73 * @return inPort
74 */
75 public PortNumber inPort() {
76 return inPort;
77 }
78
BitOhenry5e2233a2015-12-08 09:26:38 +080079 /**
80 * Gets the table.
81 *
82 * @return table
83 */
84 public short table() {
85 return table;
86 }
87
BitOhenryb53ac6c2015-11-16 20:58:58 +080088 @Override
alshabib880b6442015-11-23 22:13:04 -080089 public ExtensionTreatmentType type() {
90 return ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_RESUBMIT.type();
BitOhenryb53ac6c2015-11-16 20:58:58 +080091 }
92
93 @Override
94 public void deserialize(byte[] data) {
BitOhenry5e2233a2015-12-08 09:26:38 +080095 Map<String, Object> values = appKryo.deserialize(data);
96 inPort = (PortNumber) values.get("inPort");
97 table = (short) values.get("table");
BitOhenryb53ac6c2015-11-16 20:58:58 +080098 }
99
100 @Override
101 public byte[] serialize() {
BitOhenry5e2233a2015-12-08 09:26:38 +0800102 Map<String, Object> values = Maps.newHashMap();
103 values.put("inPort", inPort);
104 values.put("table", table);
105 return appKryo.serialize(values);
BitOhenryb53ac6c2015-11-16 20:58:58 +0800106 }
107
108 @Override
109 public int hashCode() {
BitOhenry5e2233a2015-12-08 09:26:38 +0800110 return Objects.hash(inPort, table);
BitOhenryb53ac6c2015-11-16 20:58:58 +0800111 }
112
113 @Override
114 public boolean equals(Object obj) {
115 if (this == obj) {
116 return true;
117 }
118 if (obj instanceof NiciraResubmit) {
119 NiciraResubmit that = (NiciraResubmit) obj;
BitOhenry5e2233a2015-12-08 09:26:38 +0800120 return Objects.equals(inPort, that.inPort)
121 && (table == that.table());
BitOhenryb53ac6c2015-11-16 20:58:58 +0800122 }
123 return false;
124 }
125
126 @Override
127 public String toString() {
128 return MoreObjects.toStringHelper(getClass())
129 .add("inPort", inPort)
BitOhenry5e2233a2015-12-08 09:26:38 +0800130 .add("table", table)
BitOhenryb53ac6c2015-11-16 20:58:58 +0800131 .toString();
132 }
133}