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