BitOhenry | 74dd7e1 | 2015-12-01 09:07:19 +0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Laboratory |
BitOhenry | 74dd7e1 | 2015-12-01 09:07:19 +0800 | [diff] [blame] | 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 | |
| 17 | package org.onosproject.driver.extensions; |
| 18 | |
| 19 | import com.google.common.base.MoreObjects; |
BitOhenry | 5e2233a | 2015-12-08 09:26:38 +0800 | [diff] [blame] | 20 | import com.google.common.collect.Maps; |
BitOhenry | 74dd7e1 | 2015-12-01 09:07:19 +0800 | [diff] [blame] | 21 | |
| 22 | import org.onlab.util.KryoNamespace; |
| 23 | import org.onosproject.net.PortNumber; |
Jonathan Hart | 26a8d95 | 2015-12-02 15:16:35 -0800 | [diff] [blame] | 24 | import org.onosproject.net.flow.AbstractExtension; |
| 25 | import org.onosproject.net.flow.instructions.ExtensionTreatment; |
BitOhenry | 74dd7e1 | 2015-12-01 09:07:19 +0800 | [diff] [blame] | 26 | import org.onosproject.net.flow.instructions.ExtensionTreatmentType; |
| 27 | import org.onosproject.store.serializers.PortNumberSerializer; |
| 28 | |
BitOhenry | 5e2233a | 2015-12-08 09:26:38 +0800 | [diff] [blame] | 29 | import java.util.HashMap; |
| 30 | import java.util.Map; |
BitOhenry | 74dd7e1 | 2015-12-01 09:07:19 +0800 | [diff] [blame] | 31 | import java.util.Objects; |
| 32 | |
| 33 | import static com.google.common.base.Preconditions.checkNotNull; |
| 34 | |
| 35 | /** |
| 36 | * Nicira resubmit-table extension instruction. |
| 37 | */ |
Jonathan Hart | 26a8d95 | 2015-12-02 15:16:35 -0800 | [diff] [blame] | 38 | public class NiciraResubmitTable extends AbstractExtension implements |
| 39 | ExtensionTreatment { |
BitOhenry | 74dd7e1 | 2015-12-01 09:07:19 +0800 | [diff] [blame] | 40 | |
BitOhenry | 5e2233a | 2015-12-08 09:26:38 +0800 | [diff] [blame] | 41 | private static final PortNumber DEFAULT_IN_PORT = PortNumber.portNumber(65528); |
| 42 | |
| 43 | private PortNumber inPort; |
| 44 | private short table; |
BitOhenry | 74dd7e1 | 2015-12-01 09:07:19 +0800 | [diff] [blame] | 45 | |
| 46 | private final KryoNamespace appKryo = new KryoNamespace.Builder() |
BitOhenry | 74dd7e1 | 2015-12-01 09:07:19 +0800 | [diff] [blame] | 47 | .register(new PortNumberSerializer(), PortNumber.class) |
BitOhenry | 5e2233a | 2015-12-08 09:26:38 +0800 | [diff] [blame] | 48 | .register(Map.class).register(HashMap.class) |
BitOhenry | 74dd7e1 | 2015-12-01 09:07:19 +0800 | [diff] [blame] | 49 | .register(byte[].class) |
Charles Chan | eefdedf | 2016-05-23 16:45:45 -0700 | [diff] [blame] | 50 | .build("NiciraResubmitTable"); |
BitOhenry | 74dd7e1 | 2015-12-01 09:07:19 +0800 | [diff] [blame] | 51 | |
| 52 | /** |
| 53 | * Creates a new resubmit-table instruction. |
| 54 | */ |
| 55 | NiciraResubmitTable() { |
BitOhenry | 5e2233a | 2015-12-08 09:26:38 +0800 | [diff] [blame] | 56 | inPort = DEFAULT_IN_PORT; |
| 57 | table = -1; |
BitOhenry | 74dd7e1 | 2015-12-01 09:07:19 +0800 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | /** |
| 61 | * Creates a new resubmit-table instruction with a particular inPort and table. |
| 62 | * |
BitOhenry | 5e2233a | 2015-12-08 09:26:38 +0800 | [diff] [blame] | 63 | * @param inPort the in port number |
| 64 | * @param table table |
BitOhenry | 74dd7e1 | 2015-12-01 09:07:19 +0800 | [diff] [blame] | 65 | */ |
BitOhenry | 5e2233a | 2015-12-08 09:26:38 +0800 | [diff] [blame] | 66 | public NiciraResubmitTable(PortNumber inPort, short table) { |
| 67 | checkNotNull(inPort); |
| 68 | checkNotNull(table); |
| 69 | this.inPort = inPort; |
| 70 | this.table = table; |
BitOhenry | 74dd7e1 | 2015-12-01 09:07:19 +0800 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | /** |
BitOhenry | 5e2233a | 2015-12-08 09:26:38 +0800 | [diff] [blame] | 74 | * Creates a new resubmit-table instruction with a particular table. |
BitOhenry | 74dd7e1 | 2015-12-01 09:07:19 +0800 | [diff] [blame] | 75 | * |
BitOhenry | 5e2233a | 2015-12-08 09:26:38 +0800 | [diff] [blame] | 76 | * @param table table |
BitOhenry | 74dd7e1 | 2015-12-01 09:07:19 +0800 | [diff] [blame] | 77 | */ |
BitOhenry | 5e2233a | 2015-12-08 09:26:38 +0800 | [diff] [blame] | 78 | 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; |
BitOhenry | 74dd7e1 | 2015-12-01 09:07:19 +0800 | [diff] [blame] | 100 | } |
| 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) { |
BitOhenry | 5e2233a | 2015-12-08 09:26:38 +0800 | [diff] [blame] | 109 | Map<String, Object> values = appKryo.deserialize(data); |
| 110 | inPort = (PortNumber) values.get("inPort"); |
| 111 | table = (short) values.get("table"); |
BitOhenry | 74dd7e1 | 2015-12-01 09:07:19 +0800 | [diff] [blame] | 112 | } |
| 113 | |
| 114 | @Override |
| 115 | public byte[] serialize() { |
BitOhenry | 5e2233a | 2015-12-08 09:26:38 +0800 | [diff] [blame] | 116 | Map<String, Object> values = Maps.newHashMap(); |
| 117 | values.put("inPort", inPort); |
| 118 | values.put("table", table); |
| 119 | return appKryo.serialize(values); |
BitOhenry | 74dd7e1 | 2015-12-01 09:07:19 +0800 | [diff] [blame] | 120 | } |
| 121 | |
| 122 | @Override |
| 123 | public int hashCode() { |
BitOhenry | 5e2233a | 2015-12-08 09:26:38 +0800 | [diff] [blame] | 124 | return Objects.hash(inPort, table); |
BitOhenry | 74dd7e1 | 2015-12-01 09:07:19 +0800 | [diff] [blame] | 125 | } |
| 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; |
BitOhenry | 5e2233a | 2015-12-08 09:26:38 +0800 | [diff] [blame] | 134 | return Objects.equals(inPort, that.inPort) |
| 135 | && (table == that.table); |
BitOhenry | 74dd7e1 | 2015-12-01 09:07:19 +0800 | [diff] [blame] | 136 | } |
| 137 | return false; |
| 138 | } |
| 139 | |
| 140 | @Override |
| 141 | public String toString() { |
| 142 | return MoreObjects.toStringHelper(getClass()) |
BitOhenry | 5e2233a | 2015-12-08 09:26:38 +0800 | [diff] [blame] | 143 | .add("inPort", inPort) |
| 144 | .add("table", table) |
| 145 | .toString(); |
BitOhenry | 74dd7e1 | 2015-12-01 09:07:19 +0800 | [diff] [blame] | 146 | } |
BitOhenry | 5e2233a | 2015-12-08 09:26:38 +0800 | [diff] [blame] | 147 | } |