Carmelo Cascone | 5813681 | 2018-07-19 03:40:16 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018-present Open Networking Foundation |
| 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.net.pi.runtime; |
| 18 | |
| 19 | import com.google.common.base.Objects; |
| 20 | import org.onosproject.net.PortNumber; |
| 21 | |
| 22 | import static com.google.common.base.Preconditions.checkNotNull; |
| 23 | import static java.lang.String.format; |
| 24 | |
| 25 | /** |
| 26 | * Representation of a packet replica used for multicast or cloning process in a |
| 27 | * protocol-independent packet replication engine. |
| 28 | * <p> |
| 29 | * Each replica is uniquely identified inside a given multicast group or clone |
| 30 | * session by the pair (egress port, instance ID). |
| 31 | */ |
| 32 | public class PiPreReplica { |
| 33 | |
| 34 | private final PortNumber egressPort; |
Carmelo Cascone | b0f45fe | 2018-10-11 08:31:59 -0700 | [diff] [blame] | 35 | private final int instanceId; |
Carmelo Cascone | 5813681 | 2018-07-19 03:40:16 +0200 | [diff] [blame] | 36 | |
| 37 | /** |
| 38 | * Returns a new PRE packet replica for the given egress port and instance |
| 39 | * ID. |
| 40 | * |
| 41 | * @param egressPort egress port |
| 42 | * @param instanceId instance ID |
| 43 | */ |
Carmelo Cascone | b0f45fe | 2018-10-11 08:31:59 -0700 | [diff] [blame] | 44 | public PiPreReplica(PortNumber egressPort, int instanceId) { |
Carmelo Cascone | 5813681 | 2018-07-19 03:40:16 +0200 | [diff] [blame] | 45 | this.egressPort = checkNotNull(egressPort); |
| 46 | this.instanceId = instanceId; |
| 47 | } |
| 48 | |
| 49 | /** |
| 50 | * Returns the egress port of this replica. |
| 51 | * |
| 52 | * @return egress port |
| 53 | */ |
| 54 | public PortNumber egressPort() { |
| 55 | return egressPort; |
| 56 | } |
| 57 | |
| 58 | /** |
| 59 | * Returns the instance ID of this replica. |
| 60 | * |
| 61 | * @return instance ID |
| 62 | */ |
Carmelo Cascone | b0f45fe | 2018-10-11 08:31:59 -0700 | [diff] [blame] | 63 | public int instanceId() { |
Carmelo Cascone | 5813681 | 2018-07-19 03:40:16 +0200 | [diff] [blame] | 64 | return instanceId; |
| 65 | } |
| 66 | |
| 67 | @Override |
| 68 | public int hashCode() { |
| 69 | return Objects.hashCode(egressPort, instanceId); |
| 70 | } |
| 71 | |
| 72 | @Override |
| 73 | public boolean equals(Object obj) { |
| 74 | if (this == obj) { |
| 75 | return true; |
| 76 | } |
| 77 | if (obj == null || getClass() != obj.getClass()) { |
| 78 | return false; |
| 79 | } |
| 80 | final PiPreReplica other = (PiPreReplica) obj; |
| 81 | return Objects.equal(this.egressPort, other.egressPort) |
| 82 | && Objects.equal(this.instanceId, other.instanceId); |
| 83 | } |
| 84 | |
| 85 | @Override |
| 86 | public String toString() { |
Carmelo Cascone | b0c6665 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 87 | return format("%s:0x%s", egressPort, Integer.toHexString(instanceId)); |
Carmelo Cascone | 5813681 | 2018-07-19 03:40:16 +0200 | [diff] [blame] | 88 | } |
| 89 | } |