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