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